Repository navigation
fix(sdk): separate latest deployment from official archives - #65
Closed
m4sh-wacker wants to merge 3 commits into
Closed
m4sh-wacker wants to merge 3 commits into
m4sh-wacker wants to merge 3 commits into
Conversation
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
Separates continuous latest SDK deployments from immutable milestone SDK archives so ordinary
maindeployments always publish the latest website, standalone HTML, and/api//api.jsaliases without colliding with archived versions.maincommit SHA:f3f7b15aac6c7359a92a584f7c3f077207b64928Root Cause of the Previous Deployment Failure
scripts/build-sdk.mjspreviously wrote intodist/sdk/v1/<package.json version>/(0.3.3), whilepackage.jsonstays on the previous release version until a Release Please PR is merged (and Release Please ignoreschore(deps):commits becausechoreishidden: true).195c13f) bumpedvite(8.3.5->8.4.0, updatingrolldown1.2.14->1.3.4), changing the minified bytes ofdecodebox.jsanddecodebox.mjswhilepackage.jsonremained0.3.3. Consequently,Deploy to GitHub Pagesruns46672589781and46692468864failed ondiff -qr "$release" "$target"in.github/workflows/deploy-pages.yml(just as earlier engine PRs fix(encodings): refuse Base45 and Base85 groups that overflow #50 and fix(encodings): refuse punctuation in Punycode digits #51 failed prior to0.3.2and0.3.3)./__VITE_PRELOAD__(?:[\da-f]{32})?/g.standalonePlugin()invite.config.tsreplaced only__VITE_PRELOAD__, leaving a trailing 32-hex hash ([]e115532ea529dbadd736874a4545557e) insidedist/decodebox.htmland causing aSyntaxErroron load.Why
diff -qr "$release" "$target"Was Removed from Website DeploymentIn the finalized two-channel architecture, the latest online SDK built from
mainis intentionally newer than (and allowed to differ from) older official archived SDKs. Comparing a freshly built latest SDK against an archived version directory incorrectly treated the old archive as the expected latest SDK.diff -qr "$release" "$target"from the ordinarymainwebsite deployment path in.github/workflows/deploy-pages.yml.vm.SourceTextModuleparse check ondist/decodebox.htmlbefore publishing.scripts/build-sdk.mjs(--releasemode) andscripts/publish-gh-pages.mjs(--mode archive), which refuse to overwrite any existing official archive with differing bytes.Architecture: Two Independent SDK Channels
1. Latest SDK — Continuous Deployment (
main)npm run build:sdk(scripts/build-sdk.mjsin defaultlatestmode) buildsdecodebox.js,decodebox.mjs,decodebox.d.mts, andSHA256SUMSinto staging directorybuild/sdk/(gitignored, outsidedist/).dist/:/api,/api.js,/sdk/v1/decodebox.js,/sdk/decodebox.js/sdk/v1/decodebox.esm.js,/sdk/decodebox.mjs/sdk/decodebox.d.mts/sdk/v1/<version>/archive directories during ordinary deployments.scripts/check-sdk-dist.mjsvalidates alldist/aliases againstbuild/sdk/SHA256SUMS, verifies retained official archives and absence of obsolete directories, and runs the Node smoke test.src/sdk/index.tskeepsengineVersiontied topackage.json(no artificial version bumping) and adds additivebuildIdmetadata derived from the built Git commit SHA.2. Official SDK Archives —
PATCH=0Milestone PolicyOnly stable releases whose
PATCHcomponent is0generate and publish an immutable versioned archive under/sdk/v1/{version}/:0.3.4,0.3.5,0.4.1,0.4.20.4.0,0.5.0,1.0.0,1.1.0scripts/build-sdk.mjs --release <tag>validatesPATCH === 0viaarchivePathFor(), verifies<version>matches the checked-out tag'spackage.json, builds into a temp dir, verifiesSHA256SUMS, refuses to overwrite differing existing archives, and never touches/apior/api.js.One-Time Archive Cleanup (
0.3.1–0.3.3Removed;0.2.0&0.3.0Preserved)0.2.0and0.3.0are preserved byte-for-byte (includingSHA256SUMSverification before copying forward) because both are qualifyingPATCH === 0milestone releases.0.3.1,0.3.2, and0.3.3are removed viaOBSOLETE_ARCHIVE_DIRSinscripts/publish-gh-pages.mjs(--mode latest) on the nextmaindeployment because they are pre-policy patch releases (PATCH !== 0). Once removed fromgh-pages, latest deployments never generate versioned directories, so they are never restored.Release Please Integration
mainupdates the website,decodebox.html, and/api+/api.js; pending Release Please PRs update normally without publishing archives.v0.3.4): Release Please creates the GitHub Release and.github/actions/standalone-releaseuploads/verifies the standalone HTML without creating/sdk/v1/0.3.4/or overwriting latest aliases.v0.4.0): Because tags/releases created withGITHUB_TOKENdo not trigger separatepush: tagsorreleaseworkflows,.github/workflows/release-please.ymlchecks out the exact tag viastandalone-release, builds/sdk/v1/<version>/(--release "$RELEASE_TAG"), verifiesSHA256SUMS, and publishes only that archive directory viascripts/publish-gh-pages.mjs --mode archive(never replacing website files or/api//api.js). Retries are idempotent when the archive already matches and fail closed on content differences.Concurrency & GitHub Pages Publication Safety
Separate workflow concurrency groups (
github-pagesindeploy-pages.ymlandrelease-please-${{ github.ref }}inrelease-please.yml) serialize runs within each workflow, but are not sufficient alone when a release PR merge triggers both workflows concurrently onmain. Without cross-workflow coordination, a blindgit push --forcefrom whichever finishes second would wipe out either the newly deployed website/aliases or the newly published milestone archive.To prevent lost updates across workflows:
deploy-pages.yml(--mode latest) andrelease-please.yml(--mode archive) sharescripts/publish-gh-pages.mjs.publish-gh-pages.mjsreadsrefs/heads/gh-pages(expectedOid), fetches the latestFETCH_HEAD, merges only its owned slice (latest mode: website + aliases onto retained archives; archive mode:/sdk/v1/<version>/onto the entire livegh-pagessnapshot), and pushes atomically withgit push --force-with-lease=refs/heads/gh-pages:<expectedOid>.stale info/ ref moved), it retries with backoff against the freshFETCH_HEAD(up to 5 attempts), ensuring neither workflow ever force-pushes a stale snapshot or loses the other's updates.Filesystem Integrity & CodeQL TOCTOU Resolution
Resolved GitHub Advanced Security CodeQL Alert
#32(js/file-system-race, previously flagged onscripts/sdk-integrity.mjs:26):lstat()followed byreadFile()inscripts/sdk-integrity.mjs(readRegularFile) with handle-based reading: opens the path once usingconstants.O_RDONLY | (constants.O_NOFOLLOW ?? 0), validateshandle.stat().isFile(), performs a post-openlstat(dev, ino)+isFile()check only on platforms whereO_NOFOLLOWis unavailable (Windows), and reads directly viahandle.readFile().pathExists(lstat-> read/readdir/copy) TOCTOU patterns and post-validation pathname reopenings acrossscripts/sdk-integrity.mjs,scripts/build-sdk.mjs,scripts/check-sdk-dist.mjs, andscripts/publish-gh-pages.mjs(readRegularFileIfExists,readdirIfExists,collectRegularFilesIfExists,writeVerifiedFileswriting validatedBufferpayloads directly withflag: 'wx'for exclusive archive creation).verifySha256Manifestvalidates directory contents in a single collection pass and returns verified{ digests, files }buffers reused directly by archive preservation and latest distribution checks without reopening source files.Test Results
Executed locally on Windows (Node
v24.18.0) on latest commit4b28f027e33397faff0be86891865d55ddddb47b:npm run lint(eslint .): passed (0 errors, 0 warnings)npm run typecheck(tsc --noEmit): passednpm test -- --run: 77 test files, 1,284 tests passed, includingsrc/sdk/sdk.test.ts(6 tests) andscripts/sdk-distribution.test.mjs(11 tests coveringPATCH=0policy, Scenarios A–G, realbuildSdklatest/release modes, bidirectional CAS concurrency retries against bare git remotes, non-regular file/symlink/junction rejection, concurrent rename race duringreadRegularFile, post-validation tamper resistance incopyRegularDirectory/writeVerifiedFiles, andverifySha256Manifestvalidation)npm run build&npm run check:sdk-dist: passednpm audit --audit-level=high: passed (found 0 vulnerabilities)GitHub Actions on latest commit
4b28f027e33397faff0be86891865d55ddddb47b:Analyze JavaScript/TypeScript, run46796753424, analysis2293640719): passed (results_count: 0, Alert#32state: fixed)46796753442): passed —Lint, typecheck, test, build (22),Lint, typecheck, test, build (24)(including Chrome distribution loading and Java runtime provider exercise),Dependency audit, andDependency review46796753497): passed —Markdown lintandLink check (advisory)Previously executed locally against
f3f7b15/ initial PR snapshot (3e412d6):origin/gh-pages(67a10ed0): verified0.2.0&0.3.0preserved byte-for-byte,0.3.1–0.3.3removed (HTTP 404), livecheck-sdk-dist.mjs,check-sdk-browser.mjs(6 latest JS aliases),buildIdmetadata (f3f7b15aac6c), Chromium loads ofindex.html,decodebox.html(HTTP &file://), and simulatedv0.4.0milestone archive build/publish/--releasebrowser check.deploy-pages.yml,release-please.yml, andstandalone-release/action.ymlpassed PyYAML parsing and Git Bashbash -n;verify-release-cli.cjsYAML structure assertions verified via PyYAML andsdk-paths.mjsfixture check.Remaining Risks
maindeployment after merge,/sdk/v1/0.3.1,/sdk/v1/0.3.2, and/sdk/v1/0.3.3will be removed fromgh-pages(by design under Phase 2); external links pinning those three pre-policy patch URLs will receive 404.deploy-pages.yml(mainpush / CDN propagation),release-please.yml, and.github/scripts/verify-release-cli.cjs/verify-release-notes.cjsonly run after merge or tag/release events onmain.standalone-releasechecks out the exact tagged commit, so rebuilding an old pre-PR tag runs that tag's own scripts, whereas future tags frommainuse the newPATCH=0archive and Vite 8.4.0 preload handling.