Skip to content

Make the desktop release contract tests fail when the contract breaks - #8228

Merged
danielhanchen merged 9 commits into
mainfrom
fix/release-workflow-test-drift
Aug 9, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
fix/release-workflow-test-drift

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Aug 9, 2026 •

Copy link
Copy Markdown
Member

Summary

This started as a fix for the test drift #8193 and #8194 left behind. #8240 landed that fix on main first, so none of it remains here. What is left is the part that fix did not cover: the assertions guarding the release workflow passed whether or not the thing they guard was intact.

Three of them were the same defect.

  • The scan test proved it read a directory its own step had populated, which is true of any download writing there. It never compared the scan's download pattern with publish-release's, so pointing the scan at a different artifact set left the shipped installers unscanned and still reported a clean sweep.
  • The wait contract matched on a GITHUB_RUN_ID mention plus a LEGS assignment. The polling loop and the success-status checks could both be deleted with the test still green, and publish-release would then race the build matrix to the artifact download.
  • needs: gives ordering, not success gating. An if: always() would run the scan after a failed publish, sending build artifacts to a third party on the strength of a publication that never happened, with the assertion still passing.

A fourth item was a wording bug rather than a test one. The job was named "post-publish scan", but inputs.draft defaults to true and "Create versioned release" passes --draft on that input, so the ordinary dispatch uploads the assets to a draft and publishes nothing. The name, the job summary heading and the script's heading now all say "VirusTotal release asset scan", which is true of both dispatches, and the script's SUMMARY_HEADING is the single source for the workflow's no-summary placeholder so the two cannot drift.

What the assertions now pin

  • The scan job carries no if: at all, so whether it runs is needs:'s decision alone. Every job-level condition is rejected rather than sorted into safe and unsafe, because the failure is symmetric: always() or success() || inputs.scan_anyway runs the scan without a successful publish, while ${{ false }} or success() && <anything falsey> skips the sweep after one, and any rule loose enough to admit an arbitrary trailing predicate admits the second kind.
  • The scan's input directory. ${{ runner.temp }} and $RUNNER_TEMP normalise to one token, the two download paths are compared in full rather than by leaf, and the positional argument the scan step hands to scripts/virustotal_scan.py is compared against the scan job's own download path. The shared pattern is also checked against every matrix.artifact the build uploads, so the two jobs cannot agree on a set that does not exist.
  • The wait. A helper brackets the body of the first live while ... do ... done loop by depth, taking only an unconditional : or true condition, since while false; do keeps a textually perfect body while the shell skips every read in it. The jobs API read, .status/.conclusion, the != "completed" and != "success" decisions, the sleep and the break are all asserted inside that body. The wait must also clear before the assets are downloaded, not merely before the release is created.
  • The draft contract, so the heading and the workflow's default dispatch cannot drift apart again.

Validation

pytest tests/security/test_release_desktop_permissions.py tests/python/test_virustotal_scan.py: 81 passed.

Every assertion was mutation checked on a throwaway copy of the tree, 29 mutants in all. The 27 that violate the contract each turn the intended test red: repointing the scan's pattern, deleting the polling loop and status checks while leaving GITHUB_RUN_ID and LEGS in place, if: always(), if: failure(), if: cancelled(), if: ${{ false }}, if: ${{ success() || inputs.scan_anyway }}, if: ${{ success() && false }}, if: ${{ success() && inputs.scan }}, turning while :; do into while false; do, a one-shot gh api read beside a dead while, removing every sleep or the break from the loop, deleting either the != "completed" or the != "success" decision, repointing needs, moving the checkout after the scan or the download after the scan, moving the asset download ahead of the wait, renaming the uploaded artifact out of the pattern, moving both downloads under a new parent with the same leaf, repointing the script argument, dropping merge-multiple, drifting the placeholder heading, flipping inputs.draft to false, and dropping --draft.

Two mutants are legitimate refactors rather than violations and stay green, which is the check that the assertions are not simply over-tight: writing the poll as while true; do, and moving the downloads together with the script argument to a new directory.

studio/backend/tests/ and studio/backend/hub/tests/ were run on main and on this branch: identical FAILED/ERROR line sets (78 lines, all pre-existing on main) and 354 passed in the hub suite on both.

@danielhanchen
danielhanchen force-pushed the fix/release-workflow-test-drift branch from b78dea1 to c668893 Compare August 9, 2026 07:33

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3dac0ba8e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/python/test_virustotal_scan.py Outdated
Comment on lines +899 to +902
# The two spell the runner temp dir differently, so compare the leaf.
target = download["with"]["path"].rstrip("/").rsplit("/", 1)[-1]
scan = next(step for step in steps if "virustotal_scan.py" in step.get("run", ""))
assert f"/{target}" in scan["run"], scan["run"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Compare the scan and publish artifact patterns

This test only proves that the scan reads the directory populated by its own download step; it never compares that download's pattern with the artifact download used by publish-release. If virustotal-scan is changed to download another matching artifact set while retaining the same destination, the test still passes even though the published installers are no longer scanned. Compare the two jobs' download patterns, or otherwise tie the scan input to the publish job's artifacts.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, and this is the sharpest of the four. The test proves the scan reads a directory its own step populated, which is true of any download that writes there. Tying the scan input to the publish job's own pattern is the assertion that actually holds. Fixing.

Comment on lines +63 to +68
wait = next(
(
index
for index, step in enumerate(publish["steps"])
if "GITHUB_RUN_ID" in step.get("run", "")
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate that the fallback step actually waits

When publish-release does not depend on build, this accepts any earlier step whose script mentions GITHUB_RUN_ID; the companion test only additionally requires a LEGS assignment. Removing the polling loop and success-status checks while leaving those strings would therefore keep both tests green, but the download would run while matrix legs are still building and the release job would fail on missing artifacts. Assert the jobs API polling and completed/success conclusions, rather than using the environment-variable reference as the wait contract.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct. Matching on a GITHUB_RUN_ID mention plus a LEGS assignment means the polling loop and the success-status checks can both be deleted with the test still green, and the failure mode is a download racing the matrix legs and a release job that dies on missing artifacts. The wait has to be asserted as the jobs API poll and the completed/success conclusions. Fixing.

Comment thread tests/python/test_virustotal_scan.py Outdated
Comment on lines +840 to +844
def test_the_scan_runs_once_the_release_is_published(self):
# The scan moved out of publish-release into its own job (#8194), so the
# ordering guarantee is now the dependency edge rather than step order.
scan = self._job("virustotal-scan")
assert "publish-release" in (scan.get("needs") or []), scan.get("needs")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Ensure the scan remains gated on publish success

The dependency edge establishes ordering, but it does not by itself guarantee the scan runs only after a successful publication: adding a job-level condition such as if: always() would make virustotal-scan run after a failed publish-release, while this assertion still passes. In that scenario build artifacts could be disclosed to VirusTotal even though no release was published, so this test should also reject conditions that override the default success gating (or explicitly require success()).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, and this one has a security consequence rather than a CI one: needs gives ordering, not success gating, so an if: always() would send build artifacts to a third party after a publish that never happened, with the assertion still passing. Requiring success() explicitly, and rejecting conditions that override it. Fixing.

Comment thread scripts/virustotal_scan.py Outdated
Comment on lines +188 to +190
# Matched by the workflow step that writes a placeholder when the scan
# produced no summary, so a reader sees one heading either way.
SUMMARY_HEADING = "### VirusTotal post-publish scan"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid labeling draft-release scans as post-publish

The desktop workflow defaults inputs.draft to true and passes --draft to gh release create, yet the scan job still runs after that successful draft creation. Consequently, the newly centralized heading describes the normal draft run as a “post-publish scan” even though the release has not been published, which can mislead release operators about its visibility. Use wording that covers both draft uploads and published releases, or select the heading based on the draft input.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct. inputs.draft defaults to true and the create step passes --draft, so the ordinary run is a draft and calling it a post-publish scan tells a release operator the opposite of what happened. Wording that covers both, or selected from the draft input. Fixing.

danielhanchen and others added 3 commits August 9, 2026 09:24
…test-drift

# Conflicts:
#	tests/python/test_virustotal_scan.py
#	tests/security/test_release_desktop_permissions.py
Checkpoint of in-progress work, mutation testing still outstanding.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 182cb7eb86

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tests/python/test_virustotal_scan.py Outdated
condition = job.get("if")
if condition is not None:
normalised = str(condition).replace(" ", "")
assert "success()" in normalised, (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require success as a conjunctive gate

If a future job condition is written as ${{ success() || inputs.scan_anyway }}, this assertion passes because it only looks for the success() substring, while the disjunction can still run the VirusTotal job after publish-release failed. Since the test is meant to preserve the default success gating before artifacts are sent to a third party, assert that success() is required conjunctively (or keep rejecting job-level if: entirely), not just present.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, and confirmed by mutation: adding if: ${{ success() || inputs.scan_anyway }} to virustotal-scan left all 81 tests green. Fixed in b371ec3. The condition is now stripped of its ${{ }} wrapper and whitespace, rejected outright if it contains ||, and required to be either exactly success() or to start with success() &&, so every accepted form is strictly narrower than the default gate. The same mutation now fails the test, and a legitimate narrowing (success() && inputs.scan) still passes.

Comment thread tests/python/test_virustotal_scan.py Outdated
publish_download["with"].get(key),
)
# The two spell the runner temp directory differently, so compare leaves.
assert self._leaf(download["with"]["path"]) == self._leaf(publish_download["with"]["path"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Compare the actual scan input path

When the download path is moved under another directory with the same leaf, or the VirusTotal scan invocation is changed to read a different $RUNNER_TEMP path, this leaf-only comparison can stay green while the script scans an empty or stale directory instead of the downloaded release assets. The test should compare the normalized full download path with the path passed to scripts/virustotal_scan.py, not just the final path component shared by the two download steps.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, and both halves reproduce. Moving the two download steps under a common new parent with the same leaf, and separately repointing the script argument at another $RUNNER_TEMP path, each left 81 passed. Fixed in b371ec3: a helper normalises ${{ runner.temp }}, $RUNNER_TEMP and ${RUNNER_TEMP} to one token, the two download paths are compared in full rather than by leaf, and the positional argument the VirusTotal scan step actually passes to scripts/virustotal_scan.py is compared against the scan job's download path. Both mutations now fail; moving the downloads and the argument together still passes.

Comment on lines +91 to +95
assert re.search(r'!=\s*"completed"', wait_run), wait_run
assert re.search(r'!=\s*"success"', wait_run), wait_run
# A single API read is a snapshot, not a wait: it has to loop and sleep.
assert re.search(r"^\s*while\b", wait_run, re.MULTILINE), wait_run
assert re.search(r"^\s*sleep\b", wait_run, re.MULTILINE), wait_run

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Tie the wait checks to the poll body

The new assertions added here still look for the jobs API, status fields, while, and sleep as independent substrings in the whole script; a one-shot gh api read plus any unrelated or dead loop would pass even though publish-release could reach the artifact download before all matrix legs finish. Parse or execute the wait step enough to assert that the jobs API read and .status/.conclusion success checks are inside the loop that sleeps until every leg completes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, and this was the one surviving mutant in my own sweep too. Hoisting the gh api read out of the loop and leaving a while false; do sleep 1; break; done beside it kept the step green, as did stripping every sleep out of the real loop. Fixed in b371ec3: a helper brackets the first while ... do ... done by depth, and the jobs API read, .status/.conclusion, the != "completed" and != "success" decisions, the sleep and the break are all asserted against the loop body rather than the whole script. The dead-loop and sleepless mutations both fail now.

The wait checks searched the whole step, so a one-shot jobs API read beside an
unrelated loop passed; they now run against the poll loop body and also require
a break. The scan job's condition was accepted on a success() substring, which
let a disjunction through; it now has to require success() conjunctively. And
the scan's directory was compared by leaf between two download steps, so moving
both under a new parent, or repointing the script argument, scanned an empty
directory and still reported clean; the argument the step passes is now
compared against the download path.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b371ec37a5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

with `do`, which is what the shell style in this workflow uses.
"""
lines = script.split("\n")
starts = [index for index, line in enumerate(lines) if re.match(r"\s*while\b", line)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Assert that the polling loop can execute

When the Wait for the build matrix step's while :; do is changed to while false; do, _poll_loop_body still returns its textual body and every new assertion passes, although the shell skips all API and status checks and immediately proceeds to download potentially incomplete artifacts. Fresh evidence after the prior loop-scoping fix is that this helper selects a loop without validating its condition; require an unconditional/live polling condition so this matrix race is caught.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, and reproduced: changing the step's while :; do to while false; do left all 81 tests green, because the helper selected the loop by shape and never looked at its condition. Fixed in 52b4904. The helper now matches while <condition>; do and only selects a loop whose condition is the unconditional : or true that a poll exiting via break uses, and it fails with a named message when there is none. while false; do is now red; while true; do, the equivalent live poll, still passes.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen danielhanchen changed the title Realign the desktop release tests with the post-publish VirusTotal job Make the desktop release contract tests fail when the contract breaks Aug 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6597e5d2a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/python/test_virustotal_scan.py Outdated
f"virustotal-scan carries `if: {condition}`; a disjunction can run the "
"scan on a branch where publish-release did not succeed"
)
assert normalised == "success()" or normalised.startswith("success()&&"), (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject job conditions that can skip successful scans

When a future edit sets if: success() && false (or adds any opt-out predicate that evaluates false), this assertion passes because it accepts every condition beginning with success()&&, but GitHub then skips the entire job even after a successful publication. That defeats this test's stated contract and can leave release artifacts without the VirusTotal sweep; require no job-level condition or validate only an explicitly approved predicate rather than accepting an arbitrary trailing expression.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, and if: ${{ success() && false }} did pass. The failure is symmetric, which is the argument against sorting conditions at all: a permissive rule lets the job run without a successful publish, and a rule loose enough to admit an arbitrary trailing predicate lets it be skipped after one. Fixed in 52b4904 by taking your first option and rejecting every job-level condition, so reaching virustotal-scan is needs:'s decision alone, which is what the workflow does today. success() && false, success() && inputs.scan, success() || inputs.scan_anyway, always(), failure(), cancelled() and ${{ false }} are all red now.

Accepting a condition that merely opened with success() let success() && false
through, which skips the sweep after a publication that succeeded, so no
job-level if: is accepted at all now: reaching virustotal-scan is needs:'s
decision alone. The wait helper likewise selected a loop by shape, so turning
while :; do into while false; do kept every assertion green while the shell
skipped the API reads and fell through to a download that races the matrix; the
helper now only selects an unconditional poll.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 52b4904279

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 0cd73cf into main Aug 9, 2026
19 of 23 checks passed
@danielhanchen
danielhanchen deleted the fix/release-workflow-test-drift branch August 9, 2026 11:48
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.

1 participant