#!/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 ] }