Files
reverse-engineering-anything/tests/boundary/cli/cliEvidenceCallerPath.test.ts
T
morluto 352a846127 test: reduce brittle assertions and test-only runtime paths (#9289)
* test: focus assertions on behavioral evidence

Prune redundant and wording-coupled checks while retaining diagnostic, parser, recovery, and cleanup coverage.

* refactor: remove test-only wrappers and duplicate checks

Exercise production operations through test fixtures, remove unused adapters, and keep managed-member uncertainty guidance under its existing owner.

* test: focus process validation on diagnostic facts

* refactor: remove test-only runtime helpers

Move semantic evidence fixture setup out of runtime and remove unused Windows settle recovery helpers while checking configured defaults independently.

* test: focus artifact diagnostics on format facts

* test: verify retained cleanup guidance delivery
2026-11-08 02:02:31 +08:00

120 lines
3.6 KiB
TypeScript

import { expect, it } from "vitest";
import { createEvidence } from "../../../src/domain/evidence.js";
import { err, ok } from "../../../src/domain/result.js";
import { AnalysisCancelledError } from "../../../src/domain/analysisErrorCore.js";
import { finishAnalysisCommand } from "../../../src/cli/finishAnalysisCommand.js";
import {
bindCliEvidenceCallerPath,
finishCliEvidenceCommand,
} from "../../../src/cli/cliEvidenceCallerPath.js";
it("retains the original file selection when final cleanup fails", async () => {
const evidence = createEvidence(
{ path: "/tmp/selected", sha256: "a".repeat(64), format: "file" },
{ id: "test", name: "Test", version: "1" },
{ operation: "inspect", parameters: {}, result: null },
);
const result = await finishCliEvidenceCommand(
"./selected",
async () => ok(evidence),
{
close: async () => {
throw new Error("cleanup failed");
},
},
"test",
"inspect",
new AbortController().signal,
);
if (result.ok) throw new Error("Expected cleanup failure");
expect(result.error).toMatchObject({
code: "cleanup_incomplete",
details: {
partial_observation: {
evidence_id: evidence.evidence_id,
caller_input_path: "./selected",
},
},
});
expect(evidence).not.toHaveProperty("caller_input_path");
});
it("binds authenticated partial Evidence but preserves raw partial observations", async () => {
const evidence = createEvidence(
{ path: "/tmp/selected", sha256: "a".repeat(64), format: "file" },
{ id: "test", name: "Test", version: "1" },
{ operation: "inspect", parameters: {}, result: null },
);
for (const [partial, expected] of [
[
evidence,
{ evidence_id: evidence.evidence_id, caller_input_path: "./selected" },
],
[
{
kind: "file-snapshot-hash",
path: "/tmp/selected",
sha256: "a".repeat(64),
bytes: 1,
},
{
kind: "file-snapshot-hash",
path: "/tmp/selected",
sha256: "a".repeat(64),
bytes: 1,
},
],
] as const) {
const result = await finishCliEvidenceCommand(
"./selected",
async () =>
err(
new AnalysisCancelledError("inspect", {
partialObservation: partial,
}),
),
{ close: async () => {} },
"test",
"inspect",
new AbortController().signal,
);
if (result.ok) throw new Error("Expected cancellation");
expect(result.error.details?.partial_observation).toMatchObject(expected);
if ("kind" in expected)
expect(result.error.details?.partial_observation).toEqual(expected);
}
});
it("preserves both direct input spellings when final cleanup fails", async () => {
const evidence = createEvidence(
{ path: "/tmp/schema", sha256: "a".repeat(64), format: "file" },
{ id: "test", name: "Test", version: "1" },
{ operation: "inspect", parameters: {}, result: null },
);
const result = await finishAnalysisCommand(
bindCliEvidenceCallerPath("./schema", async () => ok(evidence), {
operations_path: "./queries 雪.graphql",
}),
{
close: async () => {
throw new Error("cleanup failed");
},
},
"test",
"inspect",
new AbortController().signal,
);
if (result.ok) throw new Error("Expected cleanup failure");
expect(result.error).toMatchObject({
code: "cleanup_incomplete",
details: {
partial_observation: {
evidence_id: evidence.evidence_id,
caller_input_path: "./schema",
caller_input_paths: { operations_path: "./queries 雪.graphql" },
},
},
});
});