Read stdin via sys.stdin for cross-platform support (closes #640)#644
Conversation
`_load_and_parse(path)` in `vera/cli.py` previously handled stdin
input by calling `Path('/dev/stdin').read_text()`. On Unix that
worked because /dev/stdin is a kernel-provided special file
mapping to fd 0; on Windows the path doesn't exist as a
filesystem entry, so the path-based read raised
`FileNotFoundError` and `vera <subcommand> /dev/stdin` failed
with "Error: file not found: /dev/stdin".
Six failing tests on the post-#637 windows-latest matrix
entries: `tests/test_cli.py::TestStdinInput::*`.
Fix: when `path in _STDIN_PATHS` (already a frozenset of `"-"`
and `"/dev/stdin"`), read directly from `sys.stdin` instead of
going through Path. Portable across Unix and Windows; also more
semantically correct — the user's intent is "read from the
process's stdin", not "read from a specific file path".
Existing 7 `TestStdinInput::*` tests pass unchanged on Unix
(the path-vs-stdin distinction was an implementation detail);
they should now also pass on the windows-latest matrix entries
once #639's advisory CI picks this up.
Module resolution and output-path defaults are unchanged: stdin
still resolves to `Path.cwd() / "stdin.vera"` for the logical
path, so `vera compile /dev/stdin` writes `stdin.wasm` in CWD
and module imports resolve from CWD (not from `/dev/`).
Closes #640.
Co-Authored-By: Claude <noreply@anthropic.invalid>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
Changesstdin Input Support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related issues
Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #644 +/- ##
==========================================
- Coverage 90.97% 90.97% -0.01%
==========================================
Files 59 59
Lines 23134 23137 +3
Branches 259 259
==========================================
+ Hits 21047 21048 +1
- Misses 2080 2082 +2
Partials 7 7
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:
|
Closes the third sub-issue from PR #639's matrix-expansion follow-up cluster (#641 cp1252 file I/O encoding) and flips the Windows matrix entries from advisory to strict. This is the "now works on Windows" release. Set PYTHONUTF8=1 in the CI test job environment so Python's text-mode open() defaults to UTF-8 regardless of locale (PEP 540). Covers all CI-side encoding failures with a single config change rather than auditing ~30 individual call sites. Closes ~9 failing tests across test_codegen.py, test_codegen_monomorphize.py, test_codegen_closures.py, test_html.py. Also added explicit encoding='utf-8' to vera/parser.py's grammar load — the load-bearing site that runs on every parse, so users on Windows without PYTHONUTF8=1 in their shell still get correct grammar loading (defense-in-depth). Filed #645 for the broader audit (every text-mode open() / read_text() / write_text() call site for explicit encoding) as the durable fix. Drop continue-on-error advisory mode PR #639 added Windows entries with continue-on-error: ${{ matrix.os == 'windows-latest' }} so failures didn't block merges while #640, sub-issues now closed (PR for #642 sanitises Windows paths in test fixtures; PR for #640 reads sys.stdin cross-platform; this PR closes #641). The continue-on-error line is removed in this release; the matrix is now fully strict across all 9 entries (ubuntu / macos / windows × 3.11 / 3.12 / 3.13). Version bump 0.0.142 → 0.0.143 This is the Windows-compatibility milestone — the project went from "untested on Windows" to "Windows is a strict gate" in three sequential PRs (#643 / #644 / this). Marking with a minor version bump and "now works on Windows" framing in CHANGELOG. Co-Authored-By: Claude <noreply@anthropic.invalid>
The post-#637 Windows CI rollout (PRs #639/#643/#644/#646) hit three test-fixture footguns — `tempfile.NamedTemporaryFile`'s delete-while-open behaviour, Windows paths embedded in Vera string literals tripping the `\U` escape, and cp1252 default file I/O encoding. Each had a portable workaround. Added a "Test Fixture Conventions" section to TESTING.md (immediately before "Adding Tests") with the three rules + their canonical wrong/right code snippets. Each rule cites the test that surfaced the bug + the PR that fixed it. Added a brief "Cross-platform pitfalls" section to CLAUDE.md's project-orientation footer that points at the TESTING.md section. The CLAUDE.md entry is a one-bullet pointer per rule, not a full repeat — keeping the substantive content in TESTING.md as the single source of truth. These notes will save the next contributor (or agent) from re-discovering the same footguns. Co-Authored-By: Claude <noreply@anthropic.invalid>
Summary
Closes #640.
_load_and_parse(path)invera/cli.pypreviously handled stdin input by callingPath('/dev/stdin').read_text(). On Unix that worked because/dev/stdinis a kernel-provided special file mapping to fd 0; on Windows the path doesn't exist as a filesystem entry, so the path-based read raisedFileNotFoundErrorandvera <subcommand> /dev/stdinfailed with "Error: file not found: /dev/stdin".Failing tests on Windows (pre-fix)
All 6 in
tests/test_cli.py::TestStdinInput:test_check_reads_source_oncetest_run_dev_stdin_subprocesstest_verify_dev_stdin_subprocesstest_compile_dev_stdin_wattest_compile_dev_stdin_default_outputtest_check_dev_stdin_module_resolutionFix
When
path in _STDIN_PATHS(already a frozenset of"-"and"/dev/stdin"), read directly fromsys.stdininstead of going throughPath. Portable across Unix and Windows; also more semantically correct — the user's intent is "read from the process's stdin", not "read from a specific file path".Behaviour preservation
TestStdinInputtests pass unchanged on Unix (the path-vs-stdin distinction was an implementation detail of the read step).Path.cwd() / "stdin.vera", sovera compile /dev/stdinwritesstdin.wasmin CWD and imports resolve from CWD.-sentinel (also in_STDIN_PATHS) gets the same Windows-portable behaviour as a side benefit.Test plan
TestStdinInputpass on macOS (existing behaviour preserved)windows-latestmatrix entries once this lands (currently advisory; the count of red Windows tests should drop by 6)Part of the #637 follow-up cluster
Sibling PRs: #643 (
\Uescape in test fixtures, addresses #642), and forthcoming PR for #641 (cp1252 file I/O encoding audit + dropscontinue-on-error+ bumps version). Once all three close, the Windows entries become strict gates.🤖 Generated with Claude Code
Summary by CodeRabbit