blob: 9152f893a03d2abd4615c9d5a77687c279bbf3ae (
plain)
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
100
101
102
103
104
105
106
|
#!/usr/bin/env bats
# Tests for scripts/workflow-integrity.py: clean on the real canonical
# workflows, and exit 1 with the right finding for each breakage class.
setup() {
CHECKER="$(cd "$(dirname "$BATS_TEST_FILENAME")/../.." && pwd)/scripts/workflow-integrity.py"
TMP="$(mktemp -d)"
W="$TMP/.ai/workflows"
S="$TMP/.ai/scripts"
mkdir -p "$W" "$S"
touch "$S/helper.sh"
cat > "$W/INDEX.org" <<'EOF'
* Catalog
- =alpha.org= — the alpha workflow.
- Triggers: "do alpha"
- =engine.org= — an engine with plugins.
- Triggers: "run engine"
EOF
cat > "$W/alpha.org" <<'EOF'
* Overview
Alpha workflow. Uses .ai/scripts/helper.sh.
EOF
cat > "$W/engine.org" <<'EOF'
* Overview
The engine.
EOF
cat > "$W/engine.foo.org" <<'EOF'
* Adapter
The foo plugin of engine.
EOF
}
teardown() {
rm -rf "$TMP"
}
@test "workflow-integrity: real canonical workflows are clean" {
run python3 "$CHECKER"
[ "$status" -eq 0 ]
[[ "$output" == *"OK"* ]]
}
@test "workflow-integrity: a valid fixture passes" {
run python3 "$CHECKER" "$W"
[ "$status" -eq 0 ]
}
@test "workflow-integrity: an un-indexed non-plugin file is an orphan" {
cat > "$W/stray.org" <<'EOF'
* Overview
Not indexed, not a plugin.
EOF
run python3 "$CHECKER" "$W"
[ "$status" -eq 1 ]
[[ "$output" == *"orphan"* ]]
[[ "$output" == *"stray.org"* ]]
}
@test "workflow-integrity: an index entry with no file is stale" {
echo '- =ghost.org= — a workflow that was deleted.' >> "$W/INDEX.org"
run python3 "$CHECKER" "$W"
[ "$status" -eq 1 ]
[[ "$output" == *"stale-index"* ]]
[[ "$output" == *"ghost.org"* ]]
}
@test "workflow-integrity: a reference to a missing script fails" {
cat >> "$W/alpha.org" <<'EOF'
Also calls .ai/scripts/missing-tool.py which is gone.
EOF
run python3 "$CHECKER" "$W"
[ "$status" -eq 1 ]
[[ "$output" == *"bad-ref"* ]]
[[ "$output" == *"missing-tool.py"* ]]
}
@test "workflow-integrity: a plugin whose engine is not indexed is flagged" {
cat > "$W/lonely.plugin.org" <<'EOF'
* Adapter
A plugin with no indexed parent engine.
EOF
run python3 "$CHECKER" "$W"
[ "$status" -eq 1 ]
[[ "$output" == *"orphan-plugin"* ]]
}
@test "workflow-integrity: an indexed workflow with no orientation section is flagged" {
echo '- =bare.org= — a bare workflow.' >> "$W/INDEX.org"
cat > "$W/bare.org" <<'EOF'
* Steps
Jumps straight in with no orientation section.
EOF
run python3 "$CHECKER" "$W"
[ "$status" -eq 1 ]
[[ "$output" == *"missing-section"* ]]
[[ "$output" == *"bare.org"* ]]
}
@test "workflow-integrity: a trigger phrase claimed by two workflows is flagged" {
# Make engine also claim alpha's trigger.
sed -i 's/ - Triggers: "run engine"/ - Triggers: "run engine", "do alpha"/' "$W/INDEX.org"
run python3 "$CHECKER" "$W"
[ "$status" -eq 1 ]
[[ "$output" == *"dup-trigger"* ]]
[[ "$output" == *"do alpha"* ]]
}
|