Files
fusion/packages/cli/src/__tests__/dev-with-memory-lib.test.ts
gsxdsm 538bf42e32 fix(dev): rebuild core+engine+dashboard on dev/local startup + stale-dist check
pnpm dev/local dashboard prebuild now rebuilds @fusion/core and @fusion/engine alongside the dashboard UI (was client-only), and startup warns loudly when built dist/ is older than src/. Prevents the FN-6638 class where landed engine fixes silently never run because the process loads stale dist.
2026-06-18 13:41:37 -07:00

105 lines
3.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
buildForwardedDevArgs,
buildDevNodeArgs,
getPrebuildCommand,
normalizePrebuildMode,
parseDevWrapperArgs,
resolvePrebuildMode,
} from "../../../../scripts/dev-with-memory-lib.mjs";
describe("buildDevNodeArgs", () => {
it("enables source-condition resolution before loading the tsx runtime", () => {
const args = buildDevNodeArgs({
inspectFlags: ["--inspect=9230"],
preload: "/tmp/preflight.cjs",
loader: "/tmp/loader.mjs",
entry: "/tmp/bin.ts",
args: ["dashboard", "--host", "0.0.0.0"],
});
expect(args).toEqual([
"--inspect=9230",
"--conditions=source",
"--require",
"/tmp/preflight.cjs",
"--import",
"file:///tmp/loader.mjs",
"/tmp/bin.ts",
"dashboard",
"--host",
"0.0.0.0",
]);
});
});
describe("dev-with-memory prebuild options", () => {
it("strips wrapper-only prebuild and inspector flags before forwarding CLI args", () => {
const parsed = parseDevWrapperArgs(
["--inspect=9230", "--prebuild=none", "dashboard", "--port", "4050"],
{},
);
expect(parsed).toEqual({
inspectFlags: ["--inspect=9230"],
args: ["dashboard", "--port", "4050"],
requestedPrebuild: "none",
});
});
it("rejects explicit empty prebuild modes", () => {
expect(() => normalizePrebuildMode("")).toThrow(/Invalid prebuild mode/);
expect(() => parseDevWrapperArgs(["--prebuild=", "dashboard"], {})).toThrow(/Invalid prebuild mode/);
});
it("does not inject a dev host when --host=value is already present", () => {
expect(buildForwardedDevArgs(["dashboard", "--host=127.0.0.1"])).toEqual([
"dashboard",
"--host=127.0.0.1",
]);
});
it("injects a LAN-reachable dev host for dashboard startup without a host override", () => {
expect(buildForwardedDevArgs(["dashboard", "--port", "4050"])).toEqual([
"dashboard",
"--port",
"4050",
"--host",
"0.0.0.0",
]);
});
it("rebuilds core + engine + dashboard (UI) for dashboard startup, not the full workspace", () => {
// FN-6638/stale-dist: dev dashboard must refresh engine + core dist (not
// just the client bundle) so landed fixes are not silently stale.
expect(resolvePrebuildMode("auto", ["dashboard", "--port", "4050"])).toBe("client");
expect(getPrebuildCommand("client")).toEqual({
command: "pnpm",
args: [
"--filter",
"@fusion/core",
"--filter",
"@fusion/engine",
"--filter",
"@fusion/dashboard",
"build",
],
label: "core + engine + dashboard build",
});
});
it("skips prebuild by default for non-dashboard CLI commands", () => {
expect(resolvePrebuildMode("auto", ["task", "list"])).toBe("none");
expect(getPrebuildCommand("none")).toBeNull();
});
it("keeps full workspace prebuild available when requested", () => {
expect(resolvePrebuildMode("full", ["dashboard"])).toBe("full");
expect(getPrebuildCommand("full")).toEqual({
command: "pnpm",
args: ["build"],
label: "workspace build",
});
});
});