@celestia-island/hikari 0.55.520 → 0.55.522

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { afterEach, describe, expect, it, vi } from "vitest";
2
2
  import { createApp, h, nextTick, ref } from "vue";
3
3
 
4
- import HkDirectionalSwap, { resolveSwapDirection } from "./HkDirectionalSwap";
4
+ import HkDirectionalSwap, { readUnstretchedHeight, resolveSwapDirection } from "./HkDirectionalSwap";
5
5
 
6
6
  /**
7
7
  * HkDirectionalSwap contract:
@@ -63,6 +63,47 @@ describe("resolveSwapDirection", () => {
63
63
  });
64
64
  });
65
65
 
66
+ // MUT:swap-height-unstretch-priority — the un-stretch is a read aid,
67
+ // not a style: `readUnstretchedHeight` must hand the item back EXACTLY
68
+ // as it arrived — value AND priority. `getPropertyValue` returns the
69
+ // value alone, so a restore through `setProperty(prop, value)` silently
70
+ // drops an `!important` (R2′ probe: prior `center !important` came back
71
+ // as `center` with priority ""). Pinned on the helper directly because
72
+ // the swap creates the item in the same tick its enter hook reads it —
73
+ // no test can hand the component a prior inline style.
74
+ describe("readUnstretchedHeight", () => {
75
+ /** A grid item whose height depends on its own `align-self`, the way
76
+ * a real cell's does: the row's 100.5 while stretched, its own 40.25
77
+ * under `start` — fractional, the way a browser reports
78
+ * `getBoundingClientRect`. Returns the element. */
79
+ function gridItem(): HTMLElement {
80
+ const el = document.createElement("div");
81
+ document.body.appendChild(el);
82
+ Object.defineProperty(el, "getBoundingClientRect", {
83
+ configurable: true,
84
+ value: () => ({ height: el.style.alignSelf === "start" ? 40.25 : 100.5 }) as DOMRect,
85
+ });
86
+ return el;
87
+ }
88
+
89
+ it("reads the un-stretched height and leaves no inline align-self behind", () => {
90
+ const el = gridItem();
91
+ expect(readUnstretchedHeight(el)).toBe(40.25);
92
+ expect(el.style.getPropertyValue("align-self")).toBe("");
93
+ expect(el.style.getPropertyPriority("align-self")).toBe("");
94
+ expect(el.style.length).toBe(0);
95
+ });
96
+
97
+ it("restores a prior inline align-self with its priority intact", () => {
98
+ const el = gridItem();
99
+ el.style.setProperty("align-self", "center", "important");
100
+ expect(el.style.getPropertyPriority("align-self")).toBe("important"); // precondition
101
+ expect(readUnstretchedHeight(el)).toBe(40.25);
102
+ expect(el.style.getPropertyValue("align-self")).toBe("center");
103
+ expect(el.style.getPropertyPriority("align-self"), "priority must survive the restore").toBe("important");
104
+ });
105
+ });
106
+
66
107
  describe("HkDirectionalSwap", () => {
67
108
  it("renders the first generation with the direction and axis as data attributes", async () => {
68
109
  const c = mount({ swapKey: "preview", direction: "forward", axis: "horizontal" });
@@ -170,39 +211,51 @@ describe("HkDirectionalSwap", () => {
170
211
  });
171
212
 
172
213
  // ── animateHeight (opt-in height tween) ─────────────────────────────
173
- // happy-dom has no layout engine: every offsetHeight reads 0, so the
214
+ // happy-dom has no layout engine: every height read is 0, so the
174
215
  // tween (freeze a rendered height, step to a target) runs against
175
216
  // STUBBED heights — without a stub the unreadable-height guard skips
176
217
  // the whole tween and every assertion would pass for the wrong reason.
177
- // The tween's writes are SYNCHRONOUS inside the enter hook (no
178
- // animation frames by design — frames starve in background tabs and
179
- // automation), so armed-and-targeted is observable one tick after the
180
- // swap and released after the exchange's settle.
181
-
182
- /** The host's offsetHeight READ COUNT under the current stubLayout —
183
- * reset on every install. The tween's forced layout (the flush between
184
- * its freeze and its target) is one extra host read, so a pin can
185
- * require it: R4's M-no-flush (deleting `void host.offsetHeight`) was
218
+ // The stubs shadow `getBoundingClientRect` (the read the component
219
+ // makes — fractional, un-rounded) and NOT `offsetHeight`: a mutant
220
+ // that reverts ALL the tween's reads to the integer-rounded read hits
221
+ // the real (0) value, fails the unreadable-height guard, and never
222
+ // arms — the fractional pin goes red (MUT:swap-height-fractional-targets,
223
+ // below). (A partial revert of the flush read alone is not observable
224
+ // through the writes; the flush pin's read-count covers that one —
225
+ // MUT:swap-height-flush, below.) The tween's writes are SYNCHRONOUS inside the enter
226
+ // hook (no animation frames by design — frames starve in background
227
+ // tabs and automation), so armed-and-targeted is observable one tick
228
+ // after the swap and released after the exchange's settle.
229
+
230
+ /** The host's HEIGHT READ COUNT under the current stub — reset on
231
+ * every install. The tween's forced layout (the flush between its
232
+ * freeze and its target) is one extra host read, so a pin can
233
+ * require it: R4's M-no-flush (deleting the flush read) was
186
234
  * invisible to every read-based pin because a constant stub reads the
187
235
  * same however many times. */
188
236
  const hostReads = { count: 0 };
189
237
 
190
- /** Shadow offsetHeight for the swap's two element kinds (host reads are
191
- * counted into `hostReads`). Returns the restore thunk. */
238
+ /** A DOMRect-like object carrying just `height` (all `getBoundingClientRect`
239
+ * consumers in this component read the height). */
240
+ const rectOf = (height: number): DOMRect => ({ height }) as DOMRect;
241
+
242
+ /** Shadow `getBoundingClientRect` for the swap's two element kinds
243
+ * (host reads are counted into `hostReads`). Returns restore. */
192
244
  function stubLayout(hostH: () => number, itemH: () => number): () => void {
193
245
  const proto = HTMLElement.prototype;
194
- const shadow = Object.getOwnPropertyDescriptor(proto, "offsetHeight");
246
+ const shadow = Object.getOwnPropertyDescriptor(proto, "getBoundingClientRect");
195
247
  hostReads.count = 0;
196
- Object.defineProperty(proto, "offsetHeight", {
248
+ Object.defineProperty(proto, "getBoundingClientRect", {
197
249
  configurable: true,
198
- get(this: HTMLElement) {
199
- if (!this.classList.contains("hk-dswap-item")) hostReads.count += 1;
200
- return this.classList.contains("hk-dswap-item") ? itemH() : hostH();
250
+ value(this: HTMLElement) {
251
+ const isItem = this.classList.contains("hk-dswap-item");
252
+ if (!isItem) hostReads.count += 1;
253
+ return rectOf(isItem ? itemH() : hostH());
201
254
  },
202
255
  });
203
256
  return () => {
204
- if (shadow) Object.defineProperty(proto, "offsetHeight", shadow);
205
- else delete (proto as unknown as Record<string, unknown>).offsetHeight;
257
+ if (shadow) Object.defineProperty(proto, "getBoundingClientRect", shadow);
258
+ else delete (proto as unknown as Record<string, unknown>).getBoundingClientRect;
206
259
  };
207
260
  }
208
261
 
@@ -241,6 +294,112 @@ describe("HkDirectionalSwap", () => {
241
294
  const descGet = Object.getOwnPropertyDescriptor(CSSStyleDeclaration.prototype, "height")!.get!;
242
295
  const descSet = Object.getOwnPropertyDescriptor(CSSStyleDeclaration.prototype, "height")!.set!;
243
296
 
297
+ /** Model the grid cell's REAL geometry in a DOM with no layout engine
298
+ * (the stub above returns constants, which is exactly how the first
299
+ * cut of the tween shipped green and never ran in a browser):
300
+ * - the host renders at its ROW's height — the tallest generation
301
+ * present in ITS OWN cell (`natural` by `data-swap-key`; the
302
+ * leaving copy counts until Vue removes it), scoped through the
303
+ * element's own cell so two instances in one document never see
304
+ * each other's items;
305
+ * comment-gate-ok: the model is pinned by the `stubGrid models the
306
+ * cell` self-test below (MUT:swap-height-stubgrid-model), which sits
307
+ * after the helper because the pin needs the helper to exist first;
308
+ * - an item renders at that row height too, because grid items
309
+ * STRETCH (`align-self: normal`) — EXCEPT while its inline
310
+ * `align-self` is `start`, when it renders at its own content
311
+ * height. That is the only read that yields the incoming
312
+ * generation's own height, and the component must take it.
313
+ * - while the host is ARMED (`data-height-anim`), a browser renders
314
+ * the tween's animated value, not the row: `rendered` supplies it
315
+ * (null/unset = no armed model, the row stands in).
316
+ * - an explicit inline `height` on the item WINS over both the row
317
+ * stretch and the content height (the documented host contract) —
318
+ * modelled here so the contract case runs through this same model
319
+ * instead of a bespoke closure.
320
+ * Host reads are counted into `hostReads` as above. Returns restore. */
321
+ function stubGrid(natural: Record<string, number>, rendered?: () => number | null): () => void {
322
+ const proto = HTMLElement.prototype;
323
+ const shadow = Object.getOwnPropertyDescriptor(proto, "getBoundingClientRect");
324
+ hostReads.count = 0;
325
+ const row = (el: HTMLElement): number => {
326
+ const cell = el.classList.contains("hk-dswap-item") ? el.parentElement : el;
327
+ let tallest = 0;
328
+ for (const it of cell?.querySelectorAll<HTMLElement>(":scope > .hk-dswap-item") ?? []) {
329
+ tallest = Math.max(tallest, natural[it.dataset.swapKey ?? ""] ?? 0);
330
+ }
331
+ return tallest;
332
+ };
333
+ Object.defineProperty(proto, "getBoundingClientRect", {
334
+ configurable: true,
335
+ value(this: HTMLElement) {
336
+ if (this.classList.contains("hk-dswap-item")) {
337
+ // The pin wins over both the row and the content height.
338
+ const pinned = parseFloat(this.style.height);
339
+ if (!Number.isNaN(pinned)) return rectOf(pinned);
340
+ return rectOf(this.style.alignSelf === "start" ? (natural[this.dataset.swapKey ?? ""] ?? 0) : row(this));
341
+ }
342
+ hostReads.count += 1;
343
+ if (this.hasAttribute("data-height-anim") && rendered) {
344
+ const animated = rendered();
345
+ if (animated !== null) return rectOf(animated);
346
+ }
347
+ return rectOf(row(this));
348
+ },
349
+ });
350
+ return () => {
351
+ if (shadow) Object.defineProperty(proto, "getBoundingClientRect", shadow);
352
+ else delete (proto as unknown as Record<string, unknown>).getBoundingClientRect;
353
+ };
354
+ }
355
+
356
+ /** Make ONE side of the exchange look like it transitions for `ms` so
357
+ * Vue waits for it. happy-dom does not resolve the sheet's `var()`-
358
+ * based `transition` shorthand (both sides compute an empty duration),
359
+ * so Vue's `whenTransitionEnds` resolves BOTH at once and the leave —
360
+ * scheduled first — settles first; the whole exchange lands in one
361
+ * frame. Faking a duration on one side separates the two settles by
362
+ * ~`ms`, and either order can be produced: `leave` parks the leaving
363
+ * copy (enter settles first), `enter` parks the entering one (leave
364
+ * settles first).
365
+ * comment-gate-ok: both orders are pinned by the two settle pins
366
+ * below (MUT:swap-height-release-waits-for-leave / -enter), whose
367
+ * 1000ms bound sits under the watchdog on purpose.
368
+ * The fake is a PLAIN object carrying just the five
369
+ * fields `getTransitionInfo` reads — happy-dom's declaration accessors
370
+ * are brand-checked ("Receiver must be an instance of
371
+ * CSSStyleDeclaration"), so a prototype-chained wrapper throws the
372
+ * moment Vue reads a field the wrapper does not shadow, and Vue's
373
+ * frame callback dies with it (that side then never settles, and the
374
+ * 1500ms watchdog is what "releases" — a green pin with the wrong
375
+ * cause). The fake lists both properties the sheet transitions
376
+ * (`opacity, transform`) so Vue parses the same property list it
377
+ * would live. The duration is written in SECONDS: Vue's `toMs` parses
378
+ * `transitionDuration` by dropping the last character and reading the
379
+ * rest as a number of seconds (`"0.3s"` → 300), so a `"600ms"` reads
380
+ * as `NaN` and the side resolves at once — which is also why
381
+ * happy-dom's own millisecond-form durations never make Vue wait.
382
+ * Returns restore.
383
+ * comment-gate-ok: the NaN read was probed (toMs("300ms") → NaN,
384
+ * toMs("") → 0); it is what makes the un-faked side settle in the
385
+ * frame, and the settle pins are the load-bearing check on the
386
+ * brand-check hazard described above (MUT:swap-height-release-waits-for-enter). */
387
+ function slowSide(side: "enter" | "leave", ms: number): () => void {
388
+ const original = window.getComputedStyle;
389
+ const marker = side === "leave" ? "hk-dswap-leave-active" : "hk-dswap-enter-active";
390
+ vi.spyOn(window, "getComputedStyle").mockImplementation(((el: Element) => {
391
+ if (!el.classList?.contains(marker)) return original(el);
392
+ return {
393
+ transitionDuration: `${ms / 1000}s`,
394
+ transitionDelay: "0s",
395
+ transitionProperty: "opacity, transform",
396
+ animationDuration: "0s",
397
+ animationDelay: "0s",
398
+ } as unknown as CSSStyleDeclaration;
399
+ }) as typeof window.getComputedStyle);
400
+ return () => vi.restoreAllMocks();
401
+ }
402
+
244
403
  /** Drive microtasks/frames until `cond` holds; assert on failure so a
245
404
  * stuck wait names itself instead of timing out silently. */
246
405
  async function until(cond: () => boolean, label: string): Promise<void> {
@@ -250,6 +409,79 @@ describe("HkDirectionalSwap", () => {
250
409
  expect(cond(), label).toBe(true);
251
410
  }
252
411
 
412
+ // MUT:swap-height-stubgrid-model — the height pins are only as good
413
+ // as the geometry `stubGrid` models; R3 showed a helper that stopped
414
+ // gating `rendered` on the armed attribute went unnoticed (the
415
+ // follow-up pin's whole discriminating power is that a RELEASED host
416
+ // reads the row again). Pinned on the helper itself: one cell, two
417
+ // generations of different heights, read every way the component does.
418
+ it("stubGrid models the cell: row = tallest present, items stretch, un-stretch reads own, armed reads rendered", async () => {
419
+ const restore = stubGrid({ preview: 240, source: 100 }, () => 170);
420
+ try {
421
+ const key = ref("preview");
422
+ const container = document.createElement("div");
423
+ document.body.appendChild(container);
424
+ const app = createApp({ render: () => h(HkDirectionalSwap, { swapKey: key.value }, () => [h("p", key.value)]) });
425
+ app.mount(container);
426
+ mounts.push({ app, container });
427
+ await settle();
428
+ const host = container.querySelector<HTMLElement>(".hk-dswap")!;
429
+ const item = (k: string) => [...container.querySelectorAll<HTMLElement>(".hk-dswap-item")].find((el) => el.dataset.swapKey === k)!;
430
+ // One generation: the host IS that generation's height.
431
+ expect(host.getBoundingClientRect().height).toBe(240);
432
+ expect(item("preview").getBoundingClientRect().height).toBe(240);
433
+ // Two generations: the row is the taller one, and the shorter
434
+ // incoming copy reads stretched to it.
435
+ key.value = "source";
436
+ await nextTick();
437
+ await nextTick();
438
+ expect(host.getBoundingClientRect().height).toBe(240);
439
+ expect(item("source").getBoundingClientRect().height).toBe(240);
440
+ // …until un-stretched, when it reads its own content height.
441
+ item("source").style.alignSelf = "start";
442
+ expect(item("source").getBoundingClientRect().height).toBe(100);
443
+ item("source").style.removeProperty("align-self");
444
+ // Armed (and only armed): the host reads the animated value.
445
+ expect(host.getBoundingClientRect().height).toBe(240);
446
+ host.setAttribute("data-height-anim", "");
447
+ expect(host.getBoundingClientRect().height).toBe(170);
448
+ host.removeAttribute("data-height-anim");
449
+ expect(host.getBoundingClientRect().height).toBe(240);
450
+ } finally {
451
+ restore();
452
+ }
453
+ });
454
+
455
+ // MUT:swap-height-pinned-item-contract — a host that pins `height` on
456
+ // `.hk-dswap-item` reads its PIN, not its content: the pin wins over both
457
+ // the row stretch and the content height, so un-stretching cannot recover
458
+ // the content height and a pin AT THE ROW turns the tween back into the
459
+ // no-op #1661 fixed. That is why the contract says hosts size the pane.
460
+ // Driven through `stubGrid` (the same model every other height pin uses)
461
+ // rather than a bespoke closure, so the citation is re-derivable.
462
+ it("reads a pinned item's pin, not its content — the documented host contract", async () => {
463
+ const restore = stubGrid({ preview: 100.5, source: 100.5 });
464
+ try {
465
+ const key = ref("source");
466
+ const container = document.createElement("div");
467
+ document.body.appendChild(container);
468
+ const app = createApp({ render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]) });
469
+ app.mount(container);
470
+ mounts.push({ app, container });
471
+ await settle();
472
+ const item = container.querySelector<HTMLElement>(".hk-dswap-item")!;
473
+ // Content and row are both 100.5; the pin is 40.25.
474
+ item.style.height = "40.25px";
475
+ expect(readUnstretchedHeight(item)).toBe(40.25);
476
+ // The read restores the item's own inline style (the pin survives).
477
+ expect(item.style.height).toBe("40.25px");
478
+ expect(item.style.getPropertyValue("align-self")).toBe("");
479
+ expect(item.style.getPropertyPriority("align-self")).toBe("");
480
+ } finally {
481
+ restore();
482
+ }
483
+ });
484
+
253
485
  // MUT:swap-height-default-off — without the prop the height must stay
254
486
  // untouched (no data-height-anim, no inline height) at rest and
255
487
  // mid-exchange, AND the release hooks must not clobber a height the
@@ -302,8 +534,20 @@ describe("HkDirectionalSwap", () => {
302
534
  // value behind and turns the mid assertion red; a regression that
303
535
  // skips the freeze turns the release semantics red (nothing armed →
304
536
  // nothing to release → the host keeps whatever it had).
537
+ //
538
+ // The geometry is the REAL one (stubGrid): the SHRINKING direction,
539
+ // where the incoming copy is the shorter generation. Read stretched
540
+ // (the first cut), the target was the row — the outgoing copy's 240 —
541
+ // and the tween wrote 240px → 240px: never ran, and the whole change
542
+ // landed at the release as a snap (measured live on the docs shell's
543
+ // card). The write sequence is the pin: freeze at the taller
544
+ // generation, target at the incoming copy's OWN height.
545
+ // comment-gate-ok: the live figure is the probe quoted in the PR body;
546
+ // the behaviour is pinned by this test's own write-sequence assertion
547
+ // (MUT:swap-height-anim-arms, above — the stretched read writes the
548
+ // same value twice and the assertion goes red).
305
549
  it("arms the tween, lands the incoming height, and releases on settle", async () => {
306
- const restore = stubLayout(() => 100, () => 240);
550
+ const restore = stubGrid({ preview: 240, source: 100 });
307
551
  try {
308
552
  const key = ref("preview");
309
553
  const container = document.createElement("div");
@@ -325,12 +569,22 @@ describe("HkDirectionalSwap", () => {
325
569
  await nextTick();
326
570
  await nextTick();
327
571
  // Mid-exchange: the tween armed and BOTH writes landed, in order:
328
- // freeze at the current height (100px), then the target (240px).
329
- // An implementation that arms but never writes (R1 M10: both
330
- // writes deleted, every read-based pin green) writes nothing and
331
- // turns this red; freeze-only writes one entry (R1 M2).
572
+ // freeze at the pre-insertion height (240 — the row while the
573
+ // cell held only the outgoing copy), then the target (100 — the
574
+ // incoming copy's own height, read un-stretched). The stretched
575
+ // read writes [240px, 240px] and turns this red; an implementation
576
+ // that arms but never writes (R1 M10) writes nothing; freeze-only
577
+ // writes one entry (R1 M2).
332
578
  expect(host.hasAttribute("data-height-anim")).toBe(true);
333
- expect(writes).toEqual(["100px", "240px"]);
579
+ expect(writes).toEqual(["240px", "100px"]);
580
+ // MUT:swap-height-unstretch-restored — the un-stretch is a read
581
+ // aid, not a style: the item is put back exactly as it was (no
582
+ // inline `align-self` when it arrived with none; a leftover would
583
+ // take the item out of the cell's stretch for the rest of the
584
+ // exchange and show the band).
585
+ const incoming = [...container.querySelectorAll<HTMLElement>(".hk-dswap-item")].find((el) => el.dataset.swapKey === "source")!;
586
+ expect(incoming.style.alignSelf).toBe("");
587
+ expect(incoming.style.getPropertyValue("align-self")).toBe("");
334
588
  // MUT:swap-height-flush — the forced layout BETWEEN the two writes
335
589
  // is what establishes the freeze as the transition's before-value.
336
590
  // The two writes are synchronous neighbours, so nothing else can
@@ -352,6 +606,432 @@ describe("HkDirectionalSwap", () => {
352
606
  }
353
607
  });
354
608
 
609
+ // MUT:swap-height-from-pre-insertion — the START height is the host
610
+ // as it stood BEFORE the incoming copy inserted. In the GROWING
611
+ // direction the insertion itself lifts the row to the taller copy the
612
+ // same frame (measured live: 189 at rest, 200 the instant the taller
613
+ // copy lands), so an enter-hook read already reports the NEW height
614
+ // and the tween writes [240px, 240px] — the growth then happens at
615
+ // the START, as a snap, which is the very thing the prop exists to
616
+ // soften. The before-leave hook is the last read before the row
617
+ // moves; the write sequence pins it: freeze at 100 (the outgoing,
618
+ // shorter copy), target at 240.
619
+ it("freezes at the pre-insertion height when the incoming copy is taller", async () => {
620
+ const restore = stubGrid({ preview: 100, source: 240 });
621
+ try {
622
+ const key = ref("preview");
623
+ const container = document.createElement("div");
624
+ document.body.appendChild(container);
625
+ const app = createApp({
626
+ render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
627
+ });
628
+ app.mount(container);
629
+ mounts.push({ app, container });
630
+ await settle();
631
+ const host = container.querySelector<HTMLElement>(".hk-dswap")!;
632
+ const { writes, restore: unspy } = spyHeightWrites(host);
633
+ key.value = "source";
634
+ await nextTick();
635
+ await nextTick();
636
+ expect(host.hasAttribute("data-height-anim")).toBe(true);
637
+ expect(writes).toEqual(["100px", "240px"]);
638
+ unspy();
639
+ } finally {
640
+ restore();
641
+ }
642
+ });
643
+
644
+ // MUT:swap-height-release-waits-for-leave — the release needs BOTH
645
+ // settles: the enter at its end AND no leaving copy in the cell. With
646
+ // a leaving copy still present, `auto` resolves to the taller row it
647
+ // still holds — releasing there jumps the host UP to the outgoing
648
+ // height, then DOWN again when the copy goes (the docs shell's card
649
+ // showed exactly that band). This Chromium settles the leave first,
650
+ // so the order alone never bit here; `slowSide("leave", …)` forces the other
651
+ // order (enter settled, leave still fading) and the pin requires the
652
+ // tween to stay armed, at its target, until the copy is actually gone.
653
+ it("holds the tween armed until the leaving copy is gone when the enter settles first", async () => {
654
+ const restoreSlow = slowSide("leave", 600);
655
+ const restore = stubGrid({ preview: 240, source: 100 });
656
+ try {
657
+ const key = ref("preview");
658
+ const container = document.createElement("div");
659
+ document.body.appendChild(container);
660
+ const app = createApp({
661
+ render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
662
+ });
663
+ app.mount(container);
664
+ mounts.push({ app, container });
665
+ await settle();
666
+ const host = container.querySelector<HTMLElement>(".hk-dswap")!;
667
+ const { writes, restore: unspy } = spyHeightWrites(host);
668
+ key.value = "source";
669
+ await nextTick();
670
+ await nextTick();
671
+ const entering = () => [...container.querySelectorAll<HTMLElement>(".hk-dswap-item")].find((el) => el.dataset.swapKey === "source");
672
+ const leaving = () => [...container.querySelectorAll<HTMLElement>(".hk-dswap-item")].find((el) => el.dataset.swapKey === "preview");
673
+ // The enter settles in the frame (no transition detected on it) —
674
+ // Vue strips its active class — while the leaving copy is parked
675
+ // on its faked 600ms.
676
+ await vi.waitFor(() => expect(entering()?.classList.contains("hk-dswap-enter-active")).toBe(false), { timeout: 1000 });
677
+ expect(leaving(), "the leaving copy must still be in the cell for this pin to mean anything").toBeTruthy();
678
+ // Enter settled, leave pending: STILL armed at the target.
679
+ expect(host.hasAttribute("data-height-anim"), "released too early (enter-only settle)").toBe(true);
680
+ expect(host.style.height).toBe("100px");
681
+ expect(writes).toEqual(["240px", "100px"]);
682
+ // Then the leave resolves and the release follows. The bound sits
683
+ // UNDER the watchdog's 1500ms on purpose: a settle path that never
684
+ // fires would still be swept (and released) by the watchdog, and
685
+ // this pin would go green with the wrong cause.
686
+ // comment-gate-ok: the bound is enforced by this pin's own waitFor
687
+ // (MUT:swap-height-release-waits-for-leave, above).
688
+ await vi.waitFor(() => expect(host.hasAttribute("data-height-anim")).toBe(false), { timeout: 1000 });
689
+ expect(host.style.height).toBe("");
690
+ expect(writes).toEqual(["240px", "100px", ""]);
691
+ unspy();
692
+ } finally {
693
+ restore();
694
+ restoreSlow();
695
+ }
696
+ });
697
+
698
+ // MUT:swap-height-release-waits-for-enter — the other half of the
699
+ // release condition: with the LEAVE settled and the enter still
700
+ // running, releasing would drop the host from its MID-TWEEN height to
701
+ // `auto` in one frame — a snap to the target instead of the last
702
+ // stretch of the tween. (`slowSide("leave", …)` above cannot see
703
+ // this: there the enter settles first, so a release keyed on `leaving`
704
+ // alone lands at the right moment by accident — M7 survived it.)
705
+ it("holds the tween armed until the enter settles when the leave settles first", async () => {
706
+ const restoreSlow = slowSide("enter", 600);
707
+ const restore = stubGrid({ preview: 240, source: 100 });
708
+ try {
709
+ const key = ref("preview");
710
+ const container = document.createElement("div");
711
+ document.body.appendChild(container);
712
+ const app = createApp({
713
+ render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
714
+ });
715
+ app.mount(container);
716
+ mounts.push({ app, container });
717
+ await settle();
718
+ const host = container.querySelector<HTMLElement>(".hk-dswap")!;
719
+ const { writes, restore: unspy } = spyHeightWrites(host);
720
+ key.value = "source";
721
+ await nextTick();
722
+ await nextTick();
723
+ const leaving = () => [...container.querySelectorAll<HTMLElement>(".hk-dswap-item")].find((el) => el.dataset.swapKey === "preview");
724
+ const entering = () => [...container.querySelectorAll<HTMLElement>(".hk-dswap-item")].find((el) => el.dataset.swapKey === "source");
725
+ // The leave settles in the frame — the copy is gone — while the
726
+ // entering copy is still parked on its faked 600ms.
727
+ await vi.waitFor(() => expect(leaving()).toBeUndefined(), { timeout: 1000 });
728
+ expect(entering()?.classList.contains("hk-dswap-enter-active"), "the enter must still be running for this pin to mean anything").toBe(true);
729
+ // Leave settled, enter pending: STILL armed at the target.
730
+ expect(host.hasAttribute("data-height-anim"), "released too early (leave-only settle)").toBe(true);
731
+ expect(host.style.height).toBe("100px");
732
+ expect(writes).toEqual(["240px", "100px"]);
733
+ // Then the enter resolves and the release follows (bounded under
734
+ // the watchdog's 1500ms for the same reason as above).
735
+ await vi.waitFor(() => expect(host.hasAttribute("data-height-anim")).toBe(false), { timeout: 1000 });
736
+ expect(host.style.height).toBe("");
737
+ expect(writes).toEqual(["240px", "100px", ""]);
738
+ // MUT:swap-height-entersettle-reset — a SECOND exchange in the same
739
+ // order. The first left `enterSettled` true; `onEnter` must reset
740
+ // it, or this exchange's after-leave (which settles first here)
741
+ // reads a stale true and releases while the enter is still parked —
742
+ // a snap to `auto` mid-tween (R3: deleting the reset in `onEnter`
743
+ // left the one-swap pins green).
744
+ key.value = "preview";
745
+ await nextTick();
746
+ await nextTick();
747
+ // Roles swap with the key: the leaving copy is the source pane now.
748
+ const itemEl = (k: string) => [...container.querySelectorAll<HTMLElement>(".hk-dswap-item")].find((el) => el.dataset.swapKey === k);
749
+ await vi.waitFor(() => expect(itemEl("source")).toBeUndefined(), { timeout: 1000 });
750
+ expect(itemEl("preview")?.classList.contains("hk-dswap-enter-active"), "the second enter must still be running for this pin to mean anything").toBe(true);
751
+ expect(host.hasAttribute("data-height-anim"), "released on a stale enterSettled from the previous exchange").toBe(true);
752
+ expect(host.style.height).toBe("240px");
753
+ expect(writes).toEqual(["240px", "100px", "", "100px", "240px"]);
754
+ await vi.waitFor(() => expect(host.hasAttribute("data-height-anim")).toBe(false), { timeout: 1000 });
755
+ expect(host.style.height).toBe("");
756
+ expect(writes).toEqual(["240px", "100px", "", "100px", "240px", ""]);
757
+ unspy();
758
+ } finally {
759
+ restore();
760
+ restoreSlow();
761
+ }
762
+ });
763
+
764
+ // MUT:swap-height-teardown-live-leave — the same teardown with a LEAVING
765
+ // copy still parked in the cell (the disabled pin above parks the enter):
766
+ // the release must not wait for a copy whose leave will never settle
767
+ // under the disabled branch.
768
+ it("releases the armed tween when the host flips to disabled while a leaving copy is parked", async () => {
769
+ const restoreSlow = slowSide("leave", 600);
770
+ const restore = stubGrid({ preview: 240, source: 100 });
771
+ try {
772
+ const key = ref("preview");
773
+ const disabled = ref(false);
774
+ const container = document.createElement("div");
775
+ document.body.appendChild(container);
776
+ const app = createApp({
777
+ render: () =>
778
+ h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true, disabled: disabled.value }, () => [h("p", key.value)]),
779
+ });
780
+ app.mount(container);
781
+ mounts.push({ app, container });
782
+ await settle();
783
+ const host = container.querySelector<HTMLElement>(".hk-dswap")!;
784
+ key.value = "source";
785
+ await nextTick();
786
+ await nextTick();
787
+ const leaving = [...container.querySelectorAll<HTMLElement>(".hk-dswap-item")].find((el) => el.dataset.swapKey === "preview");
788
+ expect(leaving?.classList.contains("hk-dswap-leave-active"), "the leaving copy must still be parked for this pin to mean anything").toBe(true);
789
+ expect(host.hasAttribute("data-height-anim")).toBe(true);
790
+ disabled.value = true;
791
+ await nextTick();
792
+ await nextTick();
793
+ expect(host.hasAttribute("data-swap-disabled")).toBe(true);
794
+ expect(host.hasAttribute("data-height-anim"), "height left armed after the Transition went away").toBe(false);
795
+ expect(host.style.height).toBe("");
796
+ } finally {
797
+ restore();
798
+ restoreSlow();
799
+ }
800
+ });
801
+
802
+ // MUT:swap-height-teardown-unmount — the component's own unmount is
803
+ // the third teardown path, and the one the ref cannot serve: Vue nulls
804
+ // `hostRef` on the host vnode BEFORE the Transition child's
805
+ // `onVnodeBeforeUnmount` runs, so a release keyed on the ref alone is a
806
+ // no-op exactly here (R6 measured the detached host still armed). The
807
+ // release must land on the element the tween was armed on, so a node a
808
+ // host re-inserts never comes back frozen.
809
+ it("releases the armed tween when the component unmounts mid-exchange", async () => {
810
+ const restoreSlow = slowSide("enter", 600);
811
+ const restore = stubGrid({ preview: 240, source: 100 });
812
+ try {
813
+ const key = ref("preview");
814
+ const container = document.createElement("div");
815
+ document.body.appendChild(container);
816
+ const app = createApp({
817
+ render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
818
+ });
819
+ app.mount(container);
820
+ await settle();
821
+ const host = container.querySelector<HTMLElement>(".hk-dswap")!;
822
+ key.value = "source";
823
+ await nextTick();
824
+ await nextTick();
825
+ expect(host.hasAttribute("data-height-anim")).toBe(true);
826
+ expect(host.style.height).toBe("100px");
827
+ app.unmount();
828
+ mounts.splice(mounts.findIndex((m) => m.app === app), 1);
829
+ await nextTick();
830
+ expect(host.isConnected).toBe(false);
831
+ expect(host.hasAttribute("data-height-anim"), "the detached host came out still armed").toBe(false);
832
+ expect(host.style.height).toBe("");
833
+ } finally {
834
+ restore();
835
+ restoreSlow();
836
+ }
837
+ });
838
+
839
+ // MUT:swap-height-release-own-write-only — the release undoes THIS
840
+ // component's inline height and nothing else: a host that sized itself
841
+ // mid-exchange keeps its own number through the release (the arm is
842
+ // still undone — the attribute goes). R7: the attribute removal was
843
+ // guarded but the height write was not, so the "only ever unwinds this
844
+ // component's own writes" promise held for one of the two writes.
845
+ it("leaves a host-set inline height alone when it changed mid-exchange", async () => {
846
+ const restoreSlow = slowSide("enter", 600);
847
+ const restore = stubGrid({ preview: 240, source: 100 });
848
+ try {
849
+ const key = ref("preview");
850
+ const container = document.createElement("div");
851
+ document.body.appendChild(container);
852
+ const app = createApp({
853
+ render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
854
+ });
855
+ app.mount(container);
856
+ mounts.push({ app, container });
857
+ await settle();
858
+ const host = container.querySelector<HTMLElement>(".hk-dswap")!;
859
+ key.value = "source";
860
+ await nextTick();
861
+ await nextTick();
862
+ expect(host.hasAttribute("data-height-anim")).toBe(true);
863
+ expect(host.style.height).toBe("100px");
864
+ // The host writes its own height while the tween is armed.
865
+ host.style.height = "77px";
866
+ await vi.waitFor(() => expect(host.hasAttribute("data-height-anim")).toBe(false), { timeout: 1000 });
867
+ expect(host.style.height, "a host height written mid-exchange must survive the release").toBe("77px");
868
+ } finally {
869
+ restore();
870
+ restoreSlow();
871
+ }
872
+ });
873
+
874
+ // MUT:swap-height-fractional-targets — the tween writes the FRACTIONAL
875
+ // layout height, not an integer-rounded figure: at the release the
876
+ // explicit height comes off and the cell resolves to that same natural
877
+ // height, so the release frame must land with NO sub-pixel step (the
878
+ // docs shell shipped a visible 189 → 188.73 jump at release because the
879
+ // first cut read the rounded `offsetHeight`). A mutant that reverts to
880
+ // `offsetHeight` reads the un-stubbed real value (0), fails the
881
+ // unreadable-height guard, never arms — and this pin goes red.
882
+ it("writes fractional heights so the release lands with no sub-pixel step", async () => {
883
+ const restore = stubGrid({ preview: 200, source: 188.7265625 }, () => 188.7265625);
884
+ try {
885
+ const key = ref("preview");
886
+ const container = document.createElement("div");
887
+ document.body.appendChild(container);
888
+ const app = createApp({
889
+ render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
890
+ });
891
+ app.mount(container);
892
+ mounts.push({ app, container });
893
+ await settle();
894
+ const host = container.querySelector<HTMLElement>(".hk-dswap")!;
895
+ const { writes, restore: unspy } = spyHeightWrites(host);
896
+ key.value = "source";
897
+ await nextTick();
898
+ await nextTick();
899
+ // The freeze is the outgoing copy's exact height, the target the
900
+ // incoming copy's own — both fractional, neither rounded. (The spy
901
+ // records the set value verbatim; the real style store re-serialises
902
+ // on read-back, which is exactly the hazard the release guard below
903
+ // must tolerate.)
904
+ expect(writes).toEqual(["200px", "188.7265625px"]);
905
+ // The RELEASE side is what the first cut got wrong: its guard
906
+ // compared the read-back (re-serialised) height against the write
907
+ // exactly and never cleared, stranding the host at a fractional
908
+ // height for good. The guard must come off here — assert the
909
+ // outcome, not the armed state (MUT:swap-height-fractional-targets,
910
+ // which is this test's own id).
911
+ await vi.waitFor(() => expect(host.hasAttribute("data-height-anim")).toBe(false), { timeout: 1000 });
912
+ expect(host.style.height, "the release must come off at a genuine fractional height").toBe("");
913
+ unspy();
914
+ } finally {
915
+ restore();
916
+ }
917
+ });
918
+
919
+ // MUT:swap-height-no-tolerance — the release guard is an EXACT compare
920
+ // against the value the store itself reported for our own write at arm
921
+ // time, so the store's re-serialisation cancels on both sides and a
922
+ // host's own write is never swallowed. R3 of #1668: a 0.5px tolerance
923
+ // (a) was still ~20× wider than either serialiser needs and (b) DID
924
+ // swallow a host's write — at an armed 188.7265625, a host writing
925
+ // `189px` differs by 0.273 and was silently cleared. This pin sweeps the
926
+ // window: every offset inside ±0.5px must survive the release.
927
+ it("keeps a host write inside half a pixel of the armed height", async () => {
928
+ const natural = 188.7265625;
929
+ for (const hostWrite of ["189px", "188.5px", "188.25px", "189.25px"]) {
930
+ const restore = stubGrid({ preview: 200, source: natural }, () => natural);
931
+ try {
932
+ const key = ref("preview");
933
+ const container = document.createElement("div");
934
+ document.body.appendChild(container);
935
+ const app = createApp({
936
+ render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
937
+ });
938
+ app.mount(container);
939
+ mounts.push({ app, container });
940
+ await settle();
941
+ const host = container.querySelector<HTMLElement>(".hk-dswap")!;
942
+ key.value = "source";
943
+ await nextTick();
944
+ await nextTick();
945
+ expect(host.hasAttribute("data-height-anim")).toBe(true);
946
+ host.style.height = hostWrite;
947
+ await vi.waitFor(() => expect(host.hasAttribute("data-height-anim")).toBe(false), { timeout: 1000 });
948
+ expect(host.style.height, `a host write of ${hostWrite} must not be swallowed`).toBe(hostWrite);
949
+ } finally {
950
+ restore();
951
+ }
952
+ }
953
+ });
954
+
955
+ // MUT:swap-height-readback-nonempty — the arm-time read-back premise,
956
+ // pinned through its CONSEQUENCE and not through the DOM the component
957
+ // already wrote: a `""`/stale `armedHeight` makes the release compare
958
+ // fail silently and keeps the explicit height, so THIS pin arms at a
959
+ // height happy-dom re-serialises and requires the release to come off.
960
+ // (Its first cut only asserted the DOM at arm time — never `armedHeight`
961
+ // — and stayed green under the very mutant it named; R5 caught that.)
962
+ it("arms with the store's own read-back of our write, not an empty value", async () => {
963
+ const restore = stubGrid({ preview: 200, source: 188.7265625 }, () => 188.7265625);
964
+ try {
965
+ const key = ref("preview");
966
+ const container = document.createElement("div");
967
+ document.body.appendChild(container);
968
+ const app = createApp({
969
+ render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
970
+ });
971
+ app.mount(container);
972
+ mounts.push({ app, container });
973
+ await settle();
974
+ const host = container.querySelector<HTMLElement>(".hk-dswap")!;
975
+ key.value = "source";
976
+ await nextTick();
977
+ await nextTick();
978
+ expect(host.hasAttribute("data-height-anim")).toBe(true);
979
+ // The armed value IS the store's report of the write we just made.
980
+ expect(host.style.height).not.toBe("");
981
+ expect(host.style.height).toMatch(/^[\d.]+px$/);
982
+ // …and the premise must SUPPORT the release: a "" / stale
983
+ // `armedHeight` leaves this explicit height behind for good.
984
+ await vi.waitFor(() => expect(host.hasAttribute("data-height-anim")).toBe(false), { timeout: 1000 });
985
+ expect(host.style.height, "the arm-time read-back must let the release through").toBe("");
986
+ } finally {
987
+ restore();
988
+ }
989
+ });
990
+
991
+ // MUT:swap-height-release-order — "armed" and "carries our explicit
992
+ // height" must be observable together: the height comes off BEFORE the
993
+ // armed attribute does. A MutationObserver cannot see this (both writes
994
+ // land in one synchronous block and the callback is a microtask, so it
995
+ // only ever sees the end state — measured: the reversed order passed a
996
+ // MutationObserver pin). The order is therefore pinned at the SEAM: the
997
+ // attribute removal is observed synchronously via an own-property hook
998
+ // on `removeAttribute`, and at that instant the inline height must
999
+ // already be gone.
1000
+ it("clears the height before dropping the armed attribute", async () => {
1001
+ const restore = stubGrid({ preview: 200, source: 188.7265625 });
1002
+ try {
1003
+ const key = ref("preview");
1004
+ const container = document.createElement("div");
1005
+ document.body.appendChild(container);
1006
+ const app = createApp({
1007
+ render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
1008
+ });
1009
+ app.mount(container);
1010
+ mounts.push({ app, container });
1011
+ await settle();
1012
+ const host = container.querySelector<HTMLElement>(".hk-dswap")!;
1013
+ const atDisarm: string[] = [];
1014
+ const realRemove = host.removeAttribute.bind(host);
1015
+ Object.defineProperty(host, "removeAttribute", {
1016
+ configurable: true,
1017
+ value(name: string) {
1018
+ if (name === "data-height-anim") atDisarm.push(host.style.height);
1019
+ return realRemove(name);
1020
+ },
1021
+ });
1022
+ key.value = "source";
1023
+ await nextTick();
1024
+ await nextTick();
1025
+ await vi.waitFor(() => expect(host.hasAttribute("data-height-anim")).toBe(false), { timeout: 1000 });
1026
+ delete (host as unknown as Record<string, unknown>).removeAttribute;
1027
+ expect(atDisarm.length, "the disarm must be observed").toBeGreaterThan(0);
1028
+ expect(atDisarm, "the height must already be cleared when the armed attribute goes").toEqual([""]);
1029
+ expect(host.style.height).toBe("");
1030
+ } finally {
1031
+ restore();
1032
+ }
1033
+ });
1034
+
355
1035
  // MUT:swap-height-zero-skips — an unreadable height (hidden host, or
356
1036
  // an incoming pane not yet laid out reports 0) skips the tween: a
357
1037
  // 0px freeze would collapse the surface for the whole exchange and
@@ -435,16 +1115,26 @@ describe("HkDirectionalSwap", () => {
435
1115
  });
436
1116
 
437
1117
  // MUT:swap-height-followup-current — a faster follow-up swap arrives
438
- // AFTER Vue cancelled the interrupted enter (the release runs, then the
439
- // fresh exchange begins): its freeze must read the cell's CURRENT
440
- // rendered height via offsetHeight — never a remembered start value.
441
- // The moving `current` stub stands in for the live layout height this
442
- // DOM cannot compute; the write sequence pins it exactly: the second
443
- // exchange writes [150px (its own freeze), 240px (its target)] — a
444
- // regression that remembers the old start writes [100px, ...] first.
1118
+ // while the first exchange is mid-tween: Vue cancels the interrupted
1119
+ // enter, and the fresh exchange must freeze at the cell's CURRENT
1120
+ // RENDERED height — the animated mid-state — never the row and never a
1121
+ // remembered start. What this pin defends is the ABSENCE of a release
1122
+ // on cancel: while the tween stays armed, both the before-leave read and
1123
+ // the armed fallback at enter resolve to the animated value (they agree
1124
+ // by construction — `restHeight` itself is pinned by the growing test
1125
+ // above), whereas a cancel that releases drops `data-height-anim`, the
1126
+ // host reads `auto` — the ROW, the taller copy still in the cell — and
1127
+ // the follow-up freezes there: 240px → 240px, the tween dead (R2 of the
1128
+ // first cut measured exactly that). `stubGrid`'s `rendered` models the
1129
+ // animated value a browser renders while armed, and only while armed.
1130
+ // comment-gate-ok: the armed gating is the `stubGrid` self-test's own
1131
+ // pin (MUT:swap-height-stubgrid-model); the no-release sequence below is
1132
+ // this pin's (MUT:swap-height-followup-current, above).
1133
+ // The sequence pins it exactly: freeze, target, re-freeze at the
1134
+ // mid-state, re-target — with no release in between.
445
1135
  it("a follow-up exchange freezes at the current rendered height, not the old start", async () => {
446
- let current = 100;
447
- const restore = stubLayout(() => current, () => 240);
1136
+ let current: number | null = null;
1137
+ const restore = stubGrid({ preview: 240, source: 100 }, () => current);
448
1138
  const writes: string[] = [];
449
1139
  try {
450
1140
  const key = ref("preview");
@@ -465,22 +1155,134 @@ describe("HkDirectionalSwap", () => {
465
1155
  descSet.call(host.style, v);
466
1156
  },
467
1157
  });
468
- // First exchange.
1158
+ // First exchange: from rest (240) down to the source pane (100).
1159
+ key.value = "source";
1160
+ await nextTick();
1161
+ await nextTick();
1162
+ // Follow-up swap mid-tween: the host is armed and rendering 170.
1163
+ // Vue cancels the interrupted enter (the tween stays armed), the
1164
+ // before-leave hook reads the animated 170, and the fresh exchange
1165
+ // freezes there before its target (the preview pane's own 240).
1166
+ current = 170;
1167
+ key.value = "preview";
1168
+ await nextTick();
1169
+ await nextTick();
1170
+ expect(host.hasAttribute("data-height-anim")).toBe(true);
1171
+ expect(writes).toEqual(["240px", "100px", "170px", "240px"]);
1172
+ } finally {
1173
+ restore();
1174
+ }
1175
+ });
1176
+
1177
+ // MUT:swap-height-back-and-forth — the reader toggles back to the
1178
+ // pane they just left before the exchange settles. Vue cancels the
1179
+ // interrupted enter, then FINISHES the first copy's leave (a keyed swap
1180
+ // mounts a fresh element for the returning key; its old copy is removed
1181
+ // at once — `leave-cancelled` never fires here, measured) and enters
1182
+ // the fresh one. The cancel must not release: the second freeze has to
1183
+ // read the animated mid-state. `slowSide("enter")` keeps the source
1184
+ // pane's enter running so the exchange is genuinely mid-flight when the
1185
+ // toggle returns; the sequence pins no release between the exchanges.
1186
+ it("a back-and-forth toggle re-freezes at the mid-state through a cancelled enter", async () => {
1187
+ const restoreSlow = slowSide("enter", 600);
1188
+ let current: number | null = null;
1189
+ const restore = stubGrid({ preview: 240, source: 100 }, () => current);
1190
+ try {
1191
+ const key = ref("preview");
1192
+ const container = document.createElement("div");
1193
+ document.body.appendChild(container);
1194
+ const app = createApp({
1195
+ render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
1196
+ });
1197
+ app.mount(container);
1198
+ mounts.push({ app, container });
1199
+ await settle();
1200
+ const host = container.querySelector<HTMLElement>(".hk-dswap")!;
1201
+ const { writes, restore: unspy } = spyHeightWrites(host);
469
1202
  key.value = "source";
470
1203
  await nextTick();
471
1204
  await nextTick();
472
- // Follow-up swap: Vue cancels the interrupted enter — the release
473
- // writes "" — then the fresh exchange freezes at the CURRENT
474
- // stubbed height before its target. The full sequence pins all of
475
- // it: freeze, target, cancel-release, re-freeze, re-target.
476
- current = 150;
1205
+ expect(writes).toEqual(["240px", "100px"]);
1206
+ current = 170;
477
1207
  key.value = "preview";
478
1208
  await nextTick();
479
1209
  await nextTick();
1210
+ expect(host.hasAttribute("data-height-anim"), "armed across the cancelled leave").toBe(true);
1211
+ expect(writes).toEqual(["240px", "100px", "170px", "240px"]);
1212
+ // The returning pane (a fresh element) is live: never inert, never
1213
+ // hidden — the leaving copy's dead-content marks die with it.
1214
+ // comment-gate-ok: asserted on the two lines after the lookup
1215
+ // (MUT:swap-height-back-and-forth, above).
1216
+ const back = [...container.querySelectorAll<HTMLElement>(".hk-dswap-item")].find((el) => el.dataset.swapKey === "preview")!;
1217
+ expect(back.hasAttribute("inert")).toBe(false);
1218
+ expect(back.getAttribute("aria-hidden")).toBeNull();
1219
+ unspy();
1220
+ } finally {
1221
+ restore();
1222
+ restoreSlow();
1223
+ }
1224
+ });
1225
+
1226
+ // MUT:swap-height-teardown-releases — the other half of the bargain:
1227
+ // a tween kept armed through cancelled hooks must release when the
1228
+ // Transition itself goes away, or a host that flips to `disabled`
1229
+ // mid-exchange freezes the height for good (no exchange hook ever
1230
+ // runs again in that branch). Vue's `onVnodeBeforeUnmount` on the
1231
+ // Transition is the signal.
1232
+ it("releases the armed tween when the host flips to disabled mid-exchange", async () => {
1233
+ const restoreSlow = slowSide("enter", 600);
1234
+ const restore = stubGrid({ preview: 240, source: 100 });
1235
+ try {
1236
+ const key = ref("preview");
1237
+ const disabled = ref(false);
1238
+ const container = document.createElement("div");
1239
+ document.body.appendChild(container);
1240
+ const app = createApp({
1241
+ render: () =>
1242
+ h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true, disabled: disabled.value }, () => [h("p", key.value)]),
1243
+ });
1244
+ app.mount(container);
1245
+ mounts.push({ app, container });
1246
+ await settle();
1247
+ const host = container.querySelector<HTMLElement>(".hk-dswap")!;
1248
+ key.value = "source";
1249
+ await nextTick();
1250
+ await nextTick();
480
1251
  expect(host.hasAttribute("data-height-anim")).toBe(true);
481
- expect(writes).toEqual(["100px", "240px", "", "150px", "240px"]);
1252
+ expect(host.style.height).toBe("100px");
1253
+ disabled.value = true;
1254
+ await nextTick();
1255
+ await nextTick();
1256
+ expect(host.hasAttribute("data-swap-disabled")).toBe(true);
1257
+ expect(host.hasAttribute("data-height-anim"), "height left armed after the Transition went away").toBe(false);
1258
+ expect(host.style.height).toBe("");
1259
+ // And the disabled branch still swaps synchronously at auto height
1260
+ // (no hooks there, so nothing arms again).
1261
+ key.value = "preview";
1262
+ await nextTick();
1263
+ expect(host.hasAttribute("data-height-anim")).toBe(false);
1264
+ expect(host.style.height).toBe("");
1265
+ // Re-enabling the Transition mid-interrupted-exchange and swapping
1266
+ // again must arm and release normally (a real host path: flip
1267
+ // `disabled`, flip it back, toggle). The teardown's settle-state
1268
+ // reset is defensive here — Vue's own leave flow still fires the
1269
+ // interrupted copy's after-leave once its frame callback resolves,
1270
+ // so the counter balances with or without the reset (R3: deleting
1271
+ // the reset lines left the suite green); this pins the path, not
1272
+ // the reset.
1273
+ disabled.value = false;
1274
+ await nextTick();
1275
+ await nextTick();
1276
+ expect(host.hasAttribute("data-swap-disabled")).toBe(false);
1277
+ key.value = "source";
1278
+ await nextTick();
1279
+ await nextTick();
1280
+ expect(host.hasAttribute("data-height-anim"), "the re-enabled exchange must arm").toBe(true);
1281
+ await vi.waitFor(() => expect(host.hasAttribute("data-height-anim")).toBe(false), { timeout: 1000 });
1282
+ expect(host.style.height).toBe("");
482
1283
  } finally {
483
1284
  restore();
1285
+ restoreSlow();
484
1286
  }
485
1287
  });
486
1288