fix(affected): resolve TypeScript workspaces + path normalization (closes #176)#184
Merged
Merged
Conversation
…oses #176) Bug: codelens affected /path/to/ws auth/file.ts returned affected_count: 0 and put the workspace path in unresolved[]. Three root causes: 1. Argparse greedy-absorb: files (nargs="*") absorbed ALL positional args, leaving workspace=None. CLI dispatcher auto-detected workspace to cwd, which was wrong. Fix: in execute(), detect if first item in files is an existing directory that differs from the resolved workspace — treat it as the intended workspace. 2. lstrip('./') bug: cf.replace('\\','/').lstrip('./') is a char-set strip, not a prefix strip. It corrupted '../foo.ts' into 'foo.ts'. Fix: replace with a while loop that strips './' prefix only. 3. Path separator mismatch: os.path.relpath uses backslashes on Windows, but user input (e.g. from git diff --name-only) uses forward slashes. Fix: normalize all known files to forward slashes before matching, and build a norm_to_orig mapping to resolve back to original form. Tests: 8 new tests in TestIssue176TypeScriptAffected covering: - workspace-as-first-arg resolution - affected_count > 0 for TS file with dependents - --include-source returns all dependents - absolute changed path resolves - basename-only resolves - ./ prefix strips correctly (lstrip bug regression) - ../ path not corrupted (lstrip bug regression) - backward compat: no workspace arg uses cwd All 58 test_affected_command.py pass (50 existing + 8 new). Regression: 146 passed (test_cli + test_doctor + test_affected + test_command_registry + test_command_count). Definition of Done (issue #176): - [x] codelens affected <workspace> auth/file.ts returns correct dependents - [x] Works on Unix (/) and Windows (backslash) path separators - [x] unresolved[] is empty when input file exists in scan graph - [x] Test added: TS fixture with import chain, asserts affected returns known dependents
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
This was referenced Jul 3, 2026
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.



What
Fixes
codelens affectedreturningaffected_count: 0and putting the workspace path inunresolved[]when run against a TypeScript project. Three root causes identified and fixed.Why (issue #176)
codelens affected /path/to/ts-workspace auth/google-auth-cache.tswas a no-op for TypeScript projects. The command returned:{ "unresolved": ["/path/to/ts-workspace", "auth/google-auth-cache.ts"], "affected_count": 0 }Three root causes:
Root cause 1: argparse greedy-absorb
affected.pydefinesfileswithnargs="*"(greedy) andworkspacewithnargs="?". argparse assigns ALL positional args tofiles, leavingworkspace=None. The CLI dispatcher then auto-detects workspace to cwd — wrong when user explicitly passed a workspace path.Fix: In
execute(), detect if the first item infilesis an existing directory that differs from the resolved workspace. If so, treat it as the intended workspace and remove it from the changed-files list. Non-breaking: if the first arg is a file (not a dir), old behavior is preserved.Root cause 2:
lstrip("./")bugcf.replace('\\','/').lstrip('./')is a char-set strip, not a prefix strip.lstriptreats the argument as a set of characters to remove, so"../foo.ts"becomes"foo.ts"(corrupted!).Fix: Replace with a
whileloop that strips"./"prefix only:Root cause 3: path separator mismatch
os.path.relpathuses backslashes on Windows, but user input (e.g. fromgit diff --name-only) uses forward slashes. Direct comparison fails.Fix: Normalize all known files to forward slashes before matching, and build a
norm_to_origmapping to resolve back to the original form.Files touched
scripts/commands/affected.py— workspace detection heuristic (18 lines added)scripts/dependents_engine.py— path normalization + lstrip fix (33 lines changed)tests/test_affected_command.py— 8 new tests inTestIssue176TypeScriptAffected(163 lines added)Verification
New tests — 8 passed
Regression — 146 passed, 0 failed
All 58 test_affected_command.py pass (50 existing + 8 new).
Manual test (Definition of Done)
TS fixture:
auth/google-auth-cache.ts←auth/login.ts←tests/login.test.tsAll DoD scenarios verified:
--include-sourcereturns 3 files (google-auth-cache + login + test)./prefix strips correctly../path not corrupted (lstrip bug regression)Definition of Done (issue #176)
codelens affected <workspace> auth/google-auth-cache.tsreturns correct dependents/) and Windows (\) path separators (normalization added)unresolved[]is empty when the input file exists in the scan graphaffectedreturns known dependentsIssue link
Closes #176 — #176