Files
fusion/packages/cli/src/plugin-sdk-core-runtime-shim.mjs
Phil Larson 5d8d494230 fix(todos): restore clean build and navigation coverage (#3321)
## Summary
- remove an unavailable jest-dom type from the Todo plugin production
TypeScript build
- update the dashboard navigation fixture for the plugin-owned Todo
destination and root test id

## Test plan
- `corepack pnpm --filter @fusion-plugin-examples/todos build`
- `corepack pnpm --filter @fusion-plugin-examples/todos test`
- `FUSION_DASHBOARD_DEEP=1 corepack pnpm --filter @fusion/dashboard exec
vitest run app/components/__tests__/navigation-history.test.tsx
--project dashboard-app-quality-components-a --silent=passed-only
--reporter=dot`
- `corepack pnpm check:changesets`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
  * Restored CLI packaging for the bundled Todo Lists plugin.
  * Made `AgentStore` available to bundled plugins at runtime.
* **Tests**
* Updated navigation coverage for Todo Lists dashboard views, overflow
placement, and ordering.
* Added coverage for opening and dismissing the Todo view through
browser history navigation.
  * Improved validation of runtime exports.
* **Chores**
  * Simplified test type configuration for the Todo Lists plugin.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-03 12:14:31 -07:00

134 lines
4.7 KiB
JavaScript

import { spawn } from "node:child_process";
/*
* FNXC:BundledPlugins 2026-07-15-13:40:
* Clean CI typechecks the CLI before @fusion/core emits dist, but published
* bundled plugins need both postgresSchema runtime values and Quality's
* process-group supervisor. Keep this alias implementation in untyped MJS so
* tsc stays inside the CLI root while esbuild follows the core source schema
* and bundles every runtime export without a private @fusion/core dependency.
*/
import * as postgresSchema from "../../core/src/postgres/schema/index.js";
import { AgentStore } from "../../core/src/agents/agent-store.js";
/*
* FNXC:BundledPlugins 2026-08-03-17:18:
* The bundled Todo plugin lists project agents through AgentStore. Re-export the source implementation from the runtime shim so clean CLI packaging does not leave a private @fusion/core runtime import unresolved.
*/
export { AgentStore, postgresSchema };
/*
* FNXC:BundledPlugins 2026-07-31-09:55:
* Lifecycle ROLE resolution, re-exported for bundled plugins.
*
* A plugin that asks "is this card in a terminal lane?" must resolve the board's roles rather than
* compare against `done`/`archived`, or it stalls forever on a renamed board. That is what the
* compound-engineering reconciler now does — but this shim is what `@fusion/core` resolves to inside
* the bundled build, so an import it does not re-export is a hard esbuild failure ("No matching
* export"), not a runtime fallback. The plugin built fine in the workspace and broke only in the CLI
* bundle.
*
* Source paths, not the package barrel, for the reason above: esbuild follows core's source here and
* the CLI must not take a private @fusion/core dependency.
*/
import {
columnsWithFlag,
resolveReviewColumns,
} from "../../core/src/workflows/workflow-lifecycle-traits.js";
import { resolveWorkflowIrForTask } from "../../core/src/workflows/workflow-ir-resolver.js";
export { columnsWithFlag, resolveReviewColumns, resolveWorkflowIrForTask };
export const FUSION_RESTART_EXIT_CODE = 86;
export function superviseSpawn(command, args = [], options = {}) {
const killGraceMs = options.killGraceMs ?? 2_000;
const maxLifetimeMs = options.maxLifetimeMs;
const spawnOptions = { ...options };
delete spawnOptions.killGraceMs;
delete spawnOptions.maxLifetimeMs;
const processGroup = globalThis.process.platform !== "win32";
const child = spawn(command, [...args], { ...spawnOptions, detached: processGroup });
const pgid = processGroup && typeof child.pid === "number" ? child.pid : null;
let settled = false;
let resolveExit;
const waitExit = new Promise((resolve) => {
resolveExit = resolve;
});
const killProcess = (signal = "SIGTERM") => {
if (typeof child.pid !== "number") return;
try {
if (pgid != null) globalThis.process.kill(-pgid, signal);
else child.kill(signal);
} catch {
try {
child.kill(signal);
} catch {
// FNXC:Quality 2026-07-15-13:40: A concurrently exited child needs no further cancellation action.
}
}
};
let lifetimeTimer = null;
if (typeof maxLifetimeMs === "number" && Number.isFinite(maxLifetimeMs) && maxLifetimeMs > 0) {
lifetimeTimer = globalThis.setTimeout(() => {
if (settled) return;
killProcess("SIGTERM");
const escalationTimer = globalThis.setTimeout(() => {
if (!settled) killProcess("SIGKILL");
}, killGraceMs);
escalationTimer.unref?.();
}, maxLifetimeMs);
lifetimeTimer.unref?.();
}
child.once("close", (code, signal) => {
settled = true;
if (lifetimeTimer) globalThis.clearTimeout(lifetimeTimer);
resolveExit?.({ code, signal });
});
// FNXC:Quality 2026-07-15-13:40: Spawn failures must not crash a bundled plugin; close settles waitExit.
child.on("error", () => {});
return {
pid: child.pid,
pgid,
child,
kill(signal = "SIGTERM") {
if (settled) return;
killProcess(signal);
if (signal === "SIGTERM") {
const escalationTimer = globalThis.setTimeout(() => {
if (!settled) killProcess("SIGKILL");
}, killGraceMs);
escalationTimer.unref?.();
}
},
waitExit() {
return waitExit;
},
};
}
export const ProcessSupervisor = { superviseSpawn };
export const WORKFLOW_EXTENSION_SCHEMA_VERSION = 1;
export function workflowExtensionRegistryId(pluginId, extensionId) {
return `plugin:${pluginId}:${extensionId}`;
}
export function createBoardActionServices(store) {
return {
moveTask(input) {
return store.moveTask(input.taskId, input.column, {
preserveProgress: input.preserveProgress,
moveSource: input.source ?? "user",
});
},
updateTask(input) {
return store.updateTask(input.taskId, input.updates);
},
};
}