@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
@@ -8,19 +8,60 @@
8
8
  // workspace has `[workspace.lints]`); `src/lib.rs`, a library without code; `tests/.gitkeep`, its
9
9
  // folder of tests by the interface. Cargo needs no configuration of its own for the tests
10
10
  // (nextest, the frame's profile) nor for the typing (`cargo check`, clippy).
11
+ // - A name `cargo new` refuses (a keyword of Rust, `test`, a character out of a package's name) or
12
+ // warns against (a crate of Rust's standard library, `std`, `core`, `alloc`, `proc_macro`, whose
13
+ // neighbour that depends on it no longer builds; a reserved name of Windows) is refused, by its
14
+ // name, nothing written, cargo's reason and the name to give named (the root
15
+ // folder's name before the crate's): the skeleton writes its files without `cargo new`, and
16
+ // cargo builds and locks such a crate without a word. The judge is cargo itself, `cargo new
17
+ // --lib` of the name in a temporary folder removed at once, so that the rule stays cargo's.
11
18
  // - The workspace: the root Cargo.toml receives the crate's path in `members` of `[workspace]`,
12
19
  // written in its text, the rest of the file as it was; a root without `members` receives the
13
20
  // key, a root package without `[workspace]` the table, and a project without a root Cargo.toml a
14
21
  // virtual workspace. A member or a pattern that covers the path leaves it as it is.
15
22
  // - The lock of the versions: `cargo update --workspace`, at the root, which brings Cargo.lock in
16
23
  // line with the members alone.
24
+ // - A folder that already holds Rust code is taken as it is when the code lies in the module's
25
+ // layout, a library: `src/lib.rs` and what it declares under `src/`, its tests under `tests/`,
26
+ // each file present kept, as `cargo init` takes the code in place. Out of it (a binary,
27
+ // `src/main.rs` or `src/bin/`; a file out of `src/` and `tests/`, a `lib.rs` at the folder's
28
+ // root; code under `src/` without `src/lib.rs`), the folder is refused by its name, nothing
29
+ // written, the layout and what is missing named, in place of a skeleton beside the code.
17
30
  // - The manifest is read with smol-toml, the tool of this module (`outils`), loaded at the call.
18
- import { existsSync, readFileSync } from 'node:fs';
31
+ import { spawnSync } from 'node:child_process';
32
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
19
33
  import { createRequire } from 'node:module';
34
+ import { tmpdir } from 'node:os';
20
35
  import path from 'node:path';
21
36
 
22
37
  const require = createRequire(import.meta.url);
23
38
 
39
+ // The reason `cargo new --lib` refuses or warns against the name <nom> for (its lines `error:`
40
+ // and `warning:`), null when it accepts it without a word.
41
+ function refusDeCargo(nom) {
42
+ const dossier = mkdtempSync(path.join(tmpdir(), 'grillhouse-nom-'));
43
+ try {
44
+ const r = spawnSync(
45
+ 'cargo',
46
+ ['new', '--lib', '--vcs', 'none', '--offline', path.join(dossier, nom)],
47
+ { cwd: dossier, encoding: 'utf8' }
48
+ );
49
+ if (r.error) {
50
+ throw new Error(`cargo ne juge pas le nom ${nom} : ${r.error.message}`);
51
+ }
52
+ const raisons = r.stderr
53
+ .split('\n')
54
+ .filter(l => /^(error|warning):/.test(l))
55
+ .map(l => l.replace(/^(error|warning):\s*/, ''));
56
+ if (raisons.length) {
57
+ return raisons.join(' ; ');
58
+ }
59
+ return r.status === 0 ? null : r.stderr.trim();
60
+ } finally {
61
+ rmSync(dossier, { recursive: true, force: true });
62
+ }
63
+ }
64
+
24
65
  // The fields of a package cargo inherits from `[workspace.package]`, in the order `cargo new`
25
66
  // writes them.
26
67
  const HERITES = [
@@ -69,9 +110,37 @@ function ajouterLeMembre(texte, chemin) {
69
110
  return [...lignes.slice(0, debut + 1), nouvelle, ...lignes.slice(fin)].join('\n');
70
111
  }
71
112
 
113
+ // The refusal of the Rust files <existants> (from the crate's folder <chemin>) out of the module's
114
+ // layout (see the header), null when they lie in it.
115
+ function horsDeLaDisposition(chemin, existants) {
116
+ const rs = existants.filter(f => f.endsWith('.rs'));
117
+ const hors = rs.filter(
118
+ f =>
119
+ !(f.startsWith('src/') || f.startsWith('tests/')) ||
120
+ f === 'src/main.rs' ||
121
+ f.startsWith('src/bin/')
122
+ );
123
+ const sansLib = rs.some(f => f.startsWith('src/')) && !rs.includes('src/lib.rs');
124
+ if (!hors.length && !sansLib) {
125
+ return null;
126
+ }
127
+ const fautifs = hors.length ? hors : rs.filter(f => f.startsWith('src/'));
128
+ return `${chemin} : ${fautifs.join(', ')} hors de la disposition du module cargo, une bibliothèque : son code sous src/, que src/lib.rs déclare, ses tests sous tests/${sansLib ? ' ; src/lib.rs manque' : ''}. Range le code ainsi, puis relance la commande.`;
129
+ }
130
+
72
131
  /** @type {import('../../jointure.js').Langage['squelette']} */
73
- export function squelette(racine, { chemin }) {
132
+ export function squelette(racine, { chemin, existants }) {
133
+ const hors = horsDeLaDisposition(chemin, existants);
134
+ if (hors) {
135
+ throw new Error(hors);
136
+ }
74
137
  const nom = path.posix.basename(chemin);
138
+ const refus = refusDeCargo(nom);
139
+ if (refus) {
140
+ throw new Error(
141
+ `${chemin} : cargo refuse le nom ${nom} (${refus}). Nomme-le ${path.basename(racine)}-${nom} : le dossier et sa ligne du tableau des composants.`
142
+ );
143
+ }
75
144
  const f = path.join(racine, 'Cargo.toml');
76
145
  const texte = existsSync(f) ? readFileSync(f, 'utf8') : null;
77
146
  const espace = texte === null ? null : (require('smol-toml').parse(texte).workspace ?? null);
@@ -106,6 +175,6 @@ export function squelette(racine, { chemin }) {
106
175
  return {
107
176
  fichiers,
108
177
  espace: entree,
109
- verrouiller: { commande: 'cargo', args: ['update', '--workspace'], dossier: '.' },
178
+ verrouiller: [{ commande: 'cargo', args: ['update', '--workspace'], dossier: '.' }],
110
179
  };
111
180
  }
@@ -0,0 +1,195 @@
1
+ #!/usr/bin/env node
2
+ // The size of each test of Rust, on the model of the test pyramid of Google and of Bazel's `size`,
3
+ // as the modules typescript's and python's guards (../typescript/tailles-des-tests.mjs,
4
+ // ../python/tailles-des-tests.mjs): a large test of the day is refused, as it belongs to the night.
5
+ //
6
+ // npx grillhouse tailles-des-tests run from the repository root (a guard of grillhouse:gardes)
7
+ //
8
+ // - The test files are those of each crate of the workspace (./composants.mjs, `crates`): each
9
+ // test target cargo describes (`tests/<nom>.rs`, `tests/<dossier>/main.rs`), and each unit test
10
+ // file under `src/` (a `tests.rs`, a file of a folder `tests/`, `unitaire`). A test target whose
11
+ // name ends with `_nuit` is a night test, with `_budget` a time budget bench (`horsDuJour`,
12
+ // ./commandes.mjs); a unit test file is of the day.
13
+ // - A test is classed by a static reading of its text, of the modules it declares (`mod common;`,
14
+ // `#[path = "…"] mod x;`), followed from file to file as rustc finds them, and of each crate of
15
+ // the shared test material (`matiere`) whose name it writes (`ws_essai::`, `use ws_essai`), its
16
+ // files under `src/`; a crate of the product it uses is not read: what it starts is its own.
17
+ // - large (`grand`): it starts a process (`std::process`, `tokio::process`, `assert_cmd`, `duct`,
18
+ // `xshell`), mounts a trial repository (git's `init`, `clone` or `worktree add`, as an
19
+ // argument or a command, or git2's `Repository::init` and `Repository::clone`) and starts
20
+ // there something else than git (`Command::new` of a binary of the product, `cargo_bin`,
21
+ // `cmd!` of another program);
22
+ // - medium (`moyen`): it starts a process;
23
+ // - small (`petit`): it starts none.
24
+ // - A large test of the day is a finding, `{ fichier, regle: 'grand-de-jour', message }`; a night
25
+ // test or a bench never is one. A finding inscribed in the project's debt
26
+ // (`grillhouse-dette.json`, ../../dette.mjs) passes: the large tests of the day a project holds
27
+ // when the rule arrives are inscribed there by the update
28
+ // (./migrations/0.28.4-tailles-des-tests.mjs), the count never rises, and a new one is refused.
29
+ // - The guard writes on its error stream the count of each size, the night's included.
30
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
31
+ import path from 'node:path';
32
+ import { pathToFileURL } from 'node:url';
33
+ import { trancher } from '../../dette.mjs';
34
+ import { horsDuJour } from './commandes.mjs';
35
+ import { crates, unitaire } from './composants.mjs';
36
+
37
+ // The name of its findings and of its debt, apart from the module typescript's guard of the same
38
+ // command, whose section of the debt it never writes.
39
+ export const GARDE = 'tailles-des-tests-cargo';
40
+ export const GRAND_DE_JOUR = 'grand-de-jour';
41
+
42
+ // The use of a way to start a process.
43
+ const PROCESSUS = /\b(?:std|tokio|async_std)::process\b|\b(?:assert_cmd|duct|xshell)\b/;
44
+ // A trial repository mounted: git's `init`, `clone` or `worktree add`, as an argument or a command;
45
+ // git2's `Repository::init` or `Repository::clone`.
46
+ const DEPOT_D_ESSAI =
47
+ /"(?:init|clone)"|\bgit\s+(?:-C\s+\S+\s+)?(?:init|clone)\b|"worktree"\s*,\s*"add"|\bworktree\s+add\b|\bRepository::(?:init|clone)\w*\s*\(/;
48
+ // A call that starts a process, its program captured: `Command::new(<programme>`, assert_cmd's
49
+ // `cargo_bin(<binaire>`, the macro `cmd!` of duct (`cmd!("git", …)`) and of xshell (`cmd!(sh,
50
+ // "git …")`).
51
+ const APPEL =
52
+ /\bCommand::new\s*\(\s*([^,)\n]*)|\bcargo_bin\s*\(\s*([^,)\n]*)|\bcmd!\s*\(\s*(?:[A-Za-z_]\w*\s*,\s*)?([^,)\n]*)/g;
53
+ // A program that names git.
54
+ const GIT = /^r?#*"git(?:"|\s)/;
55
+ // The declaration of a module in its own file, `mod <nom>;`, with its attribute `#[path = "…"]`.
56
+ const MODULE =
57
+ /^[ \t]*(?:#\[path\s*=\s*"([^"]+)"\]\s*)?(?:pub(?:\([^)]*\))?\s+)?mod\s+([A-Za-z_]\w*)\s*;/gm;
58
+
59
+ // The text of the file <f>, null when it does not read.
60
+ const lireLeDisque = f => {
61
+ try {
62
+ return readFileSync(f, 'utf8');
63
+ } catch {
64
+ return null;
65
+ }
66
+ };
67
+
68
+ // Whether <f> owns its directory as rustc reads it, its modules beside it: a crate root (a test
69
+ // target `tests/<nom>.rs` or `tests/<dossier>/main.rs`, `lib.rs`, `main.rs`) or a `mod.rs`.
70
+ function racineDeModules(f) {
71
+ const base = path.basename(f);
72
+ if (['mod.rs', 'lib.rs', 'main.rs'].includes(base)) {
73
+ return true;
74
+ }
75
+ return path.basename(path.dirname(f)) === 'tests';
76
+ }
77
+
78
+ // The file of the module <nom> that <f> declares (with <chemin>, its attribute `#[path]`), read by
79
+ // <lire>: the first that reads, rustc's place first; null for none.
80
+ function fichierDuModule(f, nom, chemin, lire) {
81
+ const dir = path.dirname(f);
82
+ if (chemin) {
83
+ return path.resolve(dir, chemin);
84
+ }
85
+ const propre = path.join(dir, path.basename(f, '.rs'));
86
+ const cote = [path.join(dir, `${nom}.rs`), path.join(dir, nom, 'mod.rs')];
87
+ const dessous = [path.join(propre, `${nom}.rs`), path.join(propre, nom, 'mod.rs')];
88
+ const ordre = racineDeModules(f) ? [...cote, ...dessous] : [...dessous, ...cote];
89
+ return ordre.find(c => lire(c) !== null) ?? null;
90
+ }
91
+
92
+ /**
93
+ * The size of the test file <fichier> (absolute), read by <lire> (a path → its text, null when it
94
+ * does not read), the crates of the shared test material <matieres> (`[{ nom, fichiers }]`, `nom`
95
+ * the crate as Rust names it, `fichiers` its files, absolute): `petit`, `moyen` or `grand`.
96
+ */
97
+ export function classer(fichier, lire = lireLeDisque, matieres = []) {
98
+ const textes = [];
99
+ const vus = new Set();
100
+ const suivre = f => {
101
+ if (vus.has(f)) {
102
+ return;
103
+ }
104
+ vus.add(f);
105
+ const texte = lire(f);
106
+ if (texte === null) {
107
+ return;
108
+ }
109
+ textes.push(texte);
110
+ for (const m of texte.matchAll(MODULE)) {
111
+ const cible = fichierDuModule(f, m[2], m[1], lire);
112
+ if (cible) {
113
+ suivre(cible);
114
+ }
115
+ }
116
+ };
117
+ suivre(fichier);
118
+ const propre = textes.join('\n');
119
+ for (const m of matieres) {
120
+ if (new RegExp(`\\b${m.nom}::|\\buse\\s+${m.nom}\\b`).test(propre)) {
121
+ m.fichiers.forEach(suivre);
122
+ }
123
+ }
124
+ const tout = textes.join('\n');
125
+ const processus = PROCESSUS.test(tout);
126
+ const autreQueGit = [...tout.matchAll(APPEL)].some(m => !GIT.test((m[1] ?? m[2] ?? m[3]).trim()));
127
+ if (processus && autreQueGit && DEPOT_D_ESSAI.test(tout)) {
128
+ return 'grand';
129
+ }
130
+ return processus ? 'moyen' : 'petit';
131
+ }
132
+
133
+ // The files of Rust under <dossier>, absolute; none when it does not exist.
134
+ const rust = dossier =>
135
+ existsSync(dossier)
136
+ ? readdirSync(dossier, { recursive: true, withFileTypes: true })
137
+ .filter(e => e.isFile() && e.name.endsWith('.rs'))
138
+ .map(e => path.join(e.parentPath, e.name))
139
+ : [];
140
+
141
+ /** Each test file of the workspace at <racine> and its size: `[{ fichier, taille, nuit }]`. */
142
+ export function tailles(racine) {
143
+ const tous = crates(racine);
144
+ const matieres = tous
145
+ .filter(c => c.matiere)
146
+ .map(c => ({
147
+ nom: c.composant.nom.replace(/-/g, '_'),
148
+ fichiers: rust(path.join(c.composant.dossier, 'src')),
149
+ }));
150
+ const tests = tous.flatMap(c => {
151
+ const src = path.join(c.composant.dossier, 'src');
152
+ const unitaires = rust(src)
153
+ .filter(f => unitaire(['src', ...path.relative(src, f).split(path.sep)]))
154
+ .map(f => ({ abs: f, nuit: false }));
155
+ const cibles = c.cibles
156
+ .filter(t => t.kind.includes('test'))
157
+ .map(t => ({ abs: t.src, nuit: horsDuJour(t) !== null }));
158
+ return [...cibles, ...unitaires];
159
+ });
160
+ return tests
161
+ .map(({ abs, nuit }) => ({
162
+ fichier: path.relative(racine, abs).split(path.sep).join('/'),
163
+ taille: classer(abs, lireLeDisque, matieres),
164
+ nuit,
165
+ }))
166
+ .sort((a, b) => a.fichier.localeCompare(b.fichier, 'en'));
167
+ }
168
+
169
+ /** The findings of the workspace at <racine>: one per large test of the day. */
170
+ export function verifier(racine) {
171
+ return tailles(racine)
172
+ .filter(t => t.taille === 'grand' && !t.nuit)
173
+ .map(({ fichier }) => ({
174
+ fichier,
175
+ regle: GRAND_DE_JOUR,
176
+ message: `${fichier} : un grand test (il monte un dépôt d'essai et y lance le produit ou le cadre) est un test de nuit, jamais joué au fil du travail ; il passe en test de nuit, tests/<nom>_nuit.rs, ou il se réduit à la plus petite taille qui prouve son critère.`,
177
+ }));
178
+ }
179
+
180
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
181
+ const racine = process.cwd();
182
+ const toutes = tailles(racine);
183
+ const compte = t => toutes.filter(x => x.taille === t).length;
184
+ const { refus, lignes } = trancher(racine, GARDE, verifier(racine));
185
+ for (const r of refus) {
186
+ process.stderr.write(`⛔ ${r.message}\n`);
187
+ }
188
+ for (const l of lignes) {
189
+ process.stderr.write(`${l}\n`);
190
+ }
191
+ process.stderr.write(
192
+ `ℹ️ ${GARDE} : ${toutes.length} fichier(s) de tests, ${compte('petit')} petit(s), ${compte('moyen')} moyen(s), ${compte('grand')} grand(s) ; ${toutes.filter(x => x.nuit).length} de nuit ou de banc.\n`
193
+ );
194
+ process.exitCode = refus.length ? 1 : 0;
195
+ }
@@ -0,0 +1,159 @@
1
+ // The names of the tests of HEAD's version of a test file of Rust that cargo cannot play twice in
2
+ // one run, read without playing them (the join, `testsDeHead`; the owner's decision on
3
+ // grillhouse-3e2): a unit test file of `src/` (`src/**/tests.rs`, a file of a folder `tests/` under
4
+ // `src/`), compiled as a module of its crate, and a test target `tests/<dossier>/main.rs`, whose
5
+ // modules lie beside it; and a target `tests/<nom>.rs` whose sibling no longer compiles, read as a
6
+ // target `tests/<dossier>/main.rs`, its modules beside it (grillhouse-3e2.2). The proof of the red
7
+ // holds each name for a green HEAD already holds.
8
+ //
9
+ // - A name is the one the verdict gives (./verdict.mjs), the path nextest reports: the module path
10
+ // of the test in its binary, `<module>::…::<fn>` (tried on 2026-11-02:
11
+ // `access::engines::tests::groupe::interne` for `src/access/engines/tests.rs`, `m::dedans` and
12
+ // `aide::aidant` for `tests/scenario/main.rs` and its `mod aide;`).
13
+ // - A test is a function under an attribute `#[test]`, or `#[<chemin>::test]` (`#[tokio::test]`),
14
+ // in the inline modules that hold it (`mod <nom> { … }`); comments, strings and character
15
+ // literals are read as blanks, so that their braces do not count.
16
+ // - A unit test file of `src/`: its module path is its path under `src/` (`mod.rs` its folder's);
17
+ // the verdict gives each of its out-of-line modules (`mod <nom>;`) to its own file, so they are
18
+ // not read here. A target `tests/<dossier>/main.rs`: the verdict gives it all its binary's tests,
19
+ // so its out-of-line modules are read too, as rustc finds them (`<dossier>/<nom>.rs` or
20
+ // `<dossier>/<nom>/mod.rs`, a module of `<f>.rs` under `<f>/`).
21
+ import path from 'node:path';
22
+
23
+ // The text <t> with its comments, strings and character literals read as blanks.
24
+ export function sansLitteraux(t) {
25
+ let out = '';
26
+ let i = 0;
27
+ while (i < t.length) {
28
+ if (t.startsWith('//', i)) {
29
+ const fin = t.indexOf('\n', i);
30
+ i = fin < 0 ? t.length : fin;
31
+ continue;
32
+ }
33
+ if (t.startsWith('/*', i)) {
34
+ let profondeur = 0;
35
+ do {
36
+ if (t.startsWith('/*', i)) {
37
+ profondeur++;
38
+ i += 2;
39
+ } else if (t.startsWith('*/', i)) {
40
+ profondeur--;
41
+ i += 2;
42
+ } else {
43
+ i++;
44
+ }
45
+ } while (profondeur > 0 && i < t.length);
46
+ out += ' ';
47
+ continue;
48
+ }
49
+ const brute = /^b?r(#*)"/.exec(t.slice(i, i + 260));
50
+ if (brute && !/\w/.test(t[i - 1] ?? '')) {
51
+ const fin = t.indexOf(`"${brute[1]}`, i + brute[0].length);
52
+ i = fin < 0 ? t.length : fin + 1 + brute[1].length;
53
+ out += ' ';
54
+ continue;
55
+ }
56
+ if (t[i] === '"') {
57
+ i++;
58
+ while (i < t.length && t[i] !== '"') i += t[i] === '\\' ? 2 : 1;
59
+ i++;
60
+ out += ' ';
61
+ continue;
62
+ }
63
+ if (t[i] === "'") {
64
+ const car = /^'(?:\\(?:u\{[0-9a-fA-F]+\}|x[0-9a-fA-F]{2}|.)|[^\\'])'/.exec(
65
+ t.slice(i, i + 16)
66
+ );
67
+ if (car) {
68
+ i += car[0].length;
69
+ out += ' ';
70
+ continue;
71
+ }
72
+ }
73
+ out += t[i];
74
+ i++;
75
+ }
76
+ return out;
77
+ }
78
+
79
+ // What the text <texte> of a file of Rust holds: `tests`, each test's module path within the
80
+ // file and its name, and `externes`, each out-of-line module's path within the file.
81
+ export function lireLeFichier(texte) {
82
+ const t = sansLitteraux(texte);
83
+ const tests = [];
84
+ const externes = [];
85
+ const pile = [];
86
+ let marque = false;
87
+ const jeton = /#!?\s*\[|\bmod\s+([A-Za-z_]\w*)\s*([{;])|\bfn\s+([A-Za-z_]\w*)|[{}]/g;
88
+ const ici = () => pile.filter(Boolean);
89
+ let m;
90
+ while ((m = jeton.exec(t))) {
91
+ const j = m[0];
92
+ if (j.startsWith('#')) {
93
+ let profondeur = 1;
94
+ let k = jeton.lastIndex;
95
+ while (k < t.length && profondeur > 0) {
96
+ if (t[k] === '[') profondeur++;
97
+ else if (t[k] === ']') profondeur--;
98
+ k++;
99
+ }
100
+ const attribut = t.slice(jeton.lastIndex, k - 1).trim();
101
+ if (/^(?:\w+\s*::\s*)*test$/.test(attribut)) marque = true;
102
+ jeton.lastIndex = k;
103
+ } else if (m[1]) {
104
+ if (m[2] === '{') pile.push(m[1]);
105
+ else externes.push([...ici(), m[1]]);
106
+ marque = false;
107
+ } else if (m[3]) {
108
+ if (marque) tests.push([...ici(), m[3]]);
109
+ marque = false;
110
+ } else if (j === '{') {
111
+ pile.push(null);
112
+ } else {
113
+ pile.pop();
114
+ }
115
+ }
116
+ return { tests, externes };
117
+ }
118
+
119
+ /**
120
+ * The names of the tests of HEAD's version of the test file <chemin> (from the root), as the
121
+ * verdict names them: with <module>, a unit test file of `src/`, its module path under `src/`;
122
+ * without (null), a target `tests/<dossier>/main.rs`, its out-of-line modules read too. <lire>
123
+ * gives HEAD's text of a file from the root, null for none. Null when HEAD does not hold <chemin>.
124
+ * @param {string} chemin
125
+ * @param {string[] | null} module
126
+ * @param {(f: string) => string | null} lire
127
+ * @returns {string[] | null}
128
+ */
129
+ export function nomsDeHead(chemin, module, lire) {
130
+ const texte = lire(chemin);
131
+ if (texte === null) return null;
132
+ if (module) {
133
+ return lireLeFichier(texte).tests.map(t => [...module, ...t].join('::'));
134
+ }
135
+ const noms = [];
136
+ const vus = new Set();
137
+ // The file <f> of text <tx>, its modules under <dossier>, its tests under <prefixe>.
138
+ const parcourir = (f, tx, dossier, prefixe) => {
139
+ if (vus.has(f)) return;
140
+ vus.add(f);
141
+ const { tests, externes } = lireLeFichier(tx);
142
+ noms.push(...tests.map(t => [...prefixe, ...t].join('::')));
143
+ for (const e of externes) {
144
+ const base = path.posix.join(dossier, ...e);
145
+ for (const [g, sous] of [
146
+ [`${base}.rs`, base],
147
+ [path.posix.join(base, 'mod.rs'), base],
148
+ ]) {
149
+ const txg = lire(g);
150
+ if (txg !== null) {
151
+ parcourir(g, txg, sous, [...prefixe, ...e]);
152
+ break;
153
+ }
154
+ }
155
+ }
156
+ };
157
+ parcourir(chemin, texte, path.posix.dirname(chemin), []);
158
+ return noms;
159
+ }