Fix: fail loudly when two agent_loader tests compile to the same fixture path - #958
Open
AmaadMartin wants to merge 1 commit into
Open
Fix: fail loudly when two agent_loader tests compile to the same fixture path#958AmaadMartin wants to merge 1 commit into
AmaadMartin wants to merge 1 commit into
Conversation
…e path The AgentFile block mocks createTempDir to return one shared directory, so two tests whose agent files share a basename compile to the same absolute path. The module runner then hands the second import() the module the first test already evaluated. Seven tests were colliding on agent1.cjs and agent2.cjs. Route every esbuild.build mock through mockCompiledOutput, which claims the outfile in a file-scoped Set and throws on a repeat. Rename five fixtures so the guard is satisfiable. No test title, assertion or expected string changes.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
N/A
Problem: The
AgentFiletests mockcreateTempDirto return one shared directory, so two tests whose agent files share a basename compile to the same absolute path. The module runner then hands the secondimport()the module the first test already evaluated. Seven tests collided onagent1.cjsandagent2.cjs, and four of them asserted against a module an earlier test had built. They pass only because the colliding fixtures hold identical content, so the assertions are decorative.Solution: Every
esbuild.buildmock now goes throughmockCompiledOutput, which claims the realoptions.outfilein a file-scopedSetand throws on a repeat. I renamed five fixture files, because the guard cannot pass while the existing collisions remain. No test title, assertion or expected string changed: the agent names come from the fixture content, not from the file name.dev/src/utils/agent_loader.tsis untouched, because its?t=cache-buster is correct for the real Node ESM loader thatadk run --reload_agentsuses.Renamed fixtures (source file name only):
agent1_private_dir.js,agent1_disposed.js,agent2_cleanup.ts,agent1_as_app.js,agent1_cached.js.The
AgentLoaderblock also claims its outfile. That block is safe today only because its ownbeforeEachgives each load a freshmkdtempdirectory, so the guard keeps that property enforced.Collision check: I listed all 300 open PRs on this fork and found 20 that touch
dev/test/utils/agent_loader_test.ts(#918, #896, #892, #874, #861, #854, #832, #830, #815, #814, #793, #778, #755, #731, #727, #726, #725, #674, #664, #662). I grepped every one of those diffs for the guard. None adds it, so this does not duplicate a sibling. The overlap is line-level only, so this branch comes offmain.Testing Plan
Please describe the tests that you ran to verify your changes. This is required for all PRs that are not small documentation or typo fixes.
Unit Tests:
[x] I have added or updated unit tests for my change.
[x] All unit tests pass locally.
One new test,
rejects a second compile to a fixture name another test already used. It loads one source file through twoAgentFileinstances and asserts the secondload()rejects with the guard's message.Proof the tests can fail. I ran two mutations and reverted both.
claimCompiledFixture(options.outfile);frommockCompiledOutput. The new test failed:AssertionError: promise resolved "FakeAgent1{ …(7), …(1) }" instead of rejecting.caches loaded agent instanceback onagent1.js. That test failed:Compiled fixture 'agent1.cjs' was already produced by another test in this file. Reusing it makes this test import the earlier test's module instead of its own, so it passes or fails for the wrong reason - give this test's agent file a unique name.This proves the guard catches a real collision, not only the synthetic one.Coverage:
dev/test/**is outside the coverageincludeglobs invitest.config.ts, so the reported percentages do not move. Every added line runs. The twelveAgentFilecompile sites and the wholeAgentLoaderblock exercise the happy path, and the new test exercises the throw.Manual End-to-End (E2E) Tests:
No runtime behaviour changes, so there is nothing to exercise by hand. I ran the local gate instead, on the pushed commit:
npm run ts:checkreports 292 errors in this workspace, both with and without this change, and none in the changed file. It is not part of the CI validation workflow.Checklist
[x] I have read the CONTRIBUTING.md document.
[x] I have performed a self-review of my own code.
[x] I have commented my code, particularly in hard-to-understand areas.
[x] I have added tests that prove my fix is effective or that my feature works.
[x] New and existing unit tests pass locally with my changes.