Skip to content

The open alternative to Salesforce, designed for AI.

fix(server): stabilize flaky app-install workspace-version gate test (#22851)

Paul Rastoinb94e38c2d99a
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/failing-app-installation-workspace-version.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/failing-app-installation-workspace-version.integration-spec.ts
index a916b5a94ff..34192364033 100644
--- a/packages/twenty-server/test/integration/metadata/suites/application/failing-app-installation-workspace-version.integration-spec.ts
+++ b/packages/twenty-server/test/integration/metadata/suites/application/failing-app-installation-workspace-version.integration-spec.ts
@@ -76,29 +76,37 @@ describe('Install application is gated by the workspace completed upgrade versio
beforeAll(async () => {
jest.useRealTimers();
- // The seeded workspace's cursor is the last step of the current version.
- // Re-injecting it as a failed attempt makes the workspace resolve to the
- // previous completed version — i.e. behind the instance.
- const [workspaceCursor] = await global.testDataSource.query(
- `SELECT name FROM core."upgradeMigration"
- WHERE "workspaceId" = $1
- ORDER BY "createdAt" DESC, attempt DESC
+ // Derive the gate version from the last attempted instance command, which
+ // is exactly what the upload-time server-compat check uses
+ // (getInferredVersion). The seeded workspace cursor can sit a version ahead
+ // of the instance right after a version bump whose newest segment ends in
+ // workspace-scoped commands with no new instance command: requiring
+ // >=workspaceVersion would then fail the instance gate at upload time,
+ // before the workspace gate under test is reached.
+ const [instanceCommand] = await global.testDataSource.query(
+ `SELECT migration.name AS name
+ FROM core."upgradeMigration" migration
+ WHERE migration."workspaceId" IS NULL
+ AND migration."isInitial" = false
+ AND migration.attempt = (
+ SELECT MAX(sub.attempt)
+ FROM core."upgradeMigration" sub
+ WHERE sub.name = migration.name
+ AND sub."workspaceId" IS NULL
+ )
+ ORDER BY migration."createdAt" DESC
LIMIT 1`,
- [SEED_APPLE_WORKSPACE_ID],
);
- if (!isDefined(workspaceCursor)) {
- throw new Error(
- `Expected a seeded upgrade cursor for workspace ${SEED_APPLE_WORKSPACE_ID}`,
- );
+ if (!isDefined(instanceCommand)) {
+ throw new Error('Expected a seeded instance upgrade command');
}
- currentVersionCommandName = workspaceCursor.name;
+ // Re-injecting this command as a failed workspace attempt makes the
+ // workspace resolve to the previous completed version (behind the
+ // instance), so the install reaches the workspace gate.
+ currentVersionCommandName = instanceCommand.name;
- // Pin to the version the instance actually reached, not
- // TWENTY_CURRENT_VERSION which can be bumped ahead of the latest instance
- // command and trip the upload-time server-compat check before the
- // workspace gate under test is reached.
const inferredServerVersion = extractVersionFromCommandName(
currentVersionCommandName,
);