#!/usr/bin/env bats # tests/scripts.bats — unit tests for the deterministic skill scripts. load helpers @test "slug: path with extension and spaces" { run bash "$SKILL_SCRIPTS/slug.sh" "raw/articles/My Test Source.md" [ "$status" -eq 0 ] [ "$output" = "my-test-source" ] } @test "slug: punctuation and repeats collapse to single hyphens" { run bash "$SKILL_SCRIPTS/slug.sh" "Qualche Concetto!! Strano" [ "$output" = "qualche-concetto-strano" ] } @test "log-append: appends a well-formed INGEST entry with a run_id" { G="$(make_fixture_genome)"; cd "$G" run bash "$SKILL_SCRIPTS/log-append.sh" --type INGEST --subject foo --model m \ --context "[[raw/x]]" --output "[[sources/foo]]" --reasoning "why" [ "$status" -eq 0 ] grep -q "INGEST | foo" wiki/log.md grep -q '^- run_id: `' wiki/log.md grep -q '^- model: `m`' wiki/log.md } @test "log-append: rejects an invalid TYPE" { G="$(make_fixture_genome)"; cd "$G" run bash "$SKILL_SCRIPTS/log-append.sh" --type BOGUS --subject foo [ "$status" -ne 0 ] } @test "index-append: inserts under the right section and keeps it sorted" { G="$(make_fixture_genome)"; cd "$G" python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/zzz]] — z. `maturity: draft`' python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/aaa]] — a. `maturity: draft`' a=$(grep -n 'sources/aaa' wiki/index.md | cut -d: -f1) z=$(grep -n 'sources/zzz' wiki/index.md | cut -d: -f1) [ -n "$a" ] && [ -n "$z" ] [ "$a" -lt "$z" ] } @test "index-append: bumps frontmatter last_updated to today" { G="$(make_fixture_genome)"; cd "$G" python3 "$SKILL_SCRIPTS/index-append.py" --section Concepts --entry '- [[concepts/x]] — x. `maturity: draft`' grep -q "^last_updated: $(date +%F)$" wiki/index.md } @test "index-append: is idempotent for the same entry" { G="$(make_fixture_genome)"; cd "$G" python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/dup]] — d. `maturity: draft`' python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/dup]] — d. `maturity: draft`' [ "$(grep -c 'sources/dup' wiki/index.md)" -eq 1 ] } @test "index-append: updates an existing entry by wikilink path (no duplicate)" { G="$(make_fixture_genome)"; cd "$G" python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/foo]] — old summary. `maturity: draft`' python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/foo]] — new summary. `maturity: stable`' [ "$(grep -c 'sources/foo' wiki/index.md)" -eq 1 ] grep -q 'new summary' wiki/index.md ! grep -q 'old summary' wiki/index.md } @test "slug: refuses an all-symbols input (no empty slug)" { run bash "$SKILL_SCRIPTS/slug.sh" "!!!.md" [ "$status" -ne 0 ] [ -z "$output" ] || [[ "$output" != *"feat/ai-ingest-"* ]] } @test "index-append: self-heals a frontmatter missing last_updated" { G="$(make_fixture_genome)"; cd "$G" cat > wiki/index.md <<'EOF' --- title: "Index" type: index domain: genome-test maturity: stable private: false --- # Index ## Sources (`wiki/sources/`) *x* EOF python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/foo]] — s. `maturity: draft`' grep -q "^last_updated: $(date +%F)$" wiki/index.md } @test "log-append: dedup on stable run_id prevents duplicate entries" { G="$(make_fixture_genome)"; cd "$G" stable_id="test-stable-run-id-001" run bash "$SKILL_SCRIPTS/log-append.sh" --run-id "$stable_id" --type INGEST --subject "test" --model "m" \ --context "[[raw/x]]" --output "[[sources/x]]" --reasoning "r" [ "$status" -eq 0 ] run bash "$SKILL_SCRIPTS/log-append.sh" --run-id "$stable_id" --type INGEST --subject "test" --model "m" \ --context "[[raw/x]]" --output "[[sources/x]]" --reasoning "r" [ "$status" -eq 0 ] [[ "$output" == *"already present"* ]] count="$(grep -cF "run_id: \`${stable_id}\`" wiki/log.md || true)" [ "$count" -eq 1 ] }