Skip to content

fix(ai): keep cassettes of filtered tests when recording - #58890

Merged
rekram1-node merged 1 commit into
devfrom
recorder-keep-cassettes
Oct 25, 2026
Merged

rekram1-node merged 1 commit into
devfrom
recorder-keep-cassettes

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Problem

Recording one test with RECORD=true bun test file -t "name" deleted the cassettes of the other tests in the same file. For example, recording only the OpenAI case in test/provider/decision.recorded.test.ts wiped the TypeSafe, OpenCode and OpenRouter cassettes whenever their keys were set.

recordedTests removed the cassette while building the layer, and the layer is built when bun registers the test, before -t decides what runs:

 register test (all tests in file)
-  RECORD=true -> remove cassette        <- runs for filtered-out tests too
 run test (only tests matching -t)
+  RECORD=true -> remove cassette, then record

Change

I moved the removal into a Layer.unwrap, so it happens when the test's layer is built at run time. Only tests that actually run get their cassette replaced. There's no pruning of stale cassettes anywhere, so nothing else changes. RECORDED_PREFIX already skipped before the layer was built, so it was only -t that hit this.

Out of scope

packages/core/test/session-runner-recorded.test.ts removes its cassette at module load too, but that file has only one recorded cassette, so filtering can't delete another test's recording.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I reproduced it on the base: recording only the OpenAI decision test with -t and fake TYPESAFE_API_KEY/OPENAI_API_KEY deleted the filtered-out TypeSafe cassette. With this change only the cassette of the test that runs is replaced. testEffect provides the layer per test at run time, and building the recorder layers doesn't touch the cassette, so deleting it inside Layer.unwrap still happens before recording. The replay tests pass and tsc --noEmit for packages/ai is clean.

Public API is unchanged (test helper only).

@rekram1-node
rekram1-node merged commit dbdf775 into dev Oct 25, 2026
34 of 35 checks passed
@rekram1-node
rekram1-node deleted the recorder-keep-cassettes branch October 25, 2026 05:27
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