#!/usr/bin/env bats setup() { load 'helpers' export PENDING="${SKILL_SCRIPTS}/pending-raw.sh" export GENOMES_ROOT="${BATS_TEST_TMPDIR}" export INGEST_BASE="main" export KG_LIB_DIR="${LIB_DIR}" g_src="$(make_fixture_genome)" export g_name="fixture-genome" mv "$g_src" "${GENOMES_ROOT}/${g_name}" export g="${GENOMES_ROOT}/${g_name}" # FIX: make_fixture_genome ships raw/articles/test.md with no source page, which would # otherwise count as a permanent 'new' and break every count assertion. Clear it so each # test controls exactly what is pending (verified: count base becomes 0). ( cd "$g" && rm -f raw/articles/test.md && git add -A \ && git commit -q -m "test: clear default raw" && git push -q ) } @test "pending-raw: detects a brand new raw file" { echo "new content" > "${g}/raw/articles/new-file.md" ( cd "$g" && git add . && git commit -q -m "add raw" && git push -q ) run bash "$PENDING" "$g_name" [ "$status" -eq 0 ] echo "$output" | jq -e '.count == 1' echo "$output" | jq -e '.detail[0].path == "raw/articles/new-file.md"' echo "$output" | jq -e '.detail[0].reason == "new"' } @test "pending-raw: skips up-to-date files" { echo "ok content" > "${g}/raw/articles/ok-file.md" hash_ok="$(sha256sum "${g}/raw/articles/ok-file.md" | cut -d' ' -f1)" cat > "${g}/wiki/sources/ok-file.md" < "${g}/raw/articles/mod-file.md" hash_v1="$(sha256sum "${g}/raw/articles/mod-file.md" | cut -d' ' -f1)" cat > "${g}/wiki/sources/mod-file.md" < "${g}/raw/articles/mod-file.md" ( cd "$g" && git add . && git commit -q -m "v2" && git push -q ) run bash "$PENDING" "$g_name" [ "$status" -eq 0 ] echo "$output" | jq -e '.count == 1' echo "$output" | jq -e '.detail[0].reason == "modified"' } @test "pending-raw: nested subdirectory yields prefixed slug" { mkdir -p "${g}/raw/articles/sub-b" echo "subdir content" > "${g}/raw/articles/sub-b/file.md" ( cd "$g" && git add . && git commit -q -m "subdir" && git push -q ) run bash "$PENDING" "$g_name" [ "$status" -eq 0 ] echo "$output" | jq -e '.count == 1' echo "$output" | jq -e '.files[0] == "raw/articles/sub-b/file.md"' } @test "pending-raw: excludes noise (.stfolder, .gitkeep)" { touch "${g}/raw/articles/.gitkeep" mkdir -p "${g}/raw/articles/.stfolder" touch "${g}/raw/articles/.stfolder/sync.log" ( cd "$g" && git add . && git commit -q -m "noise" && git push -q ) run bash "$PENDING" "$g_name" [ "$status" -eq 0 ] echo "$output" | jq -e '.count == 0' } @test "pending-raw: reports both files on a slug collision" { mkdir -p "${g}/raw/articles/cibo" echo "c1" > "${g}/raw/articles/cibo-pane.md" echo "c2" > "${g}/raw/articles/cibo/pane.md" ( cd "$g" && git add . && git commit -q -m "collision" && git push -q ) run bash "$PENDING" "$g_name" [ "$status" -eq 0 ] echo "$output" | jq -e '.count == 2' }