Skip to content

test: add unit test coverage for zero-test files across tools and util#3739

Open
sandikodev wants to merge 7 commits intoaws:mainfrom
sandikodev:test/delegate-todo-coverage
Open

test: add unit test coverage for zero-test files across tools and util#3739
sandikodev wants to merge 7 commits intoaws:mainfrom
sandikodev:test/delegate-todo-coverage

Conversation

@sandikodev
Copy link
Copy Markdown

@sandikodev sandikodev commented Apr 9, 2026

Motivation

Several files had zero or minimal tests despite containing non-trivial logic. This PR systematically adds unit test coverage for functions that can be tested without a full Os or ChatSession instance.

Files covered

File Tests before Tests added
tools/delegate.rs 1 (schema only) +8
tools/todo.rs 0 +9
tools/thinking.rs 0 +4
tools/introspect.rs 0 +3
tools/custom_tool.rs 0 +4
tools/knowledge.rs 0 +4
tools/mod.rs 2 +3
util/paths.rs 0 +5

What is tested

  • Deserialization of all major tool variants (Delegate, TodoList, Knowledge, Thinking, Introspect)
  • Pure functions: truncate_description, format_launch_success, has_duplicates, generate_new_todo_id, default_timeout, add_gitignore_globs, canonicalizes_path
  • Default values: AgentStatus::default, TransportType::default
  • Edge cases: empty strings, tilde expansion, dotdot resolution, invalid glob patterns

Testing

cargo test -p chat_cli

381 passed, 0 failed (up from 328 before this PR).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…and deserialization

todo.rs had zero tests. Add coverage for:
- has_duplicates: empty, unique, and duplicate cases
- generate_new_todo_id: uniqueness (with sleep) and numeric format
- TodoList deserialization: Create, Complete, Add, Remove variants
Add three additional tests covering:
- absolute path passes through unchanged
- empty string does not panic
- tilde only expands at the start of a path, not in the middle
…tion

custom_tool.rs:
- default_timeout is 120_000ms (2 minutes)
- get_default_scopes returns non-empty strings
- TransportType::default() is Stdio

knowledge.rs:
- TodoList deserialization for Add, Search, Remove, Clear variants
thinking.rs (was 0 tests):
- deserialization
- invoke returns empty output
- validate accepts both empty and non-empty thoughts

introspect.rs (was 0 tests):
- deserialization with and without query
- validate always succeeds
…zation

delegate.rs had only 1 test (get_schema). Add coverage for:
- truncate_description: period truncation, long string, short string
- format_launch_success: contains agent name and task
- AgentStatus::default is Running
- Delegate deserialization: Launch with task, Status without agent
- resolve_agent_name fallback chain (explicit > configured > default)
…_path

paths.rs had zero tests. Add coverage for:
- add_gitignore_globs: matches file and children, trailing slash, invalid pattern error
- canonicalizes_path: absolute path, dotdot resolution
@sandikodev sandikodev changed the title test(todo): add unit tests for has_duplicates, generate_new_todo_id, and deserialization test: add unit test coverage for zero-test files across tools and util Apr 12, 2026
env_var.rs had zero tests. Add coverage for:
- get_mock_chat_response: present and absent
- is_sigv4_enabled: with value, empty value, absent
- get_editor: returns non-empty string

Uses Env::from_slice (the correct test pattern) instead of std::env::set_var
since Env::new() in test mode uses a Fake backend that ignores real env vars.
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.

1 participant