kimi-work: test that the Work token goes only to the official chat endpoint

#190 dropped the old guard assertion with the error-body test it lived in.
The guard (index.mjs:106-109) is unchanged; this puts its test back and
widens it: another host, another path, a query, credentials in the URL and
GET are all refused before any fetch.

Run: bun test packages/kimi-work (18 pass); bun scripts/check.mjs kimi-work
(ok). Removing url.search from the guard turns this test red.
This commit is contained in:
yetone
2026-10-17 14:07:29 +08:00
parent 6017ebc383
commit 3e966bb4b5
+12
View File
@@ -105,3 +105,15 @@ test('desktop import is read-only and never substitutes a Code endpoint', () =>
expect(() => I.readDesktop(file)).toThrow();
} finally {fs.rmSync(dir, {recursive: true, force: true});}
});
test('the Work token goes only to the official Work chat endpoint', async () => {
let called = 0;
const p = I.createPlugin({readSession: () => session, fetchImpl: async () => {called++; return new Response('{}');}});
const loader = await p.auth.loader(async () => auth);
for (const url of ['https://example.invalid/coding/v1/chat/completions', I.BASE + '/models',
I.BASE + '/chat/completions?x=1', 'https://user:pw@agent-gw.kimi.com/coding/v1/chat/completions']) {
await expect(loader.fetch(url, {method: 'POST', body: '{}'})).rejects.toThrow('仅接受官方');
}
await expect(loader.fetch(I.BASE + '/chat/completions', {method: 'GET'})).rejects.toThrow('仅接受官方');
expect(called).toBe(0);
});