Skip to content

test(brain-orb): close coverage gaps — owner gate, idempotency, hooks, flags, route wiring (ent#61) - #1428

Merged
dolho merged 1 commit into
feature/58-brain-orbfrom
feature/61-brain-orb-tests
Jul 3, 2026
Merged

dolho merged 1 commit into
feature/58-brain-orbfrom
feature/61-brain-orb-tests

Conversation

@vybe

@vybe vybe commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

/update-tests review of the Brain Orb Phase 1–4b surface (stacked on #1389, the open brain-orb chain PR — the tests import routers/agent_brain_orb.py, which doesn't exist on dev yet). 26 new tests; 103 total across the three files, all passing against the live backend.

tests/unit/test_brain_orb.py (+18, file total 95)

  • POST /scope owner-gate 403 — the one OwnedAgentByName route missing the non-owner proof its Phase-4 siblings had (the incomplete-fix-chain escape class from the 2026-06-27 bug-escape analysis)
  • PUT /postprocess 413 body cap (review F4)
  • Idempotency semantics: stored key folds the action verb (a reused client key can't replay a different verb's snapshot); claim released on agent 502/504 so retries aren't wedged on 409; success completes with the parsed snapshot; missing header = fail-open (Invariant Unified Executions Dashboard (EXEC-022) #18)
  • Audit-sink failure never masks a completed write (review F5) on /action and /refresh
  • Agent-server _run_hook hardening: stdout over _MAX_HOOK_OUT → 502; hook present-but-not-executable → 404; scope/tool 64 KiB body caps
  • Postprocess config (perf: Backend CPU saturation at 45% with ~30 agents due to WebSocket churn and polling storms #73): invalid JSON 400, 8000-char prompt truncation, legacy .md fallback, corrupt-JSON degrades to defaults (never 500)
  • Voice mint: _build_system_instruction clause selection + 2000-char prompt cap; new-session window < token expiry

tests/test_settings.py (+3, SMOKE)

First coverage of any brain-orb feature-flag key: brain_orb_available / brain_orb_voice_available / brain_orb_write_available present + boolean; write ⇒ available compound-gate invariant (kill-switch layering, holds under any env); endpoint requires auth.

tests/test_brain_orb_api.py (new, 5, SMOKE)

Live-backend route-wiring proof (#1069 escape class): the unit suite mounts the router on a synthetic app with overridden dependencies, so only these prove main.py registration (unauthenticated → 401, not routing 404) and the real AuthorizedAgentByName/OwnedAgentByName chain (authenticated 404s carry a real dependency/handler detail, never FastAPI's bare "Not Found"). Needs no agent and no flags.

Test plan

  • pytest unit/test_brain_orb.py -v → 95 passed (no backend needed)
  • pytest test_brain_orb_api.py test_settings.py::TestFeatureFlagsBrainOrb -v → 8 passed (live backend)
  • Run the unit file in its own pytest invocation — backend imports shadow tests/utils via sys.modules['utils'] for integration files collected in the same session (pre-existing collision, documented in the test-runner catalog)

Test-runner catalog (.claude/agents/test-runner.md) updated in the trinity-dev submodule — rides separately with the next submodule sync.

🤖 Generated with Claude Code

…hardening, flags, route wiring (abilityai/trinity-enterprise#61)

/update-tests review of the Phase 1-4b surface. 26 new tests, all passing
(103 total across the three files against the live backend).

tests/unit/test_brain_orb.py (+18, file total 95):
- POST /scope owner-gate 403 — the one mutating route missing the proof its
  Phase-4 siblings had (incomplete-fix-chain class)
- PUT /postprocess 413 body cap (review F4)
- idempotency semantics: key folds the action verb; claim released on agent
  502/504; success completes with the parsed snapshot; missing key = fail-open
  (Invariant #18)
- audit-sink failure never masks a completed write (review F5, action+refresh)
- agent-server _run_hook hardening: output cap → 502, non-executable hook →
  404, scope/search 413 body caps
- postprocess (#73): invalid JSON 400, 8000-char prompt truncation, legacy .md
  fallback, corrupt-JSON degrades to defaults
- voice mint: _build_system_instruction clause selection + 2000-char prompt
  cap; new-session window < token expiry

tests/test_settings.py (+3 SMOKE): feature-flags requires auth; brain_orb_*
keys present + boolean; write⇒available compound-gate invariant (#61
kill-switch layering) — first coverage of any brain-orb feature-flag key.

tests/test_brain_orb_api.py (new, 5 SMOKE): live-backend route-wiring proof
(#1069 escape class) — the unit suite mounts the router on a synthetic app,
so only these prove main.py registration + the real AuthorizedAgentByName /
OwnedAgentByName chain.

Test-runner catalog updated in the trinity-dev submodule (rides separately).

Co-Authored-By: Claude Fable 5 <[email protected]>
@dolho

dolho commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review — Brain Orb coverage gaps (automated review, Claude)

Coverage targets exactly the right risk areas for the #1389 surface: the OwnedAgentByName 403 on /scope (the incomplete-fix-chain class), idempotency semantics (verb-folded key so a reused client key can't replay a different verb, claim-release on agent 5xx, fail-open on missing header — all of which I confirmed match idempotency_service.begin's actual contract), the _run_hook hardening (413 caps, timeout→504, invalid-JSON→502, non-exec→404), the compound flag gates, and — valuably — the live route-wiring proof that the unit suite's synthetic-app mount can't give (401-not-404 = registered in main.py). Good instinct separating those.

Notes, not blockers:

  1. Stacked on feature/58-brain-orb, not dev. Base is the feat(ui): Brain Orb — Cornelius-class agent page: static render + live scope control (abilityai/trinity-enterprise#58) #1389 branch (correct — it imports routers/agent_brain_orb.py, absent on dev). Can't merge until feat(ui): Brain Orb — Cornelius-class agent page: static render + live scope control (abilityai/trinity-enterprise#58) #1389 lands; retarget the base to dev at that point or the diff will balloon.

  2. Body/scope drift mirrors feat(ui): Brain Orb — Cornelius-class agent page: static render + live scope control (abilityai/trinity-enterprise#58) #1389. This says "Phase 1–4b" while feat(ui): Brain Orb — Cornelius-class agent page: static render + live scope control (abilityai/trinity-enterprise#58) #1389's body still claims voice/write are "deferred" — another reason to fix the feat(ui): Brain Orb — Cornelius-class agent page: static render + live scope control (abilityai/trinity-enterprise#58) #1389 description (flagged there).

  3. The sys.modules['utils'] collision requiring a separate pytest invocation is fragile. It's pre-existing and documented in the catalog, but a test that silently mis-collects under the wrong invocation order is a footgun for the next contributor. Worth a longer-term fix (rename tests/utils or make the shadowing explicit) rather than just documenting it.

  4. The test-runner catalog update rides in the trinity-dev submodule separately — just make sure that sync actually happens, or the new tests won't be in the runner's catalog.

LGTM as an additive test-only PR, contingent on #1389.

@dolho
dolho merged commit 92a0ed9 into feature/58-brain-orb Jul 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants