Skip to content

fix(test): keep Vitest sidecar alive through teardown - #1341

Open
dmmulroy wants to merge 1 commit into
alchemy-run:mainfrom
dmmulroy:fix/vitest-sidecar-cleanup-order
Open

fix(test): keep Vitest sidecar alive through teardown#1341
dmmulroy wants to merge 1 commit into
alchemy-run:mainfrom
dmmulroy:fix/vitest-sidecar-cleanup-order

Conversation

@dmmulroy

Copy link
Copy Markdown
Contributor

Keep alchemy/Test/Vitest's shared scope and local provider sidecar alive through application teardown hooks.

vitestAroundAll(async (runSuite) => {
  try {
    await runSuite();
  } finally {
    await Effect.runPromise(closeAll);
  }
});

Vitest's default stack ordering reverses afterAll hooks, so the microtask-registered fallback ran before user hooks. aroundAll owns the complete suite lifecycle across hook-order modes and still tears down after failed setup or teardown.

The regression runs real Vitest through the public adapter. The corrected workerd reproduction is red on alchemy@2.0.0-beta.72 and green with this change, without moving telemetry onto the request path.

Addresses the local teardown failure reported in #1331.

sam-goodwin added a commit that referenced this pull request Aug 25, 2026
…r + Bun adapter)

Companion to #1341's Vitest aroundAll fix — the other two adapters had
the same class of leak, each with a different trigger:

- alchemy-test runner: runAfterAll short-circuited on the first failing
  hook, so a failing teardown assertion dropped every later afterAll —
  including Test.make's fallback that closes the shared scope and local
  provider sidecar. afterAll hooks now all run; failures aggregate.
- Test/Bun: bun:test stops the afterAll chain once a hook throws
  (verified empirically; registration order and afterAll-after-failed-
  beforeAll are fine), skipping the microtask-registered fallback. The
  adapter now guards user teardowns: on failure it runs the idempotent
  cleanup before rethrowing.

Both regression tests are red against the previous code.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant