Skip to content

Read stdin via sys.stdin for cross-platform support (closes #640)#644

Merged
aallan merged 3 commits into
mainfrom
claude/issue-640-stdin-windows
May 10, 2026
Merged

Read stdin via sys.stdin for cross-platform support (closes #640)#644
aallan merged 3 commits into
mainfrom
claude/issue-640-stdin-windows

Conversation

@aallan

@aallan aallan commented May 10, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #640.

_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".

Failing tests on Windows (pre-fix)

All 6 in tests/test_cli.py::TestStdinInput:

  • test_check_reads_source_once
  • test_run_dev_stdin_subprocess
  • test_verify_dev_stdin_subprocess
  • test_compile_dev_stdin_wat
  • test_compile_dev_stdin_default_output
  • test_check_dev_stdin_module_resolution

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".

Behaviour preservation

  • All 7 existing TestStdinInput tests pass unchanged on Unix (the path-vs-stdin distinction was an implementation detail of the read step).
  • Logical path / module resolution / output naming unchanged: stdin still resolves to Path.cwd() / "stdin.vera", so vera compile /dev/stdin writes stdin.wasm in CWD and imports resolve from CWD.
  • - sentinel (also in _STDIN_PATHS) gets the same Windows-portable behaviour as a side benefit.

Test plan

  • All 7 tests in TestStdinInput pass on macOS (existing behaviour preserved)
  • Full pytest suite green (3,782 passed, 14 skipped)
  • All 6 Windows-failing tests pass on the windows-latest matrix 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 (\U escape in test fixtures, addresses #642), and forthcoming PR for #641 (cp1252 file I/O encoding audit + drops continue-on-error + bumps version). Once all three close, the Windows entries become strict gates.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved CLI stdin handling for portability: the tool now correctly accepts piped input (including cases previously using /dev/stdin) and normalises the logical stdin path for module resolution/output naming, resolving Windows “file not found” failures and addressing related failing stdin tests.

Review Change Stack

`_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>
@coderabbitai

coderabbitai Bot commented May 10, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fe19ac8f-333c-481e-9900-70ce1d0818b5

📥 Commits

Reviewing files that changed from the base of the PR and between 27af93b and 7fddb60.

📒 Files selected for processing (1)
  • CHANGELOG.md

📝 Walkthrough

Walkthrough

_load_and_parse() in vera/cli.py now detects stdin markers ("-" and "/dev/stdin") and reads source text directly from sys.stdin instead of the filesystem. The returned logical path is normalised to Path.cwd() / "stdin.vera" for portable module resolution, whilst diagnostics retain the original CLI path argument.

Changes

stdin Input Support

Layer / File(s) Summary
Specification
vera/cli.py
Docstring clarifies stdin detection, sys.stdin reading, and the semantic distinction between logical path (module resolution) and original path (diagnostics).
Implementation
vera/cli.py
Conditional logic detects stdin markers and reads from sys.stdin; logical path normalised to CWD-relative stdin.vera; filesystem paths unchanged.
Changelog
CHANGELOG.md
Added Unreleased → Fixed note for #640 describing the stdin portability fix and closed failing stdin tests.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

  • aallan/vera#640: This PR addresses the Windows-compatibility stdin handling problem by implementing cross-platform detection of stdin markers and direct sys.stdin reading.

Possibly related PRs

  • aallan/vera#411: Both PRs modify stdin handling in vera/cli.py to avoid double-reading /dev/stdin and normalise the logical path for stdin inputs.

Suggested labels

compiler, docs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarises the primary change: replacing /dev/stdin file-system access with sys.stdin reading to resolve Windows portability issues, directly addressing issue #640.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issue-640-stdin-windows

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented May 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.97%. Comparing base (9c8dd83) to head (7fddb60).

Files with missing lines Patch % Lines
vera/cli.py 66.66% 2 Missing ⚠️
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              
Flag Coverage Δ
javascript 57.36% <ø> (ø)
python 94.76% <66.66%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aallan aallan merged commit 6922fe6 into main May 10, 2026
19 of 22 checks passed
@aallan aallan deleted the claude/issue-640-stdin-windows branch May 10, 2026 22:30
aallan added a commit that referenced this pull request May 10, 2026
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>
aallan added a commit that referenced this pull request May 10, 2026
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>
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.

Vera CLI's /dev/stdin is Unix-only — add Windows-compatible stdin handling

1 participant