Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions apps/cli/tests/helpers/branches-live.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions apps/cli/tests/helpers/branches-live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<E>(
cli: BranchCli<E>,
project: LiveProject,
Expand All @@ -170,7 +172,7 @@ export function runLiveBranchCreateEffect<E>(
);
return create.pipe(
Effect.catch((rejected) =>
isPlatformDatabaseRestart(rejected)
isPlatformTransientCreateRejection(rejected)
? clearRejected.pipe(
Effect.mapError(
(cleanup) =>
Expand Down
Loading