refactor(cli): split release scripts into pure rules and CLI shells - #39660
Open
GareArc wants to merge 1 commit into
Open
refactor(cli): split release scripts into pure rules and CLI shells#39660GareArc wants to merge 1 commit into
GareArc wants to merge 1 commit into
Conversation
The release script tests could only observe behaviour through a process exit code, because die() called process.exit from inside otherwise-pure functions. That forced every test to spawn a subprocess, which forced its input to come from cli/package.json, which is why editing that file kept breaking tests — most recently #39658, and next the difyctl version bump that cli-release.yml requires on every release. Move the decisions into lib/release-rules.mjs and lib/edge-manifest.mjs, which take every input as an argument and return values instead of exiting. release-naming.mjs and release-r2-edge.mjs keep argv parsing, manifest reading, stdout and exit codes, and nothing else. Tests now split by what they ask. Logic is unit-tested against literal inputs, the shells are tested for plumbing only, and release-config.test.ts is the single place that reads the real manifest — asserting it is internally consistent, never what it currently contains. Editing cli/package.json no longer breaks a logic test; a malformed config still fails. Verified by mutating each field in both directions. Three intentional behaviour changes: - compat-check compares the numeric A.B.C core only, ignoring prerelease and build suffixes, so Dify 1.16.0-rc1 now satisfies a 1.16.0 window. This matches the shipped runtime check in src/version/compat.ts, which already stripped suffixes; the release gate was the one disagreeing. Removes the hand-rolled prerelease ordering entirely. - validate now rejects a missing or inverted compat window. It previously passed such a config while github-env emitted minDify=undefined. - release-r2-edge reports a bad channel version under its own name rather than release-naming's, since it no longer borrows that script's die(). release-config.test.ts also pins the install scripts to the naming config. They hardcode artifact names by necessity — they run standalone on a user machine with no repo and no node — so changing tagPrefix or checksumsSuffix now fails until all four installers are updated to match, instead of silently publishing names no installer looks for.
GareArc
force-pushed
the
refactor/cli-release-script-layering
branch
from
July 28, 2026 02:15
9ab8097 to
f1c32e1
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #39660 +/- ##
==========================================
+ Coverage 86.10% 86.15% +0.04%
==========================================
Files 5075 5232 +157
Lines 287042 291169 +4127
Branches 57240 58345 +1105
==========================================
+ Hits 247159 250846 +3687
- Misses 35133 35573 +440
Partials 4750 4750
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
GareArc
marked this pull request as ready for review
July 28, 2026 03:41
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.
Summary
Follow-up to #39658. That PR stopped the compat-window bump from breaking tests, but left the underlying problem: the release script tests could only observe behaviour through a process exit code, so they had to spawn a subprocess, so their input had to come from
cli/package.json. Editing that file kept breaking logic tests.It was still live. Bumping the difyctl version — which
cli-release.ymlrequires on every release, via a gate that errors with "bump cli/package.json version" — broke 3 tests. ChangingtagPrefixorchannelbroke 1 each. And #39658 had quietly stopped covering the realdifyctl.release.targetsat all.die()calledprocess.exitfrom inside otherwise-pure functions, which is where that chain starts. This splits them:cli/scripts/lib/release-rules.mjs— version and naming rules. Every input an argument, returns values instead of exiting.cli/scripts/lib/edge-manifest.mjs— R2 manifest/index builders, same contract.release-naming.mjs/release-r2-edge.mjs— argv, manifest reading, stdout, exit codes. Nothing else.The shells themselves are now importable:
die()throws aUsageError, the entry block is the only place that prints and exits, and both scripts exportmain(argv). Their shebangs are gone — every call site (3 workflows, 4 shell scripts) already invokes them vianode, and neither file had its exec bit set, so the shebang's only real effect was breaking vitest's Windows module runner on import.Tests split by what they ask. Logic is unit-tested against literal inputs (no fixture file, no env seam —
DIFYCTL_PKG_PATHandtest/fixtures/pkg-manifest.tsare both gone). The shells are tested for plumbing by importingmain()directly. No release-script test spawns a subprocess anymore.release-config.test.tsis the single place that reads the real manifest, and asserts only that it is internally consistent — never what it currently contains.Test policy: no integration tests in the unit suite
Five files in the unit suite were integration tests of shell scripts — they spawned
sh/pwsh/bashto drive the installers and the R2 publisher end-to-end. Shell has no import boundary, so they cannot become unit tests; the e2e suite has no infra for them yet, so they are removed rather than relocated:install-cli.test.ts,install.ps1.test.ts,install-r2.test.ts,install-r2.ps1.test.ts(69 tests)release-r2-publish.test.ts(2 tests — upload ordering: binaries → verify → survivors → index → manifest, and the no-targets safety gate)Candidates for the e2e suite when installer coverage lands there.
src/http/client-tls.test.tskeeps itsopensslspawn — that generates a cert fixture; the assertions are in-process.Behaviour changes
compat-checkcompares the numericA.B.Ccore only, ignoring prerelease and build suffixes — so Dify1.16.0-rc1now satisfies a1.16.0window. This matches the shipped runtime check insrc/version/compat.ts, which already stripped suffixes; the release gate was the one disagreeing. Removes the hand-rolled prerelease ordering (~45 lines).validatenow rejects a missing or inverted compat window. It previously passed such a config whilegithub-envemittedminDify=undefinedinto$GITHUB_ENV.release-r2-edgereports a bad channel version under its own name instead ofrelease-naming's, since it no longer borrows that script'sdie().Install scripts
The installers hardcode artifact names by necessity — they run standalone on a user's machine with no repo and no node. Nothing checked the two copies agreed, so changing
tagPrefixpublisheddfctl-1.2.3-linux-x64while all four installers still hunted fordifyctl-v*: green CI, broken installs.release-config.test.tsnow pins them to the naming config. ChangingtagPrefixorchecksumsSuffixfails with the exact installer files to update.Verification
Every field of
cli/package.jsonmutated in both directions, against the full suite:tagPrefixdeliberately now fails (exactly the 4 installer-alignment tests) until the installers are updated — see above.Mutation-tested the tests themselves, after an earlier round found three assertions that could not fail — deleting the
compat-checkrelease gate, emitting a bogus compat window, and droppingvalidate-version's rejection all passed a full run. Each now trips a test.CLI behaviour diffed against a pre-refactor baseline: 40 subcommand invocations covering every subcommand and error path of both scripts, byte-identical apart from the three intentional changes above.
pnpm test(cli): 1277 passed, 0 failed, 0 skippedvp check cli: cleanKnown, not addressed here
Pre-existing, surfaced while reviewing:
install.ps1:80only understands-rc.Nwhen sorting assets; any other prerelease sorts asMaxValueand can outrank a stable release of the same core.uname→target mapping is duplicated across the installers, so adding a build target does not reach them.install-r2.sh:52parsesindex.jsonline-wise and depends ondirbeing the last key; no test guards that ordering (verified — reordering it passes the whole suite).Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint gods