Files
fusion/packages/dashboard/app/test/cssFixture.ts
gsxdsm 2a2b157cb9 FN-8585: fix dashboard composer test source reads
Stabilize dashboard composer tests when Vitest launches from the workspace root.

- Resolve dashboard test source fixtures relative to the app directory.
- Migrate affected component tests away from cwd-relative CSS reads.
- Enforce the fixture convention in test hooks and document it.

Files changed:
 docs/testing.md                                    |  4 +++
 package.json                                       |  6 ++--
 .../__tests__/AuthTokenRecoveryDialog.test.tsx     |  3 +-
 .../components/__tests__/ChatView.mobile.test.tsx  |  5 +--
 .../__tests__/EngineControlMenu.test.tsx           | 11 ++----
 .../components/__tests__/FloatingWindow.test.tsx   |  5 +--
 .../app/components/__tests__/ListView.test.tsx     |  5 +--
 .../__tests__/MissionInterviewModal.test.tsx       |  3 +-
 .../app/components/__tests__/MobileNavBar.test.tsx |  3 +-
 .../app/components/__tests__/NewTaskModal.test.tsx |  3 +-
 .../__tests__/PlanningModeModal.initial.test.tsx   |  3 +-
 .../PlanningModeModal.ui-interactions.test.tsx     |  7 ++--
 .../components/__tests__/PrCreateModal.test.tsx    |  3 +-
 .../__tests__/QuickChat.persist.test.tsx           |  3 +-
 .../components/__tests__/QuickEntryBox.test.tsx    |  3 +-
 .../components/__tests__/ReportActionMenu.test.tsx |  9 ++---
 .../app/components/__tests__/ReportModal.test.tsx  |  3 +-
 .../__tests__/ShadcnColorPicker.test.tsx           |  3 +-
 .../components/__tests__/TerminalModal.test.tsx    |  3 +-
 .../components/__tests__/ThemeDropdown.test.tsx    |  9 ++---
 .../__tests__/WorkflowNodeEditor.test.tsx          |  5 +--
 .../WorkflowOptionalStepsDropdown.test.tsx         |  3 +-
 .../components/__tests__/WorkflowSwitcher.test.tsx |  5 +--
 .../app/components/__tests__/board-mobile.test.tsx |  4 +--
 .../__tests__/CommandCenterControls.test.tsx       |  6 ++--
 .../__tests__/SystemControlsArea.test.tsx          |  5 +--
 .../__tests__/SystemStatsArea.test.tsx             |  3 +-
 .../command-center/areas/__tests__/areas.test.tsx  |  3 +-
 .../__tests__/KeyboardShortcutsSection.test.tsx    |  3 +-
 .../app/test/__tests__/cssFixture.test.ts          | 35 +++++++++++++++++++
 packages/dashboard/app/test/cssFixture.ts          | 12 +++++++
 .../check-no-cwd-relative-dashboard-test-reads.mjs | 39 ++++++++++++++++++++++
 32 files changed, 162 insertions(+), 55 deletions(-)

Fusion-Task-Id: FN-8585

Fusion-Task-Lineage: 83a35fb6-a29d-4e97-b282-1054c68b8cc9

Co-authored-by: Fusion (runfusion.ai) <noreply@runfusion.ai>
2026-07-25 06:22:23 -07:00

87 lines
3.1 KiB
TypeScript

import { readFileSync, readdirSync } from "node:fs";
import { join, resolve } from "node:path";
const APP_DIR = resolve(__dirname, "..");
const COMPONENTS_DIR = join(APP_DIR, "components");
/**
* FNXC:DashboardTests 2026-07-26-06:10:
* Dashboard test source reads MUST resolve from this module-relative app directory. Cwd-relative reads hard-crash an entire Vitest suite at import time under root-anchored invocations with ENOENT for paths such as app/components/QuickEntryBox.css.
*/
export function readAppFile(appRelativePath: string): string {
return readFileSync(resolve(APP_DIR, appRelativePath), "utf-8");
}
export function loadComponentCss(name: string): string {
return readAppFile(join("components", name));
}
let cached: string | null = null;
let stylesCached: string | null = null;
let themeDataCached: string | null = null;
let baseOnlyCached: string | null = null;
export function loadStylesCss(): string {
if (stylesCached !== null) return stylesCached;
stylesCached = readFileSync(join(APP_DIR, "styles.css"), "utf-8");
return stylesCached;
}
export function loadThemeDataCss(): string {
if (themeDataCached !== null) return themeDataCached;
themeDataCached = readFileSync(join(APP_DIR, "public", "theme-data.css"), "utf-8");
return themeDataCached;
}
export function loadAllAppCss(): string {
if (cached !== null) return cached;
// styles.css first (preserves all section-marker positions for legacy slice
// tests), then component CSS files in alphabetical order. This keeps both
// styles.css's intra-file order intact AND lets co-located component base
// rules be matched before any cross-file @media override referencing them.
// NOTE: public/theme-data.css is intentionally excluded here; tests that
// validate per-color-theme contracts should load it explicitly.
const parts: string[] = [loadStylesCss()];
const entries = readdirSync(COMPONENTS_DIR, { withFileTypes: true })
.filter((e) => e.isFile() && e.name.endsWith(".css"))
.map((e) => e.name)
.sort();
for (const name of entries) {
parts.push(readFileSync(join(COMPONENTS_DIR, name), "utf-8"));
}
cached = parts.join("\n");
return cached;
}
/**
* Returns the combined CSS with all @media (and other at-rule) blocks
* stripped out. Useful for tests that need to match a selector's BASE rule
* (top-level, not inside a media query) and want to avoid false matches
* against @media overrides that happen to come earlier in the source order.
*/
export function loadAllAppCssBaseOnly(): string {
if (baseOnlyCached !== null) return baseOnlyCached;
const src = loadAllAppCss();
// Walk and excise any top-level @<rule> { ... } block (e.g. @media, @supports)
let out = "";
let i = 0;
while (i < src.length) {
if (src[i] === "@") {
const open = src.indexOf("{", i);
if (open === -1) { out += src.slice(i); break; }
let depth = 1;
let j = open + 1;
while (j < src.length && depth > 0) {
if (src[j] === "{") depth++;
else if (src[j] === "}") depth--;
j++;
}
i = j;
continue;
}
out += src[i++];
}
baseOnlyCached = out;
return baseOnlyCached;
}