Files
reverse-engineering-anything/src/domain/analysisView/environmentStateWriteAttribution.test.ts
T
morluto 19b2972dfb fix(environment): separate request order from completion
Retain valid request starts independently of duration and require observed completion for interval-based state and write inferences. Bound indexed interference checks across captured writes while preserving ordinal fallback and unmodified Evidence.

Validated state, comparison, CLI and MCP workflows with known, unknown, overlapping and redacted timing controls; check:fast passed.
2026-10-27 05:08:14 +08:00

45 lines
1.4 KiB
TypeScript

import { expect, it } from "vitest";
import {
forgetChecked,
runningAt,
touchTarget,
WriteEffects,
type PendingTargets,
type TouchedTargets,
} from "./environmentStateWriteAttribution.js";
it("keeps an unknown write completion pending alongside later known completions", () => {
const touched: TouchedTargets = new Map();
const pending: PendingTargets = new Map();
for (const [index, end] of [undefined, 20].entries())
touchTarget(touched, pending, "entity", {
index,
tool: `write-${String(index)}`,
end,
fields: ["name"],
});
expect(runningAt(pending, "entity", 30)).toBe(true);
expect(runningAt(pending, "entity", undefined)).toBe(true);
expect(runningAt(pending, "absent", undefined)).toBe(false);
forgetChecked(
{ touched, since: pending, effects: new WriteEffects() },
"entity",
undefined,
);
expect(runningAt(pending, "entity", 30)).toBe(false);
});
it("requires a known read start to establish a known pending write completed", () => {
const touched: TouchedTargets = new Map();
const pending: PendingTargets = new Map();
touchTarget(touched, pending, "entity", {
index: 0,
tool: "write",
end: 20,
fields: ["name"],
});
expect(runningAt(pending, "entity", undefined)).toBe(true);
expect(runningAt(pending, "entity", 19)).toBe(true);
expect(runningAt(pending, "entity", 20)).toBe(false);
});