fix(process): preserve unknown filesystem absence in partial captures

Separate exhausted path enumeration from hash coverage and preserve known
effects outside incomplete roots or unfollowed symlink subtrees. Return
explicit unknown effects through capture Evidence and comparison workflows.

Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
This commit is contained in:
Ysopwnable
2026-10-09 12:09:24 +00:00
committed by GitHub
parent 4578647c59
commit c8544b1574
11 changed files with 402 additions and 29 deletions
@@ -2,19 +2,71 @@ import type {
FileState,
FilesystemCheckpoint,
} from "../../domain/process/processCapture.js";
import { sep } from "node:path";
import type { SnapshotResult } from "./FilesystemSnapshot.js";
/** Classify path-stable filesystem effects between two bounded states. */
const unobservedAbsenceReason = (
path: string,
phase: "before" | "after",
completeRoots: ReadonlySet<string>,
filesByPath: ReadonlyMap<string, FileState>,
): string | undefined => {
const alias = path.slice(0, path.indexOf(":"));
if (!completeRoots.has(alias))
return `The ${phase} snapshot did not exhaust path enumeration under ${alias}; absence remains unknown.`;
const rootPath = `${alias}:.`;
if (path !== rootPath && filesByPath.get(rootPath)?.type === "symlink")
return `The ${phase} snapshot did not follow the symbolic link at ${rootPath}; descendant absence remains unknown.`;
for (
let index = path.lastIndexOf(sep);
index > 0;
index = path.lastIndexOf(sep, index - 1)
) {
const parent = path.slice(0, index);
if (filesByPath.get(parent)?.type === "symlink")
return `The ${phase} snapshot did not follow the symbolic link at ${parent}; descendant absence remains unknown.`;
}
return undefined;
};
/** Classify effects only when a snapshot establishes the missing path's absence. */
export const classifyFilesystemEffects = (
before: readonly FileState[],
after: readonly FileState[],
before: SnapshotResult,
after: SnapshotResult,
): FilesystemCheckpoint["effects"] => {
const beforeByPath = new Map(before.map((file) => [file.path, file]));
const afterByPath = new Map(after.map((file) => [file.path, file]));
const beforeByPath = new Map(before.files.map((file) => [file.path, file]));
const afterByPath = new Map(after.files.map((file) => [file.path, file]));
const beforeCompleteRoots = new Set(before.completeRoots);
const afterCompleteRoots = new Set(after.completeRoots);
return [...new Set([...beforeByPath.keys(), ...afterByPath.keys()])]
.sort()
.map((path) => {
const beforeFile = beforeByPath.get(path) ?? null;
const afterFile = afterByPath.get(path) ?? null;
const reason =
beforeFile === null
? unobservedAbsenceReason(
path,
"before",
beforeCompleteRoots,
beforeByPath,
)
: afterFile === null
? unobservedAbsenceReason(
path,
"after",
afterCompleteRoots,
afterByPath,
)
: undefined;
if (reason !== undefined)
return {
path,
status: "unknown",
before: beforeFile,
after: afterFile,
reason,
} as const;
if (beforeFile === null) {
if (afterFile === null)
throw new TypeError(`Filesystem effect ${path} has no file state`);