diff --git a/open-sse/handlers/chatCore.ts b/open-sse/handlers/chatCore.ts index 50863e456b..ae82310eb8 100644 --- a/open-sse/handlers/chatCore.ts +++ b/open-sse/handlers/chatCore.ts @@ -166,6 +166,11 @@ import { mergeResponseToolNameMap, } from "./chatCore/passthroughToolNames.ts"; import { resolveCompressionSettings } from "./chatCore/compressionSettings.ts"; +import { + isBuiltinStackedPipeline, + isStackedCompressionCombo, + type RuntimeCompressionCombo, +} from "./chatCore/compressionComboPredicates.ts"; import { recordContextEditingTelemetryHook } from "./chatCore/contextEditingTelemetry.ts"; import { recordCompressionCacheStats } from "./chatCore/compressionCacheStats.ts"; import { writeCavemanOutputAnalytics } from "./chatCore/cavemanOutputAnalytics.ts"; @@ -908,27 +913,6 @@ export async function handleChatCore({ } let compressionComboKey = comboName ?? null; let compressionComboApplied = false; - type RuntimeCompressionCombo = { - id: string; - pipeline: NonNullable; - languagePacks: string[]; - outputMode: boolean; - outputModeIntensity: string; - }; - const isBuiltinStackedPipeline = ( - pipeline: CompressionConfig["stackedPipeline"] | undefined - ): boolean => { - if (!Array.isArray(pipeline) || pipeline.length !== 2) return false; - const [first, second] = pipeline; - return ( - first?.engine === "rtk" && - (first.intensity === undefined || first.intensity === "standard") && - !first.config && - second?.engine === "caveman" && - (second.intensity === undefined || second.intensity === "full") && - !second.config - ); - }; const applyCompressionComboConfig = ( compressionCombo: RuntimeCompressionCombo | null, routingOverrideIds: string[] = [] @@ -987,14 +971,6 @@ export async function handleChatCore({ compressionComboApplied = true; return true; }; - const isStackedCompressionCombo = ( - compressionCombo: RuntimeCompressionCombo | null - ): compressionCombo is RuntimeCompressionCombo => { - // >= 1: a single-engine default combo (user enabled exactly one layer via the - // per-engine config page) must still apply. applyCompressionComboConfig already - // guards length === 0. - return Boolean(compressionCombo && compressionCombo.pipeline.length >= 1); - }; if (isCombo && comboName) { try { const { getComboByName } = await import("../../src/lib/localDb"); diff --git a/open-sse/handlers/chatCore/compressionComboPredicates.ts b/open-sse/handlers/chatCore/compressionComboPredicates.ts new file mode 100644 index 0000000000..d73b4324cb --- /dev/null +++ b/open-sse/handlers/chatCore/compressionComboPredicates.ts @@ -0,0 +1,41 @@ +/** + * chatCore compression-combo predicates (Quality Gate v2 / Fase 9 — chatCore god-file + * decomposition, #3501). + * + * Pure predicates extracted from handleChatCore's compression setup: detect the built-in + * RTK→caveman stacked pipeline and whether a runtime combo has at least one pipeline layer. + * No handler state is captured; behaviour is byte-identical to the previous inline closures. + */ + +import type { CompressionConfig } from "../../services/compression/types.ts"; + +export type RuntimeCompressionCombo = { + id: string; + pipeline: NonNullable; + languagePacks: string[]; + outputMode: boolean; + outputModeIntensity: string; +}; + +export function isBuiltinStackedPipeline( + pipeline: CompressionConfig["stackedPipeline"] | undefined +): boolean { + if (!Array.isArray(pipeline) || pipeline.length !== 2) return false; + const [first, second] = pipeline; + return ( + first?.engine === "rtk" && + (first.intensity === undefined || first.intensity === "standard") && + !first.config && + second?.engine === "caveman" && + (second.intensity === undefined || second.intensity === "full") && + !second.config + ); +} + +export function isStackedCompressionCombo( + compressionCombo: RuntimeCompressionCombo | null +): compressionCombo is RuntimeCompressionCombo { + // >= 1: a single-engine default combo (user enabled exactly one layer via the per-engine config + // page) must still apply. applyCompressionComboConfig already guards length === 0. + return Boolean(compressionCombo && compressionCombo.pipeline.length >= 1); +} diff --git a/tests/unit/chatcore-compression-combo-predicates.test.ts b/tests/unit/chatcore-compression-combo-predicates.test.ts new file mode 100644 index 0000000000..34fb88761d --- /dev/null +++ b/tests/unit/chatcore-compression-combo-predicates.test.ts @@ -0,0 +1,64 @@ +// Characterization of the pure compression-combo predicates extracted from handleChatCore's +// compression setup (chatCore god-file decomposition, #3501). No DB, no handler state. +import { test } from "node:test"; +import assert from "node:assert/strict"; + +const { isBuiltinStackedPipeline, isStackedCompressionCombo } = await import( + "../../open-sse/handlers/chatCore/compressionComboPredicates.ts" +); + +test("isBuiltinStackedPipeline true only for the rtk(standard)→caveman(full) shape", () => { + assert.equal( + isBuiltinStackedPipeline([{ engine: "rtk" }, { engine: "caveman" }] as never), + true + ); + assert.equal( + isBuiltinStackedPipeline([ + { engine: "rtk", intensity: "standard" }, + { engine: "caveman", intensity: "full" }, + ] as never), + true + ); +}); + +test("isBuiltinStackedPipeline false for wrong length / engines / intensities / config", () => { + assert.equal(isBuiltinStackedPipeline(undefined), false); + assert.equal(isBuiltinStackedPipeline([] as never), false); + assert.equal(isBuiltinStackedPipeline([{ engine: "rtk" }] as never), false); + assert.equal( + isBuiltinStackedPipeline([{ engine: "caveman" }, { engine: "rtk" }] as never), + false + ); + assert.equal( + isBuiltinStackedPipeline([ + { engine: "rtk", intensity: "aggressive" }, + { engine: "caveman", intensity: "full" }, + ] as never), + false + ); + assert.equal( + isBuiltinStackedPipeline([ + { engine: "rtk", config: { x: 1 } }, + { engine: "caveman" }, + ] as never), + false + ); +}); + +test("isStackedCompressionCombo true when the combo has >= 1 pipeline layer", () => { + assert.equal(isStackedCompressionCombo(null), false); + assert.equal( + isStackedCompressionCombo({ id: "c", pipeline: [], languagePacks: [], outputMode: false, outputModeIntensity: "full" } as never), + false + ); + assert.equal( + isStackedCompressionCombo({ + id: "c", + pipeline: [{ engine: "rtk" }], + languagePacks: [], + outputMode: false, + outputModeIntensity: "full", + } as never), + true + ); +});