@roomi-fields/grillhouse 0.28.3 → 0.30.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 (238) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +739 -0
  3. package/bin/grillhouse.mjs +128 -26
  4. package/cadre/templates/projet/.github/workflows/ci.yml +2 -13
  5. package/cadre/templates/projet/CLAUDE.md +5 -1
  6. package/cadre/templates/projet/README.md +11 -11
  7. package/cadre/templates/projet/_gitignore +2 -5
  8. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  9. package/cadre/templates/projet/package.json +2 -2
  10. package/charte.md +37 -4
  11. package/dist/temporal/acte.d.ts +24 -0
  12. package/dist/temporal/acte.js +139 -0
  13. package/dist/temporal/acte.js.map +1 -0
  14. package/dist/temporal/attributs.d.ts +6 -0
  15. package/dist/temporal/attributs.js +15 -0
  16. package/dist/temporal/attributs.js.map +1 -0
  17. package/dist/temporal/circuit/activites.d.ts +13 -0
  18. package/dist/temporal/circuit/activites.js +33 -0
  19. package/dist/temporal/circuit/activites.js.map +1 -0
  20. package/dist/temporal/circuit/client.d.ts +72 -0
  21. package/dist/temporal/circuit/client.js +247 -0
  22. package/dist/temporal/circuit/client.js.map +1 -0
  23. package/dist/temporal/circuit/commande.d.ts +2 -0
  24. package/dist/temporal/circuit/commande.js +238 -0
  25. package/dist/temporal/circuit/commande.js.map +1 -0
  26. package/dist/temporal/circuit/contrat.d.ts +305 -0
  27. package/dist/temporal/circuit/contrat.js +24 -0
  28. package/dist/temporal/circuit/contrat.js.map +1 -0
  29. package/dist/temporal/circuit/deroule.d.ts +3 -0
  30. package/dist/temporal/circuit/deroule.js +540 -0
  31. package/dist/temporal/circuit/deroule.js.map +1 -0
  32. package/dist/temporal/client.d.ts +47 -0
  33. package/dist/temporal/client.js +69 -0
  34. package/dist/temporal/client.js.map +1 -0
  35. package/dist/temporal/commande.d.ts +2 -0
  36. package/dist/temporal/commande.js +95 -0
  37. package/dist/temporal/commande.js.map +1 -0
  38. package/dist/temporal/deroules.d.ts +5 -0
  39. package/dist/temporal/deroules.js +10 -0
  40. package/dist/temporal/deroules.js.map +1 -0
  41. package/dist/temporal/etat.d.ts +33 -0
  42. package/dist/temporal/etat.js +59 -0
  43. package/dist/temporal/etat.js.map +1 -0
  44. package/dist/temporal/file/activites.d.ts +10 -0
  45. package/dist/temporal/file/activites.js +25 -0
  46. package/dist/temporal/file/activites.js.map +1 -0
  47. package/dist/temporal/file/client.d.ts +4 -0
  48. package/dist/temporal/file/client.js +6 -0
  49. package/dist/temporal/file/client.js.map +1 -0
  50. package/dist/temporal/file/contrat.d.ts +158 -0
  51. package/dist/temporal/file/contrat.js +14 -0
  52. package/dist/temporal/file/contrat.js.map +1 -0
  53. package/dist/temporal/file/deroule.d.ts +15 -0
  54. package/dist/temporal/file/deroule.js +235 -0
  55. package/dist/temporal/file/deroule.js.map +1 -0
  56. package/dist/temporal/installation.d.ts +124 -0
  57. package/dist/temporal/installation.js +408 -0
  58. package/dist/temporal/installation.js.map +1 -0
  59. package/dist/temporal/places/activites.d.ts +8 -0
  60. package/dist/temporal/places/activites.js +13 -0
  61. package/dist/temporal/places/activites.js.map +1 -0
  62. package/dist/temporal/places/client.d.ts +28 -0
  63. package/dist/temporal/places/client.js +64 -0
  64. package/dist/temporal/places/client.js.map +1 -0
  65. package/dist/temporal/places/contrat.d.ts +106 -0
  66. package/dist/temporal/places/contrat.js +21 -0
  67. package/dist/temporal/places/contrat.js.map +1 -0
  68. package/dist/temporal/places/deroule.d.ts +3 -0
  69. package/dist/temporal/places/deroule.js +198 -0
  70. package/dist/temporal/places/deroule.js.map +1 -0
  71. package/dist/temporal/sonde/activites.d.ts +6 -0
  72. package/dist/temporal/sonde/activites.js +52 -0
  73. package/dist/temporal/sonde/activites.js.map +1 -0
  74. package/dist/temporal/sonde/contrat.d.ts +35 -0
  75. package/dist/temporal/sonde/contrat.js +10 -0
  76. package/dist/temporal/sonde/contrat.js.map +1 -0
  77. package/dist/temporal/sonde/deroule.d.ts +3 -0
  78. package/dist/temporal/sonde/deroule.js +39 -0
  79. package/dist/temporal/sonde/deroule.js.map +1 -0
  80. package/dist/temporal/tickets/activites.d.ts +7 -0
  81. package/dist/temporal/tickets/activites.js +81 -0
  82. package/dist/temporal/tickets/activites.js.map +1 -0
  83. package/dist/temporal/tickets/client.d.ts +10 -0
  84. package/dist/temporal/tickets/client.js +31 -0
  85. package/dist/temporal/tickets/client.js.map +1 -0
  86. package/dist/temporal/tickets/contrat.d.ts +56 -0
  87. package/dist/temporal/tickets/contrat.js +13 -0
  88. package/dist/temporal/tickets/contrat.js.map +1 -0
  89. package/dist/temporal/tickets/deroule.d.ts +3 -0
  90. package/dist/temporal/tickets/deroule.js +94 -0
  91. package/dist/temporal/tickets/deroule.js.map +1 -0
  92. package/dist/temporal/travailleur.d.ts +2 -0
  93. package/dist/temporal/travailleur.js +69 -0
  94. package/dist/temporal/travailleur.js.map +1 -0
  95. package/docs/ARCHITECTURE.md +813 -53
  96. package/docs/CADRE.md +17 -0
  97. package/docs/INTERFACE.md +161 -30
  98. package/hooks/crochet.mjs +19 -2
  99. package/hooks/hooks.json +11 -0
  100. package/package.json +16 -4
  101. package/scripts/activites.mjs +2182 -0
  102. package/scripts/aiguillage.d.mts +37 -0
  103. package/scripts/aiguillage.mjs +328 -0
  104. package/scripts/avancement.mjs +159 -64
  105. package/scripts/bilan.mjs +37 -19
  106. package/scripts/cadre.mjs +11 -2
  107. package/scripts/circuit.mjs +888 -3654
  108. package/scripts/circuits-cles.d.mts +4 -0
  109. package/scripts/circuits-cles.mjs +21 -0
  110. package/scripts/circuits-du-serveur.mjs +105 -0
  111. package/scripts/codes-de-sortie.mjs +9 -0
  112. package/scripts/commandes-composees.mjs +45 -41
  113. package/scripts/commandes-du-path.d.mts +7 -0
  114. package/scripts/commandes-du-path.mjs +25 -0
  115. package/scripts/composition-des-langages.mjs +30 -11
  116. package/scripts/conformite.mjs +19 -10
  117. package/scripts/copies-finies.mjs +188 -42
  118. package/scripts/depart-du-ticket.d.mts +53 -0
  119. package/scripts/depart-du-ticket.mjs +124 -0
  120. package/scripts/dependances-internes.mjs +115 -0
  121. package/scripts/dernier-vert.mjs +7 -15
  122. package/scripts/donnees-cles.mjs +228 -0
  123. package/scripts/droits.mjs +11 -1
  124. package/scripts/effets.mjs +352 -0
  125. package/scripts/enveloppe/enveloppe.mjs +119 -8
  126. package/scripts/enveloppe/lancer.sh +27 -32
  127. package/scripts/enveloppe/paquets-du-plan.mjs +2 -2
  128. package/scripts/enveloppe/travail-de-la-copie.mjs +99 -12
  129. package/scripts/etapes.mjs +6 -3
  130. package/scripts/faits-du-circuit.mjs +493 -0
  131. package/scripts/file-des-tickets.d.mts +21 -0
  132. package/scripts/file-des-tickets.mjs +58 -0
  133. package/scripts/flux-des-paquets.mjs +187 -0
  134. package/scripts/fusion-du-changelog.mjs +0 -1
  135. package/scripts/gardes-du-cadre.mjs +12 -2
  136. package/scripts/grillhouse-maj.mjs +16 -7
  137. package/scripts/integration/file.mjs +477 -422
  138. package/scripts/integration/integrer.mjs +20 -22
  139. package/scripts/integration/rejeu.mjs +19 -4
  140. package/scripts/jointure.d.ts +168 -28
  141. package/scripts/langages/cargo/commandes.mjs +426 -119
  142. package/scripts/langages/cargo/composants.mjs +187 -3
  143. package/scripts/langages/cargo/exemples.mjs +75 -17
  144. package/scripts/langages/cargo/index.mjs +32 -13
  145. package/scripts/langages/cargo/migrations/0.28.4-tailles-des-tests.mjs +35 -0
  146. package/scripts/langages/cargo/sccache.mjs +62 -16
  147. package/scripts/langages/cargo/squelette.mjs +72 -3
  148. package/scripts/langages/cargo/tailles-des-tests.mjs +195 -0
  149. package/scripts/langages/cargo/tests-de-head.mjs +159 -0
  150. package/scripts/langages/python/commandes.mjs +232 -79
  151. package/scripts/langages/python/composants.mjs +65 -3
  152. package/scripts/langages/python/exemples.mjs +21 -12
  153. package/scripts/langages/python/index.mjs +25 -5
  154. package/scripts/langages/python/lot.mjs +1 -36
  155. package/scripts/langages/python/squelette.mjs +119 -17
  156. package/scripts/langages/typescript/construire.mjs +6 -163
  157. package/scripts/langages/typescript/exemples.mjs +19 -11
  158. package/scripts/langages/typescript/frontieres.mjs +1 -1
  159. package/scripts/langages/typescript/index.mjs +48 -63
  160. package/scripts/langages/typescript/interfaces-contre-code.mjs +4 -4
  161. package/scripts/langages/typescript/migrations/0.30.0-prefixe-des-tickets.mjs +63 -0
  162. package/scripts/langages/typescript/migrations/0.30.0-tailles-des-outils-lourds.mjs +31 -0
  163. package/scripts/langages/typescript/migrations/0.30.0-titres-nommant-un-ticket.mjs +40 -0
  164. package/scripts/langages/typescript/mise-a-jour.mjs +1 -2
  165. package/scripts/langages/typescript/regle-des-tests.mjs +13 -0
  166. package/scripts/langages/typescript/squelette.mjs +18 -2
  167. package/scripts/langages/typescript/tailles-des-tests.mjs +40 -9
  168. package/scripts/langages/typescript/tests-de-nuit.mjs +44 -21
  169. package/scripts/langages/typescript/tests.mjs +17 -8
  170. package/scripts/langages/typescript/titres-de-tests.mjs +297 -0
  171. package/scripts/langages/typescript/turbo-des-paquets.mjs +183 -38
  172. package/scripts/langages/typescript/verdict.mjs +1 -1
  173. package/scripts/langages/typescript/verifier.mjs +110 -296
  174. package/scripts/langages/typescript/vitest-config/base.mjs +30 -10
  175. package/scripts/langages/typescript/vitest-config/bornes.mjs +13 -0
  176. package/scripts/langages/typescript/vitest-config/cibles.mjs +123 -62
  177. package/scripts/langages/typescript/vitest-config/delais.mjs +54 -0
  178. package/scripts/langages/typescript/vitest-config/delais.setup.mjs +11 -0
  179. package/scripts/langages/typescript/vitest-config/duree.classement.mjs +100 -0
  180. package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +56 -64
  181. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +7 -2
  182. package/scripts/langages/typescript/vitest-config/mesure.mjs +3 -2
  183. package/scripts/langages/typescript/vitest.nuit.config.mjs +22 -13
  184. package/scripts/lecture-unique.mjs +51 -0
  185. package/scripts/mesure/pression.mjs +11 -9
  186. package/scripts/mesure-de-la-machine.d.mts +21 -0
  187. package/scripts/mesure-de-la-machine.mjs +76 -0
  188. package/scripts/migrations/0.23.2-copies-du-cadre.mjs +8 -2
  189. package/scripts/migrations/0.30.0-ci-appelle-la-verification.mjs +120 -0
  190. package/scripts/migrations/0.31.0-paquets-dans-le-graphe.mjs +81 -0
  191. package/scripts/migrations.mjs +5 -0
  192. package/scripts/nuit.sh +29 -15
  193. package/scripts/outil.mjs +72 -0
  194. package/scripts/outils-cles.d.mts +24 -0
  195. package/scripts/outils-cles.mjs +0 -1
  196. package/scripts/paquet-npm.mjs +147 -0
  197. package/scripts/paquet.mjs +112 -14
  198. package/scripts/paquets.mjs +34 -6
  199. package/scripts/passe-de-la-machine.mjs +66 -0
  200. package/scripts/places-de-la-machine.mjs +360 -0
  201. package/scripts/places-du-serveur.mjs +170 -0
  202. package/scripts/prefixe-des-tickets.mjs +68 -0
  203. package/scripts/preparation.mjs +10 -3
  204. package/scripts/registre.mjs +3 -2
  205. package/scripts/regles-des-places.d.mts +36 -0
  206. package/scripts/regles-des-places.mjs +70 -0
  207. package/scripts/reponses-du-circuit.d.mts +6 -0
  208. package/scripts/reponses-du-circuit.mjs +28 -0
  209. package/scripts/resultats.mjs +29 -14
  210. package/scripts/retirer-les-copies-finies.mjs +25 -0
  211. package/scripts/sans-reponse.d.mts +4 -0
  212. package/scripts/sans-reponse.mjs +13 -0
  213. package/scripts/seances.mjs +918 -0
  214. package/scripts/services-du-noyau.mjs +28 -11
  215. package/scripts/session-start.sh +10 -1
  216. package/scripts/sortie.mjs +23 -4
  217. package/scripts/sources.mjs +3 -3
  218. package/scripts/sous-commandes.mjs +39 -9
  219. package/scripts/style-a-l-ecriture.mjs +229 -0
  220. package/scripts/superviseur.mjs +382 -16
  221. package/scripts/tableau.mjs +329 -130
  222. package/scripts/taches-du-graphe.mjs +328 -0
  223. package/scripts/ticket-du-circuit.mjs +206 -0
  224. package/scripts/transitions.d.mts +148 -0
  225. package/scripts/transitions.mjs +901 -0
  226. package/scripts/verrou-de-fichier.mjs +2 -2
  227. package/scripts/verrou-de-machine.mjs +322 -62
  228. package/skills/developpeur/SKILL.md +11 -3
  229. package/skills/explorateur/SKILL.md +2 -1
  230. package/skills/pitmaster/SKILL.md +62 -28
  231. package/skills/pitmaster/references/consigne-agent.md +5 -1
  232. package/skills/release/SKILL.md +3 -3
  233. package/skills/relecteur/SKILL.md +22 -8
  234. package/skills/testwriter/SKILL.md +47 -39
  235. package/scripts/demon.mjs +0 -138
  236. package/scripts/integration/file-attente.mjs +0 -61
  237. package/scripts/langages/cargo/touches.mjs +0 -93
  238. package/scripts/langages/typescript/script-des-tests.mjs +0 -6
@@ -5,34 +5,45 @@
5
5
  //
6
6
  // node tests-de-nuit.mjs from the root of the copy
7
7
  //
8
- // - The files `*.nuit.test.*`, `*.nuit.spec.*`, `*.budget.test.*` and `*.budget.spec.*` of the
9
- // copy, outside node_modules, dist and .git: the night tests and the time budget benches, which
10
- // `npm test` and the integration leave out (./vitest-config/cibles.mjs, HORS_DU_JOUR). A copy
11
- // with neither plays none, and the exit code is 0.
8
+ // - The files `*.nuit.test.*` and `*.nuit.spec.*` of the copy, outside node_modules, dist and
9
+ // .git, the night tests, then its measures of time, the time budget benches (`*.budget.test.*`,
10
+ // `*.budget.spec.*`) and the time witnesses (a test file that imports `mesurerAuRepos`,
11
+ // `fichiersTemoins` of ./vitest-config/cibles.mjs): what `npm test` and the integration leave
12
+ // out (./vitest-config/cibles.mjs). A copy with none plays nothing, and the exit code is 0.
12
13
  // - Vitest plays them with the frame's configuration (./vitest.nuit.config.mjs), from the root of
13
- // the copy, a bench or a night test alone as well: `npx --no-install vitest run --root <copie>
14
- // --config <configuration>`. Its exit code is this command's: 75, « à repasser », when every
15
- // failure depended on a duration, one under load (./vitest-config/duree.reporter.mjs).
14
+ // the copy: `npx --no-install vitest run --root <copie> --config <configuration>`, once for the
15
+ // night tests (GRILLHOUSE_TESTS_DE_NUIT=nuit), then once for the measures alone, one file at a
16
+ // time (GRILLHOUSE_TESTS_DE_NUIT=mesures), as Bazel plays a test tagged `exclusive` after the
17
+ // others, nothing beside it, and as the module cargo plays its benches after its night tests
18
+ // (grillhouse-bd7). Each run plays when the copy holds its files.
19
+ // - The exit code: 0 when every run is green; 75, « à repasser », when every red run is at 75
20
+ // (every failure depended on a duration, one under load, ./vitest-config/duree.reporter.mjs);
21
+ // else the code of the first red run.
16
22
  // - They play once the temporary directory has room, as every heavy pass
17
23
  // (`attendreDeLaPlace` of scripts/verrou-de-machine.mjs): a wait that reaches its bound ends at 75.
18
24
  import { spawnSync } from 'node:child_process';
19
25
  import { readdirSync } from 'node:fs';
20
26
  import path from 'node:path';
21
27
  import { fileURLToPath, pathToFileURL } from 'node:url';
22
- import { attendreDeLaPlace } from '../../services-du-noyau.mjs';
28
+ import { A_REPASSER, attendreDeLaPlace } from '../../services-du-noyau.mjs';
29
+ import {
30
+ estUnBanc,
31
+ estUnTestDeNuit,
32
+ fichiersTemoins,
33
+ NUIT_VARIABLE,
34
+ } from './vitest-config/cibles.mjs';
23
35
 
24
36
  const CONFIGURATION = fileURLToPath(new URL('./vitest.nuit.config.mjs', import.meta.url));
25
37
  const HORS = new Set(['node_modules', 'dist', '.git']);
26
- const DE_NUIT = /\.(nuit|budget)\.(test|spec)\.(c|m)?[jt]sx?$/;
27
38
 
28
- // Whether a night test or a bench lies under <dossier>.
29
- function enTient(dossier) {
39
+ // Whether a file that <est> (the rules of ./vitest-config/cibles.mjs) lies under <dossier>.
40
+ function enTient(dossier, est) {
30
41
  for (const e of readdirSync(dossier, { withFileTypes: true })) {
31
42
  if (e.isDirectory()) {
32
- if (!HORS.has(e.name) && enTient(path.join(dossier, e.name))) {
43
+ if (!HORS.has(e.name) && enTient(path.join(dossier, e.name), est)) {
33
44
  return true;
34
45
  }
35
- } else if (e.isFile() && DE_NUIT.test(e.name)) {
46
+ } else if (e.isFile() && est(e.name)) {
36
47
  return true;
37
48
  }
38
49
  }
@@ -40,11 +51,16 @@ function enTient(dossier) {
40
51
  }
41
52
 
42
53
  /**
43
- * Plays the night tests of the copy at <racine>: the exit code of Vitest, 0 when there is none.
54
+ * Plays the night tests, then the measures of time, of the copy at <racine>: 0, 75 or the code of
55
+ * the first red run of Vitest; 0 when there is none.
44
56
  * @param {string} racine the root of the copy
45
57
  */
46
58
  export function testsDeNuit(racine) {
47
- if (!enTient(racine)) {
59
+ const runs = [
60
+ enTient(racine, estUnTestDeNuit) && 'nuit',
61
+ (enTient(racine, estUnBanc) || fichiersTemoins(racine).length > 0) && 'mesures',
62
+ ].filter(Boolean);
63
+ if (runs.length === 0) {
48
64
  return 0;
49
65
  }
50
66
  try {
@@ -54,12 +70,19 @@ export function testsDeNuit(racine) {
54
70
  process.stdout.write(`${e.message}\n`);
55
71
  return e.code;
56
72
  }
57
- const r = spawnSync(
58
- 'npx',
59
- ['--no-install', 'vitest', 'run', '--root', racine, '--config', CONFIGURATION],
60
- { cwd: racine, stdio: 'inherit' }
61
- );
62
- return r.status ?? 1;
73
+ const codes = runs.map(choix => {
74
+ const r = spawnSync(
75
+ 'npx',
76
+ ['--no-install', 'vitest', 'run', '--root', racine, '--config', CONFIGURATION],
77
+ { cwd: racine, stdio: 'inherit', env: { ...process.env, [NUIT_VARIABLE]: choix } }
78
+ );
79
+ return r.status ?? 1;
80
+ });
81
+ const rouges = codes.filter(c => c !== 0);
82
+ if (rouges.length === 0) {
83
+ return 0;
84
+ }
85
+ return rouges.every(c => c === A_REPASSER) ? A_REPASSER : rouges.find(c => c !== A_REPASSER);
63
86
  }
64
87
 
65
88
  if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
@@ -89,13 +89,16 @@ import {
89
89
  ouvrirBase,
90
90
  paquetsDeLEnveloppe,
91
91
  retirerALInterruption,
92
+ SCRIPT_DES_TESTS,
93
+ surUnePlace,
94
+ TESTS_CIBLES,
95
+ testsCibles,
96
+ tracesDuPlan,
92
97
  } from '../../services-du-noyau.mjs';
93
98
  import { paquets } from '../../paquets.mjs';
94
99
  import { garderLesResumes } from './verdict.mjs';
95
100
  import { RESULTATS } from '../../resultats.mjs';
96
- import { planifier, tracesDuPlan } from './turbo-des-paquets.mjs';
97
- import { SCRIPT_DES_TESTS } from './script-des-tests.mjs';
98
- import { VARIABLE } from './vitest-config/cibles.mjs';
101
+ import { horsTypescript, planifier } from './turbo-des-paquets.mjs';
99
102
 
100
103
  const racine = process.cwd();
101
104
  // The base of the run (scripts/mesure/base-de-passe.mjs): this process and every run of
@@ -118,10 +121,10 @@ if (depuis) process.stdout.write(`${depuis.ligne}\n`);
118
121
  // (RESULTATS), Turborepo writes its summary, which goes there.
119
122
  const turbo = (args, tests) => {
120
123
  const env = { ...process.env };
121
- delete env[VARIABLE];
124
+ delete env[TESTS_CIBLES];
122
125
  delete env[CHANGEMENTS];
123
126
  Object.assign(env, depuis?.env ?? {});
124
- if (tests) env[VARIABLE] = JSON.stringify(tests);
127
+ if (tests) env[TESTS_CIBLES] = JSON.stringify(tests);
125
128
  const resume = env[RESULTATS] ? ['--summarize'] : [];
126
129
  const runs = path.join(racine, '.turbo', 'runs');
127
130
  const avant = new Set(existsSync(runs) ? readdirSync(runs) : []);
@@ -162,7 +165,8 @@ const traces = (filtres, noms) => {
162
165
  // in an envelope, the build of the packages they name with their own traces, then the tests alone.
163
166
  // Its exit code: the first that is not 0, else the tests'.
164
167
  const cibles = (filtres, passes) => {
165
- const tests = { arguments: passes, ...(force ? { rejouer: new Date().toISOString() } : {}) };
168
+ // `testsCibles` is undefined with no path and no `--force`: the variable then stays unset.
169
+ const tests = testsCibles({ arguments: passes, force });
166
170
  if (!enveloppe) return turbo([SCRIPT_DES_TESTS, ...filtres], tests);
167
171
  // A package the envelope shows read-only arrives built: only the packages it shows in writing
168
172
  // build, as the envelope mounts them (`inscriptible`).
@@ -195,7 +199,7 @@ const dossiers = new Map(liste.map(p => [p.pkg.name, path.join(racine, p.dossier
195
199
  const lancer = () => {
196
200
  if (chemins.length === 0) {
197
201
  return turbo(
198
- [SCRIPT_DES_TESTS, ...(force ? ['--force'] : [])],
202
+ [SCRIPT_DES_TESTS, ...horsTypescript(racine), ...(force ? ['--force'] : [])],
199
203
  options.length ? { arguments: options } : undefined
200
204
  );
201
205
  }
@@ -239,7 +243,12 @@ const lancer = () => {
239
243
  };
240
244
 
241
245
  try {
242
- process.exitCode = lancer();
246
+ // The run takes a place of the machine (scripts/places-de-la-machine.mjs), whose mark every run
247
+ // of Turborepo carries to its tasks.
248
+ process.exitCode = surUnePlace(env => {
249
+ Object.assign(process.env, env);
250
+ return lancer();
251
+ });
243
252
  } finally {
244
253
  lacher();
245
254
  depuis?.retirer();
@@ -0,0 +1,297 @@
1
+ #!/usr/bin/env node
2
+ // The title of a test, on the model of Software Engineering at Google (ch. 12: « write a test for
3
+ // each behavior »): a test bears the name of the behavior it proves, never a ticket's or a
4
+ // « critère N »; a test whose title does not say its behavior ends deleted. The ticket goes to the
5
+ // commit message.
6
+ //
7
+ // npx grillhouse titres-de-tests run from the repository root (a guard of grillhouse:gardes)
8
+ //
9
+ // - The count is a union: a title counts once if it names a ticket of the project (its prefix, read
10
+ // from the key `issue-prefix` of `.beads/config.yaml`, committed, never by `bd`, which a CI does
11
+ // not have; the guard names the file or the key when it is missing), followed by an
12
+ // identifier: `grillhouse-44b.10.8`) or a « critère N » (or « critères N »), or both.
13
+ // - The guard reads the Vitest tests of the project (the files `*.test.*` and `*.spec.*` of every
14
+ // component, the night tests included, as ./tailles-des-tests.mjs lists them): the calls
15
+ // `describe`, `it` and `test` and their variants (`skip`, `only`, `each`, `todo`...). It sees the
16
+ // static text of a title: a literal, the fixed parts of a template, the format of an `each`. A
17
+ // title carried by a variable is not seen, nor a title in a comment.
18
+ // - The Rust and Python tests are out of the count: their titles are function names, without
19
+ // `describe` or `it` (a deviation written here and in each refusal).
20
+ // - A finding is `{ fichier, ligne, regle: 'titre-nommant-un-ticket', message }`. The debt
21
+ // (`grillhouse-dette.json`, ../../dette.mjs) counts them file by file: a file whose count rises
22
+ // above its debt, or absent from the debt with a title counted, is refused by its name; a debt
23
+ // above the real count is refused too, so that the lot lowers it by `npm run
24
+ // grillhouse:dette:elaguer`. A test file moved or renamed by the lot, its content kept (or
25
+ // nearly), takes the debt of its former name (`renommesDuLot`).
26
+ import { spawnSync } from 'node:child_process';
27
+ import { readFileSync, writeFileSync } from 'node:fs';
28
+ import path from 'node:path';
29
+ import { pathToFileURL } from 'node:url';
30
+ import { FICHIER, lire as lireDette, trancher } from '../../dette.mjs';
31
+ import { A_ELAGUER, ecrireSarif } from '../../resultats.mjs';
32
+ import { prefixe } from '../../services-du-noyau.mjs';
33
+ import { testsDuDepot } from './tailles-des-tests.mjs';
34
+ import { TEST } from './vitest-config/lances.mjs';
35
+
36
+ export const GARDE = 'titres-de-tests';
37
+ export const REGLE = 'titre-nommant-un-ticket';
38
+
39
+ const escape = s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
40
+ const CRITERE = /(?<!\p{L})crit[èe]res?\s+\d/iu;
41
+ // The calls that carry a title: describe, it, test, a chain of variants, the arguments of an `each`
42
+ // when there are some, then the opening quote of the title.
43
+ const APPEL =
44
+ /(?<![\w$.])(?:describe|it|test)(?:\s*\.\s*(?:skip|only|todo|concurrent|sequential|fails|runIf|skipIf|each|for))*\s*(?:\([^()]*(?:\([^()]*\)[^()]*)*\)\s*)?\(\s*(['"`])/g;
45
+
46
+ // <texte> with its comments blanked (the newlines kept), the strings left as they are.
47
+ function sansCommentaires(texte) {
48
+ let out = '';
49
+ let i = 0;
50
+ while (i < texte.length) {
51
+ const c = texte[i];
52
+ const d = texte[i + 1];
53
+ if (c === '/' && d === '/') {
54
+ while (i < texte.length && texte[i] !== '\n') {
55
+ out += ' ';
56
+ i++;
57
+ }
58
+ } else if (c === '/' && d === '*') {
59
+ const fin = texte.indexOf('*/', i + 2);
60
+ const stop = fin === -1 ? texte.length : fin + 2;
61
+ out += texte.slice(i, stop).replace(/[^\n]/g, ' ');
62
+ i = stop;
63
+ } else if (c === "'" || c === '"' || c === '`') {
64
+ let j = i + 1;
65
+ while (j < texte.length && texte[j] !== c && !(c !== '`' && texte[j] === '\n')) {
66
+ j += texte[j] === '\\' ? 2 : 1;
67
+ }
68
+ out += texte.slice(i, j + 1);
69
+ i = j + 1;
70
+ } else {
71
+ out += c;
72
+ i++;
73
+ }
74
+ }
75
+ return out;
76
+ }
77
+
78
+ // The static text of the literal opened by the quote at <debut> of <texte>: the fixed parts of a
79
+ // template, its `${…}` left out.
80
+ function litteral(texte, debut) {
81
+ const guillemet = texte[debut];
82
+ let titre = '';
83
+ let i = debut + 1;
84
+ while (i < texte.length && texte[i] !== guillemet) {
85
+ if (texte[i] === '\\') {
86
+ titre += texte[i + 1] ?? '';
87
+ i += 2;
88
+ } else if (guillemet === '`' && texte[i] === '$' && texte[i + 1] === '{') {
89
+ let profondeur = 0;
90
+ do {
91
+ if (texte[i] === '{') profondeur++;
92
+ else if (texte[i] === '}') profondeur--;
93
+ i++;
94
+ } while (i < texte.length && profondeur > 0);
95
+ titre += ' ';
96
+ } else {
97
+ titre += texte[i++];
98
+ }
99
+ }
100
+ return titre;
101
+ }
102
+
103
+ /**
104
+ * The titles of <texte> (a Vitest file) that name a ticket of the prefix <prefixe> or a
105
+ * « critère N »: `[{ titre, ligne }]`, each title once, `ligne` 1-based.
106
+ */
107
+ export function titresNommantUnTicket(texte, prefixe) {
108
+ const ticket = prefixe
109
+ ? new RegExp(`(?<![\\w.-])${escape(prefixe)}-[a-z0-9]+(?:\\.[0-9]+)*(?![\\w-])`, 'i')
110
+ : null;
111
+ const propre = sansCommentaires(texte);
112
+ const out = [];
113
+ for (const m of propre.matchAll(APPEL)) {
114
+ const debut = m.index + m[0].length - 1;
115
+ const titre = litteral(propre, debut);
116
+ if (CRITERE.test(titre) || ticket?.test(titre)) {
117
+ out.push({ titre, ligne: propre.slice(0, debut).split('\n').length });
118
+ }
119
+ }
120
+ return out;
121
+ }
122
+
123
+ const MESSAGE_FIN =
124
+ "nomme le test par le comportement qu'il prouve, jamais par un ticket ni un « critère N » : le ticket va au message du commit. Les tests Rust et Python sont hors du compte (leurs titres sont des noms de fonction, sans describe ni it).";
125
+
126
+ /**
127
+ * The findings of the repository at <racine>, the prefix of the tickets <prefixe>: one
128
+ * `{ fichier, ligne, regle, message }` per title of a Vitest file that names a ticket or a
129
+ * « critère N ».
130
+ */
131
+ export function verifier(racine, prefixe) {
132
+ return testsDuDepot(racine).flatMap(fichier => {
133
+ let texte;
134
+ try {
135
+ texte = readFileSync(path.join(racine, fichier), 'utf8');
136
+ } catch {
137
+ return [];
138
+ }
139
+ return titresNommantUnTicket(texte, prefixe).map(({ titre, ligne }) => ({
140
+ fichier,
141
+ ligne,
142
+ regle: REGLE,
143
+ message: `${fichier}:${ligne} : le titre « ${titre.trim()} » nomme un ticket ou un « critère N » ; ${MESSAGE_FIN}`,
144
+ }));
145
+ });
146
+ }
147
+
148
+ const git = (racine, args) =>
149
+ spawnSync('git', ['-C', racine, ...args], { encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 });
150
+
151
+ // The share of the lines of <a> that <b> keeps, over the lines of both (0 to 1).
152
+ function ressemblance(a, b) {
153
+ const la = new Set(a.split('\n'));
154
+ const lb = new Set(b.split('\n'));
155
+ let commun = 0;
156
+ for (const l of la) if (lb.has(l)) commun++;
157
+ return commun / (la.size + lb.size - commun || 1);
158
+ }
159
+
160
+ /**
161
+ * The test files the lot of the working copy at <racine> moves or renames, against HEAD:
162
+ * `{ nouveau: ancien }`. The index is not read: a file deleted and a file added, of the same
163
+ * content (or nearly, at least half of the lines kept), are one rename.
164
+ */
165
+ export function renommesDuLot(racine) {
166
+ const supprimes = git(racine, ['diff', 'HEAD', '--name-only', '--diff-filter=D', '-z']);
167
+ const connus = git(racine, ['ls-tree', '-r', '--name-only', 'HEAD', '-z']);
168
+ if (supprimes.status !== 0 || connus.status !== 0) return {};
169
+ const anciens = supprimes.stdout.split('\0').filter(f => f && TEST.test(f));
170
+ const avant = new Set(connus.stdout.split('\0'));
171
+ const nouveaux = testsDuDepot(racine).filter(f => !avant.has(f));
172
+ const textesAnciens = new Map(
173
+ anciens.map(f => [f, git(racine, ['show', `HEAD:${f}`]).stdout ?? ''])
174
+ );
175
+ const out = {};
176
+ const pris = new Set();
177
+ const paires = nouveaux.flatMap(n => {
178
+ let texte;
179
+ try {
180
+ texte = readFileSync(path.join(racine, n), 'utf8');
181
+ } catch {
182
+ return [];
183
+ }
184
+ return anciens.map(a => ({ n, a, s: ressemblance(texte, textesAnciens.get(a)) }));
185
+ });
186
+ for (const { n, a, s } of paires.filter(p => p.s >= 0.5).sort((x, y) => y.s - x.s)) {
187
+ if (out[n] || pris.has(a)) continue;
188
+ out[n] = a;
189
+ pris.add(a);
190
+ }
191
+ return out;
192
+ }
193
+
194
+ /**
195
+ * The refusals of the findings <constats> against the <dette> read from the file: one
196
+ * `{ fichier, message }` per file whose count rises above its debt (a file absent from the debt
197
+ * has none) and per file whose debt stays above its count. <renommes> (`{ nouveau: ancien }`)
198
+ * gives a file moved or renamed the debt of its former name.
199
+ */
200
+ export function jugerLesTitres(dette, constats, renommes = {}) {
201
+ const inscrite = dette?.[GARDE] ?? {};
202
+ const permis = f => inscrite[f]?.[REGLE]?.count ?? 0;
203
+ const comptes = new Map();
204
+ for (const c of constats) comptes.set(c.fichier, (comptes.get(c.fichier) ?? 0) + 1);
205
+ const reprises = new Set(Object.values(renommes));
206
+ const refus = [];
207
+ for (const [fichier, trouve] of comptes) {
208
+ const droit = permis(fichier) + (renommes[fichier] ? permis(renommes[fichier]) : 0);
209
+ if (trouve > droit) {
210
+ refus.push({
211
+ fichier,
212
+ regle: REGLE,
213
+ message: `${fichier} : ${trouve} titre(s) nomment un ticket ou un « critère N » pour ${droit} inscrit(s) dans ${FICHIER} : ${MESSAGE_FIN}`,
214
+ });
215
+ } else if (trouve < droit) {
216
+ refus.push({
217
+ fichier,
218
+ regle: REGLE,
219
+ aElaguer: true,
220
+ trouve,
221
+ message: `${fichier} : ${trouve} titre(s) pour ${droit} inscrit(s) dans ${FICHIER} : la dette s'abaisse (npm run grillhouse:dette:elaguer), jamais à la main. ${MESSAGE_FIN}`,
222
+ });
223
+ }
224
+ }
225
+ for (const fichier of Object.keys(inscrite)) {
226
+ if (comptes.has(fichier) || reprises.has(fichier) || !permis(fichier)) continue;
227
+ refus.push({
228
+ fichier,
229
+ regle: REGLE,
230
+ aElaguer: true,
231
+ trouve: 0,
232
+ message: `${fichier} : aucun titre ne nomme plus un ticket ou un « critère N », pour ${permis(fichier)} inscrit(s) dans ${FICHIER} : la dette s'abaisse (npm run grillhouse:dette:elaguer), jamais à la main. ${MESSAGE_FIN}`,
233
+ });
234
+ }
235
+ return refus.sort((a, b) => (a.fichier < b.fichier ? -1 : a.fichier > b.fichier ? 1 : 0));
236
+ }
237
+
238
+ function main() {
239
+ const racine = process.cwd();
240
+ let pref;
241
+ try {
242
+ pref = prefixe(racine);
243
+ } catch (e) {
244
+ process.stderr.write(`⛔ ${e.message}\n`);
245
+ process.exitCode = 1;
246
+ return;
247
+ }
248
+ const constats = verifier(racine, pref);
249
+ const renommes = renommesDuLot(racine);
250
+ let refus;
251
+ let lignes = [];
252
+ if (process.env.GRILLHOUSE_DETTE) {
253
+ // A write of the debt (`inscrire`, `elaguer`): a file moved takes the debt of its former name
254
+ // first, so that the write keeps it.
255
+ const dette = lireDette(racine);
256
+ const section = dette[GARDE];
257
+ if (section) {
258
+ for (const [nouveau, ancien] of Object.entries(renommes)) {
259
+ if (section[ancien] && !section[nouveau]) section[nouveau] = section[ancien];
260
+ delete section[ancien];
261
+ }
262
+ writeFileSync(path.join(racine, FICHIER), `${JSON.stringify(dette, null, 2)}\n`);
263
+ }
264
+ const r = trancher(racine, GARDE, constats);
265
+ refus = r.refus;
266
+ lignes = r.lignes;
267
+ } else {
268
+ refus = jugerLesTitres(lireDette(racine), constats, renommes);
269
+ // Each refusal is a finding in SARIF; a debt above the count is also a note `a-elaguer`, by
270
+ // which the circuit lowers the debt d'office.
271
+ ecrireSarif({
272
+ garde: GARDE,
273
+ racine,
274
+ constats: [
275
+ ...refus.map(r => ({ fichier: r.fichier, regle: r.regle, message: r.message })),
276
+ ...refus
277
+ .filter(r => r.aElaguer)
278
+ .map(r => ({
279
+ fichier: r.fichier,
280
+ regle: r.regle,
281
+ niveau: 'note',
282
+ genre: A_ELAGUER,
283
+ trouve: r.trouve,
284
+ message: `${r.trouve} constat(s) pour une dette plus haute : la dette s'abaisse.`,
285
+ })),
286
+ ],
287
+ });
288
+ }
289
+ for (const r of refus) process.stderr.write(`⛔ ${r.message}\n`);
290
+ for (const l of lignes) process.stderr.write(`${l}\n`);
291
+ process.stderr.write(
292
+ `ℹ️ ${GARDE} : ${constats.length} titre(s) nommant un ticket ou un « critère N » ; les tests Rust et Python sont hors du compte.\n`
293
+ );
294
+ process.exitCode = refus.length ? 1 : 0;
295
+ }
296
+
297
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) main();