Skip to content

Commit fd71da2

Browse files
cliffhallclaude
andcommitted
test(web): guard message states observation before candidate causes; log the preserved drain error (round 12)
Round-12 review of PR #1793 (merge-verdict): - Finding 1: the round-11 rewording had dropped the "Expected cause:" hedge and asserted setup.ts's cleanup() as the fact, but the check only observes that a still-live armed tree was detached — it can't identify what detached it. Reworded to state that observation first, then list candidate causes: (a) a bare mid-body cleanup() in the test (the reachable case today), or (b) cleanup moved off the setup.ts setupFile hook to a same-level afterEach. No single cause asserted as fact. - Nits 2a/2b: when both a liveness error and a drain error fire, the drain error is now also console.error'd (in addition to being attached as `cause`), so it's readable regardless of whether the reporter renders `error.cause` and isn't silently dropped even if the liveness error somehow isn't an Error. Verified: a bare mid-body cleanup() throws the reworded message; eslint clean; ViewHeader unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5
1 parent 702c541 commit fd71da2

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

‎clients/web/src/test/renderWithMantine.tsx‎

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,25 @@ afterEach(async () => {
223223
// as its `cause` rather than dropping it, so a component error flushed during
224224
// the settle isn't lost when both fire. Otherwise rethrow the drain's.
225225
if (livenessError !== undefined) {
226-
if (drainError !== undefined && livenessError instanceof Error) {
227-
livenessError.cause = drainError;
226+
if (drainError !== undefined) {
227+
// Preserve the drain error rather than dropping it, so a component error
228+
// flushed during the settle isn't lost when both fire. Attach it as the
229+
// liveness error's `cause` (when that's an Error) *and* log it, so it's
230+
// readable regardless of whether the test reporter renders `cause`.
231+
if (livenessError instanceof Error) livenessError.cause = drainError;
232+
console.error(
233+
"renderWithMantineTransitions auto-settle: the drain also threw " +
234+
"(reported as the liveness error's cause):",
235+
drainError,
236+
);
228237
}
229238
throw livenessError;
230239
}
231240
if (drainError !== undefined) throw drainError;
232241
});
233242

234243
// Throw if any still-live armed tree was detached at the given point relative to
235-
// the settle — meaning `cleanup()` ran before this settle finished, so it
244+
// the settle — meaning something unmounted it before this settle finished, so it
236245
// drained against a dead tree and the #1760 leak is reopened. Only trees the
237246
// test left mounted are passed here; a tree the test unmounted itself (via the
238247
// wrapped `unmount()`) is excluded, so its legitimate detach never lands here.
@@ -241,18 +250,19 @@ function assertLiveContainersConnected(
241250
when: "before" | "after",
242251
) {
243252
if (containers.some((c) => !c.isConnected)) {
253+
// The check observes only that a tree the test left mounted is no longer
254+
// connected — it can't identify *what* detached it — so state that
255+
// observation, then list the candidate causes rather than asserting one.
244256
throw new Error(
245-
`renderWithMantineTransitions auto-settle: a still-mounted tree was ` +
246-
`detached ${when} the settle — setup.ts's cleanup() ran ` +
247-
(when === "before" ? "entirely first" : "concurrently mid-settle") +
248-
", so the settle drained nothing and the #1760 leak is reopened. This " +
249-
"hook must run and complete before cleanup, which holds because " +
250-
"cleanup() is a setupFile (outer) hook; the likely cause is cleanup " +
251-
"having been moved to a same-level afterEach (the `sequence.hooks` pin " +
252-
"is defense-in-depth, not the guarantee — see the ordering note here). " +
253-
"If instead the test unmounted the tree itself, use the `unmount()` " +
254-
"returned by renderWithMantineTransitions (which drops the tree from the " +
255-
"liveness set) rather than a bare mid-body `cleanup()`.",
257+
`renderWithMantineTransitions auto-settle: a still-mounted armed tree was ` +
258+
`detached ${when === "before" ? "before the settle started" : "while the settle was in flight"}, ` +
259+
"so the settle drained nothing and the #1760 leak is reopened. Candidate " +
260+
"causes: (a) a bare mid-body `cleanup()` in the test — use the " +
261+
"`unmount()` returned by renderWithMantineTransitions instead (it drops " +
262+
"the tree from the liveness set); or (b) `cleanup()` moved off setup.ts's " +
263+
"setupFile (outer) hook to a same-level afterEach, so it no longer runs " +
264+
"after this one (the `sequence.hooks` pin is defense-in-depth, not the " +
265+
"guarantee — see the ordering note here).",
256266
);
257267
}
258268
}

0 commit comments

Comments
 (0)