feat(rtk): add X-9Router-Token-Saver header to bypass token savers per request

This commit is contained in:
joachimBrindeau
2026-07-16 11:27:42 +07:00
parent 88a8c72d2d
commit c9926897ba
4 changed files with 57 additions and 6 deletions
+44
View File
@@ -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." }],
}),
}));
});
});