import { afterEach, expect, test } from "bun:test"; import { createHash } from "node:crypto"; import { eddyHandoffSection, handoffDelivery, withEddyHandoffSection } from "../src/eddy_handoff_delivery"; const previous = process.env.EDDY_HANDOFF_AGENT_BASE_URL; afterEach(() => { if (previous === undefined) delete process.env.EDDY_HANDOFF_AGENT_BASE_URL; else process.env.EDDY_HANDOFF_AGENT_BASE_URL = previous; }); test("worker instructions use the intranet API, with the digest of the actual bundle", () => { delete process.env.EDDY_HANDOFF_AGENT_BASE_URL; const bytes = Buffer.from("PK handoff contents"); const text = handoffDelivery("handoff-id", bytes.toString("base64")).join("\n"); expect(text).toContain("https://streamline-internal-api.bytedance.net/api/eddy/handoffs/handoff-id/zip"); expect(text).not.toContain("https://streamline.bytedance.net/api/"); expect(text).toContain(createHash("sha256").update(bytes).digest("hex")); expect(text).toContain("完整实现文件"); expect(text).toContain("若返回 HTML"); }); test("a local deployment can override the machine API without changing human links", () => { process.env.EDDY_HANDOFF_AGENT_BASE_URL = "http://127.0.0.1:18899/"; const text = handoffDelivery("a/b").join("\n"); expect(text).toContain("http://127.0.0.1:18899/api/eddy/handoffs/a%2Fb/zip"); expect(text).not.toContain("SHA256"); }); test("a feature with no handoff gets its prompt bodies back unchanged", () => { const bodies = { evalPromptTemplate: "eval {{title}}", regenPromptTemplate: null }; expect(withEddyHandoffSection(bodies, null)).toBe(bodies); }); test("a handoff feature's prompts fetch the bundle once per node and carry the fidelity rules", () => { delete process.env.EDDY_HANDOFF_AGENT_BASE_URL; const out = withEddyHandoffSection( { "feature.run.first": "run {{workspaceDir}}\n", "feature.run.second": "again", empty: null }, { id: "9ecf45a9-0000-4000-8000-000000000000", task: "camera-open-blur", baseline: "tiktokm-47.4.0" }, ); expect(out.empty).toBeNull(); for (const t of [out["feature.run.first"]!, out["feature.run.second"]!]) { expect(t).toContain("## Eddy 原型接力"); expect(t).toContain("`camera-open-blur`"); expect(t).toContain('curl -fsS -m 300 -o "$H.zip" "https://streamline-internal-api.bytedance.net/api/eddy/handoffs/9ecf45a9-0000-4000-8000-000000000000/zip"'); expect(t).toContain('ls "$H"/*/START_HERE.md >/dev/null 2>&1 ||'); expect(t).toContain("与 Eddy 原型的差异"); } expect(out["feature.run.first"]!.startsWith("run {{workspaceDir}}\n\n## Eddy 原型接力")).toBe(true); // The satellite fills {{…}} placeholders; the section must not add any of its own. expect(eddyHandoffSection({ id: "x", task: null, baseline: null })).not.toContain("{{"); });