File size: 3,431 Bytes
0c85e62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from __future__ import annotations

import subprocess
import textwrap
from pathlib import Path


REPO_ROOT = Path(__file__).resolve().parents[2]


def run_node_scenario(source: str) -> subprocess.CompletedProcess[str]:
    return subprocess.run(
        ["node", "--input-type=module"],
        input=source,
        cwd=REPO_ROOT,
        text=True,
        capture_output=True,
        check=False,
    )


def test_diff_picks_partitions_working_comparison_and_shared() -> None:
    proc = run_node_scenario(
        textwrap.dedent(
            """
            import assert from "node:assert/strict";
            import { diffPicks } from "./web/sidebar/snapshot_diff.js";

            const r = diffPicks(["x", "y"], ["y", "z"]);
            assert.deepEqual(r.onlyWorking, ["x"]);
            assert.deepEqual(r.onlyComparison, ["z"]);
            assert.deepEqual(r.shared, ["y"]);
            """
        )
    )
    assert proc.returncode == 0, proc.stderr


def test_diff_workflows_classifies_comparison_workflows_by_presence() -> None:
    proc = run_node_scenario(
        textwrap.dedent(
            """
            import assert from "node:assert/strict";
            import { diffWorkflows } from "./web/sidebar/snapshot_diff.js";

            const working = {
                directories: {
                    Basics: { workflows: { txt2img: { graph: { a: 1 } } }, directories: {} },
                },
            };
            const comparison = {
                directories: {
                    Basics: {
                        workflows: {
                            txt2img: { graph: { a: 1 } },
                            img2img: { graph: { b: 2 } },
                        },
                        directories: {},
                    },
                },
            };

            const status = diffWorkflows(working, comparison);
            // present only in the comparison -> green/new
            assert.equal(status["Basics/img2img"], "new");
            // present in both, identical graph -> plain/same
            assert.equal(status["Basics/txt2img"], "same");
            """
        )
    )
    assert proc.returncode == 0, proc.stderr


def test_diff_workflows_compares_graph_ignoring_saved_at_and_key_order() -> None:
    proc = run_node_scenario(
        textwrap.dedent(
            """
            import assert from "node:assert/strict";
            import { diffWorkflows } from "./web/sidebar/snapshot_diff.js";

            const working = { directories: { D: { workflows: {
                changed:   { graph: { nodes: [1, 2] }, savedAt: "2026-01-01T00:00:00Z" },
                unchanged: { graph: { a: 1, b: 2 },    savedAt: "2026-01-01T00:00:00Z" },
            }, directories: {} } } };
            const comparison = { directories: { D: { workflows: {
                changed:   { graph: { nodes: [1, 2, 3] }, savedAt: "2026-05-29T00:00:00Z" },
                unchanged: { graph: { b: 2, a: 1 },       savedAt: "2026-05-29T12:34:56Z" },
            }, directories: {} } } };

            const status = diffWorkflows(working, comparison);
            // graph content differs -> red/diff
            assert.equal(status["D/changed"], "diff");
            // only savedAt + key order differ -> plain/same (savedAt is volatile)
            assert.equal(status["D/unchanged"], "same");
            """
        )
    )
    assert proc.returncode == 0, proc.stderr