diff --git a/apps/cli/tests/helpers/branches-live.integration.test.ts b/apps/cli/tests/helpers/branches-live.integration.test.ts index 0dd5e7cfd8..a16c146719 100644 --- a/apps/cli/tests/helpers/branches-live.integration.test.ts +++ b/apps/cli/tests/helpers/branches-live.integration.test.ts @@ -275,6 +275,35 @@ describe("live branch lifecycle helpers", () => { }), ); + it.effect("re-issues create once after the platform drops TLS while setting the password", () => + Effect.gen(function* () { + let creates = 0; + const cli: BranchCli = (args) => + Effect.sync(() => { + if (args[1] === "create") { + creates += 1; + return creates === 1 + ? result( + JSON.stringify({ + _tag: "Error", + error: { + message: + 'unexpected create branch status 400: {"message":"Failed to update password: Client network socket disconnected before secure TLS connection was established"}', + }, + }), + "", + 1, + ) + : result(JSON.stringify(branch)); + } + return result(JSON.stringify([defaultBranch])); + }); + const ref = yield* createLiveBranchEffect(cli, project, branch.name); + expect(ref).toBe(branchRef); + expect(creates).toBe(2); + }), + ); + it.effect("fails a create rejected by a second platform database restart", () => Effect.gen(function* () { let creates = 0; diff --git a/apps/cli/tests/helpers/branches-live.ts b/apps/cli/tests/helpers/branches-live.ts index fc2d81489e..ad28f470bb 100644 --- a/apps/cli/tests/helpers/branches-live.ts +++ b/apps/cli/tests/helpers/branches-live.ts @@ -139,17 +139,19 @@ function branchRefFromCreate( ); } -// The platform rejects `branches create` with a 400 when the database it configures restarts mid-create. -const PLATFORM_DATABASE_RESTART = /\b57P01\b|the database system is shutting down/u; +// The platform rejects `branches create` with a 400 when the database it configures restarts, or its +// TLS connection drops while setting the database password, mid-create. +const PLATFORM_TRANSIENT_CREATE_REJECTION = + /\b57P01\b|the database system is shutting down|Failed to update password: Client network socket disconnected before secure TLS connection was established/u; -function isPlatformDatabaseRestart(error: unknown): boolean { +function isPlatformTransientCreateRejection(error: unknown): boolean { return ( error instanceof BranchCommandFailed && - PLATFORM_DATABASE_RESTART.test(`${error.stdout ?? ""}\n${error.stderr}`) + PLATFORM_TRANSIENT_CREATE_REJECTION.test(`${error.stdout ?? ""}\n${error.stderr}`) ); } -/** Runs `branches create`, re-issuing it once when the platform restarted the database mid-create. */ +/** Runs `branches create`, re-issuing it once when the platform rejected it with a transient mid-create failure. */ export function runLiveBranchCreateEffect( cli: BranchCli, project: LiveProject, @@ -170,7 +172,7 @@ export function runLiveBranchCreateEffect( ); return create.pipe( Effect.catch((rejected) => - isPlatformDatabaseRestart(rejected) + isPlatformTransientCreateRejection(rejected) ? clearRejected.pipe( Effect.mapError( (cleanup) =>