1import { buildNamespaceTree, flattenTree } from "@/Cli/NamespaceTree.ts";
2import { describe, expect, test } from "alchemy-test";
3import { createNode, replaceNode, updateNode } from "./PlanTestNodes.ts";
4
5describe("NamespaceTree YAML properties", { tags: ["unit", "local"] }, () => {
6 test("does not attach details in compact mode", () => {
7 const [item] = flattenTree(
8 buildNamespaceTree([
9 updateNode({ config: { retries: 2 } }, { config: { retries: 3 } }),
10 ]),
11 );
12 expect(item?.propertyYaml).toBeUndefined();
13 });
14
15 test("attaches safe structured YAML in detailed mode", () => {
16 const items = flattenTree(
17 buildNamespaceTree([
18 createNode({ config: { region: "iad" } }, "Api"),
19 updateNode({ retries: 2 }, { retries: 3 }, "Worker"),
20 ]),
21 { includePropertyYaml: true },
22 );
23 expect(
24 items.find((item) => item.id === "Api")?.propertyYaml?.lines,
25 ).toEqual(["properties:", " config:", " region: iad"]);
26 expect(
27 items.find((item) => item.id === "Worker")?.propertyYaml?.lines,
28 ).toEqual(["properties:", "- retries: 2", "+ retries: 3"]);
29 });
30
31 test("attaches drift details in compact mode", () => {
32 const node = updateNode({ value: "declared" }, { value: "declared" });
33 node.drift = {
34 expected: { value: "declared" },
35 actual: { value: "changed-out-of-band" },
36 };
37 const [item] = flattenTree(buildNamespaceTree([node]));
38 expect(item?.propertyYaml?.lines).toEqual([
39 "- value: declared",
40 "+ value: changed-out-of-band",
41 ]);
42 });
43
44 test("represents non-property replacement details honestly", () => {
45 const [item] = flattenTree(
46 buildNamespaceTree([replaceNode({ name: "same" }, { name: "same" })]),
47 { includePropertyYaml: true },
48 );
49 expect(item?.propertyYaml).toBeUndefined();
50 });
51});