Files
command-center/tests/kb-lint.bats
T
Frank 4849f46eb2 feat(kb-gates): one work log per bundle, and the quarantine is not bundle content
The bundle had two work logs. `core/log.md` was created "for tracking core directory
modifications" and holds two entries of pure migration bookkeeping (file moved,
directory created, log created) — every one recoverable from `git log` — plus a date
for the OKF conversion (2026-07-15) that matches neither the bundle log (2026-01-15)
nor git history, where the OKF rebuild lands 2026-08-28. `core/index.md` was still
linking it, which is exactly how a stale page stays in circulation. kb-lint now reports
any `log.md` that is not the bundle root's; the page moved to omp-docs/core/.AGENTTRASH/
per the trash convention, and the core index points one level up.

Both gates also walked `.AGENTTRASH/`, so trashing a page turned them red: kb-lint
demanded frontmatter from a quarantined page and kb-coverage demanded an index for the
trash directory. A gate that only goes green once the quarantined copy is deleted is a
gate that deletes history, so both skip any path containing `.AGENTTRASH` — pinned by a
test in each suite, and kb-coverage finally gets its own test file.
2026-10-20 21:49:15 -07:00

137 lines
4.1 KiB
Bash
Executable File

#!/usr/bin/env bats
# tests/kb-lint.bats — black-box tests for scripts/kb-lint.sh
#
# Contract: exit 0 when a knowledge bundle is OKF v0.1 conformant;
# one line per violation otherwise. Observable surface: stdout lines
# and exit status only.
setup() {
LINT="$BATS_TEST_DIRNAME/../scripts/kb-lint.sh"
KB="$(mktemp -d)/kb"
mkdir -p "$KB/sub"
cat > "$KB/index.md" <<'EOF'
# Index
* [Good](good.md) — fine.
EOF
cat > "$KB/good.md" <<'EOF'
---
type: reference
title: Good
---
Body.
EOF
}
teardown() { rm -rf "$(dirname "$KB")"; }
@test "conformant bundle passes" {
run bash "$LINT" "$KB"
[ "$status" -eq 0 ]
}
@test "missing frontmatter is reported" {
printf 'no frontmatter here\n' > "$KB/bad.md"
run bash "$LINT" "$KB"
[ "$status" -ne 0 ]
[[ "$output" == *"bad.md: missing frontmatter"* ]]
}
@test "frontmatter without type is reported" {
printf -- '---\ntitle: x\n---\nbody\n' > "$KB/notype.md"
run bash "$LINT" "$KB"
[ "$status" -ne 0 ]
[[ "$output" == *"notype.md"*"type"* ]]
}
@test "unclosed frontmatter is reported, not silently passed" {
# regression: a `---` in the body (fenced code, rule) must not be
# accepted as the closing delimiter of the frontmatter block
cat > "$KB/unclosed.md" <<'EOF'
---
type: reference
title: Unclosed
# Heading after a forgotten closing fence
```markdown
---
name: example
---
```
EOF
run bash "$LINT" "$KB"
[ "$status" -ne 0 ]
[[ "$output" == *"unclosed.md"* ]]
}
@test "frontmatter in index.md is reported" {
printf -- '---\ntype: x\n---\n# I\n' > "$KB/sub/index.md"
run bash "$LINT" "$KB"
[ "$status" -ne 0 ]
[[ "$output" == *"index.md must not have frontmatter"* ]]
}
@test "broken relative link is reported" {
printf -- '---\ntype: reference\n---\nsee [x](gone.md)\n' > "$KB/links.md"
run bash "$LINT" "$KB"
[ "$status" -ne 0 ]
[[ "$output" == *"links.md: broken relative link"* ]]
}
@test "broken wikilink is reported" {
printf -- '---\ntype: reference\n---\nsee [[nowhere]]\n' > "$KB/wiki.md"
run bash "$LINT" "$KB"
[ "$status" -ne 0 ]
[[ "$output" == *"wiki.md: broken wikilink"* ]]
}
@test "missing kb directory exits 2" {
run bash "$LINT" "$KB/no-such-dir"
[ "$status" -eq 2 ]
}
@test "a second work log in a subdirectory is reported" {
# One bundle, one work log. Per-directory logs are how a bundle ends up with fifty
# of them: the entry is never where the next agent looks, and each copy re-dates the
# same event on its own.
printf -- '---\ntype: changelog\n---\n## 2026-01-01\n- created a log\n' > "$KB/log.md"
printf -- '---\ntype: changelog\n---\n## 2026-01-02\n- also a log\n' > "$KB/sub/log.md"
run bash "$LINT" "$KB"
[ "$status" -ne 0 ]
[[ "$output" == *"one work log"*"at the bundle root"* ]]
[[ "$output" == *"sub/log.md"* ]]
}
@test "a work log that is not at the bundle root is reported" {
printf -- '---\ntype: changelog\n---\n## 2026-01-02\n- misplaced log\n' > "$KB/sub/log.md"
run bash "$LINT" "$KB"
[ "$status" -ne 0 ]
[[ "$output" == *"one work log"*"at the bundle root"* ]]
}
@test "the quarantine trash directory is not part of the bundle" {
# Deleted pages wait in .AGENTTRASH/ for a pruning session with Frank. Holding them
# to frontmatter and one-log rules would push an agent to delete history to go green.
mkdir -p "$KB/.AGENTTRASH"
printf 'no frontmatter, and a second log besides\n' > "$KB/.AGENTTRASH/log.md"
run bash "$LINT" "$KB"
[ "$status" -eq 0 ]
[[ "$output" == *"0 violation(s)"* ]]
}
@test "the shipped knowledge base itself is conformant" {
# The tests above exercise the linter against fixtures; nothing else in the
# suite ever points it at the real bundle, so a page added without frontmatter
# or an index that stops listing a file passes CI silently. This is the gate.
run bash "$BATS_TEST_DIRNAME/../scripts/kb-lint.sh" "$BATS_TEST_DIRNAME/../omp-docs"
[ "$status" -eq 0 ]
[[ "$output" == *"0 violation(s)"* ]]
}
@test "every page in the shipped knowledge base is listed by an index" {
run python3 "$BATS_TEST_DIRNAME/../scripts/kb-coverage.py" "$BATS_TEST_DIRNAME/../omp-docs"
[ "$status" -eq 0 ]
[[ "$output" == *"0 issue(s)"* ]]
}