refactor(javascript): own coverage facts and reuse block prefixes

Separate syntax, semantic uncertainty, examination limits and observed Electron applicability at the static producer, then preserve them through worker, graph and retained/inline summary views. Derive the established parse_status from the same facts and leave historical measurements unknown. Give semantic resource-limit classifications one schema owner.

Replace repeated block-prefix searches and copies with collector-scoped syntax indexes. Keep invocation environments separate, charge indexing/replay to the existing work budget and yield during prefix work. Remove the superseded synchronous collector entrypoint.

Validated producer, worker, CLI/MCP, historical and partial-coverage regressions, plus actual cancellation during indexing. Bounded authored 128/256-call controls preserved all prior facts while replacing repeated search/copy work with one index pass; this is not a throughput or agent-token benchmark.
This commit is contained in:
morluto committed 2026-10-25 09:49:26 +08:00
1 parent c8269ca497
commit f62a2baad8
21 files changed
+898 -125

No files matched your search

@@ -0,0 +1,106 @@
import { expect, it } from "vitest";
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
import {
javaScriptStaticParseStatus,
unexaminedJavaScriptStaticCoverage,
} from "./javascriptStaticCoverage.js";
import { aliasSelectionBudgetSource } from "../../../tests/fixtures/javascriptAliasSelectionBudget.js";
it("separates dynamic semantic uncertainty from completed syntax and examination", () => {
const result = analyzeJavaScriptStaticSource(
"const {ipcMain}=require('electron'); ipcMain.on(channel, () => {});",
);
expect(result.parse_status).toBe("partial");
expect(result.analysis_coverage).toMatchObject({
syntax: { status: "complete", error_count: 0 },
semantics: { unknown_findings: 1, uncertainty: ["dynamic-findings"] },
examination: {
status: "complete",
semantic_resource_limits: [],
electron_call_paths_limited: false,
},
applicability: { electron: "observed" },
});
expect(result.electron.ipc).toMatchObject([
{ channel: null, channel_expression: "channel" },
]);
});
it("distinguishes recovered syntax from unparseable source without inventing an error total", () => {
const recovered = analyzeJavaScriptStaticSource("let value; let value;");
expect(recovered.parse_status).toBe("partial");
expect(recovered.analysis_coverage?.syntax).toEqual({
status: "recovered",
error_count: recovered.parse_error_count,
});
const failed = analyzeJavaScriptStaticSource("const value = ;");
expect(failed.parse_status).toBe("failed");
expect(failed.analysis_coverage).toMatchObject({
syntax: { status: "failed", error_count: null },
semantics: { unknown_findings: null },
examination: { status: "not-examined" },
});
});
it("keeps framework applicability unknown without positive Electron evidence", () => {
const ordinary = analyzeJavaScriptStaticSource("export const value = 1;");
expect(ordinary.parse_status).toBe("complete");
expect(ordinary.analysis_coverage?.applicability.electron).toBe("unknown");
const electron = analyzeJavaScriptStaticSource(
"const {ipcMain}=require('electron');",
);
expect(electron.analysis_coverage?.applicability.electron).toBe("observed");
});
it("reports compiler-dependent module side effects independently of complete syntax", () => {
const result = analyzeJavaScriptStaticSource(
"import { type Config } from './config';",
);
expect(result.analysis_coverage?.syntax).toEqual({
status: "complete",
error_count: 0,
});
expect(result.analysis_coverage?.semantics.uncertainty).toContain(
"type-only-module-side-effect",
);
});
it("retains typed examination limits alongside successfully parsed source", () => {
const result = analyzeJavaScriptStaticSource(aliasSelectionBudgetSource());
expect(result.parse_status).toBe("partial");
expect(result.analysis_coverage).toMatchObject({
syntax: { status: "complete", error_count: 0 },
examination: {
status: "limited",
semantic_resource_limits: ["alias-selections"],
},
});
});
it("preserves the legacy summary responsibility without relabeling independent limitations", () => {
const base = analyzeJavaScriptStaticSource(
"export const value = 1;",
).analysis_coverage!;
expect(
javaScriptStaticParseStatus({
...base,
semantics: {
unknown_findings: 0,
uncertainty: ["returned-reference-widening"],
},
examination: {
...base.examination,
status: "limited",
electron_call_paths_limited: true,
},
}),
).toBe("complete");
expect(
unexaminedJavaScriptStaticCoverage("Caller selected another source."),
).toMatchObject({
syntax: { status: "not-examined", error_count: null },
semantics: { unknown_findings: null },
examination: { status: "not-examined" },
unexamined_reason: "Caller selected another source.",
});
});