Skip to content

internal(test-selection): fingerprint the collected tests and ask after collection - #138

Merged
mergify[bot] merged 1 commit into
mainfrom
devs/alexandregaubert/devs/alexandregaubert/pytest-collection-fingerprint/fingerprint-collected-tests-ask-collection--5f2f95e0
Sep 1, 2026
Merged

internal(test-selection): fingerprint the collected tests and ask after collection#138
mergify[bot] merged 1 commit into
mainfrom
devs/alexandregaubert/devs/alexandregaubert/pytest-collection-fingerprint/fingerprint-collected-tests-ask-collection--5f2f95e0

Conversation

@AlexandreGaubert

Copy link
Copy Markdown
Contributor

Mergify can only serve a reduced rerun when the rerun collects the same tests
its predecessor did, and pytest-mergify gave it no way to know: the plugin asked
for a selection from pytest_configure, before it had collected anything, so
the request described the run's coordinates and nothing about its contents. A
rerun whose collection had changed underneath it — a renamed file, a -k a
developer added, a test suite that grew — would have been served a subset
computed for a collection that no longer exists.

Fingerprint the collection instead, and move the request behind it. The recipe
is SHA-256 of each identifier, the digests sorted, SHA-256 of their
concatenation — sorted, so collection order does not matter, and concatenated
rather than XORed, so a repeated identifier is not a collection that cancels
itself out. It lives in mergify-ci-core rather than in six lines of hashlib
here because the same recipe is owed to the Vitest and Playwright clients, which
bind that same crate, and a drift between three implementations of it is silent
and permanent: nothing matches, the full suite runs, and the feature stops doing
anything without a single error. The
request now happens in pytest_collection_modifyitems, trylast as before, so
the fingerprint covers what survives the user's own filters; it travels as a
collection_fingerprint query parameter, and is reported with the run's spans
as the test.collection.fingerprint resource attribute so the engine can
persist it for the next run to be matched against.

Under xdist neither happens. The request cannot: the controller never collects,
so the hook never fires there, and workers were already excluded — which is what
it amounted to before, the filtering hook having never run on the controller
either, except the controller used to print a "✂️ Test selection" block claiming
a subset it had applied to nothing (MRGFY-8632). The fingerprint is withheld too,
and that one is a correctness point rather than a consequence: a worker collects
the whole suite and runs a share of it, so every worker of a run would report the
same identity over partial results, and a worker that died before uploading would
leave its siblings carrying a complete-looking, failure-free identity for a suite
a fifth of which never ran.

Vitest and Playwright are untouched: they pass no fingerprint and the parameter
is omitted rather than sent empty.

Related to MRGFY-8614

@mergify
mergify Bot had a problem deploying to Mergify Merge Protections September 1, 2026 08:52 Failure
@mergify

mergify Bot commented Sep 1, 2026

Copy link
Copy Markdown

Merge Protections

🟢 All 6 merge protections satisfied — ready to merge.

Show 6 satisfied protections

🟢 🤖 Continuous Integration

  • all of:
    • check-success=ci-gate

🟢 👀 Review Requirements

  • any of:
    • #approved-reviews-by>=2
    • author = dependabot[bot]
    • author = mergify-ci-bot
    • author = renovate[bot]

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|internal|docs|style|refactor|perf|test|build|ci|chore|revert|ui)(?:\(.+\))?!?:

🟢 🔎 Reviews

  • #changes-requested-reviews-by = 0
  • #review-requested = 0
  • #review-threads-unresolved = 0

🟢 📕 PR description

  • body ~= (?ms:.{48,})

🟢 🚦 Auto-queue

When all merge protections are satisfied, this pull request will be queued automatically.

…er collection

Mergify can only serve a reduced rerun when the rerun collects the same tests
its predecessor did, and pytest-mergify gave it no way to know: the plugin asked
for a selection from `pytest_configure`, before it had collected anything, so
the request described the run's coordinates and nothing about its contents. A
rerun whose collection had changed underneath it — a renamed file, a `-k` a
developer added, a test suite that grew — would have been served a subset
computed for a collection that no longer exists.

Fingerprint the collection instead, and move the request behind it. The recipe
is SHA-256 of each identifier, the digests sorted, SHA-256 of their
concatenation — sorted, so collection order does not matter, and concatenated
rather than XORed, so a repeated identifier is not a collection that cancels
itself out. It lives in `mergify-ci-core` rather than in six lines of `hashlib`
here because the same recipe is owed to the Vitest and Playwright clients, which
bind that same crate, and a drift between three implementations of it is silent
and permanent: nothing matches, the full suite runs, and the feature stops doing
anything without a single error. The
request now happens in `pytest_collection_modifyitems`, `trylast` as before, so
the fingerprint covers what survives the user's own filters; it travels as a
`collection_fingerprint` query parameter, and is reported with the run's spans
as the `test.collection.fingerprint` resource attribute so the engine can
persist it for the next run to be matched against.

Under xdist neither happens. The request cannot: the controller never collects,
so the hook never fires there, and workers were already excluded — which is what
it amounted to before, the filtering hook having never run on the controller
either, except the controller used to print a "✂️ Test selection" block claiming
a subset it had applied to nothing (MRGFY-8632). The fingerprint is withheld too,
and that one is a correctness point rather than a consequence: a worker collects
the whole suite and runs a share of it, so every worker of a run would report the
same identity over partial results, and a worker that died before uploading would
leave its siblings carrying a complete-looking, failure-free identity for a suite
a fifth of which never ran.

Vitest and Playwright are untouched: they pass no fingerprint and the parameter
is omitted rather than sent empty.

Related to MRGFY-8614

Change-Id: I5f2f95e0762d62e4161aaa57567a9093eb7f8067
@AlexandreGaubert
AlexandreGaubert force-pushed the devs/alexandregaubert/devs/alexandregaubert/pytest-collection-fingerprint/fingerprint-collected-tests-ask-collection--5f2f95e0 branch from 7d7871d to f988cb1 Compare September 1, 2026 08:59
@AlexandreGaubert

Copy link
Copy Markdown
Contributor Author

Revision history

# Type Changes Reason Date
1 initial 7d7871d 2026-09-01 08:59 UTC
2 content 7d7871d → f988cb1 (raw) isolate GITHUB_EVENT_NAME/PATH in tests: the host PR's real head sha was overriding the test's GITHUB_SHA 2026-09-01 08:59 UTC

@mergify
mergify Bot deployed to Mergify Merge Protections September 1, 2026 09:00 Active
@mergify
mergify Bot requested a review from a team September 1, 2026 09:02
@AlexandreGaubert
AlexandreGaubert marked this pull request as ready for review September 1, 2026 09:08
@mergify
mergify Bot requested a review from a team September 1, 2026 09:24
@mergify

mergify Bot commented Sep 1, 2026

Copy link
Copy Markdown

Merge Queue Status

  • Entered queue2026-09-01 09:52 UTC · Rule: default · triggered by merge protections
  • 🟠 Preparing checks
  • ⏳ Merge

@mergify

mergify Bot commented Sep 1, 2026

Copy link
Copy Markdown

Merge Queue Status

  • Entered queue2026-09-01 09:52 UTC · Rule: default · triggered by merge protections
  • Checks skipped · PR is already up-to-date
  • Merged2026-09-01 09:52 UTC · at f988cb12b588c6b5d3e78805f7c1c9ee29b4e89b · squash

This pull request spent 34 seconds in the queue, including 5 seconds running CI.

Required conditions to merge

@mergify mergify Bot added the queued label Sep 1, 2026
@mergify
mergify Bot merged commit 385a7b1 into main Sep 1, 2026
22 checks passed
@mergify
mergify Bot deleted the devs/alexandregaubert/devs/alexandregaubert/pytest-collection-fingerprint/fingerprint-collected-tests-ask-collection--5f2f95e0 branch September 1, 2026 09:52
@mergify mergify Bot removed the queued label Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants