* refactor(test): colocate pure-domain tests and reduce test debt Move focused immutable domain/contracts/adapter tests from tests/composition/** beside their production owners under src/** as colocated *.test.ts/*.fixture.ts, and relocate persistence-shaped composition tests under tests/boundary/filesystem/**. Update import paths, the Vitest project topology (shared worker context for pure domain/contracts and recording-port service projects), the test migration ledger, testing docs, and AGENTS.md to match. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: remove test migration ledger The cutover is complete and the ledger is no longer referenced anywhere in source, scripts, or the docs gate. Drop the standalone artifact. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: clean up stale migration artifacts Remove empty directories left by the test migration and replace the "final cutover" language in docs/testing.md with standing PR guidance that no longer references the completed migration. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: repair CI failures from schema, knip, and stale generated artifacts Three root causes fixed: 1. catalog-schemas.mjs: valuesAt only traversed anyOf from Zod's toJSONSchema, not oneOf. The webScreenshotDiffSchema change to a discriminated union produces oneOf, so the product catalog generator could not derive the web_screenshot_diff schema version. Add oneOf traversal. 2. conformancePackage.ts: the test rewrite removed the only imports of ScenarioManifest, ReplayPlan, ShimPlan, and ExpectedEvidence, making them unused exports that knip flags. Remove the dead type aliases. 3. Regenerate stale artifacts (product catalog, MCP tool catalog, skill metadata, conformance manifest) that drifted from the source changes. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
440 lines
13 KiB
TypeScript
440 lines
13 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
AnalysisCancelledError,
|
|
AnalysisCapabilityUnavailableError,
|
|
AnalysisInputError,
|
|
AnalysisOutputError,
|
|
AnalysisProtocolError,
|
|
AnalysisTimeoutError,
|
|
ArtifactOperationError,
|
|
BinaryTargetError,
|
|
BrowserObservationError,
|
|
ConfigurationError,
|
|
EvidenceFileError,
|
|
EvidenceIntegrityError,
|
|
EvidenceLimitError,
|
|
HopperCancelledError,
|
|
HopperProcessError,
|
|
HopperProtocolError,
|
|
HopperRemoteError,
|
|
HopperStartError,
|
|
HopperTimeoutError,
|
|
InvestigationWorkspaceError,
|
|
NoBinaryOpenError,
|
|
ProviderAdapterError,
|
|
ProviderSelectionError,
|
|
PermissionRequiredError,
|
|
ReplayPlanStaleError,
|
|
UnknownRegistryError,
|
|
projectAnalysisError,
|
|
type AnalysisError,
|
|
type AnalysisErrorTag,
|
|
} from "../../../src/domain/errors.js";
|
|
import { ProcessCaptureError } from "../../../src/application/ProcessHarness.js";
|
|
import {
|
|
analysisErrorJsonSchema,
|
|
analysisErrorProjectionSchema,
|
|
} from "../../../src/contracts/errorSchemas.js";
|
|
|
|
const expectSecretsHidden = (serialized: string): void => {
|
|
for (const hidden of [
|
|
"secret-token",
|
|
"AnalysisCapabilityUnavailableError",
|
|
"declaredSha256",
|
|
])
|
|
expect(serialized).not.toContain(hidden);
|
|
};
|
|
|
|
describe("analysis error projection: provider failures", () => {
|
|
it("uses the correct provider-neutral protocol tag", () => {
|
|
expect(new AnalysisProtocolError("invalid")._tag).toBe(
|
|
"AnalysisProtocolError",
|
|
);
|
|
});
|
|
|
|
it("projects bounded provider diagnostics without dropping local coordinates", () => {
|
|
const diagnostics = {
|
|
runtime_root: "/tmp/rea-ghidra-fixture",
|
|
profile_digest: "a".repeat(64),
|
|
exit_code: 1,
|
|
};
|
|
const error = new ProviderAdapterError("ghidra", "health", {
|
|
diagnostics,
|
|
});
|
|
|
|
expect(error.diagnostics).not.toBe(diagnostics);
|
|
expect(projectAnalysisError(error)).toMatchObject({
|
|
details: {
|
|
provider_id: "ghidra",
|
|
operation: "health",
|
|
diagnostics,
|
|
},
|
|
});
|
|
});
|
|
|
|
it("projects stable, safe Linux startup failure codes", () => {
|
|
const expected = [
|
|
[70, "private_display_unavailable"],
|
|
[71, "x11_authorization_failed"],
|
|
[72, "unsupported_hopper_build"],
|
|
[73, "invalid_launch_command"],
|
|
[74, "process_ownership_mismatch"],
|
|
[75, "hopper_exited_during_startup"],
|
|
[76, "unsupported_demo_dialog"],
|
|
[77, "unexpected_display_geometry"],
|
|
[78, "x11_input_failed"],
|
|
[79, "runtime_dependency_unavailable"],
|
|
[80, "x11_socket_directory_unusable"],
|
|
] as const;
|
|
for (const [exitCode, code] of expected) {
|
|
const projected = projectAnalysisError(new HopperProcessError(exitCode));
|
|
expect(projected).toMatchObject({
|
|
code: "provider_unavailable",
|
|
details: { failure_code: code, exit_code: exitCode },
|
|
});
|
|
expect(projected.message.length).toBeGreaterThan(20);
|
|
expect(JSON.stringify(projected)).not.toContain("/proc/");
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("analysis error projection: typed failures", () => {
|
|
it("projects every typed failure without secrets", () => {
|
|
const secretCause = new Error("secret-token");
|
|
const byTag = {
|
|
AnalysisProtocolError: new AnalysisProtocolError("protocol failed"),
|
|
AnalysisInputError: new AnalysisInputError("overview", {
|
|
cause: secretCause,
|
|
}),
|
|
AnalysisOutputError: new AnalysisOutputError(
|
|
"overview",
|
|
"invalid shape",
|
|
{
|
|
cause: secretCause,
|
|
},
|
|
),
|
|
AnalysisCapabilityUnavailableError:
|
|
new AnalysisCapabilityUnavailableError("fixture", "overview", "absent"),
|
|
AnalysisCancelledError: new AnalysisCancelledError("overview"),
|
|
AnalysisTimeoutError: new AnalysisTimeoutError("overview", 50),
|
|
ProviderSelectionError: new ProviderSelectionError("overview"),
|
|
ProviderAdapterError: new ProviderAdapterError("fixture", "overview", {
|
|
cause: secretCause,
|
|
}),
|
|
BrowserObservationError: new BrowserObservationError(
|
|
"inspect_web_page",
|
|
"endpoint_unreachable",
|
|
{ cause: secretCause },
|
|
),
|
|
ArtifactOperationError: new ArtifactOperationError(
|
|
"inventory_artifact",
|
|
"integrity",
|
|
),
|
|
ProcessCaptureError: new ProcessCaptureError("capture failed", {
|
|
cause: secretCause,
|
|
}),
|
|
EvidenceIntegrityError: new EvidenceIntegrityError("integrity failed", {
|
|
cause: secretCause,
|
|
}),
|
|
EvidenceLimitError: new EvidenceLimitError("records", 10),
|
|
EvidenceFileError: new EvidenceFileError("read", "outside-root", {
|
|
cause: secretCause,
|
|
}),
|
|
InvestigationWorkspaceError: new InvestigationWorkspaceError(
|
|
"update",
|
|
"revision-conflict",
|
|
{ cause: secretCause },
|
|
),
|
|
UnknownRegistryError: new UnknownRegistryError("revision-conflict", {
|
|
cause: secretCause,
|
|
}),
|
|
HopperTimeoutError: new HopperTimeoutError(100),
|
|
HopperCancelledError: new HopperCancelledError(),
|
|
HopperProtocolError: new HopperProtocolError("wire failed", {
|
|
cause: secretCause,
|
|
}),
|
|
HopperRemoteError: new HopperRemoteError(7, "safe"),
|
|
HopperProcessError: new HopperProcessError(1),
|
|
HopperStartError: new HopperStartError({ cause: secretCause }),
|
|
ConfigurationError: new ConfigurationError("configuration failed", {
|
|
cause: secretCause,
|
|
}),
|
|
NoBinaryOpenError: new NoBinaryOpenError(),
|
|
BinaryTargetError: new BinaryTargetError(
|
|
"/secret/local/path",
|
|
"invalid",
|
|
{
|
|
cause: secretCause,
|
|
},
|
|
),
|
|
PermissionRequiredError: new PermissionRequiredError({
|
|
requested: {
|
|
capability: "evidence_read",
|
|
roots: ["/workspace/evidence.json"],
|
|
executables: [],
|
|
environment_names: ["TOKEN_NAME"],
|
|
network: "none",
|
|
mount: false,
|
|
operation_identity: "read:evidence",
|
|
},
|
|
missing: { environment_names: ["TOKEN_NAME"] },
|
|
ceiling: null,
|
|
remediation: "restart",
|
|
}),
|
|
ReplayPlanStaleError: new ReplayPlanStaleError(
|
|
"a".repeat(64),
|
|
"b".repeat(64),
|
|
),
|
|
} satisfies Readonly<Record<AnalysisErrorTag, AnalysisError>>;
|
|
const errors = Object.values(byTag);
|
|
const projected = errors.map(projectAnalysisError);
|
|
expect(projected).toHaveLength(27);
|
|
const serialized = JSON.stringify(projected);
|
|
expectSecretsHidden(serialized);
|
|
expect(serialized).toContain("/secret/local/path");
|
|
expect(serialized).toContain('"environment_names":["TOKEN_NAME"]');
|
|
expect(
|
|
projectAnalysisError(byTag.AnalysisCapabilityUnavailableError),
|
|
).toMatchObject({
|
|
category: "unsupported_provider",
|
|
});
|
|
expect(
|
|
projectAnalysisError(
|
|
new ArtifactOperationError("inventory_artifact", "integrity", {
|
|
logicalPath: "main.js",
|
|
declaredSha256: "a".repeat(64),
|
|
calculatedSha256: "b".repeat(64),
|
|
unpacked: true,
|
|
}),
|
|
),
|
|
).toMatchObject({
|
|
category: "integrity_mismatch",
|
|
details: {
|
|
logical_path: "main.js",
|
|
declared_sha256: "a".repeat(64),
|
|
calculated_sha256: "b".repeat(64),
|
|
unpacked: true,
|
|
},
|
|
});
|
|
expect(projected.every(({ message }) => message.length > 0)).toBe(true);
|
|
expect(
|
|
projected.every(
|
|
(value) => analysisErrorProjectionSchema.safeParse(value).success,
|
|
),
|
|
).toBe(true);
|
|
expect(analysisErrorJsonSchema).toMatchObject({ oneOf: expect.any(Array) });
|
|
expect(
|
|
projectAnalysisError(
|
|
new ProcessCaptureError("terminal cleanup failed", {
|
|
reason: "cleanup_incomplete",
|
|
cleanupResources: ["process_group"],
|
|
}),
|
|
),
|
|
).toMatchObject({
|
|
code: "cleanup_incomplete",
|
|
details: { cleanup: "incomplete", resources: ["process_group"] },
|
|
});
|
|
expect(
|
|
projected
|
|
.map(({ message }) => message)
|
|
.filter(
|
|
(message) =>
|
|
!/try again|run `rea doctor`|current target|when ready|smaller request|smaller artifact|fresh copy|re-import|reduce|inline evidence|configured evidence directory|evidence file|allow overwrite|refresh the current state|reported setting|call open_binary|supported file|review capture policy|review the requested scope/iu.test(
|
|
message,
|
|
),
|
|
),
|
|
).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("analysis error projection: remediation", () => {
|
|
it.each([
|
|
[
|
|
"configure",
|
|
false,
|
|
false,
|
|
"Add the exact missing scope beneath the administrator ceiling, then retry.",
|
|
],
|
|
[
|
|
"elicit",
|
|
false,
|
|
true,
|
|
"Approve the exact missing scope, then retry the operation.",
|
|
],
|
|
[
|
|
"restart",
|
|
true,
|
|
false,
|
|
"Add the exact missing scope to the administrator configuration, then restart the registered MCP server or client.",
|
|
],
|
|
] as const)(
|
|
"projects %s permission remediation into the stable protocol fields",
|
|
(remediation, restartRequired, elicitationSupported, action) => {
|
|
const projected = projectAnalysisError(
|
|
new PermissionRequiredError({
|
|
requested: {
|
|
capability: "evidence_read",
|
|
roots: ["/workspace/evidence.json"],
|
|
executables: [],
|
|
environment_names: [],
|
|
network: "none",
|
|
mount: false,
|
|
operation_identity: "read:evidence",
|
|
},
|
|
missing: { roots: ["/workspace/evidence.json"] },
|
|
ceiling: null,
|
|
remediation,
|
|
}),
|
|
);
|
|
|
|
expect(projected.remediation).toEqual({
|
|
action,
|
|
restart_required: restartRequired,
|
|
elicitation_supported: elicitationSupported,
|
|
});
|
|
},
|
|
);
|
|
|
|
it("gives missing residual unknowns a lookup-specific remediation", () => {
|
|
expect(
|
|
projectAnalysisError(new UnknownRegistryError("not-found")),
|
|
).toMatchObject({
|
|
code: "execution_failure",
|
|
message:
|
|
"The requested residual unknown does not exist in this session. Check the unknown_id and try again.",
|
|
remediation: {
|
|
action:
|
|
"Check that the unknown_id belongs to this session, then retry.",
|
|
},
|
|
details: { reason: "not-found" },
|
|
});
|
|
});
|
|
|
|
it("retains custom input guidance in the projected error details", () => {
|
|
expect(
|
|
projectAnalysisError(
|
|
new AnalysisInputError("find_changed_behavior", undefined, [
|
|
{
|
|
path: [],
|
|
reason: "invalid_value",
|
|
message:
|
|
"Supply either existing comparisons or one investigation_run",
|
|
},
|
|
]),
|
|
),
|
|
).toMatchObject({
|
|
details: {
|
|
issues: [
|
|
{
|
|
path: [],
|
|
reason: "invalid_value",
|
|
message:
|
|
"Supply either existing comparisons or one investigation_run",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
});
|
|
|
|
it("distinguishes disabled integrity continuation from format support", () => {
|
|
expect(
|
|
projectAnalysisError(
|
|
new ArtifactOperationError("inventory_artifact", "policy"),
|
|
),
|
|
).toMatchObject({
|
|
code: "artifact_operation_failed",
|
|
category: "unavailable",
|
|
message: expect.stringContaining(
|
|
"REA_ARTIFACT_INTEGRITY_CONTINUE_ENABLED=true",
|
|
),
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("analysis error projection: contract variants", () => {
|
|
it("validates every closed error-reason variant against the generated contract", () => {
|
|
const variants: AnalysisError[] = [
|
|
...(
|
|
[
|
|
"cancelled",
|
|
"format",
|
|
"integrity",
|
|
"limit",
|
|
"path",
|
|
"policy",
|
|
"unavailable",
|
|
"io",
|
|
] as const
|
|
).map(
|
|
(reason) => new ArtifactOperationError("inventory_artifact", reason),
|
|
),
|
|
...(
|
|
[
|
|
"disabled",
|
|
"outside-root",
|
|
"not-file",
|
|
"too-large",
|
|
"exists",
|
|
"invalid-json",
|
|
"io",
|
|
] as const
|
|
).map((reason) => new EvidenceFileError("read", reason)),
|
|
...(
|
|
[
|
|
"disabled",
|
|
"outside-root",
|
|
"not-file",
|
|
"too-large",
|
|
"invalid-json",
|
|
"integrity",
|
|
"locked",
|
|
"revision-conflict",
|
|
"name-conflict",
|
|
"io",
|
|
] as const
|
|
).map((reason) => new InvestigationWorkspaceError("update", reason)),
|
|
...(
|
|
[
|
|
"not-found",
|
|
"already-exists",
|
|
"revision-conflict",
|
|
"invalid-transition",
|
|
"integrity",
|
|
"limit",
|
|
] as const
|
|
).map((reason) => new UnknownRegistryError(reason)),
|
|
...(
|
|
[
|
|
"capture_failed",
|
|
"cleanup_incomplete",
|
|
"permission_required",
|
|
"cancelled",
|
|
] as const
|
|
).map(
|
|
(reason) =>
|
|
new ProcessCaptureError("SECRET capture diagnostic", { reason }),
|
|
),
|
|
...(
|
|
[
|
|
"remote",
|
|
"authorization",
|
|
"invalid_request",
|
|
"bridge_exception",
|
|
] as const
|
|
).map((diagnostic) => new HopperRemoteError(9, "safe", diagnostic)),
|
|
];
|
|
|
|
expect(variants).toHaveLength(39);
|
|
for (const variant of variants) {
|
|
const projected = projectAnalysisError(variant);
|
|
const parsed = analysisErrorProjectionSchema.safeParse(projected);
|
|
expect(parsed, JSON.stringify({ variant, projected })).toMatchObject({
|
|
success: true,
|
|
});
|
|
expect(projected.code).toMatch(/^[a-z][a-z0-9_]*$/u);
|
|
expect(JSON.stringify(projected)).not.toContain("SECRET");
|
|
}
|
|
});
|
|
});
|