## Problem Reported: planning gets stuck in a cycle of retrying and regenerating after a response was already supplied. After the user answers a planning question, `submitResponse` pushed the answer to history but left `session.currentQuestion` pointing at the just-answered question for the whole next generation. The planning SSE route's catch-up path re-emits `currentQuestion` to every fresh connection — and each FN-7946 auto-retry (#2073) opens a fresh connection. So after any generation error: 1. Auto-retry connects a fresh stream → the server re-emits the **already-answered** question. 2. The client treats any question event as progress: it **resets the 3-attempt auto-retry budget** and re-shows the answered question. 3. The retry regenerates; if it errors again the cycle repeats with a fresh budget — an unbounded retry/regenerate loop. Re-answering the stale question also 409-collided with the in-flight generation, feeding the same loop. ## Fix Invariant: `currentQuestion` is only set while the session is genuinely awaiting user input. - `submitResponse` clears it the moment an answer is accepted (normal turns and the deepening checkpoint), while preserving the legacy 200 respond contract on generation failure (the modal ignores the body and lets the SSE error drive recovery). - `retrySession` scrubs stale questions persisted by pre-fix builds before regenerating. - `buildSessionFromRow` only restores a question when the persisted row is `awaiting_input`. - `didSubmitSameAnswer` now compares against the last history entry so the duplicate-submit 409 message survives. - Agent onboarding gets the same fix (its SSE route also re-emits `currentQuestion` on connect); retry now asks the next question instead of re-asking the answered one. Surface enumeration: mission and milestone interviews keep questions the same way but their SSE routes never re-emit on connect, and the auto-retry budget machinery is Planning-Mode-only — planning + onboarding were the two affected surfaces. ## Symptom Verification - **Original symptom:** after answering a question, Planning Mode loops between "Retrying…" and regenerating, re-showing the already-answered question, with the auto-retry budget never exhausting. - **Exact reproduction:** answer a question, have the next generation fail (stuck watchdog/provider error), let the client auto-retry open a fresh SSE connection. - **Assertion it is gone:** new regression suite `planning-answered-question-reemit.test.ts` asserts `currentQuestion` is cleared mid-generation, on generation failure, on retry, and on restore from non-`awaiting_input` rows — so the SSE catch-up path has nothing stale to re-emit. All 5 tests fail against pre-fix code and pass with the fix; an onboarding regression test covers the sibling surface. ## Verification - New regression tests: 5/5 fail on pre-fix code, pass with the fix (plus 1 onboarding test). - Existing suites: 137 planning server tests pass (3 failures in `routes-planning.test.ts` fail identically without this change — pre-existing on the branch); all 69 `PlanningModeModal.planning-flow` client tests pass; `tsc --noEmit` clean; `pnpm check:changesets` passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Made Planning Mode (and related planning controls) lock-free and multi-tab—no more take-over/active-in-another-tab lock overlays. * **Bug Fixes** * Fixed Planning Mode retry/generation flows where already-answered questions could reappear. * Ensured answered questions clear immediately and aren’t re-emitted during session recovery/SSE catch-up. * Improved session restoration and preserved legacy recovery behavior when generation fails after an answer. * **Tests** * Added regression coverage for the answered-question invariant and updated existing tests to reflect lock-free behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- ## Follow-up: Planning Mode is now multi-tab via DB state (lock-free) Second commit removes all cross-tab coordination from planning — the persisted session row is the single source of truth and multiple tabs can read and interact with the same session: - **Server:** `/planning/*` routes no longer run `checkSessionLock` or parse `tabId`; a stale `tabId` from an older client is ignored instead of 409'd. Subtask/mission interview routes keep their existing lock behavior. - **Client:** `PlanningModeModal` drops `useSessionLock`, the `useAiSessionSync` BroadcastChannel broadcasts, `sessionTabId`/`lockSessionId` state, and the "Take Control" overlay. Tabs stay current via the per-session SSE stream plus the global `ai_session:updated` events `useBackgroundSessions` already consumes; concurrent writes resolve via the server's generation-in-progress guard (409). - **API client:** planning functions lose their `tabId` params. - **Fix uncovered by the refactor:** the 8s stuck-poll now resolves the session id inside each tick — the removed lock state was what previously re-armed the poll after Start Planning resolved the session id. - Also fixes a pre-existing PG-cutover break in `planning-generation-cancellation.test.ts` (`getSession` is async). Verification: 144 client planning tests and 137 server planning tests pass (the 3 remaining `routes-planning.test.ts` failures are pre-existing on the branch and fail identically without these changes); `tsc --noEmit` and eslint clean on changed files; `pnpm check:changesets` passes. Lock-conflict route tests were rewritten to assert lock-free semantics, plus a new modal test proving a session stays fully interactive with no lock acquisition even when another tab is active. --- ## Follow-up 2: the per-tab session lock is gone entirely Third commit extends the multi-tab model from planning to **every** AI interview surface (planning, subtask breakdown, mission interview, milestone/slice interview) and deletes the lock machinery root and branch. **Server** - Deleted the `/ai-sessions/:id/lock`, `/lock/force`, and `/lock/beacon` routes. - Dropped `checkSessionLock` from every planning/subtask/mission/milestone route (both copies — `routes.ts` and `mission-routes.ts`). A `tabId` from an older client is ignored, never 409'd; all `tabId` body parsing is gone. - Dropped `acquireLock` / `releaseLock` / `forceAcquireLock` / `getLockHolder` / `releaseStaleLocks` from `AiSessionStore`, plus the `@fusion/core` async helpers (`acquireAiSessionLock` et al) and core's re-exports. - Removed `lockedByTab`/`lockedAt` from `AiSessionRow`/`AiSessionSummary`, the upsert SQL, and all four session producers. **Client** - Deleted `useSessionLock` and the now-orphaned `getSessionTabId` util. - Removed the Take Control overlay, the "active in another tab" banners, and `BackgroundTasksIndicator`'s active-elsewhere gate (the confirm prompt and lock badge — sessions now just open). - Reduced `useAiSessionSync` to what its own comments already called it — a low-latency *status* supplement to SSE: no `activeTabMap`, `broadcastLock/Unlock/Heartbeat`, `owningTabId`, `tab:*` messages, or stale-heartbeat sweep. - Dropped `tabId` from every session API client function; removed the lock CSS. **Deliberately kept: the two DB columns.** `ai_sessions.locked_by_tab` / `locked_at` remain as dead, always-NULL columns with a deprecation note. Dropping them is an irreversible migration, and released binaries still name those columns explicitly in their upsert — an older install pointed at the same database would fail every session write. They can be dropped once no such binary can reach it. No code reads or writes them. **Verification**: 397 client tests and 137 server planning tests pass (the same 3 `routes-planning.test.ts` failures are pre-existing — verified identical on a clean stash); `tsc --noEmit` clean for `@fusion/core` and `@fusion/dashboard`; eslint clean on all changed files; the 30 PG `schema-applier` tests pass (they exercise the retained columns); `pnpm check:changesets` passes. The lock-conflict route tests and both modal lock tests were rewritten to assert the inverse: routes and modals stay fully interactive while another tab "holds" a lock, and the lock API is never called. --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
578 lines
21 KiB
TypeScript
578 lines
21 KiB
TypeScript
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import type { AiSessionSummary } from "../../api";
|
|
import { SessionNotificationBanner, dismissedIds } from "../SessionNotificationBanner";
|
|
import { isPlanningAwaitingInput, isSessionNeedingInputForBanner } from "../../utils/appLifecycle";
|
|
|
|
function buildSession(overrides: Partial<AiSessionSummary>): AiSessionSummary {
|
|
return {
|
|
id: overrides.id ?? "session-1",
|
|
type: overrides.type ?? "planning",
|
|
status: overrides.status ?? "awaiting_input",
|
|
title: overrides.title ?? "Draft implementation plan",
|
|
projectId: overrides.projectId ?? "proj-1",
|
|
updatedAt: overrides.updatedAt ?? new Date().toISOString(),
|
|
};
|
|
}
|
|
|
|
describe("SessionNotificationBanner", () => {
|
|
beforeEach(() => {
|
|
dismissedIds.clear();
|
|
});
|
|
|
|
it("renders nothing when no sessions need input", () => {
|
|
const { container } = render(
|
|
<SessionNotificationBanner
|
|
sessions={[
|
|
buildSession({ id: "a", status: "generating" }),
|
|
buildSession({ id: "b", status: "complete" }),
|
|
]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(container.firstChild).toBeNull();
|
|
});
|
|
|
|
it("renders banner with correct awaiting_input count", () => {
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[
|
|
buildSession({ id: "a", title: "First", status: "awaiting_input" }),
|
|
buildSession({ id: "b", title: "Second", status: "awaiting_input" }),
|
|
buildSession({ id: "c", title: "Done", status: "complete" }),
|
|
]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByText("2 AI sessions need your input")).toBeInTheDocument();
|
|
expect(screen.getByText("First")).toBeInTheDocument();
|
|
expect(screen.getByText("Second")).toBeInTheDocument();
|
|
expect(screen.queryByText("Done")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("does not render sessions that are generating or complete", () => {
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[
|
|
buildSession({ id: "planning", type: "planning", title: "Planning Session", status: "awaiting_input" }),
|
|
buildSession({ id: "gen", title: "Generating", status: "generating" }),
|
|
buildSession({ id: "complete", title: "Complete", status: "complete" }),
|
|
]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByText("Planning Session")).toBeInTheDocument();
|
|
expect(screen.queryByText("Generating")).not.toBeInTheDocument();
|
|
expect(screen.queryByText("Complete")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("calls onResumeSession with the selected session", () => {
|
|
const onResumeSession = vi.fn();
|
|
const planningSession = buildSession({
|
|
id: "planning-1",
|
|
type: "planning",
|
|
status: "awaiting_input",
|
|
title: "Plan checkout flow",
|
|
});
|
|
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[planningSession]}
|
|
onResumeSession={onResumeSession}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Resume" }));
|
|
expect(onResumeSession).toHaveBeenCalledWith(planningSession);
|
|
});
|
|
|
|
it("calls onDismissSession with the session id", () => {
|
|
const onDismissSession = vi.fn();
|
|
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[buildSession({ id: "dismiss-1", title: "Dismiss me" })]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={onDismissSession}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Dismiss Dismiss me" }));
|
|
expect(onDismissSession).toHaveBeenCalledWith("dismiss-1");
|
|
});
|
|
|
|
it("calls onDismissAll when clicking dismiss all", () => {
|
|
const onDismissAll = vi.fn();
|
|
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[
|
|
buildSession({ id: "a", title: "A" }),
|
|
buildSession({ id: "b", title: "B" }),
|
|
]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={onDismissAll}
|
|
/>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /dismiss all/i }));
|
|
expect(onDismissAll).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("shows type labels and icons for planning, subtask, and mission interview", () => {
|
|
const { container } = render(
|
|
<SessionNotificationBanner
|
|
sessions={[
|
|
buildSession({ id: "planning", type: "planning", title: "Plan" }),
|
|
buildSession({ id: "subtask", type: "subtask", title: "Breakdown" }),
|
|
buildSession({ id: "mission", type: "mission_interview", title: "Mission" }),
|
|
]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByText("Planning")).toBeInTheDocument();
|
|
expect(screen.getByText("Subtask Breakdown")).toBeInTheDocument();
|
|
expect(screen.getByText("Mission Interview")).toBeInTheDocument();
|
|
|
|
expect(container.querySelector(".lucide-lightbulb")).toBeTruthy();
|
|
expect(container.querySelector(".lucide-layers")).toBeTruthy();
|
|
expect(container.querySelector(".lucide-target")).toBeTruthy();
|
|
});
|
|
|
|
it("removes dismissed sessions from the banner", () => {
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[
|
|
buildSession({ id: "first", title: "First Session" }),
|
|
buildSession({ id: "second", title: "Second Session" }),
|
|
]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Dismiss First Session" }));
|
|
|
|
expect(screen.queryByText("First Session")).not.toBeInTheDocument();
|
|
expect(screen.getByText("Second Session")).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders error sessions in the banner", () => {
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[
|
|
buildSession({ id: "error-session", type: "mission_interview", title: "Failed Mission", status: "error" }),
|
|
]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByText("Failed Mission")).toBeInTheDocument();
|
|
expect(screen.getByText("Failed")).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows 'Retry' button for error sessions instead of 'Resume'", () => {
|
|
const errorSession = buildSession({
|
|
id: "error-1",
|
|
type: "mission_interview",
|
|
status: "error",
|
|
title: "Error Session",
|
|
});
|
|
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[errorSession]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByRole("button", { name: "Retry" })).toBeInTheDocument();
|
|
expect(screen.queryByRole("button", { name: "Resume" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("calls onResumeSession when clicking Retry on error session", () => {
|
|
const onResumeSession = vi.fn();
|
|
const errorSession = buildSession({
|
|
id: "error-retry",
|
|
type: "mission_interview",
|
|
status: "error",
|
|
title: "Error to Retry",
|
|
});
|
|
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[errorSession]}
|
|
onResumeSession={onResumeSession}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Retry" }));
|
|
expect(onResumeSession).toHaveBeenCalledWith(errorSession);
|
|
});
|
|
|
|
it("shows combined header text for both awaiting_input and error sessions", () => {
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[
|
|
buildSession({ id: "awaiting", status: "awaiting_input", title: "Awaiting Input" }),
|
|
buildSession({ id: "error", status: "error", title: "Error Session" }),
|
|
]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByText("1 AI session needs your input, 1 failed")).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows error count only when no awaiting_input sessions", () => {
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[
|
|
buildSession({ id: "error1", status: "error", title: "Error 1" }),
|
|
buildSession({ id: "error2", status: "error", title: "Error 2" }),
|
|
]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByText("2 AI sessions failed")).toBeInTheDocument();
|
|
});
|
|
|
|
it("dismisses error sessions from the banner", () => {
|
|
const onDismissSession = vi.fn();
|
|
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[
|
|
buildSession({ id: "error-dismiss", status: "error", title: "Error to Dismiss" }),
|
|
]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={onDismissSession}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Dismiss Error to Dismiss" }));
|
|
expect(onDismissSession).toHaveBeenCalledWith("error-dismiss");
|
|
});
|
|
|
|
/*
|
|
FNXC:SessionBanner 2026-07-05-00:00:
|
|
Symptom Verification (FN-7614): the production banner feed (App.tsx `sessionsNeedingInput`) filters via
|
|
`isSessionNeedingInputForBanner(s) && !isPlanningAwaitingInput(s)` before it ever reaches this component. Given a
|
|
lone planning awaiting_input session, that filter yields an empty array, so the banner must render NO entry
|
|
(and no banner region at all) — reproducing the original broken-Resume-button symptom being fixed by the nav badge.
|
|
*/
|
|
it("renders no banner entry (and no banner region) for a lone planning awaiting_input session, using the production banner filter", () => {
|
|
const planningAwaitingInput = buildSession({ id: "planning-solo", type: "planning", status: "awaiting_input", title: "Solo planning session" });
|
|
const filtered = [planningAwaitingInput].filter((s) => isSessionNeedingInputForBanner(s) && !isPlanningAwaitingInput(s));
|
|
|
|
const { container } = render(
|
|
<SessionNotificationBanner
|
|
sessions={filtered}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(filtered).toEqual([]);
|
|
expect(screen.queryByText("Solo planning session")).not.toBeInTheDocument();
|
|
expect(container.firstChild).toBeNull();
|
|
});
|
|
|
|
it("keeps a mixed non-planning awaiting-input session visible while excluding planning-awaiting-input via the production filter", () => {
|
|
const planningAwaitingInput = buildSession({ id: "planning-solo2", type: "planning", status: "awaiting_input", title: "Excluded planning session" });
|
|
const cliAwaitingInput = buildSession({ id: "cli-mixed", type: "cli-agent", status: "waiting_on_input", title: "Visible CLI session" });
|
|
const filtered = [planningAwaitingInput, cliAwaitingInput].filter((s) => isSessionNeedingInputForBanner(s) && !isPlanningAwaitingInput(s));
|
|
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={filtered}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.queryByText("Excluded planning session")).not.toBeInTheDocument();
|
|
expect(screen.getByText("Visible CLI session")).toBeInTheDocument();
|
|
});
|
|
|
|
it("preserves dismissed error sessions when session status changes", () => {
|
|
const { rerender } = render(
|
|
<SessionNotificationBanner
|
|
sessions={[
|
|
buildSession({ id: "session-1", status: "error", title: "Error Session" }),
|
|
]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
// Dismiss the error session
|
|
fireEvent.click(screen.getByRole("button", { name: "Dismiss Error Session" }));
|
|
expect(screen.queryByText("Error Session")).not.toBeInTheDocument();
|
|
|
|
// Simulate session status changing to complete (should NOT reappear)
|
|
rerender(
|
|
<SessionNotificationBanner
|
|
sessions={[
|
|
buildSession({ id: "session-1", status: "complete", title: "Error Session" }),
|
|
]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
// Dismissed session should still be hidden even though status changed
|
|
expect(screen.queryByText("Error Session")).not.toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
// ── CLI agent extensions (CLI Agent Executor, U11) ──────────────────────────
|
|
function buildCliSession(overrides: Partial<AiSessionSummary>): AiSessionSummary {
|
|
return {
|
|
id: overrides.id ?? "cli-1",
|
|
type: "cli-agent",
|
|
status: overrides.status ?? "waiting_on_input",
|
|
title: overrides.title ?? "Implement FN-1",
|
|
projectId: overrides.projectId ?? "proj-1",
|
|
updatedAt: overrides.updatedAt ?? new Date().toISOString(),
|
|
cliVariant: overrides.cliVariant,
|
|
cliSessionId: Object.prototype.hasOwnProperty.call(overrides, "cliSessionId") ? overrides.cliSessionId : "cli-1",
|
|
};
|
|
}
|
|
|
|
describe("SessionNotificationBanner — cli-agent (U11)", () => {
|
|
beforeEach(() => dismissedIds.clear());
|
|
|
|
it("renders the cli-agent type without crashing (union regression)", () => {
|
|
expect(() =>
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[buildCliSession({ status: "waiting_on_input" })]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
),
|
|
).not.toThrow();
|
|
expect(screen.getByText("Implement FN-1")).toBeInTheDocument();
|
|
});
|
|
|
|
it("waiting_on_input surfaces a banner entry; busy clears it (F2)", () => {
|
|
const { rerender, container } = render(
|
|
<SessionNotificationBanner
|
|
sessions={[buildCliSession({ status: "waiting_on_input" })]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
expect(container.querySelector(".session-notification-banner")).toBeTruthy();
|
|
|
|
rerender(
|
|
<SessionNotificationBanner
|
|
sessions={[buildCliSession({ status: "generating" as AiSessionSummary["status"] })]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
expect(container.querySelector(".session-notification-banner")).toBeFalsy();
|
|
});
|
|
|
|
it("userExited needs-attention renders pinned copy + Advance/Retry/Cancel task", () => {
|
|
const onCliAction = vi.fn();
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[buildCliSession({ status: "needs_attention", cliVariant: "userExited" })]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
onCliAction={onCliAction}
|
|
/>,
|
|
);
|
|
expect(screen.getByText("Agent exited before completing")).toBeInTheDocument();
|
|
// All three pinned actions render before any action removes the item.
|
|
expect(screen.getByText("Advance")).toBeInTheDocument();
|
|
expect(screen.getByText("Retry")).toBeInTheDocument();
|
|
expect(screen.getByText("Cancel task")).toBeInTheDocument();
|
|
fireEvent.click(screen.getByText("Advance"));
|
|
expect(onCliAction).toHaveBeenCalledWith(expect.objectContaining({ id: "cli-1" }), "advance");
|
|
});
|
|
|
|
it("authFailed renders Re-authenticate / Retry", () => {
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[buildCliSession({ status: "needs_attention", cliVariant: "authFailed" })]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
onCliAction={vi.fn()}
|
|
/>,
|
|
);
|
|
expect(screen.getByText("CLI authentication failed")).toBeInTheDocument();
|
|
expect(screen.getByText("Re-authenticate")).toBeInTheDocument();
|
|
expect(screen.getByText("Retry")).toBeInTheDocument();
|
|
});
|
|
|
|
it.each(["desktop", "mobile"] as const)(
|
|
"resume-exhausted renders an enabled Relaunch fresh action at the %s breakpoint",
|
|
(breakpoint) => {
|
|
const onCliAction = vi.fn();
|
|
Object.defineProperty(window, "innerWidth", {
|
|
configurable: true,
|
|
value: breakpoint === "mobile" ? 390 : 1280,
|
|
});
|
|
window.dispatchEvent(new Event("resize"));
|
|
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[buildCliSession({ status: "needs_attention", cliVariant: "resume-exhausted" })]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
onCliAction={onCliAction}
|
|
/>,
|
|
);
|
|
expect(screen.getByText("Couldn't resume the session")).toBeInTheDocument();
|
|
const relaunchButton = screen.getByRole("button", { name: "Relaunch fresh" });
|
|
expect(relaunchButton).not.toBeDisabled();
|
|
expect(relaunchButton).not.toHaveAttribute("aria-disabled");
|
|
expect(relaunchButton).not.toHaveAttribute("data-cli-action-disabled");
|
|
fireEvent.click(relaunchButton);
|
|
expect(onCliAction).toHaveBeenCalledWith(expect.objectContaining({ id: "cli-1" }), "relaunch");
|
|
expect(screen.getByText("Cancel task")).toBeInTheDocument();
|
|
},
|
|
);
|
|
|
|
it("renders relaunch disabled when the host reports a missing CLI session id", () => {
|
|
const onCliAction = vi.fn();
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[buildCliSession({ status: "needs_attention", cliVariant: "resume-exhausted", cliSessionId: undefined })]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
onCliAction={onCliAction}
|
|
getCliActionDisabledReason={(session, action) =>
|
|
action === "relaunch" && !session.cliSessionId ? "CLI session id is missing." : null
|
|
}
|
|
/>,
|
|
);
|
|
|
|
const relaunchButton = screen.getByRole("button", { name: /Relaunch fresh unavailable: CLI session id is missing/i });
|
|
expect(relaunchButton).toBeDisabled();
|
|
fireEvent.click(relaunchButton);
|
|
expect(onCliAction).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it.each([
|
|
["userExited", ["advance", "retry", "cancel"]],
|
|
["authFailed", ["reauthenticate", "retry"]],
|
|
["resume-exhausted", ["relaunch", "cancel"]],
|
|
] as const)("makes every %s action observable or disabled", (cliVariant, actions) => {
|
|
for (const action of actions) {
|
|
dismissedIds.clear();
|
|
const onCliAction = vi.fn();
|
|
const onDismissSession = vi.fn();
|
|
const { unmount } = render(
|
|
<SessionNotificationBanner
|
|
sessions={[buildCliSession({ status: "needs_attention", cliVariant })]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={onDismissSession}
|
|
onDismissAll={vi.fn()}
|
|
onCliAction={onCliAction}
|
|
getCliActionDisabledReason={() => null}
|
|
/>,
|
|
);
|
|
|
|
const button = document.querySelector<HTMLButtonElement>(`[data-cli-action="${action}"]`);
|
|
expect(button).toBeTruthy();
|
|
if (button?.disabled) {
|
|
expect(button).toHaveAccessibleName(/unavailable:/i);
|
|
expect(onCliAction).not.toHaveBeenCalled();
|
|
} else {
|
|
fireEvent.click(button!);
|
|
expect(onCliAction).toHaveBeenCalledWith(expect.objectContaining({ id: "cli-1" }), action);
|
|
if (action === "advance" || action === "cancel") {
|
|
expect(onDismissSession).toHaveBeenCalledWith("cli-1");
|
|
} else {
|
|
expect(onDismissSession).not.toHaveBeenCalled();
|
|
}
|
|
}
|
|
unmount();
|
|
}
|
|
});
|
|
|
|
it("disables CLI actions when the host provides no action handler", () => {
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[buildCliSession({ status: "needs_attention", cliVariant: "authFailed" })]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
for (const button of screen.getAllByRole("button").filter((node) => node.hasAttribute("data-cli-action"))) {
|
|
expect(button).toBeDisabled();
|
|
expect(button).toHaveAccessibleName(/unavailable:/i);
|
|
}
|
|
});
|
|
|
|
it("disables actions that require a missing cliSessionId without leaving an empty click target", () => {
|
|
const onCliAction = vi.fn();
|
|
render(
|
|
<SessionNotificationBanner
|
|
sessions={[buildCliSession({ status: "needs_attention", cliVariant: "userExited", cliSessionId: undefined })]}
|
|
onResumeSession={vi.fn()}
|
|
onDismissSession={vi.fn()}
|
|
onDismissAll={vi.fn()}
|
|
onCliAction={onCliAction}
|
|
getCliActionDisabledReason={(session, action) =>
|
|
action === "advance" && !session.cliSessionId ? "CLI session id is missing." : null
|
|
}
|
|
/>,
|
|
);
|
|
|
|
const advance = screen.getByRole("button", { name: /advance unavailable: cli session id is missing/i });
|
|
expect(advance).toBeDisabled();
|
|
expect(advance).toHaveAttribute("data-cli-action-disabled", "true");
|
|
expect(advance).toHaveTextContent("Advance");
|
|
fireEvent.click(advance);
|
|
expect(onCliAction).not.toHaveBeenCalled();
|
|
});
|
|
});
|