Skip to content
1 change: 0 additions & 1 deletion .fallowrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// The web console is its own entry: Vite loads ui/index.html, which loads ui/src/main.tsx. The
// browser lane's specs are Playwright entry points, as the e2e tests are vitest's.
"entry": [
"src/index.ts",
"src/cli/main.ts",
"src/daemon/main.ts",
"e2e/**/*.test.ts",
Expand Down
2 changes: 1 addition & 1 deletion docs/internal/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ stats (CPU/RAM/disk), and watching another process for exit:
Filesystem — read/write/delete/stat/disk-free
ProcessRunner — spawn/exec/kill, capture stdout/stderr
Clock — now(), timers (no direct Date/setTimeout in logic)
SystemStats — cpu count, total/free RAM, disk free
SystemStats — cpu count, total RAM
HostInfo — operating system, its version, CPU architecture (`sw_vers` on macOS)
IpcConnector / IpcListenerFactory — connect to and host daemon IPC endpoints
DaemonLauncher — detached daemon startup with append-only combined logs
Expand Down
5 changes: 0 additions & 5 deletions src/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,6 @@ describe("CLI: admin credential resolution (ADR 0003 §5)", () => {
clock: new FakeClock(0),
systemStats: new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 32 * gibibyte,
totalRamBytes: 32 * gibibyte,
}),
ipc: ipcTransport,
Expand Down Expand Up @@ -1198,7 +1197,6 @@ describe("CLI: admin credential resolution (ADR 0003 §5)", () => {
clock: new FakeClock(0),
systemStats: new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 32 * gibibyte,
totalRamBytes: 32 * gibibyte,
}),
ipc: ipcTransport,
Expand Down Expand Up @@ -4711,7 +4709,6 @@ async function startTestDaemon(): Promise<{ socketPath: string; daemon: DaemonSe
registry,
systemStats: new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 32 * gibibyte,
totalRamBytes: 32 * gibibyte,
}),
});
Expand Down Expand Up @@ -4776,7 +4773,6 @@ function realCliEnvironmentPorts(
clock: new FakeClock(0),
systemStats: new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 32 * gibibyte,
totalRamBytes: 32 * gibibyte,
}),
ipc: new MemoryIpcTransport(),
Expand Down Expand Up @@ -4826,7 +4822,6 @@ async function startInMemoryDaemon(options: {
registry,
systemStats: new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 32 * gibibyte,
totalRamBytes: 32 * gibibyte,
}),
});
Expand Down
4 changes: 2 additions & 2 deletions src/contract/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ export const grantedDeviceSchema = z.object({
* last `ready` transition. Undefined for a device still `provisioning` (never made ready
* yet) and, as an upgrade path, for a record written by a pre-address daemon -- `state.json`
* from before this field existed loads without one rather than failing to start. It becomes
* defined the next time the device is made ready (`boot`/`readyProvisioned`); nothing here
* ever guesses at a value it wasn't told.
* defined the next time the device is made ready (`bootForLease`/`readyProvisionedForLease`);
* nothing here ever guesses at a value it wasn't told.
*/
address: z.string().optional(),
/** The mode the device actually has (see `DeviceRecord.mode`). */
Expand Down
5 changes: 1 addition & 4 deletions src/core/acquisition-planner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ function planner(
) {
const claims = new DeviceOperationClaims();
const capacity = new CapacityCoordinator(
createCapacityStrategy(
capacityConfig,
new FakeSystemStats({ cpuCount: 8, freeRamBytes: totalRamBytes, totalRamBytes }),
),
createCapacityStrategy(capacityConfig, new FakeSystemStats({ cpuCount: 8, totalRamBytes })),
);
return { claims, planner: new AcquisitionPlanner(capacity, claims) };
}
Expand Down
1 change: 0 additions & 1 deletion src/core/capacity/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const gibibyte = 1024 ** 3;
function build(name: CapacityStrategyName): CapacityStrategy {
const systemStats = new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 32 * gibibyte,
totalRamBytes: 32 * gibibyte,
});
const definition = capacityStrategies[name];
Expand Down
3 changes: 0 additions & 3 deletions src/core/capacity/coordinator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function coordinator(): CapacityCoordinator {
},
new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 32 * gibibyte,
totalRamBytes: 32 * gibibyte,
}),
),
Expand All @@ -47,7 +46,6 @@ function sizedCoordinator(): CapacityCoordinator {
},
new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 12 * gibibyte,
totalRamBytes: 12 * gibibyte,
}),
),
Expand Down Expand Up @@ -160,7 +158,6 @@ describe("CapacityCoordinator", () => {
},
new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 12 * gibibyte,
totalRamBytes: 12 * gibibyte,
}),
),
Expand Down
8 changes: 3 additions & 5 deletions src/core/capacity/strategies/fixed/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function strategy(options: FixedStrategyOptions) {
return fixedStrategy.create(
options,
// Passed for interface parity only: nothing in this strategy reads it.
new FakeSystemStats({ cpuCount: 1, freeRamBytes: gibibyte, totalRamBytes: gibibyte }),
new FakeSystemStats({ cpuCount: 1, totalRamBytes: gibibyte }),
);
}

Expand Down Expand Up @@ -70,7 +70,7 @@ describe("fixed strategy", () => {
it("never refuses on RAM, however little the machine has", () => {
const fixed = fixedStrategy.create(
{ maxRunning: 8 },
new FakeSystemStats({ cpuCount: 1, freeRamBytes: 0, totalRamBytes: 0 }),
new FakeSystemStats({ cpuCount: 1, totalRamBytes: 0 }),
);

expect(fixed.canProvision({ mode: "full", platform: "android" }, ready("android", 7))).toEqual({
Expand Down Expand Up @@ -112,9 +112,7 @@ describe("fixed strategy", () => {

it("defaults to a machine-independent pin", () => {
expect(
fixedStrategy.defaults(
new FakeSystemStats({ cpuCount: 64, freeRamBytes: 0, totalRamBytes: 512 * gibibyte }),
),
fixedStrategy.defaults(new FakeSystemStats({ cpuCount: 64, totalRamBytes: 512 * gibibyte })),
).toEqual({ maxRunning: 2 });
});
});
9 changes: 2 additions & 7 deletions src/core/capacity/strategies/resource/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@ const options: ResourceStrategyOptions = {
};

function withRam(totalRamBytes: number): CapacityStrategy {
return resourceStrategy.create(
options,
new FakeSystemStats({ cpuCount: 8, freeRamBytes: totalRamBytes, totalRamBytes }),
);
return resourceStrategy.create(options, new FakeSystemStats({ cpuCount: 8, totalRamBytes }));
}

describe("resource strategy defaults", () => {
it("derives device limits from the machine", () => {
const defaults = resourceStrategy.defaults(
new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 16 * gibibyte,
totalRamBytes: 32 * gibibyte,
}),
);
Expand All @@ -45,7 +41,7 @@ describe("resource strategy defaults", () => {

it("keeps at least one device per platform on a small machine", () => {
const defaults = resourceStrategy.defaults(
new FakeSystemStats({ cpuCount: 1, freeRamBytes: gibibyte, totalRamBytes: 2 * gibibyte }),
new FakeSystemStats({ cpuCount: 1, totalRamBytes: 2 * gibibyte }),
);

expect(defaults.limits.ios.maxDevices).toBe(1);
Expand Down Expand Up @@ -172,7 +168,6 @@ describe("resource strategy RAM budget by mode", () => {
{ limits: roomy, ramBudget },
new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 12 * gibibyte,
totalRamBytes: 12 * gibibyte,
}),
);
Expand Down
1 change: 0 additions & 1 deletion src/core/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const gibibyte = 1024 ** 3;
function createStats(): FakeSystemStats {
return new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 16 * gibibyte,
totalRamBytes: 32 * gibibyte,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ describe("Doctor", () => {
eventBus,
idGenerator: sequence(),
registry,
systemStats: new FakeSystemStats({ cpuCount: 8, freeRamBytes: 32, totalRamBytes: 32 }),
systemStats: new FakeSystemStats({ cpuCount: 8, totalRamBytes: 32 }),
});

await new Doctor({
Expand Down
4 changes: 2 additions & 2 deletions src/core/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export interface DeviceRecord {
* last `ready` transition. Undefined for a device still `provisioning` (never made ready
* yet) and, as an upgrade path, for a record written by a pre-address daemon -- `state.json`
* from before this field existed loads without one rather than failing to start. It becomes
* defined the next time the device is made ready (`boot`/`readyProvisioned`); nothing here
* ever guesses at a value it wasn't told.
* defined the next time the device is made ready (`bootForLease`/`readyProvisionedForLease`);
* nothing here ever guesses at a value it wasn't told.
*/
readonly address?: string;
/**
Expand Down
47 changes: 12 additions & 35 deletions src/core/driver.test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
import { describe, expect, it } from "vitest";

import { MemoryFilesystem } from "../ports/index.js";
import {
assertDiskSpace,
DiskSpaceGuard,
InsufficientDiskSpaceError,
sameReceipt,
} from "./driver.js";
import { DiskSpaceGuard, InsufficientDiskSpaceError, sameReceipt } from "./driver.js";

const gibibyte = 1024 ** 3;

describe("assertDiskSpace", () => {
it("resolves when free space covers the requirement", async () => {
const filesystem = new MemoryFilesystem(10 * gibibyte);

await expect(
assertDiskSpace(filesystem, "ios", 6 * gibibyte, "/volume"),
).resolves.toBeUndefined();
});

it("throws InsufficientDiskSpaceError naming required and available bytes when it doesn't", async () => {
const filesystem = new MemoryFilesystem(4 * gibibyte);

const error = await assertDiskSpace(filesystem, "android", 6 * gibibyte, "/volume").catch(
(caught: unknown) => caught,
);

expect(error).toBeInstanceOf(InsufficientDiskSpaceError);
expect(error).toMatchObject({
availableBytes: 4 * gibibyte,
platform: "android",
requiredBytes: 6 * gibibyte,
});
});
});

describe("DiskSpaceGuard", () => {
it("lets a single reservation through when it fits free space", async () => {
const filesystem = new MemoryFilesystem(10 * gibibyte);
Expand All @@ -45,13 +15,20 @@ describe("DiskSpaceGuard", () => {
);
});

it("rejects a reservation that alone exceeds free space, with InsufficientDiskSpaceError", async () => {
it("rejects a reservation that alone exceeds free space with InsufficientDiskSpaceError naming required and available bytes", async () => {
const filesystem = new MemoryFilesystem(4 * gibibyte);
const guard = new DiskSpaceGuard();

await expect(guard.reserve(filesystem, "ios", 6 * gibibyte, "/volume")).rejects.toBeInstanceOf(
InsufficientDiskSpaceError,
);
const error = await guard
.reserve(filesystem, "android", 6 * gibibyte, "/volume")
.catch((caught: unknown) => caught);

expect(error).toBeInstanceOf(InsufficientDiskSpaceError);
expect(error).toMatchObject({
availableBytes: 4 * gibibyte,
platform: "android",
requiredBytes: 6 * gibibyte,
});
});

it("rejects a second concurrent reservation that would overfill the volume alongside the first", async () => {
Expand Down
45 changes: 14 additions & 31 deletions src/core/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,13 +788,16 @@ export class LicenseNotAcceptedError extends Error {

/**
* Serializes disk-space preflight across concurrent component installs sharing a volume.
* `assertDiskSpace` alone only ever sees the disk's free space at the instant it is called: two
* installs racing the same preflight (an iOS runtime download and an Android system-image
* install, or two of either) can each observe enough free space and both proceed, jointly
* overfilling the volume neither alone would have. A single shared `DiskSpaceGuard` instance,
* held by `ComponentInstaller` (wired once in `src/daemon/main.ts`; drivers never see it),
* fixes that by tracking bytes reserved but not yet released, keyed per path, and checking free
* space *minus* those outstanding reservations rather than free space alone.
* Checked before any multi-GB component download/install, so a full disk fails fast with a
* clear message instead of filling up mid-download (see safety rule 4's spirit -- downloads
* must never surprise the machine they run on). A check of free space alone only ever sees the
* disk at the instant it runs: two installs racing the same preflight (an iOS runtime download
* and an Android system-image install, or two of either) can each observe enough free space and
* both proceed, jointly overfilling the volume neither alone would have. A single shared
* `DiskSpaceGuard` instance, held by `ComponentInstaller` (wired once in `src/daemon/main.ts`;
* drivers never see it), fixes that by tracking bytes reserved but not yet released, keyed per
* path, and checking free space *minus* those outstanding reservations rather than free space
* alone.
*
* `reserve` resolves or throws synchronously with respect to any other in-flight `reserve` call:
* the only `await` is `filesystem.diskFree`, and the check-then-record step immediately after it
Expand All @@ -807,10 +810,10 @@ export class DiskSpaceGuard {

/**
* Reserves `requiredBytes` against `path`'s free space, minus whatever this guard already has
* outstanding there. Throws `InsufficientDiskSpaceError` (same shape `assertDiskSpace` throws)
* when the reservation would not fit. On success, returns a release function the caller must
* invoke exactly once (typically in a `finally`) once the install this reservation was made
* for has settled, freeing the bytes for the next reservation.
* outstanding there. Throws `InsufficientDiskSpaceError` when the reservation would not fit.
* On success, returns a release function the caller must invoke exactly once (typically in a
* `finally`) once the install this reservation was made for has settled, freeing the bytes for
* the next reservation.
*/
async reserve(
filesystem: Pick<Filesystem, "diskFree">,
Expand Down Expand Up @@ -843,23 +846,3 @@ export class DiskSpaceGuard {
};
}
}

/**
* Checked before a driver starts any multi-GB component download/install, so a full disk fails
* fast with a clear message instead of filling up mid-download (see safety rule 4's spirit --
* downloads must never surprise the machine they run on). `path` defaults to `"."`, the same
* convention `CleanupReaper` uses for its own disk-pressure check (`src/core/reaper.ts`): the
* daemon process's own working-directory volume. Single-shot: does not account for another
* concurrent install's own in-flight reservation -- see `DiskSpaceGuard` for that.
*/
export async function assertDiskSpace(
filesystem: Pick<Filesystem, "diskFree">,
platform: Platform,
requiredBytes: number,
path = ".",
): Promise<void> {
const availableBytes = await filesystem.diskFree(path);
if (availableBytes < requiredBytes) {
throw new InsufficientDiskSpaceError(platform, requiredBytes, availableBytes);
}
}
1 change: 0 additions & 1 deletion src/core/lease-acquisition-coordinator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ async function createHarness(
config(options.maxDevices, options.maxRunning).capacity,
new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 32 * gibibyte,
totalRamBytes: 32 * gibibyte,
}),
),
Expand Down
9 changes: 3 additions & 6 deletions src/core/lease-engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async function createHarness(
idGenerator: { generate: () => `request-${nextId++}` },
...(options.logger === undefined ? {} : { logger: options.logger }),
registry,
systemStats: new FakeSystemStats({ cpuCount: 8, freeRamBytes: totalRamBytes, totalRamBytes }),
systemStats: new FakeSystemStats({ cpuCount: 8, totalRamBytes }),
});

return { bus, clock, driver, engine, filesystem, registry };
Expand Down Expand Up @@ -1401,7 +1401,7 @@ describe("LeaseEngine RAM budget by mode", () => {
await before.engine.release(grant.lease.id, "explicit");
}
await before.engine.settle();
await before.engine.executeCleanup({
await before.engine.cleanup.execute({
action: "shutdown",
reason: "test",
rule: "test",
Expand Down Expand Up @@ -1459,7 +1459,7 @@ describe("LeaseEngine RAM budget by mode", () => {
["shutdown", idle.device.id],
["destroy", idle.device.id],
] as const) {
await after.engine.executeCleanup({ action, reason: "test", rule: "test", target });
await after.engine.cleanup.execute({ action, reason: "test", rule: "test", target });
}
expect(after.engine.ramBudget).toEqual({
limitBytes: 5 * gibibyte,
Expand Down Expand Up @@ -1637,7 +1637,6 @@ describe("LeaseEngine startup reclaim backgrounding (#43)", () => {
const systemStats = () =>
new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 32 * gibibyte,
totalRamBytes: 32 * gibibyte,
});
// The physical device survives a daemon restart even though the daemon's
Expand Down Expand Up @@ -1897,7 +1896,6 @@ describe("LeaseEngine fresh lease identity (#75)", () => {
const driver = new FakeDriver({ availableOsVersions: ["26.5"], clock, platform: "ios" });
const systemStats = new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 32 * gibibyte,
totalRamBytes: 32 * gibibyte,
});
const beforeRegistry = await Registry.load({
Expand Down Expand Up @@ -2047,7 +2045,6 @@ describe("LeaseEngine fresh lease identity (#75)", () => {
registry,
systemStats: new FakeSystemStats({
cpuCount: 8,
freeRamBytes: 32 * gibibyte,
totalRamBytes: 32 * gibibyte,
}),
});
Expand Down
Loading
Loading