Skip to content

test(lint): ban process.cwd() / Path.cwd() outside canonical resolvers (closes #863) - #1173

Closed
bassilkhilo-ag2 wants to merge 1 commit into
sonichi:mainfrom
bassilkhilo-ag2:test/cwd-lint-863
Closed

bassilkhilo-ag2 wants to merge 1 commit into
sonichi:mainfrom
bassilkhilo-ag2:test/cwd-lint-863

Conversation

@bassilkhilo-ag2

Copy link
Copy Markdown
Collaborator

Summary

How the test works

# Strip line comments, then check for the CWD pattern
code_line = strip_comment(raw_line)
if cwd_pattern.search(code_line):
    violation!

Any new src/ file that writes workspace data via process.cwd() or Path.cwd() directly — instead of routing through resolveWorkspace() / resolve_workspace() — will fail CI immediately.

Test plan

  • python3 tests/cwd-lint.test.py — 12/12 passing
  • No current violations in src/ (confirms the 2026-05-18 audit is still clean)
  • Comment-line false-positive exclusion verified by dedicated tests

closes sonichi#863)

12 structural tests that fail-build when any src/*.py uses Path.cwd() /
os.getcwd() outside workspace_default.py + util_paths.py, or any src/*.ts
uses process.cwd() outside workspace_default.ts + util_paths.ts.

Prevents re-introducing the workspace-vs-repo bug class that the 2026-05-18
audit (PRs sonichi#815-sonichi#859) closed across ~28 sites. Comment lines are stripped
before checking so the existing "# old code used process.cwd()" annotations
in inline-tools.ts / browser-tools.ts / cartesia-tts.ts don't false-positive.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@VasiliyRad VasiliyRad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

12/12 passing, rule is well-scoped (src/.py and src/.ts only, correct allowlists), comment stripping works. Single-file PR with no unrelated changes. One minor gap: block comments (/* */) in TypeScript aren't stripped, but that's an unlikely false-positive path in practice. Clean.

@VasiliyRad VasiliyRad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

12/12 passing, rule is well-scoped (src/.py and src/.ts only, correct allowlists), comment stripping works. Single-file PR with no unrelated changes. One minor gap: block comments (/* */) in TypeScript aren't stripped, but that's an unlikely false-positive path in practice. Clean.

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.

lint: ban process.cwd() / Path.cwd() writes outside canonical resolvers

2 participants