Something went wrong. Try again.
A local-first event pipeline for independent agents, built on Jazz.
Something went wrong. Try again.
2.2 kB · 46 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import { spawn } from "node:child_process";import fs from "node:fs/promises";import path from "node:path";import { afterEach, describe, expect, test } from "vitest";import { temporaryProject, testDeclarationEnvironment } from "./helpers.js";
const roots: string[] = [];
afterEach(async () => { await Promise.all(roots.splice(0).map((root) => fs.rm(root, { recursive: true, force: true })));});
describe("thought stream independent consumer command", () => { test("processes a durable producer backlog without producer handoff", async () => { const project = await temporaryProject(); roots.push(project); await fs.cp(path.join(process.cwd(), "agents"), path.join(project, "agents"), { recursive: true }); await fs.cp(path.join(process.cwd(), "prompts"), path.join(project, "prompts"), { recursive: true }); await fs.cp(path.join(process.cwd(), "fixtures", "vault"), path.join(project, "vault"), { recursive: true });
const scan = await run(["scan", "--root", path.join(project, "vault"), "--source", "filesystem:fixture"], project); expect(scan.code).toBe(0); expect(JSON.parse(scan.stdout)).toEqual({ scan: expect.objectContaining({ added: 3 }) });
const consume = await run(["consume", "--once"], project); expect(consume.code).toBe(0); const output = JSON.parse(consume.stdout) as { runs: Array<{ runId: string }> }; expect(output.runs).toHaveLength(3); }, 15_000);});
async function run(args: string[], project: string): Promise<{ code: number | null; stdout: string; stderr: string }> { return await new Promise((resolve, reject) => { const child = spawn(process.execPath, ["--import", "tsx", "src/cli.ts", ...args], { cwd: path.resolve(import.meta.dirname, ".."), env: { ...process.env, ...testDeclarationEnvironment, THOUGHTSTREAM_ROOT: project }, stdio: ["ignore", "pipe", "pipe"], }); let stdout = ""; let stderr = ""; child.stdout.on("data", (chunk) => { stdout += String(chunk); }); child.stderr.on("data", (chunk) => { stderr += String(chunk); }); child.once("error", reject); child.once("exit", (code) => resolve({ code, stdout, stderr })); });}