test(lint,structure): Add Bats tests for linting and structure validation
This commit is contained in:
parent
9b61e74821
commit
b88468cc06
2 changed files with 111 additions and 0 deletions
71
tests/lint.bats
Normal file
71
tests/lint.bats
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
#!/usr/bin/env bats
|
||||||
|
# tests/lint.bats — lib/lint.sh validators and the scoped-lint wrapper.
|
||||||
|
load helpers
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
source "$LIB_DIR/output.sh"
|
||||||
|
source "$LIB_DIR/lint.sh"
|
||||||
|
}
|
||||||
|
|
||||||
|
write_page() { # write_page <path> <type> <domain>
|
||||||
|
cat > "$1" <<EOF
|
||||||
|
---
|
||||||
|
title: "T"
|
||||||
|
type: $2
|
||||||
|
domain: $3
|
||||||
|
tags: [x]
|
||||||
|
maturity: draft
|
||||||
|
last_updated: $(date +%F)
|
||||||
|
private: false
|
||||||
|
---
|
||||||
|
body
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "lint_markdown_file: a clean page passes (0 errors)" {
|
||||||
|
G="$(make_fixture_genome)"
|
||||||
|
write_page "$G/wiki/sources/good.md" source genome-test
|
||||||
|
run lint_markdown_file "$G/wiki/sources/good.md" genome-test
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "lint_markdown_file: invalid type + wrong domain are caught" {
|
||||||
|
G="$(make_fixture_genome)"
|
||||||
|
write_page "$G/wiki/sources/bad.md" banana wrong-genome
|
||||||
|
run lint_markdown_file "$G/wiki/sources/bad.md" genome-test
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "check_privacy_consistency: a private/ file without 'private: true' fails" {
|
||||||
|
G="$(make_fixture_genome)"
|
||||||
|
# page sits in wiki/private/ but is flagged private: false → leak
|
||||||
|
write_page "$G/wiki/private/p.md" private genome-test
|
||||||
|
run check_privacy_consistency "$G/wiki/private/p.md"
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "check_page_size: a >800-line page errors" {
|
||||||
|
G="$(make_fixture_genome)"
|
||||||
|
{ write_page "$G/wiki/sources/big.md" source genome-test; yes "x" | head -n 850 >> "$G/wiki/sources/big.md"; }
|
||||||
|
run check_page_size "$G/wiki/sources/big.md"
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "scoped-lint: aggregates findings and exits non-zero on errors" {
|
||||||
|
G="$(make_fixture_genome)"
|
||||||
|
write_page "$G/wiki/sources/bad.md" banana wrong-genome
|
||||||
|
cd "$G"
|
||||||
|
export KG_LIB_DIR="$LIB_DIR"
|
||||||
|
run bash "$SKILL_SCRIPTS/scoped-lint.sh" genome-test wiki/sources/bad.md
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "$output" == *"error(s)"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "scoped-lint: a clean page passes (exit 0)" {
|
||||||
|
G="$(make_fixture_genome)"
|
||||||
|
write_page "$G/wiki/sources/good.md" source genome-test
|
||||||
|
cd "$G"
|
||||||
|
export KG_LIB_DIR="$LIB_DIR"
|
||||||
|
run bash "$SKILL_SCRIPTS/scoped-lint.sh" genome-test wiki/sources/good.md
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
}
|
||||||
40
tests/structure.bats
Normal file
40
tests/structure.bats
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
#!/usr/bin/env bats
|
||||||
|
# tests/structure.bats — canonical-structure verify/sync.
|
||||||
|
load helpers
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
source "$LIB_DIR/output.sh"
|
||||||
|
source "$LIB_DIR/structure.sh"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "structure_report: a full fixture has no drift" {
|
||||||
|
G="$(make_fixture_genome)"
|
||||||
|
run structure_report "$G"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "structure_report: flags a missing canonical dir" {
|
||||||
|
G="$(make_fixture_genome)"
|
||||||
|
rm -rf "$G/wiki/private"
|
||||||
|
run structure_report "$G"
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "$output" == *"wiki/private"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "structure_report: notes an extra dir but does not fail on it" {
|
||||||
|
G="$(make_fixture_genome)"
|
||||||
|
mkdir -p "$G/wiki/experiments"
|
||||||
|
run structure_report "$G"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"experiments"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "structure_sync: creates missing dirs and is idempotent" {
|
||||||
|
G="$(make_fixture_genome)"
|
||||||
|
rm -rf "$G/wiki/private" "$G/raw/transcripts"
|
||||||
|
structure_sync "$G"
|
||||||
|
[ -d "$G/wiki/private" ] && [ -d "$G/raw/transcripts" ]
|
||||||
|
run structure_report "$G"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
structure_sync "$G" # second run: nothing to do
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue