petri: remove stale test markers before running test#3785
Conversation
If a test results directory is reused (e.g., when running tests interactively), its test markers (such as petri.passed) can be stale and confuse tools, people, and agents. Clear them before running the test.
There was a problem hiding this comment.
Pull request overview
This PR prevents confusion from stale Petri test-result marker files (e.g. petri.passed) when a test output directory is reused across interactive runs by clearing those markers before executing a test.
Changes:
- Added a helper to remove known Petri result marker files from a test output directory.
- Switched marker filenames in result logging to shared constants and added a unit test for marker cleanup.
- Invoked marker cleanup at the start of test execution (after resolving artifacts, before tracing init).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
petri/src/tracing.rs |
Introduces marker filename constants + clear_test_result_markers, updates result logging to use constants, and adds a unit test for cleanup. |
petri/src/test.rs |
Calls marker cleanup on the test output directory before initializing tracing and running the test. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| const TEST_RESULT_MARKERS: &[&str] = &[PETRI_PASSED, PETRI_FAILED_UNSTABLE, PETRI_FAILED]; | ||
|
|
||
| /// Clears stale Petri test result markers from a test output directory. | ||
| pub(crate) fn clear_test_result_markers(root_path: &Path) -> anyhow::Result<()> { |
There was a problem hiding this comment.
Shouldn't we just empty out the whole directory instead of only deleting these files? What about the log files and other things we place in there?
There was a problem hiding this comment.
Seems less important to me, and more likely to delete something someone didn't want us to delete...
There was a problem hiding this comment.
But you could have stale log files or screenshots, those seem even more important to me honestly.
If a test results directory is reused (e.g., when running tests
interactively), its test markers (such as petri.passed) can be stale
and confuse tools, people, and agents. Clear them before running the
test.