Registry Mirror
Skip to content

Conversation

@bhushan4work

Copy link
Copy Markdown
Collaborator

What does this change?

Adds --url <endpoint> to chatcops test so the same eval files can be run against a deployed server over the wire protocol (format: 'v1') as a post-deploy smoke test, instead of only in-process. Also adds repeatable --header "K: V" for auth (values never printed), fails mocks tests with a clear reason when --url is set rather than skipping silently, and preserves conversationId across turns.

Closes #419

How I tested this

  • pnpm test:coverage — new tests in packages/cli spin up a real server via createChatHandler + node:http (mirroring packages/server/tests) and cover multi-turn (conversationId retained across turns), an error part, and a refused request.
  • pnpm lint — clean.
  • Manually checked --url https://example.com/chat, repeatable --header "Authorization: Bearer …" (values never logged), --concurrency 1 against the server rate limit, and that --record replay still works unchanged since replays happen at the fetch level in cassette.ts.

AI assistance

none

Checklist

  • This PR targets dev
  • I was assigned the linked issue
  • pnpm -r build, pnpm test and pnpm -r typecheck pass locally
  • Tests added or updated where it makes sense
  • For a bug fix: the new test fails without my change
  • Changeset added (pnpm changeset) if this changes core, widget or server — minor changeset for @chatcops/cli
  • pnpm api run and api/ committed if an exported type or option changed
  • Docs updated if behavior or options changed — website/src/content/docs/core/testing.mdx (documents --url, repeatable --header, and --concurrency 1)

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bhushan4work, the parsing side is right. protocol: 1 is how to ask for v1, the stream reading skips : ping and [DONE], refusals come out as code: message the same as in process, and a test with mocks fails with a reason. All checks pass, including e2e. A few things need to change before it can go in:

  1. It doesn't get past session tokens, so it fails against a normal deploy. Since 1.0 every chat request needs a token unless the server sets allowAnonymous: true (packages/server/src/security/sessions.ts:64-69), and the example servers all set sessionSecrets. A token is bound to one conversation (sessions.ts:8-9), and each test makes a new eval-<uuid> (packages/cli/src/test/run.ts:128), so a fixed --header "Authorization: Bearer ..." can't carry it, and every turn ends with session_required. Before a test's first turn, POST { "conversationId": ... } to <url>/session like the widget does, use the conversationId that comes back, and send Authorization: Bearer <token> on each turn. Send the --header headers on that call too, so an Origin header works with allowedOrigins. A 404 there means session tokens are off, so carry on without one. Add a test with sessionSecrets set, and say in the docs that a server with Turnstile can't be tested this way, since minting needs a Turnstile token.

  2. --url can't record or replay. Cassettes match on a hash of the method, URL and body (packages/cli/src/test/cassette.ts:232-237), and the body has a new conversation id every run, so a recording is never found again. Replay is the default when CI is set (packages/cli/src/test/command.ts:194), which is where a check after a deploy runs, so every turn there fails with a cassette miss. The tests don't see it because run() passes an empty env. Since the point is to check the deployed server, make --url live: don't install the cassettes for it (packages/cli/src/main.ts:108), and refuse --record and --replay with --url as a ConfigError. Add a test that passes CI: 'true'.

  3. With --url the config file isn't read at all (packages/cli/src/main.ts:110-113), so its judge and prices are dropped. With judge: { type: 'claude' } in the config, a run with --url grades with Gemini instead (packages/cli/src/test/judge.ts:53), or fails for a missing GEMINI_API_KEY. Load the config when there is one (or --config is passed) and pass its judge and prices. Only server should be optional with --url.

  4. The test server at packages/cli/tests/test-command.test.ts:97 is a copy of the HTTP layer, with its own SSE writing and error JSON, so it can't catch where the CLI and the real server disagree, like the session check in 1. Put chatcopsVercelHandler (which runs packages/server/src/http.ts) behind node:http, as the issue asked. And nothing checks that --header is sent: have the server keep the headers it got and assert on them.

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bhushan4work, nearly there. All four points are fixed: a token from <url>/session for each test, sent on every turn, --url live under CI with --record and --replay refused, the config's judge and prices passed through, and tests on the real handler behind node:http that check the headers. All checks pass, including e2e.

One thing still breaks, and it's the example in the docs. website/src/content/docs/core/testing.mdx:40 runs --header "Authorization: Bearer $CHAT_TOKEN". Against a server with session tokens on, packages/cli/src/test/run.ts:311-312 puts that header and the session token in the same object under Authorization and authorization, and fetch joins them into Bearer secret, Bearer <token>. bearer() at packages/server/src/security/sessions.ts:195 doesn't match that, so every turn fails with session_required even though a token was minted. The test at packages/cli/tests/test-command.test.ts:165 sends that header, but its server has allowAnonymous: true, so no token comes back and it passes.

When a token comes back and --header has an Authorization, stop with an error that says the session token uses that header, rather than sending both. Change the docs example to --header "Origin: https://example.com", which is the one people need with allowedOrigins. And add a case to the session test that passes --header "Authorization: Bearer secret" and checks the error.

@bhushan4work

Copy link
Copy Markdown
Collaborator Author

@anurag629 thanks for the quick review, could u take a final look at this before merge.

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bhushan4work. With session tokens on, an Authorization from --header now fails the test with a message that says why instead of being sent next to the token, the new test covers it, and the docs example uses Origin. I updated your branch with dev. All checks pass, including e2e.

@anurag629
anurag629 merged commit 1ac65a2 into codercops:dev Nov 16, 2026
@anurag629

Copy link
Copy Markdown
Member

Merged, thanks @bhushan4work.

@github-actions github-actions Bot added the codercops-accepted Merged PR that counts on the monthly leaderboard (oss.codercops.com) label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codercops-accepted Merged PR that counts on the monthly leaderboard (oss.codercops.com)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chatcops test: --url to test a deployed server

2 participants