fix(evidence): normalize unknown revisions and preserve mutation intent (#1733)
Normalize generated revision fields before hashing and retain complete typed creation/update requests in a shared mutation Evidence producer. Keep imported revision authentication and canonical persisted identity/digests unchanged. Fixes #1723 Fixes #1724 Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)
This commit is contained in:
@@ -7,6 +7,10 @@ import {
|
||||
import { InvestigationRecords } from "./investigation/InvestigationRecords.js";
|
||||
import { UnknownRegistryError } from "../domain/unknownRegistryError.js";
|
||||
import { err } from "../domain/result.js";
|
||||
import { nativeApiBoundarySchema } from "../domain/native/nativeApiBoundary.js";
|
||||
import { projectNativeApiInspection } from "./native/NativeApiInspection.js";
|
||||
import { functionDossierSchema } from "../domain/hopperValues.js";
|
||||
import { ghidraFunctionDossier } from "../domain/ghidraValues.fixture.js";
|
||||
|
||||
describe("workflow residual question retention", () => {
|
||||
it("keeps questions linked to workflow Evidence and records repeats idempotently", () => {
|
||||
@@ -54,3 +58,47 @@ describe("workflow residual question retention", () => {
|
||||
).toEqual(err(error));
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
" Which boundary? ",
|
||||
"\nWhich boundary?\t",
|
||||
"\uFEFFWhich boundary?\uFEFF",
|
||||
])(
|
||||
"retains contract-accepted question %j without rewriting workflow Evidence",
|
||||
(question) => {
|
||||
const boundary = nativeApiBoundarySchema.parse({
|
||||
available: false,
|
||||
reason: "Synthetic provider unavailable boundary",
|
||||
residual_unknowns: [question],
|
||||
});
|
||||
const dossier = functionDossierSchema.parse(ghidraFunctionDossier());
|
||||
const result = projectNativeApiInspection({
|
||||
...dossier,
|
||||
native_api: boundary,
|
||||
});
|
||||
const evidence = createWorkflowEvidence({
|
||||
target: undefined,
|
||||
operation: "inspect_native_api",
|
||||
parameters: { procedure: "0x1000" },
|
||||
result,
|
||||
upstreamProfile: undefined,
|
||||
});
|
||||
const records = new InvestigationRecords();
|
||||
expect(records.recordEvidence(evidence).ok).toBe(true);
|
||||
expect(
|
||||
recordWorkflowUnknowns({
|
||||
name: "inspect_native_api",
|
||||
result,
|
||||
evidenceId: evidence.evidence_id,
|
||||
recordUnknown: (input) => records.recordUnknown(input),
|
||||
}).ok,
|
||||
).toBe(true);
|
||||
expect(records.listUnknowns()).toMatchObject([
|
||||
{ question: "Which boundary?" },
|
||||
]);
|
||||
expect(records.evidenceById(evidence.evidence_id)).toEqual(evidence);
|
||||
expect(evidence.normalized_result).toMatchObject({
|
||||
residual_unknowns: [question],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
@@ -61,7 +61,10 @@ describe("investigation record ownership", () => {
|
||||
value: {
|
||||
scope_digest: target.sha256,
|
||||
mutation_evidence_ids: [
|
||||
unknownMutationEvidence(target, input).evidence_id,
|
||||
unknownMutationEvidence(target, {
|
||||
operation: "record_unknown",
|
||||
input,
|
||||
}).evidence_id,
|
||||
],
|
||||
},
|
||||
});
|
||||
@@ -71,14 +74,19 @@ describe("investigation record ownership", () => {
|
||||
value: {
|
||||
scope_digest: null,
|
||||
mutation_evidence_ids: [
|
||||
unknownMutationEvidence(undefined, input).evidence_id,
|
||||
unknownMutationEvidence(undefined, {
|
||||
operation: "record_unknown",
|
||||
input,
|
||||
}).evidence_id,
|
||||
],
|
||||
},
|
||||
});
|
||||
const mutation = records.evidenceById(
|
||||
unknownMutationEvidence(undefined, input).evidence_id,
|
||||
unknownMutationEvidence(undefined, { operation: "record_unknown", input })
|
||||
.evidence_id,
|
||||
);
|
||||
expect(mutation?.subject).toBeNull();
|
||||
expect(mutation?.parameters).toEqual(input);
|
||||
expect(records.listUnknowns()).toHaveLength(2);
|
||||
});
|
||||
|
||||
@@ -124,6 +132,10 @@ describe("investigation record ownership", () => {
|
||||
bundle.records.find(({ operation }) => operation === "update_unknown")
|
||||
?.subject?.digest.sha256,
|
||||
).toBe(target.sha256);
|
||||
expect(
|
||||
bundle.records.find(({ operation }) => operation === "update_unknown")
|
||||
?.parameters,
|
||||
).toEqual(input);
|
||||
expect(records.updateUnknown(input, target).ok).toBe(false);
|
||||
expect(records.exportEvidenceBundle()).toEqual(bundle);
|
||||
});
|
||||
@@ -162,3 +174,59 @@ describe("investigation record ownership", () => {
|
||||
expect(records.exportEvidenceBundle()).toEqual(createEvidenceBundle([]));
|
||||
});
|
||||
});
|
||||
|
||||
it("retains complete mutation intent and distinguishes independent update requests", () => {
|
||||
const source = new InvestigationRecords();
|
||||
expect(source.recordEvidence(evidence).ok).toBe(true);
|
||||
const input = {
|
||||
...unknownInput("Which replay establishes the answer?"),
|
||||
supporting_evidence_ids: [evidence.evidence_id],
|
||||
required_environment: {
|
||||
id: "fixture",
|
||||
platform: "linux",
|
||||
architecture: "x86_64",
|
||||
isolation: "process" as const,
|
||||
},
|
||||
recommended_probes: [
|
||||
{ operation: "inspect_native_api", rationale: "Replay" },
|
||||
],
|
||||
};
|
||||
const created = source.recordUnknown(input);
|
||||
if (!created.ok) throw created.error;
|
||||
const base = source.exportEvidenceBundle();
|
||||
const creation = base.records.find(
|
||||
({ operation }) => operation === "record_unknown",
|
||||
);
|
||||
expect(creation?.parameters).toEqual(input);
|
||||
expect(creation?.evidence_links).toEqual([evidence.evidence_id]);
|
||||
|
||||
const { question: _question, domain: _domain, ...details } = input;
|
||||
const mutations = (["high", "low"] as const).map((severity) => {
|
||||
const records = new InvestigationRecords();
|
||||
expect(records.mergeEvidenceBundle(base).ok).toBe(true);
|
||||
const command = updateUnknownInputSchema.parse({
|
||||
...details,
|
||||
unknown_id: created.value.unknown_id,
|
||||
expected_revision: 1,
|
||||
status: "resolved",
|
||||
severity,
|
||||
resolution: {
|
||||
disposition: "withdrawn",
|
||||
rationale: "Caller withdrew this question",
|
||||
evidence_ids: [evidence.evidence_id],
|
||||
},
|
||||
});
|
||||
const updated = records.updateUnknown(command);
|
||||
if (!updated.ok) throw updated.error;
|
||||
const mutation = records
|
||||
.exportEvidenceBundle()
|
||||
.records.find(({ operation }) => operation === "update_unknown");
|
||||
expect(mutation?.parameters).toEqual(command);
|
||||
expect(mutation?.evidence_links).toEqual([evidence.evidence_id]);
|
||||
expect(updated.value.mutation_evidence_ids).toContain(
|
||||
mutation?.evidence_id,
|
||||
);
|
||||
return mutation;
|
||||
});
|
||||
expect(mutations[0]?.evidence_id).not.toBe(mutations[1]?.evidence_id);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { BinaryTarget } from "../../domain/binaryTargetTypes.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import type { EvidenceBundle } from "../../domain/evidenceBundle.js";
|
||||
import type { EvidenceIntegrityError } from "../../domain/evidenceErrors.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
@@ -12,11 +12,7 @@ import type {
|
||||
} from "../../domain/residualUnknown.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { EvidenceLedger, type EvidenceImportDelta } from "./EvidenceLedger.js";
|
||||
import {
|
||||
UNKNOWN_REGISTRY_PROVIDER,
|
||||
unknownEvidenceLinks,
|
||||
unknownMutationEvidence,
|
||||
} from "./UnknownEvidence.js";
|
||||
import { unknownMutationEvidence } from "./UnknownEvidence.js";
|
||||
import type {
|
||||
EvidenceReader,
|
||||
EvidenceWriter,
|
||||
@@ -83,11 +79,10 @@ export class InvestigationRecords
|
||||
input: RecordUnknownInput,
|
||||
target?: BinaryTarget,
|
||||
): Result<ResidualUnknown, AnalysisError> {
|
||||
const recorded = this.#evidence.recordUnknown(
|
||||
return this.#evidence.recordUnknown(
|
||||
input,
|
||||
unknownMutationEvidence(target, input),
|
||||
unknownMutationEvidence(target, { operation: "record_unknown", input }),
|
||||
);
|
||||
return recorded;
|
||||
}
|
||||
|
||||
/** Commit derived Evidence and its Unknown atomically without an implicit subject. */
|
||||
@@ -95,12 +90,14 @@ export class InvestigationRecords
|
||||
evidence: Evidence,
|
||||
input: RecordUnknownInput,
|
||||
): Result<ResidualUnknown | null, AnalysisError> {
|
||||
const recorded = this.#evidence.recordWithUnknown(
|
||||
return this.#evidence.recordWithUnknown(
|
||||
evidence,
|
||||
input,
|
||||
unknownMutationEvidence(undefined, input),
|
||||
unknownMutationEvidence(undefined, {
|
||||
operation: "record_unknown",
|
||||
input,
|
||||
}),
|
||||
);
|
||||
return recorded;
|
||||
}
|
||||
|
||||
/** Update an optimistic revision with an explicitly supplied Evidence subject. */
|
||||
@@ -108,23 +105,11 @@ export class InvestigationRecords
|
||||
input: UpdateUnknownInput,
|
||||
target?: BinaryTarget,
|
||||
): Result<ResidualUnknown, AnalysisError> {
|
||||
const evidence = createEvidence(target, UNKNOWN_REGISTRY_PROVIDER, {
|
||||
predicateType: "rea.residual-unknown-mutation",
|
||||
const evidence = unknownMutationEvidence(target, {
|
||||
operation: "update_unknown",
|
||||
parameters: {
|
||||
unknown_id: input.unknown_id,
|
||||
expected_revision: input.expected_revision,
|
||||
},
|
||||
result: { action: "update", status: input.status },
|
||||
confidence: "derived",
|
||||
authority: "analyst-inference",
|
||||
evidenceLinks: unknownEvidenceLinks(input),
|
||||
limitations: [
|
||||
"Registry mutation evidence records analyst intent, not proof of the answer.",
|
||||
],
|
||||
input,
|
||||
});
|
||||
const updated = this.#evidence.updateUnknown(input, evidence);
|
||||
return updated;
|
||||
return this.#evidence.updateUnknown(input, evidence);
|
||||
}
|
||||
|
||||
/** Return detached current Unknown revisions matching the selected filters. */
|
||||
|
||||
@@ -7,43 +7,54 @@ import type {
|
||||
import type { ProviderIdentity } from "../AnalysisProvider.js";
|
||||
|
||||
/** Provider identity for analyst-authored residual-unknown mutations. */
|
||||
export const UNKNOWN_REGISTRY_PROVIDER: ProviderIdentity = {
|
||||
const UNKNOWN_REGISTRY_PROVIDER: ProviderIdentity = {
|
||||
id: "rea-unknown-registry",
|
||||
name: "REA residual unknown registry",
|
||||
version: "1",
|
||||
};
|
||||
|
||||
type UnknownMutation =
|
||||
| { readonly operation: "record_unknown"; readonly input: RecordUnknownInput }
|
||||
| {
|
||||
readonly operation: "update_unknown";
|
||||
readonly input: UpdateUnknownInput;
|
||||
};
|
||||
|
||||
/** Create immutable evidence for one approved residual-unknown mutation. */
|
||||
export const unknownMutationEvidence = (
|
||||
target: BinaryTarget | undefined,
|
||||
input: RecordUnknownInput,
|
||||
mutation: UnknownMutation,
|
||||
): Evidence =>
|
||||
createEvidence(target, UNKNOWN_REGISTRY_PROVIDER, {
|
||||
predicateType: "rea.residual-unknown-mutation",
|
||||
operation: "record_unknown",
|
||||
parameters: { domain: input.domain, severity: input.severity },
|
||||
result: {
|
||||
action: "record",
|
||||
question: input.question,
|
||||
required_authority: input.required_authority,
|
||||
required_confidence: input.required_confidence,
|
||||
},
|
||||
operation: mutation.operation,
|
||||
parameters: { ...mutation.input },
|
||||
result:
|
||||
mutation.operation === "record_unknown"
|
||||
? {
|
||||
action: "record",
|
||||
question: mutation.input.question,
|
||||
required_authority: mutation.input.required_authority,
|
||||
required_confidence: mutation.input.required_confidence,
|
||||
}
|
||||
: { action: "update", status: mutation.input.status },
|
||||
confidence: "derived",
|
||||
authority: "analyst-inference",
|
||||
evidenceLinks: unknownEvidenceLinks(input),
|
||||
evidenceLinks: unknownEvidenceLinks(mutation.input),
|
||||
limitations: [
|
||||
"Registry mutation evidence records analyst intent, not proof of the answer.",
|
||||
],
|
||||
});
|
||||
|
||||
/** Deduplicate evidence links carried by an unknown mutation. */
|
||||
export const unknownEvidenceLinks = (
|
||||
const unknownEvidenceLinks = (
|
||||
input: RecordUnknownInput | UpdateUnknownInput,
|
||||
): string[] =>
|
||||
[
|
||||
): string[] => [
|
||||
...new Set([
|
||||
...input.supporting_evidence_ids,
|
||||
...input.contradicting_evidence_ids,
|
||||
...("resolution" in input && input.resolution !== null
|
||||
? input.resolution.evidence_ids
|
||||
: []),
|
||||
].filter((id, index, values) => values.indexOf(id) === index);
|
||||
]),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user