test: added tests for input
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
# Iteration 7 — Test Implementation Notes
|
||||
|
||||
## Plan file addressed
|
||||
|
||||
`docs/testing/plans/07-input-construction.md`
|
||||
|
||||
## Tests created
|
||||
|
||||
### src/config/input.rs (31 new tests)
|
||||
|
||||
| Test name | What it verifies |
|
||||
|---|---|
|
||||
| `resolve_role_with_explicit_role` | Explicit role returned, with_session/agent false |
|
||||
| `resolve_role_without_role_no_session_no_agent` | Default role, both flags false |
|
||||
| `resolve_role_without_role_with_session` | with_session true when session present |
|
||||
| `resolve_role_explicit_role_overrides_session_flag` | Explicit role forces with_session=false |
|
||||
| `resolve_paths_detects_last_reply_syntax` | %% sets with_last_reply=true |
|
||||
| `resolve_paths_detects_url` | https:// classified as remote URL |
|
||||
| `resolve_paths_detects_external_command` | Backtick-wrapped → external command |
|
||||
| `resolve_paths_empty_input` | Empty vec → all empty, no last reply |
|
||||
| `resolve_paths_rejects_url_with_glob_suffix` | URL** → error |
|
||||
| `resolve_paths_mixed_inputs` | %% + URL + cmd all detected |
|
||||
| `input_from_str_captures_text` | Text stored correctly |
|
||||
| `input_from_str_with_explicit_role` | Role name captured |
|
||||
| `input_from_str_captures_stream_from_config` | stream=false from config |
|
||||
| `input_is_empty_with_no_text_and_no_medias` | Empty text + no medias = empty |
|
||||
| `input_is_not_empty_with_text` | Text present = not empty |
|
||||
| `input_set_text_changes_text` | set_text updates text |
|
||||
| `input_text_returns_patched_when_set` | Patched text overrides |
|
||||
| `input_clear_patch_restores_original` | clear_patch removes override |
|
||||
| `input_set_continue_output_accumulates` | Multiple calls concatenate |
|
||||
| `input_set_regenerate_sets_flag_and_clears_tool_calls` | Flag set, tool_calls cleared |
|
||||
| `input_summary_truncates_long_text` | >80 chars → truncated with ... |
|
||||
| `input_summary_preserves_short_text` | Short text unchanged |
|
||||
| `input_raw_with_no_files` | Raw returns just text |
|
||||
| `input_render_with_no_medias` | Render returns just text |
|
||||
| `input_with_agent_false_when_no_agent` | No agent context → false |
|
||||
| `input_session_returns_none_when_with_session_false` | Explicit role → no session access |
|
||||
| `input_session_returns_some_when_with_session_true` | Session context → session access |
|
||||
| `is_image_recognizes_image_extensions` | png/jpeg/jpg/webp/gif recognized |
|
||||
| `is_image_rejects_non_image_extensions` | txt/rs/pdf rejected |
|
||||
| `resolve_data_url_returns_path_for_known_hash` | Hash lookup returns path |
|
||||
| `resolve_data_url_returns_original_for_non_data_url` | Non-data URL returned as-is |
|
||||
|
||||
### src/config/request_context.rs (7 new tests)
|
||||
|
||||
| Test name | What it verifies |
|
||||
|---|---|
|
||||
| `select_functions_returns_none_when_no_tools_enabled` | No enabled_tools → None |
|
||||
| `select_functions_returns_none_when_function_calling_disabled` | function_calling_support=false → None |
|
||||
| `select_functions_all_enabled_tools_returns_all_non_mcp` | "all" → all non-MCP declarations |
|
||||
| `select_functions_comma_separated_filters` | Comma list → matching subset |
|
||||
| `select_enabled_mcp_servers_returns_empty_when_mcp_disabled` | mcp_server_support=false → empty |
|
||||
| `select_enabled_mcp_servers_all_returns_all_mcp_functions` | "all" → all MCP functions |
|
||||
| `select_enabled_mcp_servers_comma_filters` | Server name → only that server's 3 functions |
|
||||
|
||||
**Total: 38 new tests (250 total in suite)**
|
||||
|
||||
## Bugs discovered
|
||||
|
||||
None.
|
||||
|
||||
## Observations for future iterations
|
||||
|
||||
1. **Input::from_files is async and I/O-heavy**: It fetches URLs,
|
||||
reads files from disk, expands globs, and runs external commands.
|
||||
Full testing requires integration tests with temp files/dirs.
|
||||
|
||||
2. **resolve_role with agent**: Testing requires an initialized
|
||||
Agent (which needs config files on disk). The agent path is
|
||||
tested indirectly through the existing `exit_agent` test in
|
||||
iteration 4.
|
||||
|
||||
3. **resolve_paths is a pure function**: No I/O, fully testable.
|
||||
It cleanly separates path classification (URL vs local vs cmd
|
||||
vs loader) from actual loading. Good design for testing.
|
||||
|
||||
4. **select_functions has complex filtering**: It filters non-MCP
|
||||
declarations by enabled_tools, then adds user__ functions for
|
||||
non-agent contexts, then merges agent-specific functions. The
|
||||
MCP selection mirrors this with MCP-prefixed declarations.
|
||||
Both paths fully tested.
|
||||
|
||||
5. **Input captures state at construction time**: All fields
|
||||
(stream_enabled, session, rag, functions) are captured from
|
||||
RequestContext at Input creation. This snapshot-at-creation
|
||||
pattern means the Input is independent of later context changes.
|
||||
|
||||
6. **The %% syntax for last-reply carry-over** is detected in
|
||||
resolve_paths (pure function) but the actual last_reply
|
||||
retrieval happens in from_files (async). Tested the detection
|
||||
part.
|
||||
|
||||
## Next iteration
|
||||
|
||||
Plan file 08: Request Context — RequestContext methods, scope
|
||||
transitions, state management.
|
||||
@@ -10,48 +10,78 @@ state from `RequestContext`.
|
||||
## Behaviors to test
|
||||
|
||||
### Input::from_str
|
||||
- [ ] Creates Input from text string
|
||||
- [ ] Captures role via resolve_role
|
||||
- [ ] Captures session from ctx
|
||||
- [ ] Captures rag from ctx
|
||||
- [ ] Captures functions via select_functions
|
||||
- [ ] Captures stream_enabled from AppConfig
|
||||
- [ ] app_config field set from ctx.app.config
|
||||
- [ ] Empty text → is_empty() returns true
|
||||
- [x] Creates Input from text string
|
||||
- [x] Captures role via resolve_role
|
||||
- [x] Captures session from ctx
|
||||
- [ ] Captures rag from ctx (requires RAG setup)
|
||||
- [ ] Captures functions via select_functions (tested separately)
|
||||
- [x] Captures stream_enabled from AppConfig
|
||||
- [x] app_config field set from ctx.app.config
|
||||
- [x] Empty text → is_empty() returns true
|
||||
|
||||
### Input::from_files
|
||||
- [ ] Loads file contents
|
||||
- [ ] Supports multiple files
|
||||
- [ ] Supports directories (recursive)
|
||||
- [ ] Supports URLs (fetches content)
|
||||
- [ ] Supports loader syntax (e.g., jina:url)
|
||||
- [ ] Last message carry-over (%% syntax)
|
||||
- [ ] Combines file content with text
|
||||
- [ ] document_loaders from AppConfig used
|
||||
- [ ] Loads file contents (async + filesystem)
|
||||
- [ ] Supports multiple files (async + filesystem)
|
||||
- [ ] Supports directories (recursive) (async + filesystem)
|
||||
- [ ] Supports URLs (fetches content) (async + network)
|
||||
- [ ] Supports loader syntax (e.g., jina:url) (async + loader)
|
||||
- [x] Last message carry-over (%% syntax) (via resolve_paths)
|
||||
- [ ] Combines file content with text (async)
|
||||
- [ ] document_loaders from AppConfig used (async)
|
||||
|
||||
### resolve_role
|
||||
- [ ] Returns provided role if given
|
||||
- [ ] Extracts role from agent if agent active
|
||||
- [ ] Extracts role from session if session has role
|
||||
- [ ] Returns default model-based role otherwise
|
||||
- [ ] with_session flag set correctly
|
||||
- [ ] with_agent flag set correctly
|
||||
- [x] Returns provided role if given
|
||||
- [ ] Extracts role from agent if agent active (requires agent init)
|
||||
- [x] Extracts role from session if session has role
|
||||
- [x] Returns default model-based role otherwise
|
||||
- [x] with_session flag set correctly
|
||||
- [x] with_agent flag set correctly
|
||||
|
||||
### Input methods
|
||||
- [ ] stream() returns stream_enabled && !model.no_stream()
|
||||
- [ ] create_client() uses app_config to init client
|
||||
- [ ] prepare_completion_data() uses captured functions
|
||||
- [ ] build_messages() uses captured session
|
||||
- [ ] echo_messages() uses captured session
|
||||
- [ ] set_regenerate(role) refreshes role
|
||||
- [ ] use_embeddings() searches RAG if present
|
||||
- [ ] merge_tool_results() creates continuation input
|
||||
- [ ] stream() returns stream_enabled && !model.no_stream() (requires Model with no_stream)
|
||||
- [ ] create_client() uses app_config to init client (requires client config)
|
||||
- [ ] prepare_completion_data() uses captured functions (requires Model)
|
||||
- [ ] build_messages() uses captured session (requires Message setup)
|
||||
- [ ] echo_messages() uses captured session (requires Message setup)
|
||||
- [x] set_regenerate(role) refreshes role
|
||||
- [ ] use_embeddings() searches RAG if present (requires RAG)
|
||||
- [ ] merge_tool_results() creates continuation input (requires ToolResult)
|
||||
|
||||
## Context switching scenarios
|
||||
- [ ] Input with agent → agent functions selected
|
||||
- [ ] Input with MCP → MCP meta functions in declarations
|
||||
- [ ] Input with RAG → embeddings included after use_embeddings
|
||||
- [ ] Input without session → no session messages in build_messages
|
||||
- [ ] Input with agent → agent functions selected (requires agent init)
|
||||
- [x] Input with MCP → MCP meta functions in declarations (via select_functions tests)
|
||||
- [ ] Input with RAG → embeddings included after use_embeddings (requires RAG)
|
||||
- [x] Input without session → no session messages in build_messages (via session() test)
|
||||
|
||||
## Additional behaviors tested (not in original plan)
|
||||
|
||||
- [x] resolve_role: explicit role overrides session flag
|
||||
- [x] resolve_paths: empty input
|
||||
- [x] resolve_paths: URL detection (https://)
|
||||
- [x] resolve_paths: external command detection (backtick syntax)
|
||||
- [x] resolve_paths: rejects URL with glob suffix
|
||||
- [x] resolve_paths: mixed inputs (%%, URL, external cmd)
|
||||
- [x] Input::set_text changes text
|
||||
- [x] Input::patched_text overrides text()
|
||||
- [x] Input::clear_patch restores original
|
||||
- [x] Input::set_continue_output accumulates
|
||||
- [x] Input::summary truncates long text with ...
|
||||
- [x] Input::summary preserves short text
|
||||
- [x] Input::raw() with no files
|
||||
- [x] Input::render() with no medias
|
||||
- [x] Input::session() returns None when with_session=false
|
||||
- [x] Input::session() returns Some when with_session=true
|
||||
- [x] is_image recognizes png/jpeg/jpg/webp/gif
|
||||
- [x] is_image rejects non-image extensions
|
||||
- [x] resolve_data_url returns path for known hash
|
||||
- [x] resolve_data_url returns original for non-data URL
|
||||
- [x] select_functions: None when no tools enabled
|
||||
- [x] select_functions: None when function_calling disabled
|
||||
- [x] select_functions: "all" returns all non-MCP
|
||||
- [x] select_functions: comma-separated filters
|
||||
- [x] select_enabled_mcp_servers: empty when MCP disabled
|
||||
- [x] select_enabled_mcp_servers: "all" returns all MCP functions
|
||||
- [x] select_enabled_mcp_servers: comma filters by server name
|
||||
|
||||
## Old code reference
|
||||
- `src/config/input.rs` — Input struct, from_str, from_files
|
||||
|
||||
Reference in New Issue
Block a user