diff options
| author | Luke Parker <[email protected]> | 2026-03-07 16:33:12 +1000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-07 16:33:12 +1000 |
| commit | 0b7a5b1e7bc7619c85e7cf4e30a1a0d4885779b6 (patch) | |
| tree | 6fcd11b17e890867a4c8d578452e90ed92fe7ffa /packages/app/e2e/actions.ts | |
| parent | 28bb16ca2a374439973d4f3f4b71d72f7fdae9cd (diff) | |
| download | opencode-0b7a5b1e7bc7619c85e7cf4e30a1a0d4885779b6.tar.gz opencode-0b7a5b1e7bc7619c85e7cf4e30a1a0d4885779b6.zip | |
test(app): abort sessions and wait for idle before e2e cleanup (#16439)
Diffstat (limited to 'packages/app/e2e/actions.ts')
| -rw-r--r-- | packages/app/e2e/actions.ts | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/packages/app/e2e/actions.ts b/packages/app/e2e/actions.ts index 8787b70f5..2354b88e8 100644 --- a/packages/app/e2e/actions.ts +++ b/packages/app/e2e/actions.ts @@ -306,6 +306,57 @@ export async function clickListItem( return item } +async function status(sdk: ReturnType<typeof createSdk>, sessionID: string) { + const data = await sdk.session + .status() + .then((x) => x.data ?? {}) + .catch(() => undefined) + return data?.[sessionID] +} + +async function stable(sdk: ReturnType<typeof createSdk>, sessionID: string, timeout = 10_000) { + let prev = "" + await expect + .poll( + async () => { + const info = await sdk.session + .get({ sessionID }) + .then((x) => x.data) + .catch(() => undefined) + if (!info) return true + const next = `${info.title}:${info.time.updated ?? info.time.created}` + if (next !== prev) { + prev = next + return false + } + return true + }, + { timeout }, + ) + .toBe(true) +} + +export async function waitSessionIdle(sdk: ReturnType<typeof createSdk>, sessionID: string, timeout = 30_000) { + await expect.poll(() => status(sdk, sessionID).then((x) => !x || x.type === "idle"), { timeout }).toBe(true) +} + +export async function cleanupSession(input: { + sessionID: string + directory?: string + sdk?: ReturnType<typeof createSdk> +}) { + const sdk = input.sdk ?? (input.directory ? createSdk(input.directory) : undefined) + if (!sdk) throw new Error("cleanupSession requires sdk or directory") + await waitSessionIdle(sdk, input.sessionID, 5_000).catch(() => undefined) + const current = await status(sdk, input.sessionID).catch(() => undefined) + if (current && current.type !== "idle") { + await sdk.session.abort({ sessionID: input.sessionID }).catch(() => undefined) + await waitSessionIdle(sdk, input.sessionID).catch(() => undefined) + } + await stable(sdk, input.sessionID).catch(() => undefined) + await sdk.session.delete({ sessionID: input.sessionID }).catch(() => undefined) +} + export async function withSession<T>( sdk: ReturnType<typeof createSdk>, title: string, @@ -317,7 +368,7 @@ export async function withSession<T>( try { return await callback(session) } finally { - await sdk.session.delete({ sessionID: session.id }).catch(() => undefined) + await cleanupSession({ sdk, sessionID: session.id }) } } |
