dsh-plugin-toolkit 0.20.47 → 0.20.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 0.20.48
2
+
3
+ - **`verify` packs exactly once, so `prepack` cannot change the archive after
4
+ the check read a different one.** The separate `npm pack --dry-run` was a
5
+ second invocation of the same hook: a non-idempotent `prepack` could write
6
+ `client.js` for the dry run and remove it for the real pack, and `verify` ran
7
+ user build code twice on every check. The dry run is gone. `verify` now runs a
8
+ single `npm pack`, judges that tarball's own file list, and — after installing
9
+ it — asks `doctor` again against the unpacked copy, so the installed patch,
10
+ client bundle and root are confirmed rather than assumed. A committed
11
+ `client.js` that `prepack` removes is caught at `pack` with the panel named.
12
+ `test/verify-prepack.test.mjs` pins one invocation per run on the
13
+ non-idempotent fixture across two runs at the library and, on the shipped CLI,
14
+ runs `verify` and `verify --no-mount` twice each on fresh copies: the first
15
+ run exits `0` after exactly one `prepack` and leaves the generated panel, and
16
+ the second exits `1` at `pack` naming `client.js`. It also spawns the shipped
17
+ CLI three times each for `verify .` and `verify --no-mount .` on the flip
18
+ fixture, requiring exit `1` every time; the generated-panel and
19
+ unmodified-scaffold controls still exit `0` with `ok packed`.
20
+
1
21
  ## 0.20.47
2
22
 
3
23
  - **`verify` judges the tarball it installs, not the separate dry run.** A
package/README.md CHANGED
@@ -80,7 +80,7 @@ npx dsh-plugin-toolkit@latest release . --pr --merge
80
80
 
81
81
  ![Five steps, and the failure each one catches](https://raw.githubusercontent.com/WJDdidi-1/dsh-plugin-toolkit/main/docs/pipeline.svg)
82
82
 
83
- The order matters. Packing first means the check reads the file list from the tarball `verify` installs, not the folder you have and not a separate dry run whose `prepack` output can differ. Installing the tarball means the root is imported by its bare specifier — the package name the loader uses — not by a file path taken from `main` or `exports["."]`. Node ignores `main` once `exports` exists, so a package whose `exports` map has no `"."` entry fails with `ERR_PACKAGE_PATH_NOT_EXPORTED` at that step even though the file is present. Mounting means the client bundle is actually executed, in jsdom, with a host that records what it registered. Packing first also means a panel built by a `prepack` hook exists when the source checks run: the hook has written it into the folder before `doctor`'s file checks are asked again.
83
+ The order matters. Packing first — exactly once — means the check reads the file list from the tarball `verify` installs, not from the folder you have. A separate dry run would execute `prepack` a second time, and that second execution can see a tree the first one changed, so the archive could differ from the list that was checked. Installing the tarball means the root is imported by its bare specifier — the package name the loader uses — not by a file path taken from `main` or `exports["."]`. Node ignores `main` once `exports` exists, so a package whose `exports` map has no `"."` entry fails with `ERR_PACKAGE_PATH_NOT_EXPORTED` at that step even though the file is present. Mounting means the client bundle is actually executed, in jsdom, with a host that records what it registered. Packing first also means a panel built by a `prepack` hook exists when the source checks run: the hook has written it into the folder before `doctor`'s file checks are asked again.
84
84
 
85
85
  Each step exists because a plugin once got past the step before it and still installed into nothing.
86
86
 
@@ -1055,7 +1055,7 @@ ok packed 5 file(s), installed the tarball, mounted the panel
1055
1055
  My panel This panel came from dsh-plugin init. Clicks: 0
1056
1056
  ```
1057
1057
 
1058
- It packs, reads that tarball's file list, installs the same tarball into a throwaway directory, then mounts the bundle **from the installed copy**. The file list therefore describes the archive users would get, so a `client.js` that a non-idempotent `prepack` writes only during the dry run no longer passes. The host half is imported by the package's bare name, exactly as the loader imports it, so an `exports` map with no `.` entry fails with `ERR_PACKAGE_PATH_NOT_EXPORTED` even when `main` names a working file; `verify --no-mount` reports that as a `root export` failure naming the missing `.` export. The host half is also called and awaited, so an `async apply()` that rejects is reported as a `host apply` failure instead of printing the success line and then crashing with an unhandled rejection; the client half's boot probe is awaited the same way, so an async `apply()` that rejects on the bare context is a `boot` failure. A package that declares neither `exports` nor `main` has no root module at all; there is nothing to import, and the success line says it skipped the host import instead of claiming one ran. When the `files` list drops the panel:
1058
+ It packs exactly once, reads that tarball's file list, installs the same tarball into a throwaway directory, then mounts the bundle **from the installed copy**. The file list therefore describes the archive users would get, and `prepack` is never asked to run a second time against a tree the first run changed. A hook that removes the panel while building the tarball — on its first run or a later one — is caught here, and the installed copy is checked again after unpacking. The host half is imported by the package's bare name, exactly as the loader imports it, so an `exports` map with no `.` entry fails with `ERR_PACKAGE_PATH_NOT_EXPORTED` even when `main` names a working file; `verify --no-mount` reports that as a `root export` failure naming the missing `.` export. The host half is also called and awaited, so an `async apply()` that rejects is reported as a `host apply` failure instead of printing the success line and then crashing with an unhandled rejection; the client half's boot probe is awaited the same way, so an async `apply()` that rejects on the bare context is a `boot` failure. A package that declares neither `exports` nor `main` has no root module at all; there is nothing to import, and the success line says it skipped the host import instead of claiming one ran. When the `files` list drops the panel:
1059
1059
 
1060
1060
  ```sh
1061
1061
  $ npx dsh-plugin-toolkit verify .
package/lib/verify.mjs CHANGED
@@ -16,24 +16,15 @@ import { resolveEntry } from './dev.mjs';
16
16
  import { resolvePath } from './paths.mjs';
17
17
  import { run } from './exec.mjs';
18
18
 
19
- function packJson(dir) {
20
- const output = run('npm', ['pack', '--json', '--dry-run'], {
21
- cwd: dir,
22
- encoding: 'utf8',
23
- stdio: ['ignore', 'pipe', 'pipe'],
24
- });
25
- const [document] = JSON.parse(output);
26
- return { files: (document.files ?? []).map((entry) => entry.path), filename: document.filename, size: document.size };
27
- }
28
-
29
19
  /**
30
- * Pack once, and report the files npm put in *that* tarball.
20
+ * Pack exactly once, and report the files npm put in *that* tarball.
31
21
  *
32
- * The returned list is the one `verify` has to judge: it describes the archive
33
- * npm install is about to receive. A dry-run list is not enough, because npm
34
- * runs `prepack` for the dry run too. A non-idempotent hook can produce a
35
- * different file set the second time, so a tarball that omits the declared
36
- * `client.js` would still pass a check made against the dry run.
22
+ * `prepack` is arbitrary user code. Running a dry run first would execute it
23
+ * twice, and the second invocation can see a tree the first one changed: a hook
24
+ * that deletes `client.js` when it already exists would pass the dry run with a
25
+ * panel and then build the tarball without one. The archive described here is
26
+ * the one the install step below receives, so its file list is the only one
27
+ * `verify` may judge.
37
28
  */
38
29
  function packTarball(dir, destination) {
39
30
  const output = run('npm', ['pack', '--pack-destination', destination, '--json'], {
@@ -196,23 +187,11 @@ export async function verify({ dir, mount = true }) {
196
187
  }
197
188
  const failures = [];
198
189
 
199
- // Keep the dry run as a cheap preflight, but do not trust its file list: a
200
- // non-idempotent `prepack` may put `client.js` in the dry-run list and omit it
201
- // from the tarball npm builds next. That second invocation is the archive
202
- // `verify` installs, so its own file list is the one checked below.
203
- try {
204
- packJson(root);
205
- } catch (error) {
206
- return {
207
- ok: false,
208
- stage: 'pack',
209
- failures: [{ check: 'pack', message: `npm pack failed: ${String(error.stderr ?? error.message).trim().split('\n').slice(-1)[0]}` }],
210
- files: [],
211
- };
212
- }
213
-
214
190
  const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-plugin-verify-'));
215
191
  try {
192
+ // One pack. The dry run that used to precede it was a second `prepack`
193
+ // invocation, and the tarball was built from a tree that hook had already
194
+ // changed. This archive is the exact one handed to `npm install` below.
216
195
  let packed;
217
196
  try {
218
197
  packed = packTarball(root, scratch);
@@ -318,6 +297,17 @@ async function inspectScratch({ dir, mount, report, packed, scratch }) {
318
297
  };
319
298
  }
320
299
 
300
+ // The tarball's own file list caught an omission before install, but the copy
301
+ // npm unpacked is what the loader will actually read. Judge that copy too: a
302
+ // prepack hook (or an ignore file) can still leave the installed package
303
+ // without the patch, the client bundle or the root it declared. `installed`
304
+ // mode skips the `files` allowlist, because by now only the unpacked files
305
+ // matter.
306
+ const unpacked = doctor(installed, { installed: true });
307
+ if (unpacked.failures.length > 0) {
308
+ return { ok: false, stage: 'install', failures: unpacked.failures, files: packed.files, installed };
309
+ }
310
+
321
311
  // The loader starts the host half by importing the bare package name. Doing
322
312
  // the same import here is the only way to know the row will have an apply —
323
313
  // 0.8.0 shipped a package whose root export was the CLI, installed cleanly,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-toolkit",
3
- "version": "0.20.47",
3
+ "version": "0.20.48",
4
4
  "description": "Preflight, release and test DeepSeek Harness plugins: check a folder or any GitHub repository, wait for npm to actually serve the version, and keep the market index honest.",
5
5
  "type": "module",
6
6
  "bin": {