@trops/dash-check 0.3.0 → 0.3.2
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 +105 -11
- package/helpers/node.js +36 -3
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -150,16 +150,7 @@ check("the work is ready for review", async (ctx) => {
|
|
|
150
150
|
});
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|---|---|
|
|
155
|
-
| handoff | `has({ keys })`, `status({ is })`, `eachHas({ list, keys })` |
|
|
156
|
-
| plan | `hasSections({ key, sections })`, `acceptanceEachHasTest({ acceptance, tests })`, `evidenceForAcceptance({ key, acceptanceKey, requireSearch, when })`, `noOpenDecisions({ key, when })` (see below) |
|
|
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
|
|
|
@@ -183,6 +174,26 @@ Checks on a planning bot's handoff, before anyone writes code. They read only th
|
|
|
183
174
|
{ "use": "plan.noOpenDecisions", "with": { "when": "ok, split" } }
|
|
184
175
|
```
|
|
185
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
|
+
|
|
186
197
|
### Factory checks: did the bot do only what it planned?
|
|
187
198
|
|
|
188
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.
|
|
@@ -197,7 +208,7 @@ Checks for a code factory, where a planning bot names the files and a coding bot
|
|
|
197
208
|
| `files.maxGrowth` | A changed file is new and over `maxLines`, crosses `maxLines`, or was already over it and grew by more than `maxAdded` | `glob` (JS/TS), `maxLines` (800), `maxAdded` (50), `exempt`, `base` |
|
|
198
209
|
| `git.validateLeavesTreeClean` | The tree isn't clean before validating, the command fails, or it leaves files changed (a formatter's `--write`, `npm install --save`) | `command` (`npm test`), `timeoutSec` (1800), `allowDirtyBefore` (false) |
|
|
199
210
|
| `node.testScriptIsReal` | The `test` script is missing, empty, a no-op (`exit 0`, `true`, `echo …`, npm's placeholder) or hides its failures (`… \|\| true`). With `run`, also when it reports fewer than `minTests` tests | `script` (`test`), `run` (false), `minTests` (1), `timeoutSec` (900) |
|
|
200
|
-
| `node.newTestsAreRun` | A **new** test file isn't named in a runner file, isn't matched by a glob written in one (`node --test 'test/*.test.js'`), and isn't in `autoGlobs` | `tests` (`**/*.{test,spec}.{js,cjs,mjs,jsx,ts,tsx}`), `runnerFiles` (`package.json`), `autoGlobs` (what the runner finds by itself, e.g. `src/**/*.test.js` for jest), `base` |
|
|
211
|
+
| `node.newTestsAreRun` | A **new** test file isn't named in a runner file, isn't matched by a glob written in one (`node --test 'test/*.test.js'`, brace globs such as `src/**/*.{test,spec}.js` included), and isn't in `autoGlobs` | `tests` (`**/*.{test,spec}.{js,cjs,mjs,jsx,ts,tsx}`), `runnerFiles` (`package.json`), `autoGlobs` (what the runner finds by itself, e.g. `src/**/*.test.js` for jest), `base` |
|
|
201
212
|
|
|
202
213
|
A coding bot's step might run them in this order:
|
|
203
214
|
|
|
@@ -294,6 +305,88 @@ explain(recipe); // ["Work is committed: at least 1 commit(s) p
|
|
|
294
305
|
|
|
295
306
|
`recipeToCode` gives a file that produces the same result as the recipe. The tests check this.
|
|
296
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
|
+
|
|
297
390
|
## The CLI
|
|
298
391
|
|
|
299
392
|
| Command | What it does |
|
|
@@ -331,6 +424,7 @@ A `.check.js` file also runs by itself, `node .dash/checks/validate.check.js`, t
|
|
|
331
424
|
## Use in Dash
|
|
332
425
|
|
|
333
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": { … } }`.
|
|
334
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`.
|
|
335
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" }`.
|
|
336
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).
|
package/helpers/node.js
CHANGED
|
@@ -254,9 +254,42 @@ const testScriptIsReal = defineHelper({
|
|
|
254
254
|
},
|
|
255
255
|
});
|
|
256
256
|
|
|
257
|
-
/**
|
|
257
|
+
/** "a,{b,c}" → ["a", "{b,c}"]: splits on commas outside a glob's {a,b}. */
|
|
258
|
+
function topLevelCommas(word) {
|
|
259
|
+
const out = [];
|
|
260
|
+
let depth = 0;
|
|
261
|
+
let cur = "";
|
|
262
|
+
for (const c of word) {
|
|
263
|
+
if (c === "{") depth++;
|
|
264
|
+
else if (c === "}" && depth > 0) depth--;
|
|
265
|
+
if (c === "," && depth === 0) {
|
|
266
|
+
out.push(cur);
|
|
267
|
+
cur = "";
|
|
268
|
+
} else cur += c;
|
|
269
|
+
}
|
|
270
|
+
out.push(cur);
|
|
271
|
+
return out;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** Are a word's { and } paired, in order? */
|
|
275
|
+
function bracesBalanced(word) {
|
|
276
|
+
let depth = 0;
|
|
277
|
+
for (const c of word) {
|
|
278
|
+
if (c === "{") depth++;
|
|
279
|
+
else if (c === "}" && --depth < 0) return false;
|
|
280
|
+
}
|
|
281
|
+
return depth === 0;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Glob-like words in a runner's text ("test/*.test.js", "src/**", "src/**\/*.{test,spec}.js"):
|
|
286
|
+
* what it finds by itself. A backslash (as in package.json's \\") ends a word. Commas inside
|
|
287
|
+
* a glob's {a,b} stay in the glob; a word whose braces don't pair (a fragment of code, not
|
|
288
|
+
* a glob) is left out.
|
|
289
|
+
*/
|
|
258
290
|
function globsIn(text) {
|
|
259
|
-
|
|
291
|
+
const words = String(text).split(/[\s"'`\\=()[\]]+/).flatMap(topLevelCommas);
|
|
292
|
+
return [...new Set(words.map((w) => w.replace(/^\.\//, "")).filter((w) => /[*?]/.test(w) && /[\w]/.test(w) && bracesBalanced(w)))];
|
|
260
293
|
}
|
|
261
294
|
|
|
262
295
|
const newTestsAreRun = defineHelper({
|
|
@@ -293,4 +326,4 @@ const newTestsAreRun = defineHelper({
|
|
|
293
326
|
},
|
|
294
327
|
});
|
|
295
328
|
|
|
296
|
-
module.exports = { testsPass, lintPasses, noNewDependencies, lockfileExplained, testScriptIsReal, newTestsAreRun, testCount, lockfileProblem, noOpScript };
|
|
329
|
+
module.exports = { testsPass, lintPasses, noNewDependencies, lockfileExplained, testScriptIsReal, newTestsAreRun, testCount, lockfileProblem, noOpScript, globsIn };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trops/dash-check",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
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",
|
|
@@ -10,7 +10,14 @@
|
|
|
10
10
|
},
|
|
11
11
|
"homepage": "https://github.com/trops/dash-check#readme",
|
|
12
12
|
"bugs": "https://github.com/trops/dash-check/issues",
|
|
13
|
-
"keywords": [
|
|
13
|
+
"keywords": [
|
|
14
|
+
"dash",
|
|
15
|
+
"checks",
|
|
16
|
+
"ci",
|
|
17
|
+
"testing",
|
|
18
|
+
"bots",
|
|
19
|
+
"deterministic"
|
|
20
|
+
],
|
|
14
21
|
"engines": {
|
|
15
22
|
"node": ">=18"
|
|
16
23
|
},
|