@trops/dash-check 0.2.0 → 0.3.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/README.md +15 -1
- package/helpers/index.d.ts +23 -1
- package/helpers/plan.js +86 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -153,7 +153,7 @@ check("the work is ready for review", async (ctx) => {
|
|
|
153
153
|
| Group | Helpers |
|
|
154
154
|
|---|---|
|
|
155
155
|
| handoff | `has({ keys })`, `status({ is })`, `eachHas({ list, keys })` |
|
|
156
|
-
| plan | `hasSections({ key, sections })`, `acceptanceEachHasTest({ acceptance, tests })` |
|
|
156
|
+
| plan | `hasSections({ key, sections })`, `acceptanceEachHasTest({ acceptance, tests })`, `evidenceForAcceptance({ key, acceptanceKey, requireSearch, when })`, `noOpenDecisions({ key, when })` (see below) |
|
|
157
157
|
| git | `onBranch({ branch })`, `committedSince({ base, min })`, `clean()`, `changedOnly({ globs, base })`, `noChangesTo({ globs, base })`, and the factory checks below |
|
|
158
158
|
| files | `exist({ paths })`, `contain({ path, text })`, `noneMatch({ glob, pattern })`, `maxGrowth(…)` |
|
|
159
159
|
| commands | `passes({ command, timeoutSec })`, `outputMatches({ command, pattern })` |
|
|
@@ -169,6 +169,20 @@ A few things every helper does for you:
|
|
|
169
169
|
- **`message`.** Every helper takes `message`, which replaces its failure text. Where the failure was (`src/index.js:12`) is kept.
|
|
170
170
|
- **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
171
|
|
|
172
|
+
### Plan checks: is the plan ready to code?
|
|
173
|
+
|
|
174
|
+
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.
|
|
175
|
+
|
|
176
|
+
| Helper | Fails when | Params (defaults) |
|
|
177
|
+
|---|---|---|
|
|
178
|
+
| `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) |
|
|
179
|
+
| `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`) |
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
{ "use": "plan.evidenceForAcceptance" }
|
|
183
|
+
{ "use": "plan.noOpenDecisions", "with": { "when": "ok, split" } }
|
|
184
|
+
```
|
|
185
|
+
|
|
172
186
|
### Factory checks: did the bot do only what it planned?
|
|
173
187
|
|
|
174
188
|
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.
|
package/helpers/index.d.ts
CHANGED
|
@@ -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: {
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|