#!/usr/bin/env bats # tests/kb-coverage.bats — black-box tests for scripts/kb-coverage.py # # Contract: exit 0 when every directory of a knowledge bundle has an index.md and each # index links its siblings. Observable surface: stdout lines and exit status. setup() { CHECK="$BATS_TEST_DIRNAME/../scripts/kb-coverage.py" KB="$(mktemp -d)/kb" mkdir -p "$KB/sub" printf '# Index\n\n* [Good](good.md)\n* [Sub](sub/)\n' > "$KB/index.md" printf '# Sub\n\n* [Deep](deep.md)\n' > "$KB/sub/index.md" printf 'body\n' > "$KB/good.md" printf 'body\n' > "$KB/sub/deep.md" } teardown() { rm -rf "$(dirname "$KB")"; } @test "a bundle whose directories index their contents passes" { run python3 "$CHECK" "$KB" [ "$status" -eq 0 ] [[ "$output" == *"0 issue(s)"* ]] } @test "a directory nobody indexes is reported" { mkdir "$KB/stray" printf 'body\n' > "$KB/stray/thing.md" run python3 "$CHECK" "$KB" [ "$status" -ne 0 ] [[ "$output" == *"stray: no index.md"* ]] } @test "an index that forgets a sibling page is reported" { printf 'body\n' > "$KB/orphan.md" run python3 "$CHECK" "$KB" [ "$status" -ne 0 ] [[ "$output" == *"does not link orphan.md"* ]] } @test "the quarantine trash directory is not part of the bundle" { # Pages deleted from the KB wait in .AGENTTRASH/ for a pruning session with Frank. # Requiring an index there, or listing its contents, would push an agent to delete # the quarantined copy just to make the gate green. mkdir -p "$KB/.AGENTTRASH" printf 'retired page\n' > "$KB/.AGENTTRASH/old-page.md" run python3 "$CHECK" "$KB" [ "$status" -eq 0 ] [[ "$output" == *"0 issue(s)"* ]] }