#2551

test: isolate detect-agent tests from ambient agent env; accept ASCII bar in notion test

Openr2jaffwants to merge intofrom

Summary

Fixes 4 test failures that show up depending on where the suite is run. No production code changes.

  • src/detect-agent.test.ts: the tests stubbed only the Cursor env vars, so when the suite runs inside another AI agent (Claude Code sets AI_AGENT/CLAUDECODE, Codex sets CODEX_*, etc.) @vercel/detect-agent picks up that agent instead. 3 tests failed, e.g. expected 'claude-code_..._agent' to be 'cursor-cli'. Now every env var @vercel/detect-agent reads is cleared in beforeEach.
  • src/add.test.ts (notion test): @clack/prompts falls back to an ASCII | bar instead of │ when Unicode isn't detected (e.g. TERM=linux). The test only stripped │, so it failed. It now accepts either.

Testing

  • pnpm vitest run: 978/978 pass (it was 974/978 inside an agent session with TERM=linux)
  • pnpm type-check and Prettier pass

Activity

2
Muguett-DBYreviewed20d ago
Muguett-DBY20d ago

I hit the same Notion assertion while testing #2518 on Windows, so I checked this at 77f9997 with Node 24.22.1.

With AI_AGENT=claude-code, CLAUDECODE=1 and TERM=linux, the parent versions of these two test files reproduce all four failures: three agent-detection assertions and the ASCII | prefix. Restoring this patch makes all four pass; running both complete files then passes all 69 tests.

I also checked the installed @vercel/detect-agent implementation: all 18 environment variables it reads are covered by the reset list. This resolves the Windows test failure I ran into. My validation here is limited to these two test files.