From 8082bc3003f2e5a1bcae42da6f07661fa6acf9f7 Mon Sep 17 00:00:00 2001 From: Matteo Cherubini Date: Wed, 1 Jul 2026 19:37:10 +0200 Subject: [PATCH] test(ingest): add tests for index-append.py --remove --- tests/index-remove.bats | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/index-remove.bats diff --git a/tests/index-remove.bats b/tests/index-remove.bats new file mode 100644 index 0000000..d1a13bd --- /dev/null +++ b/tests/index-remove.bats @@ -0,0 +1,44 @@ +#!/usr/bin/env bats +# tests/index-remove.bats — index-append.py --remove mode. +setup() { + load 'helpers' + export GENOMES_ROOT="${BATS_TEST_TMPDIR}" + g_src="$(make_fixture_genome)"; export g="$g_src" +} + +@test "index --remove: deletes the matching entry, keeps the others" { + cd "$g" + python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/a]] — A. `maturity: draft`' + python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/b]] — B. `maturity: draft`' + grep -q 'sources/a' wiki/index.md + grep -q 'sources/b' wiki/index.md + + run python3 "$SKILL_SCRIPTS/index-append.py" --remove 'sources/a' + [ "$status" -eq 0 ] + ! grep -q '\[\[sources/a\]\]' wiki/index.md + grep -q 'sources/b' wiki/index.md +} + +@test "index --remove: idempotent when the entry is absent" { + cd "$g" + run python3 "$SKILL_SCRIPTS/index-append.py" --remove 'sources/does-not-exist' + [ "$status" -eq 0 ] + [[ "$output" == *'nothing to remove'* ]] +} + +@test "index --remove: bumps last_updated" { + cd "$g" + python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/a]] — A. `maturity: draft`' + # set last_updated to an old date, then remove and check it moved + sed -i 's/^last_updated:.*/last_updated: 2000-01-01/' wiki/index.md + run python3 "$SKILL_SCRIPTS/index-append.py" --remove 'sources/a' + [ "$status" -eq 0 ] + ! grep -q '2000-01-01' wiki/index.md + grep -q "last_updated: $(date +%F)" wiki/index.md +} + +@test "index --remove: rejects passing both --entry and --remove" { + cd "$g" + run python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/a]] — x' --remove 'sources/a' + [ "$status" -eq 2 ] +}