refactor!: enforce canonical evidence and provider boundaries

Deliver complete Evidence directly through MCP with required nullable analysis profiles and immutable per-server delivery settings. Bind selected environments at construction and require typed cleanup outcomes with retained retry ownership.

Remove test-only routing, duplicate session and snapshot metadata, producer-field repairs, and ambiguous provider arguments. Separate artifact byte identity from occurrence classification and retain typed source-map and partial native facts across CLI, MCP, and verifier consumers.

BREAKING CHANGE: obsolete Evidence envelopes, session aliases, incomplete snapshots, and missing normalized producer facts are no longer accepted.
This commit is contained in:
morluto
2026-10-09 20:18:52 +08:00
parent 2a7746998d
commit 63bf91405c
514 changed files with 9296 additions and 5825 deletions
+43
View File
@@ -0,0 +1,43 @@
import { expect, it } from "vitest";
import { snapshotEnvironment } from "./snapshotEnvironment.js";
it.each(["linux", "darwin"] as const)(
"preserves case-sensitive %s variables in an immutable snapshot",
(platform) => {
const selected = { PATH: "/chosen/bin", Path: "/other/bin" };
const snapshot = snapshotEnvironment(selected, platform);
selected.PATH = "/later/bin";
expect(snapshot).toEqual({ PATH: "/chosen/bin", Path: "/other/bin" });
expect(Object.isFrozen(snapshot)).toBe(true);
},
);
it("canonicalizes selected Windows variables without inheriting ambient values", () => {
const snapshot = snapshotEnvironment(
{ Path: "C:\\selected", ComSpec: "C:\\selected\\cmd.exe" },
"win32",
);
expect(snapshot).toEqual({
PATH: "C:\\selected",
COMSPEC: "C:\\selected\\cmd.exe",
});
expect(Object.isFrozen(snapshot)).toBe(true);
});
it("uses Node's first lexicographic Windows key even when it is undefined", () => {
expect(
snapshotEnvironment(
{
path: "lower",
Path: "mixed",
PATH: "upper",
ComSpec: "mixed-cmd",
COMSPEC: "upper-cmd",
Temp: "mixed-temp",
TEMP: undefined,
},
"win32",
),
).toEqual({ PATH: "upper", COMSPEC: "upper-cmd", TEMP: undefined });
});
+16
View File
@@ -0,0 +1,16 @@
/** Snapshot caller-selected variables using Node child-process key semantics. */
export const snapshotEnvironment = (
environment: Readonly<NodeJS.ProcessEnv>,
platform: NodeJS.Platform = process.platform,
): Readonly<NodeJS.ProcessEnv> => {
if (platform !== "win32") return Object.freeze({ ...environment });
const snapshot: NodeJS.ProcessEnv = {};
// Node sorts keys lexicographically and forwards the first case-insensitive
// match on Windows. Canonical keys also make subsequent lookups deterministic.
for (const key of Object.keys(environment).sort()) {
const canonicalKey = key.toUpperCase();
if (!Object.hasOwn(snapshot, canonicalKey))
snapshot[canonicalKey] = environment[key];
}
return Object.freeze(snapshot);
};