fix: IPC trigger try/catch + test import cleanup #32

Merged
xiaomo merged 1 commits from fix/phase4-followup into main 2026-04-22 14:16:11 +00:00
3 changed files with 11 additions and 31 deletions
@@ -9,33 +9,7 @@ import { mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
// Inline the template builder (same logic as in init.ts) for isolated testing
function buildWorkflowTemplate(name: string): string {
return `import type { WorkflowDefinition } from "@uncaged/nerve-daemon";
const workflow: WorkflowDefinition = {
roles: {
main: {
async execute(prompt, ctx) {
ctx.log("${name} started");
// TODO: implement your role logic here
return { type: "done" };
},
},
},
moderate(thread, event) {
if (event.type === "thread_start") {
return { role: "main", prompt: {} };
}
return null; // workflow complete
},
};
export default workflow;
`;
}
import { buildWorkflowTemplate } from "../commands/init.js";
let tmpDir: string;
+1 -1
View File
@@ -124,7 +124,7 @@ export function validateWorkflowName(name: string): string | null {
return null;
}
function buildWorkflowTemplate(name: string): string {
export function buildWorkflowTemplate(name: string): string {
return `import type { WorkflowDefinition } from "@uncaged/nerve-daemon";
const workflow: WorkflowDefinition = {
+9 -3
View File
@@ -64,9 +64,15 @@ export function createDaemonIpcServer(
return;
}
workflowManager.startWorkflow(req.workflow, req.payload);
const resp: DaemonResponse = { ok: true };
socket.write(`${JSON.stringify(resp)}\n`);
try {
workflowManager.startWorkflow(req.workflow, req.payload);
const resp: DaemonResponse = { ok: true };
socket.write(`${JSON.stringify(resp)}\n`);
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
const resp: DaemonResponse = { ok: false, error: msg };
socket.write(`${JSON.stringify(resp)}\n`);
}
}
const server: Server = createServer((socket) => {