38 lines
1.8 KiB
Bash
38 lines
1.8 KiB
Bash
#!/usr/bin/env bats
|
|
setup() {
|
|
load 'helpers'
|
|
export ORPHAN="${SKILL_SCRIPTS}/orphan-wiki.sh"
|
|
export GENOMES_ROOT="${BATS_TEST_TMPDIR}"
|
|
export INGEST_BASE="main"
|
|
export KG_LIB_DIR="${LIB_DIR}" # orphan-wiki.sh sources clean-start.sh via KG_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}"
|
|
( cd "$g" && rm -f raw/articles/test.md && git add -A && git commit -q -m "clear" && git push -q )
|
|
}
|
|
@test "orphan-wiki: no orphans when raw and source page match" {
|
|
mkdir -p "${g}/raw/articles"; echo "content" > "${g}/raw/articles/existing.md"
|
|
hash="$(sha256sum "${g}/raw/articles/existing.md" | cut -d' ' -f1)"
|
|
mkdir -p "${g}/wiki/sources"
|
|
printf -- '---\nsource_path: raw/articles/existing.md\nsource_sha256: %s\n---\n' "$hash" > "${g}/wiki/sources/existing.md"
|
|
( cd "$g" && git add . && git commit -q -m "setup" && git push -q )
|
|
run bash "$ORPHAN" "$g_name"
|
|
[ "$status" -eq 0 ]; echo "$output" | jq -e '.count == 0'
|
|
}
|
|
@test "orphan-wiki: detects orphaned source page" {
|
|
mkdir -p "${g}/wiki/sources"
|
|
printf -- '---\nsource_path: raw/articles/deleted.md\nsource_sha256: abc123\n---\n' > "${g}/wiki/sources/orphaned.md"
|
|
( cd "$g" && git add . && git commit -q -m "orphan" && git push -q )
|
|
run bash "$ORPHAN" "$g_name"
|
|
[ "$status" -eq 0 ]
|
|
echo "$output" | jq -e '.count == 1'
|
|
echo "$output" | jq -e '.detail[0].reason == "orphan"'
|
|
}
|
|
@test "orphan-wiki: ignores legacy pages without source_path" {
|
|
mkdir -p "${g}/wiki/sources"
|
|
printf -- '---\ntitle: "Legacy"\ntype: source\n---\n' > "${g}/wiki/sources/legacy.md"
|
|
( cd "$g" && git add . && git commit -q -m "legacy" && git push -q )
|
|
run bash "$ORPHAN" "$g_name"
|
|
[ "$status" -eq 0 ]; echo "$output" | jq -e '.count == 0'
|
|
}
|