-
Notifications
You must be signed in to change notification settings - Fork 524
test(cli): reconcile live test resource lifecycles #6650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,191
−308
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a17671a
test(cli): reconcile live test resource lifecycles
jgoux 2207a7d
test(cli): address live lifecycle review feedback
jgoux dfddd9a
chore(cli): merge develop into live lifecycle tests
jgoux 6a6f04e
test(cli): fix live helper quality checks
jgoux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
162 changes: 162 additions & 0 deletions
162
apps/cli/scripts/sweep-live-projects.integration.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| import { afterEach, describe, expect, test } from "vitest"; | ||
| import { chmod, mkdtemp, rm, writeFile } from "node:fs/promises"; | ||
| import { tmpdir } from "node:os"; | ||
| import path from "node:path"; | ||
|
|
||
| const script = path.resolve(import.meta.dirname, "sweep-live-projects.sh"); | ||
| const directories: string[] = []; | ||
|
|
||
| afterEach(async () => { | ||
| await Promise.all(directories.splice(0).map((directory) => rm(directory, { recursive: true }))); | ||
| }); | ||
|
|
||
| type Scenario = { | ||
| lists: Array<unknown> | ((deletes: ReadonlyArray<string>) => unknown); | ||
| deletes: Record<string, { status: number; body?: unknown }>; | ||
| deleteStatuses?: Record<string, Array<number>>; | ||
| }; | ||
|
|
||
| async function runSweep(scenario: Scenario) { | ||
| const directory = await mkdtemp(path.join(tmpdir(), "sweep-live-projects-")); | ||
| directories.push(directory); | ||
| const fakeSleep = path.join(directory, "sleep"); | ||
| await writeFile(fakeSleep, "#!/bin/sh\nexit 0\n"); | ||
| await chmod(fakeSleep, 0o755); | ||
|
|
||
| let listIndex = 0; | ||
| const deletes: string[] = []; | ||
| const server = Bun.serve({ | ||
| port: 0, | ||
| fetch(request) { | ||
| const url = new URL(request.url); | ||
| const ref = url.pathname.split("/").pop() ?? ""; | ||
| if (request.method === "GET" && url.pathname === "/v1/projects") { | ||
| const value = | ||
| typeof scenario.lists === "function" | ||
| ? scenario.lists(deletes) | ||
| : scenario.lists[Math.min(listIndex++, scenario.lists.length - 1)]; | ||
| return typeof value === "number" | ||
| ? new Response("temporary failure", { status: value }) | ||
| : Response.json(value); | ||
| } | ||
| if (request.method === "DELETE" && url.pathname.startsWith("/v1/projects/")) { | ||
| deletes.push(ref); | ||
| const statuses = scenario.deleteStatuses?.[ref]; | ||
| const result: { status: number; body?: unknown } = | ||
| statuses === undefined | ||
| ? (scenario.deletes[ref] ?? { status: 404 }) | ||
| : { | ||
| status: | ||
| statuses[ | ||
| Math.min( | ||
| deletes.filter((value) => value === ref).length - 1, | ||
| statuses.length - 1, | ||
| ) | ||
| ] ?? 500, | ||
| }; | ||
| return new Response(result.body === undefined ? null : JSON.stringify(result.body), { | ||
| status: result.status, | ||
| headers: { "x-request-id": `delete-${ref}` }, | ||
| }); | ||
| } | ||
| return new Response("not found", { status: 404 }); | ||
| }, | ||
| }); | ||
| try { | ||
| const child = Bun.spawn(["bash", script, "e2e-"], { | ||
| env: { | ||
| ...globalThis.process.env, | ||
| PATH: `${directory}:${globalThis.process.env.PATH}`, | ||
| SUPABASE_ACCESS_TOKEN: "test-token", | ||
| SUPABASE_LIVE_API_URL: `http://127.0.0.1:${server.port}`, | ||
| }, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const timeout = setTimeout(() => child.kill(), 10_000); | ||
| const [exitCode, stdout, stderr] = await Promise.all([ | ||
| child.exited, | ||
| new Response(child.stdout).text(), | ||
| new Response(child.stderr).text(), | ||
| ]); | ||
| clearTimeout(timeout); | ||
| return { exitCode, stdout, stderr, deletes }; | ||
| } finally { | ||
| await server.stop(true); | ||
| } | ||
| } | ||
|
|
||
| const active = (ref: string, name = `e2e-${ref}`) => ({ ref, name, status: "ACTIVE" }); | ||
|
|
||
| describe.skipIf(process.platform === "win32")("sweep-live-projects.sh", { timeout: 40_000 }, () => { | ||
| test("accepts refused deletion when a fresh authenticated list shows absence", async () => { | ||
| const result = await runSweep({ | ||
| lists: [[active("gone")], []], | ||
| deletes: { gone: { status: 403, body: { message: "already removed" } } }, | ||
| }); | ||
| expect(result.exitCode).toBe(0); | ||
| expect(result.deletes).toEqual(["gone"]); | ||
| expect(`${result.stdout}\n${result.stderr}`).not.toContain("test-token"); | ||
| }); | ||
|
|
||
| test("accepts a terminal status and converges after a stale list", async () => { | ||
| const result = await runSweep({ | ||
| lists: [[active("stale")], [active("stale")], [{ ...active("stale"), status: "REMOVED" }]], | ||
| deletes: { stale: { status: 202 } }, | ||
| }); | ||
| expect(result.exitCode).toBe(0); | ||
| }); | ||
|
|
||
| test("retries a transient read failure but rejects malformed evidence", async () => { | ||
| const transient = await runSweep({ | ||
| lists: [503, [active("retry")], []], | ||
| deletes: { retry: { status: 202 } }, | ||
| }); | ||
| expect(transient.exitCode).toBe(0); | ||
|
|
||
| const malformed = await runSweep({ lists: [{ projects: [] }], deletes: {} }); | ||
| expect(malformed.exitCode).not.toBe(0); | ||
| expect(malformed.deletes).toEqual([]); | ||
| }); | ||
|
|
||
| test("fails terminal listing errors without retrying or deleting", async () => { | ||
| const forbidden = await runSweep({ lists: [403, []], deletes: {} }); | ||
| expect(forbidden.exitCode).not.toBe(0); | ||
| expect(forbidden.deletes).toEqual([]); | ||
|
|
||
| const unavailable = await runSweep({ lists: [503, 503, 503], deletes: {} }); | ||
| expect(unavailable.exitCode).not.toBe(0); | ||
| expect(unavailable.deletes).toEqual([]); | ||
|
|
||
| const malformedReconciliation = await runSweep({ | ||
| lists: [[active("bad-evidence")], { projects: [] }], | ||
| deletes: { "bad-evidence": { status: 403 } }, | ||
| }); | ||
| expect(malformedReconciliation.exitCode).not.toBe(0); | ||
| }); | ||
|
|
||
| test("attempts every owned project and fails if one remains active", async () => { | ||
| const result = await runSweep({ | ||
| lists: [ | ||
| [active("stuck"), active("other"), { ref: "foreign", name: "unrelated", status: "ACTIVE" }], | ||
| [active("stuck"), { ref: "foreign", name: "unrelated", status: "ACTIVE" }], | ||
| ], | ||
| deletes: { stuck: { status: 403 }, other: { status: 204 } }, | ||
| }); | ||
| expect(result.exitCode).not.toBe(0); | ||
| expect(result.deletes).toEqual(["stuck", "other"]); | ||
| }); | ||
|
|
||
| test("retries a transient deletion after fresh evidence still shows the project", async () => { | ||
| const result = await runSweep({ | ||
| lists: (deletes) => (deletes.length >= 2 ? [] : [active("flaky")]), | ||
| deletes: {}, | ||
| deleteStatuses: { flaky: [503, 204] }, | ||
| }); | ||
| expect(result.exitCode).toBe(0); | ||
| expect(result.deletes).toEqual(["flaky", "flaky"]); | ||
| expect(result.stderr).toContain( | ||
| "delete retry completed for project flaky (HTTP 204 request delete-flaky)", | ||
| ); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 38 additions & 11 deletions
49
apps/cli/src/commands/branches/create/create.live.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.