Something went wrong. Try again.
A local-first event pipeline for independent agents, built on Jazz.
Something went wrong. Try again.
1.9 kB · 54 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import { 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 } 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 fastmail-capture command", () => { test("ingests one explicit synthetic JMAP capture and exits", async () => { const project = await temporaryProject(); roots.push(project); const result = await run([ "--silent", "thought", "stream", "fastmail-capture", "--file", path.join(process.cwd(), "fixtures", "fastmail", "changes.json"), "--source", "fastmail:cli-fixture", "--account-id", "account-fixture", ], { THOUGHTSTREAM_ROOT: project });
expect(result.code).toBe(0); expect(result.stderr).toBe(""); const output = JSON.parse(result.stdout) as { ingest: { inserted: number; created: number; updated: number; destroyed: number; events: unknown[] }; }; expect(output.ingest).toMatchObject({ inserted: 3, created: 1, updated: 1, destroyed: 1 }); expect(output.ingest.events).toHaveLength(3); }, 10_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 })); });}