Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion packages/test-kit/src/registered-daemon-launch-plan.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { afterEach, test, vi } from 'vitest';
import { afterEach, expectTypeOf, test, vi } from 'vitest';
import {
createRegisteredDaemonFixtures,
type RegisteredDaemonChild,
Expand Down Expand Up @@ -155,3 +155,33 @@ test('a failed child join does not prevent teardown from stopping the remaining
'failed cleanup must retain state for diagnosis',
);
});

test('exit gates delay the returned launch but are not accepted on companions', async () => {
const f = fixture();
let release!: () => void;
const exitGate = new Promise<void>((resolve) => {
release = resolve;
});
const step = { kind: 'registered' as const, paths: f.paths, fields: {} };
type RegisteredLaunch = Extract<
Parameters<typeof f.fixtures.planRegisteredDaemonLaunches>[0][number],
{ kind: 'registered' }
>;
type Companion = NonNullable<RegisteredLaunch['companions']>[number];
expectTypeOf<typeof step & { exitGate: Promise<void> }>().not.toExtend<Companion>();
const launch = f.fixtures.planRegisteredDaemonLaunches([
{ ...step, exitGate, companions: [step] },
]);
const child = launch('node', []);
let exited = false;
void child.exited.then(() => {
exited = true;
});
await Promise.resolve();
assert.equal(f.launches(), 2);
assert.equal(exited, false, 'the returned child must wait for its exit gate');
release();
assert.equal(await child.exited, await f.child.exited);
await f.fixtures.finishRegisteredDaemonFixtures();
assert.equal(f.stops(), 2);
});
4 changes: 3 additions & 1 deletion packages/test-kit/src/registered-daemon-launch-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export type DaemonFixtureLaunch<P, F> =
};
exitGate?: Promise<void>;
observe?: (child: RegisteredDaemonChild) => void;
companions?: readonly Extract<DaemonFixtureLaunch<P, F>, { kind: 'registered' }>[];
companions?: readonly (Extract<DaemonFixtureLaunch<P, F>, { kind: 'registered' }> & {
exitGate?: never;
})[];
};

export type DaemonFixtureLaunchStep<P, F> =
Expand Down
16 changes: 10 additions & 6 deletions test/repo-guards/daemon-fixture-launches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import { REPO_ROOT } from '@agent-device/test-kit';
import { scanDaemonFixtureLaunches } from '../../scripts/lib/daemon-fixture-launch-guard.ts';

test('daemon fixture family mocks use declared launch plans', () => {
const files = execFileSync('git', ['ls-files', '--cached', '--others', '--exclude-standard'], {
cwd: REPO_ROOT,
encoding: 'utf8',
})
.trim()
.split('\n')
const files = execFileSync(
'git',
['ls-files', '-z', '--cached', '--others', '--exclude-standard'],
{
cwd: REPO_ROOT,
encoding: 'utf8',
},
)
.split('\0')
.filter((file) => /^(src\/|packages\/[^/]+\/src\/).*\.ts$/.test(file))
.filter((file) => fs.existsSync(path.join(REPO_ROOT, file)))
.map((file) => ({ file, source: fs.readFileSync(path.join(REPO_ROOT, file), 'utf8') }));
assert.deepEqual(scanDaemonFixtureLaunches(files), []);
});
Loading