Files
callstack__agent-device/test/integration/provider-scenarios/daemon-lifecycle.test.ts
Michał Pierzchała 59d28e8446 refactor: add provider-first device lab tests (#542)
* refactor: add provider-first device lab tests

* refactor: tighten device lab provider seams

* test: cover provider lab contracts

* docs: record device lab harness direction

* ci: run device lab integration tests

* test: move device lab under integration

* test: extract device lab helpers

* refactor: centralize apps filter defaults

* test: drop lab-covered unit tests

* test: fold platform happy paths into device lab

* test: reuse device lab helpers

* test: move device lab to in-process harness

* test: replace session handler cases with device lab

* test: harden device lab scenario contracts

* docs: define unit test retention policy

* test: expand provider device lab coverage

* test: harden provider device lab coverage

* test: cover manifest install and runner session contracts

* chore: remove unused provider cleanup code

* test: split android find device lab scenario

* test: track provider lab architecture progress

* test: clarify provider lab roadmap progress

* test: advance provider lab session coverage

* test: move menubar click routing to device lab

* test: move menubar snapshots to device lab

* refactor: centralize screenshot flag plumbing

* refactor: colocate screenshot flag metadata

* test: cover all public commands in device lab

* test: move macos wait success to device lab

* test: drop redundant perf and diff units

* test: move push payload paths to device lab

* test: move network parsing to device lab

* test: move log cleanup to device lab

* test: move log restart and boot to device lab

* test: move ios physical boot to device lab

* test: cover perf startup in device lab

* test: extract android and ios device lab worlds

* test: trim device lab world surface

* test: split snapshot capture unit coverage

* test: deepen device lab coverage and trim handler units

* test: clean up device lab migration scaffolding

* test: report device lab public command coverage

* refactor: make Apple provider seams semantic

* refactor: tighten device inventory and Linux provider seams

* refactor: tighten request provider scoping

* refactor: add semantic macos host provider

* test: broaden device lab find coverage

* test: cover workflow flags in device lab

* refactor: promote linux input provider seam

* test: clarify device lab flag coverage

* test: classify snapshot force-full progress

* test: enforce device lab progress in ci

* test: stabilize device lab ci

* test: move packaged metro smoke to integration

* test: drop stale provider seam coverage

* test: harden provider scope regression coverage

* refactor: remove stale platform barrels

* refactor: keep linux clipboard and screenshots semantic

* refactor: move macos host tools behind provider

* fix: honor remote artifact output paths

* test: deepen runtime coverage for daemon and runner paths

* test: share loopback test helpers

* refactor: make daemon runtime importable

* fix: honor replay target metadata

* chore: tighten final device lab quality gates

* test: share device lab setup helpers

* test: remove generic apple lab fallback

* test: deduplicate device lab helpers

* chore: tighten fallow duplication signal

* refactor: share apple diagnostic helpers

* fix: detect active android ime during fill verification

* test: consolidate provider-backed integration suite

* ci: fix fallow and iOS smoke setup

* chore: consolidate cleanup after ci fixes

* test: split vitest unit and integration projects

* docs: mention MCP discovery metadata

* docs: add agent skills context pointers

* fix: close provider recording coverage gaps

* fix: restore mcp compatibility smoke

* test: cover provider edge regressions

* test: consolidate loopback helpers

* docs: remove stale provider routing reference

* fix: harden final provider review issues

* chore: defer mcp cleanup from provider refactor
2026-05-18 14:50:52 +02:00

93 lines
3.0 KiB
TypeScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { test } from 'vitest';
import {
acquireDaemonLock,
parseIntegerEnv,
releaseDaemonLock,
removeInfo,
writeInfo,
} from '../../../src/daemon/server-lifecycle.ts';
test('Provider-backed integration daemon lifecycle writes metadata and protects process-owned locks', () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-daemon-lifecycle-'));
const infoPath = path.join(root, 'daemon.json');
const lockPath = path.join(root, 'daemon.lock');
const logPath = path.join(root, 'daemon.log');
try {
writeInfo(root, infoPath, logPath, {
socketPort: 4210,
httpPort: 4310,
token: 'provider-scenario-token',
version: '0.0.0-provider-scenario',
codeSignature: 'graph:1:abc',
processStartTime: 'start-time',
});
assert.equal(fs.existsSync(logPath), true);
const info = JSON.parse(fs.readFileSync(infoPath, 'utf8'));
assert.equal(info.transport, 'dual');
assert.equal(info.port, 4210);
assert.equal(info.httpPort, 4310);
assert.equal(info.token, 'provider-scenario-token');
assert.equal(info.stateDir, root);
const httpOnlyInfoPath = path.join(root, 'daemon-http.json');
writeInfo(root, httpOnlyInfoPath, path.join(root, 'daemon-http.log'), {
httpPort: 4311,
token: 'http-only-token',
version: '0.0.0-provider-scenario',
codeSignature: 'graph:1:http',
processStartTime: undefined,
});
const httpOnlyInfo = JSON.parse(fs.readFileSync(httpOnlyInfoPath, 'utf8'));
assert.equal(httpOnlyInfo.transport, 'http');
assert.equal(httpOnlyInfo.port, undefined);
assert.equal(httpOnlyInfo.httpPort, 4311);
const socketOnlyInfoPath = path.join(root, 'daemon-socket.json');
writeInfo(root, socketOnlyInfoPath, path.join(root, 'daemon-socket.log'), {
socketPort: 4211,
token: 'socket-only-token',
version: '0.0.0-provider-scenario',
codeSignature: 'graph:1:socket',
processStartTime: undefined,
});
const socketOnlyInfo = JSON.parse(fs.readFileSync(socketOnlyInfoPath, 'utf8'));
assert.equal(socketOnlyInfo.transport, 'socket');
assert.equal(socketOnlyInfo.port, 4211);
assert.equal(socketOnlyInfo.httpPort, undefined);
assert.equal(
acquireDaemonLock(root, lockPath, {
pid: process.pid,
version: '0.0.0-provider-scenario',
startedAt: 1,
}),
true,
);
assert.equal(
acquireDaemonLock(root, lockPath, {
pid: process.pid,
version: '0.0.0-provider-scenario',
startedAt: 2,
}),
true,
);
releaseDaemonLock(lockPath);
assert.equal(fs.existsSync(lockPath), false);
assert.equal(parseIntegerEnv('10'), 10);
assert.equal(parseIntegerEnv('1.5'), undefined);
assert.equal(parseIntegerEnv(undefined), undefined);
removeInfo(infoPath);
assert.equal(fs.existsSync(infoPath), false);
} finally {
fs.rmSync(root, { recursive: true, force: true });
}
});