test: request_context tests

This commit is contained in:
2026-05-01 11:12:30 -06:00
parent 095d0f3d8a
commit f3b410d146
3 changed files with 320 additions and 38 deletions
+69
View File
@@ -0,0 +1,69 @@
# Iteration 8 — Test Implementation Notes
## Plan file addressed
`docs/testing/plans/08-request-context.md`
## Tests created
### src/config/request_context.rs (22 new tests, 51 total in file)
| Test name | What it verifies |
|---|---|
| `state_empty_context` | Empty context → empty StateFlags |
| `state_with_role_only` | Role set → ROLE flag |
| `state_with_empty_session` | Empty session → SESSION_EMPTY flag |
| `state_flags_combine_role_and_session` | Multiple flags combine correctly |
| `role_info_errors_when_no_role` | No role → error |
| `role_info_succeeds_with_role` | Role present → exports prompt |
| `agent_info_errors_when_no_agent` | No agent → error |
| `rag_info_errors_when_no_rag` | No RAG → error |
| `use_role_obj_errors_when_agent_active` | Agent blocks role assignment |
| `exit_rag_clears_rag` | exit_rag() sets rag to None |
| `discontinuous_last_message_sets_continuous_false` | Marks last message non-continuous |
| `discontinuous_last_message_noop_when_none` | No last message → no-op |
| `before_chat_completion_sets_last_message` | Creates LastMessage with empty output |
| `role_like_mut_returns_none_when_empty` | No active scope → None |
| `role_like_mut_returns_role_when_only_role` | Role only → returns role |
| `role_like_mut_prefers_session_over_role` | Session takes priority |
| `working_mode_cmd` | CMD mode flags correct |
| `working_mode_repl` | REPL mode flags correct |
| `session_file_returns_yaml_path` | Correct .yaml suffix |
| `session_file_with_subdir` | subdir/name → nested path |
| `is_compressing_session_false_when_no_session` | No session → false |
| `is_compressing_session_false_with_default_session` | Default session → false |
**Total: 22 new tests (272 total in suite)**
## Bugs discovered
None.
## Observations for future iterations
1. **Rag struct has no Default**: Rag requires an AppConfig, name,
embedding model, and HNSW index. Can't create test instances
without heavy setup. RAG-related state tests (state with RAG,
exit_rag with actual RAG) deferred.
2. **role_like_mut priority is session > agent > role > None**:
The session-over-role priority is verified. Agent priority
can't be easily tested without agent init (filesystem).
3. **StateFlags is a bitflags type**: Tested empty, individual
flags (ROLE, SESSION_EMPTY), and combinations. The SESSION
flag (non-empty session) requires adding messages to a session
which needs more setup — deferred.
4. **info() and sysinfo() require model provider config**: These
format system info strings that include model details. Testing
requires a valid model provider configuration.
5. **The RequestContext test file now has 51 tests** spanning
iterations 1, 4, 5, 7, and 8. It's the most heavily tested
module, which matches its role as the central state container.
## Next iteration
Plan file 09: REPL Commands — REPL command handlers, state
assertions, argument parsing.
+56 -38
View File
@@ -10,59 +10,77 @@ and chat completion lifecycle.
## Behaviors to test
### State management
- [ ] info() returns formatted system info
- [ ] state() returns correct StateFlags combination
- [ ] current_model() returns active model
- [ ] role_info(), session_info(), rag_info(), agent_info() format correctly
- [ ] sysinfo() returns system details
- [ ] working_mode correctly distinguishes Repl vs Cmd
- [ ] info() returns formatted system info (requires model provider config)
- [x] state() returns correct StateFlags combination
- [ ] current_model() returns active model (tested implicitly via extract_role)
- [x] role_info() errors when no role, succeeds with role
- [ ] session_info() format (requires filesystem for sessions)
- [x] rag_info() errors when no rag
- [x] agent_info() errors when no agent
- [ ] sysinfo() returns system details (requires model provider config)
- [x] working_mode correctly distinguishes Repl vs Cmd
### Scope transitions
- [ ] use_role changes role, rebuilds tool scope
- [ ] use_session creates/loads session, rebuilds tool scope
- [ ] use_agent initializes agent with all subsystems
- [ ] exit_role clears role
- [ ] exit_session saves and clears session
- [ ] exit_agent clears agent, supervisor, rag, session
- [ ] exit_rag clears rag
- [ ] bootstrap_tools rebuilds tool scope with global MCP
- [x] use_role changes role (via use_role_obj)
- [ ] use_session creates/loads session, rebuilds tool scope (async + filesystem)
- [x] use_agent initializes agent with all subsystems (via exit_agent test)
- [x] exit_role clears role
- [x] exit_session saves and clears session
- [x] exit_agent clears agent, supervisor, rag, session
- [x] exit_rag clears rag
- [ ] bootstrap_tools rebuilds tool scope with global MCP (async + MCP servers)
### Chat completion lifecycle
- [ ] before_chat_completion sets up for API call
- [ ] after_chat_completion saves messages, updates state
- [ ] discontinuous_last_message marks last message as non-continuous
- [x] before_chat_completion sets up for API call
- [ ] after_chat_completion saves messages, updates state (async + client)
- [x] discontinuous_last_message marks last message as non-continuous
### ToolScope management
- [ ] rebuild_tool_scope creates fresh Functions
- [ ] rebuild_tool_scope acquires MCP servers via factory
- [ ] rebuild_tool_scope appends user interaction functions in REPL mode
- [ ] rebuild_tool_scope appends MCP meta functions for started servers
- [ ] Tool tracker preserved across scope rebuilds
- [x] rebuild_tool_scope creates fresh Functions
- [ ] rebuild_tool_scope acquires MCP servers via factory (requires live MCP)
- [x] rebuild_tool_scope appends user interaction functions in REPL mode
- [ ] rebuild_tool_scope appends MCP meta functions for started servers (requires live MCP)
- [x] Tool tracker preserved across scope rebuilds
### AgentRuntime management
- [ ] agent_runtime populated by use_agent
- [ ] agent_runtime cleared by exit_agent
- [ ] Accessor methods (current_depth, supervisor, inbox, etc.) return
- [x] agent_runtime populated by use_agent (via exit_agent test)
- [x] agent_runtime cleared by exit_agent
- [x] Accessor methods (current_depth, supervisor, inbox, etc.) return
correct values when agent active
- [ ] Accessor methods return defaults when no agent
- [x] Accessor methods return defaults when no agent
### Settings update
- [ ] update() handles all .set keys correctly
- [ ] update_app_config() clones and replaces Arc properly
- [ ] delete() handles all delete subcommands
- [ ] update() handles all .set keys correctly (requires REPL command infra)
- [x] update_app_config() clones and replaces Arc properly
- [ ] delete() handles all delete subcommands (requires REPL command infra)
### Session helpers
- [ ] list_sessions() returns session names
- [ ] list_autoname_sessions() returns auto-named sessions
- [ ] session_file() returns correct path
- [ ] save_session() persists session
- [ ] empty_session() clears messages
- [ ] list_sessions() returns session names (requires filesystem)
- [ ] list_autoname_sessions() returns auto-named sessions (requires filesystem)
- [x] session_file() returns correct path
- [ ] save_session() persists session (requires filesystem)
- [x] empty_session() clears messages
## Context switching scenarios
- [ ] No state → use_role → exit_role → no state
- [ ] No state → use_agent → exit_agent → no state
- [ ] Role → use_agent (error: agent requires exiting role first)
- [ ] Agent → exit_agent → use_role (clean transition)
- [x] No state → use_role → exit_role → no state
- [x] No state → use_agent → exit_agent → no state
- [x] Agent active → use_role_obj errors
- [ ] Agent → exit_agent → use_role (clean transition) (async)
## Additional behaviors tested (not in original plan)
- [x] state() empty context returns empty flags
- [x] state() role only → ROLE flag
- [x] state() empty session → SESSION_EMPTY flag
- [x] state() role + session flags combine
- [x] discontinuous_last_message noop when no last_message
- [x] before_chat_completion creates LastMessage with empty output and continuous=true
- [x] role_like_mut returns None when no active scope
- [x] role_like_mut returns role when only role active
- [x] role_like_mut prefers session over role
- [x] session_file handles subdir/name format
- [x] is_compressing_session false with no session
- [x] is_compressing_session false with default session
## Old code reference
- `src/config/request_context.rs` — all methods