mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 13:24:20 +00:00
* fix(errors)!: report wrong-format, missing-file and missing-Evidence refusals by their cause - inspect_labview_artifact refuses a file with no LabVIEW RSRC data as an unrecognized target (code unsupported_target, failure_kind unrecognized), as its format siblings do, instead of invalid_request. A PE whose resource tree could not be fully read is a malformed PE target. - inspect_gpu_code_objects, inspect_model_artifact and Apktool reported a missing or non-regular selected file through their own copy of the selected-file refusal (BinaryTargetError, target_unavailable). They now use the shared projectSelectedArtifactFileFailure owner (invalid_request, conforming, with its own next step), and the copy is removed. The shared owner keeps the verified-symlink recovery the copy carried. - A retained Evidence reference the session does not hold is invalid_request / invalid_input instead of evidence_integrity_mismatch. Altered or unauthenticated Evidence stays evidence_integrity_mismatch. BREAKING CHANGE: error codes change for three refusals. A non-LabVIEW file given to inspect_labview_artifact is unsupported_target (was invalid_request). A missing or non-regular selected file for inspect_gpu_code_objects, inspect_model_artifact or Apktool operations is invalid_request (was target_unavailable). A missing retained Evidence reference (details.reason "missing") is invalid_request with category invalid_input (was evidence_integrity_mismatch / integrity_mismatch). Callers that branch on these codes should match the new values; details.reason, retry_class and the remediation are unchanged in meaning. * test(model): expect the shared selected-file refusal for a missing model path The process-global host read failure test still expected target_unavailable for path errors on a model file. Those are now the shared selected-file input refusal. * fix(resources): name a rejected symlink in the shared selected-file refusal The GPU and model readers' copy of the selected-file refusal said the path was a symbolic link; the shared owner reported only ELOOP, so rejectedSymlinkRecovery failed once they moved to it. Use the rejected symlink's own message, and keep the errno message for every other selected-path refusal. * docs(errors): describe missing references and closure members as the caller's selection The comment above RESOURCE_SNAPSHOT_NOT_APPLICABLE still said a missing Evidence reference stays an integrity failure. Missing references, including retained sources and closure members, are invalid_request; only altered or unauthenticated Evidence stays an integrity failure.
148 lines
5.0 KiB
TypeScript
148 lines
5.0 KiB
TypeScript
import { noProviderEffects } from "../../fixtures/analysisExecution.js";
|
|
import { createCommandCli } from "../../support/cli/commandCli.js";
|
|
import { unknownTarget } from "../../../src/domain/targetIdentity.js";
|
|
import { readFile, stat, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import pino from "pino";
|
|
import { expect, it } from "vitest";
|
|
import {
|
|
createAnalysisExecution,
|
|
type AnalysisProvider,
|
|
} from "../../../src/ports/AnalysisProvider.js";
|
|
import { runDirectAnalysis } from "../../../src/application/DirectAnalysis.js";
|
|
import type { DirectAnalysisDependencies } from "../../../src/application/DirectAnalysisDependencies.js";
|
|
import { registerCoreNativeCommands } from "../../../src/cli/coreNativeCommands.js";
|
|
import { parseConfig } from "../../../src/config/parseConfig.js";
|
|
import { createAnalysisProfile } from "../../../src/domain/analysisProfile.js";
|
|
import { createEvidence } from "../../../src/domain/evidence.js";
|
|
import { parseEvidenceBundle } from "../../../src/domain/evidenceBundle.js";
|
|
import { ok } from "../../../src/domain/result.js";
|
|
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
const identity = { id: "fixture", name: "Fixture", version: "1" } as const;
|
|
const effects = noProviderEffects();
|
|
const procedure = {
|
|
address: "0x1000",
|
|
name: "selected",
|
|
classification: null,
|
|
body: { available: false as const, reason: "unavailable" },
|
|
};
|
|
const result = {
|
|
procedure,
|
|
direction: "incoming" as const,
|
|
reference_kinds_available: false,
|
|
references: [],
|
|
unresolved_calls: [{ address: "0x1010", reason: "unknown target" }],
|
|
};
|
|
|
|
it.each([false, true])(
|
|
"exports linked source Evidence or refuses missing closure (missing=%s)",
|
|
async (missing) => {
|
|
const root = await createTestTempDirectory("rea-procedure-references-cli-");
|
|
const path = join(root, "fixture.hop"),
|
|
output = join(root, "evidence.json");
|
|
await writeFile(path, "synthetic analysis database");
|
|
const history = createEvidence(unknownTarget("not-observed"), identity, {
|
|
operation: "health",
|
|
parameters: {},
|
|
result: "project history",
|
|
...(missing ? { evidenceLinks: ["ev_" + "a".repeat(64)] } : {}),
|
|
});
|
|
const provider: AnalysisProvider = {
|
|
identity: () => identity,
|
|
capabilities: () => [
|
|
{
|
|
provider: identity,
|
|
operation: "procedure_references",
|
|
available: true,
|
|
reason: null,
|
|
cachePolicy: "live",
|
|
limitations: [],
|
|
effects,
|
|
},
|
|
],
|
|
resolveAnalysisProfile: async () =>
|
|
ok({ profile: createAnalysisProfile(identity, { fixture: true }) }),
|
|
createClient: () => ({
|
|
execute: async () =>
|
|
ok(
|
|
createAnalysisExecution(result, identity, {
|
|
sourceEvidence: [history],
|
|
}),
|
|
),
|
|
close: async () => ok(null),
|
|
}),
|
|
};
|
|
const createSession = () => createTestBinarySession(provider);
|
|
const dependencies: DirectAnalysisDependencies = {
|
|
readConfiguration: () => parseConfig({}),
|
|
createBinarySession: createSession,
|
|
createNativeDispatchBinarySession: createSession,
|
|
createArtifactBinarySession: createSession,
|
|
createNativeBinarySession: createSession,
|
|
createManagedBinarySession: createSession,
|
|
};
|
|
const cli = createCommandCli();
|
|
registerCoreNativeCommands(
|
|
cli,
|
|
pino({ enabled: false }),
|
|
(target, tool, args, options) =>
|
|
runDirectAnalysis(dependencies, target, tool, args, options),
|
|
);
|
|
let stdout = "";
|
|
await cli.serve(
|
|
[
|
|
"procedure-references",
|
|
path,
|
|
"selected",
|
|
"--provider",
|
|
"fixture",
|
|
"--direction",
|
|
"incoming",
|
|
"--detail",
|
|
"summary",
|
|
"--evidence_output",
|
|
output,
|
|
"--json",
|
|
],
|
|
{
|
|
env: {},
|
|
stdout: (text) => {
|
|
stdout += text;
|
|
},
|
|
exit: () => undefined,
|
|
},
|
|
);
|
|
const response = JSON.parse(stdout);
|
|
if (missing) {
|
|
expect(response).toMatchObject({
|
|
code: "invalid_request",
|
|
details: { reason: "missing", evidence_id: "ev_" + "a".repeat(64) },
|
|
});
|
|
await expect(stat(output)).rejects.toMatchObject({ code: "ENOENT" });
|
|
} else {
|
|
const bundle = parseEvidenceBundle(
|
|
JSON.parse(await readFile(output, "utf8")),
|
|
);
|
|
const parent = bundle.records.find(
|
|
(record) => record.operation === "procedure_references",
|
|
);
|
|
expect(response.summary.normalized_result).toMatchObject({
|
|
parent_evidence_id: parent?.evidence_id,
|
|
summary: {
|
|
reference_count: 0,
|
|
unresolved_call_count: 1,
|
|
direction: "incoming",
|
|
},
|
|
});
|
|
expect(parent?.evidence_links).toEqual([history.evidence_id]);
|
|
expect(
|
|
bundle.records.some(
|
|
(record) => record.evidence_id === history.evidence_id,
|
|
),
|
|
).toBe(true);
|
|
}
|
|
},
|
|
);
|