dsh-plugin-toolkit 0.3.1 → 0.3.3

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,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.3
4
+
5
+ - `mount` on a path that is missing, or that is a directory, now says what to pass instead of raising `ENOENT: no such file or directory, open '…'`. Found by running the three commands in a clean HOME with a fresh clone.
6
+
7
+ ## 0.3.2
8
+
9
+ - `expectSnapshot(html, dir, name)`: the assertion form of `compare`, so a baseline test reads like a test and fails with the element that moved.
10
+ - README: how to keep a DOM baseline, and how to assert what assistive tech sees.
11
+
3
12
  ## 0.3.1
4
13
 
5
14
  - `unmount()` now waits one macrotask before the DOM goes away. React schedules work during its own unmount, and closing jsdom first turned that into `ReferenceError: window is not defined` after a passing test. Found by the example plugin's second test.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # dsh-plugin-toolkit
2
2
 
3
+ ![dsh-plugin-toolkit](docs/card.png)
4
+
3
5
  A preflight and release tool for [DeepSeek Harness](https://github.com/deepseek-ai/dsh) plugins, plus the pieces of the publishing ritual that kept going wrong by hand.
4
6
 
5
7
  ```
@@ -53,6 +55,29 @@ await panel.unmount();
53
55
 
54
56
  What you get back: `text()`, `html()`, `query(selector)`, `must(selector)` (throws with the rendered HTML when it misses), `click(selector)`, `type(selector, value)`, `press(selector, key)`, `focus`, `attributes(selector)`, `snapshot(dir, name)` for a normalised DOM baseline, and `host` for assertions about what the bundle registered.
55
57
 
58
+ ### Keep a visual baseline
59
+
60
+ The DOM is the baseline: normalising class order and whitespace gives a file that fails for the reasons a screenshot would — a lost label, a control that stopped rendering — and can be reviewed in a diff instead of by eye.
61
+
62
+ ```js
63
+ import { expectSnapshot } from 'dsh-plugin-toolkit/testkit';
64
+
65
+ const panel = await mountClient({ file: 'client.js' });
66
+ expectSnapshot(panel.html(), '__snapshots__', 'panel'); // throws with the element that moved
67
+ await panel.unmount();
68
+ ```
69
+
70
+ First run writes nothing: it tells you to re-run with `UPDATE_SNAPSHOTS=1`, so a baseline is always a decision, never a side effect.
71
+
72
+ ### Check what assistive tech sees
73
+
74
+ ```js
75
+ assert.equal(panel.attributes('[role="tab"][aria-selected="true"]').id, 'tab-protection');
76
+ assert.match(panel.must('[role="status"]').textContent, /Score moved 71 → 77/);
77
+ ```
78
+
79
+ `must()` throws with the rendered markup when the selector misses, which is the difference between "the assertion failed" and "here is what the user actually got".
80
+
56
81
  To look at a bundle by hand:
57
82
 
58
83
  ```sh
@@ -83,6 +108,10 @@ The host already swaps a rebuilt bundle without a page reload: it watches each p
83
108
  npx dsh-plugin dev . --host http://127.0.0.1:54133
84
109
  ```
85
110
 
111
+ ![dsh-plugin dev printing the revision the app reported](docs/dev.gif)
112
+
113
+ *Recorded from a real run against the running app: the last line is the revision the app sent back on `/plugins/events`, not a message the tool printed on faith.*
114
+
86
115
  ```
87
116
  demo-aiignore: /work/plugin/client.js -> ~/.dsh/profiles/desktop/node_modules/dsh-aiignore/client.js
88
117
  initial: copied 163647 bytes at 1:18:43 AM
@@ -9,4 +9,4 @@ export { createHost } from './host.mjs';
9
9
  export { createFetch } from './fetch.mjs';
10
10
  export { createModuleLoader, loadBundle } from './load.mjs';
11
11
  export { mountClient } from './mount.mjs';
12
- export { compare, normalize, snapshotPath, write } from './snapshot.mjs';
12
+ export { compare, expectSnapshot, normalize, snapshotPath, write } from './snapshot.mjs';
@@ -8,6 +8,23 @@
8
8
  */
9
9
  import fs from 'node:fs';
10
10
 
11
+ /**
12
+ * Read the bundle, or say what is wrong with the path in the caller's words.
13
+ *
14
+ * A raw ENOENT is technically true and practically useless: the usual mistake is
15
+ * passing the plugin folder, or a path relative to the wrong directory.
16
+ */
17
+ function readBundleSource(file) {
18
+ const resolved = String(file);
19
+ if (fs.existsSync(resolved) === false) {
20
+ throw new Error(`no such file: ${resolved} (mount takes the client bundle, e.g. ./client.js)`);
21
+ }
22
+ if (fs.statSync(resolved).isDirectory() === true) {
23
+ throw new Error(`${resolved} is a directory (mount takes the client bundle inside it, e.g. ${resolved}/client.js)`);
24
+ }
25
+ return fs.readFileSync(resolved, 'utf8');
26
+ }
27
+
11
28
  export function createModuleLoader({ require: provide, onLoad } = {}) {
12
29
  const loaded = [];
13
30
  const loader = {
@@ -27,7 +44,7 @@ export function createModuleLoader({ require: provide, onLoad } = {}) {
27
44
  }
28
45
 
29
46
  export function loadBundle(file, options = {}) {
30
- const source = fs.readFileSync(file, 'utf8');
47
+ const source = readBundleSource(file);
31
48
  const loader = createModuleLoader(options);
32
49
  const context = { window: { __ModuleLoader__: loader }, __ModuleLoader__: loader, ...(options.globals ?? {}) };
33
50
  // The bundle is an IIFE or a top-level statement list; the browser would run it
@@ -45,3 +45,24 @@ export function write(dir, name, html) {
45
45
  fs.writeFileSync(file, `${normalize(html)}\n`);
46
46
  return file;
47
47
  }
48
+
49
+ /**
50
+ * The assertion form of `compare`, so a baseline test reads like a test and
51
+ * fails with the thing that moved rather than two walls of markup.
52
+ */
53
+ export function expectSnapshot(html, dir, name) {
54
+ const result = compare(dir, name, html);
55
+ if (result.status === 'same') return result;
56
+ if (result.status === 'missing') {
57
+ throw new Error(`no baseline at ${result.file}; run with UPDATE_SNAPSHOTS=1 to create it`);
58
+ }
59
+ const expected = result.expected.split(/(?=<)/);
60
+ const actual = result.actual.split(/(?=<)/);
61
+ const position = result.firstDifference;
62
+ throw new Error([
63
+ `${name} changed at element ${position}`,
64
+ ` expected: ${expected[position] ?? '(nothing)'}`,
65
+ ` actual: ${actual[position] ?? '(nothing)'}`,
66
+ ` baseline: ${result.file}`,
67
+ ].join('\n'));
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-toolkit",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Preflight, release and test DeepSeek Harness plugins: checks what the host needs, waits for npm to actually serve the version, and keeps the market index honest.",
5
5
  "type": "module",
6
6
  "bin": {