Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
refactor(domain): map validation taxonomies and add inventory Result seam (#833)
morluto78f4848d70ce
diff --git a/src/domain/artifactInventoryEvidence.ts b/src/domain/artifactInventoryEvidence.tsindex 0266a0d97..efa459ebb 100644--- a/src/domain/artifactInventoryEvidence.ts+++ b/src/domain/artifactInventoryEvidence.ts@@ -8,6 +8,7 @@ import {import { canonicalDigest, canonicalJson } from "./comparisonSemantics.js";import { parseEvidence, type Evidence } from "./evidence.js";import { artifactInspectionResultSchema } from "./artifactInspection.js";+import { err, ok, type Result } from "./result.js";/** Complete or partially assembled inventory used by comparison workflows. */export interface InventorySet {@@ -20,7 +21,7 @@ export interface InventorySet {readonly complete: boolean;}-interface ParsedInventorySet {+export interface ParsedInventorySet {readonly evidence: readonly Evidence[];readonly inventory: InventorySet;}@@ -85,14 +86,36 @@ const validateInventoryPage = (inventory: ArtifactInventoryResult): void => {throw new TypeError("Artifact node ID is not content-addressed");};+/** Empty-inventory failure, distinct from malformed/unsupported/unavailable taxonomy codes. */+export interface InventoryAssemblyEmpty {+ readonly code: "empty";+ readonly message: string;+}++/**+ * Result-returning seam for the empty-pages leaf. Other assembly failures+ * still throw TypeError (migration in progress); parseArtifactInventoryEvidence+ * keeps its throwing contract until callers switch.+ */+export const tryAssembleInventorySet = (+ pages: readonly {+ readonly evidence: Evidence;+ readonly inventory: ArtifactInventoryResult;+ }[],+): Result<ParsedInventorySet, InventoryAssemblyEmpty> =>+ pages.length === 0+ ? err({+ code: "empty",+ message: "Artifact inventory requires Evidence pages",+ })+ : ok(assembleInventorySet(pages));+const assembleInventorySet = (pages: readonly {readonly evidence: Evidence;readonly inventory: ArtifactInventoryResult;}[],): ParsedInventorySet => {- if (pages.length === 0)- throw new TypeError("Artifact inventory requires Evidence pages");const first = pages[0];if (first === undefined)throw new TypeError("Artifact inventory requires Evidence pages");diff --git a/src/domain/validationTaxonomy.test.ts b/src/domain/validationTaxonomy.test.tsnew file mode 100644index 000000000..4407f8097--- /dev/null+++ b/src/domain/validationTaxonomy.test.ts@@ -0,0 +1,60 @@+import { describe, expect, it } from "vitest";++import {+ parseArtifactInventoryEvidence,+ tryAssembleInventorySet,+} from "./artifactInventoryEvidence.js";+import { EvidenceReferenceError } from "./evidenceErrors.js";+import type { ReferenceSourceReaderError } from "../reference/ReferenceSourceReaderTypes.js";++/**+ * The three validation taxonomies and their disjoint codes:+ * - Filesystem reader: cancelled | invalid-root | io | unsupported+ * (per-entry: cancelled | changed | io | symlink | unsupported).+ * - Session evidence references: missing | wrong_operation |+ * wrong_predicate | identity_mismatch.+ * - Inventory assembly: TypeError strings, migrating to Result leaves+ * starting with the empty-pages code below.+ */+const readerCodes: readonly ReferenceSourceReaderError["code"][] = [+ "cancelled",+ "invalid-root",+ "io",+ "unsupported",+];++const referenceReasons = (+ [+ "missing",+ "wrong_operation",+ "wrong_predicate",+ "identity_mismatch",+ ] as const+).map(+ (reason) =>+ new EvidenceReferenceError("ev_test", reason, "expected", null).reason,+);++describe("validation taxonomy mapping", () => {+ it("keeps session reference reasons disjoint from reader codes", () => {+ for (const reason of referenceReasons)+ expect(readerCodes).not.toContain(reason);+ });++ it("returns the empty-pages leaf as Result without throwing", () => {+ const result = tryAssembleInventorySet([]);+ expect(result).toEqual({+ ok: false,+ error: {+ code: "empty",+ message: "Artifact inventory requires Evidence pages",+ },+ });+ });++ it("keeps the throwing entry contract for empty input", () => {+ expect(() => parseArtifactInventoryEvidence([])).toThrowError(+ "Artifact inventory requires Evidence pages",+ );+ });+});