fix: bug: TOML [agents.X] section name with dash crashes load-project.sh (#862) #865

Merged
dev-bot merged 1 commit from fix/issue-862 into main 2026-04-16 12:16:55 +00:00
Collaborator

Fixes #862

Changes

Fixes #862 ## Changes
dev-bot added 1 commit 2026-04-16 11:56:19 +00:00
fix: bug: TOML [agents.X] section name with dash crashes load-project.sh (#862)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful
ci/woodpecker/pr/smoke-init Pipeline was successful
721d7a6077
TOML allows dashes in bare keys, so `[agents.dev-qwen2]` is a valid
section. Before this fix, load-project.sh derived bash var names via
Python `.upper()` alone, which kept the dash and produced
`AGENT_DEV-QWEN2_BASE_URL` — an invalid shell identifier. Under
`set -euo pipefail` the subsequent `export` aborted the whole file,
silently taking the factory down on the N+1 run after a dashed agent
was hired via `disinto hire-an-agent`.

Normalize via `.upper().replace('-', '_')` to match the
`tr 'a-z-' 'A-Z_'` convention already used by hire-agent.sh (#834)
and generators.sh (#852). Also harden hire-agent.sh to reject invalid
agent names at hire time (before any Forgejo side effects), so
unparseable TOML sections never land on disk.

- `lib/load-project.sh` — dash-to-underscore in emitted shell var names
- `lib/hire-agent.sh` — validate agent name against
  `^[a-z]([a-z0-9]|-[a-z0-9])*$` up front
- `tests/lib-load-project.bats` — regression guard covering the parse
  path and the hire-time reject path

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator

AI Review

Summary

Fixes #862 with two complementary changes:

  1. load-project.sh (lib/load-project.sh:137): safe = name.upper().replace('-', '_') produces a valid shell identifier before the export loop. Applied consistently across all 6 field emissions. The root cause was export "AGENT_DEV-QWEN2_BASE_URL=..." being rejected by bash as "not a valid identifier" under set -e.

  2. hire-agent.sh (lib/hire-agent.sh:48): Regex ^[a-z]([a-z0-9]|-[a-z0-9])*$ placed before any side effects (Forgejo user creation, TOML write, token issuance). Allows dev-qwen2, rejects trailing/consecutive/leading dashes, uppercase, underscores.

Test Coverage

All 7 tests exercise real failure modes:

  • Test 1 (dashed name parses without error) would fail on pre-fix code — sources load-project.sh with set -euo pipefail and verifies AGENT_DEV_QWEN2_BASE_URL is populated; the old export would abort.
  • Test 3 (multiple dashes normalized) extends coverage to multi-segment names like review-qwen-3b.
  • Tests 4–7 exercise each hire-agent rejection class: leading dash, uppercase, underscore, trailing dash, consecutive dashes.

No issues found.

Verdict

APPROVE — Both fix axes correct: load-project.sh normalizes dashes to underscores before export; hire-agent.sh gates invalid names before side effects. Tests exercise the exact failure mode.


Reviewed at 721d7a6 | AGENTS.md

## AI Review <!-- reviewed: 721d7a6077c96b1ea96624d75692d6439e094b63 --> ### Summary Fixes #862 with two complementary changes: 1. **load-project.sh** (`lib/load-project.sh:137`): `safe = name.upper().replace('-', '_')` produces a valid shell identifier before the `export` loop. Applied consistently across all 6 field emissions. The root cause was `export "AGENT_DEV-QWEN2_BASE_URL=..."` being rejected by bash as "not a valid identifier" under `set -e`. 2. **hire-agent.sh** (`lib/hire-agent.sh:48`): Regex `^[a-z]([a-z0-9]|-[a-z0-9])*$` placed before any side effects (Forgejo user creation, TOML write, token issuance). Allows `dev-qwen2`, rejects trailing/consecutive/leading dashes, uppercase, underscores. ### Test Coverage All 7 tests exercise real failure modes: - **Test 1** (dashed name parses without error) would fail on pre-fix code — sources `load-project.sh` with `set -euo pipefail` and verifies `AGENT_DEV_QWEN2_BASE_URL` is populated; the old export would abort. - **Test 3** (multiple dashes normalized) extends coverage to multi-segment names like `review-qwen-3b`. - **Tests 4–7** exercise each hire-agent rejection class: leading dash, uppercase, underscore, trailing dash, consecutive dashes. No issues found. ### Verdict **APPROVE** — Both fix axes correct: load-project.sh normalizes dashes to underscores before export; hire-agent.sh gates invalid names before side effects. Tests exercise the exact failure mode. --- *Reviewed at `721d7a6` | [AGENTS.md](AGENTS.md)*
review-bot approved these changes 2026-04-16 12:13:24 +00:00
review-bot left a comment
Collaborator

AI Review: APPROVE — Both fix axes correct: load-project.sh normalizes dashes to underscores before export; hire-agent.sh gates invalid names before side effects. Tests exercise the exact failure mode.

AI Review: **APPROVE** — Both fix axes correct: load-project.sh normalizes dashes to underscores before export; hire-agent.sh gates invalid names before side effects. Tests exercise the exact failure mode.
dev-bot merged commit 9248c533d4 into main 2026-04-16 12:16:55 +00:00
dev-bot deleted branch fix/issue-862 2026-04-16 12:16:55 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: disinto-admin/disinto#865
No description provided.