diff --git a/desktop/src/features/channels/ui/BotActivityBar.tsx b/desktop/src/features/channels/ui/BotActivityBar.tsx index a8981be20b..ab8f4b8c2f 100644 --- a/desktop/src/features/channels/ui/BotActivityBar.tsx +++ b/desktop/src/features/channels/ui/BotActivityBar.tsx @@ -226,7 +226,11 @@ function BotActivityAgentPill({ /** Strip-level hover popover state shared by every pill. */ hover: StripHoverPopover; onOpenAgentSession: (pubkey: string, channelId?: string | null) => void; - /** Freeze the pill's rendered width (a hover card is showing). */ + /** + * Freeze the pill's rendered width — set only while a hover card is open + * AND this pill's resize would move it (the pill anchors the card or sits + * left of the anchor). + */ pinWidth: boolean; profiles?: UserProfileLookup; }) { @@ -261,10 +265,12 @@ function BotActivityAgentPill({ ); }, [holdLabelSwap, activeId, activeLabel]); - // While a hover card is showing, the pill must not resize: label swaps + // While this pill's resize could move the open hover card (it is the + // card's anchor, or sits left of it), it must not resize: label swaps // keep animating, but a longer/shorter label truncating inside a FROZEN - // width can no longer shift the neighboring pills under the cursor. The - // width is measured once when the hold starts and dropped on release. + // width can no longer shift the card's anchor edge or slide the trigger + // out from under the cursor. The width is measured once when the pin + // starts and dropped on release. const triggerRef = React.useRef(null); const [pinnedWidth, setPinnedWidth] = React.useState(null); React.useLayoutEffect(() => { @@ -394,8 +400,9 @@ function BotActivityAgentPill({ * that run for the same duration as the slot spring, so the fade and the * move finish together and reorders read as a shuffle instead of a hard * swap. Enter/exit use the same scale+fade treatment. While a hover card is - * showing (`freezeLayout`), layout animation is disabled entirely so nothing - * can slide under the cursor. + * showing and this slot's movement would displace it (`freezeLayout` — the + * slot holds the card's anchor pill or one left of it), layout animation is + * disabled so nothing can shift the card or slide under the cursor. */ function AnimatedPillSlot({ children, @@ -405,7 +412,10 @@ function AnimatedPillSlot({ }: { /** Render prop so the pill can defer label swaps while its slot moves. */ children: (isMoving: boolean) => React.ReactNode; - /** Disable slot layout animation while a hover card is showing. */ + /** + * Disable slot layout animation while a hover card is open and this + * slot's movement would displace it (anchor pill or left of the anchor). + */ freezeLayout: boolean; shouldReduceMotion: boolean; /** @@ -470,10 +480,15 @@ function AnimatedPillSlot({ * whole turn, so liveness is carried by each pill's label ticker while * positional motion is reserved for membership changes: a newly working * agent's pill enters on the right, a finished agent's pill exits and its - * neighbors animate into the gap. No movement happens while the cursor is - * over the bar or a hover card is showing, when order, membership, layout - * animation, and pill widths are all frozen so nothing can move out from - * under (or slide under) the cursor. Each pill truncates its label at its own max width. A lone + * neighbors animate into the gap. While the cursor is over the bar or a + * hover card is showing, order and membership are frozen so a pill can't + * exit (or enter) and slide the strip under the cursor. Width pinning and + * layout freezing are narrower — placement-aware: only while a card is OPEN, + * and only for the pills whose resize would actually move it (the card is + * side="top" align="start", anchored to its pill's left edge, so just the + * anchor pill and the pills left of it qualify). Pills right of the anchor — + * and every pill when no card is open — stay free to resize with their + * label swaps. Each pill truncates its label at its own max width. A lone * pill shrinks with a narrow container (its label ellipsizes) so it always * fits; when SEVERAL pills outgrow a narrow container (thread panel * toolbars especially) the strip scrolls horizontally — scrollbar hidden, @@ -493,11 +508,13 @@ export function BotActivityComposerAction({ }: BotActivityBarProps) { const shouldReduceMotion = useReducedMotion(); const hover = useStripHoverPopover(); - // The freeze engages as soon as the cursor is anywhere over the bar — not - // only once a card opens — so pills can't move (or resize) under a cursor - // that is still traveling toward one. It also holds while a card is open - // with the cursor off the bar (over the card itself, or during the close - // grace period). + // The MEMBERSHIP freeze engages as soon as the cursor is anywhere over the + // bar — not only once a card opens — so pills can't enter/exit and slide + // the strip under a cursor that is still traveling toward one. It also + // holds while a card is open with the cursor off the bar (over the card + // itself, or during the close grace period). Width pinning is NOT tied to + // this hold — it is placement-aware and applies per pill only while a + // card is open (see activeCardIndex below). const [barHovered, setBarHovered] = React.useState(false); const holdActive = barHovered || hover.activePubkey !== null; @@ -568,6 +585,20 @@ export function BotActivityComposerAction({ ); }, [holdActive, liveOrderedAgents]); + // Placement-aware resize guard: index of the pill anchoring the open hover + // card, or -1 with no card up. The card is side="top" align="start" — + // anchored to its pill's LEFT edge — so only a resize of the anchor pill + // itself (which could also slide the trigger out from under the cursor) + // or of a pill left of it can move the card. Those pills pin their width + // and freeze their slot's layout animation; pills right of the anchor — + // and every pill when no card is open — resize freely with label swaps. + const activeCardIndex = + hover.activePubkey === null + ? -1 + : orderedAgents.findIndex( + (agent) => agent.pubkey.toLowerCase() === hover.activePubkey, + ); + if (orderedAgents.length === 0 && typingIndicator == null) { return null; } @@ -589,6 +620,10 @@ export function BotActivityComposerAction({ // a dead gutter after the fade. At rest nothing changes: the padding // keeps the first pill aligned to the gutter. className="relative -mx-5 min-w-0 flex-1" + // Exposes the membership hold to the e2e suite: width pins no longer + // engage on bar hover alone, so tests need this to know the hold is + // armed before mutating membership. + data-hold={holdActive ? "true" : undefined} data-testid="bot-activity-strip" onMouseEnter={() => setBarHovered(true)} onMouseLeave={() => setBarHovered(false)} @@ -620,32 +655,39 @@ export function BotActivityComposerAction({ )} > - {orderedAgents.map((agent) => ( - - {(isMoving) => ( - - )} - - ))} + {orderedAgents.map((agent, index) => { + const guardsOpenCard = + activeCardIndex !== -1 && index <= activeCardIndex; + return ( + + {(isMoving) => ( + + )} + + ); + })} {typingIndicator == null ? null : ( { + const count = await triggers.count(); + const measure = () => + Promise.all( + Array.from({ length: count }, (_, index) => + triggers.nth(index).boundingBox(), + ), + ); + const before = await measure(); + await page.waitForTimeout(150); + expect(await measure()).toEqual(before); + }).toPass(); +} + /** * Open #agents with two seeded working agents. Pill order follows turn * START anchors (earliest worker left-most): nova's turn starts 60s before @@ -2335,6 +2363,17 @@ async function openAgentsChannelWithTwoWorkingPills( "aria-label", "nova is working. View activity.", ); + // The pills mount with the generic " is working…" label and GROW + // when the seeded headlines tick in. Wait for the swap and for the boxes + // to settle so callers measure — and park the cursor against — final + // geometry, not a strip that is still expanding rightward. + await expect(triggers.first()).toContainText( + "Nova: tracing the observer store", + ); + await expect(triggers.nth(1)).toContainText( + "Astra: reviewing the composer wiring", + ); + await waitForSettledPillBoxes(page, triggers); return { baseMs, triggers }; } @@ -2427,22 +2466,32 @@ test("hovering the bar itself freezes pill membership without opening a card", a await installMockBridge(page, { managedAgents: PILL_AGENT_SEEDS }); const { baseMs, triggers } = await openAgentsChannelWithTwoWorkingPills(page); - // Park the cursor in the gap between the two pills — over the strip, not a - // pill trigger. The strip sizes to its content, so there is no reliable - // "empty right side"; the inter-pill gap is the one spot guaranteed to be - // strip-not-pill. This alone must engage the freeze; no card opens. + // Park the cursor on the strip past the last pill — over the bar, not a + // pill trigger. The strip root is a flex-1 row item, so the space right of + // the pills is strip-not-pill. Widths are no longer pinned on bar hover, + // so the inter-pill gap is unsafe: a label swap growing the left pill + // would push the trigger under a cursor parked there and open a card. + // This alone must engage the membership freeze; no card opens. const novaBox = await triggers.first().boundingBox(); const astraBox = await triggers.nth(1).boundingBox(); if (!novaBox || !astraBox) { throw new Error("Both pills must be visible."); } await page.mouse.move( - (novaBox.x + novaBox.width + astraBox.x) / 2, + astraBox.x + astraBox.width + 60, novaBox.y + novaBox.height / 2, ); - // The bar hold pins every pill's width via an inline style — waiting for - // it proves the freeze is engaged before the membership change below. - await expect(triggers.first()).toHaveAttribute("style", /width/); + // Bar hover alone no longer pins pill widths (the pin is placement-aware + // and engages only for pills at/left of an OPEN card's anchor) — the strip + // exposes the membership hold via data-hold; waiting for it proves the + // freeze is engaged before the membership change below. + await expect(page.getByTestId("bot-activity-strip")).toHaveAttribute( + "data-hold", + "true", + ); + // No card is open, so no pill is width-pinned. + await expect(triggers.first()).not.toHaveAttribute("style", /width/); + await expect(triggers.nth(1)).not.toHaveAttribute("style", /width/); await expect(page.getByTestId("composer-live-activity-feed")).toHaveCount(0); // Astra's turn completes — her pill would exit, sliding the strip under @@ -2492,6 +2541,99 @@ test("hovering the bar itself freezes pill membership without opening a card", a ); }); +test("open card pins only its anchor pill and the pills left of it", async ({ + page, +}) => { + await installMockBridge(page, { managedAgents: PILL_AGENT_SEEDS }); + const { baseMs, triggers } = await openAgentsChannelWithTwoWorkingPills(page); + + const novaPill = page.getByRole("button", { + name: "nova is working. View activity.", + }); + const astraPill = page.getByRole("button", { + name: "astra is working. View activity.", + }); + const feed = page.getByTestId("composer-live-activity-feed"); + + // Give astra a SHORT label first so the long label seeded mid-hover below + // grows her pill by a measurable amount (the helper's default label may + // already sit near the pill's max-width cap). + await seedPillActivityMessage(page, { + agentPubkey: PILL_AGENT_ASTRA, + atMs: baseMs + 3_000, + seq: baseMs + 10_003, + text: "Astra: ok", + turnId: "pill-turn-astra", + }); + await expect(astraPill).toContainText("Astra: ok"); + // The shrink animates via the slot layout spring — settle before + // measuring baseline geometry. + await waitForSettledPillBoxes(page, triggers); + + // Card on the FIRST pill: the card anchors to nova's left edge, so astra + // (right of the anchor) stays free to resize — her growth cannot move it. + await novaPill.hover(); + await expect(feed).toBeVisible(); + // Only the anchor pill carries the inline width pin. + await expect(novaPill).toHaveAttribute("style", /width/); + await expect(astraPill).not.toHaveAttribute("style", /width/); + const novaBox = await novaPill.boundingBox(); + const astraBox = await astraPill.boundingBox(); + const feedBox = await feed.boundingBox(); + if (!novaBox || !astraBox || !feedBox) { + throw new Error("Both pills and the card must be visible."); + } + + await seedPillActivityMessage(page, { + agentPubkey: PILL_AGENT_ASTRA, + atMs: baseMs + 4_000, + seq: baseMs + 10_004, + text: "Astra: expanding into a much longer running action label", + turnId: "pill-turn-astra", + }); + await expect(astraPill).toContainText("much longer running action"); + // Astra's pill grew with the label swap (no pin right of the anchor)... + await expect + .poll(async () => (await astraPill.boundingBox())?.width ?? 0) + .toBeGreaterThan(astraBox.width + 4); + // ...while the anchor pill and its open card never moved. The card gets a + // 2px tolerance: Radix's popper re-measures on content changes and lands + // with sub-pixel rounding jitter that toBeCloseTo(…, 0) would flag. + const novaAfter = await novaPill.boundingBox(); + const feedAfter = await feed.boundingBox(); + expect(novaAfter?.x).toBeCloseTo(novaBox.x, 0); + expect(novaAfter?.width).toBeCloseTo(novaBox.width, 0); + expect(Math.abs((feedAfter?.x ?? Number.NaN) - feedBox.x)).toBeLessThan(2); + expect(Math.abs((feedAfter?.y ?? Number.NaN) - feedBox.y)).toBeLessThan(2); + + // Inverse: a card on the SECOND pill pins the pill left of the anchor — + // nova resizing would shift astra's left edge and drag the card with it. + await page.getByTestId("chat-title").hover(); + await expect(feed).toBeHidden(); + await astraPill.hover(); + await expect(feed).toBeVisible(); + await expect(novaPill).toHaveAttribute("style", /width/); + await expect(astraPill).toHaveAttribute("style", /width/); + const novaPinned = await novaPill.boundingBox(); + if (!novaPinned) { + throw new Error("Nova's pill must be visible."); + } + await seedPillActivityMessage(page, { + agentPubkey: PILL_AGENT_NOVA, + atMs: baseMs + 5_000, + seq: baseMs + 10_005, + text: "Nova: ok", + turnId: "pill-turn-nova", + }); + await expect(novaPill).toContainText("Nova: ok"); + // The shorter label swapped in but truncates inside the FROZEN width — + // the pill can't shrink and shift the card's anchor. + const novaHeld = await novaPill.boundingBox(); + expect(novaHeld?.x).toBeCloseTo(novaPinned.x, 0); + expect(novaHeld?.width).toBeCloseTo(novaPinned.width, 0); + await expect(feed).toBeVisible(); +}); + test("hovering across pills switches a single live-activity card", async ({ page, }) => {