Skip to content

Commit 6c6437e

Browse files
committed
test: restore production coverage for daemon export sweep
1 parent 1908337 commit 6c6437e

33 files changed

Lines changed: 456 additions & 432 deletions

‎packages/daemon/src/execution/interaction/internal/interaction-touch-routing.test.ts‎

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
mockHoverRef,
1414
mockLongPressPoint,
1515
mockTapPoint,
16+
mockTypeText,
1617
resetGetRuntimeFixture,
1718
runtimeBindingSpies,
1819
} from '../../__tests__/interaction-get-runtime-fixture.ts';
@@ -237,7 +238,69 @@ test('hover @ref on web dispatches through the provider hoverRef route, not coor
237238
});
238239
expect(mockHoverRef).toHaveBeenCalledWith(expect.objectContaining({ ref: '@e1' }));
239240
expect(mockHoverPoint).not.toHaveBeenCalled();
240-
expect(sessionStore.get(sessionName)?.actions[0]?.command).toBe('hover');
241+
const hoverAction = sessionStore.get(sessionName)?.actions[0];
242+
expect(hoverAction?.command).toBe('hover');
243+
expect(hoverAction?.result).toMatchObject({ ref: 'e1', gesture: 'hover' });
244+
expect(hoverAction?.result).not.toHaveProperty('x');
245+
expect(hoverAction?.result).not.toHaveProperty('y');
246+
247+
const typeResponse = await handleInteractionCommands({
248+
createCommandSurface: touchCreateCommandSurface,
249+
req: {
250+
token: 't',
251+
session: sessionName,
252+
command: 'type',
253+
positionals: [' ok'],
254+
flags: {},
255+
},
256+
sessionName,
257+
sessionStore,
258+
contextFromFlags,
259+
...getRuntimeBindings(),
260+
});
261+
262+
expect(typeResponse?.ok).toBe(true);
263+
expect(mockTypeText).toHaveBeenCalledOnce();
264+
expect(sessionStore.get(sessionName)?.actions.at(-1)).toMatchObject({
265+
command: 'type',
266+
positionals: [' ok'],
267+
});
268+
});
269+
270+
test('click @ref on web records the ref result without fabricated coordinates', async () => {
271+
const sessionStore = makeSessionStore();
272+
const sessionName = 'click-ref';
273+
const session = makeSession(sessionName);
274+
session.device = WEB_DESKTOP_DEVICE;
275+
session.snapshot = {
276+
nodes: attachRefs([{ index: 0, role: 'link', label: 'Second message', enabled: true }]),
277+
createdAt: Date.now(),
278+
backend: 'web',
279+
};
280+
sessionStore.publish(sessionName, session);
281+
282+
const response = await handleInteractionCommands({
283+
createCommandSurface: touchCreateCommandSurface,
284+
req: {
285+
token: 't',
286+
session: sessionName,
287+
command: 'click',
288+
positionals: ['@e1'],
289+
flags: {},
290+
},
291+
sessionName,
292+
sessionStore,
293+
contextFromFlags,
294+
...getRuntimeBindings(),
295+
});
296+
297+
expect(response).toMatchObject({ ok: true, data: { ref: 'e1' } });
298+
const action = sessionStore.get(sessionName)?.actions[0];
299+
expect(action?.command).toBe('click');
300+
expect(action?.positionals).toEqual(['@e1']);
301+
expect(action?.result).toMatchObject({ ref: 'e1' });
302+
expect(action?.result).not.toHaveProperty('x');
303+
expect(action?.result).not.toHaveProperty('y');
241304
});
242305

243306
test('hover selector on web resolves the target and dispatches coordinate hover', async () => {

‎packages/daemon/src/server/http/http-server-provider-scenarios.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ test('Provider-backed integration daemon HTTP server accepts uploads and streams
525525
assert.equal(rejectedUpload.status, 401);
526526
} finally {
527527
await closeLoopbackServer(server);
528-
fs.rmSync(root, { recursive: true, force: true });
529528
}
530529
});
531530

@@ -818,7 +817,6 @@ test('Provider-backed integration daemon HTTP auth hook can scope tenants and re
818817
}
819818
if (previousHook === undefined) delete process.env.AGENT_DEVICE_HTTP_AUTH_HOOK;
820819
else process.env.AGENT_DEVICE_HTTP_AUTH_HOOK = previousHook;
821-
fs.rmSync(root, { recursive: true, force: true });
822820
}
823821
});
824822

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import type { DeviceInfo } from '@agent-device/kernel/device';
2+
import { buildAmbiguousMatchError } from '../../src/execution/selector-match-errors.ts';
3+
import { refMutationAdmissionResponse } from '../../src/execution/interaction/internal/interaction-ref-policy.ts';
4+
import { resolveRefStalenessWarning } from '../../src/execution/session-snapshot.ts';
5+
import { activateCompleteRefFrame, readRefMutationFrame } from '../../src/core/ref-frame.ts';
6+
import type { SessionState } from '../../src/core/session-state.ts';
7+
import { buildDeviceInUseBySessionError } from '../../src/core/session-recovery-hints.ts';
8+
import { buildDeviceClaimConflictError } from '../../src/resources/device/device-claim-conflict.ts';
9+
10+
function buildDaemonErrorSampleResponses() {
11+
const owningSession = {
12+
address: 'checkout',
13+
session: { name: 'checkout' } as SessionState,
14+
};
15+
const device = { id: 'SIM-001', name: 'iPhone 17 Pro' } as Parameters<
16+
typeof buildDeviceInUseBySessionError
17+
>[1];
18+
const deviceInUse = buildDeviceInUseBySessionError(owningSession, device);
19+
20+
const claimDevice: DeviceInfo = {
21+
platform: 'android',
22+
id: 'emulator-5554',
23+
name: 'Pixel',
24+
kind: 'emulator',
25+
};
26+
const deviceClaimInUse = buildDeviceClaimConflictError(claimDevice, {
27+
fileName: 'claim.json',
28+
deviceKey: 'local:android:none:emulator-5554',
29+
classification: 'live',
30+
claim: {
31+
schemaVersion: 2,
32+
deviceKey: 'local:android:none:emulator-5554',
33+
device: {
34+
family: 'android',
35+
id: 'emulator-5554',
36+
name: 'Pixel',
37+
kind: 'emulator',
38+
},
39+
session: 'checkout',
40+
workspace: '/worktrees/checkout',
41+
stateDir: '/state/checkout',
42+
ownerPid: 4242,
43+
ownerStartTime: 'start',
44+
ownerToken: 'token',
45+
createdAtMs: 1,
46+
updatedAtMs: 1,
47+
},
48+
});
49+
50+
const session = { snapshotGeneration: 7 } as SessionState;
51+
activateCompleteRefFrame(session);
52+
const ref = '@e12';
53+
const mintedGeneration = 5;
54+
const staleRef = refMutationAdmissionResponse({
55+
ref,
56+
mintedGeneration,
57+
staleRefsWarning: resolveRefStalenessWarning({ session, ref, mintedGeneration }),
58+
frame: readRefMutationFrame({ session, ref, mintedGeneration }),
59+
});
60+
if (!staleRef) throw new Error('Expected the stale ref producer to refuse the mutation');
61+
62+
const matches = [
63+
{ ref: 'e2', type: 'Button', label: 'Follow' },
64+
{ ref: 'e5', type: 'Button', label: 'Follow' },
65+
{ ref: 'e9', type: 'Button', label: 'Follow' },
66+
] as Parameters<typeof buildAmbiguousMatchError>[0];
67+
68+
return {
69+
deviceInUse,
70+
deviceClaimInUse,
71+
staleRef,
72+
ambiguousMatch: buildAmbiguousMatchError(matches, 'text', 'Follow'),
73+
};
74+
}
75+
76+
process.stdout.write(JSON.stringify(buildDaemonErrorSampleResponses()));

‎packages/daemon/test/nightly/concurrency-torture/envelope.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import crypto from 'node:crypto';
44
import fs from 'node:fs';
55
import path from 'node:path';
66
import { fileURLToPath } from 'node:url';
7-
import { laneEnvelope, type LaneEnvelope, type LaneResult } from './lane-envelope.ts';
7+
import { laneEnvelope, type LaneEnvelope, type LaneResult } from '@agent-device/test-kit';
88

99
const LANE_ID = 'concurrency-torture';
1010

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { readFileSync } from 'node:fs';
2+
import type { DaemonResponseData, ResponseLevel } from '@agent-device/kernel/contracts';
3+
import { RESPONSE_VIEWS } from '../../src/server/response-views.ts';
4+
5+
function responseView(
6+
command: string,
7+
data: DaemonResponseData,
8+
level: ResponseLevel,
9+
): DaemonResponseData {
10+
const view = RESPONSE_VIEWS[command];
11+
if (!view) throw new Error(`No daemon response view is registered for ${command}`);
12+
return view(data, level);
13+
}
14+
15+
function renderOutputEconomyResponseViews(fixtures: {
16+
snapshot: DaemonResponseData;
17+
settle: DaemonResponseData;
18+
settleTail: DaemonResponseData;
19+
selector: DaemonResponseData;
20+
screenshot: DaemonResponseData;
21+
network: DaemonResponseData;
22+
}) {
23+
return {
24+
snapshotDigest: responseView('snapshot', fixtures.snapshot, 'digest'),
25+
settleDigest: responseView('click', fixtures.settle, 'digest'),
26+
settleTailDigest: responseView('click', fixtures.settleTail, 'digest'),
27+
selectorDigest: responseView('get', fixtures.selector, 'digest'),
28+
screenshotDefault: responseView('screenshot', fixtures.screenshot, 'default'),
29+
screenshotDigest: responseView('screenshot', fixtures.screenshot, 'digest'),
30+
networkDigest: responseView('network', fixtures.network, 'digest'),
31+
};
32+
}
33+
34+
const fixtures = JSON.parse(readFileSync(0, 'utf8')) as Parameters<
35+
typeof renderOutputEconomyResponseViews
36+
>[0];
37+
process.stdout.write(JSON.stringify(renderOutputEconomyResponseViews(fixtures)));

‎packages/remote/src/__tests__/daemon-artifacts-directory.test.ts‎

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import assert from 'node:assert/strict';
22
import fs from 'node:fs';
3-
import http from 'node:http';
43
import path from 'node:path';
5-
import { gzipSync } from 'node:zlib';
64
import { test } from 'vitest';
7-
import * as tar from 'tar-stream';
85
import { AppError } from '@agent-device/kernel/errors';
96
import { downloadRemoteArtifact } from '../daemon-artifacts.ts';
7+
import {
8+
createArtifactDownloadServer,
9+
createDirectoryArtifactArchive,
10+
} from './support/artifact-download-fixtures.ts';
1011
import {
1112
closeLoopbackServer,
1213
listenOnLoopback,
@@ -16,49 +17,6 @@ import {
1617

1718
const SUITE_INVOCATION_ID = 'cd5f9c01feec8d70';
1819

19-
async function createDirectoryArtifactArchive(directoryPath: string): Promise<Buffer> {
20-
const pack = tar.pack();
21-
const rootName = path.basename(directoryPath);
22-
const visit = async (currentPath: string, archivePath: string): Promise<void> => {
23-
for (const entry of await fs.promises.readdir(currentPath, { withFileTypes: true })) {
24-
const sourcePath = path.join(currentPath, entry.name);
25-
const name = `${archivePath}/${entry.name}`;
26-
if (entry.isDirectory()) {
27-
await visit(sourcePath, name);
28-
} else if (entry.isSymbolicLink()) {
29-
pack.entry(
30-
{ name, type: 'symlink', linkname: await fs.promises.readlink(sourcePath) },
31-
Buffer.alloc(0),
32-
);
33-
} else if (entry.isFile()) {
34-
pack.entry({ name, type: 'file' }, await fs.promises.readFile(sourcePath));
35-
}
36-
}
37-
};
38-
await visit(directoryPath, rootName);
39-
pack.finalize();
40-
const chunks: Buffer[] = [];
41-
for await (const chunk of pack) chunks.push(Buffer.from(chunk));
42-
return gzipSync(Buffer.concat(chunks));
43-
}
44-
45-
function createArtifactDownloadServer(archives: ReadonlyMap<string, Buffer>): http.Server {
46-
return http.createServer((request, response) => {
47-
const prefix = '/artifacts/';
48-
const artifactId = request.url?.startsWith(prefix)
49-
? decodeURIComponent(request.url.slice(prefix.length))
50-
: undefined;
51-
const archive = request.method === 'GET' && artifactId ? archives.get(artifactId) : undefined;
52-
if (!archive) {
53-
response.statusCode = 404;
54-
response.end('not found');
55-
return;
56-
}
57-
response.setHeader('content-type', 'application/gzip');
58-
response.end(archive);
59-
});
60-
}
61-
6220
test('downloadRemoteArtifact extracts a directory artifact into the caller-local artifacts root', async (t) => {
6321
if (await skipWhenLoopbackUnavailable(t, 'remote test-artifacts directory download coverage'))
6422
return;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import fs from 'node:fs';
2+
import http from 'node:http';
3+
import path from 'node:path';
4+
import { gzipSync } from 'node:zlib';
5+
import * as tar from 'tar-stream';
6+
7+
export async function createDirectoryArtifactArchive(directoryPath: string): Promise<Buffer> {
8+
const pack = tar.pack();
9+
const rootName = path.basename(directoryPath);
10+
const visit = async (currentPath: string, archivePath: string): Promise<void> => {
11+
for (const entry of await fs.promises.readdir(currentPath, { withFileTypes: true })) {
12+
const sourcePath = path.join(currentPath, entry.name);
13+
const name = `${archivePath}/${entry.name}`;
14+
if (entry.isDirectory()) {
15+
await visit(sourcePath, name);
16+
} else if (entry.isSymbolicLink()) {
17+
pack.entry(
18+
{ name, type: 'symlink', linkname: await fs.promises.readlink(sourcePath) },
19+
Buffer.alloc(0),
20+
);
21+
} else if (entry.isFile()) {
22+
pack.entry({ name, type: 'file' }, await fs.promises.readFile(sourcePath));
23+
}
24+
}
25+
};
26+
await visit(directoryPath, rootName);
27+
pack.finalize();
28+
const chunks: Buffer[] = [];
29+
for await (const chunk of pack) chunks.push(Buffer.from(chunk));
30+
return gzipSync(Buffer.concat(chunks));
31+
}
32+
33+
export function createArtifactDownloadServer(archives: ReadonlyMap<string, Buffer>): http.Server {
34+
return http.createServer((request, response) => {
35+
const prefix = '/artifacts/';
36+
const artifactId = request.url?.startsWith(prefix)
37+
? decodeURIComponent(request.url.slice(prefix.length))
38+
: undefined;
39+
const archive = request.method === 'GET' && artifactId ? archives.get(artifactId) : undefined;
40+
if (!archive) {
41+
response.statusCode = 404;
42+
response.end('not found');
43+
return;
44+
}
45+
response.setHeader('content-type', 'application/gzip');
46+
response.end(archive);
47+
});
48+
}

‎packages/test-kit/src/index.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export {
3636
dispatchDisclosureRowsOwnedBy,
3737
} from './dispatch-disclosure.fixtures.ts';
3838
export { restoreEnv } from './env.ts';
39+
export {
40+
laneEnvelope,
41+
LANE_ENVELOPE_SCHEMA_VERSION,
42+
type LaneEnvelope,
43+
type LaneEnvelopeInput,
44+
type LaneResult,
45+
} from './lane-envelope.ts';
3946
export {
4047
type FilesystemBoundaryFixture,
4148
type FilesystemBoundaryOwner,

packages/daemon/test/nightly/concurrency-torture/lane-envelope.ts renamed to packages/test-kit/src/lane-envelope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const LANE_ENVELOPE_SCHEMA_VERSION = 1;
1+
export const LANE_ENVELOPE_SCHEMA_VERSION = 1;
22

33
export type LaneResult = 'pass' | 'fail';
44

0 commit comments

Comments
 (0)