Skip to content

fix(cli): resolveCliPath off-by-one in src + dist fallback paths#1223

Merged
christso merged 1 commit intomainfrom
fix/1221-resolve-cli-path
May 6, 2026
Merged

fix(cli): resolveCliPath off-by-one in src + dist fallback paths#1223
christso merged 1 commit intomainfrom
fix/1221-resolve-cli-path

Conversation

@christso
Copy link
Copy Markdown
Collaborator

@christso christso commented May 6, 2026

Closes #1221

Summary

Two off-by-one errors in resolveCliPath (added in the original eval-runner introduction, surfaced during PR #1220 e2e UAT) prevented Studio from spawning the CLI when run from a source checkout against any cwd that isn't the agentv repo itself.

Bug

apps/cli/src/commands/results/eval-runner.ts:215-216 resolved fallback paths from currentDir (where the eval-runner module is loaded from) using:

const fromSrc = path.resolve(currentDir, '../../../cli.ts');  // ❌ apps/cli/cli.ts (no src/)
const fromDist = path.resolve(currentDir, '../../cli.js');    // ❌ apps/cli.js (one too high)

For a dev-from-source run, currentDir = .../apps/cli/src/commands/results/ and we want apps/cli/src/cli.ts — so it's two .. not three. For a tsup-bundled dist run, currentDir = .../apps/cli/dist/ (chunks live alongside cli.js) and we want cli.js in the same dir — no .. at all.

End users with agentv installed globally hit the third fallback (global PATH lookup) and were unaffected. Developers running Studio from a worktree against a project outside the agentv repo got {"error":"Cannot locate agentv CLI entry point"}.

Fix

- const fromSrc = path.resolve(currentDir, '../../../cli.ts');
- const fromDist = path.resolve(currentDir, '../../cli.js');
+ const fromSrc = path.resolve(currentDir, '../../cli.ts');
+ const fromDist = path.resolve(currentDir, 'cli.js');

Plus a comment block explaining the two layouts so the next person doesn't have to re-derive them.

Tests

The resume-API request-shaping tests in apps/cli/test/commands/results/serve.test.ts previously tolerated [202, 500] because of this exact bug ("either spawn succeeded or no CLI on disk in test env"). With the fix, the running-process fallback always succeeds in the test runner, so tightened those assertions to exactly 202. A regression of this off-by-one will now fail CI.

Red / Green UAT

Foreign cwd: /tmp/agentv-1221-aXeco4 (random scratch dir, not the agentv repo).

Red — main

$ POST /api/eval/run {"resume":true,"output":"runs/r","suite_filter":"x"}
→ 500 {"error":"Cannot locate agentv CLI entry point"}

Green — this branch

$ POST /api/eval/run {"resume":true,"output":"runs/r","suite_filter":"x.eval.yaml","target":"y"}
→ 202 {"id":"studio-20260506-140143-gfjn","status":"running","command":"agentv eval x.eval.yaml --target y --output runs/r --resume"}

$ POST /api/eval/preview {"rerun_failed":true,...}
→ 200 {"command":"agentv eval x.eval.yaml --target y --output runs/r --rerun-failed"}

Test plan

  • bun test apps/cli/test/commands/results/serve.test.ts — 53 tests pass with strict 202 assertions
  • bun run lint — clean
  • bun run typecheck — clean
  • Manual red/green UAT (above)

🤖 Generated with Claude Code

Both fallback path resolutions in resolveCliPath were off:

- src: '../../../cli.ts' from .../apps/cli/src/commands/results/ resolved
  to apps/cli/cli.ts (missing src/). Should be '../../cli.ts'.
- dist: '../../cli.js' from .../apps/cli/dist/ resolved to apps/cli.js
  (one dir too high). tsup emits chunks alongside cli.js, so the entry
  is in the same dir — should be 'cli.js'.

End users with `agentv` installed globally were unaffected because the
third fallback (global PATH lookup) covered them. Affected: developers
running Studio from a source checkout against any cwd that isn't the
agentv repo itself.

Strengthened the existing resume-API tests to assert exact 202 (was
[202, 500]) so a regression of this off-by-one will fail CI.

Closes #1221

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying agentv with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7bba0a1
Status: ✅  Deploy successful!
Preview URL: https://00f2dc5a.agentv.pages.dev
Branch Preview URL: https://fix-1221-resolve-cli-path.agentv.pages.dev

View logs

@christso christso marked this pull request as ready for review May 6, 2026 12:06
@christso christso merged commit 0bab7a3 into main May 6, 2026
4 checks passed
@christso christso deleted the fix/1221-resolve-cli-path branch May 6, 2026 12:41
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.

bug(cli): resolveCliPath returns 'Cannot locate agentv CLI entry point' when Studio is run from source against a foreign cwd

1 participant