## Summary Restacks onto latest main after #2285 and clears the remaining Full Suite red classes from run [29633869887](https://github.com/Runfusion/Fusion/actions/runs/29633869887) (post-#2285): - **Shard 1:** `agent-skills-flow` vitest TDZ — hoist `mockFiles` via `vi.hoisted` (same class as skill-resolver in #2285) - **Shard 2/3:** incomplete mocks after product drift - `isFullScreenSheetViewport` / `isShortViewport` on viewport mocks (without overriding dynamic mobile helpers) - `fetchCodebaseMetrics` on Command Center `api/legacy` mocks - `fetchSettings` on `agent-modals-mobile` api mock - **Shard 3:** PlanningMode `ui-interactions` race — sync-settle `fetchGlobalSettings` (FN-8245 pattern from planning-flow) - **Shard 3:** settings search drift guard — inventory `SettingsFieldRow` `htmlFor` keys (`mobileNavPrimaryItems`) - **Shard 2:** FloatingWindow shared-stack product bug — only reclaim z-index on hidden→visible (not every mount effect), so last-mounted utility stays on top - **Shard 4:** grok process-lifecycle timeout under shard load — prove bound with 5 reimports instead of 15 ## Test plan - [x] `agent-skills-flow.test.ts` green - [x] `process-lifecycle.test.ts` green - [x] FileBrowserModal, FloatingWindowStack.cross-type, agent-modals-mobile, settings-search-index, SystemControlsArea, PlanningModeModal.ui-interactions + planning-flow (210 tests) green - [ ] PR merge gate (Lint/Typecheck/Build/Gate) - [ ] Post-merge Full Suite on `main` green <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved floating-window stacking so reopened or interacted windows appear in the correct order. * Restored consistent layering between floating windows and expanded dock modals. * **Tests** * Updated automated coverage for viewport behavior, codebase metrics, settings search indexing, and process lifecycle scenarios. * Improved test reliability and consistency across responsive layouts and modal interactions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
120 lines
4.1 KiB
TypeScript
120 lines
4.1 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import { NewTaskModal } from "../NewTaskModal";
|
|
import { useAgentsMapCache } from "../../hooks/useAgentsMapCache";
|
|
import { writeCache, SWR_CACHE_KEYS } from "../../utils/swrCache";
|
|
|
|
const mockFetchAgents = vi.fn();
|
|
|
|
vi.mock("../../api", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("../../api")>();
|
|
return {
|
|
...actual,
|
|
fetchAgents: (...args: unknown[]) => mockFetchAgents(...args),
|
|
uploadAttachment: vi.fn().mockResolvedValue({ attachment: null }),
|
|
};
|
|
});
|
|
|
|
vi.mock("../../hooks/useSetupReadiness", () => ({ useSetupReadiness: vi.fn(() => ({ hasAiProvider: true, hasGithub: true, loading: false })) }));
|
|
vi.mock("../../hooks/useConfirm", () => ({ useConfirm: vi.fn(() => ({ confirm: vi.fn().mockResolvedValue(true) })) }));
|
|
vi.mock("../../hooks/useMobileKeyboard", () => ({ useMobileKeyboard: vi.fn(() => ({ keyboardOverlap: 0, viewportHeight: null, viewportOffsetTop: 0, keyboardOpen: false })) }));
|
|
vi.mock("../../hooks/useMobileScrollLock", () => ({
|
|
useMobileScrollLock: vi.fn(),
|
|
useMobileKeyboardViewportLock: vi.fn(),
|
|
useMobileViewportRestoreReset: vi.fn(),
|
|
}));
|
|
vi.mock("../../hooks/useNodes", () => ({ useNodes: vi.fn(() => ({ nodes: [] })) }));
|
|
vi.mock("../../hooks/useViewportMode", () => {
|
|
const useViewportMode = vi.fn(() => "desktop");
|
|
return { isFullScreenSheetViewport: () => false,
|
|
isShortViewport: () => false,
|
|
|
|
MOBILE_MEDIA_QUERY: "(max-width: 768px), (max-height: 480px)",
|
|
getViewportMode: () => useViewportMode(),
|
|
isMobileViewport: () => useViewportMode() === "mobile",
|
|
useViewportMode,
|
|
};
|
|
});
|
|
|
|
function deferred<T>() {
|
|
let resolve!: (value: T) => void;
|
|
const promise = new Promise<T>((res) => {
|
|
resolve = res;
|
|
});
|
|
return { promise, resolve };
|
|
}
|
|
|
|
describe("NewTaskModal shared cache", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
localStorage.clear();
|
|
mockFetchAgents.mockResolvedValue([]);
|
|
});
|
|
|
|
const baseProps = {
|
|
isOpen: true,
|
|
projectId: "p1",
|
|
tasks: [],
|
|
onCreateTask: vi.fn(),
|
|
addToast: vi.fn(),
|
|
onClose: vi.fn(),
|
|
};
|
|
|
|
it("shows cached agents without cold fetch", () => {
|
|
writeCache(`${SWR_CACHE_KEYS.CHAT_AGENTS_MAP_PREFIX}p1`, [
|
|
{ id: "agent-1", name: "Agent One", role: "executor", state: "active" },
|
|
{ id: "agent-2", name: "Agent Two", role: "reviewer", state: "active" },
|
|
], { maxBytes: 500_000 });
|
|
|
|
render(<NewTaskModal {...baseProps} />);
|
|
fireEvent.click(screen.getByTestId("new-task-agent-button"));
|
|
|
|
expect(screen.getByText("Agent One")).toBeInTheDocument();
|
|
expect(screen.getByText("Agent Two")).toBeInTheDocument();
|
|
});
|
|
|
|
it("reuses warm cache across remounts", () => {
|
|
writeCache(`${SWR_CACHE_KEYS.CHAT_AGENTS_MAP_PREFIX}p1`, [
|
|
{ id: "agent-1", name: "Agent One", role: "executor", state: "active" },
|
|
], { maxBytes: 500_000 });
|
|
|
|
const first = render(<NewTaskModal {...baseProps} />);
|
|
first.unmount();
|
|
render(<NewTaskModal {...baseProps} />);
|
|
|
|
expect(mockFetchAgents.mock.calls.length).toBeLessThanOrEqual(1);
|
|
});
|
|
|
|
it("dedups agent fetch with another useAgentsMapCache consumer", () => {
|
|
const request = deferred<Array<{ id: string; name: string; role: string; state: string }>>();
|
|
mockFetchAgents.mockReturnValue(request.promise);
|
|
|
|
function AgentsConsumer() {
|
|
useAgentsMapCache("p1");
|
|
return null;
|
|
}
|
|
|
|
render(
|
|
<>
|
|
<NewTaskModal {...baseProps} />
|
|
<AgentsConsumer />
|
|
</>,
|
|
);
|
|
|
|
expect(mockFetchAgents).toHaveBeenCalledTimes(1);
|
|
request.resolve([]);
|
|
});
|
|
|
|
it("opens picker synchronously on cache hit", () => {
|
|
writeCache(`${SWR_CACHE_KEYS.CHAT_AGENTS_MAP_PREFIX}p1`, [
|
|
{ id: "agent-1", name: "Agent One", role: "executor", state: "active" },
|
|
], { maxBytes: 500_000 });
|
|
|
|
render(<NewTaskModal {...baseProps} />);
|
|
fireEvent.click(screen.getByTestId("new-task-agent-button"));
|
|
|
|
expect(screen.getByText("Select agent")).toBeInTheDocument();
|
|
expect(screen.queryByText("Loading agents...")).toBeNull();
|
|
});
|
|
});
|