Skip to content

Fail fstat for chains.py alone in the descriptor test (closes #713) - #714

Merged
pmazzocchi merged 1 commit into
mainfrom
iss-713-fstat-fake-capture
Oct 29, 2026
Merged

pmazzocchi merged 1 commit into
mainfrom
iss-713-fstat-fake-capture

Conversation

@fametrano

Copy link
Copy Markdown
Member

deps-latest is red on main because a test in tests/chains_test.py replaced os.fstat for the whole process. pytest 9.2.0's capture calls os.fstat on its own buffer at the end of the call phase, before the monkeypatch is undone, so the fake failed pytest itself (PR pytest-dev/pytest#14687). cookie_auth behaves correctly.

The test now gives chains.py alone a copy of os whose fstat fails, and its match names the fake's error. The issue proposed a fake that delegates to the real fstat for every other file. At the locked pytest nothing reaches that delegate, and tests is under the 100% coverage floor.

Evidence

Each run is the targeted test with -n 0. The pytest 9.2.0 environment is the lock after uv lock --upgrade-package pytest. The mutant removes the os.close(fd) in cookie_auth's fstat except.

test chains.py pytest 9.1.1 (lock) pytest 9.2.0
before (main) main passes fails, OSError: no fstat
this branch main passes passes
this branch mutant fails, descriptor count fails, descriptor count

The whole suite (uv run --locked pytest, coverage 100%), uv run --locked pre-commit run --all-files and the docs build exit 0 on 22fb92a. A deps-latest run dispatched on the branch at e835688 passed on all eight jobs (run 40804121574); 22fb92a differs from it only in a test comment and the commit message. Local review: dedicated reviewer CLEARED e835688, fresh reviewer CLEARED 22fb92a466473c348b10a568d7d673781593bffe.

Closes #713

🤖 Generated with Claude Code

test_a_descriptor_that_cannot_be_inspected_is_closed_and_refused
replaced os.fstat for the whole process. pytest 9.2.0's fd-level
capture calls os.fstat on its own buffer at the end of the call phase,
before the monkeypatch is undone, so the fake failed pytest itself and
deps-latest went red on every cell that runs the test
(PR pytest-dev/pytest#14687). cookie_auth was right throughout: it
closed the descriptor and raised FetchError.

The fake replaces the os module chains.py sees, with fstat failing, so
the code under test is the only caller that meets it. The match names
"no fstat", so the test also shows that it is the fake's error that
cookie_auth turned into FetchError.

The issue proposed a fake that delegates to the real fstat for every
file but the cookie. At the locked pytest nothing reaches that
delegate, and tests is under the 100% coverage floor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Ferdinando Ametrano <[email protected]>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ACK 22fb92a

Not checked: the pull request's evidence table was not run. That is the targeted test with -n 0 at pytest 9.1.1 and at 9.2.0 (after uv lock --upgrade-package pytest), on main's chains.py and on the mutant without os.close(fd).

@fametrano
fametrano enabled auto-merge (squash) October 29, 2026 02:31
@pmazzocchi

Copy link
Copy Markdown
Contributor

Claimed: a /btclib-pr session of pmazzocchi is reviewing this pull request toward approval, night of 2026-10-29. It pushes nothing to the branch without saying so here first.

@pmazzocchi pmazzocchi 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.

Approved at 22fb92a: the descriptor test fails os.fstat for chains.py alone, so pytest 9.2.0's capture keeps working (closes #713).

A fresh review cleared this head: patching bitcoin_core_rpc.chains.os reaches only cookie_auth, the new match= takes the fake's message and no other, and deps-latest dispatched on the branch passed on pytest 9.2.0 in every cell. The only file is a test, the bot acknowledged this sha, no thread is open, and every check passed.

@pmazzocchi
pmazzocchi merged commit 6020f10 into main Oct 29, 2026
25 checks passed
@pmazzocchi
pmazzocchi deleted the iss-713-fstat-fake-capture branch October 29, 2026 16:07
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.

chains_test's fstat fake breaks pytest 9.2.0's capture, turning deps-latest red

2 participants