Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-6291: stop paying for jsdom in pure-logic frontend suites (#7081)

Bohan Jiang2a643cc7407c
diff --git a/CLAUDE.md b/CLAUDE.md
index c1a4cfd4ea..ac9b47bace 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -208,6 +208,8 @@ Tests follow the code:
Rules:
- Never test shared component behavior in an app test file.
+- Give each product behavior ONE canonical layer. Pure parsing, state transitions and boundary matrices belong in a `.test.ts` beside the helper; the component suite keeps the happy path, the wiring, accessibility and named regressions, and points at the canonical file in a comment. Do not re-run a helper's matrix through a DOM mount.
+- A `.test.ts` that needs no DOM must start with `// @vitest-environment node`. jsdom costs ~0.8s of setup per file and buys such a suite nothing. Do not add it to a test whose code under test branches on `typeof window`/`document` — under node it would silently take the SSR path and still pass.
- `packages/views/` tests must not mock `next/*` or `react-router-dom`.
- Mock `@multica/core` stores with the Zustand callable-store shape (`selectorFn` plus `getState`).
- Mock `@multica/core/api` for API calls.
diff --git a/apps/desktop/src/main/auth-session-coordinator.test.ts b/apps/desktop/src/main/auth-session-coordinator.test.ts
index e1cd67f389..cf30b8e9b7 100644
--- a/apps/desktop/src/main/auth-session-coordinator.test.ts
+++ b/apps/desktop/src/main/auth-session-coordinator.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it, vi } from "vitest";
import {
AuthSessionCoordinator,
diff --git a/apps/desktop/src/main/cli-release-asset.test.ts b/apps/desktop/src/main/cli-release-asset.test.ts
index 253880731b..d151ba2941 100644
--- a/apps/desktop/src/main/cli-release-asset.test.ts
+++ b/apps/desktop/src/main/cli-release-asset.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { selectPlatformReleaseAssetName } from "./cli-release-asset";
diff --git a/apps/desktop/src/main/context-menu.test.ts b/apps/desktop/src/main/context-menu.test.ts
index 46011b0a99..8cc1e80160 100644
--- a/apps/desktop/src/main/context-menu.test.ts
+++ b/apps/desktop/src/main/context-menu.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it, vi, beforeEach } from "vitest";
// Capture every MenuItem the SUT constructs so each test can assert
diff --git a/apps/desktop/src/main/daemon-auth-probe.test.ts b/apps/desktop/src/main/daemon-auth-probe.test.ts
index f122de6a81..dfaf4f8de9 100644
--- a/apps/desktop/src/main/daemon-auth-probe.test.ts
+++ b/apps/desktop/src/main/daemon-auth-probe.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { classifyAuthProbe, isAuthStatusError } from "./daemon-auth-probe";
diff --git a/apps/desktop/src/main/daemon-os.test.ts b/apps/desktop/src/main/daemon-os.test.ts
index 87240d1f8e..12e37fc186 100644
--- a/apps/desktop/src/main/daemon-os.test.ts
+++ b/apps/desktop/src/main/daemon-os.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it, vi } from "vitest";
import {
diff --git a/apps/desktop/src/main/daemon-profile.test.ts b/apps/desktop/src/main/daemon-profile.test.ts
index ce61abedf1..15b1250b05 100644
--- a/apps/desktop/src/main/daemon-profile.test.ts
+++ b/apps/desktop/src/main/daemon-profile.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { homedir } from "os";
import { join } from "path";
import { describe, expect, it } from "vitest";
diff --git a/apps/desktop/src/main/dev-log.test.ts b/apps/desktop/src/main/dev-log.test.ts
index 2fdc6e4366..fab86f928f 100644
--- a/apps/desktop/src/main/dev-log.test.ts
+++ b/apps/desktop/src/main/dev-log.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { EventEmitter } from "node:events";
import { describe, expect, it, vi } from "vitest";
import { createBestEffortDevLog } from "./dev-log";
diff --git a/apps/desktop/src/main/external-url.test.ts b/apps/desktop/src/main/external-url.test.ts
index 41c9187be2..52aae506b6 100644
--- a/apps/desktop/src/main/external-url.test.ts
+++ b/apps/desktop/src/main/external-url.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it, vi, beforeEach } from "vitest";
vi.mock("electron", () => ({
diff --git a/apps/desktop/src/main/freeze-breadcrumb.test.ts b/apps/desktop/src/main/freeze-breadcrumb.test.ts
index 05ef0dcac6..6e730479dd 100644
--- a/apps/desktop/src/main/freeze-breadcrumb.test.ts
+++ b/apps/desktop/src/main/freeze-breadcrumb.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { afterEach, describe, expect, it } from "vitest";
import { mkdtempSync, rmSync, writeFileSync, existsSync } from "node:fs";
import { tmpdir } from "node:os";
diff --git a/apps/desktop/src/main/keyboard-shortcuts.test.ts b/apps/desktop/src/main/keyboard-shortcuts.test.ts
index 97fa0e5e2a..0e13643c6b 100644
--- a/apps/desktop/src/main/keyboard-shortcuts.test.ts
+++ b/apps/desktop/src/main/keyboard-shortcuts.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it, vi } from "vitest";
import { handleAppShortcut, type ShortcutInput } from "./keyboard-shortcuts";
diff --git a/apps/desktop/src/main/navigation-gestures.test.ts b/apps/desktop/src/main/navigation-gestures.test.ts
index cac9cc23be..3133f6dc39 100644
--- a/apps/desktop/src/main/navigation-gestures.test.ts
+++ b/apps/desktop/src/main/navigation-gestures.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import type { BrowserWindow } from "electron";
import { describe, expect, it, vi } from "vitest";
import { NAVIGATION_GESTURE_CHANNEL } from "../shared/navigation-gestures";
diff --git a/apps/desktop/src/main/navigation-guard.test.ts b/apps/desktop/src/main/navigation-guard.test.ts
index 8c12f6de12..98432db611 100644
--- a/apps/desktop/src/main/navigation-guard.test.ts
+++ b/apps/desktop/src/main/navigation-guard.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { beforeEach, describe, expect, it, vi } from "vitest";
import {
describeBlockedNavigation,
diff --git a/apps/desktop/src/main/notification-gate.test.ts b/apps/desktop/src/main/notification-gate.test.ts
index f36798234b..6d4b16fef6 100644
--- a/apps/desktop/src/main/notification-gate.test.ts
+++ b/apps/desktop/src/main/notification-gate.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import {
NotificationGate,
diff --git a/apps/desktop/src/main/renderer-recovery.test.ts b/apps/desktop/src/main/renderer-recovery.test.ts
index 22d75394e0..f6c02aca9b 100644
--- a/apps/desktop/src/main/renderer-recovery.test.ts
+++ b/apps/desktop/src/main/renderer-recovery.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
import { createElectronReloadPrompt, installRendererRecoveryHandlers } from "./renderer-recovery";
diff --git a/apps/desktop/src/main/runtime-config-loader.test.ts b/apps/desktop/src/main/runtime-config-loader.test.ts
index 350f3d58d7..2bd6840cc5 100644
--- a/apps/desktop/src/main/runtime-config-loader.test.ts
+++ b/apps/desktop/src/main/runtime-config-loader.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { mkdtemp, writeFile } from "fs/promises";
import { join } from "path";
import { tmpdir } from "os";
diff --git a/apps/desktop/src/main/updater-preferences.test.ts b/apps/desktop/src/main/updater-preferences.test.ts
index cc5106f2b3..9df50f279f 100644
--- a/apps/desktop/src/main/updater-preferences.test.ts
+++ b/apps/desktop/src/main/updater-preferences.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { afterEach, describe, expect, it } from "vitest";
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
diff --git a/apps/desktop/src/main/updater.test.ts b/apps/desktop/src/main/updater.test.ts
index a778bda248..6d6b29e2df 100644
--- a/apps/desktop/src/main/updater.test.ts
+++ b/apps/desktop/src/main/updater.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { BrowserWindow, WebContents } from "electron";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
diff --git a/apps/desktop/src/main/version-decision.test.ts b/apps/desktop/src/main/version-decision.test.ts
index cfc109ff37..b7b3f1a4bf 100644
--- a/apps/desktop/src/main/version-decision.test.ts
+++ b/apps/desktop/src/main/version-decision.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { decideVersionAction } from "./version-decision";
diff --git a/apps/desktop/src/main/window-state.test.ts b/apps/desktop/src/main/window-state.test.ts
index 9cbca9aa53..bcc65ba81c 100644
--- a/apps/desktop/src/main/window-state.test.ts
+++ b/apps/desktop/src/main/window-state.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { afterEach, describe, expect, it } from "vitest";
import { mkdtempSync, rmSync, writeFileSync, readFileSync, existsSync } from "node:fs";
import { tmpdir } from "node:os";
diff --git a/apps/desktop/src/renderer/src/components/parse-daemon-log.test.ts b/apps/desktop/src/renderer/src/components/parse-daemon-log.test.ts
index 84e057c5e0..154c9f81e3 100644
--- a/apps/desktop/src/renderer/src/components/parse-daemon-log.test.ts
+++ b/apps/desktop/src/renderer/src/components/parse-daemon-log.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { parseLogLine } from "./parse-daemon-log";
diff --git a/apps/desktop/src/renderer/src/font-fallback-order.test.ts b/apps/desktop/src/renderer/src/font-fallback-order.test.ts
index b48fc79186..96188792d2 100644
--- a/apps/desktop/src/renderer/src/font-fallback-order.test.ts
+++ b/apps/desktop/src/renderer/src/font-fallback-order.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";
diff --git a/apps/desktop/src/renderer/src/freeze-flush.test.ts b/apps/desktop/src/renderer/src/freeze-flush.test.ts
index 7d291b3772..1b61004da9 100644
--- a/apps/desktop/src/renderer/src/freeze-flush.test.ts
+++ b/apps/desktop/src/renderer/src/freeze-flush.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
/**
* Two regressions are pinned here, both found in review of MUL-5345.
*
diff --git a/apps/desktop/src/renderer/src/platform/daemon-login-sync.test.ts b/apps/desktop/src/renderer/src/platform/daemon-login-sync.test.ts
index 3de432a1eb..304bf5ac89 100644
--- a/apps/desktop/src/renderer/src/platform/daemon-login-sync.test.ts
+++ b/apps/desktop/src/renderer/src/platform/daemon-login-sync.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { beforeEach, describe, expect, it, vi } from "vitest";
import {
diff --git a/apps/desktop/src/shared/daemon-types.test.ts b/apps/desktop/src/shared/daemon-types.test.ts
index 76c3bbf801..54675678bf 100644
--- a/apps/desktop/src/shared/daemon-types.test.ts
+++ b/apps/desktop/src/shared/daemon-types.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { daemonStatusAlive } from "./daemon-types";
diff --git a/apps/desktop/src/shared/issue-window.test.ts b/apps/desktop/src/shared/issue-window.test.ts
index 9d3a472641..4e0af33533 100644
--- a/apps/desktop/src/shared/issue-window.test.ts
+++ b/apps/desktop/src/shared/issue-window.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import {
encodeIssueWindowArgument,
diff --git a/apps/desktop/src/shared/main-renderer-messages.test.ts b/apps/desktop/src/shared/main-renderer-messages.test.ts
index 010aa9b28b..b3a44a52c2 100644
--- a/apps/desktop/src/shared/main-renderer-messages.test.ts
+++ b/apps/desktop/src/shared/main-renderer-messages.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it, vi } from "vitest";
import {
MainRendererMessageQueue,
diff --git a/apps/desktop/src/shared/navigation-gestures.test.ts b/apps/desktop/src/shared/navigation-gestures.test.ts
index adfbe5d004..2ba059f35a 100644
--- a/apps/desktop/src/shared/navigation-gestures.test.ts
+++ b/apps/desktop/src/shared/navigation-gestures.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import {
isNavigationGesture,
diff --git a/apps/desktop/src/shared/renderer-route-context.test.ts b/apps/desktop/src/shared/renderer-route-context.test.ts
index 42c5d1c110..47ca4f653b 100644
--- a/apps/desktop/src/shared/renderer-route-context.test.ts
+++ b/apps/desktop/src/shared/renderer-route-context.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
/**
* This context is attached to freeze/crash reports, which leave the machine.
* The sanitizer is the last checkpoint before a renderer-supplied payload is
diff --git a/apps/desktop/src/shared/runtime-config.test.ts b/apps/desktop/src/shared/runtime-config.test.ts
index 411f815d09..08d5b72a3a 100644
--- a/apps/desktop/src/shared/runtime-config.test.ts
+++ b/apps/desktop/src/shared/runtime-config.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import {
DEFAULT_RUNTIME_CONFIG,
diff --git a/apps/desktop/test/setup.ts b/apps/desktop/test/setup.ts
index 03d550a130..7231809125 100644
--- a/apps/desktop/test/setup.ts
+++ b/apps/desktop/test/setup.ts
@@ -19,37 +19,42 @@ function createMemoryStorage(): Storage {
};
}
-const localStorageIsUsable =
- typeof globalThis.localStorage?.getItem === "function" &&
- typeof globalThis.localStorage?.setItem === "function" &&
- typeof globalThis.localStorage?.removeItem === "function" &&
- typeof globalThis.localStorage?.clear === "function";
+// Everything below patches gaps in jsdom. Pure-logic suites opt out of jsdom
+// with `// @vitest-environment node` and share this file, so there is no DOM to
+// patch there — bail out rather than guard each stub.
+if (typeof window !== "undefined") {
+ const localStorageIsUsable =
+ typeof globalThis.localStorage?.getItem === "function" &&
+ typeof globalThis.localStorage?.setItem === "function" &&
+ typeof globalThis.localStorage?.removeItem === "function" &&
+ typeof globalThis.localStorage?.clear === "function";
-if (!localStorageIsUsable) {
- const storage = createMemoryStorage();
- Object.defineProperty(globalThis, "localStorage", {
- configurable: true,
- value: storage,
- });
- Object.defineProperty(window, "localStorage", {
- configurable: true,
- value: storage,
- });
-}
+ if (!localStorageIsUsable) {
+ const storage = createMemoryStorage();
+ Object.defineProperty(globalThis, "localStorage", {
+ configurable: true,
+ value: storage,
+ });
+ Object.defineProperty(window, "localStorage", {
+ configurable: true,
+ value: storage,
+ });
+ }
-// jsdom doesn't provide matchMedia; the sidebar's compact breakpoint and
-// auto-collapse band both read it. Nothing matches, so a shell mounted here
-// renders at its full desktop width. Mirrors packages/views/test/setup.ts.
-if (typeof window.matchMedia !== "function") {
- window.matchMedia = (query: string) =>
- ({
- matches: false,
- media: query,
- onchange: null,
- addListener: () => {},
- removeListener: () => {},
- addEventListener: () => {},
- removeEventListener: () => {},
- dispatchEvent: () => false,
- }) as MediaQueryList;
+ // jsdom doesn't provide matchMedia; the sidebar's compact breakpoint and
+ // auto-collapse band both read it. Nothing matches, so a shell mounted here
+ // renders at its full desktop width. Mirrors packages/views/test/setup.ts.
+ if (typeof window.matchMedia !== "function") {
+ window.matchMedia = (query: string) =>
+ ({
+ matches: false,
+ media: query,
+ onchange: null,
+ addListener: () => {},
+ removeListener: () => {},
+ addEventListener: () => {},
+ removeEventListener: () => {},
+ dispatchEvent: () => false,
+ }) as MediaQueryList;
+ }
}
diff --git a/apps/web/app/brand-variant-cascade.test.ts b/apps/web/app/brand-variant-cascade.test.ts
index 5f588215f1..dd7a133e18 100644
--- a/apps/web/app/brand-variant-cascade.test.ts
+++ b/apps/web/app/brand-variant-cascade.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { readFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import postcss from "postcss";
diff --git a/apps/web/app/font-fallback-order.test.ts b/apps/web/app/font-fallback-order.test.ts
index b12a546830..c8f961fb0d 100644
--- a/apps/web/app/font-fallback-order.test.ts
+++ b/apps/web/app/font-fallback-order.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";
diff --git a/apps/web/app/text-contrast.test.ts b/apps/web/app/text-contrast.test.ts
index f2f4ca5818..1f114a6fdf 100644
--- a/apps/web/app/text-contrast.test.ts
+++ b/apps/web/app/text-contrast.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { readFileSync, readdirSync, statSync } from "node:fs";
import { resolve, join, relative } from "node:path";
import { describe, expect, it } from "vitest";
diff --git a/apps/web/app/type-scale.test.ts b/apps/web/app/type-scale.test.ts
index 7382a94d1b..47817d0a4a 100644
--- a/apps/web/app/type-scale.test.ts
+++ b/apps/web/app/type-scale.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { readFileSync, readdirSync, statSync } from "node:fs";
import { resolve, join, relative } from "node:path";
import { describe, expect, it } from "vitest";
diff --git a/apps/web/config/runtime-urls.test.ts b/apps/web/config/runtime-urls.test.ts
index b69036cb14..b3f01b10c1 100644
--- a/apps/web/config/runtime-urls.test.ts
+++ b/apps/web/config/runtime-urls.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import {
diff --git a/apps/web/features/landing/utils/github-release.test.ts b/apps/web/features/landing/utils/github-release.test.ts
index aad44aa1c7..92fe1dbf25 100644
--- a/apps/web/features/landing/utils/github-release.test.ts
+++ b/apps/web/features/landing/utils/github-release.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { fetchLatestRelease } from "./github-release";
diff --git a/apps/web/features/landing/utils/parse-release-assets.test.ts b/apps/web/features/landing/utils/parse-release-assets.test.ts
index ce867354e2..ad17745d00 100644
--- a/apps/web/features/landing/utils/parse-release-assets.test.ts
+++ b/apps/web/features/landing/utils/parse-release-assets.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { parseReleaseAssets } from "./parse-release-assets";
diff --git a/apps/web/features/landing/utils/use-github-stars.test.ts b/apps/web/features/landing/utils/use-github-stars.test.ts
index 8ceba6e32c..3823b87890 100644
--- a/apps/web/features/landing/utils/use-github-stars.test.ts
+++ b/apps/web/features/landing/utils/use-github-stars.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { formatStarCount } from "./use-github-stars";
diff --git a/apps/web/lib/docs-href.test.ts b/apps/web/lib/docs-href.test.ts
index 4dda146c12..7eacacf4db 100644
--- a/apps/web/lib/docs-href.test.ts
+++ b/apps/web/lib/docs-href.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { docsHrefForLocale } from "./docs-href";
diff --git a/apps/web/lib/public-host.test.ts b/apps/web/lib/public-host.test.ts
index 2a2f42e830..0e838569e0 100644
--- a/apps/web/lib/public-host.test.ts
+++ b/apps/web/lib/public-host.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { isOfficialMarketingHost } from "./public-host";
diff --git a/apps/web/lib/use-case-locale-fallback.test.ts b/apps/web/lib/use-case-locale-fallback.test.ts
index e6e8e85790..118f8b47c8 100644
--- a/apps/web/lib/use-case-locale-fallback.test.ts
+++ b/apps/web/lib/use-case-locale-fallback.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { beforeEach, describe, expect, it, vi } from "vitest";
const mockUseCasesSource = vi.hoisted(() => ({
diff --git a/apps/web/platform/client-os.test.ts b/apps/web/platform/client-os.test.ts
index b61f6ffef1..1ffff9fbb8 100644
--- a/apps/web/platform/client-os.test.ts
+++ b/apps/web/platform/client-os.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { detectWebOS } from "./client-os";
diff --git a/apps/web/test/setup.ts b/apps/web/test/setup.ts
index 9881d55857..27b58c14cf 100644
--- a/apps/web/test/setup.ts
+++ b/apps/web/test/setup.ts
@@ -1,48 +1,53 @@
import "@testing-library/jest-dom/vitest";
import { vi } from "vitest";
-// jsdom doesn't provide ResizeObserver; stub it so components that rely on it
-// (e.g. input-otp) can render in tests.
-if (typeof globalThis.ResizeObserver === "undefined") {
- globalThis.ResizeObserver = class ResizeObserver {
- observe() {}
- unobserve() {}
- disconnect() {}
- } as unknown as typeof ResizeObserver;
-}
+// Everything below patches gaps in jsdom. Pure-logic suites opt out of jsdom
+// with `// @vitest-environment node` and share this file, so there is no DOM to
+// patch there — bail out rather than guard each stub.
+if (typeof window !== "undefined") {
+ // jsdom doesn't provide ResizeObserver; stub it so components that rely on it
+ // (e.g. input-otp) can render in tests.
+ if (typeof globalThis.ResizeObserver === "undefined") {
+ globalThis.ResizeObserver = class ResizeObserver {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ } as unknown as typeof ResizeObserver;
+ }
-// jsdom doesn't implement elementFromPoint; input-otp uses it internally.
-if (typeof document.elementFromPoint !== "function") {
- document.elementFromPoint = () => null;
-}
+ // jsdom doesn't implement elementFromPoint; input-otp uses it internally.
+ if (typeof document.elementFromPoint !== "function") {
+ document.elementFromPoint = () => null;
+ }
-// jsdom 29 / Node.js 22+ may not provide a proper Web Storage API.
-// Create a proper localStorage mock if methods are missing.
-if (
- typeof globalThis.localStorage === "undefined" ||
- typeof globalThis.localStorage.getItem !== "function"
-) {
- const store: Record<string, string> = {};
- const localStorageMock = {
- getItem: vi.fn((key: string) => store[key] ?? null),
- setItem: vi.fn((key: string, value: string) => {
- store[key] = value;
- }),
- removeItem: vi.fn((key: string) => {
- delete store[key];
- }),
- clear: vi.fn(() => {
- for (const key of Object.keys(store)) {
+ // jsdom 29 / Node.js 22+ may not provide a proper Web Storage API.
+ // Create a proper localStorage mock if methods are missing.
+ if (
+ typeof globalThis.localStorage === "undefined" ||
+ typeof globalThis.localStorage.getItem !== "function"
+ ) {
+ const store: Record<string, string> = {};
+ const localStorageMock = {
+ getItem: vi.fn((key: string) => store[key] ?? null),
+ setItem: vi.fn((key: string, value: string) => {
+ store[key] = value;
+ }),
+ removeItem: vi.fn((key: string) => {
delete store[key];
- }
- }),
- get length() {
- return Object.keys(store).length;
- },
- key: vi.fn((index: number) => Object.keys(store)[index] ?? null),
- };
- Object.defineProperty(globalThis, "localStorage", {
- value: localStorageMock,
- writable: true,
- });
+ }),
+ clear: vi.fn(() => {
+ for (const key of Object.keys(store)) {
+ delete store[key];
+ }
+ }),
+ get length() {
+ return Object.keys(store).length;
+ },
+ key: vi.fn((index: number) => Object.keys(store)[index] ?? null),
+ };
+ Object.defineProperty(globalThis, "localStorage", {
+ value: localStorageMock,
+ writable: true,
+ });
+ }
}
diff --git a/packages/views/agents/agents-i18n-parity.test.ts b/packages/views/agents/agents-i18n-parity.test.ts
index d67a06c5e9..f1ecc4a898 100644
--- a/packages/views/agents/agents-i18n-parity.test.ts
+++ b/packages/views/agents/agents-i18n-parity.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import en from "../locales/en/agents.json";
import zhHans from "../locales/zh-Hans/agents.json";
diff --git a/packages/views/agents/components/inspector/model-capability.test.ts b/packages/views/agents/components/inspector/model-capability.test.ts
index f573728445..6628765ceb 100644
--- a/packages/views/agents/components/inspector/model-capability.test.ts
+++ b/packages/views/agents/components/inspector/model-capability.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import type { RuntimeModel } from "@multica/core/types";
import {
diff --git a/packages/views/agents/components/inspector/model-change-cleanup.test.ts b/packages/views/agents/components/inspector/model-change-cleanup.test.ts
index 5e48c0c8d9..688203c0fd 100644
--- a/packages/views/agents/components/inspector/model-change-cleanup.test.ts
+++ b/packages/views/agents/components/inspector/model-change-cleanup.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import type { RuntimeModel } from "@multica/core/types";
import { buildModelChangeUpdate } from "./model-change-cleanup";
diff --git a/packages/views/agents/components/tabs/env-file.test.ts b/packages/views/agents/components/tabs/env-file.test.ts
index bbefccadb6..fb576acc85 100644
--- a/packages/views/agents/components/tabs/env-file.test.ts
+++ b/packages/views/agents/components/tabs/env-file.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import type { EnvAssignment } from "./env-file";
diff --git a/packages/views/agents/components/tabs/mcp-config-model.test.ts b/packages/views/agents/components/tabs/mcp-config-model.test.ts
index 0b308fce5c..ea45b8261b 100644
--- a/packages/views/agents/components/tabs/mcp-config-model.test.ts
+++ b/packages/views/agents/components/tabs/mcp-config-model.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import {
listManagedMcpServers,
diff --git a/packages/views/agents/components/tabs/task-failure.test.ts b/packages/views/agents/components/tabs/task-failure.test.ts
index 0710d14b9c..55483e86e6 100644
--- a/packages/views/agents/components/tabs/task-failure.test.ts
+++ b/packages/views/agents/components/tabs/task-failure.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { cancelReasonLabel, failureReasonLabel } from "./task-failure";
diff --git a/packages/views/autopilots/components/autopilots-page.test.ts b/packages/views/autopilots/components/autopilots-page.test.ts
index c6412130ee..8126804015 100644
--- a/packages/views/autopilots/components/autopilots-page.test.ts
+++ b/packages/views/autopilots/components/autopilots-page.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
diff --git a/packages/views/autopilots/components/run-now-toast.test.ts b/packages/views/autopilots/components/run-now-toast.test.ts
index 58f0728485..8a229c754b 100644
--- a/packages/views/autopilots/components/run-now-toast.test.ts
+++ b/packages/views/autopilots/components/run-now-toast.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { runNowToastKind, runNowBlockedKey } from "./run-now-toast";
diff --git a/packages/views/autopilots/components/schedule-editor/cron-grammar.test.ts b/packages/views/autopilots/components/schedule-editor/cron-grammar.test.ts
index 0134f8e374..7fbfc97955 100644
--- a/packages/views/autopilots/components/schedule-editor/cron-grammar.test.ts
+++ b/packages/views/autopilots/components/schedule-editor/cron-grammar.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect, vi } from "vitest";
import { cronFields, parseCron, toCron } from "./cron-mapping";
diff --git a/packages/views/autopilots/components/schedule-editor/cron-mapping.test.ts b/packages/views/autopilots/components/schedule-editor/cron-mapping.test.ts
index a1c431f1de..6465216e65 100644
--- a/packages/views/autopilots/components/schedule-editor/cron-mapping.test.ts
+++ b/packages/views/autopilots/components/schedule-editor/cron-mapping.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { cronFields, parseCron, toCron } from "./cron-mapping";
import type { ScheduleConfig } from "./model";
diff --git a/packages/views/autopilots/components/schedule-editor/schedule-editor.test.tsx b/packages/views/autopilots/components/schedule-editor/schedule-editor.test.tsx
index a3cea6ea55..1d52b7092a 100644
--- a/packages/views/autopilots/components/schedule-editor/schedule-editor.test.tsx
+++ b/packages/views/autopilots/components/schedule-editor/schedule-editor.test.tsx
@@ -463,21 +463,6 @@ describe("ScheduleEditor", () => {
expect(screen.getByTestId("cron-out").textContent).toBe("30 14 * * *");
});
- it("keeps the minute across a fixed time → minute-step window → fixed time trip", async () => {
- const user = userEvent.setup();
- renderEditor(cron("30 14 * * *"));
- await user.click(screen.getByRole("button", { name: "At an interval" }));
- await user.click(screen.getByLabelText("Interval unit"));
- await user.click(await screen.findByRole("option", { name: "minutes" }));
- await user.click(screen.getByLabelText("Window start hour"));
- await user.keyboard("14");
- await user.click(screen.getByRole("button", { name: "At a time" }));
- // A minute-step window is hour-granular, so its bounds read :00 — but the
- // model still holds the 30 the user typed. Reading the anchor back off the
- // window would silently fire the schedule half an hour early.
- expect(screen.getByTestId("cron-out").textContent).toBe("30 14 * * *");
- });
-
it("focuses the interval when the time switches to an interval", async () => {
const user = userEvent.setup();
renderEditor(cron("0 9 * * *"));
@@ -707,18 +692,6 @@ describe("ScheduleEditor", () => {
expect(cronOut()).toBe("0 9-23/3 * * *");
});
- it("takes a window widened back to the whole day as all day again", async () => {
- const user = userEvent.setup();
- renderEditor(cron("0 9-21/3 * * *"));
- await user.click(screen.getByLabelText("Window start hour"));
- await user.keyboard("00");
- await user.click(screen.getByLabelText("Window end hour"));
- await user.keyboard("23");
- // A window that spans the day IS all day: the schedule has one form, and
- // "0-23/3" is not a second one.
- expect(cronOut()).toBe("0 */3 * * *");
- });
-
it("clears the window end to the end of the day, not onto its start", async () => {
const user = userEvent.setup();
renderEditor(cron("0 9-15 * * *"));
@@ -738,15 +711,6 @@ describe("ScheduleEditor", () => {
expect(cronOut()).toBe("0 * * * *");
});
- it("raises the window end when the start is moved past it", async () => {
- const user = userEvent.setup();
- renderEditor(cron("0 9-12 * * *"));
- const startHour = screen.getByLabelText("Window start hour");
- await user.click(startHour!);
- await user.keyboard("18");
- expect(cronOut()).toBe("0 18-18 * * *");
- });
-
it("moves the shared firing minute when the window end's minute is edited", async () => {
const user = userEvent.setup();
renderEditor(cron("0 9-21 * * *"));
@@ -757,16 +721,9 @@ describe("ScheduleEditor", () => {
expect(cronOut()).toBe("30 9-21 * * *");
});
- it("keeps the firing minute across an interval unit round-trip", async () => {
- const user = userEvent.setup();
- renderEditor(cron("30 */2 * * *"));
- await user.click(screen.getAllByRole("combobox")[0]!);
- await user.click(await screen.findByRole("option", { name: "minutes" }));
- await user.click(screen.getAllByRole("combobox")[0]!);
- await user.click(await screen.findByRole("option", { name: "hours" }));
- expect(cronOut()).toBe("30 */2 * * *");
- });
-
+ // The all-day variant of this round-trip is the same wiring with a strictly
+ // weaker assertion; clampWindow's own unit round-trip matrix is in
+ // transitions.test.ts.
it("keeps the firing minute across a unit round-trip with a time window", async () => {
const user = userEvent.setup();
renderEditor(cron("30 9-21/2 * * *"));
diff --git a/packages/views/autopilots/components/schedule-editor/schedule-editor.tsx b/packages/views/autopilots/components/schedule-editor/schedule-editor.tsx
index 220372f738..b456faae21 100644
--- a/packages/views/autopilots/components/schedule-editor/schedule-editor.tsx
+++ b/packages/views/autopilots/components/schedule-editor/schedule-editor.tsx
@@ -49,6 +49,17 @@ import {
} from "./cron-mapping";
import { classifyScheduleRejection } from "./validate";
import { useDescribeSchedule } from "./describe";
+import {
+ clampWindow,
+ defaultAtTime,
+ defaultEveryTime,
+ displayWindow,
+ isFullDay,
+ timeAnchorOf,
+ toggleDay,
+ type EveryPattern,
+ type ScheduleWindow,
+} from "./transitions";
export interface ScheduleEditorProps {
value: ScheduleConfig;
@@ -63,9 +74,6 @@ export interface ScheduleEditorProps {
const PREVIEW_DEBOUNCE_MS = 300;
-type EveryPattern = Extract<TimePattern, { kind: "every" }>;
-type ScheduleWindow = { from: string; to: string };
-
function useNowTicker(intervalMs = 30_000): Date {
const [now, setNow] = useState(() => new Date());
useEffect(() => {
@@ -98,113 +106,6 @@ function useFormatCountdown() {
};
}
-// The window is a dimension of the schedule, not a mode of the editor: all day is
-// the window that spans the day, and the model spells that one way — `window:
-// null`. Every window the editor commits goes through here, so the two never drift
-// into two representations of the same schedule.
-//
-// The bounds are read as hours. A minute-step window is hour-granular (its ends
-// read :00 and :59), and an hours-step window carries the firing minute at both
-// ends — neither minute has a say in whether the window spans the day.
-function isFullDay(window: ScheduleWindow): boolean {
- return timeParts(window.from).hour === 0 && timeParts(window.to).hour === 23;
-}
-
-/** The window as the controls show it. All day has no window of its own, and the
- * fields still have to render something: the bounds it stands for. */
-function displayWindow(time: EveryPattern): ScheduleWindow {
- if (time.window !== null) return time.window;
- return time.unit === "hours"
- ? { from: `00:${pad2(time.minute)}`, to: `23:${pad2(time.minute)}` }
- : { from: "00:00", to: "23:59" };
-}
-
-// An "every N hours, all day" pattern has nowhere to keep an hour, so the last
-// hour:minute the user actually expressed is carried outside the model. Without
-// it, at 14:30 → interval → at silently comes back as 09:30.
-//
-// The hour comes from the window, the minute from `minute` — never from the
-// window's own text. A minute-step window is hour-granular, so its bounds read
-// :00; taking the minute from there would drop the 30 of a 14:30 the user typed
-// before switching, which the model still holds.
-//
-// All day has no hour to give: the 00:00 its fields show is the absence of a
-// bound, not a time the user picked, and carrying it over would rewrite their
-// 14:30 to 00:30 on the way back to a fixed time.
-function timeAnchorOf(time: TimePattern): string | null {
- if (time.kind === "at") return time.time;
- if (time.window === null) return null;
- return `${pad2(timeParts(time.window.from).hour)}:${pad2(time.minute)}`;
-}
-
-function defaultAtTime(prev: TimePattern, anchor: string): string {
- return (
- timeAnchorOf(prev) ??
- `${pad2(timeParts(anchor).hour)}:${pad2(prev.kind === "every" ? prev.minute : 0)}`
- );
-}
-
-// Switching to a fixed time can only carry one HH:MM, so the step, the unit and
-// the window would be gone on the way back — "every 3h, 9:00–21:00" would return
-// as "every hour, all day". They are remembered outside the model and restored,
-// rebased on whatever time the user is now switching away from.
-function defaultEveryTime(prev: TimePattern, anchor: EveryPattern | null): EveryPattern {
- if (prev.kind === "every") return prev;
- const { hour, minute } = timeParts(prev.time);
- const base: EveryPattern = anchor ?? {
- kind: "every",
- interval: 1,
- unit: "hours",
- window: null,
- minute,
- };
- const time: EveryPattern = { ...base, minute };
- if (time.window === null) return time;
- // The window restarts at the time the user is switching away from — but only
- // where that still leaves a window. Rebasing "09:00–15:00" onto a 22:00 fixed
- // time would drag the end up to 22 and hand back the single hour 22:00–22:00,
- // destroying the very window this anchor exists to keep.
- // Strictly earlier: a start rebased onto the end hour itself leaves the single
- // hour 15:00–15:00, which is the same collapse by another name.
- const rebased =
- hour < timeParts(time.window.to).hour
- ? { from: `${pad2(hour)}:${pad2(minute)}`, to: time.window.to }
- : time.window;
- // Rebasing a window that ends at 23 onto a midnight fixed time spans the whole
- // day, and a window that spans the day is not one — the model holds that as all
- // day, and nothing else may hand back a second form of it.
- const window = clampWindow(rebased, time.unit, minute);
- return { ...time, window: isFullDay(window) ? null : window };
-}
-
-// Keep windows canonical: `minute` — not the window's own current text — is the
-// single source of truth for the firing minute, so a hours → minutes → hours
-// unit round-trip restores it instead of leaving the zeroed value behind. Minute
-// intervals are hour-granular, and `to` is never earlier than `from`.
-function clampWindow(
- window: ScheduleWindow,
- unit: EveryPattern["unit"],
- minute: number,
-): ScheduleWindow {
- const from = timeParts(window.from);
- const to = timeParts(window.to);
- const edgeMinute = unit === "hours" ? minute : 0;
- const endMinute = unit === "hours" ? minute : 59;
- const endHour = Math.max(to.hour, from.hour);
- return {
- from: `${pad2(from.hour)}:${pad2(edgeMinute)}`,
- to: `${pad2(endHour)}:${pad2(endMinute)}`,
- };
-}
-
-function toggleDay(days: number[], day: number): number[] {
- if (days.includes(day)) {
- if (days.length === 1) return days;
- return days.filter((d) => d !== day);
- }
- return [...days, day].toSorted((a, b) => a - b);
-}
-
/** One dimension of the schedule. A fieldset, not a styled div: a greyed-out
* control that keyboard users can still reach would silently overwrite the
* stored expression. */
diff --git a/packages/views/autopilots/components/schedule-editor/transitions.test.ts b/packages/views/autopilots/components/schedule-editor/transitions.test.ts
new file mode 100644
index 0000000000..166e0acde0
--- /dev/null
+++ b/packages/views/autopilots/components/schedule-editor/transitions.test.ts
@@ -0,0 +1,220 @@
+// @vitest-environment node
+import { describe, expect, it } from "vitest";
+import type { TimePattern } from "./model";
+import {
+ clampWindow,
+ defaultAtTime,
+ defaultEveryTime,
+ displayWindow,
+ isFullDay,
+ timeAnchorOf,
+ toggleDay,
+ type EveryPattern,
+} from "./transitions";
+
+// The canonical matrix for the editor's schedule state transitions. These ran
+// as full DOM mounts in schedule-editor.test.tsx, one userEvent chain per
+// combination; the component suite now keeps the wiring and focus cases and
+// defers the combination space to the table below.
+
+const every = (over: Partial<EveryPattern> = {}): EveryPattern => ({
+ kind: "every",
+ interval: 1,
+ unit: "hours",
+ window: null,
+ minute: 0,
+ ...over,
+});
+
+describe("isFullDay", () => {
+ it.each([
+ ["00:00", "23:59", true],
+ ["00:30", "23:30", true],
+ ["00:00", "23:00", true],
+ ["09:00", "21:00", false],
+ ["00:00", "22:59", false],
+ ["01:00", "23:59", false],
+ ["22:00", "22:00", false],
+ ])("%s–%s spans the day: %s", (from, to, expected) => {
+ expect(isFullDay({ from, to })).toBe(expected);
+ });
+
+ // Only the hours decide. An hours-step window carries the firing minute at
+ // both ends, and a minute-step window reads :00/:59 — neither may turn a
+ // day-spanning window into something the model would hold as a real window.
+ it("ignores the minutes at both bounds", () => {
+ expect(isFullDay({ from: "00:59", to: "23:00" })).toBe(true);
+ });
+});
+
+describe("displayWindow", () => {
+ it("passes a real window through untouched", () => {
+ const window = { from: "09:00", to: "21:00" };
+ expect(displayWindow(every({ window }))).toEqual(window);
+ });
+
+ // All day has no window of its own, but the fields still render something:
+ // the bounds it stands for, at the granularity of the unit.
+ it("renders all day as the bounds it stands for, per unit", () => {
+ expect(displayWindow(every({ unit: "hours", minute: 30 }))).toEqual({
+ from: "00:30",
+ to: "23:30",
+ });
+ expect(displayWindow(every({ unit: "minutes", minute: 30 }))).toEqual({
+ from: "00:00",
+ to: "23:59",
+ });
+ });
+});
+
+describe("timeAnchorOf", () => {
+ it("takes a fixed time verbatim", () => {
+ expect(timeAnchorOf({ kind: "at", time: "14:30" })).toBe("14:30");
+ });
+
+ // The hour comes from the window, the minute from `minute` — never from the
+ // window's own text. A minute-step window is hour-granular, so its bounds
+ // read :00; reading the minute off them would fire a 14:30 schedule at 14:00.
+ it("takes the hour from the window and the minute from the model", () => {
+ expect(
+ timeAnchorOf(
+ every({ unit: "minutes", minute: 30, window: { from: "14:00", to: "14:59" } }),
+ ),
+ ).toBe("14:30");
+ expect(
+ timeAnchorOf(
+ every({ unit: "hours", minute: 30, window: { from: "14:30", to: "21:30" } }),
+ ),
+ ).toBe("14:30");
+ });
+
+ // All day has no hour to give: the 00:00 its fields show is the absence of a
+ // bound, not a time the user picked. Carrying it over would rewrite a 14:30.
+ it("has no anchor for an all-day interval", () => {
+ expect(timeAnchorOf(every({ minute: 30 }))).toBeNull();
+ });
+});
+
+describe("defaultAtTime", () => {
+ it("carries the anchor the current pattern can give", () => {
+ expect(defaultAtTime({ kind: "at", time: "14:30" }, "09:00")).toBe("14:30");
+ expect(
+ defaultAtTime(every({ minute: 30, window: { from: "14:30", to: "21:30" } }), "09:00"),
+ ).toBe("14:30");
+ });
+
+ // Falling back to the remembered anchor keeps the hour, but the minute is the
+ // schedule's own and outranks the anchor's.
+ it("falls back to the remembered hour with the pattern's minute", () => {
+ expect(defaultAtTime(every({ minute: 45 }), "08:15")).toBe("08:45");
+ expect(defaultAtTime({ kind: "at", time: "00:00" }, "08:15")).toBe("00:00");
+ });
+});
+
+describe("defaultEveryTime", () => {
+ it("leaves an interval pattern alone", () => {
+ const time = every({ interval: 3, window: { from: "09:00", to: "21:00" } });
+ expect(defaultEveryTime(time, null)).toBe(time);
+ });
+
+ // Step, unit and window are as much user input as the hour is; rebuilding
+ // from defaults would turn "every 3h, 9–21" into "every hour, all day".
+ it("restores the remembered step, unit and window", () => {
+ const anchor = every({ interval: 3, window: { from: "09:00", to: "21:00" } });
+ expect(defaultEveryTime({ kind: "at", time: "10:00" }, anchor)).toMatchObject({
+ interval: 3,
+ unit: "hours",
+ window: { from: "10:00", to: "21:00" },
+ });
+ });
+
+ it("falls back to hourly all day with no anchor", () => {
+ expect(defaultEveryTime({ kind: "at", time: "10:15" }, null)).toEqual(
+ every({ interval: 1, unit: "hours", window: null, minute: 15 }),
+ );
+ });
+
+ // Rebasing "09:00–15:00" onto a 22:00 fixed time would drag the end up and
+ // hand back the single hour 22:00–22:00, destroying the very window the
+ // anchor exists to keep. Rebasing onto the end hour itself is the same
+ // collapse by another name, so the guard is strictly-earlier.
+ it.each([
+ ["22:00", { from: "09:00", to: "15:00" }],
+ ["15:00", { from: "09:00", to: "15:00" }],
+ ])("keeps the window when %s would collapse it", (time, window) => {
+ expect(
+ defaultEveryTime({ kind: "at", time }, every({ interval: 3, window })),
+ ).toMatchObject({ window });
+ });
+
+ // A window rebased across the whole day is not a window — the model spells
+ // that one way, and nothing else may hand back a second form of it.
+ it("collapses a rebased day-spanning window to all day", () => {
+ expect(
+ defaultEveryTime(
+ { kind: "at", time: "00:00" },
+ every({ interval: 3, window: { from: "09:00", to: "23:00" } }),
+ ),
+ ).toMatchObject({ window: null });
+ });
+});
+
+describe("clampWindow", () => {
+ // `minute` — not the window's own current text — is the single source of
+ // truth for the firing minute, so an hours → minutes → hours round-trip
+ // restores it instead of leaving the zeroed value behind.
+ it.each([
+ ["hours", 30, { from: "09:00", to: "21:00" }, { from: "09:30", to: "21:30" }],
+ ["minutes", 30, { from: "09:30", to: "21:30" }, { from: "09:00", to: "21:59" }],
+ ["hours", 0, { from: "09:30", to: "21:30" }, { from: "09:00", to: "21:00" }],
+ ] as const)("%s at :%s canonicalises the bounds", (unit, minute, input, expected) => {
+ expect(clampWindow(input, unit, minute)).toEqual(expected);
+ });
+
+ // The end is never earlier than the start: moving the start past the end
+ // raises the end to meet it rather than inverting the range.
+ it.each([
+ [{ from: "18:00", to: "12:00" }, { from: "18:00", to: "18:00" }],
+ [{ from: "09:00", to: "09:00" }, { from: "09:00", to: "09:00" }],
+ [{ from: "00:00", to: "23:00" }, { from: "00:00", to: "23:00" }],
+ ])("raises an overrun end to the start", (input, expected) => {
+ expect(clampWindow(input, "hours", 0)).toEqual(expected);
+ });
+
+ it("survives a unit round-trip with the firing minute intact", () => {
+ const start = { from: "09:30", to: "21:30" };
+ const toMinutes = clampWindow(start, "minutes", 30);
+ expect(clampWindow(toMinutes, "hours", 30)).toEqual(start);
+ });
+});
+
+describe("toggleDay", () => {
+ it("adds a day in ascending order", () => {
+ expect(toggleDay([1, 5], 3)).toEqual([1, 3, 5]);
+ expect(toggleDay([3], 0)).toEqual([0, 3]);
+ });
+
+ it("removes a day that is already selected", () => {
+ expect(toggleDay([1, 3, 5], 3)).toEqual([1, 5]);
+ });
+
+ // A weekly schedule with no days never fires; the last one is not removable.
+ it("keeps the last remaining day", () => {
+ expect(toggleDay([3], 3)).toEqual([3]);
+ });
+});
+
+// A fixed time survives a trip out to an interval and back. The component
+// suite keeps one round-trip case for the wiring; the pattern-level guarantee
+// it rests on is here.
+describe("fixed time → interval → fixed time", () => {
+ it.each([
+ ["14:30", every({ interval: 3, window: { from: "09:00", to: "21:00" } })],
+ ["14:30", null],
+ ["00:15", null],
+ ])("returns %s unchanged", (time, anchor) => {
+ const at: TimePattern = { kind: "at", time };
+ const interval = defaultEveryTime(at, anchor);
+ expect(defaultAtTime(interval, time)).toBe(time);
+ });
+});
diff --git a/packages/views/autopilots/components/schedule-editor/transitions.ts b/packages/views/autopilots/components/schedule-editor/transitions.ts
new file mode 100644
index 0000000000..f7d3c9cd89
--- /dev/null
+++ b/packages/views/autopilots/components/schedule-editor/transitions.ts
@@ -0,0 +1,115 @@
+import type { TimePattern } from "./model";
+import { pad2, timeParts } from "./model";
+
+export type EveryPattern = Extract<TimePattern, { kind: "every" }>;
+export type ScheduleWindow = { from: string; to: string };
+
+// The window is a dimension of the schedule, not a mode of the editor: all day is
+// the window that spans the day, and the model spells that one way — `window:
+// null`. Every window the editor commits goes through here, so the two never drift
+// into two representations of the same schedule.
+//
+// The bounds are read as hours. A minute-step window is hour-granular (its ends
+// read :00 and :59), and an hours-step window carries the firing minute at both
+// ends — neither minute has a say in whether the window spans the day.
+export function isFullDay(window: ScheduleWindow): boolean {
+ return timeParts(window.from).hour === 0 && timeParts(window.to).hour === 23;
+}
+
+/** The window as the controls show it. All day has no window of its own, and the
+ * fields still have to render something: the bounds it stands for. */
+export function displayWindow(time: EveryPattern): ScheduleWindow {
+ if (time.window !== null) return time.window;
+ return time.unit === "hours"
+ ? { from: `00:${pad2(time.minute)}`, to: `23:${pad2(time.minute)}` }
+ : { from: "00:00", to: "23:59" };
+}
+
+// An "every N hours, all day" pattern has nowhere to keep an hour, so the last
+// hour:minute the user actually expressed is carried outside the model. Without
+// it, at 14:30 → interval → at silently comes back as 09:30.
+//
+// The hour comes from the window, the minute from `minute` — never from the
+// window's own text. A minute-step window is hour-granular, so its bounds read
+// :00; taking the minute from there would drop the 30 of a 14:30 the user typed
+// before switching, which the model still holds.
+//
+// All day has no hour to give: the 00:00 its fields show is the absence of a
+// bound, not a time the user picked, and carrying it over would rewrite their
+// 14:30 to 00:30 on the way back to a fixed time.
+export function timeAnchorOf(time: TimePattern): string | null {
+ if (time.kind === "at") return time.time;
+ if (time.window === null) return null;
+ return `${pad2(timeParts(time.window.from).hour)}:${pad2(time.minute)}`;
+}
+
+export function defaultAtTime(prev: TimePattern, anchor: string): string {
+ return (
+ timeAnchorOf(prev) ??
+ `${pad2(timeParts(anchor).hour)}:${pad2(prev.kind === "every" ? prev.minute : 0)}`
+ );
+}
+
+// Switching to a fixed time can only carry one HH:MM, so the step, the unit and
+// the window would be gone on the way back — "every 3h, 9:00–21:00" would return
+// as "every hour, all day". They are remembered outside the model and restored,
+// rebased on whatever time the user is now switching away from.
+export function defaultEveryTime(
+ prev: TimePattern,
+ anchor: EveryPattern | null,
+): EveryPattern {
+ if (prev.kind === "every") return prev;
+ const { hour, minute } = timeParts(prev.time);
+ const base: EveryPattern = anchor ?? {
+ kind: "every",
+ interval: 1,
+ unit: "hours",
+ window: null,
+ minute,
+ };
+ const time: EveryPattern = { ...base, minute };
+ if (time.window === null) return time;
+ // The window restarts at the time the user is switching away from — but only
+ // where that still leaves a window. Rebasing "09:00–15:00" onto a 22:00 fixed
+ // time would drag the end up to 22 and hand back the single hour 22:00–22:00,
+ // destroying the very window this anchor exists to keep.
+ // Strictly earlier: a start rebased onto the end hour itself leaves the single
+ // hour 15:00–15:00, which is the same collapse by another name.
+ const rebased =
+ hour < timeParts(time.window.to).hour
+ ? { from: `${pad2(hour)}:${pad2(minute)}`, to: time.window.to }
+ : time.window;
+ // Rebasing a window that ends at 23 onto a midnight fixed time spans the whole
+ // day, and a window that spans the day is not one — the model holds that as all
+ // day, and nothing else may hand back a second form of it.
+ const window = clampWindow(rebased, time.unit, minute);
+ return { ...time, window: isFullDay(window) ? null : window };
+}
+
+// Keep windows canonical: `minute` — not the window's own current text — is the
+// single source of truth for the firing minute, so a hours → minutes → hours
+// unit round-trip restores it instead of leaving the zeroed value behind. Minute
+// intervals are hour-granular, and `to` is never earlier than `from`.
+export function clampWindow(
+ window: ScheduleWindow,
+ unit: EveryPattern["unit"],
+ minute: number,
+): ScheduleWindow {
+ const from = timeParts(window.from);
+ const to = timeParts(window.to);
+ const edgeMinute = unit === "hours" ? minute : 0;
+ const endMinute = unit === "hours" ? minute : 59;
+ const endHour = Math.max(to.hour, from.hour);
+ return {
+ from: `${pad2(from.hour)}:${pad2(edgeMinute)}`,
+ to: `${pad2(endHour)}:${pad2(endMinute)}`,
+ };
+}
+
+export function toggleDay(days: number[], day: number): number[] {
+ if (days.includes(day)) {
+ if (days.length === 1) return days;
+ return days.filter((d) => d !== day);
+ }
+ return [...days, day].toSorted((a, b) => a - b);
+}
diff --git a/packages/views/chat/components/task-status-pill.test.ts b/packages/views/chat/components/task-status-pill.test.ts
index 2b15e9917f..92cfe2bde3 100644
--- a/packages/views/chat/components/task-status-pill.test.ts
+++ b/packages/views/chat/components/task-status-pill.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { effectiveTaskStatus, pickStageKeys } from "./task-status-pill";
diff --git a/packages/views/chat/floating-chat-visibility.test.ts b/packages/views/chat/floating-chat-visibility.test.ts
index 401ddd8839..733e8bee7c 100644
--- a/packages/views/chat/floating-chat-visibility.test.ts
+++ b/packages/views/chat/floating-chat-visibility.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { isFloatingChatRouteSuppressed } from "./floating-chat-visibility";
diff --git a/packages/views/chat/lib/copy-text.test.ts b/packages/views/chat/lib/copy-text.test.ts
index 70937f77e0..b6ba987ad2 100644
--- a/packages/views/chat/lib/copy-text.test.ts
+++ b/packages/views/chat/lib/copy-text.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import type { ChatMessage } from "@multica/core/types";
import type { ChatTimelineItem } from "@multica/core/chat";
diff --git a/packages/views/chat/lib/quick-actions.test.ts b/packages/views/chat/lib/quick-actions.test.ts
index 156e7d409b..240de792e3 100644
--- a/packages/views/chat/lib/quick-actions.test.ts
+++ b/packages/views/chat/lib/quick-actions.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { stripChatQuickActionsProtocol } from "./quick-actions";
diff --git a/packages/views/common/avatar-crop.test.ts b/packages/views/common/avatar-crop.test.ts
index 6460ef7bab..9269b63377 100644
--- a/packages/views/common/avatar-crop.test.ts
+++ b/packages/views/common/avatar-crop.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { blobToAvatarFile } from "./avatar-crop";
diff --git a/packages/views/common/color-utils.test.ts b/packages/views/common/color-utils.test.ts
index 779a091975..44547c4fa2 100644
--- a/packages/views/common/color-utils.test.ts
+++ b/packages/views/common/color-utils.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import {
hexToHsv,
diff --git a/packages/views/common/format-in-time-zone.test.ts b/packages/views/common/format-in-time-zone.test.ts
index 69b7cfca33..4d75ad5f98 100644
--- a/packages/views/common/format-in-time-zone.test.ts
+++ b/packages/views/common/format-in-time-zone.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { formatInTimeZone } from "./format-in-time-zone";
diff --git a/packages/views/common/github-url.test.ts b/packages/views/common/github-url.test.ts
index e12ab4b788..270878b9ea 100644
--- a/packages/views/common/github-url.test.ts
+++ b/packages/views/common/github-url.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { githubShortLabel, midTruncate } from "./github-url";
diff --git a/packages/views/common/task-transcript/build-steps.test.ts b/packages/views/common/task-transcript/build-steps.test.ts
index 8f82309403..855e48338a 100644
--- a/packages/views/common/task-transcript/build-steps.test.ts
+++ b/packages/views/common/task-transcript/build-steps.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import {
buildLanes,
diff --git a/packages/views/common/task-transcript/build-timeline.test.ts b/packages/views/common/task-transcript/build-timeline.test.ts
index 5f70299516..eb9f6c5563 100644
--- a/packages/views/common/task-transcript/build-timeline.test.ts
+++ b/packages/views/common/task-transcript/build-timeline.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import type { TaskMessagePayload } from "@multica/core/types/events";
import { appendTimelineItem, buildTimeline, coalesceTimelineItems, type TimelineItem } from "./build-timeline";
diff --git a/packages/views/common/task-transcript/redact.test.ts b/packages/views/common/task-transcript/redact.test.ts
index 2d92bd02c1..9f7a9a63ce 100644
--- a/packages/views/common/task-transcript/redact.test.ts
+++ b/packages/views/common/task-transcript/redact.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { redactSecrets } from "./redact";
diff --git a/packages/views/common/task-transcript/run-outcome.test.ts b/packages/views/common/task-transcript/run-outcome.test.ts
index fc984e8e22..99c8714b2f 100644
--- a/packages/views/common/task-transcript/run-outcome.test.ts
+++ b/packages/views/common/task-transcript/run-outcome.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { buildRunOutcome } from "./run-outcome";
import { buildSteps } from "./build-steps";
diff --git a/packages/views/common/task-transcript/trace-event-presenter.test.ts b/packages/views/common/task-transcript/trace-event-presenter.test.ts
index 750b0507f9..02daab9cca 100644
--- a/packages/views/common/task-transcript/trace-event-presenter.test.ts
+++ b/packages/views/common/task-transcript/trace-event-presenter.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import {
collapseDiffContext,
diff --git a/packages/views/common/task-transcript/transcript-follow.test.ts b/packages/views/common/task-transcript/transcript-follow.test.ts
index ae7cba0763..1934097ed4 100644
--- a/packages/views/common/task-transcript/transcript-follow.test.ts
+++ b/packages/views/common/task-transcript/transcript-follow.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { createNewestFirstFollow, FOLLOW_EDGE_THRESHOLD } from "./transcript-follow";
diff --git a/packages/views/common/type-scale-merge.test.ts b/packages/views/common/type-scale-merge.test.ts
index 8f901dbba7..3e2918976e 100644
--- a/packages/views/common/type-scale-merge.test.ts
+++ b/packages/views/common/type-scale-merge.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { cn } from "@multica/ui/lib/utils";
diff --git a/packages/views/editor/extensions/pinyin-match.test.ts b/packages/views/editor/extensions/pinyin-match.test.ts
index de369d93d0..f3aca4f152 100644
--- a/packages/views/editor/extensions/pinyin-match.test.ts
+++ b/packages/views/editor/extensions/pinyin-match.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { matchesPinyin } from "./pinyin-match";
diff --git a/packages/views/editor/extensions/slash-command-extension.test.ts b/packages/views/editor/extensions/slash-command-extension.test.ts
index a83c5b5d00..106445039c 100644
--- a/packages/views/editor/extensions/slash-command-extension.test.ts
+++ b/packages/views/editor/extensions/slash-command-extension.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { SlashCommandExtension } from "./slash-command-extension";
diff --git a/packages/views/editor/syntax-highlight.test.ts b/packages/views/editor/syntax-highlight.test.ts
index 8428969c8a..fd064eb539 100644
--- a/packages/views/editor/syntax-highlight.test.ts
+++ b/packages/views/editor/syntax-highlight.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { codeLowlight, highlightCode } from "./syntax-highlight";
diff --git a/packages/views/editor/utils/escape-markdown-label.test.ts b/packages/views/editor/utils/escape-markdown-label.test.ts
index 19a20333e2..010b1bc48c 100644
--- a/packages/views/editor/utils/escape-markdown-label.test.ts
+++ b/packages/views/editor/utils/escape-markdown-label.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { escapeMarkdownLabel } from "./escape-markdown-label";
diff --git a/packages/views/editor/utils/hash-string.test.ts b/packages/views/editor/utils/hash-string.test.ts
index 38e856980d..704f35ad8d 100644
--- a/packages/views/editor/utils/hash-string.test.ts
+++ b/packages/views/editor/utils/hash-string.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { hashString } from "./hash-string";
diff --git a/packages/views/editor/utils/highlight-markdown.test.ts b/packages/views/editor/utils/highlight-markdown.test.ts
index 7e82fc9e1e..5bd40bbbc0 100644
--- a/packages/views/editor/utils/highlight-markdown.test.ts
+++ b/packages/views/editor/utils/highlight-markdown.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { highlightToHtml } from "./highlight-markdown";
diff --git a/packages/views/editor/utils/highlight-match.test.ts b/packages/views/editor/utils/highlight-match.test.ts
index 625d082f25..9af70b3865 100644
--- a/packages/views/editor/utils/highlight-match.test.ts
+++ b/packages/views/editor/utils/highlight-match.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { matchHighlightAt, findLiteralRanges } from "./highlight-match";
diff --git a/packages/views/editor/utils/parse-markdown-chunked.test.ts b/packages/views/editor/utils/parse-markdown-chunked.test.ts
index ebdb898be1..ff8f51af61 100644
--- a/packages/views/editor/utils/parse-markdown-chunked.test.ts
+++ b/packages/views/editor/utils/parse-markdown-chunked.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it, vi } from "vitest";
import {
MARKDOWN_CHUNK_THRESHOLD,
diff --git a/packages/views/editor/utils/preprocess-links.test.ts b/packages/views/editor/utils/preprocess-links.test.ts
index 3f021a820d..f0afb4453e 100644
--- a/packages/views/editor/utils/preprocess-links.test.ts
+++ b/packages/views/editor/utils/preprocess-links.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { preprocessLinks } from "@multica/ui/markdown/linkify";
diff --git a/packages/views/editor/utils/preview.test.ts b/packages/views/editor/utils/preview.test.ts
index 31a9f78af3..9439c2a015 100644
--- a/packages/views/editor/utils/preview.test.ts
+++ b/packages/views/editor/utils/preview.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import {
extensionToLanguage,
diff --git a/packages/views/editor/utils/zoom-transform.test.ts b/packages/views/editor/utils/zoom-transform.test.ts
index 6c93cd0556..22e471cdcc 100644
--- a/packages/views/editor/utils/zoom-transform.test.ts
+++ b/packages/views/editor/utils/zoom-transform.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import {
MAX_SCALE,
diff --git a/packages/views/inbox/components/inbox-display.test.ts b/packages/views/inbox/components/inbox-display.test.ts
index 28c7bf9848..fbd2c4aef8 100644
--- a/packages/views/inbox/components/inbox-display.test.ts
+++ b/packages/views/inbox/components/inbox-display.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import type { InboxItem } from "@multica/core/types";
import {
diff --git a/packages/views/issues/blocked-trigger-copy.test.ts b/packages/views/issues/blocked-trigger-copy.test.ts
index f31366eb4b..66efd8e72f 100644
--- a/packages/views/issues/blocked-trigger-copy.test.ts
+++ b/packages/views/issues/blocked-trigger-copy.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { blockedReasonLabel, blockedShortReasonLabel } from "./blocked-trigger-copy";
diff --git a/packages/views/issues/components/description-preview.test.ts b/packages/views/issues/components/description-preview.test.ts
index 97e37f8ec6..ae3326469b 100644
--- a/packages/views/issues/components/description-preview.test.ts
+++ b/packages/views/issues/components/description-preview.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { descriptionPreview } from "./description-preview";
diff --git a/packages/views/issues/components/thread-utils.test.ts b/packages/views/issues/components/thread-utils.test.ts
index 7886b22c80..6e86314bca 100644
--- a/packages/views/issues/components/thread-utils.test.ts
+++ b/packages/views/issues/components/thread-utils.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import type { TimelineEntry } from "@multica/core/types";
import {
diff --git a/packages/views/issues/utils/filter.test.ts b/packages/views/issues/utils/filter.test.ts
index 08a1eb93c0..62ee4c47f5 100644
--- a/packages/views/issues/utils/filter.test.ts
+++ b/packages/views/issues/utils/filter.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import type { Issue, IssueAssigneeGroup } from "@multica/core/types";
import {
diff --git a/packages/views/issues/utils/strip-mention-markdown.test.ts b/packages/views/issues/utils/strip-mention-markdown.test.ts
index a393ada8d7..c79462a22f 100644
--- a/packages/views/issues/utils/strip-mention-markdown.test.ts
+++ b/packages/views/issues/utils/strip-mention-markdown.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import { stripMentionMarkdown } from "./strip-mention-markdown";
diff --git a/packages/views/locales/parity.test.ts b/packages/views/locales/parity.test.ts
index edd8c7a4a6..9da42b2080 100644
--- a/packages/views/locales/parity.test.ts
+++ b/packages/views/locales/parity.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { readdirSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, resolve } from "node:path";
diff --git a/packages/views/onboarding/source-backfill-merge.test.ts b/packages/views/onboarding/source-backfill-merge.test.ts
index 32f611501f..057b346949 100644
--- a/packages/views/onboarding/source-backfill-merge.test.ts
+++ b/packages/views/onboarding/source-backfill-merge.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { mergedQuestionnairePatch } from "./source-backfill-merge";
diff --git a/packages/views/onboarding/source-backfill-modal.test.tsx b/packages/views/onboarding/source-backfill-modal.test.tsx
index 40d454699d..e0f1ccd731 100644
--- a/packages/views/onboarding/source-backfill-modal.test.tsx
+++ b/packages/views/onboarding/source-backfill-modal.test.tsx
@@ -137,13 +137,12 @@ function renderModal() {
}
describe("SourceBackfillModal", () => {
- it("does not render when there is no user", () => {
- renderModal();
- expect(
- screen.queryByText(/How did you hear about Multica/i),
- ).not.toBeInTheDocument();
- });
-
+ // Which users need the backfill is needsSourceBackfill's contract — no user,
+ // not yet onboarded, empty/missing/legacy-string/malformed source, the skip
+ // flag and the dismiss cap all have their matrix in
+ // @multica/core/onboarding/needs-backfill.test.ts. What belongs here is the
+ // modal's own reaction to the verdict, so one settled user stands for the
+ // whole "predicate says no" family.
it("does not render when the user already recorded a source", () => {
setUser({
id: "u1",
@@ -275,18 +274,6 @@ describe("SourceBackfillModal", () => {
expect(sent.use_case).toEqual(["manage_team"]);
});
- it("treats a legacy single-string source as already answered", () => {
- setUser({
- id: "u1",
- onboarded_at: "2026-01-01T00:00:00Z",
- onboarding_questionnaire: { source: "search" },
- });
- renderModal();
- expect(
- screen.queryByText(/How did you hear about Multica/i),
- ).not.toBeInTheDocument();
- });
-
it("picking a second option replaces the first (single-select primary source)", async () => {
// The modal is a single-select radio. Industry default for HDYHAU
// is to capture the primary acquisition source, so picking a
diff --git a/packages/views/projects/components/project-issue-metrics.test.ts b/packages/views/projects/components/project-issue-metrics.test.ts
index 42611a0d6f..9ae9fe7682 100644
--- a/packages/views/projects/components/project-issue-metrics.test.ts
+++ b/packages/views/projects/components/project-issue-metrics.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { getProjectIssueMetrics } from "./project-issue-metrics";
diff --git a/packages/views/rich-content/package-exports.test.ts b/packages/views/rich-content/package-exports.test.ts
index 6ab36b6892..394202fc57 100644
--- a/packages/views/rich-content/package-exports.test.ts
+++ b/packages/views/rich-content/package-exports.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
/**
* Package export-target guard.
*
diff --git a/packages/views/rich-content/rich-content-boundary.test.ts b/packages/views/rich-content/rich-content-boundary.test.ts
index 4034023c61..0d7f9d301e 100644
--- a/packages/views/rich-content/rich-content-boundary.test.ts
+++ b/packages/views/rich-content/rich-content-boundary.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
/**
* Import boundary guard (MUL-4922, Howard's contract #3).
*
diff --git a/packages/views/rich-content/streaming-fence.test.ts b/packages/views/rich-content/streaming-fence.test.ts
index fc0747af5d..c75ebc9404 100644
--- a/packages/views/rich-content/streaming-fence.test.ts
+++ b/packages/views/rich-content/streaming-fence.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { computeClosedFenceOffsets } from "./streaming-fence";
diff --git a/packages/views/runtimes/components/pending-runtime.test.ts b/packages/views/runtimes/components/pending-runtime.test.ts
index fe9ef796c4..5a4fa2412f 100644
--- a/packages/views/runtimes/components/pending-runtime.test.ts
+++ b/packages/views/runtimes/components/pending-runtime.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import type { AgentRuntime, RuntimeProfile } from "@multica/core/types";
import {
diff --git a/packages/views/runtimes/components/runtime-docs.test.ts b/packages/views/runtimes/components/runtime-docs.test.ts
index b1dfe26379..6c43c633c4 100644
--- a/packages/views/runtimes/components/runtime-docs.test.ts
+++ b/packages/views/runtimes/components/runtime-docs.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import {
customRuntimeDocsHref,
diff --git a/packages/views/runtimes/components/runtime-profile-catalog.test.ts b/packages/views/runtimes/components/runtime-profile-catalog.test.ts
index 454e164432..cab94f34ee 100644
--- a/packages/views/runtimes/components/runtime-profile-catalog.test.ts
+++ b/packages/views/runtimes/components/runtime-profile-catalog.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import type { RuntimeProfile } from "@multica/core/types";
import {
diff --git a/packages/views/skills/components/refresh-skill-dialog.test.tsx b/packages/views/skills/components/refresh-skill-dialog.test.tsx
index 1f51f1801d..755e2f2c10 100644
--- a/packages/views/skills/components/refresh-skill-dialog.test.tsx
+++ b/packages/views/skills/components/refresh-skill-dialog.test.tsx
@@ -73,23 +73,14 @@ describe("RefreshSkillDialog source URL", () => {
expect((link.textContent ?? "").length).toBeLessThanOrEqual(60);
});
- it("renders no link when the origin has no source_url", () => {
- renderDialog({ type: "manual" });
- expect(screen.queryByRole("link")).toBeNull();
- });
-
- // config.origin is persisted verbatim through the skill update API, so an
- // injected source_url must never surface as a live anchor in the dialog.
- it("renders no link when a non-import origin carries an injected source_url", () => {
+ // Which source_urls are linkable is originSourceUrl's contract, and its full
+ // matrix — host mismatch, lookalike hosts, non-http schemes, malformed and
+ // missing values, non-import origins — lives in ../lib/origin.test.ts. This
+ // case pins the wiring instead: when the helper refuses, the dialog renders
+ // no anchor at all. config.origin is persisted verbatim through the skill
+ // update API, so an injected source_url is the rejection that matters most.
+ it("renders no link when the helper refuses the source_url", () => {
renderDialog({ type: "manual", source_url: SOURCE_URL });
expect(screen.queryByRole("link")).toBeNull();
});
-
- it("renders no link when the source_url host does not match the origin type", () => {
- renderDialog({
- type: "github",
- source_url: "https://evil.example/anthropics/skills",
- });
- expect(screen.queryByRole("link")).toBeNull();
- });
});
diff --git a/packages/views/skills/components/skill-detail-page.test.tsx b/packages/views/skills/components/skill-detail-page.test.tsx
index 92dc7dce9d..9a6f05a781 100644
--- a/packages/views/skills/components/skill-detail-page.test.tsx
+++ b/packages/views/skills/components/skill-detail-page.test.tsx
@@ -451,19 +451,11 @@ describe("SkillDetailPage origin link", () => {
).toBeNull();
});
- it("does not link an imported origin whose source_url is missing", async () => {
- skillRef.current = {
- ...baseSkill,
- config: { origin: { type: "github" } },
- };
- renderPage();
- expect(await screen.findByText("Imported · GitHub")).toBeTruthy();
- expect(
- screen.queryByRole("link", { name: "Imported · GitHub" }),
- ).toBeNull();
- });
-
- it("does not link a source_url whose host does not match the origin type", async () => {
+ // Which source_urls are linkable is originSourceUrl's contract; its full
+ // matrix lives in ../lib/origin.test.ts. What belongs here is the chip's
+ // behaviour when the helper refuses: it degrades to plain text, still
+ // naming the origin, rather than dropping the label along with the href.
+ it("degrades a refused source_url to plain text, keeping the chip", async () => {
skillRef.current = {
...baseSkill,
config: {
diff --git a/packages/views/skills/lib/origin.test.ts b/packages/views/skills/lib/origin.test.ts
index 57a1f81019..b09e83908b 100644
--- a/packages/views/skills/lib/origin.test.ts
+++ b/packages/views/skills/lib/origin.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, expect, it } from "vitest";
import { originSourceUrl, type OriginInfo } from "./origin";
diff --git a/packages/views/test/setup.ts b/packages/views/test/setup.ts
index 574c61519d..1712edb6f2 100644
--- a/packages/views/test/setup.ts
+++ b/packages/views/test/setup.ts
@@ -19,50 +19,55 @@ function createMemoryStorage(): Storage {
};
}
-if (typeof globalThis.localStorage?.clear !== "function") {
- const storage = createMemoryStorage();
- Object.defineProperty(globalThis, "localStorage", {
- configurable: true,
- value: storage,
- });
- Object.defineProperty(window, "localStorage", {
- configurable: true,
- value: storage,
- });
-}
+// Everything below patches gaps in jsdom. Pure-logic suites opt out of jsdom
+// with `// @vitest-environment node` and share this file, so there is no DOM to
+// patch there — bail out rather than guard each stub.
+if (typeof window !== "undefined") {
+ if (typeof globalThis.localStorage?.clear !== "function") {
+ const storage = createMemoryStorage();
+ Object.defineProperty(globalThis, "localStorage", {
+ configurable: true,
+ value: storage,
+ });
+ Object.defineProperty(window, "localStorage", {
+ configurable: true,
+ value: storage,
+ });
+ }
-// jsdom doesn't provide matchMedia; useIsMobile() relies on it.
-if (typeof window.matchMedia !== "function") {
- window.matchMedia = (query: string) =>
- ({
- matches: false,
- media: query,
- onchange: null,
- addListener: () => {},
- removeListener: () => {},
- addEventListener: () => {},
- removeEventListener: () => {},
- dispatchEvent: () => false,
- }) as MediaQueryList;
-}
+ // jsdom doesn't provide matchMedia; useIsMobile() relies on it.
+ if (typeof window.matchMedia !== "function") {
+ window.matchMedia = (query: string) =>
+ ({
+ matches: false,
+ media: query,
+ onchange: null,
+ addListener: () => {},
+ removeListener: () => {},
+ addEventListener: () => {},
+ removeEventListener: () => {},
+ dispatchEvent: () => false,
+ }) as MediaQueryList;
+ }
-// jsdom doesn't provide ResizeObserver; stub it so components that rely on it
-// (e.g. input-otp) can render in tests.
-if (typeof globalThis.ResizeObserver === "undefined") {
- globalThis.ResizeObserver = class ResizeObserver {
- observe() {}
- unobserve() {}
- disconnect() {}
- } as unknown as typeof ResizeObserver;
-}
+ // jsdom doesn't provide ResizeObserver; stub it so components that rely on it
+ // (e.g. input-otp) can render in tests.
+ if (typeof globalThis.ResizeObserver === "undefined") {
+ globalThis.ResizeObserver = class ResizeObserver {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ } as unknown as typeof ResizeObserver;
+ }
-// jsdom doesn't implement elementFromPoint; input-otp uses it internally.
-if (typeof document.elementFromPoint !== "function") {
- document.elementFromPoint = () => null;
-}
+ // jsdom doesn't implement elementFromPoint; input-otp uses it internally.
+ if (typeof document.elementFromPoint !== "function") {
+ document.elementFromPoint = () => null;
+ }
-// jsdom has no layout, so it doesn't implement scrollIntoView; list components
-// that keep a keyboard cursor in view (e.g. the thread navigator) call it.
-if (typeof Element.prototype.scrollIntoView !== "function") {
- Element.prototype.scrollIntoView = () => {};
+ // jsdom has no layout, so it doesn't implement scrollIntoView; list components
+ // that keep a keyboard cursor in view (e.g. the thread navigator) call it.
+ if (typeof Element.prototype.scrollIntoView !== "function") {
+ Element.prototype.scrollIntoView = () => {};
+ }
}
diff --git a/packages/views/workspace/slug.test.ts b/packages/views/workspace/slug.test.ts
index 55e6cf4cb5..6aaa508493 100644
--- a/packages/views/workspace/slug.test.ts
+++ b/packages/views/workspace/slug.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { describe, it, expect } from "vitest";
import {
nameToWorkspaceSlug,