Skip to content

Commit 1bcd0a5

Browse files
committed
test(daemon-client): stamp the start-race winner with the client's own code identity
1 parent aad9cac commit 1bcd0a5

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

‎src/daemon-client/__tests__/daemon-client-startup-race.test.ts‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import assert from 'node:assert/strict';
22
import fs from 'node:fs';
3-
import path from 'node:path';
4-
import { afterEach, test, vi } from 'vitest';
3+
import { afterEach, beforeAll, test, vi } from 'vitest';
54
import { mkdtempForTestSync } from '../../__tests__/test-utils/tmp-dir.ts';
65

76
vi.mock('@agent-device/host-kit/command', async (importOriginal) => ({
@@ -33,8 +32,8 @@ import { resolveDaemonPaths, type DaemonPaths } from '../../daemon-resolution.ts
3332
import { sendToDaemon } from '../daemon-client.ts';
3433
import { runCmdDetachedMonitored, type ExecDetachedExit } from '@agent-device/host-kit/command';
3534
import { sleep } from '@agent-device/host-kit/retry';
36-
import { findProjectRoot, readVersion } from '@agent-device/host-kit/version';
37-
import { computeDaemonCodeSignature } from '@agent-device/host-kit/code-signature';
35+
import { readVersion } from '@agent-device/host-kit/version';
36+
import { resolveLocalDaemonCodeIdentity } from '../daemon-launch-spec.ts';
3837
import {
3938
startHttpDaemonFixture,
4039
type HttpDaemonFixture,
@@ -58,16 +57,13 @@ afterEach(() => {
5857
vi.unstubAllEnvs();
5958
});
6059

61-
/** The code signature this client expects of a daemon it may reuse. */
62-
function currentDaemonCodeSignature(): string {
63-
const root = findProjectRoot();
64-
const distPath = path.join(root, 'dist', 'src', 'internal', 'daemon.js');
65-
const entryPath =
66-
process.execArgv.includes('--experimental-strip-types') || !fs.existsSync(distPath)
67-
? path.join(root, 'src', 'daemon.ts')
68-
: distPath;
69-
return computeDaemonCodeSignature(entryPath, root);
70-
}
60+
/** The code signature this client stamps on, and expects of, a daemon it may reuse. */
61+
let codeSignature: string | undefined;
62+
63+
beforeAll(async () => {
64+
const identity = await resolveLocalDaemonCodeIdentity();
65+
codeSignature = identity.origin === 'installed' ? undefined : identity.codeSignature;
66+
});
7167

7268
/** Records the winning daemon the way it would: the startup lock, then its reachable metadata. */
7369
function writeWinner(
@@ -88,7 +84,7 @@ function writeWinner(
8884
token: 'winner-secret',
8985
pid: WINNER_PID,
9086
version,
91-
codeSignature: currentDaemonCodeSignature(),
87+
codeSignature,
9288
processStartTime: 'winner',
9389
httpPort: fixture.port,
9490
transport: 'http',

0 commit comments

Comments
 (0)