Something went wrong. Try again.
A local-first event pipeline for independent agents, built on Jazz.
Something went wrong. Try again.
2.6 kB · 67 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768import { spawn } from "node:child_process";import fs from "node:fs/promises";import http from "node:http";import path from "node:path";import { afterEach, describe, expect, test } from "vitest";import { temporaryProject } from "./helpers.js";
const roots: string[] = [];const servers: http.Server[] = [];
afterEach(async () => { await Promise.all(servers.splice(0).map((server) => new Promise<void>((resolve) => { server.closeAllConnections(); server.close(() => resolve()); }))); await Promise.all(roots.splice(0).map((root) => fs.rm(root, { recursive: true, force: true })));});
describe("thought stream rss command", () => { test("runs one explicit local poll, prints receipts, and exits", async () => { const body = await fs.readFile(path.join(process.cwd(), "fixtures", "rss", "feed.xml"), "utf8"); const server = http.createServer((_request, response) => { response.writeHead(200, { "content-type": "application/rss+xml", etag: '"cli-v1"' }); response.end(body); }); servers.push(server); await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve)); const address = server.address(); if (!address || typeof address === "string") throw new Error("Missing RSS CLI fixture server address"); const project = await temporaryProject(); roots.push(project); const result = await run([ "--silent", "thought", "stream", "rss", "--url", `http://127.0.0.1:${address.port}/feed.xml`, "--source", "rss:cli-fixture", ], { THOUGHTSTREAM_ROOT: project });
expect(result.code).toBe(0); expect(result.stderr).toBe(""); const output = JSON.parse(result.stdout) as { poll: { status: string; inserted: number; events: unknown[] }; }; expect(output.poll).toMatchObject({ status: "updated", inserted: 2 }); expect(output.poll.events).toHaveLength(2); }, 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 })); });}