@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 68 lines 2.66 KB
Raw
1 import { describe, expect, it } from "@alchemy.run/test";
2 import * as Redacted from "effect/Redacted";
3 import { packEnvValue, packEnvValueKeepRedacted, unpackEnvValue } from "@/RuntimeContext.ts";
4
5 describe("packEnvValue / unpackEnvValue", { tags: ["unit", "local"] }, () => {
6 it("stores a plain string verbatim (no quote characters on the wire)", () => {
7 // #1243: a queue name must reach the env binding bare so raw readers
8 // (dashboard, MessageBatch.queue comparisons) see the real name.
9 expect(packEnvValue("my-queue")).toBe("my-queue");
10 expect(packEnvValue("https://example.com/a?b=c")).toBe("https://example.com/a?b=c");
11 });
12
13 it("keeps ambiguous strings packed so the read side can't reinterpret them", () => {
14 // These would JSON.parse into a different value if stored bare.
15 for (const s of ["123", "-4.5", "null", "true", '"quoted"', '{"a":1}', "[1]"]) {
16 expect(packEnvValue(s)).toBe(JSON.stringify(s));
17 expect(unpackEnvValue(packEnvValue(s))).toBe(s);
18 }
19 });
20
21 it("round-trips every string exactly", () => {
22 for (const s of [
23 "my-queue",
24 "",
25 " ",
26 "123",
27 "null",
28 "Infinity",
29 '"unterminated',
30 "{not json",
31 "line\nbreak",
32 ]) {
33 expect(unpackEnvValue(packEnvValue(s))).toBe(s);
34 }
35 });
36
37 it("round-trips non-string JSON values", () => {
38 expect(unpackEnvValue(packEnvValue(8080))).toBe(8080);
39 expect(unpackEnvValue(packEnvValue(true))).toBe(true);
40 expect(unpackEnvValue(packEnvValue({ a: [1, "x"] }))).toEqual({
41 a: [1, "x"],
42 });
43 });
44
45 it("round-trips Redacted through the marker", () => {
46 const out = unpackEnvValue<Redacted.Redacted<string>>(packEnvValue(Redacted.make("s3cret")));
47 expect(Redacted.isRedacted(out)).toBe(true);
48 expect(Redacted.value(out!)).toBe("s3cret");
49 });
50
51 it("packEnvValueKeepRedacted keeps the wrapper outside the packed string", () => {
52 const packed = packEnvValueKeepRedacted(Redacted.make("s3cret"));
53 expect(Redacted.isRedacted(packed)).toBe(true);
54 const inner = Redacted.value(packed as Redacted.Redacted<string>);
55 const out = unpackEnvValue<Redacted.Redacted<string>>(inner);
56 expect(Redacted.isRedacted(out)).toBe(true);
57 expect(Redacted.value(out!)).toBe("s3cret");
58 // Non-Redacted values stay plain strings.
59 expect(packEnvValueKeepRedacted("my-queue")).toBe("my-queue");
60 });
61
62 it("unpackEnvValue passes through raw env vars a user set directly", () => {
63 expect(unpackEnvValue("my-queue")).toBe("my-queue");
64 expect(unpackEnvValue(undefined)).toBeUndefined();
65 // A user-set raw numeric env var still parses — unchanged behavior.
66 expect(unpackEnvValue("123")).toBe(123);
67 });
68 });