mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 17:44:27 +00:00
* test(adapters): compare CLI and MCP Evidence for every CLI analysis operation Run each official, workflow, native, artifact and managed operation that has a CLI command through the CLI command tree and the MCP server over one simulated provider, and require identical Evidence or failure. The differences main has today are recorded per operation so the W2 invoke path can only remove them. Split bindDirectAnalysis(dependencies) out of createDirectAnalysis so the CLI can run over injected session owners. * test(adapters): give each parity case its own CLI and MCP connection * refactor(evidence): build a completed provider operation's Evidence in one owner The CLI's DirectAnalysis and the MCP provider-operation handler each defaulted the subject, admitted the completed analysis and created the Evidence. completedOperationEvidence in SessionEvidenceReuse now does it for both, reusing the record the session issued for the same execution and parameters. The session-Evidence lookup is no longer exported. * test(evidence): deliver the record a one-shot Ghidra decompile session issued
132 lines
4.5 KiB
TypeScript
132 lines
4.5 KiB
TypeScript
import { evidenceSubjectDisplay } from "../../domain/evidence.js";
|
|
import { basename } from "node:path";
|
|
import type { AnalysisExecution } from "../../ports/AnalysisProvider.js";
|
|
import type { Evidence } from "../../domain/evidence.js";
|
|
import type { JsonValue } from "../../domain/jsonValue.js";
|
|
import { equalJsonText } from "../../domain/jsonSerialization.js";
|
|
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
|
import { createAnalysisExecutionEvidence } from "../../domain/analysisObservation.js";
|
|
import type { BinaryTarget } from "../../domain/binaryTargetTypes.js";
|
|
import { ok, type Result } from "../../domain/result.js";
|
|
import { admitCompletedAnalysis } from "../investigation/admitCompletedAnalysis.js";
|
|
import type { RecoveryAdmission } from "../investigation/InvestigationRetention.js";
|
|
|
|
// Proof belongs to the exact object issued by the session. A wrapper that
|
|
// copies or transforms the observation cannot carry it forward.
|
|
const issued = new WeakMap<AnalysisExecution, Evidence>();
|
|
|
|
export const bindSessionEvidenceExecution = (
|
|
execution: AnalysisExecution,
|
|
evidence: Evidence,
|
|
): AnalysisExecution => {
|
|
if (
|
|
(execution.sourceEvidence !== undefined &&
|
|
execution.sourceEvidence.length > 0) ||
|
|
evidence.caller_input_path !== undefined
|
|
)
|
|
return execution;
|
|
// Semantic IDs intentionally omit display paths and names. A duplicate in
|
|
// the ledger can therefore refer to the same bytes at a different path.
|
|
const selected = execution.subject;
|
|
const display = evidenceSubjectDisplay(evidence);
|
|
if (
|
|
selected == null
|
|
? display !== undefined
|
|
: display === undefined ||
|
|
display.local_path !== selected.path ||
|
|
display.name !== (basename(selected.path) || "artifact")
|
|
)
|
|
return execution;
|
|
const subject =
|
|
execution.subject === undefined || execution.subject === null
|
|
? execution.subject
|
|
: Object.freeze({ ...execution.subject });
|
|
const result = Object.freeze({
|
|
...execution,
|
|
result: evidence.normalized_result,
|
|
rawResult: evidence.raw_result,
|
|
provider: evidence.provider,
|
|
...(evidence.analysis_profile === null
|
|
? {}
|
|
: { analysisProfile: evidence.analysis_profile }),
|
|
limitations: evidence.limitations,
|
|
locations: evidence.locations,
|
|
...(evidence.relationship_coverage === null
|
|
? {}
|
|
: { relationshipCoverage: evidence.relationship_coverage }),
|
|
...(subject === undefined ? {} : { subject }),
|
|
});
|
|
issued.set(result, evidence);
|
|
return result;
|
|
};
|
|
|
|
const sessionEvidenceForExecution = (
|
|
execution: AnalysisExecution,
|
|
operation: string,
|
|
parameters: Readonly<Record<string, JsonValue>>,
|
|
lookup: (id: string) => Evidence | undefined,
|
|
): Evidence | undefined => {
|
|
const evidence = issued.get(execution);
|
|
if (
|
|
evidence === undefined ||
|
|
evidence.operation !== operation ||
|
|
lookup(evidence.evidence_id) !== evidence ||
|
|
!equalJsonText(evidence.parameters, parameters)
|
|
)
|
|
return undefined;
|
|
return evidence;
|
|
};
|
|
|
|
/** How one completed session execution becomes Evidence. */
|
|
export interface CompletedOperationEvidenceOptions {
|
|
/** The subject when the provider names none. */
|
|
readonly target: BinaryTarget | null;
|
|
readonly admitRecovery?: RecoveryAdmission | undefined;
|
|
/** The session's records, to reuse the record it issued for this call. */
|
|
readonly evidenceById?: ((id: string) => Evidence | undefined) | undefined;
|
|
}
|
|
|
|
/**
|
|
* The Evidence of one completed provider operation, built once for every
|
|
* adapter: the record the session issued for this exact execution and
|
|
* parameters when it holds one, else a new record admitted against the
|
|
* completed analysis.
|
|
*/
|
|
export const completedOperationEvidence = (
|
|
operation: string,
|
|
parameters: Readonly<Record<string, JsonValue>>,
|
|
execution: AnalysisExecution,
|
|
options: CompletedOperationEvidenceOptions,
|
|
): Result<Evidence, AnalysisError> => {
|
|
const reusable =
|
|
options.evidenceById === undefined
|
|
? undefined
|
|
: sessionEvidenceForExecution(
|
|
execution,
|
|
operation,
|
|
parameters,
|
|
options.evidenceById,
|
|
);
|
|
if (reusable !== undefined) return ok(reusable);
|
|
const observation = {
|
|
...execution,
|
|
subject:
|
|
execution.subject === undefined ? options.target : execution.subject,
|
|
};
|
|
const admitted = admitCompletedAnalysis(
|
|
operation,
|
|
parameters,
|
|
observation,
|
|
options.admitRecovery,
|
|
);
|
|
if (!admitted.ok) return admitted;
|
|
return ok(
|
|
createAnalysisExecutionEvidence(
|
|
operation,
|
|
parameters,
|
|
observation,
|
|
"observed",
|
|
),
|
|
);
|
|
};
|