# Releasing

This is the checklist this project follows. The last section records facts that
cost time to learn.

## 1. Decide the version

| Change | Version bump |
|---|---|
| Documentation, comments, the changelog itself | patch: 0.1.2 becomes 0.1.3 |
| A fix that does not change behaviour | patch |
| A behaviour change, a new configuration key, a new provider | minor |
| Anything that breaks an existing configuration | major |

The package is below 1.0.0, so the peer pins and the on-disk layer format may still
move in a minor release.

## 2. Cut the changelog and bump the version

1. Move the entries under `## [Unreleased]` in [`CHANGELOG.md`](../CHANGELOG.md)
   into a new dated section, `## [x.y.z] - YYYY-MM-DD`.
2. Leave the `## [Unreleased]` heading in place, empty.
3. Add a one-line introduction to the new section when the release has one theme.
4. Bump `version` in [`package.json`](../package.json) to the same number.

## 3. Run the gates

The configuration-stability rules and the full gate table (including the manual
legs a CI run cannot execute) are in [MIGRATION.md](MIGRATION.md#gates-a-release-must-clear).

```bash
pnpm test
pnpm run test:coverage
pnpm run test:browser   # once: pnpm exec playwright install chromium
```

The release workflow runs all three before it publishes.

Release evidence is split into three gates:

```text
Source gate: every PR/main run
Candidate gate: every tag before publish
Post-release gate: every stable/next tag after registry propagation
```

Source evidence does not substitute for official-package evidence: a passing
source gate says nothing about the published tarball, so the candidate and
post-release gates must produce their own official-package smoke evidence. The
source compatibility gate remains authoritative for full Windows/WSL probe
coverage.

`pnpm test` includes the build-freshness gate: modules whose source lives in
`src/*.ts` must be rebuilt (`pnpm run build`) and the result committed under
`lib/`, so the tarball always ships exactly what the sources say without any
build step at pack time.

The coverage thresholds are 85 lines / 84 branches / 70 functions. The
branch threshold is one point under the others deliberately: the
integration layer is now measured, and part of what it leaves uncovered
needs a live `wsl.exe` — the distro-bound paths in `lib/wsl-filesystem.js` and
`lib/wsl-shell.js` (the resolved home, the distro home, arming the watcher), the `wsl.exe` calls
in `lib/wsl.js` (`defaultDistro`'s no-distro throw, `linuxHomePath`,
and the other distro calls), and the real spawn internals
in `lib/watcher.js`. The real-machine probes cover that tail, not CI.
The rest of the uncovered branches — the host-path arm of
`wslWritableRoots` in `lib/provider-common.js`, the sandbox-error and rethrow
arms, and the unrestricted-path result in `lib/wsl-filesystem.js` — are ordinary
CI-coverable code. Do not raise the branch number without either covering
the `wsl.exe` tail on the Windows CI legs or moving the coverage job
(currently `runs-on: ubuntu-latest` in `.github/workflows/ci.yml`) to
`windows-latest`.

Run the full real-machine suite when behaviour changed, and keep its output for
the pull request or the release notes. The harness application must be closed;
the runner waits until it exits:

```bash
bash test/probe/run-all-when-closed.sh --include-fs
```

See [CONTRIBUTING.md](../CONTRIBUTING.md) for individual probes, prerequisites,
and optional performance probes not included in the suite.

`npm publish` runs the `prepublishOnly` script, which is `pnpm test`. The local
gates therefore run again during a hand-run release step. (The release workflow
publishes the candidate **tarball path**, and a tarball publish runs no
lifecycle scripts at all — its Gates step has already run the chain. A hand-run
publish from the package directory keeps the hook as its safety net.)

## 4. Commit and tag

```bash
git add package.json CHANGELOG.md
git commit -m "Release x.y.z: <what the release is>"
git tag -a vx.y.z -m "dsh-plugin-wsl-env x.y.z"
git push origin main vx.y.z
```

The version in `package.json` and `CHANGELOG.md` carries no `v`. The tag and the
GitHub Release do. The tag push starts the release workflow described in step 5.

## 5. Publish

### The tag-triggered workflow

Stable publishing is blocked until the `candidate-package-smoke` job succeeds.
The `pack-candidate` job packs the tagged commit once on **Ubuntu** (the only
pack: a Windows filesystem has no exec bit, and npm does not fix up non-`bin`
entries, so a Windows-packed tarball turned the shipped shell scripts into
0644). The same `.tgz` is uploaded as the `candidate-package` artifact — the
Windows smoke and the publish job both consume those bytes, never a repack.

`candidate-package-smoke` provisions the distro and WSL prerequisites
(`.github/actions/provision-wsl`: systemd, `bubblewrap`, `dbus`, `git`,
`curl`, linger) and runs `pnpm run smoke:official-harness` against the pinned
official Harness (`DSH_OFFICIAL_HARNESS_VERSION`, the floor in
`docs/PEER-PARITY.md`). The official installer resolves from the official
CDN's exact-version path
(`download.deepseek.com/dsh-desk/bin/win-x64/deepseek-harness-<version>-win-x64.exe`);
the CDN publishes no checksum object, so the smoke records the downloaded
file's sha256 instead of verifying a published one, and requires `dsh
--version` to report the exact requested version. The smoke identifies the
package by its tarball/registry identity (name, version, sha512);
`--dump-config` proves the profile composes the plugin with no skipped
entries, and the through-plugin probe (`test/probe/official-smoke-probe.mjs`)
runs on a headless boot of the official CLI — with the plugin's WSL shell
executor inserted so `ctx.shell` is the plugin's — exercising one shell
command, one workspace file operation through the routed filesystem, and one
sandbox-refused command. This is provider-level coverage of the plugin
package; the session-runtime preset path stays the source gate's authority.
Logs land in `test/probe/.scratch/` and are uploaded as a release artifact,
kept even when the smoke fails.

Pushing the tag starts `.github/workflows/release.yml`. It does these things,
in this order:

1. Packs the candidate tarball on Ubuntu (`pack-candidate`) and uploads it as
   the `candidate-package` artifact. A `workflow_dispatch` run stops here and
   runs the candidate smoke — the dry run; it never publishes.
2. Runs the official-Harness candidate smoke on Windows
   (`candidate-package-smoke`). Publish depends on this job, so a failing
   candidate blocks the release.
3. Runs `pnpm test`, `pnpm run test:coverage`, and the shipped x86_64 and
   aarch64 native-agent tests (the latter under QEMU).
4. Downloads the `candidate-package` artifact, verifies its sha512 integrity
   and `pack.json` identity equal the pack job's outputs, asks the registry
   whether this version is already published, and skips the upload when it
   is. Re-pushing the same tag therefore does not publish again — it only
   gets you as far as the GitHub Release.
5. Publishes the downloaded candidate tarball with
   `npm publish <tgz> --provenance --access public`. That attaches a signed
   attestation tying the tarball to this workflow run and this commit. A
   tarball publish runs no lifecycle scripts; the Gates step has already run
   the full chain. A hand-run publish from the package directory keeps the
   `prepublishOnly` hook as its safety net.
6. Reads back what the registry serves (integrity, file count, README name)
   and fails if the served bytes are not the smoke candidate.
7. Creates the GitHub Release, with notes taken from the changelog section by
   `scripts/changelog-section.mjs`, then re-runs the official-Harness smoke
   against the exact published version (`post-release-package-smoke`); its
   failure appends a warning to the Release notes and opens an issue.

The workflow requires a trusted publisher configured on npmjs.com for this
repository, this workflow file, and the `npm-publish` environment. That is what
lets npm exchange the run's OIDC token (`id-token: write`) for a short-lived
publish credential, so no npm token is stored in the repository.

If trusted publishing is not configured, add an `NPM_TOKEN` repository secret and
hand it to the Publish step in `.github/workflows/release.yml` — the step does not
read it on its own, so add `env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}` to it.
The `npm-publish` environment is the trusted-publishing binding and the audit
anchor for each run. **Required reviewers are deliberately not configured.**
This is a single-maintainer repository; the full gate chain and the tag/version
check still run before the upload, and the owner accepts that a mistaken tag can
publish without a second pair of eyes. Revisit the decision if a second
maintainer joins the release rotation.

### Repository settings the workflow cannot verify

The Windows matrix legs run on GitHub-hosted `windows-latest`. The
`.github/workflows/cloud-wsl-gate.yml` Cloud WSL Gate provisions Ubuntu and WSL
itself and implements the 19-entry closed-app suite after Desktop exits.
Suite evidence is accepted only after a run uploads the complete log/results
with every entry PASS and no SKIP or NOT RUN. Local evidence remains available through
`test/probe/run-all-when-closed.sh --include-fs`.

If a runner is added later, give it a custom `self-hosted-wsl` label rather than
the hosted `windows-latest` label, and update every matrix / `runs-on` /
fork-gate reference in `ci.yml` together.

The `npm-publish` environment has no required reviewers by decision, not by
oversight: see the paragraph above. Its presence is still required for npm
trusted publishing, so do not delete it while removing approval gates.

### Manual fallback

Use this when the workflow cannot run. On a trusted machine, authenticate with
`npm login --registry=https://registry.npmjs.org/` and complete the interactive
authentication and publishing challenges required by the npm account and package.
See [npm's two-factor authentication guidance](https://docs.npmjs.com/requiring-2fa-for-package-publishing-and-settings-modification/).
Keep credentials outside the repository and never put them in command arguments
or shell history. If a granular token is used instead, follow npm's package policy
and revoke the token after the release.

Run the same tag check the workflow runs, against the tag you are about to push,
then publish:

```bash
node scripts/check-release-tag.mjs vx.y.z

npm publish --registry=https://registry.npmjs.org/ --access public
```

Set `--registry` explicitly. A local `~/.npmrc` may point at a mirror, and a
release published to a mirror is not a release.

A manual publish does not create the GitHub Release, so do step 7 by hand.

## 6. Verify on the registry

`npm publish` prints `+ dsh-plugin-wsl-env@x.y.z` when the upload is accepted. That
is not the same as the version being visible. The version and the `dist-tags`
appear in the registry several minutes later (0.26.0 took about six), so poll instead of checking once — the release workflow waits up to ten minutes:

```bash
# expect 200, not 404
curl -sS -o /dev/null -w '%{http_code}\n' \
  https://registry.npmjs.org/dsh-plugin-wsl-env/x.y.z

curl -sS https://registry.npmjs.org/-/package/dsh-plugin-wsl-env/dist-tags
```

Then check the metadata:

```bash
npm view dsh-plugin-wsl-env version dist-tags dist.fileCount \
  --registry=https://registry.npmjs.org/ --prefer-online

npm view dsh-plugin-wsl-env readmeFilename \
  --registry=https://registry.npmjs.org/ --prefer-online
```

`readmeFilename` must be `README.md`. Compare the file count with what
`npm pack --dry-run` reports from the same commit: a difference means the `files`
list in `package.json` changed since the release.

Use `--prefer-online`, or a fresh cache directory, while verifying. A cached
packument shows the previous release and looks like a failed publish.

## 7. Create the GitHub Release

The tag-triggered workflow creates the Release for you, with notes from the
changelog section. Do it by hand only after a manual publish:

```bash
node scripts/changelog-section.mjs > notes.md

gh release create vx.y.z --repo Big-Dao/dsh-plugin-wsl-env \
  --title "vx.y.z - <short title>" --notes-file notes.md --verify-tag
```

The notes summarise the changelog section. Mention anything a user must do, such as
a new required configuration key.

The release workflow's `post-release-package-smoke` job then downloads exactly
`dsh-plugin-wsl-env@<version>` (never `latest` or a dist tag), checks its
integrity against the registry's `dist.integrity`, runs
`pnpm run smoke:official-harness` against it and uploads the logs. If it fails,
the job opens or updates a GitHub issue and appends a warning to the Release
notes; the version is not rolled back, so treat it as unverified and follow
section 9.

## 8. Refresh the runtime mirror

The Windows copy of the checkout is what the app loads. Sync it to the tagged
state:

```bash
pnpm run sync:windows
```

Then confirm that the two trees match:

```bash
diff -rq --exclude=.git --exclude=node_modules --exclude=.scratch \
  . /mnt/c/Users/<you>/Documents/deepseek-harness/default-workspace/dsh-plugin-wsl
```

Read this as "no unexpected differences", not "no output". `test/probe/.scratch`
is never copied, and the sync is additive on purpose — it never deletes — so the
mirror legitimately keeps files this checkout no longer has.
`test/probe/sync-to-windows.sh` reports that same residual set as a note rather
than a failure. What matters is the other direction: a file this checkout has and
the mirror does not, or one that differs.

That destination is outside a session workspace, so a confined agent session is
refused there and has to approve a wider permission for the one command.

## 8.5. Announce on the upstream discussions

Every release appends an update comment to both plugin threads in
[deepseek-ai/deepseek-harness](https://github.com/deepseek-ai/deepseek-harness):
[discussion #8644](https://github.com/deepseek-ai/deepseek-harness/discussions/8644)
(node id `D_kwDOT3T1g84AptnQ`) and
[discussion #11251](https://github.com/deepseek-ai/deepseek-harness/discussions/11251)
(node id `D_kwDOT3T1g84AqhvH`), so followers of either thread see each version
without watching this repository:

- One comment per release in **each** thread, in Chinese (the established
  language for updates; the English original stays as the top post, refreshed
  on notable releases).
- Content: the version, the two or three headline changes, the current
  verification snapshot in one line (unit tests, matrix, container and qemu
  legs, the manual closed-app probe suite), and the release link.
- Post it with the same GraphQL mutation the 2026-10-27 update used
  (`addDiscussionComment` on the discussion's node id) from a session that
  holds the maintainer's GitHub credentials — the release workflow's
  `GITHUB_TOKEN` is scoped to this repository and cannot write there. Post the
  same body to both, then read each back and compare it to the local source.

This is a hard checklist item, not a nicety: the threads are where the DSH
community found the plugin, and a stale thread reads as an abandoned one.

## 9. If a version turns out to be bad

npm does not let a published version be replaced, so the fix goes forward:

1. Deprecate the bad version, so anyone who installs it sees the warning:

   ```bash
   npm deprecate dsh-plugin-wsl-env@x.y.z "<what is wrong>; use x.y.(z+1)" \
     --registry=https://registry.npmjs.org/
   ```

2. Cut the fix as the next patch version, following this document from step 2.
   Prefer that to `npm unpublish`, which is not a rollback: it removes the
   tarball for every consumer that already resolved it.

3. Correct the GitHub Release for the bad tag, or point its notes at the patch
   release. The release notes stay the first thing a reader finds.

## Operational facts worth remembering

| Fact | What it means in practice |
|---|---|
| `npm publish` prints success at upload time | The version may still return 404 for several minutes (0.26.0 took about six). Poll the registry for up to ten minutes, and do not conclude that the publish failed. |
| A repeated publish of the same version is refused | npm checks the registry first and stops with `You cannot publish over the previously published versions: x.y.z.`; a registry-side conflict surfaces as `EPUBLISHCONFLICT` ("Cannot publish over existing version."). Either one means the first publish landed. Verify it instead of publishing again — the release workflow's already-published check exists for the same reason. |
| The npm readme is chosen from the candidate files at the package root, and the rule is not fully explained. With `README.md` and `README.zh.md` side by side, version 0.1.1 published as `readmeFilename: README.zh.md`, so its npm page rendered Chinese — even though the tarball listed `README.md` first. Both names match the npm CLI's own selection code (`@npmcli/package-json/lib/normalize.js` globs `{README,README.*}` and accepts `/\.m?a?r?k?d?o?w?n?$/i`, which does match `.md`), so neither name is screened out. | Do not rely on the rule. Keep exactly one readme candidate at the package root, which `pnpm run lint:style` checks. The Chinese README lives in `docs/` for this reason. |
| A local `~/.npmrc` may point at a mirror | Pass `--registry=https://registry.npmjs.org/` on every publish and every verification. |
| The npm token is a credential | Keep it out of command arguments and the repository; revoke a temporary token after the release. |
| `gh api -f body="$var"` posts the variable as literal text, so a JSON-encoded string lands as visible `\uXXXX` escapes | The 0.19.0 announcement (2026-11-06) rendered as `\u5d2f\u53d1...` on discussion #8644 because the body was `json.dumps`-encoded and then passed through `-f`, which treats the value as raw. For non-ASCII content use `-F body=@file` (`-F` reads the file's bytes verbatim), and delete the bad comment via `deleteDiscussionComment` before reposting. |
| A successful write to an external system says nothing about the rendered content | Every release step that posts content (discussion comments, GitHub Release notes) must read the result back and compare it to the local source before declaring the step done. The API returns success for a double-encoded body; only the read-back — grep for `\u` escape sequences, diff the first lines against the source file — catches it. The workflow's release-verify step had to be re-created by hand on 0.19.0 for the sibling reason: its one-shot registry check ran inside the propagation window (now fixed to poll, cea5d4a). |
| WSL mounts drvfs per terminal session | After a `C:` 9p mount flips to read-only, `sudo mount -t drvfs 'C:' /mnt/c -o remount,rw` only fixes the session that ran it; another shell (a probe runner, an agent session) keeps the stale read-only mount and `sync-to-windows` fails with tar exit 2 ("Read-only file system"). Recover in the terminal that will run the sync: `sudo umount -l /mnt/c && sudo mount -t drvfs 'C:' /mnt/c -o rw,uid=1000,gid=1000`, then verify with `touch` before rerunning. |
