Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -395,21 +395,20 @@
if (claim.status !== 'acquired') throw new Error('fixture claim refused');
let released = false;
spawn.mockImplementation((_command, _args, options) => {
if (spawn.mock.calls.length !== 1)
throw new Error('no second launch: the retry boundary must be observable without a sweeper');
const child = spawnRegisteredDaemonFixture(paths, fields(http.port), options, undefined, {
emitStartupMarkerBeforeAcquisition: true,
});
if (spawn.mock.calls.length === 1) {
void child.exited.then((exit) => {
assert.equal(exit.exitCode, DAEMON_STARTUP_EXIT_CODES.busy);
if (!released) {
void claim.acquisition.release().then(() => {
released = true;
});
}
});
return child;
}
throw new Error('no second launch: the retry boundary must be observable without a sweeper');
void child.exited.then((exit) => {
assert.equal(exit.exitCode, DAEMON_STARTUP_EXIT_CODES.busy);
if (!released) {
void claim.acquisition.release().then(() => {
released = true;
});
}
});
return child;
});
pause.mockImplementation((ms) => actualRetry.sleep(Math.min(Number(ms), 50)));
try {
Expand All @@ -418,6 +417,11 @@
(error: unknown) =>
error instanceof AppError && error.details?.kind === 'daemon_startup_failed',
);
assert.equal(
fs.readdirSync(path.join(paths.baseDir, 'fixture-entries')).length,
1,
'the refused retry must not launch another marker writer',
);

Check warning on line 424 in packages/daemon-client/src/__tests__/daemon-client-startup-race.test.ts

View check run for this annotation

apex-sentinel-staging / Apex Sentinel

minor: New assertion checks the mock's own throw, so it cannot fail on any production change

The `fixture-entries` count is vacuously true: the mock's own guard at lines 398–399 throws before `spawnRegisteredDaemonFixture` runs, so a second entry directory can never appear regardless of what production code does. A production change that launched a third attempt or retried past the boundary would still pass this assertion. This is a mock asserting its own inputs, which `docs/agents/test-authoring.md` prohibits. ### Also raised here Also raised at this location by persona `javascript`: New assertion can fail with a raw ENOENT instead of its own message — If the client stops launching any fixture child at all — a regression where sendToDaemon rejects with `daemon_startup_failed` before the spawn — `fs.readdirSync(path.join(paths.baseDir, 'fixture-entries'))` throws `ENOENT: no such file or directory` rather than reporting the intended message, because that directory exists only as a side effect of a spawn in registered-daemon-fixture.ts. The intended `released === true` check at line 430 never runs, so the failure reads as a missing file. Assert the spawn count first (a mock count, not a filesystem side effect); the directory then exists whenever the count is 1. Also raised at this location by persona `senior-developer`: Test reaches into the fixture helper's private 'fixture-entries' layout — The new assertion hardcodes the `fixture-entries` directory name owned by `packages/test-kit/src/registered-daemon-fixture.ts:92`, so a rename of that internal layout makes `fs.readdirSync` throw `ENOENT` for this path instead of the assertion's own message. Prefer the observable seam the test already has (`spawn.mock.calls.length`), or have the fixture helper expose a count, so the failure names the invariant rather than a missing directory.
Comment on lines +420 to +424

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The new fixture-entries count only proves no fixture child was written; it does not prove the retry was never attempted, because the refused spawn throws and is swallowed as a startup error. Assert the spawn count directly after the rejection so a retry attempt fails the test.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/daemon-client/src/__tests__/daemon-client-startup-race.test.ts, line 420:

<comment>The new `fixture-entries` count only proves no fixture child was written; it does not prove the retry was never attempted, because the refused spawn throws and is swallowed as a startup error. Assert the spawn count directly after the rejection so a retry attempt fails the test.</comment>

<file context>
@@ -418,6 +417,11 @@ test('a busy contender that exits sweeps its own pre-lock marker before the retr
       (error: unknown) =>
         error instanceof AppError && error.details?.kind === 'daemon_startup_failed',
     );
+    assert.equal(
+      fs.readdirSync(path.join(paths.baseDir, 'fixture-entries')).length,
+      1,
</file context>
Suggested change
assert.equal(
fs.readdirSync(path.join(paths.baseDir, 'fixture-entries')).length,
1,
'the refused retry must not launch another marker writer',
);
assert.equal(
spawn.mock.calls.length,
1,
'the refused retry must not reach spawn again',
);

Comment on lines +420 to +424

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · New assertion checks the mock's own throw, so it cannot fail on any production change

The fixture-entries count is vacuously true: the mock's own guard at lines 398–399 throws before spawnRegisteredDaemonFixture runs, so a second entry directory can never appear regardless of what production code does. A production change that launched a third attempt or retried past the boundary would still pass this assertion. This is a mock asserting its own inputs, which docs/agents/test-authoring.md prohibits.

Suggested change

assert.equal(spawn.mock.calls.length, 1, 'the refused retry must not launch another marker writer');

Details

Also raised here

Also raised at this location by persona javascript: New assertion can fail with a raw ENOENT instead of its own message — If the client stops launching any fixture child at all — a regression where sendToDaemon rejects with daemon_startup_failed before the spawn — fs.readdirSync(path.join(paths.baseDir, 'fixture-entries')) throws ENOENT: no such file or directory rather than reporting the intended message, because that directory exists only as a side effect of a spawn in registered-daemon-fixture.ts. The intended released === true check at line 430 never runs, so the failure reads as a missing file. Assert the spawn count first (a mock count, not a filesystem side effect); the directory then exists whenever the count is 1.

Also raised at this location by persona senior-developer: Test reaches into the fixture helper's private 'fixture-entries' layout — The new assertion hardcodes the fixture-entries directory name owned by packages/test-kit/src/registered-daemon-fixture.ts:92, so a rename of that internal layout makes fs.readdirSync throw ENOENT for this path instead of the assertion's own message. Prefer the observable seam the test already has (spawn.mock.calls.length), or have the fixture helper expose a count, so the failure names the invariant rather than a missing directory.

persona: senior-developer, javascript

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

assert.deepEqual(
fs.readdirSync(paths.baseDir).filter((e) => e.startsWith('daemon-startup-phases')),
[],
Expand Down
Loading