mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-04 14:22:09 +03:00
v3.8.40 cycle integration → main. All test gates green (Unit/Integration/Coverage/Node-compat/Quality-Ratchet). The only red check, 'PR Test Policy', is the test-masking heuristic firing on the cumulative ~57-commit release diff (legitimate assert consolidations already reviewed per-PR — Gemini CLI removal #5246, retired GPT models #5280, provider catalog refreshes); overridden with --admin per the documented release-PR convention. CodeQL/SonarQube advisory scans non-blocking; #5278's code already passed CodeQL on main. Homologated on VPS 192.168.0.15 (v3.8.40 healthy).
45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import type { CompressionResult } from "../types.ts";
|
|
import type { CompressionConfig } from "../types.ts";
|
|
import { applyRiskMask, restoreRiskBlocks } from "./riskGateStep.ts";
|
|
import type { RiskGateConfig } from "./riskGate.ts";
|
|
|
|
/** Resolve the effective risk-gate config (explicit option wins over config); enabled-gated. */
|
|
export function resolveRiskGate(options?: {
|
|
riskGate?: RiskGateConfig;
|
|
config?: CompressionConfig;
|
|
}): RiskGateConfig | undefined {
|
|
const rg = options?.riskGate ?? options?.config?.riskGate;
|
|
return rg?.enabled ? rg : undefined;
|
|
}
|
|
|
|
function attach(
|
|
result: CompressionResult,
|
|
mask: ReturnType<typeof applyRiskMask>
|
|
): CompressionResult {
|
|
if (mask.blocks.length) result.body = restoreRiskBlocks(result.body, mask.blocks);
|
|
if (result.stats) result.stats.riskGate = mask.stats;
|
|
return result;
|
|
}
|
|
|
|
/** Outer mask→run→restore wrapper for a sync compression entry point. Byte-identical when gate absent. */
|
|
export function withRiskGate(
|
|
body: Record<string, unknown>,
|
|
riskGate: RiskGateConfig | undefined,
|
|
run: (b: Record<string, unknown>) => CompressionResult
|
|
): CompressionResult {
|
|
if (!riskGate) return run(body);
|
|
const mask = applyRiskMask(body, riskGate);
|
|
return attach(run(mask.maskedBody), mask);
|
|
}
|
|
|
|
/** Async variant of withRiskGate. */
|
|
export async function withRiskGateAsync(
|
|
body: Record<string, unknown>,
|
|
riskGate: RiskGateConfig | undefined,
|
|
run: (b: Record<string, unknown>) => Promise<CompressionResult>
|
|
): Promise<CompressionResult> {
|
|
if (!riskGate) return run(body);
|
|
const mask = applyRiskMask(body, riskGate);
|
|
return attach(await run(mask.maskedBody), mask);
|
|
}
|