Skip to content

Commit e0f8c55

Browse files
authored
refactor(move): move managed device allocation into its own workspace package (#2316) (#2321)
* refactor(move): move managed device allocation into its own workspace package (#2316) * chore(gates): unrank the managed-allocation zone, declare its durable-json seam, and ignore its unconsumed root dependency (#2316)
1 parent 80997b6 commit e0f8c55

45 files changed

Lines changed: 236 additions & 38 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.fallowrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
// @agent-device/provider-limrun owns the source import, while the published
5757
// root build externalizes @limrun/api and retains runtime imports in packed chunks.
5858
"@limrun/api",
59+
// @agent-device/managed-allocation has no root consumer yet: the managed runtime binding
60+
// (ADR 0021 §3) is its first, and it lands after the package's move out of src/daemon.
61+
"@agent-device/managed-allocation",
5962
// Oxlint resolves the shared config's JS plugins dynamically from their package names.
6063
"@nkzw/eslint-plugin",
6164
"eslint-plugin-no-only-tests",

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
"check:unit": "pnpm test:unit && pnpm check:tmpdir-leaks && pnpm test:smoke",
168168
"check": "pnpm check:tooling && pnpm check:fallow && pnpm check:unit",
169169
"prepack": "pnpm check:mcp-metadata && pnpm package:npm",
170-
"typecheck": "tsc -b packages/xml packages/kernel packages/contracts packages/host-kit packages/capture-kit packages/provision-kit packages/platform-apple packages/platform-android packages/platform-harmonyos packages/platform-vega packages/platform-linux packages/platform-web packages/ad-script packages/selectors packages/ad-replay packages/maestro packages/replay-test packages/provider-webdriver packages/provider-limrun && tsc -p tsconfig.json && tsc -p examples/sdk/tsconfig.json",
170+
"typecheck": "tsc -b packages/xml packages/kernel packages/contracts packages/host-kit packages/capture-kit packages/managed-allocation packages/provision-kit packages/platform-apple packages/platform-android packages/platform-harmonyos packages/platform-vega packages/platform-linux packages/platform-web packages/ad-script packages/selectors packages/ad-replay packages/maestro packages/replay-test packages/provider-webdriver packages/provider-limrun && tsc -p tsconfig.json && tsc -p examples/sdk/tsconfig.json",
171171
"test-app:install": "pnpm install --dir examples/test-app",
172172
"test-app:start": "pnpm --dir examples/test-app start",
173173
"test-app:ios": "pnpm --dir examples/test-app ios",
@@ -280,6 +280,7 @@
280280
"@agent-device/contracts": "workspace:*",
281281
"@agent-device/host-kit": "workspace:*",
282282
"@agent-device/kernel": "workspace:*",
283+
"@agent-device/managed-allocation": "workspace:*",
283284
"@agent-device/maestro": "workspace:*",
284285
"@agent-device/platform-android": "workspace:*",
285286
"@agent-device/platform-apple": "workspace:*",

packages/capture-kit/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
"types": "./src/index.ts",
1515
"default": "./src/index.ts"
1616
},
17+
"./durable-json": {
18+
"types": "./src/durable-json.ts",
19+
"default": "./src/durable-json.ts"
20+
},
1721
"./ios-snapshot-acquisition": {
1822
"types": "./src/ios-snapshot-acquisition.ts",
1923
"default": "./src/ios-snapshot-acquisition.ts"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "@agent-device/managed-allocation",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"description": "Private managed-device allocation-operation mechanics composed by the daemon: durable allocation-operation store, recovery journal, decision policy, and record codec for the Simlock-backed lease handoff (ADR 0021).",
7+
"dependencies": {
8+
"@agent-device/capture-kit": "workspace:*",
9+
"@agent-device/contracts": "workspace:*",
10+
"@agent-device/host-kit": "workspace:*",
11+
"@agent-device/kernel": "workspace:*"
12+
},
13+
"exports": {
14+
"./decision": {
15+
"types": "./src/decision.ts",
16+
"default": "./src/decision.ts"
17+
},
18+
"./fence": {
19+
"types": "./src/fence.ts",
20+
"default": "./src/fence.ts"
21+
},
22+
"./journal": {
23+
"types": "./src/journal.ts",
24+
"default": "./src/journal.ts"
25+
},
26+
"./record": {
27+
"types": "./src/record.ts",
28+
"default": "./src/record.ts"
29+
},
30+
"./schema": {
31+
"types": "./src/schema.ts",
32+
"default": "./src/schema.ts"
33+
},
34+
"./status": {
35+
"types": "./src/status.ts",
36+
"default": "./src/status.ts"
37+
},
38+
"./store": {
39+
"types": "./src/store.ts",
40+
"default": "./src/store.ts"
41+
},
42+
"./transitions": {
43+
"types": "./src/transitions.ts",
44+
"default": "./src/transitions.ts"
45+
}
46+
}
47+
}

src/daemon/managed-device-allocation/__tests__/decision.test.ts renamed to packages/managed-allocation/src/__tests__/decision.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from 'node:assert/strict';
22
import { test } from 'vitest';
3-
import { newAllocationOperation } from '../record-factory.ts';
3+
import { newAllocationOperation } from '../record.ts';
44
import { applyAllocationTransition } from '../transitions.ts';
55
import { decideAllocationAction } from '../decision.ts';
66
import { ALLOCATION_LEASE, ALLOCATION_REQUEST } from './fixtures.ts';

src/daemon/managed-device-allocation/__tests__/fixtures.ts renamed to packages/managed-allocation/src/__tests__/fixtures.ts

File renamed without changes.

src/daemon/managed-device-allocation/__tests__/journal.test.ts renamed to packages/managed-allocation/src/__tests__/journal.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import type {
77
ManagedDeviceAllocatorPort,
88
SupersedeLeaseRequestInput,
99
} from '@agent-device/contracts/managed-device-allocation';
10-
import type { ScriptedAllocatorMethod } from '../../../__tests__/test-utils/managed-device-allocator.fixtures.ts';
11-
import { createScriptedManagedDeviceAllocator } from '../../../__tests__/test-utils/managed-device-allocator.fixtures.ts';
12-
import { mkdtempForTestSync } from '../../../__tests__/test-utils/tmp-dir.ts';
10+
import type { ScriptedAllocatorMethod } from './test-utils/managed-device-allocator.fixtures.ts';
11+
import { createScriptedManagedDeviceAllocator } from './test-utils/managed-device-allocator.fixtures.ts';
12+
import { mkdtempForTestSync } from './test-utils/tmp-dir.ts';
1313
import { createAllocationOperationJournal, type AllocationBindingHooks } from '../journal.ts';
1414
import { createAllocationOperationStore, type AllocationOperationStore } from '../store.ts';
1515
import {

src/daemon/managed-device-allocation/__tests__/record.test.ts renamed to packages/managed-allocation/src/__tests__/record.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import { test } from 'vitest';
33
import type { LeaseRequestStatus } from '@agent-device/contracts/managed-device-allocation';
44
import { managedBindingFence } from '@agent-device/contracts/platform-runtime';
55
import { AppError } from '@agent-device/kernel/errors';
6-
import { ALLOCATION_OPERATION_SCHEMA_VERSION, bindingFenceFor } from '../record.ts';
7-
import { newAllocationOperation } from '../record-factory.ts';
6+
import {
7+
ALLOCATION_OPERATION_SCHEMA_VERSION,
8+
bindingFenceFor,
9+
decodeAllocationOperationRecord,
10+
newAllocationOperation,
11+
type AllocationOperationRecord,
12+
type AllocationTransition,
13+
} from '../record.ts';
814
import { applyAllocationTransition } from '../transitions.ts';
9-
import type { AllocationOperationRecord, AllocationTransition } from '../record.ts';
10-
import { decodeAllocationOperationRecord } from '../record-codec.ts';
1115
import {
1216
ALLOCATION_GRANTED_STATUS,
1317
ALLOCATION_LEASE,

src/daemon/managed-device-allocation/__tests__/store.test.ts renamed to packages/managed-allocation/src/__tests__/store.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import path from 'node:path';
44
import { test, vi } from 'vitest';
55
import { acquireProcessLock } from '@agent-device/host-kit/file';
66
import { readCurrentOwnerIdentity } from '@agent-device/host-kit/process';
7-
import { mkdtempForTestSync } from '../../../__tests__/test-utils/tmp-dir.ts';
8-
import { newAllocationOperation } from '../record-factory.ts';
9-
import type { AllocationOperationRecord } from '../record.ts';
7+
import { mkdtempForTestSync } from './test-utils/tmp-dir.ts';
8+
import { newAllocationOperation, type AllocationOperationRecord } from '../record.ts';
109
import { createAllocationOperationStore, type AllocationOperationStore } from '../store.ts';
1110
import { ALLOCATION_LEASE, ALLOCATION_REQUEST } from './fixtures.ts';
1211

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import type { ManagedDeviceAllocatorPort } from '@agent-device/contracts/managed-device-allocation';
2+
3+
export type ScriptedAllocatorMethod = keyof Omit<ManagedDeviceAllocatorPort, 'instanceId'>;
4+
5+
export type ScriptedAllocatorCall = Readonly<{
6+
method: ScriptedAllocatorMethod;
7+
input: unknown;
8+
}>;
9+
10+
export type ScriptedManagedDeviceAllocator = ManagedDeviceAllocatorPort &
11+
Readonly<{ calls: ScriptedAllocatorCall[] }>;
12+
13+
/**
14+
* The only implementation of the allocator port in the foundations: it replays one scripted step
15+
* per call, in the order the script lists them for that method, and refuses a call the script did
16+
* not anticipate. No transport, no timers, and no lifecycle rules of its own — a test that wants
17+
* an allocator behavior states it as a step.
18+
*/
19+
export function createScriptedManagedDeviceAllocator(
20+
options: {
21+
instanceId?: string;
22+
script?: Partial<Record<ScriptedAllocatorMethod, readonly unknown[]>>;
23+
} = {},
24+
): ScriptedManagedDeviceAllocator {
25+
const calls: ScriptedAllocatorCall[] = [];
26+
const remaining = new Map<ScriptedAllocatorMethod, unknown[]>(
27+
Object.entries(options.script ?? {}).map(([method, steps]) => [
28+
method as ScriptedAllocatorMethod,
29+
[...(steps ?? [])],
30+
]),
31+
);
32+
const next = async <Result>(method: ScriptedAllocatorMethod, input: unknown): Promise<Result> => {
33+
calls.push(Object.freeze({ method, input }));
34+
const steps = remaining.get(method) ?? [];
35+
if (steps.length === 0) throw new Error(`Unscripted allocator call: ${method}`);
36+
const step = steps.shift();
37+
if (step instanceof Error) throw step;
38+
return step as Result;
39+
};
40+
return Object.freeze({
41+
instanceId: options.instanceId ?? 'scripted-allocator',
42+
calls,
43+
requestLease: async (input) => await next('requestLease', input),
44+
getLeaseRequestStatus: async (request) => await next('getLeaseRequestStatus', request),
45+
supersedeLeaseRequest: async (input) => await next('supersedeLeaseRequest', input),
46+
cancelLeaseRequest: async (request) => await next('cancelLeaseRequest', request),
47+
renewLease: async (input) => await next('renewLease', input),
48+
releaseLease: async (input) => await next('releaseLease', input),
49+
confirmLeaseActivation: async (proof) => await next('confirmLeaseActivation', proof),
50+
getManagedIdentityStatus: async (identity) => await next('getManagedIdentityStatus', identity),
51+
acknowledgeManagedIdentityRemoval: async (identity) =>
52+
await next('acknowledgeManagedIdentityRemoval', identity),
53+
});
54+
}

0 commit comments

Comments
 (0)