fix(deps): anchor index resolution to target path; add fresh deps exraction - #79
Merged
Merged
Conversation
…raction
Two related fixes around dependency extraction safety.
1. CLI index-resolution data-loss bug
`cocosearch deps extract <path>` (and `index <path>`) resolved the index
name from the caller's cwd, not the target path. All three resolution
steps — config discovery, git derivation, and the derived-name fallback —
ignored the path argument. Run from a project directory, `deps extract
/other/repo --fresh` would resolve to *this* project's index and wipe its
edges while re-extracting against the wrong files.
- find_config_file(start_dir=None): anchor config + git-root discovery to a
given directory (git-root lookup now uses `git -C`).
- derive_index_from_git(path=None): forward the path to get_main_repo_root.
- _resolve_index_name: pass fallback_path into the git derivation step.
- deps_extract_command / index_command: anchor config and index-name
resolution to the target codebase path.
Changes are backward compatible (new params default to cwd behavior); the
read-only deps show/tree/impact/stats commands are intentionally untouched
(they take a relative file arg and run in-project).
2. Dashboard "Fresh Extract Deps"
The dashboard "Extract Deps" button only ran incremental extraction, so
files unchanged since a broken/stale index never got re-extracted. Added a
fresh option end to end: /api/extract-deps now accepts a `fresh` flag and
forwards it to extract_dependencies; a red "Fresh Extract Deps" button
mirrors the existing Reindex/Fresh Index two-button pattern.
Tests: find_config_file start_dir anchoring, derive_index_from_git path
forwarding, deps_extract_command regression (resolves from target path), and
/api/extract-deps fresh-flag forwarding (default + explicit).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
index_command received the same cwd-anchoring fix as deps_extract_command but lacked an equivalent regression test. Add one asserting that config discovery (find_config_file) and index-name resolution (_resolve_index_name fallback_path) are anchored to the target codebase path, not the caller's cwd — closing the test-coverage asymmetry between the two commands. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related dependency-extraction safety fixes, discovered while diagnosing why another repository index had thin
dependency data (only workflow-YAML edges, no Python).
cocosearch deps extract resolved the index name from the caller's cwd, not the target path. All three
resolution steps — config discovery (find_config_file), git derivation (derive_index_from_git), and the derived-name
fallback — ignored the path argument.
Impact: run from a project directory, deps extract /other/repo --fresh resolves to this project's index and wipes its
edges while re-extracting against the wrong files. (index had the same latent bug; fallback_path only masked
it when no cwd config existed.)
Fix:
uses git -C)
Backward compatible (new params default to cwd behavior). The read-only deps show/tree/impact/stats commands are
intentionally untouched — they take a relative file arg and are meant to run in-project.
The dashboard "Extract Deps" button only ran incremental extraction, so files unchanged since a stale/broken index
were never re-extracted (the button reported success but did nothing for them). Added a fresh path end to end:
Testing
deps_extract_command regression (resolves from target path, not cwd), /api/extract-deps fresh-flag forwarding
(default + explicit)
different project dir) — now correctly targets the right index and leaves the cwd project's edges untouched