From 3e966bb4b5f21b9b3d1cbe6c4d15cca8fbf32fe9 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 17 Oct 2026 14:07:29 +0800 Subject: [PATCH] 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. --- packages/kimi-work/kimi-work.test.mjs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/kimi-work/kimi-work.test.mjs b/packages/kimi-work/kimi-work.test.mjs index 4f6fee5..693881d 100644 --- a/packages/kimi-work/kimi-work.test.mjs +++ b/packages/kimi-work/kimi-work.test.mjs @@ -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); +});