@rt-tools/agent-kit 0.36.0 → 0.37.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.
Files changed (143) hide show
  1. package/assets/checks/board-pull-state.github.mjs +82 -13
  2. package/assets/checks/board.github.mjs +1 -1
  3. package/assets/checks/check-board.github.mjs +20 -12
  4. package/assets/checks/check-specs.mjs +2 -2
  5. package/assets/checks/epic-table.github.mjs +4 -3
  6. package/assets/checks/lib-common.mjs +10 -2
  7. package/assets/checks/lib-domains.mjs +1 -1
  8. package/assets/checks/lib-manifests.mjs +34 -2
  9. package/assets/checks/push-inputs.mjs +401 -0
  10. package/assets/checks/push-trace.mjs +108 -0
  11. package/assets/checks/rt-kit-checks.config.mjs +17 -2
  12. package/assets/checks/spec-anchors.mjs +4 -4
  13. package/assets/checks/spec-contract.mjs +5 -5
  14. package/assets/commands/next-session.md +3 -1
  15. package/assets/commands/night.md +28 -18
  16. package/assets/defaults/project.sh +37 -8
  17. package/assets/defaults/push.sh +23 -0
  18. package/assets/defaults/turn-map.md +10 -6
  19. package/assets/docs/GLOSSARY.md +3 -1
  20. package/assets/hooks/epic-stop-guard.sh +62 -15
  21. package/assets/hooks/git-guard-push-ahead.sh +31 -1
  22. package/assets/hooks/git-guard-push-marks.sh +173 -29
  23. package/assets/hooks/git-guard-push-tests.sh +22 -3
  24. package/assets/hooks/handoff-entry-guard.sh +2 -2
  25. package/assets/hooks/pre-push.sh +6 -0
  26. package/assets/hooks/push-set.sh +29 -4
  27. package/assets/hooks/task-flow-context.sh +15 -4
  28. package/assets/hooks/task-flow-guard.sh +4 -3
  29. package/assets/hooks/turn-exit-epic.sh +1 -1
  30. package/assets/hooks/turn-exit-guard.sh +8 -8
  31. package/assets/hooks/turn-exit-role.sh +45 -0
  32. package/assets/laws/work-conduct.md +9 -8
  33. package/assets/patterns/autonomous-work-run.md +35 -10
  34. package/assets/patterns/browser-verification-measure.md +10 -20
  35. package/assets/patterns/browser-verification-stand.md +30 -42
  36. package/assets/patterns/doc-style-human.md +0 -6
  37. package/assets/patterns/doc-style-sweep.md +7 -7
  38. package/assets/patterns/doc-style-trace.md +5 -4
  39. package/assets/patterns/doc-style-write.md +7 -7
  40. package/assets/patterns/epic-flow-declare.md +15 -8
  41. package/assets/patterns/git-workflow-commit.github.md +1 -1
  42. package/assets/patterns/git-workflow-freshness.md +12 -11
  43. package/assets/patterns/git-workflow-merge.md +14 -11
  44. package/assets/patterns/git-workflow-migration.md +4 -2
  45. package/assets/patterns/git-workflow-pr-body.github.md +1 -1
  46. package/assets/patterns/git-workflow-pr-ready.md +5 -4
  47. package/assets/patterns/git-workflow-pr.azure.md +91 -25
  48. package/assets/patterns/git-workflow-pr.github.md +17 -19
  49. package/assets/patterns/git-workflow-pr.gitlab.md +75 -29
  50. package/assets/patterns/git-workflow-restart.md +3 -2
  51. package/assets/patterns/git-workflow-stack.md +25 -21
  52. package/assets/patterns/lib-layers-new.md +7 -3
  53. package/assets/patterns/queue-audit-read.github.md +9 -3
  54. package/assets/patterns/spec-driven-domain.md +50 -48
  55. package/assets/patterns/spec-driven-rule.md +18 -19
  56. package/assets/patterns/status-report-table.github.md +1 -1
  57. package/assets/patterns/task-flow-archive.md +14 -34
  58. package/assets/patterns/task-flow-close.md +3 -2
  59. package/assets/patterns/task-flow-graph.needs-graph.md +98 -0
  60. package/assets/patterns/task-flow-handoff.md +4 -4
  61. package/assets/patterns/task-flow-resume.md +56 -20
  62. package/assets/patterns/task-flow-start.md +3 -4
  63. package/assets/patterns/testing-e2e.md +14 -18
  64. package/assets/patterns/testing-unit.md +9 -13
  65. package/assets/patterns/turn-entry-map.md +13 -3
  66. package/assets/pitfalls/autonomous-work.md +15 -0
  67. package/assets/pitfalls/doc-style.md +3 -3
  68. package/assets/pitfalls/git-workflow.github.md +5 -9
  69. package/assets/pitfalls/spec-driven.md +9 -7
  70. package/assets/pitfalls/task-flow.md +14 -25
  71. package/assets/pitfalls/testing.md +11 -12
  72. package/assets/pitfalls/turn-conduct.md +6 -6
  73. package/assets/rules/autonomous-work.md +37 -29
  74. package/assets/rules/browser-verification.md +27 -22
  75. package/assets/rules/dependencies.md +3 -3
  76. package/assets/rules/deploy-flow.azure.md +35 -12
  77. package/assets/rules/deploy-flow.github.md +10 -6
  78. package/assets/rules/deploy-flow.gitlab.md +40 -17
  79. package/assets/rules/doc-style.md +21 -17
  80. package/assets/rules/epic-flow.md +5 -3
  81. package/assets/rules/git-workflow.azure.md +140 -122
  82. package/assets/rules/git-workflow.github.md +7 -8
  83. package/assets/rules/git-workflow.gitlab.md +128 -117
  84. package/assets/rules/queue-audit.github.md +5 -3
  85. package/assets/rules/spec-driven.md +17 -25
  86. package/assets/rules/status-report.md +5 -3
  87. package/assets/rules/task-flow.md +33 -15
  88. package/assets/rules/testing.md +35 -32
  89. package/assets/rules/turn-conduct.md +26 -24
  90. package/assets/templates/rule.md +2 -2
  91. package/assets/traits.json +3 -0
  92. package/lib/cargo-prose.d.ts +2 -1
  93. package/lib/cargo-prose.d.ts.map +1 -1
  94. package/lib/cargo-prose.js.map +1 -1
  95. package/lib/companion.d.ts +0 -5
  96. package/lib/companion.d.ts.map +1 -1
  97. package/lib/companion.js +1 -1
  98. package/lib/companion.js.map +1 -1
  99. package/lib/cost.d.ts +0 -8
  100. package/lib/cost.d.ts.map +1 -1
  101. package/lib/cost.js +4 -4
  102. package/lib/cost.js.map +1 -1
  103. package/lib/hooks-map.d.ts +0 -12
  104. package/lib/hooks-map.d.ts.map +1 -1
  105. package/lib/hooks-map.js +2 -25
  106. package/lib/hooks-map.js.map +1 -1
  107. package/lib/observations-cargo.d.ts +1 -5
  108. package/lib/observations-cargo.d.ts.map +1 -1
  109. package/lib/observations-cargo.js +2 -2
  110. package/lib/observations-cargo.js.map +1 -1
  111. package/lib/observations.d.ts +0 -2
  112. package/lib/observations.d.ts.map +1 -1
  113. package/lib/observations.js.map +1 -1
  114. package/lib/order.d.ts +0 -2
  115. package/lib/order.d.ts.map +1 -1
  116. package/lib/order.js +0 -4
  117. package/lib/order.js.map +1 -1
  118. package/lib/outcomes.d.ts +2 -7
  119. package/lib/outcomes.d.ts.map +1 -1
  120. package/lib/outcomes.js +3 -3
  121. package/lib/outcomes.js.map +1 -1
  122. package/lib/proposals.d.ts +0 -1
  123. package/lib/proposals.d.ts.map +1 -1
  124. package/lib/proposals.js +1 -1
  125. package/lib/proposals.js.map +1 -1
  126. package/lib/shipment.d.ts +2 -11
  127. package/lib/shipment.d.ts.map +1 -1
  128. package/lib/shipment.fixture.d.ts +0 -3
  129. package/lib/shipment.fixture.d.ts.map +1 -1
  130. package/lib/shipment.fixture.js +3 -3
  131. package/lib/shipment.fixture.js.map +1 -1
  132. package/lib/shipment.js +2 -2
  133. package/lib/shipment.js.map +1 -1
  134. package/lib/traits.d.ts +0 -3
  135. package/lib/traits.d.ts.map +1 -1
  136. package/lib/traits.js +2 -2
  137. package/lib/traits.js.map +1 -1
  138. package/lib/variants.d.ts +0 -1
  139. package/lib/variants.d.ts.map +1 -1
  140. package/lib/variants.js +1 -1
  141. package/lib/variants.js.map +1 -1
  142. package/package.json +1 -1
  143. package/assets/checks/signals/ui-kit.json +0 -11
@@ -1,12 +1,13 @@
1
1
  /**
2
2
  * The state of an open request read by its tip: a run pushed out of the queue, a missing run, a
3
- * finished piece of work left as a draft, a conflict. Lives in a file of its own — the audit of
4
- * the work queue stands at the length limit even without it, and these four checks are read
3
+ * finished piece of work left as a draft, a missing reviewer, a conflict. Lives in a file of its
4
+ * own — the audit of the work queue stands at the length limit even without it, and these five checks are read
5
5
  * together and apart from the rest.
6
6
  *
7
7
  * The line printer and the name of the main branch come as arguments: the module knows the
8
8
  * hosting, not the settings of the tree that called it.
9
9
  */
10
+ import { OfflineError, OWNER, REPO, ghJson } from './board.mjs';
10
11
  import { onlyIgnoredPaths } from './board-paths.mjs';
11
12
  import { evictedOnHead, headCommittedAt, runsOnHead, verdictOnHead } from './board-runs.mjs';
12
13
 
@@ -54,6 +55,17 @@ export function checkHeadRun(pull, report, mainBranch, options) {
54
55
  return;
55
56
  }
56
57
 
58
+ // A PR whose base is not the main branch gets no run at all: the workflow listens for PRs
59
+ // into the main branch and does not see events with another base. That is the order of
60
+ // handing in, not a discrepancy — every task of an epic is handed in exactly so — and the
61
+ // audit says nothing about it. The former line was wrong three times over: the event was not
62
+ // lost, reopening will not bring it back, and the base of a task request stays the epic
63
+ // branch to the merge. It is asked before the conflict: a conflicting task PR is named by the
64
+ // conflict line, and «no run while it conflicts» would promise a run that never comes.
65
+ if (pull.baseRefName && pull.baseRefName !== mainBranch) {
66
+ return;
67
+ }
68
+
57
69
  if (pull.mergeable === 'CONFLICTING') {
58
70
  report(
59
71
  `PR #${pull.number}: there is no run on the tip ${pull.headRefOid.slice(0, 8)} and there will be none while it conflicts — ` +
@@ -64,16 +76,6 @@ export function checkHeadRun(pull, report, mainBranch, options) {
64
76
  return;
65
77
  }
66
78
 
67
- // A PR whose base is not the main branch gets no run at all: the workflow listens for PRs
68
- // into the main branch and does not see events with another base. That is the order of
69
- // handing in, not a discrepancy — every task of an epic is handed in exactly so — and the
70
- // audit says nothing about it. The former line was wrong three times over: the event was not
71
- // lost, reopening will not bring it back, and the base of a task request stays the epic
72
- // branch to the merge.
73
- if (pull.baseRefName && pull.baseRefName !== mainBranch) {
74
- return;
75
- }
76
-
77
79
  report(
78
80
  `PR #${pull.number}: there is no run on the tip ${pull.headRefOid.slice(0, 8)}, and it has lain there ${minutes} min — ` +
79
81
  `the pipeline received no event; bring it back by a new commit or by reopening the PR ` +
@@ -138,6 +140,71 @@ function checkReadyDraft(pull, report, options) {
138
140
  );
139
141
  }
140
142
 
143
+ /**
144
+ * Who was asked to review a PR and who left a review, each with the kind of the account.
145
+ *
146
+ * Read by REST, a call per list. The same lists asked through the list of PRs need the scope
147
+ * `read:org`, and a token of a machine account that lacks it gets the whole query refused: the
148
+ * audit then printed one line of an error and no line of its own.
149
+ *
150
+ * FAIL-OPEN: no answer — `null`, and the PR is not judged. Without network the refusal is thrown,
151
+ * as everywhere.
152
+ */
153
+ export function fetchReviewers(number, options) {
154
+ if (!OWNER || !REPO) {
155
+ return null;
156
+ }
157
+ const path = `repos/${OWNER}/${REPO}/pulls/${number}`;
158
+ try {
159
+ return {
160
+ asked: ghJson(
161
+ ['api', `${path}/requested_reviewers`, '--jq', '[.users[] | {login, type}] + [.teams[] | {login: .slug, type: "Team"}]'],
162
+ options
163
+ ),
164
+ left: ghJson(['api', `${path}/reviews`, '--jq', '[.[] | {login: .user.login, type: .user.type}]'], options),
165
+ };
166
+ } catch (error) {
167
+ if (error instanceof OfflineError) {
168
+ throw error;
169
+ }
170
+ return null;
171
+ }
172
+ }
173
+
174
+ /**
175
+ * A PR nobody was asked to review.
176
+ *
177
+ * Such a PR reaches no inbox: the queue stands while it looks as if it works. A request to review
178
+ * oneself does not count — the host accepts it and creates nothing — so the author is taken out of
179
+ * both lists. A PR opened by a person shows here too: an author cannot be asked, and nobody else
180
+ * was.
181
+ *
182
+ * The lists come apart from the PR, by REST: `reviewers` is `{asked, left}`, each entry a login
183
+ * with the kind of its account.
184
+ *
185
+ * FAIL-OPEN: no lists — the PR is not judged. Silence about the reviewers is not the same as their
186
+ * absence, and a line on it would go red on every PR of a host that hides them.
187
+ */
188
+ export function checkReviewer(pull, report, reviewers) {
189
+ if (!reviewers) {
190
+ return;
191
+ }
192
+
193
+ const author = pull.author?.login ?? null;
194
+ // A bot asked for a review or one that left it is not a person: the PR still reaches no inbox.
195
+ const person = (entry) =>
196
+ Boolean(entry?.login) && entry.type !== 'Bot' && !entry.login.endsWith('[bot]') && entry.login !== author;
197
+ if ([...(reviewers.asked ?? []), ...(reviewers.left ?? [])].some(person)) {
198
+ return;
199
+ }
200
+
201
+ report(
202
+ `PR #${pull.number}: the PR has no reviewer — nobody but its author was asked or left a review, and it reaches no inbox; ` +
203
+ `request one by a REST call: gh api -X POST repos/<owner>/<repo>/pulls/${pull.number}/requested_reviewers -f 'reviewers[]=<login>'; ` +
204
+ `a PR opened by the reviewer's own account cannot ask them — close it and open it again as the machine account`
205
+ );
206
+ }
207
+
141
208
  /**
142
209
  * A PR that conflicts with the main branch.
143
210
  *
@@ -156,8 +223,10 @@ export function checkConflicting(pull, report) {
156
223
  return;
157
224
  }
158
225
 
226
+ // The host counts mergeability against the base of the PR: for a task that is the epic branch.
227
+ const base = pull.baseRefName ? `«${pull.baseRefName}»` : 'branch';
159
228
  report(
160
- `PR #${pull.number}: it conflicts with the main branch — merge it into the task branch, resolve the conflict and push; ` +
229
+ `PR #${pull.number}: it conflicts with its base ${base} — merge the base into the PR branch, resolve the conflict and push; ` +
161
230
  `the owner cannot merge this request, and on the page that shows only inside it`
162
231
  );
163
232
  }
@@ -262,7 +262,7 @@ export function behindMain(branch, mainBranch, options) {
262
262
  * and asking for it later would mean a second call per PR. */
263
263
  export function fetchOpenPulls(options) {
264
264
  return ghJson(
265
- ['pr', 'list', '--state', 'open', '--limit', '200', '--json', 'number,title,headRefName,headRefOid,isDraft,body,mergeable,baseRefName'],
265
+ ['pr', 'list', '--state', 'open', '--limit', '200', '--json', 'number,title,headRefName,headRefOid,isDraft,body,mergeable,baseRefName,author'],
266
266
  options
267
267
  );
268
268
  }
@@ -49,7 +49,7 @@ import {
49
49
  taskDirs,
50
50
  } from './board.mjs';
51
51
  import { checkBranchFolders, checkUntrackedFolders } from './board-folders.mjs';
52
- import { checkConflicting, checkHeadRun } from './board-pull-state.mjs';
52
+ import { checkConflicting, checkHeadRun, checkReviewer, fetchReviewers } from './board-pull-state.mjs';
53
53
  import { checkLongWork } from './board-long-work.mjs';
54
54
  import { HAS_PIPELINE, deployLag, lastDeploy, lastMainRun, pipelineText, pipelineWakesOnPush } from './board-runs.mjs';
55
55
  import { checkEpicLinks, checkEpicPullBase, checkEpicState, checkEpicSubIssues } from './board-epics.mjs';
@@ -162,7 +162,7 @@ function folderInBranch(branch, options) {
162
162
  }
163
163
  }
164
164
 
165
- let checked = { issues: 0, pulls: 0, cargo: 0, offBase: 0 };
165
+ let checked = { issues: 0, pulls: 0, cargo: 0, offBase: 0, lagging: [] };
166
166
 
167
167
  // Drafts are judged by the disk and so are checked always: no connection is needed for that.
168
168
  checkDrafts();
@@ -181,7 +181,7 @@ try {
181
181
  // such a record, whatever labels it wears.
182
182
  const open = CARGO_LABELS.size === 0 ? allOpen : allOpen.filter((issue) => !isCargo(issue));
183
183
  const pulls = fetchOpenPulls(options);
184
- checked = { issues: issues.length, pulls: pulls.length, cargo: allOpen.length - open.length, offBase: 0 };
184
+ checked = { issues: issues.length, pulls: pulls.length, cargo: allOpen.length - open.length, offBase: 0, lagging: [] };
185
185
 
186
186
  for (const item of board.foreign) {
187
187
  report(`the board: ${item} — the board holds tasks, not PRs about them`);
@@ -241,16 +241,16 @@ try {
241
241
  }
242
242
 
243
243
  checkConflicting(pull, report);
244
-
245
- // The PR falling behind the main branch: the guard judges the base once, at the minute of
246
- // opening, and a PR stands for days. Merged while behind, it carries into main a
247
- // combination nobody checked — and the PR page does not show this: the run on it is green.
248
- const behind = behindMain(pull.headRefName, MAIN_BRANCH, options);
244
+ checkReviewer(pull, report, fetchReviewers(pull.number, options));
245
+
246
+ // The PR falling behind its base is counted, not refused: a lag without a conflict the host
247
+ // merges itself, and a line that told to merge the base in sent the executor to do what the
248
+ // rules forbid. A conflicting PR is named by its own line above. The base of a task is the
249
+ // epic branch, and its lag behind main is the epic's, not the task's.
250
+ const base = pull.baseRefName || MAIN_BRANCH;
251
+ const behind = pull.mergeable === 'CONFLICTING' ? 0 : behindMain(pull.headRefName, base, options);
249
252
  if (behind > 0) {
250
- report(
251
- `PR #${pull.number}: the branch lags «${MAIN_BRANCH}» by ${behind} commits — the run went from a base ` +
252
- `the main branch no longer carries. Merge the main branch in, revise the check set by what the branch carries now, and run again`
253
- );
253
+ checked.lagging.push(`PR #${pull.number} lags «${base}» by ${behind} commits`);
254
254
  }
255
255
 
256
256
  if (!FOLDER_SKIP.test(String(pull.body ?? '')) && pull.headRefName) {
@@ -394,6 +394,14 @@ if (!offline && checked.offBase > 0) {
394
394
  );
395
395
  }
396
396
 
397
+ // A lag is a count, not a discrepancy: the line changes no exit code and asks for no merge.
398
+ if (!offline && checked.lagging.length > 0) {
399
+ console.log(
400
+ `check-board: open PRs behind their base without a conflict — ${checked.lagging.join('; ')}: ` +
401
+ `nothing to do, the host merges such a branch itself; ask the host again before the merge`
402
+ );
403
+ }
404
+
397
405
  // What was filtered out is named by number: silent filtering is indistinguishable from a broken
398
406
  // audit — a label named with a typo would switch the check off entirely and say nothing about it.
399
407
  if (!offline && checked.cargo > 0) {
@@ -16,7 +16,7 @@
16
16
  * decision, and four discount mechanics that were never started would have found no binding
17
17
  * at all. The key of the link is the text of the rule itself, so it cannot be reworded while
18
18
  * the binding is left unfixed. A rule without a binding is an intention, and it is written as
19
- * an open question of a law — `Q-<law letter>-<number>`.
19
+ * an open question: `Q-<law letters>-<number>` in a law, `Q-<number>` in a spec.
20
20
  *
21
21
  * 2. THE CONTRACT AGAINST THE DECORATORS. The table of procedures is audited against what is
22
22
  * declared in the domain's `*.procedure.ts`: `@RequiresPermission` / `@PublicProcedure` and
@@ -410,7 +410,7 @@ for (const scenario of byId.values()) {
410
410
  report(
411
411
  `${scenario.file}:${scenario.line}`,
412
412
  `${scenario.id} promises what a person sees, and ${off ? 'the end-to-end test for it is switched off by an environment variable' : 'only a unit test checks it'} ` +
413
- `(${places[0].place}) — either the test goes the path of the user, or the scenario needs the mark «Покрытие: частичное»`
413
+ `(${places[0].place}) — either the test goes the path of the user, or the scenario needs the mark «Coverage: partial»`
414
414
  );
415
415
  continue;
416
416
  }
@@ -163,11 +163,12 @@ function rowOf(number, board, pulls) {
163
163
  /**
164
164
  * Why the epic exists, in one sentence — the first phrase of the section the plan opens with.
165
165
  *
166
- * A plan whose first section is worded otherwise loses the phrase, and the paragraph then names
167
- * only the count of the tasks: that is the open question `Q-WC-9` of the subdomain.
166
+ * The draft of the plan opens with «Что даёт»; plans written before it open with «Зачем». A plan
167
+ * whose first section is worded otherwise loses the phrase, and the paragraph then names only the
168
+ * count of the tasks.
168
169
  */
169
170
  function whyOf(plan) {
170
- const section = /^##\s+Зачем\s*$/m.exec(plan);
171
+ const section = /^##\s+(?:Что даёт|Зачем)\s*$/m.exec(plan);
171
172
  if (!section) {
172
173
  return '';
173
174
  }
@@ -43,7 +43,13 @@ const COMMON_DOMAIN_LAYERS = [...FLAT_LAYERS, 'feature'].sort();
43
43
  const API_DOMAIN_LAYERS = ['api', 'data-access', 'feature', 'util'];
44
44
  /** Where libs that ended up outside the domain grid are looked for */
45
45
  const LIB_ROOTS = [...FAMILIES, ...API_FAMILIES].map((family) => `${LIBS_ROOT}/${family}`);
46
- const REQUIRED_FILES = ['project.json', 'tsconfig.json', 'vitest.config.mts', 'src/index.ts'];
46
+ /**
47
+ * The files every lib has. The test runner is not among them: it is declared in one of two forms,
48
+ * and `lib-manifests.mjs` judges that on its own.
49
+ */
50
+ const REQUIRED_FILES = ['project.json', 'tsconfig.json', 'src/index.ts'];
51
+ /** The executor that runs the tests of a lib through the Angular builder */
52
+ const ANGULAR_TEST_EXECUTOR = '@angular/build:unit-test';
47
53
  const BOUNDARIES_DIR = 'eslint/boundaries/domains';
48
54
 
49
55
  const problems = [];
@@ -51,7 +57,8 @@ const report = (path, message) => problems.push(`${path}: ${message}`);
51
57
 
52
58
  const readJson = (path) => JSON.parse(readFileSync(join(ROOT, path), 'utf8'));
53
59
  const isDir = (path) => existsSync(join(ROOT, path)) && statSync(join(ROOT, path)).isDirectory();
54
- const IGNORED_DIRS = ['src', 'node_modules'];
60
+ /** The sources of a lib and everything the tree never walks into. */
61
+ const IGNORED_DIRS = ['src', ...CONFIG.skippedDirs];
55
62
  const dirsIn = (path) =>
56
63
  isDir(path)
57
64
  ? readdirSync(join(ROOT, path), { withFileTypes: true })
@@ -187,6 +194,7 @@ export {
187
194
  API_DOMAIN_LAYERS,
188
195
  LIB_ROOTS,
189
196
  REQUIRED_FILES,
197
+ ANGULAR_TEST_EXECUTOR,
190
198
  BOUNDARIES_DIR,
191
199
  IGNORED_DIRS,
192
200
  allowlist,
@@ -196,7 +196,7 @@ function collectStrayLibs(knownLibs) {
196
196
  * layers by their make-up — a domain is one lib — but everything else is checked on a par with
197
197
  * the domain grid. Before the narrowing, the exception on this root took off from them the
198
198
  * make-up of the files, the tag and the alias too: a new lib was started without
199
- * `vitest.config.mts`, and `nx test` silently ran not a single test over it.
199
+ * a test runner, and `nx test` silently ran not a single test over it.
200
200
  */
201
201
  function collectFlatLibs() {
202
202
  return [...(allowlist.flatLibRoots?.keys() ?? [])]
@@ -6,12 +6,43 @@
6
6
  * The name does not begin with `check-`: by walking such names the package default assembles the
7
7
  * push gate set, and a helper with one would be run by the gate as a check of its own.
8
8
  */
9
- import { existsSync } from 'node:fs';
9
+ import { existsSync, statSync } from 'node:fs';
10
10
  import { join } from 'node:path';
11
11
 
12
- import { LIB_PREFIX, REQUIRED_FILES, declaredAlias, importAlias, libTag, projectName, readJson, report } from './lib-common.mjs';
12
+ import { ANGULAR_TEST_EXECUTOR, LIB_PREFIX, REQUIRED_FILES, declaredAlias, importAlias, libTag, projectName, readJson, report } from './lib-common.mjs';
13
13
  import { ROOT } from './rt-kit-checks.config.mjs';
14
14
 
15
+ /**
16
+ * A lib runs its tests in one of two forms: its own `vitest.config.mts`, or the Angular builder.
17
+ * The second counts only when all three hold at once: `project.json` declares the `test` target on
18
+ * the executor `@angular/build:unit-test`, `options.tsConfig` names a file that exists on disk, and
19
+ * the lib has its own `tsconfig.spec.json`. A lib with both forms is not an error.
20
+ */
21
+ function checkTestRunner(libPath, project) {
22
+ if (existsSync(join(ROOT, libPath, 'vitest.config.mts'))) {
23
+ return;
24
+ }
25
+ const expected = `a lib needs a test runner: either ${libPath}/vitest.config.mts, or a \`test\` target on the executor ${ANGULAR_TEST_EXECUTOR} with options.tsConfig pointing at an existing file, together with its own ${libPath}/tsconfig.spec.json`;
26
+ const target = project.targets?.test;
27
+ if (!target) {
28
+ report(libPath, `no file vitest.config.mts and no \`test\` target in project.json; ${expected}`);
29
+ return;
30
+ }
31
+ if (target.executor !== ANGULAR_TEST_EXECUTOR) {
32
+ report(libPath, `no file vitest.config.mts, and the \`test\` target ${target.executor ? `runs on «${target.executor}»` : 'names no executor'}; ${expected}`);
33
+ return;
34
+ }
35
+ const tsConfig = target.options?.tsConfig;
36
+ if (typeof tsConfig !== 'string' || tsConfig === '') {
37
+ report(libPath, `no file vitest.config.mts, and the \`test\` target names no options.tsConfig; ${expected}`);
38
+ } else if (!existsSync(join(ROOT, tsConfig)) || !statSync(join(ROOT, tsConfig)).isFile()) {
39
+ report(libPath, `no file vitest.config.mts, and options.tsConfig «${tsConfig}» is not an existing file; ${expected}`);
40
+ }
41
+ if (!existsSync(join(ROOT, libPath, 'tsconfig.spec.json'))) {
42
+ report(libPath, `no file vitest.config.mts, and no file tsconfig.spec.json; ${expected}`);
43
+ }
44
+ }
45
+
15
46
  function checkLib(libPath, { requirePrefix = true } = {}) {
16
47
  for (const file of REQUIRED_FILES) {
17
48
  if (!existsSync(join(ROOT, libPath, file))) {
@@ -24,6 +55,7 @@ function checkLib(libPath, { requirePrefix = true } = {}) {
24
55
  }
25
56
 
26
57
  const project = readJson(`${libPath}/project.json`);
58
+ checkTestRunner(libPath, project);
27
59
  // The name the tree wrote down is the name. The formula speaks only where nothing is written:
28
60
  // it says what the name must become, and judging a declared name by it reddens a lib that
29
61
  // breaks nothing.