Conversation
anurag629
left a comment
There was a problem hiding this comment.
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:
-
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 setsessionSecrets. A token is bound to one conversation (sessions.ts:8-9), and each test makes a neweval-<uuid>(packages/cli/src/test/run.ts:128), so a fixed--header "Authorization: Bearer ..."can't carry it, and every turn ends withsession_required. Before a test's first turn, POST{ "conversationId": ... }to<url>/sessionlike the widget does, use theconversationIdthat comes back, and sendAuthorization: Bearer <token>on each turn. Send the--headerheaders on that call too, so anOriginheader works withallowedOrigins. A 404 there means session tokens are off, so carry on without one. Add a test withsessionSecretsset, and say in the docs that a server with Turnstile can't be tested this way, since minting needs a Turnstile token. -
--urlcan'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 whenCIis 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 becauserun()passes an empty env. Since the point is to check the deployed server, make--urllive: don't install the cassettes for it (packages/cli/src/main.ts:108), and refuse--recordand--replaywith--urlas aConfigError. Add a test that passesCI: 'true'. -
With
--urlthe config file isn't read at all (packages/cli/src/main.ts:110-113), so itsjudgeandpricesare dropped. Withjudge: { type: 'claude' }in the config, a run with--urlgrades with Gemini instead (packages/cli/src/test/judge.ts:53), or fails for a missingGEMINI_API_KEY. Load the config when there is one (or--configis passed) and pass itsjudgeandprices. Onlyservershould be optional with--url. -
The test server at
packages/cli/tests/test-command.test.ts:97is 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. PutchatcopsVercelHandler(which runspackages/server/src/http.ts) behindnode:http, as the issue asked. And nothing checks that--headeris sent: have the server keep the headers it got and assert on them.
anurag629
left a comment
There was a problem hiding this comment.
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.
|
@anurag629 thanks for the quick review, could u take a final look at this before merge. |
anurag629
left a comment
There was a problem hiding this comment.
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.
|
Merged, thanks @bhushan4work. |
What does this change?
Adds
--url <endpoint>tochatcops testso 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), failsmockstests with a clear reason when--urlis set rather than skipping silently, and preservesconversationIdacross turns.Closes #419
How I tested this
pnpm test:coverage— new tests inpackages/clispin up a real server viacreateChatHandler+node:http(mirroringpackages/server/tests) and cover multi-turn (conversationIdretained across turns), an error part, and a refused request.pnpm lint— clean.--url https://example.com/chat, repeatable--header "Authorization: Bearer …"(values never logged),--concurrency 1against the server rate limit, and that--recordreplay still works unchanged since replays happen at thefetchlevel incassette.ts.AI assistance
none
Checklist
devpnpm -r build,pnpm testandpnpm -r typecheckpass locallypnpm changeset) if this changescore,widgetorserver— minor changeset for@chatcops/clipnpm apirun andapi/committed if an exported type or option changedwebsite/src/content/docs/core/testing.mdx(documents--url, repeatable--header, and--concurrency 1)