refactor(test): colocate pure-domain tests and reduce test debt (#471)

* 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>
This commit is contained in:
morluto
2026-08-10 14:57:44 +08:00
committed by GitHub
co-authored by Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent 344b9b6dff
commit e91c8c39c2
302 changed files with 6822 additions and 5781 deletions
+2 -2
View File
@@ -15,7 +15,7 @@ import {
HopperStartError,
hopperStartupFailure,
HopperTimeoutError,
type HopperStartupDiagnostic,
type HopperStartupFailureDiagnostic,
} from "../domain/errors.js";
import { err, ok, type Result } from "../domain/result.js";
import type { JsonValue } from "../domain/jsonValue.js";
@@ -90,7 +90,7 @@ export class HopperClient {
#nextId = 1;
#closing = false;
#launcherExitCode: number | null | undefined;
#launcherFailureDiagnostic: HopperStartupDiagnostic | undefined;
#launcherFailureDiagnostic: HopperStartupFailureDiagnostic | undefined;
#startupController: AbortController | undefined;
#startPromise: Promise<Result<HopperServerInfo, HopperError>> | undefined;
#closePromise: Promise<Result<null, AnalysisError>> | undefined;
+2 -2
View File
@@ -1,6 +1,6 @@
import {
hopperStartupFailure,
type HopperStartupDiagnostic,
type HopperStartupFailureDiagnostic,
} from "../domain/errors.js";
import type { ProviderProcessDiagnostic } from "../process/ProviderProcess.js";
import { parseLinuxPrivateDisplayDiagnostic } from "./LinuxPrivateDisplayDiagnostic.js";
@@ -8,7 +8,7 @@ import { parseLinuxPrivateDisplayDiagnostic } from "./LinuxPrivateDisplayDiagnos
/** Extract only a matching, versioned Linux adapter failure record. */
export const hopperLauncherFailureDiagnostic = (
event: Extract<ProviderProcessDiagnostic, { readonly type: "exit" }>,
): HopperStartupDiagnostic | undefined => {
): HopperStartupFailureDiagnostic | undefined => {
const parsed = parseLinuxPrivateDisplayDiagnostic(
event.snapshot.stderr.text,
event.snapshot.stderr.truncated,
+41
View File
@@ -0,0 +1,41 @@
import { describe, expect, it } from "vitest";
import { parseConfig } from "../config.js";
import { silentLogger } from "../logger.js";
import { HopperProvider } from "./HopperProvider.js";
describe("Hopper provider capabilities", () => {
it("publishes deterministic immutable capability descriptors", () => {
const config = parseConfig({});
expect(config.ok).toBe(true);
if (!config.ok) return;
const provider = new HopperProvider(config.value, silentLogger);
const capabilities = provider.capabilities();
expect(capabilities).toHaveLength(37);
expect(new Set(capabilities.map(({ operation }) => operation)).size).toBe(
capabilities.length,
);
expect(Object.isFrozen(capabilities)).toBe(true);
for (const descriptor of capabilities) {
expect(descriptor.provider).toEqual(provider.identity());
expect(descriptor).toMatchObject({
inputContractVersion: 1,
outputContractVersion: 1,
available: true,
reason: null,
});
expect(Object.isFrozen(descriptor)).toBe(true);
expect(Object.isFrozen(descriptor.effects)).toBe(true);
expect(Object.isFrozen(descriptor.limits)).toBe(true);
expect(Object.isFrozen(descriptor.limitations)).toBe(true);
}
expect(
capabilities.find(({ operation }) => operation === "list_procedures"),
).toMatchObject({ pagination: "offset" });
expect(
capabilities.find(({ operation }) => operation === "set_comment"),
).toMatchObject({
effects: { mutatesArtifact: true, mayWriteFilesystem: true },
});
});
});
+51 -48
View File
@@ -7,39 +7,56 @@ import {
export const LINUX_PRIVATE_DISPLAY_DIAGNOSTIC_PREFIX = "REA_X11_DIAGNOSTIC_V1=";
const diagnosticSchema = z
.object({
schema_version: z.literal(1),
component: z.literal("hopper_private_display"),
operation: z.enum(["probe", "launch"]),
status: z.enum(["ready", "error"]),
failure_code: z.string().max(64).nullable(),
reason: z
.string()
.regex(/^[a-z0-9_]+$/u)
.max(64),
socket_directory: z.literal("/tmp/.X11-unix"),
socket_directory_mode: z
.string()
.regex(/^[0-7]{4}$/u)
.nullable(),
mount_read_only: z.boolean().nullable(),
effective_socket_directory_mode: z
.string()
.regex(/^[0-7]{4}$/u)
.nullable(),
effective_mount_read_only: z.boolean().nullable(),
wsl: z.boolean(),
strategy: z.enum(["direct", "user-mount-namespace", "unavailable"]),
fallback_reason: z
.string()
.regex(/^[a-z0-9_]+$/u)
.max(64)
.nullable(),
xvfb_stderr_bytes: z.number().int().nonnegative().safe(),
xvfb_stderr_truncated: z.boolean(),
})
.strict();
const diagnosticContextSchema = z.object({
schema_version: z.literal(1),
component: z.literal("hopper_private_display"),
operation: z.enum(["probe", "launch"]),
reason: z
.string()
.regex(/^[a-z0-9_]+$/u)
.max(64),
socket_directory: z.literal("/tmp/.X11-unix"),
socket_directory_mode: z
.string()
.regex(/^[0-7]{4}$/u)
.nullable(),
mount_read_only: z.boolean().nullable(),
effective_socket_directory_mode: z
.string()
.regex(/^[0-7]{4}$/u)
.nullable(),
effective_mount_read_only: z.boolean().nullable(),
wsl: z.boolean(),
strategy: z.enum(["direct", "user-mount-namespace", "unavailable"]),
fallback_reason: z
.string()
.regex(/^[a-z0-9_]+$/u)
.max(64)
.nullable(),
xvfb_stderr_bytes: z.number().int().nonnegative().safe(),
xvfb_stderr_truncated: z.boolean(),
});
const failureCodeSchema = z
.string()
.max(64)
.transform((value, context) => {
if (isHopperStartupFailureCode(value)) return value;
context.addIssue({
code: "custom",
message: "Unknown startup failure code",
});
return z.NEVER;
});
const diagnosticSchema = z.discriminatedUnion("status", [
diagnosticContextSchema
.extend({ status: z.literal("ready"), failure_code: z.null() })
.strict(),
diagnosticContextSchema
.extend({ status: z.literal("error"), failure_code: failureCodeSchema })
.strict(),
]);
export type LinuxPrivateDisplayDiagnosticParse =
| { readonly ok: true; readonly value: HopperStartupDiagnostic }
@@ -70,21 +87,7 @@ export const parseLinuxPrivateDisplayDiagnostic = (
JSON.parse(record.slice(LINUX_PRIVATE_DISPLAY_DIAGNOSTIC_PREFIX.length)),
);
if (!parsed.success) return { ok: false, reason: "diagnostic_malformed" };
const code = parsed.data.failure_code;
if (code !== null && !isHopperStartupFailureCode(code))
return { ok: false, reason: "diagnostic_malformed" };
if (
(parsed.data.status === "ready" && code !== null) ||
(parsed.data.status === "error" && code === null)
)
return { ok: false, reason: "diagnostic_malformed" };
return {
ok: true,
value: {
...parsed.data,
failure_code: code,
},
};
return { ok: true, value: parsed.data };
} catch {
return { ok: false, reason: "diagnostic_malformed" };
}
+10 -12
View File
@@ -4,7 +4,9 @@ import {
hopperStartupExitCode,
type HopperPrivateDisplayStrategy,
type HopperStartupDiagnostic,
type HopperStartupFailureDiagnostic,
type HopperStartupFailureCode,
type HopperStartupReadyDiagnostic,
} from "../domain/hopperStartupFailure.js";
import { cleanupOwnedProcessGroup } from "../process/ProcessOwnership.js";
import {
@@ -46,13 +48,13 @@ export type LinuxPrivateDisplaySelection =
| {
readonly ok: true;
readonly strategy: LinuxPrivateDisplayRunnableStrategy;
readonly diagnostic: HopperStartupDiagnostic;
readonly diagnostic: HopperStartupReadyDiagnostic;
}
| {
readonly ok: false;
readonly strategy: "unavailable";
readonly exitCode: number;
readonly diagnostic: HopperStartupDiagnostic;
readonly diagnostic: HopperStartupFailureDiagnostic;
};
/** Probe the exact Xvfb boundary and select the least-privileged viable strategy. */
@@ -188,11 +190,11 @@ const evaluatedProbe = async (
| {
readonly ok: true;
readonly strategy: LinuxPrivateDisplayRunnableStrategy;
readonly diagnostic: HopperStartupDiagnostic;
readonly diagnostic: HopperStartupReadyDiagnostic;
}
| {
readonly ok: false;
readonly diagnostic: HopperStartupDiagnostic;
readonly diagnostic: HopperStartupFailureDiagnostic;
}
> => {
let processResult: LinuxPrivateDisplayProbeProcessResult;
@@ -258,14 +260,13 @@ const exitMatchesDiagnostic = (
): boolean =>
diagnostic.status === "ready"
? exitCode === 0
: diagnostic.failure_code !== null &&
hopperStartupExitCode(diagnostic.failure_code) === exitCode;
: hopperStartupExitCode(diagnostic.failure_code) === exitCode;
const syntheticDiagnostic = (
strategy: LinuxPrivateDisplayRunnableStrategy,
reason: string,
failureCode: HopperStartupFailureCode = "private_display_unavailable",
): HopperStartupDiagnostic => ({
): HopperStartupFailureDiagnostic => ({
schema_version: 1,
component: "hopper_private_display",
operation: "probe",
@@ -285,14 +286,11 @@ const syntheticDiagnostic = (
});
const unavailable = (
diagnostic: HopperStartupDiagnostic,
diagnostic: HopperStartupFailureDiagnostic,
): LinuxPrivateDisplaySelection => ({
ok: false,
strategy: "unavailable",
exitCode:
diagnostic.failure_code === null
? 70
: (hopperStartupExitCode(diagnostic.failure_code) ?? 70),
exitCode: hopperStartupExitCode(diagnostic.failure_code) ?? 70,
diagnostic: { ...diagnostic, strategy: "unavailable" },
});