Fix tokens compare in subdirectory showing all files as "added"#105
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes waza tokens compare behavior when executed from a subdirectory of a git repo, where files were incorrectly classified as “added” due to inconsistent path resolution between git ls-tree and git show.
Changes:
- Adjust
GetFileFromRefto prefix paths with./sogit show <ref>:./<file>resolves relative to the current working directory. - Add a regression test to ensure subdirectory execution reports modified files as modified (📈) rather than added (🆕).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cmd/waza/tokens/internal/git/git.go | Updates git show invocation to align path resolution with subdirectory execution. |
| cmd/waza/tokens/compare_test.go | Adds a regression test covering tokens compare when run from a subdirectory. |
Related to microsoft#105 Proactive test cases for the action_sequence grader. Written from the spec while Linus implements. Covers: exact_match, in_order_match, any_order_match modes, score calculations, error cases, and factory integration. **Test breakdown (31 test cases):** - Constructor validation: 6 tests (missing actions, empty actions, invalid mode, valid modes) - exact_match mode: 6 tests (pass, extra step, missing step, wrong order, empty actual, single tool) - in_order_match mode: 5 tests (exact seq, extras interspersed, wrong order, missing step, subset order) - any_order_match mode: 5 tests (reordered, extras, missing, duplicate expected, insufficient duplicates) - Score calculations: 4 tests (perfect, partial, zero, details verification + f1 check) - Edge cases: 3 tests (nil session, nil tools_used, duration recording) - Factory integration: 2 tests (Create success, Create invalid params error) **Note:** These tests depend on the implementation in the companion PR. Merge the implementation PR first.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #105 +/- ##
=======================================
Coverage ? 72.83%
=======================================
Files ? 130
Lines ? 14826
Branches ? 0
=======================================
Hits ? 10799
Misses ? 3222
Partials ? 805
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
wbreza
left a comment
There was a problem hiding this comment.
Code Review: PR #105 — Fix tokens compare in subdirectory showing all files as "added"
✅ What Looks Good
- Clear root cause analysis — PR description is excellent, explains the
ls-treevsgit showpath resolution mismatch thoroughly - Surgical fix — only 2 call sites changed, preserving
GetFileFromReffor callers that intentionally want repo-root paths (e.g., reading.waza.yaml) - Comprehensive tests — 4 unit subtests for
GetCWDFileFromRef(repo root, subdirectory, repo-root file invisible from subdir, confirming old function unchanged) + regression test + two-ref skills test - Proper error wrapping —
ErrFileNotFoundsentinel makes it easy for callers to distinguish missing files from git errors
🟡 Medium (1 finding)
1. Inconsistent error handling patterns — GetFileFromRef uses errors.AsType[*exec.ExitError] (generics-based) while GetCWDFileFromRef uses errors.As(err, &exitErr) (traditional). Same file, same purpose — consider using one pattern consistently.
Summary
| Priority | Count |
|---|---|
| Critical | 0 |
| High | 0 |
| Medium | 1 |
| Low | 0 |
Overall Assessment: Approve — clean, well-documented bug fix with thorough test coverage.
When running
waza tokens comparefrom a subdirectory of a git repository, all files were incorrectly reported as added instead of modified . The "Before" column showed-for every file, even though the files existed at the base ref:Root Cause
A mismatch between how two git commands resolve file paths when the working directory is a subdirectory of the repository:
git ls-tree -r --name-only HEAD(used byGetFilesFromRef) is CWD-aware — it returns paths relative to the current directory (e.g.,README.md).git show HEAD:README.md(used byGetFileFromRef) treats the path as repo-root-relative — so it looks forREADME.mdat the repository root, not atsubdir/README.md.When the file doesn't exist at the repo root,
git showfails. The error is silently caught (by design, matching the TypeScript implementation), causinghasBaseto remainfalseand every file to be classified as "added".Fix
Added a new
GetCWDFileFromReffunction that uses a./path prefix to resolvefiles relative to the working directory (matching
ls-tree's behavior):compareFilesetsnow usesGetCWDFileFromReffor reading file content (wherepaths come from CWD-relative
ls-treeoutput), whileGetFileFromRefremainsrepo-root-relative for callers that intentionally read root-level files (e.g.,
skillRootsForRefreading.waza.yamlat a ref).Changed Files
cmd/waza/tokens/internal/git/git.go— addedGetCWDFileFromRef; updatedGetFileFromRefdoc to clarify repo-root path resolutioncmd/waza/tokens/internal/git/git_test.go— addedTestGetCWDFileFromRefwith 4 subtestscmd/waza/tokens/compare.go—compareFilesetsusesGetCWDFileFromReffor file content readscmd/waza/tokens/compare_test.go— addedTestCompare_Subdirectoryregression test; added--skillstwo-ref test