feat: auto-fix Bun and npm lockfiles on PR branches - #10
Merged
Merged
Conversation
Restore Socket Firewall Bun tarball URL fields to Bun native empty resolution fields. Spec: docs/ideation/bun-lockfile-socket-firewall-scrub/spec-phase-1.md
Add explicit workspace-relative lockfile selection, preserve Bun defaults, and normalize npm resolved URL fields without reformatting. Cover npm lockfile versions 1–3 and shrinkwrap with tests and CI install smokes. Spec: docs/ideation/bun-lockfile-socket-firewall-scrub/spec-phase-1.md
Preserve upstream public-token and fork-fallback behavior alongside npm scrub tests. Run the protected scrub smoke only when Socket Firewall is active.
Default to guarded GITHUB_TOKEN repair using atomic createCommitOnBranch. No checkout or caller-owned commit/push is required. Include a temporary PR-10-only live trial to verify branch updates. Spec: docs/ideation/bun-lockfile-socket-firewall-scrub/spec-phase-1.md
Contributor
Author
|
peakematt
marked this pull request as ready for review
September 14, 2026 13:19
peakematt
requested review from
d6vid99,
nickcollisson-workos and
willporter-workos
September 14, 2026 13:19
Contributor
Author
|
[from Pi]: @greptile please re-review the current head, dfe43cb, and report any remaining actionable findings and the updated confidence score. The Devin permission finding has been investigated: GitHub documents that GET /repos/{owner}/{repo}/pulls/{pull_number} accepts either Contents: read or Pull requests: read, so the existing contents: write permission suffices. Evidence is recorded in the resolved thread. No code or permission changes were made. |
lanceblais-wos
approved these changes
Sep 14, 2026
peakematt
added a commit
that referenced
this pull request
Sep 14, 2026
The automatic `v1` release after PR #10 failed with `GitHub-signed release commit tree differs from the staged tree`, leaving the lockfile repair action unpublished. The new `scripts/scrub-lockfile.sh` was executable in the staged package, but GitHub's `createCommitOnBranch` file additions cannot specify an executable mode for a new file. This removes the helper's unnecessary executable bit (`100755` → `100644`). The controller, CI, and tests already invoke it through `bash`, so its behavior does not change. **No publisher logic, signature verification, exact-tree checks, token permissions, or release workflow is changed.** The previous publisher mock returned the desired tree hash directly, hiding this mismatch. The regression now constructs an actual Git tree from the mutation payload, preserving existing file modes and assigning `100644` to new files against a five-file pre-scrub release fixture. The fixed package passes. Reintroducing the executable bit produces the same release error and verifies that neither discovery ref moves and the temporary staging branch is cleaned up. The packaged controller/normalizer tests also run successfully with the non-executable helper. From the repository root, with Bash, Node.js 24+, Git, jq, and standard command-line utilities, no credentials or dependency installation are needed: ```bash bash scripts/publish-release.test.sh bash scripts/build-release.test.sh node --test scripts/fix-lockfile.test.mjs scripts/scrub-npm-lockfile.test.mjs ``` These checks passed locally. The new publisher regression failed with the original file mode before the fix. All 49 Node tests, the existing shell suites, ShellCheck, shfmt, and workflow linting passed as well. After this merges and main CI passes, the existing release workflow should publish the new action-only commit. This PR does not publish a release or manually move any refs; that live verification remains necessary after merge. Failed release run: https://github.com/workos/setup-socket-firewall/actions/runs/34853295286 Related work: #10 https://linear.app/workos/issue/HELP-723
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.
Socket Firewall URLs saved in lockfiles can bind later installs to an endpoint that contributors or external CI cannot access. Bun can record those URLs directly; npm has a preventive
omit-lockfile-registry-resolvedsetting, but also benefits from a cleanup backstop. Detecting or editing runner files alone does not repair the pull request branch.This action fixes the branch itself. One invocation of
workos/setup-socket-firewall/lockfile-scrubreads the selected committed lockfile from the PR head, normalizes it, and creates a commit on that same PR branch usingGITHUB_TOKEN. It defaults tomode: fixandlockfile: bun.lock. The caller grantscontents: write; no checkout, dependency installation, or separate commit/push step is required.Bun URLs become the native empty resolved-URL field. npm
package-lock.jsonandnpm-shrinkwrap.jsonversions 1–3 retain their tarball paths withregistry.npmjs.orgreplacing the Socket Firewall origin inresolvedvalues. Nested repository-relative paths are supported. A clean file creates no commit; explicitmode: checkreports whether repair is needed without writing. Outputs includechangedand the repaircommit-sha.The action—not caller shell code—enforces branch safety. It accepts ordinary
pull_requestevents, rejects default-branch writes, fails dirty forks with repair guidance, and refuses stale PR heads. GitHub's atomiccreateCommitOnBranchoperation checks the expected head SHA and changes only the selected file, so a concurrent contributor push is not overwritten. It neither force-pushes nor retries denied or ambiguous writes. The Node 24 action runs only its own normalizer in an isolated directory; it does not execute target-repository code or pass the token to that subprocess.A live test on this draft PR proved the complete path: the action created a verified
github-actions[bot]commit, replacing the test Bun URL with an empty field while changing only that lockfile. The temporary trial workflow and fixture were removed afterward.From the repository root, with Bash and Node.js 24+, these offline checks exercise branch-write guards, transformations, and the packaged release runtime without dependencies or live credentials:
All 49 Node tests and the existing shell/release suites passed locally, along with ShellCheck, shfmt, and workflow linting. The six npm install smoke combinations and protected-registry smoke remain in CI.
Do not rely on
GITHUB_TOKENcommits to run follow-up CI automatically. In the live trial, GitHub createdaction_requiredfollow-up runs with no jobs executed; a repaired lockfile is not proof of fresh-head application CI. This PR supplies the complete self-fixing action, but does not yet install it in the four target repositories. Those workflows must use the signed action-only release SHA after source merge. Yarn and pnpm scrubbing remain out of scope.Tracking: https://linear.app/workos/issue/HELP-723