#!/usr/bin/env bats # ============================================================================= # tests/lib-load-project.bats — Regression guard for the #862 fix. # # TOML allows dashes in bare keys, so `[agents.dev-qwen2]` is a valid section # header. Before #862, load-project.sh translated the section name into a # shell variable name via Python's `.upper()` alone, which kept the dash and # produced `AGENT_DEV-QWEN2_BASE_URL`. `export "AGENT_DEV-QWEN2_..."` is # rejected by bash ("not a valid identifier"), and with `set -euo pipefail` # anywhere up-stack that error aborts load-project.sh — effectively crashing # the factory on the N+1 run after a dashed agent was hired. # # The fix normalizes via `.upper().replace('-', '_')`, matching the # `tr 'a-z-' 'A-Z_'` convention already used in hire-agent.sh and # generators.sh. # ============================================================================= setup() { ROOT="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)" TOML="${BATS_TEST_TMPDIR}/test.toml" } @test "dashed [agents.*] section name parses without error" { cat > "$TOML" < "$TOML" < "$TOML" < "$TOML" <&1 echo \"GOOD=\${MIRROR_GOOD:-MISSING}\" " # Whole load did not abort under set -e. [ "$status" -eq 0 ] # The valid mirror still loads. [[ "$output" == *"GOOD=https://example.com/good"* ]] # The invalid one triggers a warning; load continues instead of crashing. [[ "$output" == *"skipping invalid shell identifier"* ]] [[ "$output" == *"MIRROR_BAD-NAME"* ]] } @test "[agents.*] quoted section with space: warn-and-skip, does not crash" { # TOML permits quoted keys with arbitrary characters. A hand-edited # `[agents."weird name"]` would survive the Python .replace('-', '_') # (because it has no dash) but still contains a space, which would # yield AGENT_WEIRD NAME_BASE_URL — not a valid identifier. cat > "$TOML" <<'EOF' name = "test" repo = "test-owner/test-repo" forge_url = "http://localhost:3000" [agents.llama] base_url = "http://10.10.10.1:8081" model = "qwen" [agents."weird name"] base_url = "http://10.10.10.1:8082" model = "qwen-bad" EOF run bash -c " set -euo pipefail source '${ROOT}/lib/load-project.sh' '$TOML' 2>&1 echo \"LLAMA=\${AGENT_LLAMA_BASE_URL:-MISSING}\" " # The sane sibling must still be loaded despite the malformed neighbour. [ "$status" -eq 0 ] [[ "$output" == *"LLAMA=http://10.10.10.1:8081"* ]] # The invalid agent's identifier triggers a warning and is skipped. [[ "$output" == *"skipping invalid shell identifier"* ]] }