@trops/dash-check 0.0.0-stage → 0.2.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.
Files changed (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +355 -2
  3. package/cli/bin.js +12 -0
  4. package/cli/index.d.ts +7 -0
  5. package/cli/index.js +566 -0
  6. package/examples/changes-match-plan.bad.json +4 -0
  7. package/examples/changes-match-plan.check.js +18 -0
  8. package/examples/changes-match-plan.sample.json +4 -0
  9. package/examples/commits-scoped.bad.json +5 -0
  10. package/examples/commits-scoped.check.json +6 -0
  11. package/examples/commits-scoped.sample.json +5 -0
  12. package/examples/every-acceptance-has-a-test.bad.json +3 -0
  13. package/examples/every-acceptance-has-a-test.check.js +19 -0
  14. package/examples/every-acceptance-has-a-test.sample.json +3 -0
  15. package/examples/helpers/changelog.js +23 -0
  16. package/examples/jira-comment-from-job.bad.json +5 -0
  17. package/examples/jira-comment-from-job.check.js +10 -0
  18. package/examples/jira-comment-from-job.sample.json +5 -0
  19. package/examples/lockfile-explained.bad.json +11 -0
  20. package/examples/lockfile-explained.check.json +6 -0
  21. package/examples/lockfile-explained.sample.json +11 -0
  22. package/examples/max-growth.bad.json +8 -0
  23. package/examples/max-growth.check.json +6 -0
  24. package/examples/max-growth.sample.json +8 -0
  25. package/examples/merge-outcome.bad.json +4 -0
  26. package/examples/merge-outcome.check.js +9 -0
  27. package/examples/merge-outcome.sample.json +4 -0
  28. package/examples/new-tests-are-run.bad.json +4 -0
  29. package/examples/new-tests-are-run.check.json +7 -0
  30. package/examples/new-tests-are-run.sample.json +4 -0
  31. package/examples/no-new-debt.bad.json +8 -0
  32. package/examples/no-new-debt.check.json +14 -0
  33. package/examples/no-new-debt.sample.json +8 -0
  34. package/examples/on-branch.bad.json +6 -0
  35. package/examples/on-branch.check.js +12 -0
  36. package/examples/on-branch.sample.json +6 -0
  37. package/examples/plan-complete.bad.json +5 -0
  38. package/examples/plan-complete.check.js +14 -0
  39. package/examples/plan-complete.sample.json +5 -0
  40. package/examples/plan-scope.bad.json +4 -0
  41. package/examples/plan-scope.check.json +6 -0
  42. package/examples/plan-scope.sample.json +4 -0
  43. package/examples/pr-ci.bad.json +4 -0
  44. package/examples/pr-ci.check.js +12 -0
  45. package/examples/pr-ci.sample.json +4 -0
  46. package/examples/ready-for-review.bad.json +6 -0
  47. package/examples/ready-for-review.check.json +12 -0
  48. package/examples/ready-for-review.sample.json +6 -0
  49. package/examples/setup.bad.json +6 -0
  50. package/examples/setup.check.js +8 -0
  51. package/examples/setup.sample.json +6 -0
  52. package/examples/source-has-tests.bad.json +4 -0
  53. package/examples/source-has-tests.check.json +6 -0
  54. package/examples/source-has-tests.sample.json +4 -0
  55. package/examples/test-script-is-real.bad.json +6 -0
  56. package/examples/test-script-is-real.check.json +6 -0
  57. package/examples/test-script-is-real.sample.json +6 -0
  58. package/examples/ticket-has-acceptance.bad.json +4 -0
  59. package/examples/ticket-has-acceptance.check.js +10 -0
  60. package/examples/ticket-has-acceptance.sample.json +4 -0
  61. package/examples/validate-leaves-tree-clean.bad.json +6 -0
  62. package/examples/validate-leaves-tree-clean.check.json +7 -0
  63. package/examples/validate-leaves-tree-clean.sample.json +6 -0
  64. package/examples/validate.bad.json +6 -0
  65. package/examples/validate.check.js +14 -0
  66. package/examples/validate.sample.json +6 -0
  67. package/examples/work-committed.bad.json +13 -0
  68. package/examples/work-committed.check.js +13 -0
  69. package/examples/work-committed.sample.json +5 -0
  70. package/examples/workspace-cleaned.bad.json +4 -0
  71. package/examples/workspace-cleaned.check.js +7 -0
  72. package/examples/workspace-cleaned.sample.json +4 -0
  73. package/helpers/commands.js +62 -0
  74. package/helpers/files.js +124 -0
  75. package/helpers/git.js +379 -0
  76. package/helpers/github.js +77 -0
  77. package/helpers/handoff.js +80 -0
  78. package/helpers/index.d.ts +103 -0
  79. package/helpers/index.js +36 -0
  80. package/helpers/node.js +296 -0
  81. package/helpers/plan.js +55 -0
  82. package/helpers/tracker.js +60 -0
  83. package/index.d.ts +347 -0
  84. package/index.js +86 -0
  85. package/lib/adapters/fs.js +85 -0
  86. package/lib/adapters/git.js +163 -0
  87. package/lib/adapters/github.js +151 -0
  88. package/lib/adapters/run.js +76 -0
  89. package/lib/adapters/tool.js +64 -0
  90. package/lib/context.js +102 -0
  91. package/lib/discover.js +102 -0
  92. package/lib/expect.js +238 -0
  93. package/lib/glob.js +89 -0
  94. package/lib/handoff.js +68 -0
  95. package/lib/helper.js +236 -0
  96. package/lib/register.js +35 -0
  97. package/lib/runner.js +214 -0
  98. package/lib/scope.js +107 -0
  99. package/lib/util.js +122 -0
  100. package/lib/values.js +138 -0
  101. package/package.json +59 -4
  102. package/recipe/index.d.ts +70 -0
  103. package/recipe/index.js +381 -0
  104. package/recipe/schema.json +55 -0
@@ -0,0 +1,10 @@
1
+ // Walkthrough 12. Reporter: "The ticket got its comment", checked in Jira itself.
2
+ // Lives in a tracker package (@dash-checks/jira). Reads: item, tool, job.
3
+ // ctx.tool only works when Dash runs the check (it supplies the provider).
4
+ const { check, expect } = require("@trops/dash-check");
5
+
6
+ check("the ticket has this job's comment", async ({ item, tool, job }) => {
7
+ const { comments } = await tool("jira", "listJiraIssueComments", { issueIdOrKey: item.id, orderBy: "-created", maxResults: 5 });
8
+ expect(comments.some((c) => new Date(c.created) >= new Date(job.startedAt)), "a comment since the job started")
9
+ .toBe(true, `No comment on ${item.id} since this job started`);
10
+ });
@@ -0,0 +1,5 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"summary\": \"Commented on DASH-97\" }\n```" },
3
+ "item": { "id": "DASH-97" },
4
+ "job": { "id": "job-1", "startedAt": "2026-11-26T07:50:00Z" }
5
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "_about": "Run on a branch whose package-lock.json changed (node_modules/foo) while package.json's dependencies didn't.",
3
+ "row": {
4
+ "repo": {
5
+ "baseBranch": "main"
6
+ }
7
+ },
8
+ "workspace": {
9
+ "dir": "."
10
+ }
11
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "The lockfile changed only with a dependency",
3
+ "steps": [
4
+ { "use": "node.lockfileExplained", "with": { "base": "{repo.baseBranch}" } }
5
+ ]
6
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "_about": "Run on a branch whose package-lock.json changed along with a dependency in package.json (or only in its version).",
3
+ "row": {
4
+ "repo": {
5
+ "baseBranch": "main"
6
+ }
7
+ },
8
+ "workspace": {
9
+ "dir": "."
10
+ }
11
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "_about": "Run on a branch that added 60 lines to a file already past 800.",
3
+ "row": {
4
+ "repo": {
5
+ "baseBranch": "main"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "No file grows too big",
3
+ "steps": [
4
+ { "use": "files.maxGrowth", "with": { "base": "{repo.baseBranch}", "maxLines": 800, "maxAdded": 50 } }
5
+ ]
6
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "_about": "Run on a branch whose changed files stay under 800 lines.",
3
+ "row": {
4
+ "repo": {
5
+ "baseBranch": "main"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"prUrl\": \"https://github.com/trops/code-factory-sandbox/pull/12\", \"merged\": true }\n```" },
3
+ "settings": { "mergeWhenGreen": false }
4
+ }
@@ -0,0 +1,9 @@
1
+ // Walkthrough 10. Merge Bot: "The PR was merged only when allowed".
2
+ // Checks the outcome on GitHub, not the bot's word. Reads: handoff, github, settings.
3
+ const { check, expect } = require("@trops/dash-check");
4
+
5
+ check("the PR was merged only when allowed", async ({ handoff, github, settings }) => {
6
+ const pr = await github.pr(handoff.prUrl);
7
+ if (settings.mergeWhenGreen) expect(pr.merged, "merged").toBe(true, `PR #${pr.number} wasn't merged`);
8
+ else expect(pr.merged, "merged").toBe(false, `PR #${pr.number} was merged, but Merge when green is off`);
9
+ });
@@ -0,0 +1,4 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"prUrl\": \"https://github.com/trops/code-factory-sandbox/pull/12\", \"merged\": true }\n```" },
3
+ "settings": { "mergeWhenGreen": true }
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "row": { "repo": { "baseBranch": "main" } },
3
+ "settings": { "autoGlobs": "" }
4
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "New tests are run",
3
+ "steps": [
4
+ { "use": "node.newTestsAreRun",
5
+ "with": { "base": "{repo.baseBranch}", "runnerFiles": "package.json, scripts/ci.sh", "autoGlobs": "{autoGlobs}" } }
6
+ ]
7
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "row": { "repo": { "baseBranch": "main" } },
3
+ "settings": { "autoGlobs": "src/**/*.test.js" }
4
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "_about": "Run on a branch that added a console.log and a TODO.",
3
+ "row": {
4
+ "repo": {
5
+ "baseBranch": "main"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "No new TODO, console.log or disables",
3
+ "steps": [
4
+ { "use": "git.noNewMatches",
5
+ "with": { "glob": "src/**/*.js, !**/*.test.js", "pattern": "console\\.log\\(", "base": "{repo.baseBranch}" },
6
+ "message": "Remove the console.log you added" },
7
+ { "use": "git.noNewMatches",
8
+ "with": { "glob": "**/*.{js,jsx,ts,tsx}", "pattern": "\\b(TODO|FIXME|HACK|XXX)\\b", "base": "{repo.baseBranch}" },
9
+ "message": "Do the TODO or file a ticket; don't commit it" },
10
+ { "use": "git.noNewMatches",
11
+ "with": { "glob": "**/*.{js,jsx,ts,tsx}", "pattern": "eslint-disable|@ts-ignore|\\.only\\(|debugger;", "base": "{repo.baseBranch}" },
12
+ "message": "Fix the code instead of turning the check off" }
13
+ ]
14
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "_about": "Run on a branch that added no TODO, console.log or eslint-disable (old ones are fine).",
3
+ "row": {
4
+ "repo": {
5
+ "baseBranch": "main"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"summary\": \"Workspace ready\" }\n```" },
3
+ "item": { "id": "DASH-97" },
4
+ "workspace": { "dir": ".", "branch": "feat/DASH-97-somewhere-else" },
5
+ "row": { "repo": { "baseBranch": "main" } }
6
+ }
@@ -0,0 +1,12 @@
1
+ // Walkthrough 3. Workspace Bot: "On the ticket's branch" (Dash's git-on-branch).
2
+ // Reads: git, workspace, row. Run it in the job's workspace repo.
3
+ const { check, expect } = require("@trops/dash-check");
4
+
5
+ check("the workspace is on the job's branch", async ({ workspace, git }) => {
6
+ expect(await git.branch(), "the branch").toBe(workspace.branch, `The workspace is on another branch, not ${workspace.branch}`);
7
+ });
8
+
9
+ check("the branch is new from the base", async ({ git, row }) => {
10
+ const base = `origin/${row.repo?.baseBranch || "main"}`;
11
+ expect(await git.commitsSince(base), `commits past ${base}`).toBe(0, `The branch already has commits past ${base}: start it fresh from ${base}`);
12
+ });
@@ -0,0 +1,6 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"summary\": \"Workspace ready\" }\n```" },
3
+ "item": { "id": "DASH-97" },
4
+ "workspace": { "dir": ".", "branch": "feat/DASH-97-titlecase" },
5
+ "row": { "repo": { "baseBranch": "main" } }
6
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"plan\": { \"cause\": \"The slug drops dashes\", \"fix\": \"\" } }\n```" },
3
+ "picks": { "repo": "some-other-repo" },
4
+ "settings": { "repo": [{ "key": "code-factory-sandbox", "baseBranch": "main" }] }
5
+ }
@@ -0,0 +1,14 @@
1
+ // Walkthrough 2. Triage: "The plan is complete".
2
+ // Lives in the shared package. Reads: handoff, picks, settings (the Repos table).
3
+ const { check, expect } = require("@trops/dash-check");
4
+
5
+ check("the plan has a cause, a fix and a test", ({ handoff }) => {
6
+ for (const part of ["cause", "fix", "test"]) {
7
+ expect(handoff.plan?.[part], `handoff.plan.${part}`).toBeNonEmptyString(`The plan has no ${part}`);
8
+ }
9
+ });
10
+
11
+ check("the plan picks one of the team's repos", ({ picks, settings }) => {
12
+ const keys = (settings.repo || []).map((r) => r.key);
13
+ expect(picks.repo, "picks.repo").toBeOneOf(keys, `"${picks.repo}" isn't in the Repos table (${keys.join(", ")})`);
14
+ });
@@ -0,0 +1,5 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"plan\": { \"cause\": \"The slug drops dashes\", \"fix\": \"Keep dashes in slugify()\", \"test\": \"slugify('a-b') is 'a-b'\" } }\n```" },
3
+ "picks": { "repo": "code-factory-sandbox" },
4
+ "settings": { "repo": [{ "key": "code-factory-sandbox", "baseBranch": "main" }, { "key": "dash-core", "baseBranch": "master" }] }
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"files\": [\"src/a.js\"] }\n```" },
3
+ "row": { "repo": { "baseBranch": "main" } }
4
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "Only the planned files changed",
3
+ "steps": [
4
+ { "use": "git.changesMatchPlan", "with": { "base": "{repo.baseBranch}", "alsoAllow": "CHANGELOG.md" } }
5
+ ]
6
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"files\": [\"src/a.js\"], \"tests\": [{ \"acceptance\": \"A works\", \"file\": \"src/a.test.js\" }] }\n```" },
3
+ "row": { "repo": { "baseBranch": "main" } }
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "input": { "answer": "Opened the PR.\n\n```json\n{ \"prUrl\": \"https://github.com/trops/code-factory-sandbox/pull/13\" }\n```" },
3
+ "item": { "id": "DASH-97" }
4
+ }
@@ -0,0 +1,12 @@
1
+ // Walkthrough 9. PR Bot: "The PR's CI passes" (Dash's pr-ci). It fails closed:
2
+ // no CI is a failure that says what to do. Reads: handoff, github (GH_TOKEN).
3
+ const { check, expect } = require("@trops/dash-check");
4
+
5
+ check("the PR's CI passed", async ({ handoff, github }) => {
6
+ const pr = await github.pr(handoff.prUrl);
7
+ expect(pr.state, `PR #${pr.number}'s state`).toBe("open", `PR #${pr.number} isn't open`);
8
+
9
+ const result = await github.waitForChecks(pr.head.sha, { timeoutSec: 1200, noChecksAfterSec: 180 });
10
+ expect(result.runs, "the CI runs").not.toBeEmpty(`${handoff.prUrl} has no CI. Enable Actions on the repo, or set ifNoCI: "pass" on this step`);
11
+ expect(result.failed, "the failed CI runs").toBeEmpty(`CI failed: ${result.failed.map((r) => `${r.name} (${r.conclusion})`).join(", ")}`);
12
+ });
@@ -0,0 +1,4 @@
1
+ {
2
+ "input": { "answer": "Opened the PR.\n\n```json\n{ \"prUrl\": \"https://github.com/trops/code-factory-sandbox/pull/12\" }\n```" },
3
+ "item": { "id": "DASH-97" }
4
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "input": { "answer": "Done.\n\n```json\n{ \"status\": \"ok\", \"files\": [] }\n```" },
3
+ "item": { "id": "DASH-97" },
4
+ "workspace": { "dir": ".", "branch": "feat/DASH-97-titlecase" },
5
+ "row": { "repo": { "baseBranch": "main" } }
6
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "The work is ready for review",
3
+ "steps": [
4
+ { "use": "git.committedSince", "with": { "base": "{repo.baseBranch}", "min": 1 } },
5
+ { "use": "node.testsPass", "with": { "command": "npm test" } },
6
+ { "use": "files.noneMatch",
7
+ "with": { "glob": "src/**/*.js", "pattern": "console\\.log" },
8
+ "message": "Remove console.log from src" },
9
+ { "expect": "handoff.files", "matcher": "toHaveLengthAtLeast", "args": [1],
10
+ "message": "The handoff lists no changed files" }
11
+ ]
12
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "input": { "answer": "Done.\n\n```json\n{ \"status\": \"ok\", \"files\": [\"src/index.js\", \"test/index.test.js\"] }\n```" },
3
+ "item": { "id": "DASH-97" },
4
+ "workspace": { "dir": ".", "branch": "feat/DASH-97-titlecase" },
5
+ "row": { "repo": { "baseBranch": "main" } }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"summary\": \"Workspace ready\" }\n```" },
3
+ "item": { "id": "DASH-97" },
4
+ "workspace": { "dir": ".", "branch": "feat/DASH-97-titlecase" },
5
+ "row": { "repo": { "baseBranch": "main" } }
6
+ }
@@ -0,0 +1,8 @@
1
+ // Walkthrough 4. Workspace Bot: "Setup command passes".
2
+ // Lives in the repo: <repo>/.dash/checks/setup.check.js. Reads: run.
3
+ const { check, expect } = require("@trops/dash-check");
4
+
5
+ check("dependencies install", async ({ run }) => {
6
+ const r = await run("npm ci", { timeoutSec: 900 });
7
+ expect(r.code, "npm ci's exit code").toBe(0, `npm ci failed:\n${r.stderr.slice(-2000)}`);
8
+ });
@@ -0,0 +1,6 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"summary\": \"Workspace ready\" }\n```" },
3
+ "item": { "id": "DASH-97" },
4
+ "workspace": { "dir": ".", "branch": "feat/DASH-97-titlecase" },
5
+ "row": { "repo": { "baseBranch": "main" } }
6
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "row": { "repo": { "baseBranch": "main" } },
3
+ "settings": { "testsMode": "paired" }
4
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "Changed source has tests",
3
+ "steps": [
4
+ { "use": "git.sourceHasTests", "with": { "base": "{repo.baseBranch}", "mode": "{testsMode}", "exempt": "**/index.js" } }
5
+ ]
6
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "row": { "repo": { "baseBranch": "main" } },
3
+ "settings": { "testsMode": "any" }
4
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "_about": "Run in a repo whose test script is \"exit 0\".",
3
+ "workspace": {
4
+ "dir": "."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "npm test runs tests",
3
+ "steps": [
4
+ { "use": "node.testScriptIsReal", "with": { "script": "test", "run": true, "minTests": 1 } }
5
+ ]
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "_about": "Run in a repo whose npm test runs and reports its tests.",
3
+ "workspace": {
4
+ "dir": "."
5
+ }
6
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "input": { "answer": "Took DASH-97.\n\n```json\n{ \"summary\": \"Title-case the board names\", \"acceptance\": [] }\n```" },
3
+ "item": { "id": "DASH-97" }
4
+ }
@@ -0,0 +1,10 @@
1
+ // Walkthrough 1. Ticket Bot: "A ticket with acceptance items".
2
+ // Lives in the shared package @dash-checks/code-factory. Reads: handoff.
3
+ const { check, expect } = require("@trops/dash-check");
4
+
5
+ check("the ticket has acceptance items", ({ handoff }) => {
6
+ expect(handoff.acceptance, "handoff.acceptance").toBeArray("The ticket's acceptance items aren't a list");
7
+ expect(handoff.acceptance, "handoff.acceptance").not.toBeEmpty(
8
+ "The ticket has no acceptance items: add them to the ticket, or write one per testable thing it asks for",
9
+ );
10
+ });
@@ -0,0 +1,4 @@
1
+ {
2
+ "input": { "answer": "Took DASH-97.\n\n```json\n{ \"summary\": \"Title-case the board names\", \"acceptance\": [\"Names are title case\", \"Dashes are kept\"] }\n```" },
3
+ "item": { "id": "DASH-97", "title": "Title-case board names" }
4
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "_about": "Run in a repo whose npm run ci runs a formatter that rewrites a tracked file.",
3
+ "workspace": {
4
+ "dir": "."
5
+ }
6
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "Validate doesn't rewrite files",
3
+ "steps": [
4
+ { "use": "git.validateLeavesTreeClean", "with": { "command": "npm run ci", "timeoutSec": 1800 },
5
+ "message": "Validation rewrote tracked files (a formatter's --write, or npm install --save): fix the script, and don't commit them" }
6
+ ]
7
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "_about": "Run in a repo whose npm run ci only checks.",
3
+ "workspace": {
4
+ "dir": "."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"summary\": \"Workspace ready\" }\n```" },
3
+ "item": { "id": "DASH-97" },
4
+ "workspace": { "dir": ".", "branch": "feat/DASH-97-titlecase" },
5
+ "row": { "repo": { "baseBranch": "main" } }
6
+ }
@@ -0,0 +1,14 @@
1
+ // Walkthrough 6. Coder: "Validate command passes".
2
+ // Lives in the repo: <repo>/.dash/checks/validate.check.js. Reads: run.
3
+ // Dash runs the base branch's copy, so the Coder can't edit it to pass.
4
+ const { check, expect } = require("@trops/dash-check");
5
+
6
+ check("lint passes", async ({ run }) => {
7
+ const r = await run("npm run lint");
8
+ expect(r.code, "npm run lint's exit code").toBe(0, r.stdout.slice(-2000));
9
+ });
10
+
11
+ check("tests pass", async ({ run }) => {
12
+ const r = await run("npm test", { timeoutSec: 900 });
13
+ expect(r.code, "npm test's exit code").toBe(0, r.stdout.slice(-3000));
14
+ });
@@ -0,0 +1,6 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"summary\": \"Workspace ready\" }\n```" },
3
+ "item": { "id": "DASH-97" },
4
+ "workspace": { "dir": ".", "branch": "feat/DASH-97-titlecase" },
5
+ "row": { "repo": { "baseBranch": "main" } }
6
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "input": {
3
+ "answer": "```json\n{ \"summary\": \"Committed the fix\" }\n```"
4
+ },
5
+ "item": {
6
+ "id": "DASH-98"
7
+ },
8
+ "row": {
9
+ "repo": {
10
+ "baseBranch": "main"
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ // Walkthrough 7. Coder: "Work is committed" (Dash's git-committed).
2
+ // Reads: git, row, item.
3
+ const { check, expect } = require("@trops/dash-check");
4
+
5
+ check("the work is committed", async ({ git, row }) => {
6
+ const base = `origin/${row.repo?.baseBranch || "main"}`;
7
+ expect(await git.commitsSince(base), `commits past ${base}`).toBeGreaterThan(0, `No commits past ${base}`);
8
+ expect(await git.isClean(), "the work tree is clean").toBe(true, "There are uncommitted changes");
9
+ });
10
+
11
+ check("the commit names the item", async ({ git, item }) => {
12
+ expect(await git.lastCommitMessage(), "the last commit's message").toContain(item.id, `The commit message should start with ${item.id}`);
13
+ });
@@ -0,0 +1,5 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"summary\": \"Committed the fix\" }\n```" },
3
+ "item": { "id": "DASH-97" },
4
+ "row": { "repo": { "baseBranch": "main" } }
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"summary\": \"Reported and cleaned up\" }\n```" },
3
+ "workspace": { "dir": "." }
4
+ }
@@ -0,0 +1,7 @@
1
+ // Walkthrough 11. Reporter: "The ticket's folder is gone". (Better still: Dash
2
+ // removes the job's workspace itself, and this check goes away.) Reads: workspace.
3
+ const { check, expect } = require("@trops/dash-check");
4
+
5
+ check("the workspace is cleaned up", async ({ workspace }) => {
6
+ expect(await workspace.dirExists(), `${workspace.dir} exists`).toBe(false, `${workspace.dir} is still there`);
7
+ });
@@ -0,0 +1,4 @@
1
+ {
2
+ "input": { "answer": "```json\n{ \"summary\": \"Reported and cleaned up\" }\n```" },
3
+ "workspace": { "dir": "/tmp/dash-check-example-workspace-that-is-gone/DASH-97" }
4
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Commands helpers: run the repo's own commands. Built only from Layer 0
3
+ * (ctx.run).
4
+ */
5
+ "use strict";
6
+
7
+ const { defineHelper, expect, fail, note } = require("..");
8
+
9
+ const tail = (s, n = 1500) => {
10
+ const t = String(s || "").trim();
11
+ return t.length > n ? `…${t.slice(-n)}` : t;
12
+ };
13
+
14
+ /** Run a command; on a non-zero exit fail with its last output. Gives the run. */
15
+ async function runOrFail(ctx, command, timeoutSec, what = command) {
16
+ const r = await ctx.run(command, { timeoutSec });
17
+ if (r.timedOut) {
18
+ fail(`${what} didn't finish in ${timeoutSec} seconds: make it faster, or raise the time limit`, { at: tail(r.stdout + r.stderr, 800) || undefined });
19
+ } else if (r.code !== 0) {
20
+ const out = tail(`${r.stdout}\n${r.stderr}`);
21
+ fail(`${what} failed (exit ${r.code})`, { at: out || undefined, received: r.code, expected: 0 });
22
+ }
23
+ return r;
24
+ }
25
+
26
+ const passes = defineHelper({
27
+ id: "commands.passes",
28
+ group: "Commands",
29
+ label: "Command passes",
30
+ description: "Exit 0",
31
+ sentence: "{command} exits 0",
32
+ params: {
33
+ command: { type: "text", label: "Command", required: true },
34
+ timeoutSec: { type: "number", label: "Time limit (s)", default: 120 },
35
+ },
36
+ reads: ["run"],
37
+ async run(ctx, { command, timeoutSec }) {
38
+ const r = await runOrFail(ctx, command, timeoutSec);
39
+ if (r.code === 0) note(`${command} passed`);
40
+ },
41
+ });
42
+
43
+ const outputMatches = defineHelper({
44
+ id: "commands.outputMatches",
45
+ group: "Commands",
46
+ label: "Command output matches",
47
+ description: "Its output matches a pattern",
48
+ sentence: "the output of {command} matches {pattern}",
49
+ params: {
50
+ command: { type: "text", label: "Command", required: true },
51
+ pattern: { type: "regex", label: "Pattern", required: true },
52
+ timeoutSec: { type: "number", label: "Time limit (s)", default: 120 },
53
+ },
54
+ reads: ["run"],
55
+ async run(ctx, { command, pattern, timeoutSec }) {
56
+ const r = await ctx.run(command, { timeoutSec });
57
+ const out = `${r.stdout}${r.stderr ? `\n${r.stderr}` : ""}`;
58
+ expect(out, `the output of ${command}`).toMatch(pattern, `The output of ${command} doesn't match /${pattern.source}/`);
59
+ },
60
+ });
61
+
62
+ module.exports = { passes, outputMatches, runOrFail };