Skip to content

Commit d5f9b48

Browse files
committed
test(serverReady): assert breakpoint action runs
Fix serverReady breakpoint handling during startup hops.
1 parent 4b1d967 commit d5f9b48

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

src/session.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,6 +2899,45 @@ export async function startDebuggingAndWaitForStop(params: StartDebuggingAndWait
28992899
)
29002900
&& hops < maxHops
29012901
) {
2902+
// Special-case: serverReady breakpoint stop (after entry).
2903+
// If we don't process it here, we'll keep re-stopping on the same breakpoint.
2904+
if (
2905+
serverReady
2906+
&& serverReadySource
2907+
&& typeof nextStop.line === "number"
2908+
&& nextStop.line === serverReady.trigger?.line
2909+
) {
2910+
logger.info(
2911+
`Hit serverReady breakpoint during startup hops at line ${nextStop.line}; executing action then continuing to user breakpoint.`,
2912+
);
2913+
if (!serverReadyTriggerSummary) {
2914+
serverReadyTriggerSummary = serverReady.trigger?.path
2915+
? `Breakpoint ${serverReady.trigger.path}:${serverReady.trigger.line}`
2916+
: "serverReady breakpoint hit";
2917+
}
2918+
await executeServerReadyAction("late");
2919+
// Remove serverReady breakpoint to avoid re-trigger.
2920+
vscode.debug.removeBreakpoints([serverReadySource]);
2921+
serverReadySource = undefined;
2922+
try {
2923+
await nextStop.session.customRequest("continue", {
2924+
threadId: nextStop.threadId,
2925+
});
2926+
}
2927+
catch (e) {
2928+
const msg = e instanceof Error ? e.message : String(e);
2929+
throw new Error(
2930+
`Failed to continue after serverReady breakpoint (DAP 'continue'): ${msg}`,
2931+
);
2932+
}
2933+
const elapsed = Date.now() - loopStart;
2934+
const remaining = Math.max(0, remainingMs - elapsed);
2935+
nextStop = await waitForDebuggerStopBySessionId({
2936+
sessionId,
2937+
timeout: remaining,
2938+
});
2939+
continue;
2940+
}
29022941
hops++;
29032942
const elapsed = Date.now() - loopStart;
29042943
const remaining = Math.max(0, remainingMs - elapsed);

src/test/serverReady.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,29 @@ describe("serverReady breakpoint", function () {
7575
},
7676
});
7777

78+
assert.strictEqual(
79+
context.serverReadyInfo.configured,
80+
true,
81+
"serverReady should be reported as configured",
82+
);
83+
assert.strictEqual(
84+
context.serverReadyInfo.triggerMode,
85+
"breakpoint",
86+
"serverReady trigger mode should be breakpoint",
87+
);
88+
assert.ok(
89+
context.serverReadyInfo.phases.some(
90+
p => p.phase === "entry" || p.phase === "late",
91+
),
92+
`Expected serverReady action to execute for breakpoint trigger, but phases were: ${JSON.stringify(
93+
context.serverReadyInfo.phases,
94+
)}`,
95+
);
96+
assert.ok(
97+
context.serverReadyInfo.triggerSummary?.includes("Breakpoint"),
98+
`Expected serverReady trigger summary to mention Breakpoint, but was: ${context.serverReadyInfo.triggerSummary}`,
99+
);
100+
78101
// Assert we stopped at the user breakpoint (not serverReady line)
79102
assert.strictEqual(
80103
context.frame.line,
@@ -145,6 +168,29 @@ describe("serverReady breakpoint", function () {
145168
action: { type: "httpRequest", url: "http://localhost:31337/health" },
146169
},
147170
});
171+
172+
assert.strictEqual(
173+
context.serverReadyInfo.configured,
174+
true,
175+
"serverReady should be reported as configured (httpRequest)",
176+
);
177+
assert.strictEqual(
178+
context.serverReadyInfo.triggerMode,
179+
"breakpoint",
180+
"serverReady trigger mode should be breakpoint (httpRequest)",
181+
);
182+
assert.ok(
183+
context.serverReadyInfo.phases.some(
184+
p => p.phase === "entry" || p.phase === "late",
185+
),
186+
`Expected serverReady action to execute for breakpoint trigger (httpRequest), but phases were: ${JSON.stringify(
187+
context.serverReadyInfo.phases,
188+
)}`,
189+
);
190+
assert.ok(
191+
context.serverReadyInfo.triggerSummary?.includes("Breakpoint"),
192+
`Expected serverReady trigger summary to mention Breakpoint (httpRequest), but was: ${context.serverReadyInfo.triggerSummary}`,
193+
);
148194
assert.strictEqual(
149195
context.frame.line,
150196
userBreakpointLine,

0 commit comments

Comments
 (0)