Skip to content
53 changes: 0 additions & 53 deletions e2e/image-tag.test.ts

This file was deleted.

12 changes: 5 additions & 7 deletions e2e/lease-environment-passthrough.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,16 @@ describe("reaching a leased device", () => {
},
);

it.each([
[["simctl", "delete", "ABCD"], "simctl delete"],
[["adb", "kill-server"], "adb kill-server"],
[["adb", "-s", "emulator-5586", "emu", "kill"], "adb emu kill"],
])("refuses %s with a usage error naming what to run instead", async (args, refused) => {
// One verb is enough: which verbs are refused is each driver's decision, tested with the
// drivers. What only separate processes show is the refusal reaching the shell as exit 2.
it("refuses a destructive passthrough with a usage error naming what to run instead", async () => {
const env = await withDaemon();

const refusal = await env.cli(args);
const refusal = await env.cli(["simctl", "delete", "ABCD"]);

expect(refusal.code).toBe(2);
expect(refusal.error?.code).toBe("USAGE");
expect(refusal.error?.message).toContain(refused);
expect(refusal.error?.message).toContain("simctl delete");
expect(refusal.error?.message).toContain("simlock release");
expect(refusal.stdout).toBe("");
});
Expand Down
21 changes: 0 additions & 21 deletions src/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
NodeFilesystem,
NodeIpcTransport,
NoopLogger,
SocketPathTooLongError,
type Filesystem,
type IdGenerator,
} from "../ports/index.js";
Expand Down Expand Up @@ -49,7 +48,6 @@ import { connectSimlockAdmin } from "../admin/index.js";
import { RELEASE_TIMEOUT_MS } from "../lease-policy/index.js";
import {
buildCliEnvironment,
errorExitCode,
parseDuration,
readLogFile,
readPipedStdin,
Expand Down Expand Up @@ -164,8 +162,6 @@ describe("CLI: exit codes", () => {
["UNKNOWN_LEASE", 1],
] as const)("maps %s to exit %d, from ERROR_TABLE not a second map", async (code, expected) => {
const error = simlockError(code);
expect(errorExitCode(error)).toBe(expected);

const output = outputCapture();
await expect(
runCli(
Expand Down Expand Up @@ -4338,28 +4334,11 @@ describe("CLI: a SIMLOCK_HOME the kernel could not bind", () => {
expect(reported.error.code).toBe("USAGE");
expect(reported.error.message).toContain("SIMLOCK_HOME");
});

it("maps the error to the documented usage exit code", () => {
expect(errorExitCode(new SocketPathTooLongError(`${tooDeep}/daemon.sock`, 103))).toBe(2);
});
});

describe("CLI: requester id from the agent session", () => {
const sessionEnv = { CLAUDE_CODE_SESSION_ID: "abc" };

it("buildCliEnvironment resolves requesterId to the session-derived id when SIMLOCK_AGENT_ID is unset", () => {
expect(buildCliEnvironment(realCliEnvironmentPorts(), sessionEnv).requesterId).toBe(
"claude-code:abc",
);
});

it("buildCliEnvironment prefers SIMLOCK_AGENT_ID over a session-derived id", () => {
expect(
buildCliEnvironment(realCliEnvironmentPorts(), { ...sessionEnv, SIMLOCK_AGENT_ID: "agent-7" })
.requesterId,
).toBe("agent-7");
});

it("buildCliEnvironment falls back to the pid when no agent id or session id is set", () => {
expect(buildCliEnvironment(realCliEnvironmentPorts(), {}).requesterId).toBe(
String(process.pid),
Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ async function resolveRemoteLeaseId(
/** ADR §7: "CLI exit codes and HTTP status codes are columns of the same error table, not
* second mappings" -- driven from `ERROR_TABLE`'s `cliExitCode` column rather than a second,
* CLI-maintained map. */
export function errorExitCode(error: unknown): number {
function errorExitCode(error: unknown): number {
if (error instanceof UsageError || error instanceof SocketPathTooLongError) return 2;
if (isSimlockError(error)) return ERROR_TABLE[error.code].cliExitCode;
return 1;
Expand Down
15 changes: 1 addition & 14 deletions src/contract/errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";

import { ERROR_TABLE, fromWireError, isSimlockError, SimlockError } from "./errors.js";
import { ERROR_TABLE, fromWireError, isSimlockError } from "./errors.js";

describe("SimlockError", () => {
it("narrows details by code", () => {
Expand Down Expand Up @@ -41,17 +41,4 @@ describe("SimlockError", () => {
it("isSimlockError rejects a plain Error", () => {
expect(isSimlockError(new Error("boom"))).toBe(false);
});

it("every table entry's code matches its own key", () => {
for (const [key, entry] of Object.entries(ERROR_TABLE)) {
expect(entry.code).toBe(key);
}
});

it("constructs directly with typed details", () => {
const error = new SimlockError("UNKNOWN_LEASE", "domain", "no such lease", {
leaseId: "lease_9",
});
expect(error.details.leaseId).toBe("lease_9");
});
});
32 changes: 2 additions & 30 deletions src/contract/operations.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
import { z } from "zod";
import { describe, expect, it } from "vitest";

import { defineOperation, OPERATIONS, type Effect, type OperationName } from "./operations.js";
import { OPERATIONS, type Effect, type OperationName } from "./operations.js";
import { PUSH_SCHEMAS } from "./pushes.js";
import { ROLES, type Role } from "./roles.js";

describe("defineOperation", () => {
it("returns the definition unchanged, typed from its zod schemas", () => {
const echo = defineOperation({
name: "test.echo",
role: "agent",
effect: "read",
input: z.object({ value: z.string() }),
output: z.object({ value: z.string() }),
});
expect(echo.input.parse({ value: "hi" })).toEqual({ value: "hi" });
expect(echo.output.parse({ value: "hi" })).toEqual({ value: "hi" });
expect(echo.role).toBe("agent");
});
});
import type { Role } from "./roles.js";

/**
* The ADR §3 operation matrix, name -> role. A table-driven test against this makes
Expand Down Expand Up @@ -84,10 +68,6 @@ describe("operation role matrix", () => {
expect(declaredNames).toEqual(matrixNames);
});

it("only ever resolves to one of the two declared roles", () => {
for (const row of ROLE_MATRIX) expect(ROLES).toContain(row.role);
});

it.each(ROLE_MATRIX)("$name with $input resolves to role $role", ({ name, input, role }) => {
const operation = OPERATIONS[name];
const roleFn = operation.role as Role | ((input: unknown) => Role);
Expand Down Expand Up @@ -163,14 +143,6 @@ describe("operation effects", () => {
expect(new Set(EFFECT_MATRIX.map((row) => row.name))).toEqual(new Set(Object.keys(OPERATIONS)));
});

it("doctor.run is a write only with fix or purgeOrphans, and cleanup.run is a read only with dryRun", () => {
expect(resolvedEffect("doctor.run", {})).toBe("read");
expect(resolvedEffect("doctor.run", { fix: true })).toBe("write");
expect(resolvedEffect("doctor.run", { purgeOrphans: true })).toBe("write");
expect(resolvedEffect("cleanup.run", {})).toBe("write");
expect(resolvedEffect("cleanup.run", { dryRun: true })).toBe("read");
});

it.each(EFFECT_MATRIX)("$name with $input is a $effect", ({ name, input, effect }) => {
expect(resolvedEffect(name, input)).toBe(effect);
});
Expand Down
2 changes: 1 addition & 1 deletion src/contract/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface OperationDefinition<
readonly authorize?: (input: z.infer<InputSchema>, context: AuthorizeContext) => boolean;
}

export function defineOperation<
function defineOperation<
Name extends string,
InputSchema extends z.ZodTypeAny,
OutputSchema extends z.ZodTypeAny,
Expand Down
18 changes: 0 additions & 18 deletions src/contract/protocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import { describe, expect, it } from "vitest";

import {
helloRequestSchema,
LEGACY_DAEMON_PROTOCOL_VERSION,
mapLegacyProtocolMismatch,
negotiateProtocolVersion,
normalizeProtocolVersion,
PROTOCOL_VERSION_RANGE,
} from "./protocol.js";

describe("negotiateProtocolVersion", () => {
Expand All @@ -30,21 +27,6 @@ describe("normalizeProtocolVersion", () => {
});
});

describe("mapLegacyProtocolMismatch", () => {
it("reports the daemon range as {2, 2} and an unknown daemon version", () => {
const error = mapLegacyProtocolMismatch(
PROTOCOL_VERSION_RANGE,
"Protocol version 3 is not supported",
);
expect(error.code).toBe("PROTOCOL_VERSION_UNSUPPORTED");
expect(error.details).toEqual({
client: PROTOCOL_VERSION_RANGE,
daemon: { min: LEGACY_DAEMON_PROTOCOL_VERSION, max: LEGACY_DAEMON_PROTOCOL_VERSION },
daemonVersion: "unknown",
});
});
});

describe("helloRequestSchema", () => {
it("accepts a bare legacy protocolVersion with no range", () => {
expect(() =>
Expand Down
2 changes: 1 addition & 1 deletion src/contract/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const PROTOCOL_VERSION_RANGE: ProtocolRange = { min: 9, max: 9 };
* in this repository to negotiate with; this constant documents the historical fact the ADR's
* compatibility note depends on.
*/
export const LEGACY_DAEMON_PROTOCOL_VERSION = 2;
const LEGACY_DAEMON_PROTOCOL_VERSION = 2;

/** Highest version present in both ranges, or `undefined` if they do not overlap at all. */
export function negotiateProtocolVersion(
Expand Down
2 changes: 1 addition & 1 deletion src/contract/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* below an operation's -- is the dispatcher's job (§2), which is PR 2. This module only
* declares the vocabulary the rest of the contract is typed against.
*/
export const ROLES = ["agent", "admin"] as const;
const ROLES = ["agent", "admin"] as const;
export type Role = (typeof ROLES)[number];

/**
Expand Down
12 changes: 0 additions & 12 deletions src/core/capacity/strategies/fixed/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,6 @@ describe("fixed strategy", () => {
});
});

it("ignores deleted devices when counting against the pin", () => {
const fixed = strategy({ maxRunning: 1 });

expect(
fixed.canProvision({ mode: "full", platform: "ios" }, [
{ mode: "full" as const, platform: "ios", state: "deleted" },
]),
).toEqual({
ok: true,
});
});

it("grants up to maxRunning whatever the modes, never refuses a boot, and reports no RAM budget", () => {
const fixed = strategy({ maxRunning: 3 });
const mixed = [...ready("ios", 1, "slim"), ...ready("ios", 1, "full")];
Expand Down
10 changes: 0 additions & 10 deletions src/core/capacity/strategies/resource/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ describe("resource strategy provisioning", () => {
});
});

it("does not count deleted devices against capacity", () => {
const devices: CapacityDevice[] = [
{ mode: "full" as const, platform: "ios", state: "deleted" },
];

expect(withRam(32 * gibibyte).canProvision({ mode: "full", platform: "ios" }, devices)).toEqual(
{ ok: true },
);
});

it("accounts for active devices on both platforms in the shared RAM budget", () => {
const devices: CapacityDevice[] = [
{ mode: "full" as const, platform: "android", state: "ready" },
Expand Down
Loading
Loading