mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 12:22:14 +03:00
The fast-path (PR->release/**) does not run the full unit+integration suites, so four merged feature PRs shipped with stale/incorrect tests that only surface on the release PR (PR->main). Repairs (features are correct; align tests to the new behavior — no assertions weakened): - #5480 (gate claude adaptive thinking): adaptive thinking is now injected only for a real Claude Code client (x-app:cli / claude-code UA), not for any bare Claude OAuth token. claude-thinking-tool-choice-guard + base-thinking-budget-5312 now identify as a Claude Code client to exercise the adaptive path (3 tests). - #5527 (T02 inflation guard): the guard reverts a stacked body that did not shrink in tokens. The bail-out/advancement fixtures used growth-appending mock engines; they now carry a droppable padding message the engines empty, so the body realistically shrinks and the marker assertions survive. bailout (5), stacked-async (3), engine-enabled-toggle (2). - #5427 (render onboarding wizard at /providers/new): integration-wiring asserted the old redirect stub; now asserts the route renders ProviderOnboardingWizard. - #5521 (mimocode SOCKS5 per-account proxy): the constructor's default account omitted the proxy field (undefined), breaking the 'all proxies null' backward compat guard. Default it to null, mirroring syncAccountsFromCredentials().
129 lines
4.4 KiB
TypeScript
129 lines
4.4 KiB
TypeScript
/**
|
|
* Registry `enabled` toggle — the stacked loop must honor setEngineEnabled.
|
|
*
|
|
* `enabled` was a flag the stacked pipeline never consulted: getCompressionEngine
|
|
* returned the engine regardless, so flipping it via setEngineEnabled had no effect
|
|
* (the toggle "lied"). Both the sync and async stacked loops now skip a step whose
|
|
* engine is disabled.
|
|
*/
|
|
import { describe, it, before, after, beforeEach } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
applyStackedCompression,
|
|
applyStackedCompressionAsync,
|
|
} from "../../../open-sse/services/compression/index.ts";
|
|
import {
|
|
registerCompressionEngine,
|
|
unregisterCompressionEngine,
|
|
setEngineEnabled,
|
|
} from "../../../open-sse/services/compression/engines/registry.ts";
|
|
import type {
|
|
CompressionEngine,
|
|
CompressionEngineTarget,
|
|
} from "../../../open-sse/services/compression/engines/types.ts";
|
|
import type {
|
|
CompressionPipelineStep,
|
|
CompressionResult,
|
|
} from "../../../open-sse/services/compression/types.ts";
|
|
|
|
const ENGINE_ID = "enabled-toggle-engine";
|
|
|
|
/** Engine that tags user content and reports a real gain when it runs. */
|
|
function makeTaggingEngine(id: string): CompressionEngine {
|
|
return {
|
|
id,
|
|
name: id,
|
|
description: id,
|
|
icon: "x",
|
|
targets: ["messages"] as CompressionEngineTarget[],
|
|
stackable: true,
|
|
stackPriority: 0,
|
|
metadata: {
|
|
id,
|
|
name: id,
|
|
description: id,
|
|
inputScope: "messages",
|
|
targetLatencyMs: 1,
|
|
supportsPreview: false,
|
|
stable: true,
|
|
},
|
|
compress: (body) => ({ body, compressed: false, stats: null }),
|
|
getConfigSchema: () => [],
|
|
validateConfig: () => ({ valid: true, errors: [] }),
|
|
apply: (body) => {
|
|
const messages = (body.messages as Array<{ role: string; content: string }>) ?? [];
|
|
// Tag the user message; drop any padding (non-user) content so the body shrinks
|
|
// and the #5527 (T02) inflation guard keeps the tagged output instead of reverting.
|
|
const next = messages.map((m) =>
|
|
m.role === "user" ? { ...m, content: m.content + "|tagged" } : { ...m, content: "" }
|
|
);
|
|
return {
|
|
body: { ...body, messages: next },
|
|
compressed: true,
|
|
stats: {
|
|
originalTokens: 100,
|
|
compressedTokens: 70,
|
|
savingsPercent: 30,
|
|
techniquesUsed: [id],
|
|
mode: "stacked",
|
|
timestamp: 0,
|
|
durationMs: 0.1,
|
|
},
|
|
};
|
|
},
|
|
};
|
|
}
|
|
|
|
function pipeline(...ids: string[]): CompressionPipelineStep[] {
|
|
return ids.map((engine) => ({ engine })) as unknown as CompressionPipelineStep[];
|
|
}
|
|
|
|
function userContent(result: CompressionResult): string {
|
|
const messages = result.body.messages as Array<{ role: string; content: string }>;
|
|
return messages.find((m) => m.role === "user")!.content;
|
|
}
|
|
|
|
function freshBody() {
|
|
// Includes a droppable padding message so an engine that runs nets a real token shrink
|
|
// (the engine empties non-user content), keeping the #5527 inflation guard from reverting.
|
|
return {
|
|
messages: [
|
|
{ role: "user", content: "hi" },
|
|
{ role: "assistant", content: "padding tokens ".repeat(40) },
|
|
],
|
|
};
|
|
}
|
|
|
|
describe("registry enabled toggle — stacked loop honors setEngineEnabled", () => {
|
|
before(() => registerCompressionEngine(makeTaggingEngine(ENGINE_ID)));
|
|
beforeEach(() => setEngineEnabled(ENGINE_ID, true)); // default-on before each case
|
|
after(() => unregisterCompressionEngine(ENGINE_ID));
|
|
|
|
it("applies the engine while enabled (sync)", () => {
|
|
const result = applyStackedCompression(freshBody(), pipeline(ENGINE_ID));
|
|
assert.equal(result.compressed, true);
|
|
assert.equal(userContent(result), "hi|tagged");
|
|
});
|
|
|
|
it("skips the engine once disabled (sync)", () => {
|
|
setEngineEnabled(ENGINE_ID, false);
|
|
const result = applyStackedCompression(freshBody(), pipeline(ENGINE_ID));
|
|
assert.equal(result.compressed, false);
|
|
assert.equal(userContent(result), "hi"); // unchanged — step skipped
|
|
});
|
|
|
|
it("applies the engine while enabled (async)", async () => {
|
|
const result = await applyStackedCompressionAsync(freshBody(), pipeline(ENGINE_ID));
|
|
assert.equal(result.compressed, true);
|
|
assert.equal(userContent(result), "hi|tagged");
|
|
});
|
|
|
|
it("skips the engine once disabled (async)", async () => {
|
|
setEngineEnabled(ENGINE_ID, false);
|
|
const result = await applyStackedCompressionAsync(freshBody(), pipeline(ENGINE_ID));
|
|
assert.equal(result.compressed, false);
|
|
assert.equal(userContent(result), "hi");
|
|
});
|
|
});
|