knowledge-genome-orchestrator/tests/helpers.bash

104 lines
2.5 KiB
Bash

#!/usr/bin/env bash
# tests/helpers.bash — shared helpers for the bats suite.
REPO_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." && pwd)"
LIB_DIR="${REPO_ROOT}/lib"
SKILL_SCRIPTS="${REPO_ROOT}/skills/ingest/scripts"
# Canonical dirs a fresh genome must contain (kept in sync with lib/structure.sh).
FIXTURE_DIRS=(
raw/articles raw/transcripts raw/code-packs raw/assets raw/private
wiki/sources wiki/entities wiki/concepts wiki/queries wiki/private
)
# make_fixture_genome → echoes the path to a throwaway genome checkout with a
# local bare remote, the full canonical structure, and rendered index/log.
# Uses BATS_TEST_TMPDIR so bats cleans it up automatically.
make_fixture_genome() {
local base; base="$(mktemp -d "${BATS_TEST_TMPDIR:-/tmp}/genome.XXXXXX")"
git init --bare -q "${base}/origin.git"
local g="${base}/genome"
local d
for d in "${FIXTURE_DIRS[@]}"; do mkdir -p "${g}/${d}"; touch "${g}/${d}/.gitkeep"; done
cat > "${g}/wiki/index.md" <<'EOF'
---
title: "Index — genome-test"
type: index
domain: genome-test
maturity: stable
last_updated: 2026-01-01
private: false
---
# Master Index: genome-test
---
## Sources (`wiki/sources/`)
*Ingested raw materials.*
## Entities (`wiki/entities/`)
*People, tools.*
## Concepts (`wiki/concepts/`)
*Patterns.*
## Queries (`wiki/queries/`)
*Answers.*
## Conflicts Pending Review (`wiki/queries/conflict-*.md`)
*slugs only.*
## Private Synthesis (`wiki/private/`)
_Restricted access. Requires `PRIVATE_CONTEXT: enabled` and unlocked repo._
_List slug names ONLY. Do not append summaries — prevents metadata leakage._
EOF
cat > "${g}/wiki/log.md" <<'EOF'
---
title: "Operations Log — genome-test"
type: log
domain: genome-test
maturity: stable
last_updated: 2026-01-01
private: false
---
# Operations Log
---
## [2026-01-01] CONFIG | scaffolded
- run_id: `init`
EOF
echo "raw test" > "${g}/raw/articles/test.md"
mkdir -p "${base}/nohooks"
(
cd "${g}"
git init -q
# Hermetic: ignore the user's global git config (signing, global hooks);
# otherwise commit.gpgsign or a global core.hooksPath makes git commit fail here.
git config --local user.name "Framework Test"
git config --local user.email "test@genome.local"
git config --local commit.gpgsign false
git config --local core.hooksPath "${base}/nohooks"
git branch -M main
git remote add origin "${base}/origin.git"
git add .
git commit -q -m "chore: initial scaffold"
git push -q -u origin main
)
echo "${g}"
}