test(ai): add unit coverage for pure helpers in ai.py (#55) #69
Loading…
Reference in a new issue
No description provided.
Delete branch "test/issue-55-ai-pure-helpers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #55.
ai.pywas documented as fully exempt from unit testing because the dir loop and synthesis pass require a live Anthropic API. But several helpers in the module are pure functions with no API dependency, and they're the kind of thing that breaks silently. The #57 refactor added two more (_build_dir_loop_context,_flush_partial_dir_entry) that are also naturally testable.New file:
tests/test_ai_pure.py— 45 tests across 8 helpers_should_skip_dir*.egg-infoglob, no-match (3 sub-cases)_path_is_safe_default_survey_filter_dir_toolsunchanged_format_survey_block_filter_dir_tools_format_survey_signals_block_to_dict_flush_partial_dir_entry(added by #57)Uses the same
_make_manager()pattern astest_cache.pyto construct a_CacheManagerrooted in a tempdir, sidesteppingCACHE_ROOTentirely.Doc updates
CLAUDE.md,README.md,docs/wiki/DevelopmentGuide.md:ai.pyis no longer fully exempt. Only the API-dependent loops are. Pure helpers are covered bytest_ai_pure.py. The wiki update is in a separate commit on the wiki repo.Verification
tempfile.mkdtemp().Notable
_filter_dir_toolswas the riskiest helper per the issue, with the most branching. The threshold-boundary case (confidence == _SURVEY_CONFIDENCE_THRESHOLD) confirmed the gate is<not<=— keeping that pinned in a test makes future tweaks loud._path_is_safe(/tmp/foovs/tmp/foo_sibling) is the easy-to-miss path-traversal edge case. Now pinned.