perf(analysis-view): reuse validated immutable parents

Reuse successful format validation for exact authenticated immutable native and imported JavaScript results. Preserve schema normalization and alias topology before borrowing source data; owned JavaScript graph wrappers retain their existing metadata-normalization path.

Validated with 130 source tests, 36 compiled CLI/MCP boundary tests, 27 default-deadline integration tests, full checks/docs/build, and paired real retained-Evidence tasks. The report preserves cold costs, previous negative results, incomplete resource-stopped runs, and the limits of offline token estimates.

Fixes #4810

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
This commit is contained in:
Ysopwnable
2026-10-18 14:38:00 +08:00
committed by GitHub
parent b83b9caf4a
commit 8f7d12e30d
13 changed files with 1473 additions and 22 deletions
@@ -56,6 +56,101 @@ const issuesFrom = (action: () => unknown) => {
throw new Error("Expected complete result validation to reject the input");
};
describe("immutable JavaScript result reuse", () => {
it("preserves parser copies shared across owned graphs and result metadata", () => {
const owned = ownedExample();
const input = freezeJsonSnapshot({
...owned,
limitations: owned.graph.limitations,
});
for (let repeat = 0; repeat < 2; repeat += 1) {
const parsed = complete(
parseOwnedJavaScriptApplicationAnalysisSteps(input),
);
expect(parsed).not.toBe(input);
expect(parsed.graph).toBe(input.graph);
expect(parsed.limitations).toEqual(input.graph.limitations);
expect(parsed.limitations).not.toBe(parsed.graph.limitations);
}
});
it.each(["hidden-extra", "changed-enumerability"])(
"preserves parsed results when the source has %s normalization",
(kind) => {
const input = example();
if (kind === "hidden-extra")
Object.defineProperty(input, "not_in_parsed_result", {
value: { unvalidated: true },
enumerable: false,
});
else Object.defineProperty(input, "input_path", { enumerable: false });
freezeJsonSnapshot(input);
const expected = javascriptApplicationAnalysisResultSchema.parse(input);
for (let repeat = 0; repeat < 2; repeat += 1) {
const parsed = complete(
parseOwnedJavaScriptApplicationAnalysisSteps(input),
);
expect(parsed).not.toBe(input);
expect(Object.hasOwn(parsed, "not_in_parsed_result")).toBe(false);
expect(
Object.getOwnPropertyDescriptor(parsed, "input_path")?.enumerable,
).toBe(
Object.getOwnPropertyDescriptor(expected, "input_path")?.enumerable,
);
}
},
);
it("borrows imported immutable results only after complete format validation", () => {
const input = example();
delete input.statistics.skipped_javascript_files;
freezeJsonSnapshot(input);
const result = complete(
parseOwnedJavaScriptApplicationAnalysisSteps(input),
);
expect(result).toBe(input);
expect(result).toEqual(
javascriptApplicationAnalysisResultSchema.parse(input),
);
expect(result.statistics).not.toHaveProperty("skipped_javascript_files");
expect(complete(parseOwnedJavaScriptApplicationAnalysisSteps(input))).toBe(
input,
);
expect(Reflect.set(input.statistics, "findings", -1)).toBe(false);
});
it("preserves a normalized representation instead of borrowing changed input", () => {
const input = example();
Object.setPrototypeOf(input, null);
freezeJsonSnapshot(input);
for (let repeat = 0; repeat < 2; repeat += 1) {
const result = complete(
parseOwnedJavaScriptApplicationAnalysisSteps(input),
);
expect(result).not.toBe(input);
expect(Object.getPrototypeOf(result)).toBe(Object.prototype);
expect(result).toEqual(
javascriptApplicationAnalysisResultSchema.parse(input),
);
}
});
it.each(["mutable", "shallow-frozen"])(
"rechecks changed %s metadata despite authenticated nested graphs",
(kind) => {
const input = ownedExample();
if (kind === "shallow-frozen") Object.freeze(input);
expect(
complete(parseOwnedJavaScriptApplicationAnalysisSteps(input)),
).not.toBe(input);
input.statistics.findings = -1;
expect(() =>
complete(parseOwnedJavaScriptApplicationAnalysisSteps(input)),
).toThrow(z.ZodError);
},
);
});
describe("owned JavaScript graph validation", () => {
it("reuses exact sealed graphs and preserves all public result fields", () => {
const input = ownedExample();
@@ -239,6 +334,7 @@ describe("owned JavaScript result bindings", () => {
input.semantic_graph = complete(
createImmutableJavaScriptSemanticGraphSteps(semantic),
);
freezeJsonSnapshot(input);
const steps = parseOwnedJavaScriptApplicationAnalysisSteps(input);
expect(steps.next().done).toBe(false);
steps.return(input);