mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
fix(api): /api/compression/preview accepts mode caveman + stacked-zero (#6425) (net +1/-0, test OK). Integrated into release/v3.8.46.
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
- **fix(api):** `/api/compression/preview` now accepts `mode: "caveman"` and correctly handles stacked / zero-compression previews ([#6425](https://github.com/diegosouzapw/OmniRoute/issues/6425)). Regression guard: `tests/unit/api/compression-preview-caveman-and-stacked-6425.test.ts`. (thanks @chirag127)
|
||||
- **feat(providers):** add **Zed** hosted LLM aggregator as a native-app provider ([#6118](https://github.com/diegosouzapw/OmniRoute/pull/6118)) — OAuth sign-in via the Zed hosted flow, registered through the shared provider registry + executor. Regression guards: `tests/unit/zed-oauth-provider.test.ts`, `zed-import-utils.test.ts`, `zed-docker-detect.test.ts`, `mitm-handler-zed.test.ts`. VPS-validated via live operator login (Hard Rule #18).
|
||||
- **fix(oauth):** the Kiro SSO-cache auto-import now **preserves the IDC region** — cross-region Amazon Q / Kiro profiles imported from the SSO cache are no longer collapsed to the default region ([#6113](https://github.com/diegosouzapw/OmniRoute/pull/6113)). Regression guard: `tests/unit/kiro-auto-import-idc-2059.test.ts`. VPS-validated via live operator login (Hard Rule #18).
|
||||
- **fix(dashboard):** passthrough model aliases no longer collide when two namespaced model ids share a last segment. `enx/gpt-5.5` and `enx/codebuddy/gpt-5.5` both auto-generated the alias `gpt-5.5`, so the second model could never be added (the UI just alerted "alias already exists"). Aliases are now disambiguated deterministically — bare last segment when free, then parent-qualified (`codebuddy-gpt-5.5`), then a numeric suffix — while re-adding the exact same model id is still blocked. Regression guard: `tests/unit/passthrough-alias-1850.test.ts`. (thanks @arpicato)
|
||||
|
||||
@@ -289,9 +289,22 @@ export const cavemanEngine: CompressionEngine = {
|
||||
},
|
||||
apply(body, options) {
|
||||
const adapter = adaptBodyForCompression(body);
|
||||
// Mirror rtkAdapter's default-enabled behavior (see rtk/index.ts:530-535). When this engine
|
||||
// is invoked as a stacked step without explicit `enabled` on either the cavemanConfig or the
|
||||
// stepConfig, default `enabled: true` so the rules actually run. Without this,
|
||||
// DEFAULT_CAVEMAN_CONFIG.enabled=false made cavemanCompress() a silent no-op, and the
|
||||
// preview route's default [rtk, caveman] pipeline reported 0% savings even on trigger prose.
|
||||
// (Issue #6425.)
|
||||
const explicitCavemanConfig = options?.config?.cavemanConfig;
|
||||
const explicitStepConfig = options?.stepConfig;
|
||||
const explicitEnabled =
|
||||
(explicitCavemanConfig && "enabled" in explicitCavemanConfig) ||
|
||||
(explicitStepConfig && "enabled" in explicitStepConfig);
|
||||
const enabledDefault = explicitEnabled ? {} : { enabled: true };
|
||||
const cavemanConfig = {
|
||||
...(options?.config?.cavemanConfig ?? {}),
|
||||
...(options?.stepConfig ?? {}),
|
||||
...enabledDefault,
|
||||
...(explicitCavemanConfig ?? {}),
|
||||
...(explicitStepConfig ?? {}),
|
||||
...(options?.config?.languageConfig?.enabled
|
||||
? {
|
||||
language: options.config.languageConfig.defaultLanguage,
|
||||
|
||||
@@ -32,7 +32,7 @@ export const PreviewRequestSchema = z.object({
|
||||
)
|
||||
.min(1),
|
||||
mode: z
|
||||
.enum(["off", "lite", "standard", "aggressive", "ultra", "rtk", "stacked"])
|
||||
.enum(["off", "lite", "standard", "aggressive", "ultra", "rtk", "stacked", "caveman"])
|
||||
.optional()
|
||||
.default("stacked"),
|
||||
engineId: z.string().optional(),
|
||||
@@ -183,8 +183,11 @@ export async function POST(req: Request) {
|
||||
);
|
||||
}
|
||||
|
||||
const { messages, mode, engineId, pipeline, config, fidelityGate, fuzzyDedup, riskGate, quantumLock, heatmap: heatmapMode } =
|
||||
const { messages, mode, engineId: rawEngineId, pipeline, config, fidelityGate, fuzzyDedup, riskGate, quantumLock, heatmap: heatmapMode } =
|
||||
parsed.data;
|
||||
// Alias: `mode: "caveman"` is a synonym for `engineId: "caveman"` (single-engine stacked run).
|
||||
// The caveman engine is not a top-level CompressionMode, but it IS a registered engine.
|
||||
const engineId = mode === "caveman" && !rawEngineId ? "caveman" : rawEngineId;
|
||||
const effectiveMode: CompressionMode =
|
||||
engineId || pipeline ? "stacked" : (mode as CompressionMode);
|
||||
const originalText = messagesToText(messages);
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* Regression #6425 — /api/compression/preview rejects mode:"caveman" and stacked yields 0%.
|
||||
*
|
||||
* Two independent defects, one test file (both surface via the same endpoint):
|
||||
*
|
||||
* 1. `mode: "caveman"` was rejected by the Zod enum (only "off"/"lite"/"standard"/
|
||||
* "aggressive"/"ultra"/"rtk"/"stacked" allowed). The `caveman` engine exists in the
|
||||
* registry (see cavemanAdapter.ts) so the mode alias should be accepted and mapped
|
||||
* to a single-engine stacked run.
|
||||
*
|
||||
* 2. `mode: "stacked"` on prose containing well-known caveman-rule triggers ("Basically",
|
||||
* "I think", "probably", "just", "comprehensive") returned savingsPct: 0. Root cause:
|
||||
* the caveman engine's stacked-adapter did not default `enabled: true` when invoked
|
||||
* with no explicit stepConfig — DEFAULT_CAVEMAN_CONFIG.enabled=false made
|
||||
* cavemanCompress() a no-op. Mirrors the rtkAdapter fix pattern (rtk defaults enabled).
|
||||
*
|
||||
* Auth pattern mirrors compression-preview-engine.test.ts (JWT session, temp DATA_DIR).
|
||||
*/
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { makeManagementSessionRequest } from "../../helpers/managementSession.ts";
|
||||
|
||||
// ─── temp DB isolation ────────────────────────────────────────────────────────
|
||||
|
||||
const TEST_DATA_DIR = fs.mkdtempSync(
|
||||
path.join(os.tmpdir(), "omniroute-compression-preview-6425-")
|
||||
);
|
||||
const originalDataDir = process.env.DATA_DIR;
|
||||
const originalJwtSecret = process.env.JWT_SECRET;
|
||||
|
||||
process.env.DATA_DIR = TEST_DATA_DIR;
|
||||
|
||||
const core = await import("../../../src/lib/db/core.ts");
|
||||
const settingsDb = await import("../../../src/lib/db/settings.ts");
|
||||
const previewRoute = await import("../../../src/app/api/compression/preview/route.ts");
|
||||
|
||||
// ─── helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const CAVEMAN_TRIGGER =
|
||||
"Basically, I think we should probably just use a comprehensive analysis approach to " +
|
||||
"actually really understand the very important issue at hand.";
|
||||
|
||||
async function setupAuth(): Promise<void> {
|
||||
core.resetDbInstance();
|
||||
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
||||
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
||||
await settingsDb.updateSettings({
|
||||
requireLogin: true,
|
||||
setupComplete: true,
|
||||
password: "test-password-hash",
|
||||
});
|
||||
}
|
||||
|
||||
// ─── lifecycle ────────────────────────────────────────────────────────────────
|
||||
|
||||
test.beforeEach(async () => {
|
||||
process.env.DATA_DIR = TEST_DATA_DIR;
|
||||
await setupAuth();
|
||||
});
|
||||
|
||||
test.after(() => {
|
||||
if (originalDataDir === undefined) delete process.env.DATA_DIR;
|
||||
else process.env.DATA_DIR = originalDataDir;
|
||||
if (originalJwtSecret === undefined) delete process.env.JWT_SECRET;
|
||||
else process.env.JWT_SECRET = originalJwtSecret;
|
||||
core.resetDbInstance();
|
||||
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
// ─── tests ────────────────────────────────────────────────────────────────────
|
||||
|
||||
test("#6425 (a): POST /api/compression/preview accepts mode:'caveman' and produces >0% savings", async () => {
|
||||
const request = await makeManagementSessionRequest(
|
||||
"http://localhost/api/compression/preview",
|
||||
{
|
||||
method: "POST",
|
||||
body: {
|
||||
messages: [{ role: "user", content: CAVEMAN_TRIGGER }],
|
||||
mode: "caveman",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const response = await previewRoute.POST(request);
|
||||
assert.equal(
|
||||
response.status,
|
||||
200,
|
||||
`mode:"caveman" should be accepted (was rejected before #6425 fix), got ${response.status}`
|
||||
);
|
||||
|
||||
const body = (await response.json()) as {
|
||||
originalTokens: number;
|
||||
compressedTokens: number;
|
||||
savingsPct: number;
|
||||
techniquesUsed: string[];
|
||||
mode: string;
|
||||
};
|
||||
|
||||
assert.ok(body.originalTokens > 0, "originalTokens should be > 0");
|
||||
assert.ok(
|
||||
body.compressedTokens < body.originalTokens,
|
||||
`caveman rules should shrink well-known filler prose (got ${body.compressedTokens} vs ${body.originalTokens})`
|
||||
);
|
||||
assert.ok(body.savingsPct > 0, `savingsPct should be > 0, got ${body.savingsPct}`);
|
||||
});
|
||||
|
||||
test("#6425 (b): POST /api/compression/preview mode:'stacked' returns >0% on caveman-trigger prose", async () => {
|
||||
const request = await makeManagementSessionRequest(
|
||||
"http://localhost/api/compression/preview",
|
||||
{
|
||||
method: "POST",
|
||||
body: {
|
||||
messages: [{ role: "user", content: CAVEMAN_TRIGGER }],
|
||||
mode: "stacked",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const response = await previewRoute.POST(request);
|
||||
assert.equal(response.status, 200, `Expected 200, got ${response.status}`);
|
||||
|
||||
const body = (await response.json()) as {
|
||||
originalTokens: number;
|
||||
compressedTokens: number;
|
||||
savingsPct: number;
|
||||
engineBreakdown: Array<{ engine: string; savingsPercent: number }>;
|
||||
};
|
||||
|
||||
assert.ok(body.originalTokens > 0, "originalTokens should be > 0");
|
||||
assert.ok(
|
||||
body.savingsPct > 0,
|
||||
`stacked pipeline (default [rtk, caveman]) should produce >0% savings on filler-heavy prose, got ${body.savingsPct}% (regression: caveman step was silently disabled by DEFAULT_CAVEMAN_CONFIG.enabled=false)`
|
||||
);
|
||||
|
||||
// Assert the caveman step in the breakdown actually did work — this is the tightest guard
|
||||
// against the specific fix in cavemanAdapter.ts (default enabled when no explicit config).
|
||||
const cavemanStep = body.engineBreakdown.find((s) => s.engine === "caveman");
|
||||
assert.ok(cavemanStep, "engineBreakdown should include a caveman step");
|
||||
assert.ok(
|
||||
cavemanStep.savingsPercent > 0,
|
||||
`caveman step should report >0% savings on trigger prose, got ${cavemanStep.savingsPercent}%`
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user