blob: a9f9e58cad0e8f964f3befbc6357198bef8648e7 (
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
|
#!/usr/bin/env bats
# Tests for scripts/kb-hygiene.sh — the monthly agent-KB hygiene report.
setup() {
SCRIPT="$BATS_TEST_DIRNAME/../kb-hygiene.sh"
KB="$BATS_TEST_TMPDIR/kb"
OUT="$BATS_TEST_TMPDIR/inbox"
mkdir -p "$KB/agents" "$OUT"
# A hand-authored node that links to agent node AAA.
cat > "$KB/20240101000000-craig-note.org" << 'EOF'
:PROPERTIES:
:ID: craig-1111
:END:
#+title: Craig's note
See [[id:agent-aaa][the agent fact]].
EOF
# Agent node AAA — linked from Craig's note (not an orphan).
cat > "$KB/agents/20250101000000-linked-fact.org" << 'EOF'
:PROPERTIES:
:ID: agent-aaa
:END:
#+title: Linked fact
#+filetags: :agent:reference:
A fact someone links to.
EOF
# Agent node BBB — nothing links to it (orphan).
cat > "$KB/agents/20250102000000-orphan-fact.org" << 'EOF'
:PROPERTIES:
:ID: agent-bbb
:END:
#+title: Orphan fact
#+filetags: :agent:reference:
Nobody links here.
EOF
}
@test "missing KB path: exits nonzero with a message" {
run "$SCRIPT" "$BATS_TEST_TMPDIR/nope" "$OUT"
[ "$status" -ne 0 ]
[[ "$output" == *"no KB"* ]]
}
@test "writes a dated report file into the report dir" {
run "$SCRIPT" "$KB" "$OUT"
[ "$status" -eq 0 ]
ls "$OUT" | grep -q "kb-hygiene-report.org"
}
@test "counts agent nodes correctly" {
run "$SCRIPT" "$KB" "$OUT"
report=$(ls "$OUT"/*kb-hygiene-report.org)
grep -q "Agent nodes: 2" "$report"
}
@test "flags the orphan and not the linked node" {
run "$SCRIPT" "$KB" "$OUT"
report=$(ls "$OUT"/*kb-hygiene-report.org)
grep -q "orphan-fact" "$report"
! grep -A2 "Orphans" "$report" | grep -q "linked-fact"
}
@test "flags duplicate agent titles" {
cat > "$KB/agents/20250103000000-dupe.org" << 'EOF'
:PROPERTIES:
:ID: agent-ccc
:END:
#+title: Orphan fact
#+filetags: :agent:reference:
EOF
run "$SCRIPT" "$KB" "$OUT"
report=$(ls "$OUT"/*kb-hygiene-report.org)
grep -qi "duplicate" "$report"
grep -c "Orphan fact" "$report" | grep -qv '^0$'
}
@test "reports sync-conflict file count" {
touch "$KB/junk.sync-conflict-20260101-000000-XXXX.org"
run "$SCRIPT" "$KB" "$OUT"
report=$(ls "$OUT"/*kb-hygiene-report.org)
grep -q "Conflict files: 1" "$report"
}
|