Skip to content

Test: fail integration tests fast when the ADK CLI is not built - #673

Open
AmaadMartin wants to merge 1 commit into
mainfrom
fix/test-api-server-build-precondition-guard
Open

Test: fail integration tests fast when the ADK CLI is not built#673
AmaadMartin wants to merge 1 commit into
mainfrom
fix/test-api-server-build-precondition-guard

Conversation

@AmaadMartin

Copy link
Copy Markdown
Owner

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

  1. Link to an existing issue (if applicable):

  2. Or, if no issue exists, describe the change:

Problem: AdkTsApiServer.start() spawns node dev/dist/esm/cli_entrypoint.js without checking that the file exists. A contributor who runs an integration test before npm run build gets a raw ERR_MODULE_NOT_FOUND dump and then CLI exited prematurely with code 1. That message names neither the missing file nor the fix. Five suites reach this path, including tests/integration/a2a/basic/a2a_agent_test.ts and tests/integration/adk_web/webui_test.ts.

Solution: assertAdkCliBuilt() runs as the first statement of start(). It names the resolved path and tells the developer to run npm run build, which is the order CONTRIBUTING.md documents. AdkGoServer.start() already checks a prerequisite with fs.existsSync in that position, so this follows an in-repo precedent. The guard is exported at module scope so a test can call it without widening the private getAdkCliArgs.

Scope notes:

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

New file tests/integration/test_api_server_test.ts, 3 tests:

npx vitest run --project integration tests/integration/test_api_server_test.ts
# 3 passed, 7 ms

Proof the tests can fail. I mutated the source twice and re-ran the same file:

Mutation Result
Deleted assertAdkCliBuilt(CLI_ENTRYPOINT_PATH); from start() 1 failed: AssertionError: promise resolved "AdkApiClient{ backendUrl: 'http://lo…' }" instead of rejecting
Inverted the guard to if (fs.existsSync(cliPath)) 3 failed: AssertionError: expected [Function] to throw an error, and expected [Function] to not throw an error but 'Error: ADK CLI entrypoint not found a…' was thrown

Coverage: vitest.config.ts measures core/src, dev/src and integrations/src only, so files under tests/ are not reported. Both branches of the new if execute, and the start() call site is pinned by the third test.

Manual End-to-End (E2E) Tests:

Reproduce an unbuilt entrypoint on a built tree, then restore it:

npm run build
mv dev/dist/esm/cli_entrypoint.js /tmp/cli_entrypoint.js.bak
npx vitest run --project integration tests/integration/a2a/basic/a2a_agent_test.ts
mv /tmp/cli_entrypoint.js.bak dev/dist/esm/cli_entrypoint.js

Before this change the run ended in CLI exited prematurely with code 1. Now it fails in 4 ms of test time with:

Error: ADK CLI entrypoint not found at <repo>/dev/dist/esm/cli_entrypoint.js.
The integration tests spawn the built CLI; run `npm run build` from the
repository root first.

Behaviour on a built tree is unchanged. Both dependent suites still pass:

npx vitest run --project integration tests/integration/a2a/basic/a2a_agent_test.ts   # 1 passed
npx vitest run --project integration tests/integration/adk_web/webui_test.ts         # 2 passed
npm run lint          # clean
npm run format:check  # clean
npm run ts:check      # 281 pre-existing errors in 41 files, identical with and without this change

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

AdkTsApiServer.start() spawned node on dev/dist/esm/cli_entrypoint.js
without checking that the build output exists. On a fresh checkout the
child exits 1 and the harness reports only "CLI exited prematurely with
code 1", which names neither the missing file nor the fix.

assertAdkCliBuilt() now runs as the first statement of start() and names
the resolved path and the npm run build command. This mirrors the
existing prerequisite check in AdkGoServer.start().
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