@trops/dash-check 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +309 -2
- package/cli/bin.js +12 -0
- package/cli/index.d.ts +7 -0
- package/cli/index.js +566 -0
- package/examples/changes-match-plan.bad.json +4 -0
- package/examples/changes-match-plan.check.js +10 -0
- package/examples/changes-match-plan.sample.json +4 -0
- package/examples/every-acceptance-has-a-test.bad.json +3 -0
- package/examples/every-acceptance-has-a-test.check.js +19 -0
- package/examples/every-acceptance-has-a-test.sample.json +3 -0
- package/examples/helpers/changelog.js +23 -0
- package/examples/jira-comment-from-job.bad.json +5 -0
- package/examples/jira-comment-from-job.check.js +10 -0
- package/examples/jira-comment-from-job.sample.json +5 -0
- package/examples/merge-outcome.bad.json +4 -0
- package/examples/merge-outcome.check.js +9 -0
- package/examples/merge-outcome.sample.json +4 -0
- package/examples/on-branch.bad.json +6 -0
- package/examples/on-branch.check.js +12 -0
- package/examples/on-branch.sample.json +6 -0
- package/examples/plan-complete.bad.json +5 -0
- package/examples/plan-complete.check.js +14 -0
- package/examples/plan-complete.sample.json +5 -0
- package/examples/pr-ci.bad.json +4 -0
- package/examples/pr-ci.check.js +12 -0
- package/examples/pr-ci.sample.json +4 -0
- package/examples/ready-for-review.bad.json +6 -0
- package/examples/ready-for-review.check.json +12 -0
- package/examples/ready-for-review.sample.json +6 -0
- package/examples/setup.bad.json +6 -0
- package/examples/setup.check.js +8 -0
- package/examples/setup.sample.json +6 -0
- package/examples/ticket-has-acceptance.bad.json +4 -0
- package/examples/ticket-has-acceptance.check.js +10 -0
- package/examples/ticket-has-acceptance.sample.json +4 -0
- package/examples/validate.bad.json +6 -0
- package/examples/validate.check.js +14 -0
- package/examples/validate.sample.json +6 -0
- package/examples/work-committed.bad.json +13 -0
- package/examples/work-committed.check.js +13 -0
- package/examples/work-committed.sample.json +5 -0
- package/examples/workspace-cleaned.bad.json +4 -0
- package/examples/workspace-cleaned.check.js +7 -0
- package/examples/workspace-cleaned.sample.json +4 -0
- package/helpers/commands.js +62 -0
- package/helpers/files.js +74 -0
- package/helpers/git.js +116 -0
- package/helpers/github.js +77 -0
- package/helpers/handoff.js +80 -0
- package/helpers/index.d.ts +15 -0
- package/helpers/index.js +36 -0
- package/helpers/node.js +106 -0
- package/helpers/plan.js +55 -0
- package/helpers/tracker.js +60 -0
- package/index.d.ts +325 -0
- package/index.js +86 -0
- package/lib/adapters/fs.js +85 -0
- package/lib/adapters/git.js +87 -0
- package/lib/adapters/github.js +151 -0
- package/lib/adapters/run.js +76 -0
- package/lib/adapters/tool.js +64 -0
- package/lib/context.js +102 -0
- package/lib/discover.js +102 -0
- package/lib/expect.js +238 -0
- package/lib/glob.js +89 -0
- package/lib/handoff.js +68 -0
- package/lib/helper.js +219 -0
- package/lib/register.js +35 -0
- package/lib/runner.js +214 -0
- package/lib/scope.js +107 -0
- package/lib/util.js +122 -0
- package/lib/values.js +138 -0
- package/package.json +59 -4
- package/recipe/index.d.ts +70 -0
- package/recipe/index.js +381 -0
- package/recipe/schema.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 trops
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,310 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @trops/dash-check
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Write checks that prove a bot (or a person) did the job: tests pass, the work is committed, every acceptance item has a test, the PR's CI is green. If you know Jest, you already know most of it.
|
|
4
|
+
|
|
5
|
+
- **Deterministic.** No AI. The same input gives the same result, and a failure says exactly what to fix.
|
|
6
|
+
- **Made of building blocks.** Pick a ready-made helper, compose your own check in a file or as JSON, or write your own helper once and reuse it.
|
|
7
|
+
- **Runs anywhere Node runs:** in [Dash](https://github.com/trops/dash-electron), in CI and on your laptop.
|
|
8
|
+
- **No dependencies.** Node 18 or later.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install --save-dev @trops/dash-check
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Your first check in 2 minutes
|
|
17
|
+
|
|
18
|
+
**1. Make one.** In your repo:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npx dash-check new ready
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
That writes two files:
|
|
25
|
+
|
|
26
|
+
- `.dash/checks/ready.check.js`, the check;
|
|
27
|
+
- `.dash/checks/ready.sample.json`, a sample input to try it on.
|
|
28
|
+
|
|
29
|
+
**2. Read it.** It looks like a Jest test:
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
const { check, expect } = require("@trops/dash-check");
|
|
33
|
+
const { handoff } = require("@trops/dash-check/helpers");
|
|
34
|
+
|
|
35
|
+
check("ready", async (ctx) => {
|
|
36
|
+
await handoff.has(ctx, { keys: ["summary"] });
|
|
37
|
+
expect(ctx.handoff.files, "handoff.files").toHaveLengthAtLeast(1, "The handoff lists no changed files");
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`ctx` holds everything a check can look at (the bot's handoff, the work item, git, the files…). The last argument of a matcher, `"The handoff lists no changed files"`, is what the failure says. Write it as the fix.
|
|
42
|
+
|
|
43
|
+
**3. Run it.**
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npx dash-check ready
|
|
47
|
+
# ✓ ready: The handoff has summary
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**4. Make it fail.** Edit the sample so `"files": []` and run it again:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
✗ ready
|
|
54
|
+
● The handoff lists no changed files
|
|
55
|
+
✗ ready: The handoff lists no changed files
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
A good check passes on good input **and** fails on bad input with a reason that says what to fix. Always try both.
|
|
59
|
+
|
|
60
|
+
## How a check runs
|
|
61
|
+
|
|
62
|
+
A check gets an **input**: Dash's check input, or a sample file. The input is JSON with the bot's answer, the work item, the workspace and the team's settings:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"input": { "answer": "Done.\n\n```json\n{ \"files\": [\"src/index.js\"] }\n```" },
|
|
67
|
+
"item": { "id": "DASH-97", "title": "Title-case board names" },
|
|
68
|
+
"workspace": { "dir": ".", "branch": "feat/DASH-97-titlecase" },
|
|
69
|
+
"row": { "repo": { "baseBranch": "main" } },
|
|
70
|
+
"settings": { "mergeWhenGreen": true }
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
It gives a **result**:
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
{ pass: false,
|
|
78
|
+
reason: "The handoff lists no changed files",
|
|
79
|
+
checks: [{ name: "ready", pass: false, reason: "…", failures: [{ message, at?, expected, received }] }] }
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Run as a file, it prints a report, then one last line of JSON, `{"reason": "…", "details": {…}}`. That's Dash's check contract: exit 0 passes, and the last line says why.
|
|
83
|
+
|
|
84
|
+
Every failing `expect` is **collected**, and the check goes on, so a check lists *all* the gaps, not just the first. A matcher returns `true` or `false`, so you can guard code that needs the value:
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
if (expect(handoff.tests, "handoff.tests").toBeArray()) {
|
|
88
|
+
for (const t of handoff.tests) expect(t.file, `${t.acceptance}'s file`).toBeNonEmptyString(`No file for: ${t.acceptance}`);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## The layers
|
|
93
|
+
|
|
94
|
+
dash-check has three layers. Each is built only from the one below it, so anything a helper or a recipe does, you can do in code.
|
|
95
|
+
|
|
96
|
+
### Layer 0: primitives (`@trops/dash-check`)
|
|
97
|
+
|
|
98
|
+
**The runner.** `check(name, fn)`, `check.skip`, `check.only` and `describe(name, fn)`. `fn` gets `ctx` and may be async.
|
|
99
|
+
|
|
100
|
+
**`expect(value, label?)`.** `label` names the value in a failure. Every matcher takes an optional last argument, `message`, which is the fix shown on failure:
|
|
101
|
+
|
|
102
|
+
| Kind | Matchers |
|
|
103
|
+
|---|---|
|
|
104
|
+
| Equality and type | `toBe`, `toEqual`, `toBeDefined`, `toBeTruthy`, `toBeArray`, `toBeString`, `toBeNonEmptyString`, `toBeNumber` |
|
|
105
|
+
| Size | `toBeEmpty`, `toHaveLength(n)`, `toHaveLengthAtLeast(n)` |
|
|
106
|
+
| Membership | `toContain(item)`, `toBeOneOf(list)`, `toHaveKeys(keys)` |
|
|
107
|
+
| Text and numbers | `toMatch(regex or string)`, `toBeGreaterThan(n)`, `toBeLessThan(n)` |
|
|
108
|
+
| Modifiers | `.not`, `.resolves`, `.rejects` (`await expect(p).resolves.toBe(1)`) |
|
|
109
|
+
|
|
110
|
+
You can also call `fail(message, { at })` to fail with a message and a location, and `note(text)` to say how a check passed.
|
|
111
|
+
|
|
112
|
+
**The context (`ctx`).**
|
|
113
|
+
|
|
114
|
+
| Reader | What it gives |
|
|
115
|
+
|---|---|
|
|
116
|
+
| `ctx.input` | The raw check input (Dash's `$DASH_INPUT`) |
|
|
117
|
+
| `ctx.answer` | The bot's whole answer |
|
|
118
|
+
| `ctx.handoff` | The bot's handoff: its answer's last ```` ```json ```` block, parsed. `{}` when there's none |
|
|
119
|
+
| `ctx.item`, `ctx.picks`, `ctx.row`, `ctx.settings`, `ctx.step`, `ctx.job` | Dash's job data. Each is `{}` outside Dash |
|
|
120
|
+
| `ctx.workspace` | `{ dir, branch, exists(p), read(p), file(p), dirExists() }` |
|
|
121
|
+
| `ctx.env` | The environment, `DASH_*` included |
|
|
122
|
+
| `ctx.fs` | `exists(p)`, `read(p)`, `readJson(p)`, `list(glob)`, `dirExists(p)`, relative to the workspace |
|
|
123
|
+
| `ctx.run(cmd, { timeoutSec })` | Runs a command in the workspace: `{ code, stdout, stderr, timedOut }` |
|
|
124
|
+
| `ctx.git` | `branch()`, `isClean()`, `uncommitted()`, `commitsSince(ref)`, `changedFiles(ref)`, `lastCommitMessage()`, `remoteHas(branch)`, `defaultBranch()`, `fileAt(ref, path)` |
|
|
125
|
+
| `ctx.github` | `pr(urlOrNumber)`, `checksFor(sha)`, `waitForChecks(sha, { timeoutSec, noChecksAfterSec })`, using `GH_TOKEN`. A failure says the HTTP code and what to do |
|
|
126
|
+
| `ctx.tool(provider, name, args)` | A read-only call to one of the bot's providers (Jira, …). Only Dash can answer it, so outside Dash it fails and says so |
|
|
127
|
+
| `ctx.get(path)`, `ctx.fill(text)`, `ctx.when(expr)` | Read a value by path (`"handoff.files"`), fill `"{placeholders}"`, test a `when` |
|
|
128
|
+
|
|
129
|
+
In a test, give the context what it can't have outside Dash:
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
const { createContext } = require("@trops/dash-check");
|
|
133
|
+
const ctx = createContext(sampleInput, { cwd: repoDir, fetch: fakeFetch, tool: fakeTool });
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Layer 1: helpers (`@trops/dash-check/helpers`)
|
|
137
|
+
|
|
138
|
+
A helper is a few lines of Layer 0 plus a description: a label, a sentence and typed params. Call one with `ctx` and its params:
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
const { check } = require("@trops/dash-check");
|
|
142
|
+
const { git, node, files } = require("@trops/dash-check/helpers");
|
|
143
|
+
|
|
144
|
+
check("the work is ready for review", async (ctx) => {
|
|
145
|
+
await git.committedSince(ctx, { base: "{repo.baseBranch}" });
|
|
146
|
+
await node.testsPass(ctx);
|
|
147
|
+
await files.noneMatch(ctx, { glob: "src/**/*.js", pattern: "console\\.log", message: "Remove console.log from src" });
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
| Group | Helpers |
|
|
152
|
+
|---|---|
|
|
153
|
+
| handoff | `has({ keys })`, `status({ is })`, `eachHas({ list, keys })` |
|
|
154
|
+
| plan | `hasSections({ key, sections })`, `acceptanceEachHasTest({ acceptance, tests })` |
|
|
155
|
+
| git | `onBranch({ branch })`, `committedSince({ base, min })`, `clean()`, `changedOnly({ globs, base })`, `noChangesTo({ globs, base })` |
|
|
156
|
+
| files | `exist({ paths })`, `contain({ path, text })`, `noneMatch({ glob, pattern })` |
|
|
157
|
+
| commands | `passes({ command, timeoutSec })`, `outputMatches({ command, pattern })` |
|
|
158
|
+
| node | `testsPass({ command })`, `lintPasses({ command })`, `noNewDependencies({ base, allow })` |
|
|
159
|
+
| github | `prOpen({ prKey })`, `ciPassed({ prKey, timeoutSec, noChecksAfterSec, ifNoChecks })` |
|
|
160
|
+
| tracker | `ticketExists({ provider, tool, idArg, id })`, `ticketHasLabel({ label, … })` (these need Dash's `ctx.tool`) |
|
|
161
|
+
|
|
162
|
+
`npx dash-check --list-helpers` lists each one with its params and defaults.
|
|
163
|
+
|
|
164
|
+
A few things every helper does for you:
|
|
165
|
+
|
|
166
|
+
- **Placeholders.** A param can hold `{placeholders}`: `{repo.baseBranch}` is the picked row's `baseBranch`, `{workRoot}` is a team setting, and `{item.id}` is the work item's id. A default whose placeholder has no value counts as empty: with no `repo` row, `git.committedSince` uses the repo's default branch.
|
|
167
|
+
- **`message`.** Every helper takes `message`, which replaces its failure text. Where the failure was (`src/index.js:12`) is kept.
|
|
168
|
+
- **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.
|
|
169
|
+
|
|
170
|
+
### Writing your own helper
|
|
171
|
+
|
|
172
|
+
Put a file in `.dash/checks/helpers/` in your repo. Build it only from `ctx` and `expect`, never from `fs`, `child_process` or `fetch` directly:
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
// .dash/checks/helpers/changelog.js
|
|
176
|
+
const { defineHelper, expect, note } = require("@trops/dash-check");
|
|
177
|
+
|
|
178
|
+
module.exports = defineHelper({
|
|
179
|
+
id: "team.changelogUpdated", // "group.name"
|
|
180
|
+
group: "Your helpers",
|
|
181
|
+
label: "Changelog updated",
|
|
182
|
+
description: "CHANGELOG.md changed on this branch",
|
|
183
|
+
sentence: "{file} changed since {base}",
|
|
184
|
+
params: {
|
|
185
|
+
file: { type: "path", label: "Changelog", default: "CHANGELOG.md" },
|
|
186
|
+
base: { type: "text", label: "Base branch", default: "{repo.baseBranch}" },
|
|
187
|
+
},
|
|
188
|
+
reads: ["git"],
|
|
189
|
+
async run(ctx, { file, base }) {
|
|
190
|
+
const ref = `origin/${base || (await ctx.git.defaultBranch()) || "main"}`;
|
|
191
|
+
const changed = await ctx.git.changedFiles(ref);
|
|
192
|
+
expect(changed, `files changed since ${ref}`).toContain(file, `${file} isn't updated: add a line for ${ctx.item.id || "this change"}`);
|
|
193
|
+
note(`${file} is updated`);
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Param types are `text`, `number`, `boolean`, `select` (with `options`), `path`, `glob`, `regex` and `list`. Values are converted to the type before `run` gets them: a `list` given as `"a, b"` arrives as `["a", "b"]`, and a `regex` arrives as a `RegExp`.
|
|
199
|
+
|
|
200
|
+
Then use it from code with `helper("team.changelogUpdated")(ctx, { … })`, or from a recipe with `{ "use": "team.changelogUpdated" }`. It also shows in `dash-check --list-helpers`, and so in Dash's check composer.
|
|
201
|
+
|
|
202
|
+
**Sharing helpers in a package:** list them in its `package.json`:
|
|
203
|
+
|
|
204
|
+
```json
|
|
205
|
+
{ "name": "@acme/dash-checks", "dashCheck": { "helpers": ["./helpers/changelog.js"] } }
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Any repo that has the package in `dependencies` or `devDependencies` picks them up. If a helper file won't load, `--list-helpers` reports its error, and the other helpers still load.
|
|
209
|
+
|
|
210
|
+
### Layer 2: recipes (`@trops/dash-check/recipe`)
|
|
211
|
+
|
|
212
|
+
A recipe is a check as JSON. It holds no code, so it's safe to store on a bot, share and edit in a UI. Save it as `.dash/checks/<name>.check.json`:
|
|
213
|
+
|
|
214
|
+
```json
|
|
215
|
+
{
|
|
216
|
+
"name": "The work is ready for review",
|
|
217
|
+
"steps": [
|
|
218
|
+
{ "use": "git.committedSince", "with": { "base": "{repo.baseBranch}", "min": 1 } },
|
|
219
|
+
{ "use": "node.testsPass", "with": { "command": "npm test" } },
|
|
220
|
+
{ "use": "files.noneMatch", "with": { "glob": "src/**/*.js", "pattern": "console\\.log" },
|
|
221
|
+
"message": "Remove console.log from src" },
|
|
222
|
+
{ "expect": "handoff.files", "matcher": "toHaveLengthAtLeast", "args": [1],
|
|
223
|
+
"message": "The handoff lists no changed files" }
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
- `use` names a helper, and `with` holds its params.
|
|
229
|
+
- `expect` names a value by path (`handoff.files`, `item.id`, `env.DASH_BRANCH`, `repo.baseBranch`). Add a `matcher`, its `args`, and `"not": true` to expect the opposite.
|
|
230
|
+
- `when` skips the step unless a value is truthy: a path (`"handoff.prUrl"`) or a placeholder (`"{mergeWhenGreen}"`). A `!` in front turns it around.
|
|
231
|
+
- `message` replaces the step's failure text.
|
|
232
|
+
- `label` renames the row.
|
|
233
|
+
|
|
234
|
+
```js
|
|
235
|
+
const { validateRecipe, runRecipe, recipeToCode, explain, schema } = require("@trops/dash-check/recipe");
|
|
236
|
+
|
|
237
|
+
validateRecipe(recipe); // { valid, errors: [{ path: "steps[1].with.min", message }] }
|
|
238
|
+
await runRecipe(recipe, input, { cwd, only: [0, 2] });
|
|
239
|
+
// { pass, reason, checks, steps: [{ index, label, sentence, pass, reason, failures }] }
|
|
240
|
+
recipeToCode(recipe); // the same check as a .check.js file ("View as code")
|
|
241
|
+
explain(recipe); // ["Work is committed: at least 1 commit(s) past {repo.baseBranch}, …", …]
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
`recipeToCode` gives a file that produces the same result as the recipe. The tests check this.
|
|
245
|
+
|
|
246
|
+
## The CLI
|
|
247
|
+
|
|
248
|
+
| Command | What it does |
|
|
249
|
+
|---|---|
|
|
250
|
+
| `dash-check` | Runs every `.check.js` and `.check.json` in `.dash/checks/`, plus plain executables, the way Dash does |
|
|
251
|
+
| `dash-check <name> --input sample.json` | Runs one check. With no `--input`, `<name>.sample.json` next to it is used |
|
|
252
|
+
| `dash-check --watch` | Reruns on every change |
|
|
253
|
+
| `dash-check --ci` | Prints a Jest-like report. A missing check counts as a failure |
|
|
254
|
+
| `dash-check --json` | Gives the results as JSON |
|
|
255
|
+
| `dash-check --list` | Lists the checks |
|
|
256
|
+
| `dash-check --list-helpers [--json] [--input f]` | Every helper and matcher with its metadata (the composer's palette). With `--input`, it also lists the value paths in that sample |
|
|
257
|
+
| `dash-check --explain <file>` | Prints a recipe as sentences, or a code file's check names |
|
|
258
|
+
| `dash-check new <name> [--recipe]` | Scaffolds a check and its sample input |
|
|
259
|
+
|
|
260
|
+
Options: `--cwd <dir>`, `--timeout <sec>` (2 minutes by default), and `--no-color`.
|
|
261
|
+
|
|
262
|
+
**Exit codes:** 0 when everything passed, 1 when a check failed, and 2 for bad arguments or a missing check.
|
|
263
|
+
|
|
264
|
+
A check gets the same contract as in Dash:
|
|
265
|
+
|
|
266
|
+
- `cwd` is the repo;
|
|
267
|
+
- the input is JSON in `$DASH_INPUT` and on stdin;
|
|
268
|
+
- the environment has `DASH_ITEM_*`, `DASH_WORKSPACE`, `DASH_BRANCH` and `DASH_STEP`.
|
|
269
|
+
|
|
270
|
+
A `.check.js` file runs in its own `node`. A `.check.json` recipe runs in the CLI. Any other file in `.dash/checks/` runs by its `#!` line, or else by its extension: `.js` with node, `.sh` with bash, `.py` with python3, and anything else with sh.
|
|
271
|
+
|
|
272
|
+
A `.check.js` file also runs by itself, `node .dash/checks/validate.check.js`, the way Dash runs a repo check.
|
|
273
|
+
|
|
274
|
+
**In CI**, add a step:
|
|
275
|
+
|
|
276
|
+
```yaml
|
|
277
|
+
- run: npx dash-check --ci
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Use in Dash
|
|
281
|
+
|
|
282
|
+
- **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.
|
|
283
|
+
- **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`.
|
|
284
|
+
- **`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" }`.
|
|
285
|
+
- **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).
|
|
286
|
+
|
|
287
|
+
## Examples
|
|
288
|
+
|
|
289
|
+
[`examples/`](examples) holds the Code Factory's checks, written with dash-check. Each has a `.sample.json` that passes and a `.bad.json` that fails:
|
|
290
|
+
|
|
291
|
+
| Example | Proves | Reads |
|
|
292
|
+
|---|---|---|
|
|
293
|
+
| `ticket-has-acceptance` | The ticket has acceptance items | handoff |
|
|
294
|
+
| `plan-complete` | The plan has a cause, fix and test, and picks a known repo | handoff, picks, settings |
|
|
295
|
+
| `on-branch` | The workspace is on the job's branch, fresh from the base | git, workspace, row |
|
|
296
|
+
| `setup` | `npm ci` passes | run |
|
|
297
|
+
| `every-acceptance-has-a-test` | Every acceptance item has a test; the plan names real files | handoff, workspace |
|
|
298
|
+
| `validate` | Lint and tests pass, reported apart | run |
|
|
299
|
+
| `work-committed` | The work is committed, and the commit names the item | git, item |
|
|
300
|
+
| `changes-match-plan` | Only the planned files changed | git, handoff, row |
|
|
301
|
+
| `pr-ci` | The PR's CI passed (no CI is a failure) | github |
|
|
302
|
+
| `merge-outcome` | The PR was merged only when allowed | github, settings |
|
|
303
|
+
| `workspace-cleaned` | The job's folder is gone | workspace |
|
|
304
|
+
| `jira-comment-from-job` | The ticket got this job's comment | tool, job |
|
|
305
|
+
| `ready-for-review.check.json` | The composer mockup's recipe | git, run, fs, handoff |
|
|
306
|
+
| `helpers/changelog.js` | A team's own helper | git |
|
|
307
|
+
|
|
308
|
+
## License
|
|
309
|
+
|
|
310
|
+
MIT © trops
|
package/cli/bin.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
require("./index")
|
|
5
|
+
.main(process.argv.slice(2))
|
|
6
|
+
.then((code) => {
|
|
7
|
+
process.exitCode = code;
|
|
8
|
+
})
|
|
9
|
+
.catch((e) => {
|
|
10
|
+
process.stderr.write(`dash-check broke: ${e && e.stack ? e.stack : e}\n`);
|
|
11
|
+
process.exitCode = 2;
|
|
12
|
+
});
|
package/cli/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Types for @trops/dash-check/cli.
|
|
2
|
+
export function main(argv: string[], io?: { log?: (s: string) => void; err?: (s: string) => void; signal?: AbortSignal }): Promise<number>;
|
|
3
|
+
export function parseArgs(argv: string[]): Record<string, any>;
|
|
4
|
+
export function listChecks(cwd: string): Array<{ name: string; file: string; type: "js" | "recipe" | "exec"; sample?: string }>;
|
|
5
|
+
export function runEntry(entry: { name: string; file: string; type: "js" | "recipe" | "exec" }, opts: { cwd: string; input: Record<string, any>; timeoutSec?: number }): Promise<any>;
|
|
6
|
+
export function lastProof(output: string): { proof: { reason?: string; details?: any }; index: number; lines: string[] } | null;
|
|
7
|
+
export const CHECKS_DIR: string;
|