diff --git a/.claude/skills/bump-bundled-tools/SKILL.md b/.claude/skills/bump-bundled-tools/SKILL.md new file mode 100644 index 000000000..3fd98217d --- /dev/null +++ b/.claude/skills/bump-bundled-tools/SKILL.md @@ -0,0 +1,15 @@ +--- +name: bump-bundled-tools +description: Update a versioned tool bundled in the native CLI. Use when bumping socket-patch, uv, cdxgen, or synp. +user-invocable: true +--- + +# Bump a bundled native tool + +Take a tool name and its exact upstream version as `$ARGUMENTS`; ask if either +is missing. Read [the bundled tool inventory](references/bundled-tools.md), +then follow that tool's matching `bump-*` skill. Update one tool per change. + +Check the target-specific payload and manifest after building. Keep any tool +unavailable while its provenance, license, or notice checks remain unresolved. +Do not add a new tool here unless the builder stages it into the VFS. diff --git a/.claude/skills/bump-bundled-tools/references/bundled-tools.md b/.claude/skills/bump-bundled-tools/references/bundled-tools.md new file mode 100644 index 000000000..4631298b4 --- /dev/null +++ b/.claude/skills/bump-bundled-tools/references/bundled-tools.md @@ -0,0 +1,13 @@ +# Tools bundled in the native CLI + +| Tool and type | Pin | Staging path | Target and status | Skill | +| --- | --- | --- | --- | --- | +| `socket-patch` executable | `dependencies.@socketsecurity/socket-patch` in `package.json` | `src/sea/build-sea.mts` → `resources/socket-patch` | Built for targets with a matching locked platform package; the manifest records its digest. | [bump-socket-patch](../../bump-socket-patch/SKILL.md) | +| `uv` executable | `src/sea/stage/uv-pins.json` | `src/sea/stage/uv.mts` → `tools/uv` | Target archives are checksum-verified; the manifest records each binary digest. | [bump-uv](../../bump-uv/SKILL.md) | +| `cdxgen` JavaScript API | `devDependencies.@cyclonedx/cdxgen` in `package.json` | `.config/rollup.cdxgen-sea.config.mjs` and `src/sea/build-sea.mts` → `tools/cdxgen` | `darwin-arm64` only; capability stays disabled until provenance and notices are resolved. | [bump-cdxgen](../../bump-cdxgen/SKILL.md) | +| `synp` JavaScript package | `devDependencies.synp` in `package.json` | `src/sea/stage/synp.mts` → `tools/synp` | `darwin-arm64` only; Yarn Classic stays disabled until provenance and notices are resolved. | [bump-synp](../../bump-synp/SKILL.md) | + +Node is the SEA runtime; use [bump-node-sea](../../bump-node-sea/SKILL.md). +Coana runs from a Socket API download; use [bump-coana](../../bump-coana/SKILL.md). +The .NET facts helper is built from source and requires a compatible .NET SDK. +Socket Python CLI has no version pin or VFS staging step in this repo. diff --git a/.claude/skills/bump-cdxgen/SKILL.md b/.claude/skills/bump-cdxgen/SKILL.md new file mode 100644 index 000000000..f17a5c9cc --- /dev/null +++ b/.claude/skills/bump-cdxgen/SKILL.md @@ -0,0 +1,27 @@ +--- +name: bump-cdxgen +description: Update the pinned cdxgen package staged into the native CLI VFS. Use when changing @cyclonedx/cdxgen. +user-invocable: true +--- + +# Bump cdxgen + +Take the exact released version as `$ARGUMENTS`; ask if missing. Read +[the VFS and provenance reference](references/vfs-provenance.md), update the +exact dev dependency and lockfile with +`pnpm add -D --save-exact "@cyclonedx/cdxgen@$ARGUMENTS"`, then rebuild the +macOS arm64 SEA prototype with `pnpm build:sea -- --prototype`. + +Check the new dependency graph and update package-version-specific provenance, +license text, and notices where required. Keep the cdxgen capability unavailable +while any source or notice obligation remains unresolved. Run the SEA builder +and runtime tests, then inspect the manifest and confirm the capability remains +unavailable: + +```sh +pnpm run test:unit \ + test/unit/sea/build-sea.test.mts test/unit/sea/runtime.test.mts +pnpm build:sea -- --prototype +``` + +Create one signed conventional commit and a PR against `v1.x`. diff --git a/.claude/skills/bump-cdxgen/references/vfs-provenance.md b/.claude/skills/bump-cdxgen/references/vfs-provenance.md new file mode 100644 index 000000000..387a6a896 --- /dev/null +++ b/.claude/skills/bump-cdxgen/references/vfs-provenance.md @@ -0,0 +1,13 @@ +# cdxgen VFS and provenance + +- The pin is the `@cyclonedx/cdxgen` dev dependency in `package.json`; pnpm + records its graph in `pnpm-lock.yaml`. +- `src/sea/build-sea.mts` bundles it through the Rollup config + `.config/rollup.cdxgen-sea.config.mjs` for darwin-arm64. +- Exact-version license and source provenance entries live in + `.config/rollup.cdxgen-sea.config.mjs` and `src/sea/rollup-provenance.mjs`. +- `src/sea/README.md` records that cdxgen remains unavailable until source + provenance and notice obligations are resolved. A package bump alone does + not qualify it for use. +- Validate with `test/unit/sea/build-sea.test.mts`, + `test/unit/sea/runtime.test.mts`, and a darwin-arm64 prototype build. diff --git a/.claude/skills/bump-coana/SKILL.md b/.claude/skills/bump-coana/SKILL.md index 830361b02..5f944168b 100644 --- a/.claude/skills/bump-coana/SKILL.md +++ b/.claude/skills/bump-coana/SKILL.md @@ -1,149 +1,36 @@ --- name: bump-coana -description: Bump the pinned Coana CLI to a new version, update changelog, and create a PR. Use when user wants to upgrade Coana CLI, bump Coana version, or says "bump coana" with a version number. +description: Update the pinned Coana CLI, native help snapshots, and changelog. Use when bumping Coana CLI. allowed-tools: Read, Edit, Write, Bash, Glob user-invocable: true --- -# Bump Coana CLI Version +# Bump the Coana CLI -Automates the process of upgrading the pinned Coana CLI to a new version, including the pin, changelog entry, and PR creation. +Take the exact Coana version as `$ARGUMENTS` in `X.Y.Z` form; ask if it is +missing. Read [the pin and snapshot notes](references/pin-and-snapshots.md). -## Input +1. Read the current `COANA_CLI_VERSION` as `$CURRENT_VERSION`, then update it + in `src/constants.mts`. Leave `src/vendor/coana-cache.mjs` and the root + `package.json` version unchanged. +2. Refresh the native help snapshots: -- **Version**: The Coana version to upgrade to (e.g., `14.12.173`) -- Passed via `$ARGUMENTS` (e.g., `/bump-coana 14.12.173`) + ```sh + node scripts/test/swap-snapshot-version.mts \ + --dep coana --from "$CURRENT_VERSION" + ``` -If no version is provided, ask the user for the Coana version to upgrade to. + If the helper cannot update them, run `pnpm snapshots:update:dep coana` with + a built native CLI. +3. Add or replace the Unreleased changelog entry: -## Workflow + ```sh + node scripts/release/add-unreleased.mts \ + --replace '^Updated the Coana CLI to v ' \ + "Updated the Coana CLI to v \`$ARGUMENTS\`." + ``` -### Step 1: Parse and Validate Input - -Extract the version number from `$ARGUMENTS`: - -```bash -COANA_VERSION="$ARGUMENTS" - -# Validate version format (should be semver-like: X.Y.Z) -if [[ ! "$COANA_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "ERROR: Invalid version format. Expected X.Y.Z (e.g., 14.12.173)" - exit 1 -fi -``` - -### Step 2: Update the pin - -1. Read `src/constants.mts`. -2. Find the line `const COANA_CLI_VERSION = ''` and note the version as `CURRENT_VERSION`. -3. Replace the version on that line with the new one. - -Socket CLI downloads that version through the Socket API, so it has to be a -release Coana published to its GCS bucket, not one that only exists on npm. - -Don't edit `src/vendor/coana-cache.mjs`. It is generated in -coana-package-manager, and Coana's release workflow refreshes it in its own bump -PRs. - -🚨 **Do NOT touch `package.json`'s top-level `version` field.** The release workflow owns it: -between releases the manifest holds the last released version, and -`scripts/release/prepare.mts` derives and writes the next one in-run. Hand-writing -it invents a version that never releases and breaks the next release — a manifest -already sitting on the version being released has no line for the bump to -advance. - -**Values to extract**: -- `CURRENT_VERSION`: The old Coana CLI version (for PR body) - -### Step 3: Update CHANGELOG.md - -Do not hand-edit the file. Run the helper, which owns the shape: - -```bash -node scripts/release/add-unreleased.mts \ - --replace '^Updated the Coana CLI to v ' \ - "Updated the Coana CLI to v \`$COANA_VERSION\`." -``` - -It puts the entry under `## [Unreleased]` in the `### Changed` section, -recreating either when the previous release consumed it, and `--replace` -rewrites a Coana line left by an earlier unreleased bump instead of stacking a -second one. Rerunning it for the same version changes nothing. - -🚨 **Never write a `## []` heading.** Release headings belong to the -release workflow, which promotes the whole `## [Unreleased]` block under the -version it derives. Writing one here both names a version that may never exist -and consumes the block, leaving the real release with empty notes. - -🚨 **Never put a date on the `## [Unreleased]` heading.** `unreleasedRange()` in -`scripts/release/changelog.mts` finds the block by matching that heading for -equality (case-insensitively, but otherwise exactly), so a heading like -`## [Unreleased] - 2026-08-27` is invisible to it. The release then promotes -nothing, falls back to a section derived from the commits in range, and inserts -its own heading *above* the block it could not see — stranding the entry below a -released version, where no release will ever pick it up. Dates belong only on -release headings, which the workflow writes. (The helper repairs such a heading -if it finds one; hand-editing is what puts one there.) - -**Resulting shape**: -```markdown -## [Unreleased] - -### Changed -- Updated the Coana CLI to v `COANA_VERSION`. -``` - -### Step 4: Create Branch and Commit - -```bash -# Create branch -git checkout -b "coana-$COANA_VERSION" - -# Stage changes -git add src/constants.mts CHANGELOG.md - -# Commit (skip pre-commit hooks with -n) -git commit -n -m "upgrading coana to version $COANA_VERSION" -``` - -### Step 5: Push and Create PR - -```bash -# Push branch -git push -u origin "coana-$COANA_VERSION" - -# Create PR targeting v1.x branch -gh pr create --base v1.x --title "upgrading coana to version $COANA_VERSION" --body "$(cat <<'EOF' -## Summary -- Upgrades the Coana CLI from CURRENT_VERSION to COANA_VERSION - -## Coana Changelog -For details on what's included in this Coana release, see the [Coana Changelogs](https://docs.coana.tech/changelogs). -EOF -)" -``` - -Replace `CURRENT_VERSION` and `COANA_VERSION` with actual values. - -## Output - -- Branch: `coana-` pushed to origin -- PR: Created targeting `v1.x` branch -- Files modified: `src/constants.mts` (the `COANA_CLI_VERSION` line only), - `CHANGELOG.md` (under `## [Unreleased]`) - -Report the PR URL to the user when complete. - -## Error Handling - -- **No version provided**: Ask user for the version number -- **Invalid version format**: Report error with expected format -- **PR creation fails**: Verify `gh` CLI is authenticated - -## Important Notes - -- Do NOT add any AI/Claude co-authorship or attribution to the commit message or PR. -- Do NOT include "Generated with Claude Code" or similar text anywhere. -- Do NOT bump `package.json`'s `version` or write a `## []` changelog - heading. Both belong to the release workflow. Hand-writing them has produced - versions that never released and cost a real release its notes entirely. + Leave release headings and the top-level package version to the release + workflow. +4. Run `pnpm run test:unit:snapshot-dependencies`. Create one signed + conventional commit and open a PR against `v1.x`. diff --git a/.claude/skills/bump-coana/references/pin-and-snapshots.md b/.claude/skills/bump-coana/references/pin-and-snapshots.md new file mode 100644 index 000000000..4ce3f756b --- /dev/null +++ b/.claude/skills/bump-coana/references/pin-and-snapshots.md @@ -0,0 +1,11 @@ +# Coana pin and snapshot paths + +- The pinned version is `COANA_CLI_VERSION` in `src/constants.mts`. +- The native CLI snapshots that print this version are listed under `coana` in + `scripts/test/snapshot-dependencies.mts`. The checked-in files are the fix, + scan-create, and scan-reach help snapshots. +- Use `node scripts/test/swap-snapshot-version.mts --dep coana --from ` to + preserve the terminal row width without a native build. If it refuses the + change, regenerate with `pnpm snapshots:update:dep coana` on a built native + CLI. +- Coana runs from its Socket API download. SEA does not bundle it. diff --git a/.claude/skills/bump-node-sea/SKILL.md b/.claude/skills/bump-node-sea/SKILL.md new file mode 100644 index 000000000..c59957cb9 --- /dev/null +++ b/.claude/skills/bump-node-sea/SKILL.md @@ -0,0 +1,31 @@ +--- +name: bump-node-sea +description: Update the Node runtime bundled in the native CLI. Use when changing src/sea/.node-version. +user-invocable: true +--- + +# Bump the SEA Node runtime + +Take the exact official Node release version as `$ARGUMENTS`; ask if missing. +Read [the Node pin reference](references/pin-and-qualification.md), then update +`src/sea/.node-version`. + +Confirm the official Node release publishes the required archive for each +supported SEA target and exposes the SEA/VFS APIs the builder uses. Build the +native prototype first. It updates the README marker from the new pin: + +```sh +pnpm build:sea -- --prototype +``` + +Then run the Node pin and SEA builder tests: + +```sh +pnpm run test:unit \ + test/unit/sea/version.test.mts test/unit/sea/build-sea.test.mts +``` + +Check that `src/sea/README.md`'s marked version follows the pin. Do not claim +qualification for a target that was not built and tested. Add a changelog +entry when the runtime change affects released binaries. Create one signed +conventional commit and a PR against `v1.x`. diff --git a/.claude/skills/bump-node-sea/references/pin-and-qualification.md b/.claude/skills/bump-node-sea/references/pin-and-qualification.md new file mode 100644 index 000000000..0b3396479 --- /dev/null +++ b/.claude/skills/bump-node-sea/references/pin-and-qualification.md @@ -0,0 +1,11 @@ +# Node SEA pin and qualification + +- `src/sea/.node-version` is the source pin. `src/sea/node-version.mts` reads + it, and the README version markers are updated from that value during the SEA + build. +- `src/sea/build-sea.mts` downloads the official Node archive and verifies it + against that release's `SHASUMS256.txt` before building. +- The builder relies on the Node SEA VFS API. Check the release notes and build + on the intended OS/architecture before describing it as qualified. +- Read [the SEA build notes](../../../../src/sea/README.md) for target support + and experimental status. diff --git a/.claude/skills/bump-socket-patch/SKILL.md b/.claude/skills/bump-socket-patch/SKILL.md new file mode 100644 index 000000000..b12efd151 --- /dev/null +++ b/.claude/skills/bump-socket-patch/SKILL.md @@ -0,0 +1,48 @@ +--- +name: bump-socket-patch +description: Bump the pinned Socket Patch package and refresh its native CLI version snapshot. Use when updating @socketsecurity/socket-patch. +user-invocable: true +--- + +# Bump Socket Patch + +Take the exact released version as `$ARGUMENTS`. Ask for it if missing. Read +[the pin and SEA notes](references/pin-and-sea.md), then: + +1. Read the current exact `@socketsecurity/socket-patch` pin from + `package.json`. +2. Update it with `pnpm add --save-exact "@socketsecurity/socket-patch@$ARGUMENTS"`. +3. Refresh the native version screenshot without rebuilding: + + ```sh + node scripts/test/swap-snapshot-version.mts --dep socket-patch --from + ``` + + If the helper reports no matching version or insufficient row space, use + `pnpm snapshots:update:dep socket-patch` with a native build. +4. Add or replace the Unreleased entry: + + ```sh + node scripts/release/add-unreleased.mts \ + --replace '^Updated @socketsecurity/socket-patch to v' \ + "Updated @socketsecurity/socket-patch to v $ARGUMENTS." + ``` + + Never write a release heading or change the top-level CLI version. +5. Run the snapshot checks and refresh the native snapshots: + + ```sh + pnpm run test:unit:snapshot-dependencies + pnpm run test:unit test/unit/sea/build-sea.test.mts + pnpm snapshots:update:dep socket-patch + ``` + + Review any changed help snapshots. Inspect the generated + `build/sea/*.manifest.json` to confirm the target records the new patch + version and its executable/license payloads. +6. Create one signed conventional commit and a PR against `v1.x` titled + `build(deps): update Socket Patch to v`. + +Keep the change scoped to the package pin, lockfile, affected snapshots, +changelog entry, and any verified redistribution metadata needed by that +release. diff --git a/.claude/skills/bump-socket-patch/references/pin-and-sea.md b/.claude/skills/bump-socket-patch/references/pin-and-sea.md new file mode 100644 index 000000000..b08b14509 --- /dev/null +++ b/.claude/skills/bump-socket-patch/references/pin-and-sea.md @@ -0,0 +1,14 @@ +# Socket Patch pin and SEA notes + +- The source pin is `dependencies.@socketsecurity/socket-patch` in + `package.json`; pnpm records the resolved package and platform variants in + `pnpm-lock.yaml`. +- `scripts/test/snapshot-dependencies.mts` lists the native help snapshots and + the version snapshot. The version snapshot is the one that changes with a + package version bump. +- `src/sea/build-sea.mts` reads the exact package version, verifies installed + metadata and lockfile integrity, and stages the target executable plus its + license into the SEA VFS. +- Read [the SEA build notes](../../../../src/sea/README.md) before changing + bundled-tool or notice behavior. Verify platform packages and license files + against their upstream sources. diff --git a/.claude/skills/bump-socket/SKILL.md b/.claude/skills/bump-socket/SKILL.md new file mode 100644 index 000000000..b21b79c4d --- /dev/null +++ b/.claude/skills/bump-socket/SKILL.md @@ -0,0 +1,27 @@ +--- +name: bump-socket +description: Prepare the next Socket CLI npm release on stable v1.x or the native 2.1 prerelease track. +user-invocable: true +--- + +# Prepare a Socket CLI release + +Take `v1` or `native` as `$ARGUMENTS`; ask if the lane is missing or unclear. +Use the release workflow; do not edit package versions or changelog headings +by hand. Read [the release lanes](references/release-lanes.md), then dispatch a +dry run for the requested lane: + +```sh +# Stable v1.x: socket, @socketsecurity/cli, and @socketsecurity/cli-with-sentry +gh workflow run publish-npm.yml --ref v1.x \ + -f mode=release-pr -f dry-run=true -f release-major=1 + +# Native 2.1 prerelease: socket only +gh workflow run publish-npm.yml --ref v1.x \ + -f mode=release-pr -f dry-run=true -f release-major=2 +``` + +Review the proposed version and changelog output. If the requested task is to +prepare the release PR, rerun with `dry-run=false`; do not ask again for that +authorization. Do not dispatch `mode=publish` as part of bump preparation. +Report the workflow run and resulting PR. diff --git a/.claude/skills/bump-socket/references/release-lanes.md b/.claude/skills/bump-socket/references/release-lanes.md new file mode 100644 index 000000000..29399da46 --- /dev/null +++ b/.claude/skills/bump-socket/references/release-lanes.md @@ -0,0 +1,26 @@ +# Socket CLI release lanes + +The workflow is `.github/workflows/publish-npm.yml`. It prepares a version PR +first; publishing is a separate dispatch after that PR is merged. + +| Lane | Release line | npm packages | npm dist-tag | +| --- | --- | --- | --- | +| Stable | v1.x | `socket`, `@socketsecurity/cli`, `@socketsecurity/cli-with-sentry` | `latest` | +| Native prerelease | 2.1.0 RCs | `socket` only | `rc-2.1.0` | + +The package list is enforced by `scripts/release/packages.mts`. The build +matrix is defined in `scripts/build-package-matrix.mts`. Prerelease versions +come from `.config/release.json`; keep the `rc` identifier and configured +dist-tag. Never publish an RC as `latest` or promote this track to stable. + +`release-major=1` selects the stable v1 line. `release-major=2` selects the +configured prerelease-only line. The `release-pr` workflow derives the next +patch or minor version from commits unless `release-as` is required for a +breaking release. A dry run prints the proposed version and changelog without +opening a PR. Set `dry-run=false` only when the user asks to create the release +preparation PR. + +After the merged version PR, the separate `mode=publish` workflow builds and +tests package tarballs. Stable releases stage all three packages; RC releases +stage only `socket`. A human approves each npm stage ID locally. Approval and +GitHub release creation are not part of the bump skill. diff --git a/.claude/skills/bump-synp/SKILL.md b/.claude/skills/bump-synp/SKILL.md new file mode 100644 index 000000000..f910447ae --- /dev/null +++ b/.claude/skills/bump-synp/SKILL.md @@ -0,0 +1,24 @@ +--- +name: bump-synp +description: Update the pinned synp package staged into the native CLI VFS. Use when changing synp. +user-invocable: true +--- + +# Bump synp + +Take the exact released version as `$ARGUMENTS`; ask if missing. Read +[the VFS and notice reference](references/vfs-notices.md), update the exact dev +dependency and lockfile with `pnpm add -D --save-exact "synp@$ARGUMENTS"`, then +rebuild the macOS arm64 SEA prototype with `pnpm build:sea -- --prototype`. + +Keep the Yarn Classic capability unavailable while source provenance or notice +obligations remain unresolved. Run the SEA builder and runtime tests, then +inspect the manifest and confirm the capability remains unavailable: + +```sh +pnpm run test:unit \ + test/unit/sea/build-sea.test.mts test/unit/sea/runtime.test.mts +pnpm build:sea -- --prototype +``` + +Create one signed conventional commit and a PR against `v1.x`. diff --git a/.claude/skills/bump-synp/references/vfs-notices.md b/.claude/skills/bump-synp/references/vfs-notices.md new file mode 100644 index 000000000..bd7906a1b --- /dev/null +++ b/.claude/skills/bump-synp/references/vfs-notices.md @@ -0,0 +1,11 @@ +# synp VFS and notices + +- The pin is the `synp` dev dependency in `package.json`; pnpm records its graph + in `pnpm-lock.yaml`. +- `src/sea/stage/synp.mts` stages it under `tools/synp`; the VFS manifest is + written in `src/sea/build-sea.mts`. +- `src/sea/README.md` says the Yarn Classic capability remains unavailable + while source provenance and third-party notice obligations are unresolved. + A version bump must not enable the capability by itself. +- Validate with `test/unit/sea/build-sea.test.mts`, + `test/unit/sea/runtime.test.mts`, and a darwin-arm64 prototype build. diff --git a/.claude/skills/bump-uv/SKILL.md b/.claude/skills/bump-uv/SKILL.md new file mode 100644 index 000000000..dbf9d43e6 --- /dev/null +++ b/.claude/skills/bump-uv/SKILL.md @@ -0,0 +1,29 @@ +--- +name: bump-uv +description: Update the pinned uv binary embedded in the native CLI VFS. Use when changing src/sea/stage/uv-pins.json. +user-invocable: true +--- + +# Bump embedded uv + +Take the exact upstream release version as `$ARGUMENTS`; ask if missing. Read +[the uv pin reference](references/pin-and-verification.md), then update +`src/sea/stage/uv-pins.json` from the official uv release and source tag. + +Refresh the release URL, archive name, and SHA-256 for every declared target. +Refresh the license-file hashes only from the matching upstream tag. Do not +guess a digest or reuse one from another target. + +Run the SEA builder and runtime tests, then build on each available native CI +target: + +```sh +pnpm run test:unit \ + test/unit/sea/build-sea.test.mts test/unit/sea/runtime.test.mts +pnpm build:sea -- --prototype +``` + +Confirm the adjacent `build/sea/*.manifest.json` reports the new uv version +and the installed binary's digest matches the manifest. Add a changelog entry +only when the change affects user-visible behavior. Create one signed +conventional commit and a PR against `v1.x`. diff --git a/.claude/skills/bump-uv/references/pin-and-verification.md b/.claude/skills/bump-uv/references/pin-and-verification.md new file mode 100644 index 000000000..f9fbe0e99 --- /dev/null +++ b/.claude/skills/bump-uv/references/pin-and-verification.md @@ -0,0 +1,10 @@ +# uv pin and verification + +- `src/sea/stage/uv-pins.json` is the complete pin: version, official release base + URLs, license file hashes, and archive metadata plus SHA-256 for each target. +- `src/sea/stage/uv.mts` accepts only the declared target set and verifies the + downloaded archive digest before extracting the executable. +- `src/sea/runtime.mts` verifies the embedded executable digest before use. +- Read [SEA build and support notes](../../../../src/sea/README.md) for the + target platforms and runtime behavior. Keep any target unsupported unless a + matching upstream asset is available and the build validates it. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 91d77c291..014ff1352 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -879,7 +879,7 @@ jobs: with: mode: restore path: ~/.cache/socket-sea/downloads/v1/blobs - key: sea-downloads-v1-${{ matrix.target }}-${{ hashFiles('pnpm-lock.yaml', 'src/sea/uv-pins.json', 'src/sea/build-sea.mts') }}${{ inputs.refresh-native-cache && format('-refresh-{0}-{1}', github.run_id, github.run_attempt) || '' }} + key: sea-downloads-v1-${{ matrix.target }}-${{ hashFiles('pnpm-lock.yaml', 'src/sea/stage/uv-pins.json', 'src/sea/build-sea.mts') }}${{ inputs.refresh-native-cache && format('-refresh-{0}-{1}', github.run_id, github.run_attempt) || '' }} restore-keys: | sea-downloads-v1-${{ matrix.target }}- @@ -904,7 +904,7 @@ jobs: with: mode: save path: ~/.cache/socket-sea/downloads/v1/blobs - key: sea-downloads-v1-${{ matrix.target }}-${{ hashFiles('pnpm-lock.yaml', 'src/sea/uv-pins.json', 'src/sea/build-sea.mts') }}${{ inputs.refresh-native-cache && format('-refresh-{0}-{1}', github.run_id, github.run_attempt) || '' }} + key: sea-downloads-v1-${{ matrix.target }}-${{ hashFiles('pnpm-lock.yaml', 'src/sea/stage/uv-pins.json', 'src/sea/build-sea.mts') }}${{ inputs.refresh-native-cache && format('-refresh-{0}-{1}', github.run_id, github.run_attempt) || '' }} - name: Run native screenshot tests shell: bash diff --git a/.gitignore b/.gitignore index 471255d5a..3bee437a1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ !.gitignore !/.claude/ !/.claude/skills/ -!/.claude/skills/bump-coana/ +!/.claude/skills/** !/.config/ !/.config/** !/.husky/ @@ -45,6 +45,7 @@ !/scripts/test/terminal-report.mts !/scripts/test/snapshots.mts !/scripts/test/snapshot-dependencies.mts +!/scripts/test/swap-snapshot-version.mts !/scripts/utils/ !/shadow-bin/ !/src/ @@ -193,6 +194,8 @@ !/src/sea/archive-paths.mts !/src/sea/adapters/ !/src/sea/build/ +!/src/sea/stage/ +!/src/sea/stage/** !/src/sea/download-cache.mts !/src/sea/capabilities.mts !/src/sea/licenses/ @@ -259,6 +262,7 @@ !/test/native-snapshots/** !/test/unit/scripts/test/snapshots.test.mts !/test/unit/scripts/test/snapshot-dependencies.test.mts +!/test/unit/scripts/test/swap-snapshot-version.test.mts !/test/package-matrix.test.mts !/test/fixtures/ !/test/fixtures/commands/ @@ -348,7 +352,6 @@ !/test/fixtures/manifest-bazel/native/bzlmod/ !/test/fixtures/manifest-bazel/native/workspace/ !/test/fixtures/manifest-bazel/python-pypi/ -!/.claude/skills/bump-coana/SKILL.md !/.editorconfig !/.env.dist !/.env.external @@ -1079,10 +1082,7 @@ !/src/sea/rollup-provenance.mjs !/src/sea/runtime.mts !/src/sea/download-bytes.mts -!/src/sea/stage-synp.mts -!/src/sea/stage-uv.mts !/src/sea/version.mts -!/src/sea/uv-pins.json !/src/shadow/common.mts !/src/shadow/npm-base.mts !/src/shadow/npm-base.test.mts diff --git a/package.json b/package.json index 259f1758c..246059b90 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,7 @@ "test": "pnpm run check --all && run-s test:prepare test:unit integration-tests e2e-tests", "test:prepare": "dotenvx -q run -f .env.test -- pnpm build && del-cli 'test/**/node_modules'", "test:unit": "dotenvx -q run -f .env.test -- vitest run --config .config/vitest.config.mts", + "test:unit:snapshot-dependencies": "pnpm run test:unit test/unit/scripts/test/snapshot-dependencies.test.mts", "test:unit:update": "dotenvx -q run -f .env.test -- vitest run --config .config/vitest.config.mts --update", "test:unit:coverage": "dotenvx -q run -f .env.test -- vitest run --config .config/vitest.config.mts --coverage", "test-ci": "run-s test:prepare test:unit integration-tests", diff --git a/scripts/test/snapshot-dependencies.mts b/scripts/test/snapshot-dependencies.mts index 55d992767..16750403a 100644 --- a/scripts/test/snapshot-dependencies.mts +++ b/scripts/test/snapshot-dependencies.mts @@ -39,7 +39,9 @@ export const SNAPSHOT_DEPENDENCIES = { 'test/native-snapshots/socket-patch-repair-help.help.svg', 'test/native-snapshots/socket-patch-version.version.svg', ], - versionSnapshots: ['test/native-snapshots/socket-patch-version.version.svg'], + versionSnapshots: [ + 'test/native-snapshots/socket-patch-version.version.svg', + ], testNamePattern: 'captures bundled patch help for (apply|rollback|get|scan|list|remove|setup|repair)|captures bundled socket-patch version', }, @@ -48,6 +50,52 @@ export const SNAPSHOT_DEPENDENCIES = { export type SnapshotDependencyName = 'coana' | 'patch' | 'socket-patch' type SnapshotDependencyMapName = keyof typeof SNAPSHOT_DEPENDENCIES +function escapeRegExp(text: string): string { + return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') +} + +function snapshotVersionPattern(version: string): string { + return `(? { + found = true + const width = from.length + padding.length + if (to.length > width) { + throw new Error(`No room in the row to replace ${from} with ${to}`) + } + return `${to}${tail}${' '.repeat(width - to.length)}` + }, + ) + if (!found) { + if (snapshotContainsVersion(contents, to)) { + return contents + } + throw new Error(`The snapshot does not mention ${from}`) + } + return swapped +} + export interface StaleSnapshotDependency { readonly dependencyName: SnapshotDependencyName readonly packageName: string @@ -55,25 +103,31 @@ export interface StaleSnapshotDependency { readonly snapshots: readonly string[] } +export async function readPinnedVersion( + dependency: SnapshotDependency, +): Promise { + const source = await fs.readFile(path.join(ROOT, dependency.source), 'utf8') + const version = dependency.versionPattern.exec(source)?.[1] + if (!version) { + throw new Error( + `Could not read ${dependency.packageName} version from ${dependency.source}`, + ) + } + return version +} + export async function findStaleSnapshotDependencies(): Promise< StaleSnapshotDependency[] > { const findings = await Promise.all( - (Object.entries(SNAPSHOT_DEPENDENCIES) as Array<[ - string, - SnapshotDependency, - ]>).map(async ([name, dependency]) => { - const source = await fs.readFile( - path.join(ROOT, dependency.source), - 'utf8', - ) - const version = dependency.versionPattern.exec(source)?.[1] - if (!version) { - throw new Error( - `Could not read ${dependency.packageName} version from ${dependency.source}`, - ) - } - const versionSnapshots = dependency.versionSnapshots ?? dependency.snapshots + ( + Object.entries(SNAPSHOT_DEPENDENCIES) as Array< + [string, SnapshotDependency] + > + ).map(async ([name, dependency]) => { + const version = await readPinnedVersion(dependency) + const versionSnapshots = + dependency.versionSnapshots ?? dependency.snapshots const snapshots = await Promise.all( versionSnapshots.map(async snapshot => ({ path: snapshot, @@ -81,12 +135,16 @@ export async function findStaleSnapshotDependencies(): Promise< })), ) const staleSnapshots = snapshots - .filter(snapshot => !snapshot.contents.includes(version)) + .filter( + snapshot => !snapshotContainsVersion(snapshot.contents, version), + ) .map(snapshot => snapshot.path) if (staleSnapshots.length) { return { dependencyName: - name === 'patch' ? 'socket-patch' : (name as SnapshotDependencyName), + name === 'patch' + ? 'socket-patch' + : (name as SnapshotDependencyName), packageName: dependency.packageName, version, snapshots: dependency.versionSnapshots @@ -109,8 +167,12 @@ export async function findStaleSnapshotDependencies(): Promise< export function normalizeSnapshotDependencyName( name: string, ): SnapshotDependencyMapName | undefined { - if (name === 'socket-patch') {return 'patch'} - if (name === 'coana' || name === 'patch') {return name} + if (name === 'socket-patch') { + return 'patch' + } + if (name === 'coana' || name === 'patch') { + return name + } return undefined } diff --git a/scripts/test/swap-snapshot-version.mts b/scripts/test/swap-snapshot-version.mts new file mode 100644 index 000000000..fbc93a1d1 --- /dev/null +++ b/scripts/test/swap-snapshot-version.mts @@ -0,0 +1,106 @@ +#!/usr/bin/env node +/** + * @file Move a pinned tool's native snapshots from its old version to the + * pinned one by editing the version text, for automation that bumps the pin + * but cannot build the native CLI. + * + * Usage: + * node scripts/test/swap-snapshot-version.mts --dep coana --from 15.15.0 + */ + +import { promises as fs } from 'node:fs' +import path from 'node:path' +import process from 'node:process' +import { parseArgs } from 'node:util' + +import { + SNAPSHOT_DEPENDENCIES, + findStaleSnapshotDependencies, + normalizeSnapshotDependencyName, + readPinnedVersion, + snapshotDependencyUpdateHint, + swapVersionInSnapshot, +} from './snapshot-dependencies.mts' +import { isMainModule } from '../lib/is-main-module.mts' +import { runMain } from '../lib/run-main.mts' + +import type { SnapshotDependency } from './snapshot-dependencies.mts' +import type { ScriptMeta } from '../lib/run-main.mts' + +const ROOT = path.resolve(import.meta.dirname, '../..') + +export interface SwapArgs { + readonly dependencyName: string + readonly from: string +} + +export function parseSwapArgs(argv: readonly string[]): SwapArgs { + const { values } = parseArgs({ + args: [...argv], + options: { dep: { type: 'string' }, from: { type: 'string' } }, + strict: true, + }) + if (!values.dep || !values.from) { + throw new Error('Pass both --dep and --from ') + } + return { dependencyName: values.dep, from: values.from } +} + +export async function main(): Promise { + const { dependencyName, from } = parseSwapArgs(process.argv.slice(2)) + const name = normalizeSnapshotDependencyName(dependencyName) + if (!name) { + throw new Error(`Unknown snapshot dependency: ${dependencyName}`) + } + const dependency: SnapshotDependency = SNAPSHOT_DEPENDENCIES[name] + const to = await readPinnedVersion(dependency) + const snapshots = dependency.versionSnapshots ?? dependency.snapshots + // Swap every file in memory first, so a failure leaves none of them edited. + const swapped = await Promise.all( + snapshots.map(async snapshot => { + const file = path.join(ROOT, snapshot) + try { + const original = await fs.readFile(file, 'utf8') + return { + file, + original, + contents: swapVersionInSnapshot(original, from, to), + } + } catch (e) { + throw new Error(`${snapshot}: ${(e as Error).message}`) + } + }), + ) + const pendingWrites = swapped.filter( + ({ contents, original }) => contents !== original, + ) + await Promise.all( + pendingWrites.map(({ contents, file }) => fs.writeFile(file, contents)), + ) + const stale = (await findStaleSnapshotDependencies()).filter( + finding => normalizeSnapshotDependencyName(finding.dependencyName) === name, + ) + if (stale.length) { + throw new Error(snapshotDependencyUpdateHint(stale)) + } + process.stdout.write( + `Updated ${pendingWrites.length} ${dependency.packageName} snapshots from ${from} to ${to}\n`, + ) +} + +const SCRIPT_META: ScriptMeta = { + describe: + "moves a pinned tool's native snapshots to its pinned version without a native build", + help: `Usage: node scripts/test/swap-snapshot-version.mts --dep --from + + --dep coana, socket-patch or patch + --from the version the snapshots show now + + Run it after bumping the pin. It fails without editing anything when a + snapshot does not show the old version or a row has no room for the new one. + Fall back to pnpm snapshots:update:dep in that case.`, +} + +if (isMainModule(import.meta.url)) { + runMain(main, SCRIPT_META) +} diff --git a/src/sea/build-sea.mts b/src/sea/build-sea.mts index e9c8f0ad7..68488145b 100644 --- a/src/sea/build-sea.mts +++ b/src/sea/build-sea.mts @@ -18,19 +18,19 @@ import { downloadBytes } from './download-bytes.mts' import { cachedDownload } from './download-cache.mts' import { NODE_VERSION } from './node-version.mts' import { updateSeaReadmeVersion } from './readme-version.mts' -import { stageSynp } from './stage-synp.mts' -import { stageUv } from './stage-uv.mts' +import { stageSynp } from './stage/synp.mts' +import { stageUv } from './stage/uv.mts' import { SEA_VERSION } from './version.mts' import { quotePowerShell } from '../utils/quote-powershell.mts' -const HERE = path.dirname(fileURLToPath(import.meta.url)) -const ROOT = path.resolve(HERE, '../..') +const SEA_DIRECTORY = path.dirname(fileURLToPath(import.meta.url)) +const REPOSITORY_ROOT = path.resolve(SEA_DIRECTORY, '../..') const MAX_PINNED_ARCHIVE_BYTES = 512 * 1024 * 1024 const MAX_NODE_SUMS_BYTES = 1024 * 1024 // `pnpm build:dist:src` starts by deleting `dist/`. Keep SEA artifacts outside // that managed distribution tree so an ordinary package build cannot erase // the output of a preceding SEA build. -const DEFAULT_OUT = path.join(ROOT, 'build/sea') +const DEFAULT_OUT = path.join(REPOSITORY_ROOT, 'build/sea') const TARGETS = [ ['darwin', 'arm64', 'darwin-arm64'], @@ -316,7 +316,10 @@ async function stageSocketPatch( const [platform, arch] = target const packagePlatform = platform === 'win32' ? 'win32' : platform const packageName = `@socketsecurity/socket-patch-${packagePlatform}-${arch}` - const lock = await fs.readFile(path.join(ROOT, 'pnpm-lock.yaml'), 'utf8') + const lock = await fs.readFile( + path.join(REPOSITORY_ROOT, 'pnpm-lock.yaml'), + 'utf8', + ) const integrity = findLockedPackageIntegrity(lock, packageName, version) if (!integrity) { return undefined @@ -376,7 +379,7 @@ async function stageSocketPatch( flag: 'wx', }) await fs.copyFile( - path.join(HERE, 'licenses/socket-patch-MIT.txt'), + path.join(SEA_DIRECTORY, 'licenses/socket-patch-MIT.txt'), path.join(payloadDirectory, 'socket-patch-LICENSE.txt'), ) return { @@ -413,7 +416,10 @@ async function stageCdxgenApi( } const packageName = '@cyclonedx/cdxgen' - const packageRoot = path.join(ROOT, 'node_modules/@cyclonedx/cdxgen') + const packageRoot = path.join( + REPOSITORY_ROOT, + 'node_modules/@cyclonedx/cdxgen', + ) const packagePath = path.join(packageRoot, 'package.json') if (!existsSync(packagePath)) { throw new Error( @@ -436,7 +442,10 @@ async function stageCdxgenApi( ) } - const lock = await fs.readFile(path.join(ROOT, 'pnpm-lock.yaml'), 'utf8') + const lock = await fs.readFile( + path.join(REPOSITORY_ROOT, 'pnpm-lock.yaml'), + 'utf8', + ) const integrity = findLockedPackageIntegrity(lock, packageName, version) if (!integrity) { throw new Error( @@ -535,13 +544,13 @@ async function stageCdxgenApi( } await fs.copyFile(licensePath, path.join(payloadRoot, 'LICENSE')) await fs.copyFile( - path.join(HERE, 'adapters/cdxgen-worker.mjs'), + path.join(SEA_DIRECTORY, 'adapters/cdxgen-worker.mjs'), path.join(payloadRoot, 'sea-worker.mjs'), ) const workerUtils = path.join(payloadRoot, 'utils') await fs.mkdir(workerUtils, { recursive: true }) await fs.copyFile( - path.join(ROOT, 'src/utils/is-object-object.mjs'), + path.join(REPOSITORY_ROOT, 'src/utils/is-object-object.mjs'), path.join(workerUtils, 'is-object-object.mjs'), ) // Keep a concrete VFS path for cdxgen's plugin-directory override. The @@ -756,7 +765,7 @@ async function run( command: string, args: string[], env?: NodeJS.ProcessEnv, - cwd = ROOT, + cwd = REPOSITORY_ROOT, ): Promise { const { spawn } = await import('node:child_process') await new Promise((resolve, reject) => { @@ -836,7 +845,10 @@ async function main(): Promise { 'No matching supported target; pass --platform and --arch explicitly for cross builds', ) } - await updateSeaReadmeVersion(path.join(HERE, 'README.md'), NODE_VERSION) + await updateSeaReadmeVersion( + path.join(SEA_DIRECTORY, 'README.md'), + NODE_VERSION, + ) const [, , triple] = target if (target[0] !== process.platform || target[1] !== process.arch) { throw new Error( @@ -844,7 +856,7 @@ async function main(): Promise { ) } const packageJson = JSON.parse( - await fs.readFile(path.join(ROOT, 'package.json'), 'utf8'), + await fs.readFile(path.join(REPOSITORY_ROOT, 'package.json'), 'utf8'), ) as { version?: string dependencies?: Record @@ -864,7 +876,10 @@ async function main(): Promise { } const socketPatchPackage = JSON.parse( await fs.readFile( - path.join(ROOT, 'node_modules/@socketsecurity/socket-patch/package.json'), + path.join( + REPOSITORY_ROOT, + 'node_modules/@socketsecurity/socket-patch/package.json', + ), 'utf8', ), ) as { @@ -897,7 +912,7 @@ async function main(): Promise { let releaseDotnetLock: (() => Promise) | undefined try { releaseDotnetLock = await acquireBuildLock( - path.join(ROOT, '.cache/socket-sea-dotnet.lock'), + path.join(REPOSITORY_ROOT, '.cache/socket-sea-dotnet.lock'), ) } catch (error) { await releaseOutputLock() @@ -1028,7 +1043,10 @@ async function main(): Promise { ) const synpLock = synpPayload ? (parseYaml( - await fs.readFile(path.join(ROOT, 'pnpm-lock.yaml'), 'utf8'), + await fs.readFile( + path.join(REPOSITORY_ROOT, 'pnpm-lock.yaml'), + 'utf8', + ), ) as { packages?: Record< string, @@ -1063,7 +1081,7 @@ async function main(): Promise { const source = filename === 'node-runtime-LICENSE' ? nodeRuntime.licenseFile - : path.join(ROOT, filename) + : path.join(REPOSITORY_ROOT, filename) if (!existsSync(source)) { throw new Error(`Required SEA VFS runtime file is missing: ${source}`) } @@ -1155,7 +1173,7 @@ async function main(): Promise { 'pnpm', ['exec', 'rollup', '-c', '.config/rollup.sea.config.mjs'], { - SEA_BOOTSTRAP: path.join(HERE, 'bootstrap.mts'), + SEA_BOOTSTRAP: path.join(SEA_DIRECTORY, 'bootstrap.mts'), SEA_OUTPUT: bootstrap, }, ) diff --git a/src/sea/stage-synp.mts b/src/sea/stage/synp.mts similarity index 90% rename from src/sea/stage-synp.mts rename to src/sea/stage/synp.mts index 96624f5e0..dd952df37 100644 --- a/src/sea/stage-synp.mts +++ b/src/sea/stage/synp.mts @@ -5,9 +5,9 @@ import { promises as fs } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' -const HERE = path.dirname(fileURLToPath(import.meta.url)) -const ROOT = path.resolve(HERE, '../..') -const CONFIG = path.join(ROOT, '.config/rollup.synp-sea.config.mjs') +const STAGE_DIRECTORY = path.dirname(fileURLToPath(import.meta.url)) +const REPOSITORY_ROOT = path.resolve(STAGE_DIRECTORY, '../../..') +const CONFIG = path.join(REPOSITORY_ROOT, '.config/rollup.synp-sea.config.mjs') const EXPECTED_PACKAGE = 'synp' function sha256(bytes: Uint8Array): string { @@ -57,7 +57,7 @@ export async function stageSynp( noticeInventorySha256: string noticeDocuments: Array<{ path: string; sha256: string }> }> { - const packageRoot = path.join(ROOT, 'node_modules/synp') + const packageRoot = path.join(REPOSITORY_ROOT, 'node_modules/synp') const metadata = JSON.parse( await fs.readFile(path.join(packageRoot, 'package.json'), 'utf8'), ) as { name?: string; version?: string; license?: string } @@ -75,12 +75,19 @@ export async function stageSynp( await fs.mkdir(outputRoot, { recursive: true }) execFileSync( process.execPath, - [path.join(ROOT, 'node_modules/rollup/dist/bin/rollup'), '-c', CONFIG], + [ + path.join(REPOSITORY_ROOT, 'node_modules/rollup/dist/bin/rollup'), + '-c', + CONFIG, + ], { - cwd: ROOT, + cwd: REPOSITORY_ROOT, env: { ...process.env, - SEA_SYNP_INPUT: path.join(HERE, 'adapters/synp-worker.mjs'), + SEA_SYNP_INPUT: path.join( + STAGE_DIRECTORY, + '../adapters/synp-worker.mjs', + ), SEA_SYNP_OUTPUT: outputRoot, }, stdio: 'inherit', diff --git a/src/sea/uv-pins.json b/src/sea/stage/uv-pins.json similarity index 100% rename from src/sea/uv-pins.json rename to src/sea/stage/uv-pins.json diff --git a/src/sea/stage-uv.mts b/src/sea/stage/uv.mts similarity index 99% rename from src/sea/stage-uv.mts rename to src/sea/stage/uv.mts index 57e1b9f7d..8a17c69c3 100644 --- a/src/sea/stage-uv.mts +++ b/src/sea/stage/uv.mts @@ -5,8 +5,8 @@ import { promises as fs } from 'node:fs' import path from 'node:path' import { gunzipSync, inflateRawSync } from 'node:zlib' -import { downloadBytes } from './download-bytes.mts' -import { cachedDownload } from './download-cache.mts' +import { downloadBytes } from '../download-bytes.mts' +import { cachedDownload } from '../download-cache.mts' import pins from './uv-pins.json' with { type: 'json' } const UV_VERSION = pins.version diff --git a/test/unit/scripts/test/snapshot-dependencies.test.mts b/test/unit/scripts/test/snapshot-dependencies.test.mts index 5cf429da1..3eb7c4033 100644 --- a/test/unit/scripts/test/snapshot-dependencies.test.mts +++ b/test/unit/scripts/test/snapshot-dependencies.test.mts @@ -2,9 +2,55 @@ import { describe, expect, it } from 'vitest' import { findStaleSnapshotDependencies, + snapshotContainsVersion, snapshotDependencyUpdateHint, + swapVersionInSnapshot, } from '../../../../scripts/test/snapshot-dependencies.mts' +describe('swapVersionInSnapshot', () => { + it('preserves the row width when the version grows or shrinks', () => { + const row = 'Default: 15.15.0. ' + + expect(swapVersionInSnapshot(row, '15.15.0', '15.15.10')).toBe( + 'Default: 15.15.10. ', + ) + expect(swapVersionInSnapshot(row, '15.15.0', '9.0.0')).toBe( + 'Default: 9.0.0. ', + ) + }) + + it('matches complete versions and rejects suffixes', () => { + expect(snapshotContainsVersion('Default: 15.15.0. ', '15.15.0')).toBe(true) + expect(snapshotContainsVersion('Default: 15.15.0-rc.1 ', '15.15.0')).toBe( + false, + ) + expect( + snapshotContainsVersion('Default: 15.15.0+build.1 ', '15.15.0'), + ).toBe(false) + expect(snapshotContainsVersion('Default: 15.15.0.1 ', '15.15.0')).toBe( + false, + ) + expect(() => + swapVersionInSnapshot('Default: 15.15.0-rc.1 ', '15.15.0', '15.16.0'), + ).toThrow('does not mention 15.15.0') + }) + + it('accepts files already updated by an earlier partial write', () => { + const row = 'Default: 15.15.10. ' + + expect(swapVersionInSnapshot(row, '15.15.0', '15.15.10')).toBe(row) + }) + + it('fails when the new version does not fit or the old version is absent', () => { + expect(() => + swapVersionInSnapshot('Default: 1.0.0.', '1.0.0', '10.0.0'), + ).toThrow('No room in the row') + expect(() => + swapVersionInSnapshot('Default: 2.0.0 ', '1.0.0', '3.0.0'), + ).toThrow('does not mention 1.0.0') + }) +}) + describe('snapshot dependency hints', () => { it('matches pinned Coana and socket-patch versions in their snapshots', async () => { await expect(findStaleSnapshotDependencies()).resolves.toEqual([]) diff --git a/test/unit/scripts/test/swap-snapshot-version.test.mts b/test/unit/scripts/test/swap-snapshot-version.test.mts new file mode 100644 index 000000000..66b237e28 --- /dev/null +++ b/test/unit/scripts/test/swap-snapshot-version.test.mts @@ -0,0 +1,45 @@ +import { readFile } from 'node:fs/promises' +import path from 'node:path' + +import { describe, expect, it } from 'vitest' + +import { + SNAPSHOT_DEPENDENCIES, + readPinnedVersion, + swapVersionInSnapshot, +} from '../../../../scripts/test/snapshot-dependencies.mts' +import { parseSwapArgs } from '../../../../scripts/test/swap-snapshot-version.mts' + +describe('Coana snapshots', () => { + it('round-trips the checked-in Coana snapshots', async () => { + const pinned = await readPinnedVersion(SNAPSHOT_DEPENDENCIES.coana) + await Promise.all( + SNAPSHOT_DEPENDENCIES.coana.snapshots.map(async snapshot => { + const contents = await readFile( + path.join(process.cwd(), snapshot), + 'utf8', + ) + const moved = swapVersionInSnapshot(contents, pinned, '99.99.999') + expect(moved).toHaveLength(contents.length) + expect(moved).not.toContain(pinned) + expect(swapVersionInSnapshot(moved, '99.99.999', pinned)).toBe(contents) + }), + ) + }) +}) + +describe('parseSwapArgs', () => { + it('reads --dep and --from', () => { + expect(parseSwapArgs(['--dep', 'coana', '--from', '15.15.0'])).toEqual({ + dependencyName: 'coana', + from: '15.15.0', + }) + }) + + it('needs both flags', () => { + expect(() => parseSwapArgs(['--dep', 'coana'])).toThrow('Pass both') + expect(() => parseSwapArgs(['--to', '1.0.0'])).toThrow( + "Unknown option '--to'", + ) + }) +}) diff --git a/test/unit/sea/build-sea.test.mts b/test/unit/sea/build-sea.test.mts index bb59c1d4a..57d61600f 100644 --- a/test/unit/sea/build-sea.test.mts +++ b/test/unit/sea/build-sea.test.mts @@ -79,14 +79,20 @@ describe('SEA lockfile metadata', () => { await readFile(path.join(root, 'pnpm-lock.yaml'), 'utf8') ).replace(/\r\n/g, '\n') const packageName = '@socketsecurity/socket-patch-win32-x64' - const integrity = findLockedPackageIntegrity(lock, packageName, '2.0.0') + const packageJson = JSON.parse( + await readFile(path.join(root, 'package.json'), 'utf8'), + ) as { + dependencies: { '@socketsecurity/socket-patch': string } + } + const version = packageJson.dependencies['@socketsecurity/socket-patch'] + const integrity = findLockedPackageIntegrity(lock, packageName, version) expect(integrity).toMatch(/^sha512-/) expect( findLockedPackageIntegrity( lock.replace(/\r?\n/g, '\r\n'), packageName, - '2.0.0', + version, ), ).toBe(integrity) expect(findLockedPackageIntegrity(lock, packageName, '99.99.99')).toBe(