Test: cover module type resolution by file extension and the --file_type override - #874
Open
AmaadMartin wants to merge 1 commit into
Open
Test: cover module type resolution by file extension and the --file_type override#874AmaadMartin wants to merge 1 commit into
AmaadMartin wants to merge 1 commit into
Conversation
…type override getFileModuleType() maps a file extension to a module type before it reads package.json, and AgentFile.load() lets AgentFileOptions.moduleType override the whole lookup. Four of the five branches had no test, so a refactor could change the compiled extension and the esbuild format without a red suite. Test-only change. No production file is modified.
AmaadMartin
force-pushed
the
fix/agent-loader-module-type-extension-tests
branch
from
August 9, 2026 16:35
1e50f23 to
c4f456d
Compare
AmaadMartin
changed the base branch from
fix/agent-loader-test-package-json-module-type
to
main
August 9, 2026 16:35
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
Link to an existing issue (if applicable):
Or, if no issue exists, describe the change:
Problem:
getFileModuleType()picks a module type from the file extension before it readspackage.json. Four of its five outcomes have no test:.cjs/.cts,.mjs/.mts, the unknown-extension default, and theAgentFileOptions.moduleTypeoverride behind the--file_typeflag. A refactor can therefore change the compiled file extension and theesbuildformat while the suite stays green.Solution: I added seven tests to
dev/test/utils/agent_loader_test.ts. They drive the publicAgentFileclass and assert the recordedesbuild.buildoptions, becausegetFileModuleTypeis module-private and must stay private. This is a test-only change; no production file is modified.Every compiled fixture uses an
ext_basename prefix. The Vitest module runner caches an imported module by path and ignores the cache-busting query thatAgentFile.load()appends, so a repeated basename returns the earlier test's module.Collision check. I ran this before starting:
No open PR covers the extension branches or the
moduleTypeoverride. PR #778 edits the same test file for thepackage.jsonhalf of the decision. This branch stays based onmainso it carries none of that PR's work, and the two diffs sit in different regions of the file.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.
Proof the tests can fail. I mutated
dev/src/utils/agent_loader.ts, re-ran the file, and reverted each time.['.mts', '.mjs']branch returnsCJSext_mjs_agent.mjs,ext_mts_agent.mts['.cjs', '.cts']branch returnsESMext_cjs_agent.cjs,ext_cts_agent.ctsreturn FileModuleType.CJSreturnsESMext_unsupported_agent.jsxthis.options.moduleType ||fromAgentFile.load()prefers an explicit ... moduleTypetestsM4 failure message:
Known gap, disclosed. Deleting the
['.cjs', '.cts']branch is not detectable. Those extensions then reach the samereturn FileModuleType.CJSdefault, so the result does not change. The tests pin the resolved value, not the existence of the branch.Other local checks on the pushed commit:
Two pre-existing problems, unrelated to this change.
cli_create_test.ts > should handle Vertex AI selection with gcloud defaultsreads the machine's real gcloud config and fails onmaintoo.npx tsc --noEmitreports 287 errors, all incore/test/andtests/integration/, none indev/, and the count is identical with and without this change.CI is green on ubuntu, macOS and Windows. The first Windows run timed out after 40 s in
tests/integration/app_loader/app_loader_test.ts, which this change does not touch; it passed on a rerun of the same commit.Manual End-to-End (E2E) Tests:
None. No behaviour ships. The tests pin what a user already gets from
adk run path/to/agent.mjs(ESM, nopackage.jsonread) andadk run path/to/agent.js --file_type esm(explicit override).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.