Files
Nathan Nguyen 6790e3431f feat(cache): add static layout proof and variant budget guardrails (#1288)
* feat(cache): add disabled static layout reuse proof

Static layout cache artifacts can already carry render observations, but the cache proof model could not prove or reject static layout reuse independently of cache serving. That left private, dynamic, and incomplete observations covered only by downgrade classification, not by the reusable artifact boundary.

The missing invariant was that a reusable layout needs positive layout/root/boundary proof and negative request API proof before any future cache authority can consume it.

Add a disabled static layout proof evaluator with rejection trace codes for mismatched layout output, unknown root boundaries, private variant dimensions, private/dynamic observations, and missing or observed request APIs. Keep runtime cache reuse disabled by carrying the proof only on the disabled decision.

* feat(cache): enforce route variant budget fallback

Cache variant construction previously had a lossy scalar route count, so callers could not distinguish a duplicate admissible variant from a genuinely new variant that would exceed the route ceiling.

That violated the #726 cache proof invariant that variant cardinality must have an owned breaker path. Route budget admission now tracks canonical variant keys per route, allows duplicate variants without consuming budget, and returns structured breaker fallbacks for route mismatches or over-ceiling variants.

Tests cover duplicate admission, second distinct admission, and the over-budget breaker fallback for #726-CACHE-10.

* fix(cache): derive static layout proof authority

* docs(cache): clarify static proof evidence copy

* perf(cache): binary-search route variant keys

* refactor(cache): move sorted key search to utils

* test(cache): cover static proof boundary mismatch
2026-05-18 11:09:36 +01:00

22 lines
1.0 KiB
TypeScript

import { describe, expect, it } from "vite-plus/test";
import { findSortedStringPosition } from "../packages/vinext/src/utils/sorted-array.js";
describe("sorted array utilities", () => {
it("finds existing sorted string positions", () => {
const values = ["alpha", "bravo", "charlie", "delta"];
expect(findSortedStringPosition(values, "alpha")).toEqual({ found: true, index: 0 });
expect(findSortedStringPosition(values, "charlie")).toEqual({ found: true, index: 2 });
expect(findSortedStringPosition(values, "delta")).toEqual({ found: true, index: 3 });
});
it("returns insertion positions for missing sorted strings", () => {
const values = ["bravo", "delta"];
expect(findSortedStringPosition([], "alpha")).toEqual({ found: false, index: 0 });
expect(findSortedStringPosition(values, "alpha")).toEqual({ found: false, index: 0 });
expect(findSortedStringPosition(values, "charlie")).toEqual({ found: false, index: 1 });
expect(findSortedStringPosition(values, "echo")).toEqual({ found: false, index: 2 });
});
});