The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | |
| 3 | import { fxSubagentOutcome } from "./adapter.ts"; |
| 4 | |
| 5 | describe("fx subagent replies", () => { |
| 6 | it.each(["", "1", "12", "123"])("preserves literal Unicode spelling ending in u%s", (digits) => { |
| 7 | for (const slashes of [1, 2]) { |
| 8 | const suffix = "\\".repeat(slashes) + "u" + digits; |
| 9 | const padding = "x".repeat( |
| 10 | 200 - '{"ok":true,"result":"'.length - JSON.stringify(suffix).length + 2, |
| 11 | ); |
| 12 | const reply = padding + suffix + "4 more text"; |
| 13 | const whole = JSON.stringify({ ok: true, result: reply }); |
| 14 | expect(fxSubagentOutcome(whole)).toEqual({ ok: true, result: reply }); |
| 15 | expect(fxSubagentOutcome(Buffer.from(whole).subarray(0, 200).toString("utf8"))).toEqual({ |
| 16 | ok: true, |
| 17 | result: padding + suffix + "…", |
| 18 | }); |
| 19 | } |
| 20 | }); |
| 21 | |
| 22 | it.each([0, 1, 2])( |
| 23 | "recovers incomplete Unicode escapes after %i literal backslashes", |
| 24 | (slashes) => { |
| 25 | for (const digits of ["", "0", "00", "000"]) { |
| 26 | const prefix = "reply" + "\\".repeat(slashes * 2); |
| 27 | expect(fxSubagentOutcome('{"ok":true,"result":"' + prefix + "\\u" + digits)).toEqual({ |
| 28 | ok: true, |
| 29 | result: "reply" + "\\".repeat(slashes) + "…", |
| 30 | }); |
| 31 | } |
| 32 | }, |
| 33 | ); |
| 34 | |
| 35 | it.each([ |
| 36 | ['{"ok":true,"result":"hello', { ok: true, result: "hello…" }], |
| 37 | ['{"ok":false,"result":null}', { ok: false, result: null }], |
| 38 | ['{"ok":true,"result":"hello"', { ok: true, result: "hello" }], |
| 39 | ['{"unexpected":"body"}', undefined], |
| 40 | ['{"ok":true,"result":"\\q', { ok: true, result: null }], |
| 41 | ])("retains existing normalization for %s", (text, expected) => { |
| 42 | expect(fxSubagentOutcome(text)).toEqual(expected); |
| 43 | }); |
| 44 | }); |