Something went wrong. Try again.
A local-first event pipeline for independent agents, built on Jazz.
Something went wrong. Try again.
2.9 kB · 81 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182import { spawn } from "node:child_process";import fs from "node:fs/promises";import path from "node:path";import { afterEach, describe, expect, test } from "vitest";import type { JazzThoughtStore } from "../src/jazz/store.js";import { temporaryProject, testStore } from "./helpers.js";
const SECRET = "PRIVATE_INCIDENT_CLI_SOURCE_SENTINEL";const roots: string[] = [];const stores: JazzThoughtStore[] = [];
afterEach(async () => { for (const store of stores.splice(0)) await store.close(); for (const root of roots.splice(0)) await fs.rm(root, { recursive: true, force: true });});
describe("thought stream incidents command", () => { test("projects existing failure evidence into the private ledger and exits", async () => { const project = await temporaryProject("thoughtstream-incidents-cli-"); roots.push(project); const store = await testStore(project); stores.push(store); await store.appendEvent({ type: "stream.thought.connector.failed", schemaVersion: 1, source: "jetstream:fixture", sourceKind: "jetstream", externalId: "connector-failure", idempotencyKey: "connector-failure", occurredAt: "2026-07-22T01:00:00.000Z", actor: "jetstream:fixture", correlationId: "connector-failure", privacy: "public-source", payload: { status: "failed", phase: "live-subscribe", error: SECRET }, }); await store.close(); stores.splice(stores.indexOf(store), 1); await fs.writeFile(path.join(project, "thoughtstream.yaml"), [ "version: 1", "incidents:", " enabled: true", " ledgerPath: .thoughtstream/error-ledger.jsonl", " intervalMs: 1000", "sources: []", "", ].join("\n"));
const result = await run([ "--silent", "thought", "stream", "incidents", "--config", "thoughtstream.yaml", "--once", ], { THOUGHTSTREAM_ROOT: project });
expect(result.code).toBe(0); expect(result.stderr).toBe(""); expect(result.stdout).toContain('"incidentService"'); const ledger = await fs.readFile(path.join(project, ".thoughtstream", "error-ledger.jsonl"), "utf8"); expect(ledger).toContain('"category":"connector-failure"'); expect(ledger).not.toContain(SECRET); }, 15_000);});
async function run(args: string[], extraEnv: Record<string, string>): Promise<{ code: number | null; stdout: string; stderr: string }> { return new Promise((resolve, reject) => { const child = spawn("pnpm", args, { cwd: process.cwd(), env: { ...process.env, ...extraEnv }, 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 })); });}