@roomi-fields/grillhouse 0.29.0 → 0.31.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 (263) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +769 -0
  3. package/agents/developpeur.md +0 -1
  4. package/agents/explorateur.md +0 -1
  5. package/agents/questionneur.md +0 -1
  6. package/agents/testwriter.md +0 -1
  7. package/bin/grillhouse.mjs +79 -18
  8. package/cadre/templates/projet/.github/workflows/ci.yml +2 -13
  9. package/cadre/templates/projet/CLAUDE.md +5 -1
  10. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  11. package/cadre/templates/projet/package.json +2 -2
  12. package/charte.md +24 -0
  13. package/dist/temporal/acte.d.ts +24 -0
  14. package/dist/temporal/acte.js +139 -0
  15. package/dist/temporal/acte.js.map +1 -0
  16. package/dist/temporal/attributs.d.ts +6 -0
  17. package/dist/temporal/attributs.js +15 -0
  18. package/dist/temporal/attributs.js.map +1 -0
  19. package/dist/temporal/circuit/activites.d.ts +13 -0
  20. package/dist/temporal/circuit/activites.js +33 -0
  21. package/dist/temporal/circuit/activites.js.map +1 -0
  22. package/dist/temporal/circuit/client.d.ts +72 -0
  23. package/dist/temporal/circuit/client.js +247 -0
  24. package/dist/temporal/circuit/client.js.map +1 -0
  25. package/dist/temporal/circuit/commande.d.ts +2 -0
  26. package/dist/temporal/circuit/commande.js +238 -0
  27. package/dist/temporal/circuit/commande.js.map +1 -0
  28. package/dist/temporal/circuit/contrat.d.ts +305 -0
  29. package/dist/temporal/circuit/contrat.js +30 -0
  30. package/dist/temporal/circuit/contrat.js.map +1 -0
  31. package/dist/temporal/circuit/deroule.d.ts +3 -0
  32. package/dist/temporal/circuit/deroule.js +540 -0
  33. package/dist/temporal/circuit/deroule.js.map +1 -0
  34. package/dist/temporal/client.d.ts +47 -0
  35. package/dist/temporal/client.js +69 -0
  36. package/dist/temporal/client.js.map +1 -0
  37. package/dist/temporal/commande.d.ts +2 -0
  38. package/dist/temporal/commande.js +94 -0
  39. package/dist/temporal/commande.js.map +1 -0
  40. package/dist/temporal/deroules.d.ts +5 -0
  41. package/dist/temporal/deroules.js +10 -0
  42. package/dist/temporal/deroules.js.map +1 -0
  43. package/dist/temporal/etat.d.ts +33 -0
  44. package/dist/temporal/etat.js +59 -0
  45. package/dist/temporal/etat.js.map +1 -0
  46. package/dist/temporal/file/activites.d.ts +10 -0
  47. package/dist/temporal/file/activites.js +25 -0
  48. package/dist/temporal/file/activites.js.map +1 -0
  49. package/dist/temporal/file/client.d.ts +4 -0
  50. package/dist/temporal/file/client.js +6 -0
  51. package/dist/temporal/file/client.js.map +1 -0
  52. package/dist/temporal/file/contrat.d.ts +158 -0
  53. package/dist/temporal/file/contrat.js +14 -0
  54. package/dist/temporal/file/contrat.js.map +1 -0
  55. package/dist/temporal/file/deroule.d.ts +15 -0
  56. package/dist/temporal/file/deroule.js +235 -0
  57. package/dist/temporal/file/deroule.js.map +1 -0
  58. package/dist/temporal/installation.d.ts +120 -0
  59. package/dist/temporal/installation.js +386 -0
  60. package/dist/temporal/installation.js.map +1 -0
  61. package/dist/temporal/places/activites.d.ts +8 -0
  62. package/dist/temporal/places/activites.js +13 -0
  63. package/dist/temporal/places/activites.js.map +1 -0
  64. package/dist/temporal/places/client.d.ts +28 -0
  65. package/dist/temporal/places/client.js +64 -0
  66. package/dist/temporal/places/client.js.map +1 -0
  67. package/dist/temporal/places/contrat.d.ts +106 -0
  68. package/dist/temporal/places/contrat.js +21 -0
  69. package/dist/temporal/places/contrat.js.map +1 -0
  70. package/dist/temporal/places/deroule.d.ts +3 -0
  71. package/dist/temporal/places/deroule.js +198 -0
  72. package/dist/temporal/places/deroule.js.map +1 -0
  73. package/dist/temporal/sonde/activites.d.ts +6 -0
  74. package/dist/temporal/sonde/activites.js +52 -0
  75. package/dist/temporal/sonde/activites.js.map +1 -0
  76. package/dist/temporal/sonde/contrat.d.ts +35 -0
  77. package/dist/temporal/sonde/contrat.js +10 -0
  78. package/dist/temporal/sonde/contrat.js.map +1 -0
  79. package/dist/temporal/sonde/deroule.d.ts +3 -0
  80. package/dist/temporal/sonde/deroule.js +39 -0
  81. package/dist/temporal/sonde/deroule.js.map +1 -0
  82. package/dist/temporal/tickets/activites.d.ts +7 -0
  83. package/dist/temporal/tickets/activites.js +81 -0
  84. package/dist/temporal/tickets/activites.js.map +1 -0
  85. package/dist/temporal/tickets/client.d.ts +10 -0
  86. package/dist/temporal/tickets/client.js +31 -0
  87. package/dist/temporal/tickets/client.js.map +1 -0
  88. package/dist/temporal/tickets/contrat.d.ts +56 -0
  89. package/dist/temporal/tickets/contrat.js +13 -0
  90. package/dist/temporal/tickets/contrat.js.map +1 -0
  91. package/dist/temporal/tickets/deroule.d.ts +3 -0
  92. package/dist/temporal/tickets/deroule.js +94 -0
  93. package/dist/temporal/tickets/deroule.js.map +1 -0
  94. package/dist/temporal/travailleur.d.ts +2 -0
  95. package/dist/temporal/travailleur.js +69 -0
  96. package/dist/temporal/travailleur.js.map +1 -0
  97. package/docs/ARCHITECTURE.md +646 -87
  98. package/docs/CADRE.md +27 -0
  99. package/docs/INTERFACE.md +139 -42
  100. package/hooks/crochet.mjs +19 -2
  101. package/hooks/hooks.json +11 -0
  102. package/package.json +16 -4
  103. package/scripts/activites.mjs +2255 -0
  104. package/scripts/aiguillage.d.mts +37 -0
  105. package/scripts/aiguillage.mjs +40 -14
  106. package/scripts/avancement.mjs +155 -26
  107. package/scripts/bilan.mjs +137 -43
  108. package/scripts/cadre.mjs +16 -4
  109. package/scripts/circuit.mjs +993 -4075
  110. package/scripts/circuits-cles.d.mts +4 -0
  111. package/scripts/circuits-cles.mjs +21 -0
  112. package/scripts/circuits-du-serveur.mjs +105 -0
  113. package/scripts/codes-de-sortie.mjs +9 -0
  114. package/scripts/commandes-composees.mjs +45 -41
  115. package/scripts/commandes-du-path.d.mts +7 -0
  116. package/scripts/commandes-du-path.mjs +25 -0
  117. package/scripts/composants-affectes.mjs +64 -21
  118. package/scripts/composition-des-langages.mjs +18 -12
  119. package/scripts/conformite.mjs +56 -28
  120. package/scripts/copies-finies.mjs +52 -47
  121. package/scripts/depart-du-ticket.d.mts +53 -0
  122. package/scripts/depart-du-ticket.mjs +124 -0
  123. package/scripts/dependances-internes.mjs +121 -0
  124. package/scripts/dernier-vert.mjs +61 -34
  125. package/scripts/dette.mjs +32 -11
  126. package/scripts/donnees-cles.mjs +244 -0
  127. package/scripts/droits.mjs +51 -16
  128. package/scripts/effets.mjs +352 -0
  129. package/scripts/empreinte-d-etape.mjs +17 -0
  130. package/scripts/engendres.mjs +15 -5
  131. package/scripts/enveloppe/enveloppe.mjs +259 -55
  132. package/scripts/enveloppe/lancer.sh +14 -18
  133. package/scripts/enveloppe/paquets-du-plan.mjs +2 -2
  134. package/scripts/enveloppe/travail-de-la-copie.mjs +41 -13
  135. package/scripts/etapes.mjs +5 -2
  136. package/scripts/faits-du-circuit.mjs +493 -0
  137. package/scripts/file-des-tickets.d.mts +21 -0
  138. package/scripts/file-des-tickets.mjs +58 -0
  139. package/scripts/flux-des-paquets.mjs +201 -0
  140. package/scripts/gardes-du-cadre.mjs +21 -5
  141. package/scripts/init.mjs +11 -4
  142. package/scripts/integration/file.mjs +544 -434
  143. package/scripts/integration/integrer.mjs +87 -43
  144. package/scripts/integration/rejeu.mjs +45 -13
  145. package/scripts/jointure.d.ts +151 -28
  146. package/scripts/langages/cargo/commandes.mjs +383 -124
  147. package/scripts/langages/cargo/composants.mjs +154 -42
  148. package/scripts/langages/cargo/exemples.mjs +12 -21
  149. package/scripts/langages/cargo/index.mjs +22 -8
  150. package/scripts/langages/cargo/sccache.mjs +8 -14
  151. package/scripts/langages/cargo/tests-de-head.mjs +25 -9
  152. package/scripts/langages/python/commandes.mjs +218 -100
  153. package/scripts/langages/python/composants.mjs +53 -21
  154. package/scripts/langages/python/exemples.mjs +6 -16
  155. package/scripts/langages/python/index.mjs +28 -8
  156. package/scripts/langages/python/lot.mjs +1 -36
  157. package/scripts/langages/typescript/chemins-des-tests.mjs +6 -2
  158. package/scripts/langages/typescript/composants.mjs +9 -3
  159. package/scripts/langages/typescript/consommateurs-arbitres.mjs +40 -14
  160. package/scripts/langages/typescript/consommateurs.mjs +39 -14
  161. package/scripts/langages/typescript/construire.mjs +6 -163
  162. package/scripts/langages/typescript/elements-du-lot.mjs +36 -12
  163. package/scripts/langages/typescript/exemples.mjs +3 -11
  164. package/scripts/langages/typescript/frontieres.mjs +66 -22
  165. package/scripts/langages/typescript/index-interfaces.mjs +36 -13
  166. package/scripts/langages/typescript/index.mjs +50 -61
  167. package/scripts/langages/typescript/interfaces-contre-code.mjs +113 -45
  168. package/scripts/langages/typescript/lecteurs.mjs +36 -11
  169. package/scripts/langages/typescript/migrations/0.23.0-config-vitest.mjs +15 -5
  170. package/scripts/langages/typescript/migrations/0.25.0-chemins-des-tests.mjs +6 -2
  171. package/scripts/langages/typescript/migrations/0.25.0-tailles-des-tests.mjs +6 -2
  172. package/scripts/langages/typescript/migrations/0.30.0-prefixe-des-tickets.mjs +63 -0
  173. package/scripts/langages/typescript/migrations/0.30.0-tailles-des-outils-lourds.mjs +33 -0
  174. package/scripts/langages/typescript/migrations/0.30.0-titres-nommant-un-ticket.mjs +40 -0
  175. package/scripts/langages/typescript/mise-a-jour.mjs +1 -2
  176. package/scripts/langages/typescript/parcours.mjs +12 -4
  177. package/scripts/langages/typescript/regle-des-tests.mjs +9 -3
  178. package/scripts/langages/typescript/resumes.mjs +9 -3
  179. package/scripts/langages/typescript/tailles-des-tests.mjs +93 -20
  180. package/scripts/langages/typescript/tests-de-nuit.mjs +15 -10
  181. package/scripts/langages/typescript/tests.mjs +40 -15
  182. package/scripts/langages/typescript/titres-de-tests.mjs +320 -0
  183. package/scripts/langages/typescript/turbo-des-paquets.mjs +327 -81
  184. package/scripts/langages/typescript/verdict.mjs +4 -2
  185. package/scripts/langages/typescript/verifier.mjs +58 -20
  186. package/scripts/langages/typescript/vitest-config/avancement.reporter.mjs +15 -5
  187. package/scripts/langages/typescript/vitest-config/base.mjs +29 -3
  188. package/scripts/langages/typescript/vitest-config/bornes.mjs +13 -0
  189. package/scripts/langages/typescript/vitest-config/changements.mjs +21 -8
  190. package/scripts/langages/typescript/vitest-config/cibles.mjs +36 -14
  191. package/scripts/langages/typescript/vitest-config/delais.mjs +60 -0
  192. package/scripts/langages/typescript/vitest-config/delais.setup.mjs +11 -0
  193. package/scripts/langages/typescript/vitest-config/duree.classement.mjs +108 -0
  194. package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +56 -59
  195. package/scripts/langages/typescript/vitest-config/lances.mjs +83 -27
  196. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +10 -0
  197. package/scripts/langages/typescript/vitest-config/resultats.mjs +3 -1
  198. package/scripts/langages/typescript/vitest.nuit.config.mjs +4 -0
  199. package/scripts/lint-des-scripts.mjs +58 -0
  200. package/scripts/mesure/base-de-passe.mjs +117 -25
  201. package/scripts/mesure/pression.mjs +12 -6
  202. package/scripts/mesure-de-la-machine.d.mts +21 -0
  203. package/scripts/mesure-de-la-machine.mjs +76 -0
  204. package/scripts/migrations/0.23.0-charte-importee.mjs +6 -2
  205. package/scripts/migrations/0.23.0-crochets-de-seance.mjs +25 -8
  206. package/scripts/migrations/0.23.0-marche-du-projet.mjs +18 -6
  207. package/scripts/migrations/0.23.2-copies-du-cadre.mjs +56 -18
  208. package/scripts/migrations/0.24.12-tri-des-decouvertes.mjs +6 -2
  209. package/scripts/migrations/0.25.0-script-des-tests.mjs +15 -5
  210. package/scripts/migrations/0.30.0-ci-appelle-la-verification.mjs +124 -0
  211. package/scripts/migrations/0.31.0-paquets-dans-le-graphe.mjs +81 -0
  212. package/scripts/migrations.mjs +5 -0
  213. package/scripts/nuit.sh +25 -3
  214. package/scripts/outil.mjs +3 -1
  215. package/scripts/outils-cles.d.mts +24 -0
  216. package/scripts/outils-cles.mjs +18 -8
  217. package/scripts/paquet-npm.mjs +157 -0
  218. package/scripts/paquet.mjs +73 -4
  219. package/scripts/paquets.mjs +46 -10
  220. package/scripts/passe-de-la-machine.mjs +71 -0
  221. package/scripts/places-de-la-machine.mjs +414 -0
  222. package/scripts/places-du-serveur.mjs +170 -0
  223. package/scripts/prefixe-des-tickets.mjs +68 -0
  224. package/scripts/preparation.mjs +25 -8
  225. package/scripts/registre.mjs +9 -4
  226. package/scripts/regles-des-places.d.mts +36 -0
  227. package/scripts/regles-des-places.mjs +70 -0
  228. package/scripts/reponses-du-circuit.d.mts +6 -0
  229. package/scripts/reponses-du-circuit.mjs +28 -0
  230. package/scripts/reprise.mjs +66 -0
  231. package/scripts/resultats.mjs +112 -46
  232. package/scripts/retirer-les-copies-finies.mjs +25 -0
  233. package/scripts/sans-reponse.d.mts +4 -0
  234. package/scripts/sans-reponse.mjs +13 -0
  235. package/scripts/seances.mjs +936 -0
  236. package/scripts/services-du-noyau.mjs +27 -8
  237. package/scripts/session-start.sh +2 -2
  238. package/scripts/sortie.mjs +3 -3
  239. package/scripts/sous-commandes.mjs +41 -10
  240. package/scripts/style-a-l-ecriture.mjs +260 -0
  241. package/scripts/superviseur.mjs +122 -111
  242. package/scripts/tableau.mjs +180 -117
  243. package/scripts/taches-du-graphe.mjs +348 -0
  244. package/scripts/ticket-du-circuit.mjs +216 -0
  245. package/scripts/transitions.d.mts +148 -0
  246. package/scripts/transitions.mjs +1018 -0
  247. package/scripts/verrou-de-fichier.mjs +8 -4
  248. package/scripts/verrou-de-machine.mjs +150 -51
  249. package/scripts/verrous/commande.mjs +50 -17
  250. package/scripts/verrous/ticket-du-sous-agent.mjs +9 -3
  251. package/scripts/verrous/verrou.mjs +42 -14
  252. package/skills/explorateur/SKILL.md +9 -2
  253. package/skills/grill/SKILL.md +1 -1
  254. package/skills/mesure/SKILL.md +3 -0
  255. package/skills/pitmaster/SKILL.md +17 -18
  256. package/skills/pitmaster/references/consigne-agent.md +5 -1
  257. package/skills/release/SKILL.md +3 -3
  258. package/skills/relecteur/SKILL.md +5 -3
  259. package/skills/testwriter/SKILL.md +49 -31
  260. package/scripts/demon.mjs +0 -251
  261. package/scripts/integration/file-attente.mjs +0 -61
  262. package/scripts/langages/cargo/touches.mjs +0 -93
  263. package/scripts/langages/typescript/script-des-tests.mjs +0 -6
@@ -0,0 +1,320 @@
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] === '{') {
92
+ profondeur++;
93
+ } else if (texte[i] === '}') {
94
+ profondeur--;
95
+ }
96
+ i++;
97
+ } while (i < texte.length && profondeur > 0);
98
+ titre += ' ';
99
+ } else {
100
+ titre += texte[i++];
101
+ }
102
+ }
103
+ return titre;
104
+ }
105
+
106
+ /**
107
+ * The titles of <texte> (a Vitest file) that name a ticket of the prefix <prefixe> or a
108
+ * « critère N »: `[{ titre, ligne }]`, each title once, `ligne` 1-based.
109
+ */
110
+ export function titresNommantUnTicket(texte, prefixe) {
111
+ const ticket = prefixe
112
+ ? new RegExp(`(?<![\\w.-])${escape(prefixe)}-[a-z0-9]+(?:\\.[0-9]+)*(?![\\w-])`, 'i')
113
+ : null;
114
+ const propre = sansCommentaires(texte);
115
+ const out = [];
116
+ for (const m of propre.matchAll(APPEL)) {
117
+ const debut = m.index + m[0].length - 1;
118
+ const titre = litteral(propre, debut);
119
+ if (CRITERE.test(titre) || ticket?.test(titre)) {
120
+ out.push({ titre, ligne: propre.slice(0, debut).split('\n').length });
121
+ }
122
+ }
123
+ return out;
124
+ }
125
+
126
+ const MESSAGE_FIN =
127
+ "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).";
128
+
129
+ /**
130
+ * The findings of the repository at <racine>, the prefix of the tickets <prefixe>: one
131
+ * `{ fichier, ligne, regle, message }` per title of a Vitest file that names a ticket or a
132
+ * « critère N ».
133
+ */
134
+ export function verifier(racine, prefixe) {
135
+ return testsDuDepot(racine).flatMap(fichier => {
136
+ let texte;
137
+ try {
138
+ texte = readFileSync(path.join(racine, fichier), 'utf8');
139
+ } catch {
140
+ return [];
141
+ }
142
+ return titresNommantUnTicket(texte, prefixe).map(({ titre, ligne }) => ({
143
+ fichier,
144
+ ligne,
145
+ regle: REGLE,
146
+ message: `${fichier}:${ligne} : le titre « ${titre.trim()} » nomme un ticket ou un « critère N » ; ${MESSAGE_FIN}`,
147
+ }));
148
+ });
149
+ }
150
+
151
+ const git = (racine, args) =>
152
+ spawnSync('git', ['-C', racine, ...args], { encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 });
153
+
154
+ // The share of the lines of <a> that <b> keeps, over the lines of both (0 to 1).
155
+ function ressemblance(a, b) {
156
+ const la = new Set(a.split('\n'));
157
+ const lb = new Set(b.split('\n'));
158
+ let commun = 0;
159
+ for (const l of la) {
160
+ if (lb.has(l)) {
161
+ commun++;
162
+ }
163
+ }
164
+ return commun / (la.size + lb.size - commun || 1);
165
+ }
166
+
167
+ /**
168
+ * The test files the lot of the working copy at <racine> moves or renames, against HEAD:
169
+ * `{ nouveau: ancien }`. The index is not read: a file deleted and a file added, of the same
170
+ * content (or nearly, at least half of the lines kept), are one rename.
171
+ */
172
+ export function renommesDuLot(racine) {
173
+ const supprimes = git(racine, ['diff', 'HEAD', '--name-only', '--diff-filter=D', '-z']);
174
+ const connus = git(racine, ['ls-tree', '-r', '--name-only', 'HEAD', '-z']);
175
+ if (supprimes.status !== 0 || connus.status !== 0) {
176
+ return {};
177
+ }
178
+ const anciens = supprimes.stdout.split('\0').filter(f => f && TEST.test(f));
179
+ const avant = new Set(connus.stdout.split('\0'));
180
+ const nouveaux = testsDuDepot(racine).filter(f => !avant.has(f));
181
+ const textesAnciens = new Map(
182
+ anciens.map(f => [f, git(racine, ['show', `HEAD:${f}`]).stdout ?? ''])
183
+ );
184
+ const out = {};
185
+ const pris = new Set();
186
+ const paires = nouveaux.flatMap(n => {
187
+ let texte;
188
+ try {
189
+ texte = readFileSync(path.join(racine, n), 'utf8');
190
+ } catch {
191
+ return [];
192
+ }
193
+ return anciens.map(a => ({ n, a, s: ressemblance(texte, textesAnciens.get(a)) }));
194
+ });
195
+ for (const { n, a } of paires.filter(p => p.s >= 0.5).sort((x, y) => y.s - x.s)) {
196
+ if (out[n] || pris.has(a)) {
197
+ continue;
198
+ }
199
+ out[n] = a;
200
+ pris.add(a);
201
+ }
202
+ return out;
203
+ }
204
+
205
+ /**
206
+ * The refusals of the findings <constats> against the <dette> read from the file: one
207
+ * `{ fichier, message }` per file whose count rises above its debt (a file absent from the debt
208
+ * has none) and per file whose debt stays above its count. <renommes> (`{ nouveau: ancien }`)
209
+ * gives a file moved or renamed the debt of its former name.
210
+ */
211
+ export function jugerLesTitres(dette, constats, renommes = {}) {
212
+ const inscrite = dette?.[GARDE] ?? {};
213
+ const permis = f => inscrite[f]?.[REGLE]?.count ?? 0;
214
+ const comptes = new Map();
215
+ for (const c of constats) {
216
+ comptes.set(c.fichier, (comptes.get(c.fichier) ?? 0) + 1);
217
+ }
218
+ const reprises = new Set(Object.values(renommes));
219
+ const refus = [];
220
+ for (const [fichier, trouve] of comptes) {
221
+ const droit = permis(fichier) + (renommes[fichier] ? permis(renommes[fichier]) : 0);
222
+ if (trouve > droit) {
223
+ refus.push({
224
+ fichier,
225
+ regle: REGLE,
226
+ message: `${fichier} : ${trouve} titre(s) nomment un ticket ou un « critère N » pour ${droit} inscrit(s) dans ${FICHIER} : ${MESSAGE_FIN}`,
227
+ });
228
+ } else if (trouve < droit) {
229
+ refus.push({
230
+ fichier,
231
+ regle: REGLE,
232
+ aElaguer: true,
233
+ trouve,
234
+ 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}`,
235
+ });
236
+ }
237
+ }
238
+ for (const fichier of Object.keys(inscrite)) {
239
+ if (comptes.has(fichier) || reprises.has(fichier) || !permis(fichier)) {
240
+ continue;
241
+ }
242
+ refus.push({
243
+ fichier,
244
+ regle: REGLE,
245
+ aElaguer: true,
246
+ trouve: 0,
247
+ 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}`,
248
+ });
249
+ }
250
+ return refus.sort((a, b) => (a.fichier < b.fichier ? -1 : a.fichier > b.fichier ? 1 : 0));
251
+ }
252
+
253
+ function main() {
254
+ const racine = process.cwd();
255
+ let pref;
256
+ try {
257
+ pref = prefixe(racine);
258
+ } catch (e) {
259
+ process.stderr.write(`⛔ ${e.message}\n`);
260
+ process.exitCode = 1;
261
+ return;
262
+ }
263
+ const constats = verifier(racine, pref);
264
+ const renommes = renommesDuLot(racine);
265
+ let refus;
266
+ let lignes = [];
267
+ if (process.env.GRILLHOUSE_DETTE) {
268
+ // A write of the debt (`inscrire`, `elaguer`): a file moved takes the debt of its former name
269
+ // first, so that the write keeps it.
270
+ const dette = lireDette(racine);
271
+ const section = dette[GARDE];
272
+ if (section) {
273
+ for (const [nouveau, ancien] of Object.entries(renommes)) {
274
+ if (section[ancien] && !section[nouveau]) {
275
+ section[nouveau] = section[ancien];
276
+ }
277
+ delete section[ancien];
278
+ }
279
+ writeFileSync(path.join(racine, FICHIER), `${JSON.stringify(dette, null, 2)}\n`);
280
+ }
281
+ const r = trancher(racine, GARDE, constats);
282
+ refus = r.refus;
283
+ lignes = r.lignes;
284
+ } else {
285
+ refus = jugerLesTitres(lireDette(racine), constats, renommes);
286
+ // Each refusal is a finding in SARIF; a debt above the count is also a note `a-elaguer`, by
287
+ // which the circuit lowers the debt d'office.
288
+ ecrireSarif({
289
+ garde: GARDE,
290
+ racine,
291
+ constats: [
292
+ ...refus.map(r => ({ fichier: r.fichier, regle: r.regle, message: r.message })),
293
+ ...refus
294
+ .filter(r => r.aElaguer)
295
+ .map(r => ({
296
+ fichier: r.fichier,
297
+ regle: r.regle,
298
+ niveau: 'note',
299
+ genre: A_ELAGUER,
300
+ trouve: r.trouve,
301
+ message: `${r.trouve} constat(s) pour une dette plus haute : la dette s'abaisse.`,
302
+ })),
303
+ ],
304
+ });
305
+ }
306
+ for (const r of refus) {
307
+ process.stderr.write(`⛔ ${r.message}\n`);
308
+ }
309
+ for (const l of lignes) {
310
+ process.stderr.write(`${l}\n`);
311
+ }
312
+ process.stderr.write(
313
+ `ℹ️ ${GARDE} : ${constats.length} titre(s) nommant un ticket ou un « critère N » ; les tests Rust et Python sont hors du compte.\n`
314
+ );
315
+ process.exitCode = refus.length ? 1 : 0;
316
+ }
317
+
318
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
319
+ main();
320
+ }