@trops/dash-check 0.2.0 → 0.3.1

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/README.md CHANGED
@@ -150,16 +150,7 @@ check("the work is ready for review", async (ctx) => {
150
150
  });
151
151
  ```
152
152
 
153
- | Group | Helpers |
154
- |---|---|
155
- | handoff | `has({ keys })`, `status({ is })`, `eachHas({ list, keys })` |
156
- | plan | `hasSections({ key, sections })`, `acceptanceEachHasTest({ acceptance, tests })` |
157
- | git | `onBranch({ branch })`, `committedSince({ base, min })`, `clean()`, `changedOnly({ globs, base })`, `noChangesTo({ globs, base })`, and the factory checks below |
158
- | files | `exist({ paths })`, `contain({ path, text })`, `noneMatch({ glob, pattern })`, `maxGrowth(…)` |
159
- | commands | `passes({ command, timeoutSec })`, `outputMatches({ command, pattern })` |
160
- | node | `testsPass({ command })`, `lintPasses({ command })`, `noNewDependencies({ base, allow })`, `lockfileExplained(…)`, `testScriptIsReal(…)`, `newTestsAreRun(…)` |
161
- | github | `prOpen({ prKey })`, `ciPassed({ prKey, timeoutSec, noChecksAfterSec, ifNoChecks })` |
162
- | tracker | `ticketExists({ provider, tool, idArg, id })`, `ticketHasLabel({ label, … })` (these need Dash's `ctx.tool`) |
153
+ There are 33, in eight groups: `handoff`, `plan`, `git`, `files`, `commands`, `node`, `github` and `tracker`. The [helper reference](#helper-reference) lists every one with its params, defaults and an example step.
163
154
 
164
155
  `npx dash-check --list-helpers` lists each one with its params and defaults.
165
156
 
@@ -169,6 +160,40 @@ A few things every helper does for you:
169
160
  - **`message`.** Every helper takes `message`, which replaces its failure text. Where the failure was (`src/index.js:12`) is kept.
170
161
  - **Errors become failures.** If a helper throws (the folder isn't a git repo, GitHub says 404), the failure says why, and the check goes on to the next step.
171
162
 
163
+ ### Plan checks: is the plan ready to code?
164
+
165
+ Checks on a planning bot's handoff, before anyone writes code. They read only the handoff (no folder, no git), and judge it only when its `status` is one of `when` (default `ok`); any other status passes with "No plan (<status>)", so a bot that answers `none` or `ask` isn't failed for having no plan.
166
+
167
+ | Helper | Fails when | Params (defaults) |
168
+ |---|---|---|
169
+ | `plan.evidenceForAcceptance` | The plan has no `notYetDone`; its `searchedDone` (what it searched for done work, and found) is empty; an acceptance item has no `missing` entry `{ acceptance, read, why }` with the same text and a non-empty `read` and `why`; or it says some code was "not read" | `key` (`notYetDone`), `acceptanceKey` (`acceptance`), `requireSearch` (true), `when` (`ok`; empty judges every handoff) |
170
+ | `plan.noOpenDecisions` | The plan has no `openDecisions` list, or the list isn't empty (then the bot should ask, not plan) | `key` (`openDecisions`), `when` (`ok`) |
171
+
172
+ ```json
173
+ { "use": "plan.evidenceForAcceptance" }
174
+ { "use": "plan.noOpenDecisions", "with": { "when": "ok, split" } }
175
+ ```
176
+
177
+ A handoff both pass:
178
+
179
+ ```json
180
+ {
181
+ "status": "ok",
182
+ "acceptance": ["Links look clickable"],
183
+ "notYetDone": {
184
+ "searchedDone": "Done tickets about link styles: none. safeMarkdown.js sets only rel and target on links.",
185
+ "missing": [
186
+ { "acceptance": "Links look clickable",
187
+ "read": "src/utils/safeMarkdown.js ensureLinkHook",
188
+ "why": "It adds no class, so links render as plain text" }
189
+ ]
190
+ },
191
+ "openDecisions": []
192
+ }
193
+ ```
194
+
195
+ With a question in `openDecisions` (`["Which colour?"]`), `plan.noOpenDecisions` fails: "The plan leaves decisions open: Which colour?. Don't plan: answer status ask with the question for the user." With no `searchedDone` or no `missing` entry for an item, `plan.evidenceForAcceptance` fails saying what to add.
196
+
172
197
  ### Factory checks: did the bot do only what it planned?
173
198
 
174
199
  Checks for a code factory, where a planning bot names the files and a coding bot changes them. Each works on any repo: all it needs is git and, for the plan checks, a handoff that lists files. Every one compares with `base` (default `{repo.baseBranch}`; empty means the repo's default branch, through `origin/` when the remote has it), and every one judges only **what the work changed**, so existing debt in the repo doesn't fail it.
@@ -280,6 +305,88 @@ explain(recipe); // ["Work is committed: at least 1 commit(s) p
280
305
 
281
306
  `recipeToCode` gives a file that produces the same result as the recipe. The tests check this.
282
307
 
308
+ ## Helper reference
309
+
310
+ Every helper in `@trops/dash-check/helpers`, from `dash-check --list-helpers --json` (the same data Dash's check composer shows). In a recipe, a step is `{ "use": "<id>", "with": { …params } }`; in code, `await <group>.<name>(ctx, { …params })`. Every helper also takes `message`, which replaces its failure text.
311
+
312
+ - A param with no default is optional unless it says *required*.
313
+ - A `list` takes `"a, b"` or `["a", "b"]`. A glob's `{a,b}` stays whole.
314
+ - `{placeholders}` are filled from the job: `{repo.baseBranch}` from the picked row, `{item.id}` from the work item, `{workRoot}` (any name) from the team's settings, `{workspace.branch}` from the job's workspace. A placeholder with no value counts as empty, so `base` falls back to the repo's default branch.
315
+ - `tracker.*` call `ctx.tool`, which only Dash answers.
316
+
317
+ ### handoff
318
+
319
+ | Helper | Checks | Params (default) | Example step |
320
+ |---|---|---|---|
321
+ | `handoff.has` | The bot's handoff includes these, not empty | `keys` list (required) | `{"use":"handoff.has","with":{"keys":"prUrl, plan.cause"}}` |
322
+ | `handoff.status` | The handoff's status (ok, none, ask or split) | `is` select (`ok`): `ok` or `none` or `ask` or `split` | `{"use":"handoff.status","with":{"is":"ok"}}` |
323
+ | `handoff.eachHas` | Every entry of a handoff list has these, not empty | `list` text (required); `keys` list (required) | `{"use":"handoff.eachHas","with":{"list":"tests","keys":"acceptance, file"}}` |
324
+
325
+ ### plan
326
+
327
+ | Helper | Checks | Params (default) | Example step |
328
+ |---|---|---|---|
329
+ | `plan.hasSections` | The handoff's plan has each section, not empty | `key` text (`plan`); `sections` list (`cause, fix, test`) | `{"use":"plan.hasSections","with":{"sections":"cause, fix, test"}}` |
330
+ | `plan.acceptanceEachHasTest` | Plan: every item is tested | `acceptance` text (`acceptance`); `tests` text (`tests`) | `{"use":"plan.acceptanceEachHasTest"}` |
331
+ | `plan.evidenceForAcceptance` | Plan: it searched for finished work, and for each acceptance item says what it read and why it's still missing | `key` text (`notYetDone`); `acceptanceKey` text (`acceptance`); `requireSearch` boolean (`true`); `when` list (`ok`) | `{"use":"plan.evidenceForAcceptance"}` |
332
+ | `plan.noOpenDecisions` | Plan: it lists the decisions still open, and there are none | `key` text (`openDecisions`); `when` list (`ok`) | `{"use":"plan.noOpenDecisions","with":{"when":"ok, split"}}` |
333
+
334
+ ### git
335
+
336
+ | Helper | Checks | Params (default) | Example step |
337
+ |---|---|---|---|
338
+ | `git.onBranch` | The workspace is on workspace.branch | `branch` text (`{workspace.branch}`) | `{"use":"git.onBranch"}` |
339
+ | `git.committedSince` | Commits past the base, nothing uncommitted | `base` text (`{repo.baseBranch}`); `min` number (`1`) | `{"use":"git.committedSince","with":{"base":"{repo.baseBranch}","min":1}}` |
340
+ | `git.clean` | No staged, unstaged or untracked changes | none | `{"use":"git.clean"}` |
341
+ | `git.changedOnly` | Changed files match globs | `globs` list (required); `base` text (`{repo.baseBranch}`) | `{"use":"git.changedOnly","with":{"globs":"src/**, test/**"}}` |
342
+ | `git.noChangesTo` | No changed file matches the globs | `globs` list (required); `base` text (`{repo.baseBranch}`) | `{"use":"git.noChangesTo","with":{"globs":".github/workflows/**, .dash/checks/**"}}` |
343
+ | `git.changesMatchPlan` | Every changed file is named in the handoff's plan | `base` text (`{repo.baseBranch}`); `planKeys` list (`files, newFiles, tests`); `alsoAllow` list; `lockfiles` list (`package-lock.json, npm-shrinkwrap.json, yarn.lock, pnpm-lock.yaml`) | `{"use":"git.changesMatchPlan","with":{"alsoAllow":"CHANGELOG.md"}}` |
344
+ | `git.commitsScoped` | Every commit touches only planned files and names the item | `base` text (`{repo.baseBranch}`); `planKeys` list (`files, newFiles, tests`); `alsoAllow` list; `lockfiles` list (`package-lock.json, npm-shrinkwrap.json, yarn.lock, pnpm-lock.yaml`); `mentions` text (`{item.id}`) | `{"use":"git.commitsScoped","with":{"mentions":"{item.id}"}}` |
345
+ | `git.sourceHasTests` | Each changed source file has a changed test (paired by name, or any) | `sources` list (`src/**/*.{js,jsx,ts,tsx,mjs,cjs}, lib/**/*.{js,jsx,ts,tsx,mjs,cjs}, !**/*.{test,spec}.*, !**/__tests__/**, !**/*.stories.*, !**/*.d.ts`); `tests` list (`**/*.{test,spec}.*, **/__tests__/**, test/**, tests/**`); `testPattern` list (`<dir>/<name>.{test,spec}.*, <dir>/__tests__/<name>.*, {test,tests}/**/<name>.{test,spec}.*, {test,tests}/**/<name>.*`); `mode` select (`paired`): `paired` or `any`; `exempt` list; `base` text (`{repo.baseBranch}`) | `{"use":"git.sourceHasTests","with":{"mode":"paired","exempt":"**/index.js"}}` |
346
+ | `git.noNewMatches` | e.g. no new TODO or console.log; lines already there don't count | `glob` list (required); `pattern` regex (required); `base` text (`{repo.baseBranch}`) | `{"use":"git.noNewMatches","with":{"glob":"src/**, !**/*.test.*","pattern":"console\\.log\\("}}` |
347
+ | `git.validateLeavesTreeClean` | Running the validate command leaves no file changed (no formatter --write, no npm install --save) | `command` text (`npm test`); `timeoutSec` number (`1800`); `allowDirtyBefore` boolean (`false`) | `{"use":"git.validateLeavesTreeClean","with":{"command":"npm run ci"}}` |
348
+
349
+ ### files
350
+
351
+ | Helper | Checks | Params (default) | Example step |
352
+ |---|---|---|---|
353
+ | `files.exist` | Paths in the workspace | `paths` list (required) | `{"use":"files.exist","with":{"paths":"README.md, src/index.js"}}` |
354
+ | `files.contain` | A file has some text in it | `path` path (required); `text` text (required) | `{"use":"files.contain","with":{"path":"CHANGELOG.md","text":"{item.id}"}}` |
355
+ | `files.noneMatch` | e.g. no console.log in src | `glob` glob (required); `pattern` regex (required) | `{"use":"files.noneMatch","with":{"glob":"src/**/*.js","pattern":"debugger"}}` |
356
+ | `files.maxGrowth` | A changed file stays under a size, and a big file doesn't grow much | `glob` list (`**/*.{js,jsx,ts,tsx,mjs,cjs}`); `maxLines` number (`800`); `maxAdded` number (`50`); `exempt` list; `base` text (`{repo.baseBranch}`) | `{"use":"files.maxGrowth","with":{"maxLines":800,"maxAdded":50}}` |
357
+
358
+ ### commands
359
+
360
+ | Helper | Checks | Params (default) | Example step |
361
+ |---|---|---|---|
362
+ | `commands.passes` | Exit 0 | `command` text (required); `timeoutSec` number (`120`) | `{"use":"commands.passes","with":{"command":"npm run build","timeoutSec":300}}` |
363
+ | `commands.outputMatches` | Its output matches a pattern | `command` text (required); `pattern` regex (required); `timeoutSec` number (`120`) | `{"use":"commands.outputMatches","with":{"command":"node --version","pattern":"^v(18\|20\|22)\\."}}` |
364
+
365
+ ### node
366
+
367
+ | Helper | Checks | Params (default) | Example step |
368
+ |---|---|---|---|
369
+ | `node.testsPass` | npm test, or a command | `command` text (`npm test`); `timeoutSec` number (`900`) | `{"use":"node.testsPass","with":{"command":"npm test"}}` |
370
+ | `node.lintPasses` | npm run lint, or a command | `command` text (`npm run lint`); `timeoutSec` number (`300`) | `{"use":"node.lintPasses"}` |
371
+ | `node.noNewDependencies` | package.json adds none since the base | `base` text (`{repo.baseBranch}`); `allow` list | `{"use":"node.noNewDependencies","with":{"allow":"@trops/dash-check"}}` |
372
+ | `node.lockfileExplained` | The lockfile changed only with a dependency (or only its version) | `base` text (`{repo.baseBranch}`); `lockfile` path (`package-lock.json`); `manifest` path | `{"use":"node.lockfileExplained"}` |
373
+ | `node.testScriptIsReal` | package.json's test script isn't a no-op, and can run tests | `script` text (`test`); `run` boolean (`false`); `minTests` number (`1`); `timeoutSec` number (`900`) | `{"use":"node.testScriptIsReal","with":{"run":true,"minTests":1}}` |
374
+ | `node.newTestsAreRun` | Every new test file is picked up by a test runner | `base` text (`{repo.baseBranch}`); `tests` list (`**/*.{test,spec}.{js,cjs,mjs,jsx,ts,tsx}`); `runnerFiles` list (`package.json`); `autoGlobs` list | `{"use":"node.newTestsAreRun","with":{"runnerFiles":"package.json, scripts/ci.sh","autoGlobs":"src/**/*.test.js"}}` |
375
+
376
+ ### github
377
+
378
+ | Helper | Checks | Params (default) | Example step |
379
+ |---|---|---|---|
380
+ | `github.prOpen` | The handoff's PR is open on GitHub | `prKey` text (`prUrl`) | `{"use":"github.prOpen"}` |
381
+ | `github.ciPassed` | Waits, with a deadline | `prKey` text (`prUrl`); `timeoutSec` number (`1200`); `noChecksAfterSec` number (`180`); `ifNoChecks` select (`fail`): `fail` or `pass` | `{"use":"github.ciPassed","with":{"timeoutSec":1200,"ifNoChecks":"fail"}}` |
382
+
383
+ ### tracker
384
+
385
+ | Helper | Checks | Params (default) | Example step |
386
+ |---|---|---|---|
387
+ | `tracker.ticketExists` | The work item is in the tracker | `provider` text (`jira`); `tool` text (`getJiraIssue`); `idArg` text (`issueIdOrKey`); `id` text (`{item.id}`) | `{"use":"tracker.ticketExists"}` |
388
+ | `tracker.ticketHasLabel` | The work item carries a label | `label` text (required); `provider` text (`jira`); `tool` text (`getJiraIssue`); `idArg` text (`issueIdOrKey`); `id` text (`{item.id}`) | `{"use":"tracker.ticketHasLabel","with":{"label":"factory"}}` |
389
+
283
390
  ## The CLI
284
391
 
285
392
  | Command | What it does |
@@ -317,6 +424,7 @@ A `.check.js` file also runs by itself, `node .dash/checks/validate.check.js`, t
317
424
  ## Use in Dash
318
425
 
319
426
  - **A repo check.** Commit `.dash/checks/<name>.check.js` (or `.check.json`) in a PR. A bot step `{ "kind": "repo", "name": "<name>" }` runs it from the repo's **base branch**, so a bot working on a branch can't change the check that judges it.
427
+ - **One helper on a bot.** A step `{ "kind": "helper", "use": "git.changesMatchPlan", "with": { … }, "handoffFrom": "handed" }` runs one helper with no file. `handoffFrom: "handed"` reads the handoff the bot was handed (a Coder's check reads the Planner's plan). Bots › Checks offers the factory and plan helpers; any other helper works too. Several helpers on a bot: `{ "kind": "recipe", "recipe": { … } }`.
320
428
  - **What the check sees.** Dash passes the job's item, workspace, picked rows and settings in the input. Those are `ctx.item`, `ctx.workspace`, `ctx.row` and `ctx.settings`.
321
429
  - **`ctx.tool`.** Dash answers `ctx.tool` through `DASH_TOOL_SOCKET`, a local socket that takes one JSON line `{ "id", "provider", "tool", "args" }` and answers `{ "id", "result" }` or `{ "id", "error" }`.
322
430
  - **The composer.** Dash's composer lists the palette from `dash-check --list-helpers --json`. It runs a recipe on a sample with `runRecipe` (Try it), and shows it as code with `recipeToCode` (View as code).
@@ -73,8 +73,30 @@ export interface NewTestsAreRunParams extends Base {
73
73
  autoGlobs?: List;
74
74
  }
75
75
 
76
+ export interface EvidenceForAcceptanceParams {
77
+ /** The evidence: { searchedDone, missing: [{ acceptance, read, why }] }. Default "notYetDone". */
78
+ key?: string;
79
+ /** Default "acceptance". */
80
+ acceptanceKey?: string;
81
+ /** Needs searchedDone. Default true. */
82
+ requireSearch?: boolean;
83
+ /** Judge only when the handoff's status is one of these; others pass. Default ["ok"]; empty judges every handoff. */
84
+ when?: List;
85
+ }
86
+ export interface NoOpenDecisionsParams {
87
+ /** Default "openDecisions". */
88
+ key?: string;
89
+ /** Judge only when the handoff's status is one of these; others pass. Default ["ok"]; empty judges every handoff. */
90
+ when?: List;
91
+ }
92
+
76
93
  export const handoff: { has: H; status: H; eachHas: H };
77
- export const plan: { hasSections: H; acceptanceEachHasTest: H };
94
+ export const plan: {
95
+ hasSections: H;
96
+ acceptanceEachHasTest: H;
97
+ evidenceForAcceptance: Helper<EvidenceForAcceptanceParams>;
98
+ noOpenDecisions: Helper<NoOpenDecisionsParams>;
99
+ };
78
100
  export const git: {
79
101
  onBranch: H;
80
102
  committedSince: H;
package/helpers/plan.js CHANGED
@@ -3,7 +3,7 @@
3
3
  */
4
4
  "use strict";
5
5
 
6
- const { defineHelper, expect, note } = require("..");
6
+ const { defineHelper, expect, fail, note } = require("..");
7
7
  const { needHandoff } = require("./handoff");
8
8
 
9
9
  const hasSections = defineHelper({
@@ -52,4 +52,88 @@ const acceptanceEachHasTest = defineHelper({
52
52
  },
53
53
  });
54
54
 
55
- module.exports = { hasSections, acceptanceEachHasTest };
55
+ /**
56
+ * Whether to judge this handoff: only when its status is one of `when`
57
+ * (empty: always). Otherwise it notes "No plan (<status>)" and passes.
58
+ */
59
+ function judges(ctx, when) {
60
+ if (!when.length) return true;
61
+ const s = ctx.handoff && ctx.handoff.status;
62
+ if (when.includes(s)) return true;
63
+ note(`No plan (${s === undefined ? "no status" : s})`);
64
+ return false;
65
+ }
66
+
67
+ const NOT_READ = /not read|didn.t read|wasn.t read|unread/i;
68
+
69
+ const evidenceForAcceptance = defineHelper({
70
+ id: "plan.evidenceForAcceptance",
71
+ group: "Handoff",
72
+ label: "It checked the work isn't already done",
73
+ description: "Plan: it searched for finished work, and for each acceptance item says what it read and why it's still missing",
74
+ sentence: "handoff.{key} has a search and, for every item in handoff.{acceptanceKey}, what was read and why it's missing",
75
+ params: {
76
+ key: { type: "text", label: "Evidence key", default: "notYetDone", description: "Holds searchedDone and missing: [{ acceptance, read, why }]" },
77
+ acceptanceKey: { type: "text", label: "Acceptance key", default: "acceptance" },
78
+ requireSearch: { type: "boolean", label: "Needs a search", default: true, description: "The evidence must say what it searched for done work (searchedDone)" },
79
+ when: { type: "list", label: "Only when status is", default: ["ok"], description: "Other statuses pass; empty judges every handoff" },
80
+ },
81
+ reads: ["handoff"],
82
+ run(ctx, { key, acceptanceKey, requireSearch, when }) {
83
+ if (!needHandoff(ctx)) return;
84
+ if (!judges(ctx, when)) return;
85
+ const nd = ctx.get(`handoff.${key}`);
86
+ if (!nd || typeof nd !== "object" || Array.isArray(nd)) {
87
+ fail(
88
+ `No ${key}: before planning, ${requireSearch ? "search for done work like this (searchedDone) and, " : ""}for each ${acceptanceKey} item, read the code that would do it and say why it is still missing (missing)`
89
+ );
90
+ return;
91
+ }
92
+ if (requireSearch && !String(nd.searchedDone || "").trim()) {
93
+ fail(`${key}.searchedDone is empty: search for done tickets like this one and say what you searched and found`);
94
+ }
95
+ const acc = ctx.get(`handoff.${acceptanceKey}`);
96
+ const items = Array.isArray(acc) ? acc : [];
97
+ const miss = Array.isArray(nd.missing) ? nd.missing : [];
98
+ const lacking = items.filter(
99
+ (a) => !miss.some((m) => m && m.acceptance === a && String(m.read || "").trim() && String(m.why || "").trim())
100
+ );
101
+ if (lacking.length) {
102
+ fail(
103
+ `No evidence it is still missing for: ${lacking.join("; ")}. For each, name the file and function you read (read) and why it does not already do it (why).`
104
+ );
105
+ }
106
+ if (NOT_READ.test(JSON.stringify(nd))) fail(`${key} says some code was not read: read it before planning`);
107
+ note(`${requireSearch ? "Searched for done work, and evidence" : "Evidence"} for ${items.length} ${acceptanceKey} item${items.length === 1 ? "" : "s"}`);
108
+ },
109
+ });
110
+
111
+ const noOpenDecisions = defineHelper({
112
+ id: "plan.noOpenDecisions",
113
+ group: "Handoff",
114
+ label: "Nothing is left for the user to decide",
115
+ description: "Plan: it lists the decisions still open, and there are none",
116
+ sentence: "handoff.{key} is an empty list",
117
+ params: {
118
+ key: { type: "text", label: "Decisions key", default: "openDecisions" },
119
+ when: { type: "list", label: "Only when status is", default: ["ok"], description: "Other statuses pass; empty judges every handoff" },
120
+ },
121
+ reads: ["handoff"],
122
+ run(ctx, { key, when }) {
123
+ if (!needHandoff(ctx)) return;
124
+ if (!judges(ctx, when)) return;
125
+ const list = ctx.get(`handoff.${key}`);
126
+ if (!Array.isArray(list)) {
127
+ fail(`No ${key}: list every choice the ticket or your plan leaves open (approach, design, scope, work outside the repos), or [] if there are none`);
128
+ return;
129
+ }
130
+ if (list.length) {
131
+ const text = list.map((d) => (typeof d === "string" ? d : JSON.stringify(d))).join("; ");
132
+ fail(`The plan leaves decisions open: ${text}. Don't plan: answer status ask with the question for the user.`);
133
+ return;
134
+ }
135
+ note("No open decisions");
136
+ },
137
+ });
138
+
139
+ module.exports = { hasSections, acceptanceEachHasTest, evidenceForAcceptance, noOpenDecisions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trops/dash-check",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Compose deterministic checks from small, described building blocks: Jest-style files, JSON recipes and helpers. Runs in Dash, in CI and on a laptop.",
5
5
  "license": "MIT",
6
6
  "author": "trops",