Repository navigation
fix: one traced-run path for verify and the adapter; crash-safe trace writes - #168
Merged
Merged
Conversation
… writes (#154) verify.run and pytest_adapter.run duplicated the temp dir, env, runner and trace load, and refused in different orders and words. Both now go through pytest_adapter.run_traced / load_trace. A _workdir parameter replaces the tests' global patch of tempfile.TemporaryDirectory. - --json refusals print {"refused": true, "error": ...} in both CLIs - tgtrace flushes and fsyncs before os.replace; a non-regular target (/dev/stdout, a FIFO) is written directly - --trace-out is written atomically (write_json_atomic) - harness/trace.py treats an unreadable trace as no trace and removes stale <out>.tmp.* files before a run - adapter trace-refusal tests move to test_pytest_adapter.py; the dying-write tests use an unserializable payload instead of patching json Fixes #154
…review) - F1/F2/F8: one stream rule in both writers (/dev/*, /proc/*, FIFOs are written in place) so /dev/stdout works even when redirected to a file; the adapter's temp is now <path>.tmp.<pid>, like tgtrace's; a parity test holds the two copies in step - F3: a truncated JUnit report is refused (exit 2), not a ParseError - F4: a trace object without tgtrace's tests/declared shape is refused; harness/trace.py treats it as no trace - F5: harness/trace.py refuses a non-regular --out instead of deleting it - F6: the stale-temp sweep takes only .tmp.<digits> of dead pids - F7: unittest.main() moved to the end of the two test files - F9: --trace-out is checked before the suite runs; verify refuses an unreadable registry instead of raising - C1: direct test that a missing JUnit report is no verdicts, not a pass
… review round 2) Writing /dev/stdout in place corrupted it (a second open has its own offset, so pytest's output overwrote the JSON), and the /dev/ prefix rule also caught /dev/shm, an ordinary tmpfs. Stream support is dropped: - one rule, not_a_file_target: abspath, then /dev/ or /proc/ but not /dev/shm/, or an existing non-regular file. tgtrace refuses at pytest_configure; the adapter refuses --trace-out before the run; harness/trace.py imports the adapter's rule. The tgtrace copy is parity-tested, including a child whose stdout is a regular file. - writers keep only temp + fsync + rename - payload_shape_error checks each entry; declared: null stays accepted - verify refuses a registry that is not a JSON object - review test fixtures become mixins, so no inherited test runs twice
…ry (#154 review round 3) - R3-1: pytest calls unconfigure even after configure raised; tgtrace now writes and stops only if tracing started (it had replaced a refused FIFO on 3.11 and raised on 3.12+), for both the stream and xdist refusals - R3-2: the real-pytest tgtrace test skips without pytest (CI matrix) - R3-3: declared ids need only be hashable; covers(1) is a bad declaration for verify to report, not a broken trace - R3-4: the target rule resolves the directory with realpath, so a symlinked parent or //dev is still /dev - R3-5: registry.load refuses JSON that is not an object, for every caller - R3-6: x/, x/. and x/.. are refused; writers normalise the path once - R3-7: a directory --trace-out says so - R3-8/R3-9: one ROOT in harness/trace.py; tests pick writers by key
8 tasks
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.
Fixes #154
What
Every item on #154's list, plus nine defects found while reviewing it:
verify --jsonandpytest_adapter --jsonprint a refusal as{"refused": true, "error": "..."}and still exit 2. Before, they printed prose.verifyand the adapter run pytest through one helper, so they refuse a broken run in the same order and with the same words: a missing trace (with pytest's stderr tail), then a truncated trace, then a trace that isn't a tgtrace object.--trace-outnow writes the same way instead of with a plain open-and-dump./dev/stdout, pipes, other device paths) are refused before any test runs, with a message saying why./dev/shmcounts as a file location.harness/trace.pyreads a broken trace as "no trace" instead of crashing, and removes temp files left behind by killed runs.tempfile.TemporaryDirectoryorjson.dumpfor the whole process. The adapter's trace tests now live intest_pytest_adapter.py.How
pytest_adapter.run_tracedandload_traceare the shared seam. A missing JUnit report is the one place the callers still differ, on purpose. The adapter refuses, because it has nothing to join the trace against.verifyreads it as no verdicts, so every selected journey is reported incomplete, never passed.verify's behaviour is otherwise unchanged.not_a_file_target. It appliesabspath, then refuses anything under/dev/or/proc/(except/dev/shm/) and any existing non-regular file. tgtrace refuses atpytest_configure, so before any test runs. The adapter refuses--trace-outbefore the suite starts.harness/trace.pyimports the adapter's rule. tgtrace can't import testgraph, so it carries a copy, andWriterParityTestskeeps the two copies identical: 11 path cases, plus a child process whose stdout is a regular file. It also checks they use the same<path>.tmp.<pid>temp name.tests/declaredentries aren't tgtrace's shape (checked per entry;declared: nullstays accepted, as onmain), and a registry that's unreadable or not a JSON object. Each of these used to exit 1, which is the code for "tests failed".--trace-out(directory exists and is writable, target isn't a directory). Before, a bad path only failed after a full run.<out>.tmp.<digits>files whose process is dead. A broader pattern deleted unrelated files and the temp file of a run still in progress.open("/dev/stdout", "w")truncates the redirected file and gets its own offset, so pytest's output overwrote the JSON: exit 0 with a corrupt trace. The/dev/prefix rule it used also caught/dev/shm, which is ordinary tmpfs, and that brokeharness/trace.py --out /dev/shm/....isfile./dev/stdoutredirected to a file resolves to a regular file.Measured (base
6e87ce8vs this branch, Linux, Python 3.14, pytest 9.0.3)Ran 600 tests ... OK(571 on base). Each test runs once (no inherited duplicates), and running each file directly matches discover: 47, 38, 48. The real-pytest e2e ran; nothing was skipped.2ce4041(failures=13, errors=11). The round-2 tests failed on756e9a3(failures=15, errors=4).verifyresults onmainand756e9a3(6 test bodies × 10 argument sets). The redesign changes no verdict path. It only adds refusals for stream targets and malformed inputs.Known limits
/dev/stdout, pipes) are refused rather than supported. Trace handling follow-ups after #108: --json refusal, harness/trace.py, fsync, --trace-out, shared runner #154 noted no caller uses them. Supporting one properly needs a separate output channel, not a file path.main.