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
| 1 | import { describe, expect, test } from "@alchemy.run/test"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Redacted from "effect/Redacted"; |
| 4 | import { |
| 5 | formatDeclaredPropertyYaml, |
| 6 | formatDriftPropertyYaml, |
| 7 | formatYamlLines, |
| 8 | } from "@/Cli/PropertyDiff.ts"; |
| 9 | import * as Output from "@/Output.ts"; |
| 10 | |
| 11 | describe("YAML property display", { tags: ["unit", "local"] }, () => { |
| 12 | test("preserves nested create properties", () => { |
| 13 | expect( |
| 14 | formatDeclaredPropertyYaml({}, { config: { ports: [80, 443], region: "iad" } }, "create") |
| 15 | ?.lines, |
| 16 | ).toEqual([ |
| 17 | "properties:", |
| 18 | " config:", |
| 19 | " ports:", |
| 20 | " - 80", |
| 21 | " - 443", |
| 22 | " region: iad", |
| 23 | ]); |
| 24 | }); |
| 25 | |
| 26 | test("shows contextual git-style YAML for updates", () => { |
| 27 | expect( |
| 28 | formatDeclaredPropertyYaml( |
| 29 | { id: "same", config: { enabled: true, retries: 2 } }, |
| 30 | { id: "same", config: { enabled: true, retries: 3 } }, |
| 31 | "update", |
| 32 | )?.lines, |
| 33 | ).toEqual([ |
| 34 | "properties:", |
| 35 | " config:", |
| 36 | " enabled: true", |
| 37 | "- retries: 2", |
| 38 | "+ retries: 3", |
| 39 | " id: same", |
| 40 | ]); |
| 41 | }); |
| 42 | |
| 43 | test("does not invent property changes", () => { |
| 44 | expect( |
| 45 | formatDeclaredPropertyYaml({ name: "same" }, { name: "same" }, "replace"), |
| 46 | ).toBeUndefined(); |
| 47 | }); |
| 48 | |
| 49 | test("shows only changed drift attributes", () => { |
| 50 | expect( |
| 51 | formatDriftPropertyYaml( |
| 52 | { id: "same", config: { enabled: true, retries: 2 } }, |
| 53 | { id: "same", config: { enabled: true, retries: 5 } }, |
| 54 | ).lines, |
| 55 | ).toEqual(["config:", " enabled: true", "- retries: 2", "+ retries: 5", "id: same"]); |
| 56 | }); |
| 57 | |
| 58 | test("identifies resources missing from the cloud", () => { |
| 59 | expect(formatDriftPropertyYaml({ id: "expected" }, undefined, true).lines).toEqual([ |
| 60 | "- id: expected", |
| 61 | "+ (missing)", |
| 62 | ]); |
| 63 | }); |
| 64 | |
| 65 | test("never evaluates or reveals deferred and secret values", () => { |
| 66 | let evaluated = false; |
| 67 | const lines = formatYamlLines({ |
| 68 | output: Output.fromEffect( |
| 69 | Effect.sync(() => { |
| 70 | evaluated = true; |
| 71 | return "resolved"; |
| 72 | }), |
| 73 | ), |
| 74 | secret: Redacted.make("super-secret"), |
| 75 | task: Effect.sync(() => "computed"), |
| 76 | }).join("\n"); |
| 77 | expect(evaluated).toBe(false); |
| 78 | expect(lines).toContain("output: (known after apply)"); |
| 79 | expect(lines).toContain("secret: (redacted)"); |
| 80 | expect(lines).toContain("task: (computed)"); |
| 81 | expect(lines).not.toContain("super-secret"); |
| 82 | expect(lines).not.toContain("resolved"); |
| 83 | }); |
| 84 | |
| 85 | test("shows a secret change without exposing either value", () => { |
| 86 | const lines = formatDeclaredPropertyYaml( |
| 87 | { token: Redacted.make("old-secret") }, |
| 88 | { token: Redacted.make("new-secret") }, |
| 89 | "update", |
| 90 | )?.lines.join("\n"); |
| 91 | expect(lines).toContain("properties:\n token: (redacted)"); |
| 92 | expect(lines).not.toContain("old-secret"); |
| 93 | expect(lines).not.toContain("new-secret"); |
| 94 | }); |
| 95 | |
| 96 | test("handles bigint and cycles", () => { |
| 97 | const value: Record<string, unknown> = { size: 2n }; |
| 98 | value.self = value; |
| 99 | expect(formatYamlLines(value)).toEqual(["self: (circular)", "size: 2n"]); |
| 100 | }); |
| 101 | }); |