From 7985fdce04edc071d44de99a54731ff2d49c8986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 28 Nov 2026 08:48:49 +0100 Subject: [PATCH 1/3] test: dedupe lease admission tests Co-Authored-By: Claude Sonnet 5.5 --- .../__tests__/index-lease-admission.test.ts | 10 +- .../cli-lease-admission-proxy.test.ts | 212 ++++-------------- src/__tests__/cli-lease-admission.test.ts | 146 ++++++------ 3 files changed, 119 insertions(+), 249 deletions(-) diff --git a/packages/daemon-client/src/__tests__/index-lease-admission.test.ts b/packages/daemon-client/src/__tests__/index-lease-admission.test.ts index a510e771bd..1560a57d94 100644 --- a/packages/daemon-client/src/__tests__/index-lease-admission.test.ts +++ b/packages/daemon-client/src/__tests__/index-lease-admission.test.ts @@ -3,11 +3,13 @@ import path from 'node:path'; import { expect, test } from 'vitest'; import { closeLoopbackServer, listenOnLoopback, mkdtempForTestSync } from '@agent-device/test-kit'; import { DAEMON_HTTP_INSTANCE_MISMATCH_HEADER } from '@agent-device/contracts/daemon-http'; -import { sendToDaemon } from '../index.ts'; +import { LeaseAdmissionUnsupportedError } from '@agent-device/daemon-contracts/daemon-resolution'; +import { createEnsuredDaemonTransport } from '../index.ts'; // A request whose reused lease no heartbeat checked reads `lease-admission` from the `/health` gate // it already passes, so it costs `/health` and `/rpc` and nothing more. Without the capability it is -// refused before the send, so the caller can fall back to its heartbeat. +// refused before the send. The CLI falls back to its heartbeat on that refusal's class alone, so +// these requests go through the CLI's transport. const LEASE_ADMISSION = ['script-artifacts', 'lease-admission']; @@ -29,7 +31,7 @@ async function sendAdmissionChecked( }); const root = mkdtempForTestSync('lease-admission-'); try { - const result = await sendToDaemon( + const result = await createEnsuredDaemonTransport()( { command: 'snapshot', session: 'remote', @@ -88,6 +90,7 @@ test.each([ ])('a $name is refused before the send', async ({ health }) => { const { result, routes } = await sendAdmissionChecked(() => health); + expect(result).toBeInstanceOf(LeaseAdmissionUnsupportedError); expect(result).toMatchObject({ code: 'UNSUPPORTED_OPERATION', details: { reason: 'lease_admission_unsupported', daemonRequestSent: false, dispatched: 'no' }, @@ -116,6 +119,7 @@ test.each([ }, ); + expect(result).toBeInstanceOf(LeaseAdmissionUnsupportedError); expect(result).toMatchObject({ details: { reason: 'lease_admission_unsupported', daemonRequestSent: false, dispatched: 'no' }, }); diff --git a/src/__tests__/cli-lease-admission-proxy.test.ts b/src/__tests__/cli-lease-admission-proxy.test.ts index e0777941e2..149f80a901 100644 --- a/src/__tests__/cli-lease-admission-proxy.test.ts +++ b/src/__tests__/cli-lease-admission-proxy.test.ts @@ -1,10 +1,8 @@ import assert from 'node:assert/strict'; import fs from 'node:fs'; -import http from 'node:http'; import path from 'node:path'; import { test } from 'vitest'; import { createDaemonProxyServer } from '@agent-device/proxy'; -import { DAEMON_HTTP_INSTANCE_MISMATCH_HEADER } from '@agent-device/contracts/daemon-http'; import { closeLoopbackServer, listenOnLoopback, @@ -36,42 +34,18 @@ const LEASE_SCOPE = { test('a lease the daemon dropped is reallocated through the proxy without a heartbeat', async (t) => { if (await skipWhenLoopbackUnavailable(t)) return; - const { root, home, project } = makeTempWorkspace(); - const daemon = await startPublicDaemonRuntime({ - serverMode: 'http', - env: { AGENT_DEVICE_ANDROID_DEVICE_ALLOWLIST: 'emulator-9999' }, - }); - const upstream: string[] = []; - const proxy = createDaemonProxyServer({ - upstreamBaseUrl: daemon.baseUrl, - upstreamToken: daemon.runtime.token, - clientToken: 'client-secret', - upstreamFetch: async (request) => { - upstream.push(await describe(request)); - return await fetch(request); - }, - }); - try { - const baseUrl = `http://127.0.0.1:${await listenOnLoopback(proxy)}/agent-device`; + await withProxiedDaemon(async ({ baseUrl, project, stateDir, upstream, cli }) => { const client = createAgentDeviceClient({ daemonBaseUrl: baseUrl, daemonAuthToken: 'client-secret', daemonTransport: 'http', }); const lease = await client.leases.allocate({ ...LEASE_SCOPE, leaseId: 'b'.repeat(32) }); - const stateDir = path.join(root, 'state'); writeConnection(stateDir, project, baseUrl, lease.leaseId); await client.leases.release({ ...LEASE_SCOPE, leaseId: lease.leaseId }); upstream.length = 0; - const result = await runCliCapture( - ['snapshot', '--session', 'agent', '--state-dir', stateDir, '--json'], - { - cwd: project, - env: { HOME: home, AGENT_DEVICE_DAEMON_AUTH_TOKEN: 'client-secret' }, - useRealDaemonClient: true, - }, - ); + const result = await cli(['snapshot']); const reallocated = readRemoteConnectionState({ stateDir, session: 'agent' })?.leaseId; assert.ok(reallocated && reallocated !== lease.leaseId, result.stdout); @@ -84,35 +58,13 @@ test('a lease the daemon dropped is reallocated through the proxy without a hear if (result.code !== null) { assert.notEqual(JSON.parse(result.stdout).error.details?.reason, 'LEASE_NOT_FOUND'); } - } finally { - await closeLoopbackServer(proxy); - await daemon.close(); - fs.rmSync(root, { recursive: true, force: true }); - } + }); }); -// A checked connection keeps the one checked request for a command that checks no lease. A command on -// the connection's reused lease reads `lease-admission` from `/health`, so it goes on `/rpc`. -test('a checked connection sends a reused-lease command health-first and without a heartbeat', async (t) => { +// A reused lease on the connection does not move a command that checks no lease off the checked route. +test('a checked connection sends a command that checks no lease as its one checked request', async (t) => { if (await skipWhenLoopbackUnavailable(t)) return; - const { root, home, project } = makeTempWorkspace(); - const daemon = await startPublicDaemonRuntime({ - serverMode: 'http', - env: { AGENT_DEVICE_ANDROID_DEVICE_ALLOWLIST: 'emulator-9999' }, - }); - const upstream: string[] = []; - const proxy = createDaemonProxyServer({ - upstreamBaseUrl: daemon.baseUrl, - upstreamToken: daemon.runtime.token, - clientToken: 'client-secret', - upstreamFetch: async (request) => { - upstream.push(await describe(request)); - return await fetch(request); - }, - }); - try { - const baseUrl = `http://127.0.0.1:${await listenOnLoopback(proxy)}/agent-device`; - const stateDir = path.join(root, 'state'); + await withProxiedDaemon(async ({ baseUrl, project, stateDir, upstream, cli }) => { const remoteConfigPath = path.join(project, 'checked.remote.json'); fs.writeFileSync( remoteConfigPath, @@ -127,136 +79,64 @@ test('a checked connection sends a reused-lease command health-first and without platform: 'android', }), ); - const cli = async (argv: string[]) => - await runCliCapture([...argv, '--session', 'agent', '--state-dir', stateDir, '--json'], { - cwd: project, - env: { HOME: home, AGENT_DEVICE_DAEMON_AUTH_TOKEN: 'client-secret' }, - useRealDaemonClient: true, - }); const connected = await cli(['connect', '--remote-config', remoteConfigPath]); assert.equal(connected.code, null, connected.stdout); const state = readRemoteConnectionState({ stateDir, session: 'agent' }); assert.ok(state?.daemon?.checkedRpcTarget, connected.stdout); - - // The lease comes from the daemon directly, so this process holds no `/health` for the proxy. - const direct = createAgentDeviceClient({ - daemonBaseUrl: daemon.baseUrl, - daemonAuthToken: daemon.runtime.token, - daemonTransport: 'http', - }); - const lease = await direct.leases.allocate({ ...LEASE_SCOPE, leaseId: 'c'.repeat(32) }); writeRemoteConnectionState({ stateDir, - state: { ...state, leaseId: lease.leaseId, deviceKey: LEASE_SCOPE.deviceKey }, + state: { ...state, leaseId: 'c'.repeat(32), deviceKey: LEASE_SCOPE.deviceKey }, }); upstream.length = 0; const listed = await cli(['session', 'list']); assert.equal(listed.code, null, listed.stdout); assert.deepEqual(upstream, ['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/rpc/checked session_list']); + }); +}); - upstream.length = 0; - await cli(['snapshot']); - // No device answers, so the failed command also reads its diagnostics record. - assert.deepEqual( - upstream.filter((route) => !route.startsWith('/sessions/')), - ['/health', '/rpc snapshot'], - ); +type ProxiedDaemon = Readonly<{ + /** The proxy's base URL, which the CLI and the SDK client reach with `client-secret`. */ + baseUrl: string; + project: string; + stateDir: string; + /** What the proxy forwarded to the daemon: the path, and for an RPC its method or command. */ + upstream: string[]; + cli: (argv: string[]) => ReturnType; +}>; + +/** Runs `use` against a real daemon behind a real proxy, with an empty CLI workspace. */ +async function withProxiedDaemon(use: (proxied: ProxiedDaemon) => Promise) { + const { root, home, project } = makeTempWorkspace(); + const daemon = await startPublicDaemonRuntime({ + serverMode: 'http', + env: { AGENT_DEVICE_ANDROID_DEVICE_ALLOWLIST: 'emulator-9999' }, + }); + const upstream: string[] = []; + const proxy = createDaemonProxyServer({ + upstreamBaseUrl: daemon.baseUrl, + upstreamToken: daemon.runtime.token, + clientToken: 'client-secret', + upstreamFetch: async (request) => { + upstream.push(await describe(request)); + return await fetch(request); + }, + }); + try { + const baseUrl = `http://127.0.0.1:${await listenOnLoopback(proxy)}/agent-device`; + const stateDir = path.join(root, 'state'); + const cli = async (argv: string[]) => + await runCliCapture([...argv, '--session', 'agent', '--state-dir', stateDir, '--json'], { + cwd: project, + env: { HOME: home, AGENT_DEVICE_DAEMON_AUTH_TOKEN: 'client-secret' }, + useRealDaemonClient: true, + }); + await use({ baseUrl, project, stateDir, upstream, cli }); } finally { await closeLoopbackServer(proxy); await daemon.close(); fs.rmSync(root, { recursive: true, force: true }); } -}); - -// A proxy that names no upstream daemon cannot say whose admission would check the lease: the next -// request carries only the proxy's own instance fence. -test.for([ - { path: 'the first health check', replaced: false, rpcs: ['heartbeat', 'snapshot'] }, - // The first send is refused before dispatch for its stale instance, so only the second one runs. - { - path: 'the refresh after an instance mismatch', - replaced: true, - rpcs: ['snapshot', 'heartbeat', 'snapshot'], - }, -])( - 'a proxy answer with no upstream on $path gets the heartbeat before the command', - async ({ replaced, rpcs }, context) => { - if (await skipWhenLoopbackUnavailable(context)) return; - const { root, home, project } = makeTempWorkspace(); - const proxy = await proxyWithoutUpstream(replaced); - try { - const stateDir = path.join(root, 'state'); - writeConnection(stateDir, project, proxy.baseUrl, 'd'.repeat(32)); - - const result = await runCliCapture( - ['snapshot', '--session', 'agent', '--state-dir', stateDir, '--json'], - { - cwd: project, - env: { HOME: home, AGENT_DEVICE_DAEMON_AUTH_TOKEN: 'client-secret' }, - useRealDaemonClient: true, - }, - ); - - assert.equal(result.code, null, result.stdout); - assert.deepEqual(proxy.rpcs, rpcs); - } finally { - await proxy.close(); - fs.rmSync(root, { recursive: true, force: true }); - } - }, -); - -/** - * A remote whose `/health` is a proxy's with a top-level `lease-admission` and no upstream. With - * `replaced`, it first names an upstream daemon and refuses the first RPC for its stale instance. - */ -async function proxyWithoutUpstream(replaced: boolean) { - const capabilities = ['script-artifacts', 'lease-admission']; - let named = replaced; - const rpcs: string[] = []; - const server = http.createServer((req, res) => { - res.setHeader('content-type', 'application/json'); - if (req.url === '/health') { - const link = named - ? { upstream: { service: 'agent-device-daemon', instanceId: 'daemon-1', capabilities } } - : { capabilities }; - res.end( - JSON.stringify({ - ok: true, - service: 'agent-device-proxy', - instanceId: named ? 'proxy-1' : 'proxy-2', - ...link, - }), - ); - return; - } - let body = ''; - req.on('data', (chunk) => (body += chunk)); - req.on('end', () => { - const { id, method, params } = JSON.parse(body); - rpcs.push(method === 'agent_device.lease.heartbeat' ? 'heartbeat' : params.command); - if (named) { - named = false; - res.statusCode = 409; - res.setHeader(DAEMON_HTTP_INSTANCE_MISMATCH_HEADER, 'true'); - const error = { code: -32000, message: 'stale instance' }; - res.end(JSON.stringify({ jsonrpc: '2.0', id, error })); - return; - } - const lease = { - leaseId: params.leaseId, - tenantId: LEASE_SCOPE.tenant, - runId: LEASE_SCOPE.runId, - backend: LEASE_SCOPE.leaseBackend, - }; - const data = - method === 'agent_device.lease.heartbeat' ? { lease } : { nodes: [], truncated: false }; - res.end(JSON.stringify({ jsonrpc: '2.0', id, result: { ok: true, data } })); - }); - }); - const baseUrl = `http://127.0.0.1:${await listenOnLoopback(server)}`; - return { baseUrl, rpcs, close: () => closeLoopbackServer(server) }; } async function describe(request: Request): Promise { diff --git a/src/__tests__/cli-lease-admission.test.ts b/src/__tests__/cli-lease-admission.test.ts index 1cd69acbec..9b5f6a0ccf 100644 --- a/src/__tests__/cli-lease-admission.test.ts +++ b/src/__tests__/cli-lease-admission.test.ts @@ -15,7 +15,11 @@ import { type RemoteConnectionState, } from '@agent-device/remote/remote-connection-state'; import { prepareMetroRuntime } from '@agent-device/react-native'; -import { runCliCapture, type CapturedDaemonRequest } from './cli-capture.ts'; +import { + runCliCapture, + type CapturedDaemonRequest, + type CliCaptureOptions, +} from './cli-capture.ts'; import { metroPrepareResult } from './remote-connection.fixtures.ts'; vi.mock('@agent-device/react-native', async (importOriginal) => ({ @@ -119,13 +123,17 @@ function admissionRefusal(dispatched?: DispatchDisclosure): AppError { }); } -async function run(ws: Workspace, argv: string[], daemon: Daemon) { +async function run( + ws: Workspace, + argv: string[], + sendToDaemon: NonNullable, +) { return await runCliCapture( [...argv, '--session', 'agent', '--state-dir', ws.stateDir, '--json'], { cwd: ws.project, env: { HOME: ws.home }, - sendToDaemon: transportTo(daemon), + sendToDaemon, }, ); } @@ -145,7 +153,7 @@ test.each([ ['a proxy open on the stored device', ['open', 'com.example'], 'open'], ])('%s reaches a lease-admission daemon without a heartbeat', async (_name, argv, command) => { const ws = workspace(); - const result = await run(ws, argv, { leaseAdmission: true }); + const result = await run(ws, argv, transportTo({ leaseAdmission: true })); assert.equal(result.code, null, result.stdout); assert.deepEqual(commandsOf(result), [command]); @@ -159,7 +167,7 @@ test.each([ test('a daemon without lease admission gets the heartbeat, then the command once more', async () => { const ws = workspace(); - const result = await run(ws, ['snapshot'], { leaseAdmission: false }); + const result = await run(ws, ['snapshot'], transportTo({ leaseAdmission: false })); assert.equal(result.code, null, result.stdout); assert.deepEqual(commandsOf(result), ['snapshot', 'lease_heartbeat', 'snapshot']); @@ -169,25 +177,38 @@ test('a daemon without lease admission gets the heartbeat, then the command once fs.rmSync(ws.root, { recursive: true, force: true }); }); -test('a lease refused at admission is reallocated and the command is sent once more', async () => { - const ws = workspace(); - const result = await run(ws, ['snapshot'], { - leaseAdmission: true, - refusal: () => admissionRefusal('no'), - }); - - assert.equal(result.code, null, result.stdout); - assert.deepEqual(commandsOf(result), ['snapshot', 'lease_allocate', 'snapshot']); - const allocated = scopeOf(result.calls[1], 'leaseId'); - assert.notEqual(allocated, STORED_LEASE); - assert.equal(scopeOf(result.calls[2], 'leaseId'), allocated); - assert.equal( - readRemoteConnectionState({ stateDir: ws.stateDir, session: 'agent' })?.leaseId, - allocated, - ); +test.each([ + ['succeeds', false], + ['is refused again and not sent a third time', true], +])( + 'a lease refused at admission is reallocated and the resent command %s', + async (_name, refusedAgain) => { + const ws = workspace(); + const admits = transportTo({ leaseAdmission: true }); + const result = await run(ws, ['snapshot'], async (req) => { + const refused = refusedAgain || scopeOf(req, 'leaseId') === STORED_LEASE; + if (refused && req.command !== 'lease_allocate') throw admissionRefusal('no'); + return await admits(req); + }); + + assert.equal(result.code, refusedAgain ? 1 : null, result.stdout); + assert.deepEqual(commandsOf(result), ['snapshot', 'lease_allocate', 'snapshot']); + const allocated = scopeOf(result.calls[1], 'leaseId'); + assert.notEqual(allocated, STORED_LEASE); + assert.equal(scopeOf(result.calls[2], 'leaseId'), allocated); + assert.equal( + readRemoteConnectionState({ stateDir: ws.stateDir, session: 'agent' })?.leaseId, + allocated, + ); + if (refusedAgain) { + const details = JSON.parse(result.stdout).error.details; + assert.equal(details.reason, 'LEASE_NOT_FOUND'); + assert.equal(details.dispatched, 'no'); + } - fs.rmSync(ws.root, { recursive: true, force: true }); -}); + fs.rmSync(ws.root, { recursive: true, force: true }); + }, +); test.each([ ['an inactive-lease refusal without dispatch disclosure', () => admissionRefusal(), {}], @@ -222,7 +243,7 @@ test.each([ ], ])('%s is never resent', async (_name, refusal, expected) => { const ws = workspace(); - const result = await run(ws, ['snapshot'], { leaseAdmission: true, refusal }); + const result = await run(ws, ['snapshot'], transportTo({ leaseAdmission: true, refusal })); assert.equal(result.code, 1, result.stdout); assert.deepEqual(commandsOf(result), ['snapshot']); @@ -236,7 +257,11 @@ test.each([ // A `close` ends the connection's session, so no lease is rented or renewed for it. test('a close refused for an inactive lease allocates nothing and is not resent', async () => { const ws = workspace(); - const result = await run(ws, ['close'], { leaseAdmission: true, refusal: admissionRefusal }); + const result = await run( + ws, + ['close'], + transportTo({ leaseAdmission: true, refusal: admissionRefusal }), + ); assert.equal(result.code, 1, result.stdout); assert.deepEqual(commandsOf(result), ['close']); @@ -246,29 +271,6 @@ test('a close refused for an inactive lease allocates nothing and is not resent' fs.rmSync(ws.root, { recursive: true, force: true }); }); -test('a resent command refused again is not sent a third time', async () => { - const ws = workspace(); - const result = await runCliCapture( - ['snapshot', '--session', 'agent', '--state-dir', ws.stateDir, '--json'], - { - cwd: ws.project, - env: { HOME: ws.home }, - sendToDaemon: async (req) => { - if (req.command === 'lease_allocate') return leaseAnswer(req); - throw admissionRefusal('no'); - }, - }, - ); - - assert.equal(result.code, 1, result.stdout); - assert.deepEqual(commandsOf(result), ['snapshot', 'lease_allocate', 'snapshot']); - const details = JSON.parse(result.stdout).error.details; - assert.equal(details.reason, 'LEASE_NOT_FOUND'); - assert.equal(details.dispatched, 'no'); - - fs.rmSync(ws.root, { recursive: true, force: true }); -}); - test.each<[string, string[], Partial]>([ [ 'a host-allocated macos-app lease', @@ -307,7 +309,7 @@ test.each<[string, string[], Partial]>([ ['a test run, which reads its scripts from paths', ['test', 'flow.ad'], {}], ])('%s keeps the heartbeat on a lease-admission daemon', async (_name, argv, connection) => { const ws = workspace(connection); - const result = await run(ws, argv, { leaseAdmission: true }); + const result = await run(ws, argv, transportTo({ leaseAdmission: true })); assert.equal(commandsOf(result)[0], 'lease_heartbeat', result.stdout); assert.equal(markedOf(result).includes(true), false); @@ -324,25 +326,18 @@ test('an open that prepares Metro replaces an ended lease before the bridge setu events.push(`prepare ${input.bridgeScope?.leaseId}`); return metroPrepareResult(); }); - const result = await runCliCapture( - ['open', 'com.example', '--session', 'agent', '--state-dir', ws.stateDir, '--json'], - { - cwd: ws.project, - env: { HOME: ws.home }, - sendToDaemon: async (req) => { - events.push(`${req.command} ${scopeOf(req, 'leaseId')}`); - if (req.command === 'lease_heartbeat') throw admissionRefusal(); - // The by-spec allocation names no device; the lease answer does. - if (req.command === 'lease_allocate') { - return leaseAnswer({ - ...req, - meta: { ...req.meta, deviceKey: 'android:mobile:emulator-5554' }, - }); - } - return { ok: true, data: { session: req.session } }; - }, - }, - ); + const result = await run(ws, ['open', 'com.example'], async (req) => { + events.push(`${req.command} ${scopeOf(req, 'leaseId')}`); + if (req.command === 'lease_heartbeat') throw admissionRefusal(); + // The by-spec allocation names no device; the lease answer does. + if (req.command === 'lease_allocate') { + return leaseAnswer({ + ...req, + meta: { ...req.meta, deviceKey: 'android:mobile:emulator-5554' }, + }); + } + return { ok: true, data: { session: req.session } }; + }); assert.equal(result.code, null, result.stdout); const live = readRemoteConnectionState({ stateDir: ws.stateDir, session: 'agent' })?.leaseId; @@ -361,18 +356,9 @@ test('a lease scope refusal arrives before fill --text-stdin reads the pipe', as const pipe = Readable.from(['piped-secret']); const stdin = vi.spyOn(process, 'stdin', 'get').mockReturnValue(pipe as typeof process.stdin); const ws = workspace(); - const result = await runCliCapture( - ['fill', '@e3', '--text-stdin', '--session', 'agent', '--state-dir', ws.stateDir, '--json'], - { - cwd: ws.project, - env: { HOME: ws.home }, - sendToDaemon: async () => { - throw new AppError('UNAUTHORIZED', 'Lease scope mismatch', { - reason: 'LEASE_SCOPE_MISMATCH', - }); - }, - }, - ); + const result = await run(ws, ['fill', '@e3', '--text-stdin'], async () => { + throw new AppError('UNAUTHORIZED', 'Lease scope mismatch', { reason: 'LEASE_SCOPE_MISMATCH' }); + }); stdin.mockRestore(); assert.equal(result.code, 1, result.stdout); From 8ca1819f121408c290d197203e409a6bde2c04e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 28 Nov 2026 08:52:26 +0100 Subject: [PATCH 2/3] test: rename the proxied-daemon callback off the hook name Co-Authored-By: Claude Opus 5.5 --- src/__tests__/cli-lease-admission-proxy.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/__tests__/cli-lease-admission-proxy.test.ts b/src/__tests__/cli-lease-admission-proxy.test.ts index 149f80a901..aafabca1a3 100644 --- a/src/__tests__/cli-lease-admission-proxy.test.ts +++ b/src/__tests__/cli-lease-admission-proxy.test.ts @@ -105,8 +105,8 @@ type ProxiedDaemon = Readonly<{ cli: (argv: string[]) => ReturnType; }>; -/** Runs `use` against a real daemon behind a real proxy, with an empty CLI workspace. */ -async function withProxiedDaemon(use: (proxied: ProxiedDaemon) => Promise) { +/** Runs `run` against a real daemon behind a real proxy, with an empty CLI workspace. */ +async function withProxiedDaemon(run: (proxied: ProxiedDaemon) => Promise) { const { root, home, project } = makeTempWorkspace(); const daemon = await startPublicDaemonRuntime({ serverMode: 'http', @@ -131,7 +131,7 @@ async function withProxiedDaemon(use: (proxied: ProxiedDaemon) => Promise) env: { HOME: home, AGENT_DEVICE_DAEMON_AUTH_TOKEN: 'client-secret' }, useRealDaemonClient: true, }); - await use({ baseUrl, project, stateDir, upstream, cli }); + await run({ baseUrl, project, stateDir, upstream, cli }); } finally { await closeLoopbackServer(proxy); await daemon.close(); From 35eae2c874435010eaaa12176af4b5e6c65b6220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 28 Nov 2026 10:05:32 +0100 Subject: [PATCH 3/3] test: drive the host-bound transport in lease admission tests Co-Authored-By: Claude Opus 5.5 --- .../src/__tests__/index-lease-admission.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/daemon-client/src/__tests__/index-lease-admission.test.ts b/packages/daemon-client/src/__tests__/index-lease-admission.test.ts index 1560a57d94..d37011d01a 100644 --- a/packages/daemon-client/src/__tests__/index-lease-admission.test.ts +++ b/packages/daemon-client/src/__tests__/index-lease-admission.test.ts @@ -1,7 +1,12 @@ import http from 'node:http'; import path from 'node:path'; import { expect, test } from 'vitest'; -import { closeLoopbackServer, listenOnLoopback, mkdtempForTestSync } from '@agent-device/test-kit'; +import { + closeLoopbackServer, + createTestHostEnvironment, + listenOnLoopback, + mkdtempForTestSync, +} from '@agent-device/test-kit'; import { DAEMON_HTTP_INSTANCE_MISMATCH_HEADER } from '@agent-device/contracts/daemon-http'; import { LeaseAdmissionUnsupportedError } from '@agent-device/daemon-contracts/daemon-resolution'; import { createEnsuredDaemonTransport } from '../index.ts'; @@ -31,7 +36,7 @@ async function sendAdmissionChecked( }); const root = mkdtempForTestSync('lease-admission-'); try { - const result = await createEnsuredDaemonTransport()( + const result = await createEnsuredDaemonTransport({ host: createTestHostEnvironment() })( { command: 'snapshot', session: 'remote',