mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
feat(rtk): add X-9Router-Token-Saver header to bypass token savers per request
This commit is contained in:
@@ -250,4 +250,48 @@ describe("handleChatCore Headroom diagnostics", () => {
|
||||
expect.stringContaining("reported token delta, but outbound JSON shrank <5%; provider may bill near-original payload")
|
||||
);
|
||||
});
|
||||
|
||||
it("bypasses token savers when requested by the client", async () => {
|
||||
const log = { debug: vi.fn(), info: vi.fn(), warn: vi.fn() };
|
||||
const pxpipeTransform = vi.fn();
|
||||
const messages = [{ role: "user", content: "Write polished prose." }];
|
||||
|
||||
global.fetch = vi.fn(async (url) => {
|
||||
throw new Error(`unexpected fetch: ${url}`);
|
||||
});
|
||||
|
||||
await handleChatCore({
|
||||
body: { model: "gpt-4o", stream: false, messages },
|
||||
modelInfo: { provider: "openai", model: "gpt-4o" },
|
||||
credentials: { apiKey: "test-key", providerSpecificData: {} },
|
||||
log,
|
||||
connectionId: "test-conn",
|
||||
headroomEnabled: true,
|
||||
headroomUrl: "http://localhost:8787",
|
||||
headroomCompressUserMessages: true,
|
||||
rtkEnabled: true,
|
||||
cavemanEnabled: true,
|
||||
cavemanLevel: "full",
|
||||
ponytailEnabled: true,
|
||||
ponytailLevel: "full",
|
||||
pxpipeEnabled: true,
|
||||
pxpipeTransform,
|
||||
clientRawRequest: {
|
||||
endpoint: "/v1/chat/completions",
|
||||
body: {},
|
||||
headers: {
|
||||
accept: "application/json",
|
||||
"x-9router-token-saver": "off",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(global.fetch).not.toHaveBeenCalled();
|
||||
expect(pxpipeTransform).not.toHaveBeenCalled();
|
||||
expect(executeMock).toHaveBeenCalledWith(expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
messages: [{ role: "user", content: "Write polished prose." }],
|
||||
}),
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user