@roomi-fields/grillhouse 0.25.5 → 0.27.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 (83) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/agents/testwriter.md +1 -1
  3. package/bin/grillhouse.mjs +20 -3
  4. package/cadre/templates/cargo/package.json +3 -0
  5. package/cadre/templates/projet/.gitattributes +1 -0
  6. package/cadre/templates/projet/CLAUDE.md +13 -0
  7. package/cadre/templates/projet/docs/ARCHITECTURE.md +15 -0
  8. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  9. package/cadre/templates/python/package.json +18 -0
  10. package/charte.md +32 -1
  11. package/docs/ARCHITECTURE.md +146 -40
  12. package/docs/CADRE.md +7 -6
  13. package/docs/INTERFACE.md +108 -32
  14. package/hooks/register.tsx +57 -16
  15. package/package.json +9 -3
  16. package/scripts/circuit.mjs +165 -27
  17. package/scripts/commande-du-langage.mjs +2 -2
  18. package/scripts/commandes-composees.mjs +156 -0
  19. package/scripts/composition-des-langages.mjs +306 -0
  20. package/scripts/conformite.mjs +1 -3
  21. package/scripts/copies-finies.mjs +167 -28
  22. package/scripts/crochets.mjs +9 -3
  23. package/scripts/dernier-vert.mjs +15 -2
  24. package/scripts/engendres.mjs +170 -0
  25. package/scripts/enveloppe/enveloppe.mjs +59 -17
  26. package/scripts/enveloppe/lancer.sh +15 -22
  27. package/scripts/enveloppe/travail-de-la-copie.mjs +262 -0
  28. package/scripts/etapes.mjs +1 -1
  29. package/scripts/fusion-du-changelog.mjs +120 -0
  30. package/scripts/gardes-du-cadre.mjs +7 -4
  31. package/scripts/grillhouse-maj.mjs +171 -99
  32. package/scripts/index-interfaces.mjs +78 -0
  33. package/scripts/init.mjs +5 -5
  34. package/scripts/integration/file.mjs +270 -117
  35. package/scripts/integration/integrer.mjs +50 -62
  36. package/scripts/jointure.d.ts +48 -14
  37. package/scripts/langages/cargo/binaires.json +2 -1
  38. package/scripts/langages/cargo/binaires.mjs +29 -6
  39. package/scripts/langages/cargo/clippy.mjs +12 -2
  40. package/scripts/langages/cargo/commandes.mjs +60 -7
  41. package/scripts/langages/cargo/composants.mjs +229 -8
  42. package/scripts/langages/cargo/exemples.mjs +1 -15
  43. package/scripts/langages/cargo/index-interfaces.mjs +20 -3
  44. package/scripts/langages/cargo/index.mjs +25 -17
  45. package/scripts/langages/cargo/mise-a-jour.mjs +2 -1
  46. package/scripts/langages/cargo/sccache.mjs +172 -0
  47. package/scripts/langages/cargo/verdict.mjs +50 -10
  48. package/scripts/langages/python/binaires.json +3 -0
  49. package/scripts/langages/python/binaires.mjs +59 -0
  50. package/scripts/langages/python/commandes.mjs +411 -0
  51. package/scripts/langages/python/composants.mjs +272 -0
  52. package/scripts/langages/python/exemples.mjs +260 -0
  53. package/scripts/langages/python/index-interfaces.mjs +77 -0
  54. package/scripts/langages/python/index.mjs +94 -0
  55. package/scripts/langages/python/lot.mjs +76 -0
  56. package/scripts/langages/python/mise-a-jour.mjs +54 -0
  57. package/scripts/langages/python/tailles-des-tests.mjs +102 -0
  58. package/scripts/langages/python/verdict.mjs +85 -0
  59. package/scripts/langages/typescript/exemples.mjs +1 -20
  60. package/scripts/langages/typescript/index-interfaces.mjs +10 -3
  61. package/scripts/langages/typescript/index.mjs +15 -17
  62. package/scripts/langages/typescript/regle-des-tests.mjs +37 -0
  63. package/scripts/langages-des-paquets.mjs +171 -0
  64. package/scripts/langages.mjs +60 -41
  65. package/scripts/migrations/0.27.0-langages-dans-l-architecture.mjs +182 -0
  66. package/scripts/migrations.mjs +2 -0
  67. package/scripts/nuit.sh +15 -1
  68. package/scripts/outils-cles.mjs +188 -0
  69. package/scripts/resultats.mjs +22 -6
  70. package/scripts/session-start.sh +34 -9
  71. package/scripts/sources.mjs +2 -1
  72. package/scripts/sous-commandes.mjs +21 -3
  73. package/scripts/tableau-des-composants.mjs +138 -0
  74. package/scripts/verrou-de-machine.mjs +14 -13
  75. package/scripts/verrous/verrou.mjs +53 -16
  76. package/skills/developpeur/SKILL.md +4 -0
  77. package/skills/explorateur/SKILL.md +3 -1
  78. package/skills/grill/SKILL.md +9 -1
  79. package/skills/pitmaster/SKILL.md +12 -3
  80. package/skills/pitmaster/references/consigne-agent.md +3 -3
  81. package/skills/redacteur/references/documents-d-un-composant.md +12 -0
  82. package/skills/relecteur/SKILL.md +6 -2
  83. package/skills/testwriter/SKILL.md +29 -6
@@ -68,6 +68,25 @@ export interface FichierEngendre {
68
68
  * does not write. */
69
69
  export type ClasseDeTest = { joue: boolean; test: boolean; matiere: boolean } | null;
70
70
 
71
+ /** What the testwriter writes of the manifests, as the author of a test of Bazel declares the deps
72
+ * of its target: the part of a component's manifest that declares what its tests depend on, and
73
+ * the lock files of the versions. */
74
+ export interface Manifestes {
75
+ /** The lock files of the versions, from the root: the testwriter writes them, and the envelope
76
+ * opens them to him. */
77
+ verrous: string[];
78
+ /** The parts of a file of a component at `chemin` (absolute, or from `racine`) that change from
79
+ * `avant` (null: no file) to `apres` out of the part of its tests, each named, empty for none:
80
+ * of its manifest, the part that declares what its tests depend on; for cargo, of a file of code
81
+ * of `src/`, its test module. Null for a file the module does not judge. */
82
+ horsDesTests(
83
+ chemin: string,
84
+ racine: string,
85
+ avant: string | null,
86
+ apres: string
87
+ ): string[] | null;
88
+ }
89
+
71
90
  /** The readers, by the code, of the elements a ticket names (composants-affectes). */
72
91
  export interface Lecteurs {
73
92
  elements: {
@@ -172,20 +191,19 @@ export interface MiseAJour {
172
191
  } | null;
173
192
  }
174
193
 
175
- /** A module of language, the default export of `scripts/langages/<nom>/index.mjs`. */
176
- export interface Langage {
194
+ /** What the core asks of the languages of a project: a module of language, or the composition of
195
+ * the modules a project declares (scripts/composition-des-langages.mjs), whose name joins theirs
196
+ * with `+`. */
197
+ export interface Composition {
177
198
  nom: string;
178
- /** Whether the repository at `racine` holds code of this language, which the update declares. */
179
- trouve(racine: string): boolean;
180
- /** What `trouve` looks for, in words: the refusal of the update names it. */
181
- signe: string;
182
199
  /** The tools a project of this language installs, optional peers of the package. */
183
200
  outils: string[];
184
201
  /** The binaries a project of this language installs on the machine, each at its exact version:
185
202
  * the update installs each one missing or at another version (`miseAJour.installation`). */
186
203
  binaires: Record<string, string>;
187
204
  /** The directories the language's tools write in a project, by name: the source files leave them
188
- * out, and the update writes them in the project's `.gitignore`. */
205
+ * out, the update writes them in the project's `.gitignore`, and the removal of the finished
206
+ * copies removes them from a kept copy whose ticket is closed (scripts/copies-finies.mjs). */
189
207
  ignorer: string[];
190
208
  /** Where a run of the language's tools writes, which the envelope opens to a session. */
191
209
  sorties: {
@@ -222,20 +240,35 @@ export interface Langage {
222
240
  ): { tester: Commande; verifier: Commande; typer: Commande } & Record<string, Commande>;
223
241
  verdict(dossier: string): { rapports: RapportDeTest[]; taches: TacheJouee[] };
224
242
  estUnTest(chemin: string, racine: string): ClasseDeTest;
243
+ manifestes: Manifestes;
225
244
  fichiersEngendres(racine: string): FichierEngendre[];
226
245
  gardes(racine: string): string[][];
227
246
  migrations: Migration[];
247
+ }
248
+
249
+ /** A module of language, the default export of `scripts/langages/<nom>/index.mjs`. */
250
+ export interface Langage extends Composition {
251
+ /** The manifest of a package of this language, in its folder (`package.json`, `Cargo.toml`):
252
+ * the guard of the languages asks it of a package the architecture declares of this language. */
253
+ manifeste: string;
254
+ /** The entries of the index of the interfaces, one per interface of the module's components and
255
+ * the root's, `lignes` as the index writes them, which the core assembles for a project of
256
+ * several languages (scripts/index-interfaces.mjs). */
257
+ entreesDeLIndex(racine: string): { rel: string; lignes: string[] }[];
228
258
  miseAJour: MiseAJour;
229
259
  }
230
260
 
231
261
  /** The frame's languages, each its module. */
232
262
  export const LANGAGES: Record<string, string>;
233
- /** The languages the project at `racine` declares (`grillhouse.langages`), empty for none. */
263
+ /** The languages the project at `racine` declares: the column « Langage » of the table of the
264
+ * components of its docs/ARCHITECTURE.md, each once, empty for none. */
234
265
  export function langagesDeclares(racine: string): string[];
235
- /** The languages of the frame whose module finds its code in the repository at `racine`. */
236
- export function langagesTrouves(racine: string): string[];
237
- /** The module of the language that serves the project at `racine`; throws when it declares none. */
238
- export function langageDe(racine: string): Langage;
266
+ /** The modules of the languages the project at `racine` declares, in the order of the table;
267
+ * throws when it declares none, or one out of the list. */
268
+ export function langagesDe(racine: string): Langage[];
269
+ /** The join of the modules that serve the project at `racine`: the module itself for one, their
270
+ * composition for several; throws as `langagesDe`. */
271
+ export function langageDe(racine: string): Composition;
239
272
 
240
273
  // The services of the core to a module of language, which imports of the core its published
241
274
  // entries alone (.dependency-cruiser.projet.cjs of the frame's repository).
@@ -294,8 +327,9 @@ export function attendreLeRepos(o?: Record<string, unknown>): unknown;
294
327
  export const CHANGEMENTS: string;
295
328
  /** The variable naming the commit of the last green a run measures itself from. */
296
329
  export const DEPUIS_LE_VERT: string;
297
- /** Keeps the green of a pass, which the next one measures itself from. */
298
- export function garderLeVert(etat: unknown): void;
330
+ /** Keeps the green of a pass, which the next one measures itself from; deferred to the file
331
+ * `GRILLHOUSE_VERT_DIFFERE` of `env` names, in a project of several languages. */
332
+ export function garderLeVert(etat: unknown, env?: NodeJS.ProcessEnv): void;
299
333
  /** The measure of the repository at `racine` against its last green. */
300
334
  export function mesure(racine: string, o?: { tout?: boolean; dans?: string }): unknown;
301
335
  /** The wait for the lock of the machine, ended without it (scripts/verrou-de-machine.mjs). */
@@ -1,4 +1,5 @@
1
1
  {
2
2
  "cargo-deny": "0.20.2",
3
- "cargo-nextest": "0.9.150"
3
+ "cargo-nextest": "0.9.150",
4
+ "sccache": "0.19.0"
4
5
  }
@@ -9,8 +9,11 @@
9
9
  // which cargo-binstall's installations also write). Cargo absent or failing: a line on the error
10
10
  // stream, named, and the code 1.
11
11
  // - `installer`: `cargo binstall --no-confirm --locked <nom>@<version>`, its output this process's
12
- // error stream, its code this process's; a failure names on the error stream the command to type
13
- // and how cargo-binstall installs itself.
12
+ // error stream, its code this process's; a failure names on the error stream the command to type.
13
+ // A machine whose cargo lacks binstall (`cargo --list`) first receives cargo-binstall from cargo,
14
+ // at its exact version (`cargo install --locked cargo-binstall@<BINSTALL>`, the installation the
15
+ // README of cargo-binstall gives): the update installs the binaries without a step by hand
16
+ // (grillhouse-qmk, OSC Bridge). Its failure names that command, and no binstall runs.
14
17
  import { spawnSync } from 'node:child_process';
15
18
  import { pathToFileURL } from 'node:url';
16
19
 
@@ -28,16 +31,36 @@ export function installes() {
28
31
  );
29
32
  }
30
33
 
31
- /** Installs <cible> (`<nom>@<version>`): the exit code of cargo binstall. */
34
+ /** The version of cargo-binstall that cargo installs when the machine lacks it. */
35
+ export const BINSTALL = '1.26.2';
36
+
37
+ // Whether cargo has the subcommand binstall, as `cargo --list` lists it.
38
+ const avecBinstall = () => {
39
+ const r = spawnSync('cargo', ['--list'], { encoding: 'utf8' });
40
+ return r.status === 0 && /^\s+binstall\s*$/m.test(r.stdout ?? '');
41
+ };
42
+
43
+ /**
44
+ * Installs <cible> (`<nom>@<version>`): the exit code of cargo binstall, or of the installation of
45
+ * cargo-binstall when it lacks and fails.
46
+ */
32
47
  export function installer(cible) {
48
+ if (!avecBinstall()) {
49
+ const args = ['install', '--locked', `cargo-binstall@${BINSTALL}`];
50
+ const r = spawnSync('cargo', args, { stdio: ['ignore', 2, 2] });
51
+ const code = r.error ? 127 : (r.status ?? 1);
52
+ if (code !== 0) {
53
+ const cause = r.error ? r.error.message : `code ${code}`;
54
+ process.stderr.write(`⛔ \`cargo ${args.join(' ')}\` échoue (${cause}) ; lance-la.\n`);
55
+ return code;
56
+ }
57
+ }
33
58
  const args = ['binstall', '--no-confirm', '--locked', cible];
34
59
  const r = spawnSync('cargo', args, { stdio: ['ignore', 2, 2] });
35
60
  const code = r.error ? 127 : (r.status ?? 1);
36
61
  if (code !== 0) {
37
62
  const cause = r.error ? r.error.message : `code ${code}`;
38
- process.stderr.write(
39
- `⛔ \`cargo ${args.join(' ')}\` échoue (${cause}) ; lance-la (cargo-binstall s'installe par \`cargo install cargo-binstall\`).\n`
40
- );
63
+ process.stderr.write(`⛔ \`cargo ${args.join(' ')}\` échoue (${cause}) ; lance-la.\n`);
41
64
  }
42
65
  return code;
43
66
  }
@@ -5,7 +5,10 @@
5
5
  // node clippy.mjs in the root of the workspace; 0 green, 1 a finding refused
6
6
  //
7
7
  // - It runs `cargo clippy --all-targets --message-format=json -- -D warnings`: every target, the
8
- // tests of `tests/` included, which clippy reads only with `--all-targets`; every warning denied.
8
+ // tests of `tests/` included, which clippy reads only with `--all-targets`; every warning denied;
9
+ // rustc wrapped by sccache, as every command of the module that compiles (./sccache.mjs), its
10
+ // server started first under the machine's /tmp (`demarrerLeServeur`); a
11
+ // PATH without sccache refuses before cargo runs, the line naming `npx grillhouse maj`.
9
12
  // - Each diagnostic of the compiler that carries a code is a finding: its file, the primary span's
10
13
  // from the root, its line, its message the compiler's. A lint (`clippy::needless_return`, a lint
11
14
  // of rustc such as `unused_variables`) is its rule, which the debt keys; an error of compilation
@@ -20,6 +23,7 @@ import { spawnSync } from 'node:child_process';
20
23
  import path from 'node:path';
21
24
  import { pathToFileURL } from 'node:url';
22
25
  import { MODE, trancher } from '../../dette.mjs';
26
+ import { avecSccache, demarrerLeServeur, sccacheAbsent } from './sccache.mjs';
23
27
 
24
28
  export const GARDE = 'clippy';
25
29
  export const ARGS = ['clippy', '--all-targets', '--message-format=json', '--', '-D', 'warnings'];
@@ -76,9 +80,15 @@ export function constatsDeClippy(sortie, racine) {
76
80
  * @param {{ env?: NodeJS.ProcessEnv }} [o] the environment (the results directory, the debt's mode)
77
81
  */
78
82
  export function commande(racine, { env = process.env } = {}) {
83
+ const absent = sccacheAbsent(racine, env);
84
+ if (absent) {
85
+ process.stderr.write(`${absent}\n`);
86
+ return 1;
87
+ }
88
+ demarrerLeServeur(racine, env);
79
89
  const r = spawnSync('cargo', ARGS, {
80
90
  cwd: racine,
81
- env,
91
+ env: avecSccache(racine, env),
82
92
  encoding: 'utf8',
83
93
  maxBuffer: 256 * 1024 * 1024,
84
94
  });
@@ -4,7 +4,7 @@
4
4
  // `commandes`; run by `grillhouse <commande>` in the root of the workspace, its arguments after.
5
5
  //
6
6
  // npx grillhouse tests [--force] [<chemin>…] [--<option>…] tester
7
- // npx grillhouse verifier [--tout] verifier
7
+ // npx grillhouse verifier [--tout | --gardes] verifier
8
8
  // node commandes.mjs typer typer
9
9
  // npx grillhouse preparer preparer
10
10
  // npx grillhouse clippy | frontieres | index-interfaces each guard, its own script
@@ -35,6 +35,10 @@
35
35
  // time (`avecLaMachine` of ./jointure, as the module typescript's verifier): a measure that
36
36
  // holds it makes it wait, and the bound of the wait reached, it stops at 75 without running
37
37
  // cargo.
38
+ // - `verifier --gardes` plays the guards alone, the same verdict as the module typescript's: the
39
+ // project's root scripts `grillhouse:gardes` (the frame's guards) then `gardes` (its own), each
40
+ // one the package.json holds a task of the root, by npm, without its tests nor cargo deny, and
41
+ // keeps no last green.
38
42
  // - `tester` and `verifier` play under a temporary directory of their pass, the module's guard of
39
43
  // the temporary directory, as the CI of osc-bridge (OB-ud1.3): a base (`ouvrirBase` of
40
44
  // ./jointure, genre `tests` or `verification`) in the temporary directory of the environment,
@@ -44,6 +48,11 @@
44
48
  // directory or file with the crate `tempfile` (`TempDir`, `NamedTempFile`), removed when dropped,
45
49
  // a failed test included, never a path built by hand under `std::env::temp_dir()`.
46
50
  // - `typer`: `cargo check --all-targets`. `preparer`: `cargo fetch --locked`.
51
+ // - Cargo runs with rustc wrapped by sccache, its cache common to the copies of the machine
52
+ // (./sccache.mjs), in a copy as in an agent's envelope (grillhouse-cyr), its server started
53
+ // under the machine's /tmp before each run of cargo that compiles (grillhouse-qmk). `tester`, `verifier`
54
+ // and `typer` refuse, before any run of cargo, a PATH without sccache, in one line that names it
55
+ // and `npx grillhouse maj`, which installs it (code 2).
47
56
  // - Nextest reads the frame's profile `grillhouse` (./nextest.toml, a tool's configuration under
48
57
  // the project's own, `--tool-config-file`), whose JUnit report lands at
49
58
  // `<target>/nextest/grillhouse/junit.xml`.
@@ -87,6 +96,7 @@ import {
87
96
  retirerALInterruption,
88
97
  } from '../../services-du-noyau.mjs';
89
98
  import { composantDans, crates, joueDesTests, metadonnees } from './composants.mjs';
99
+ import { avecSccache, demarrerLeServeur, sccacheAbsent } from './sccache.mjs';
90
100
  import { touchesDesFichiers } from './touches.mjs';
91
101
  import { JUNIT, TACHES } from './verdict.mjs';
92
102
 
@@ -99,6 +109,10 @@ const RACINE = '//';
99
109
  const VERROU = 'Cargo.lock';
100
110
  // The commands that play the exact versions of the repository, refused without its Cargo.lock.
101
111
  const VERROUILLEES = ['tester', 'verifier', 'preparer'];
112
+ // The commands that compile, refused without sccache on the PATH (./sccache.mjs).
113
+ const COMPILENT = ['tester', 'verifier', 'typer'];
114
+ // The subcommands of cargo that compile, before which the server of sccache starts.
115
+ const COMPILATIONS = ['test', 'nextest', 'check'];
102
116
 
103
117
  /** The guards of structure of the module, in the order they play: each its name, its script beside
104
118
  * this one, and its arguments as a guard. */
@@ -140,6 +154,8 @@ function passe(racine, env) {
140
154
  const id = `${Date.now()}-${process.pid}`;
141
155
  const taches = [];
142
156
  const cibles = {};
157
+ // Cargo compiles through sccache (./sccache.mjs).
158
+ const compilation = avecSccache(racine, env);
143
159
  const ecrire = () => {
144
160
  if (!dossier) {
145
161
  return;
@@ -167,11 +183,15 @@ function passe(racine, env) {
167
183
  ecrire();
168
184
  return { t, args };
169
185
  },
170
- jouer({ t, args }, { junit = null, journal = null } = {}) {
186
+ jouer({ t, args }, { junit = null, journal = null, programme = 'cargo' } = {}) {
171
187
  // A report of an earlier run is no report of this one, which may write none.
172
188
  if (junit) {
173
189
  rmSync(junit, { force: true });
174
190
  }
191
+ // The server of sccache, started under a short temporary directory (./sccache.mjs).
192
+ if (COMPILATIONS.includes(args[0])) {
193
+ demarrerLeServeur(racine, env);
194
+ }
175
195
  let r;
176
196
  if (journal) {
177
197
  // The output of cargo, both streams in their order, goes to the task's log, then to the
@@ -179,14 +199,18 @@ function passe(racine, env) {
179
199
  mkdirSync(path.dirname(journal), { recursive: true });
180
200
  const fd = openSync(journal, 'w');
181
201
  try {
182
- r = spawnSync('cargo', args, { cwd: racine, env, stdio: ['inherit', fd, fd] });
202
+ r = spawnSync(programme, args, {
203
+ cwd: racine,
204
+ env: compilation,
205
+ stdio: ['inherit', fd, fd],
206
+ });
183
207
  } finally {
184
208
  closeSync(fd);
185
209
  }
186
210
  process.stderr.write(readFileSync(journal, 'utf8'));
187
211
  t.journal = path.relative(racine, journal);
188
212
  } else {
189
- r = spawnSync('cargo', args, { cwd: racine, env, stdio: 'inherit' });
213
+ r = spawnSync(programme, args, { cwd: racine, env: compilation, stdio: 'inherit' });
190
214
  }
191
215
  t.code = r.error ? 127 : (r.status ?? 128 + (constants.signals[r.signal] ?? 0));
192
216
  if (junit && dossier && existsSync(junit)) {
@@ -277,7 +301,7 @@ function choisir(racine, tous, chemins) {
277
301
  continue;
278
302
  }
279
303
  if (!joueDesTests(racine, c)) {
280
- refus.push(`${chemin} : ${c.nom} n'a pas de dossier tests/`);
304
+ refus.push(`${chemin} : ${c.nom} n'a aucun test, ni dossier tests/, ni tests.rs sous src/`);
281
305
  continue;
282
306
  }
283
307
  const cible = crate.cibles.find(t => t.kind.includes('test') && t.src === abs);
@@ -305,6 +329,9 @@ function choisir(racine, tous, chemins) {
305
329
  // last green.
306
330
  function verifier(racine, args, env) {
307
331
  const p = passe(racine, env);
332
+ if (args.includes('--gardes')) {
333
+ return gardes(racine, p);
334
+ }
308
335
  const tous = crates(racine);
309
336
  const { choix, m } = depuisLeVert(racine, tous, args.includes('--tout'), env);
310
337
  try {
@@ -325,6 +352,30 @@ function verifier(racine, args, env) {
325
352
  }
326
353
  }
327
354
 
355
+ // The scripts of guards of the project, in the order they play, as the module typescript's
356
+ // `--gardes` plays its tasks: the frame's, then the project's own.
357
+ const SCRIPTS_DE_GARDES = ['grillhouse:gardes', 'gardes'];
358
+
359
+ // The pass of `verifier --gardes` in <racine>, the run <p>: each script of SCRIPTS_DE_GARDES the
360
+ // root package.json holds, a task of the root, whatever the verdict of the one before; no test.
361
+ function gardes(racine, p) {
362
+ let scripts = {};
363
+ try {
364
+ scripts = JSON.parse(readFileSync(path.join(racine, 'package.json'), 'utf8')).scripts ?? {};
365
+ } catch {
366
+ scripts = {};
367
+ }
368
+ for (const nom of SCRIPTS_DE_GARDES.filter(n => typeof scripts[n] === 'string')) {
369
+ p.jouer(p.prevoir(RACINE, racine, nom, false, ['run', '--silent', nom]), { programme: 'npm' });
370
+ }
371
+ return p.code();
372
+ }
373
+
374
+ // Node's compile cache, which npm enables under the temporary directory (`module.enableCompileCache()`)
375
+ // when `verifier --gardes` runs the project's scripts: the guard of the base tolerates it at its
376
+ // root, as the module typescript's base of Vitest, and the base removes it with the rest.
377
+ const CACHE_DE_NODE = 'node-compile-cache';
378
+
328
379
  // Plays <jouer>(env) under the base of a pass of <genre> in the temporary directory of <env>,
329
380
  // named to cargo in TMPDIR, TMP and TEMP: its code, 1 when the tests left something there, named.
330
381
  // The base goes at the end, or at an interruption.
@@ -333,7 +384,7 @@ function sousLaBase(genre, env, jouer) {
333
384
  const lacher = retirerALInterruption(base.fermer);
334
385
  try {
335
386
  const code = jouer({ ...env, ...base.env });
336
- const ligne = ligneDesRestes(base.restes());
387
+ const ligne = ligneDesRestes(base.restes().filter(n => n !== CACHE_DE_NODE));
337
388
  if (!ligne) {
338
389
  return code;
339
390
  }
@@ -369,7 +420,9 @@ export function verrouNonVersionne(racine) {
369
420
  * @param {{ racine?: string, env?: NodeJS.ProcessEnv }} [o]
370
421
  */
371
422
  export function lancer(nom, args, { racine = process.cwd(), env = process.env } = {}) {
372
- const refus = VERROUILLEES.includes(nom) ? verrouNonVersionne(racine) : null;
423
+ const refus =
424
+ (VERROUILLEES.includes(nom) ? verrouNonVersionne(racine) : null) ??
425
+ (COMPILENT.includes(nom) ? sccacheAbsent(racine, env) : null);
373
426
  if (refus) {
374
427
  process.stderr.write(`${refus}\n`);
375
428
  return 2;
@@ -13,20 +13,43 @@
13
13
  // ./touches.mjs reads as the whole workspace.
14
14
  // - The shared test material: the crates whose manifest says `[package.metadata.grillhouse]
15
15
  // matiere = true`.
16
- // - A crate plays tests when it has a folder `tests/`, where cargo finds its integration tests:
17
- // the tests of the project live there (decision 5 of the epic grillhouse-pkl).
16
+ // - A test lives in a file of its own, never in a file of code (decision 5 of the epic
17
+ // grillhouse-pkl, amended by grillhouse-agr): the tests by the interface under `tests/` of each
18
+ // crate, where cargo finds its integration tests; the unit tests near their module, under
19
+ // `src/`, in a file `tests.rs` or a folder `tests/`, as rustc's tidy check wants them
20
+ // (src/tools/tidy/src/unit_tests.rs), declared in the module by `#[cfg(test)] mod tests;`, a line
21
+ // the testwriter writes with his test. A crate plays tests when it has either.
18
22
  // - The readers of a crate: the members that depend on it by its path, of any kind (`normal`,
19
23
  // `dev`, `build`), the kind in `par`; a name no member bears is without provider. The types
20
24
  // give no survey of their own: `etat` done, no element.
21
25
  // - What the testwriter writes: a file of `<crate>/tests/` is a test file; the runner plays the
22
26
  // ones cargo makes a test target of, `tests/<nom>.rs` and `tests/<dossier>/main.rs`, and the
23
27
  // others are their helpers and data (`tests/fixtures/`, as OSC Bridge's devices); a file of
24
- // `<crate>/tests/common/`, the helpers cargo's book puts there, is test material too; a file of
25
- // a crate of the shared test material is material; any other file of a crate (`src/` included)
26
- // is none of them.
28
+ // `<crate>/tests/common/`, the helpers cargo's book puts there, is test material too; a file
29
+ // `tests.rs` under `src/`, and any file of a folder `tests/` under `src/`, is a unit test file,
30
+ // played with its crate when it is Rust; a file of a crate of the shared test material is
31
+ // material; any other file of a crate (the code of `src/`) is none of them.
32
+ // - What the testwriter writes of the manifests (`manifestes`): the tables that declare what the
33
+ // tests of a crate depend on, `[dev-dependencies]` and `[target.<cible>.dev-dependencies]` of
34
+ // its Cargo.toml (cargo's book, « Development dependencies »), as the author of a test of Bazel
35
+ // declares the deps of its target; and Cargo.lock at the root, which cargo brings in line with
36
+ // them. A change of any other table is named by it; the Cargo.toml of a virtual workspace is
37
+ // no crate's. Of a file of code of `src/` of a crate, the testwriter writes its test module
38
+ // alone (grillhouse-agr): the declaration `#[cfg(test)] mod tests;` added or removed, without
39
+ // which a new tests.rs is never compiled, and an inline `#[cfg(test)] mod tests { … }` removed,
40
+ // which he moves into tests.rs; any other change is named by its first line. The manifests are
41
+ // read with smol-toml, a tool of this module (`outils`), an optional peer of the package loaded
42
+ // when a manifest is judged, so that a project of another language, which loads this module
43
+ // without it, never needs it.
27
44
  import { spawnSync } from 'node:child_process';
28
- import { existsSync, statSync } from 'node:fs';
45
+ import { existsSync, readdirSync, statSync } from 'node:fs';
46
+ import { createRequire } from 'node:module';
29
47
  import path from 'node:path';
48
+ import { isDeepStrictEqual } from 'node:util';
49
+
50
+ // The loader of the optional peers this module reads when it needs them (smol-toml), under the
51
+ // name by which knip reads a dependency.
52
+ const require = createRequire(import.meta.url);
30
53
 
31
54
  // The genre of a dependency as cargo names its kind, null for a normal one.
32
55
  const genre = kind => kind ?? 'normal';
@@ -100,10 +123,33 @@ export const matieres = racine =>
100
123
  .filter(c => c.matiere)
101
124
  .map(c => c.composant);
102
125
 
103
- /** Whether the crate <composant> has a folder `tests/`, its integration tests. */
126
+ // Whether <parts>, a path from the folder of a crate split, is a unit test file under its `src/`:
127
+ // a file `tests.rs`, or a file of a folder `tests/`.
128
+ // `src/bin/tests.rs` and `src/bin/tests/` are a binary target for cargo, its code.
129
+ const unitaire = parts =>
130
+ parts[0] === 'src' &&
131
+ parts.length > 1 &&
132
+ !(parts[1] === 'bin' && ['tests.rs', 'tests'].includes(parts[2])) &&
133
+ (parts.at(-1) === 'tests.rs' || parts.slice(1, -1).includes('tests'));
134
+
135
+ /**
136
+ * Whether the crate <composant> plays tests: a folder `tests/`, its integration tests, or a unit
137
+ * test file under `src/`.
138
+ */
104
139
  export function joueDesTests(_racine, composant) {
105
140
  const d = path.join(composant.dossier, 'tests');
106
- return existsSync(d) && statSync(d).isDirectory();
141
+ if (existsSync(d) && statSync(d).isDirectory()) {
142
+ return true;
143
+ }
144
+ const src = path.join(composant.dossier, 'src');
145
+ if (!existsSync(src)) {
146
+ return false;
147
+ }
148
+ return readdirSync(src, { recursive: true, withFileTypes: true }).some(
149
+ e =>
150
+ e.isFile() &&
151
+ unitaire(['src', ...path.relative(src, path.join(e.parentPath, e.name)).split(path.sep)])
152
+ );
107
153
  }
108
154
 
109
155
  /**
@@ -193,5 +239,180 @@ export function estUnTest(chemin, racine) {
193
239
  (parts.length === 3 && parts[2] === 'main.rs');
194
240
  return { joue, test: true, matiere };
195
241
  }
242
+ // The unit tests near their module, compiled with it: `tests.rs`, the files of `tests/`.
243
+ if (unitaire(parts)) {
244
+ return { joue: parts.at(-1).endsWith('.rs'), test: true, matiere };
245
+ }
196
246
  return matiere ? { joue: false, test: false, matiere: true } : null;
197
247
  }
248
+
249
+ // The tables of a manifest that declare what its tests depend on.
250
+ const DES_TESTS = 'dev-dependencies';
251
+
252
+ // The table <t> of a parsed manifest, an object; {} for any other value.
253
+ const table = t => (t !== null && typeof t === 'object' && !Array.isArray(t) ? t : {});
254
+
255
+ // The parts of the parsed manifests <a> and <b> that differ, out of the tables of the tests: each
256
+ // `[<table>]` (`[target.<cible>.<table>]` under `target`), a key out of every table bare.
257
+ function partiesHors(a, b) {
258
+ const cles = (x, y) => [...new Set([...Object.keys(x), ...Object.keys(y)])].sort();
259
+ const out = [];
260
+ for (const k of cles(a, b)) {
261
+ if (k === DES_TESTS || isDeepStrictEqual(a[k], b[k])) continue;
262
+ if (k !== 'target') {
263
+ const tableau = [a[k], b[k]].some(v => v !== null && typeof v === 'object');
264
+ out.push(tableau ? `[${k}]` : k);
265
+ continue;
266
+ }
267
+ const [ta, tb] = [table(a.target), table(b.target)];
268
+ for (const c of cles(ta, tb)) {
269
+ const [ca, cb] = [table(ta[c]), table(tb[c])];
270
+ for (const s of cles(ca, cb)) {
271
+ if (s !== DES_TESTS && !isDeepStrictEqual(ca[s], cb[s])) out.push(`[target.${c}.${s}]`);
272
+ }
273
+ }
274
+ }
275
+ return out;
276
+ }
277
+
278
+ // The head of the test module, `#[cfg(test)]`, other attributes after it, then `mod tests`.
279
+ const TETE = String.raw`#\[cfg\(test\)\](?:\s*#\[[^\]\n]*\])*\s*(?:pub(?:\([^)]*\))?\s+)?mod\s+tests\s*`;
280
+
281
+ // The declaration of the test module in a file of code, `#[cfg(test)] mod tests;`, its lines and
282
+ // the blank line before them.
283
+ const DECLARATION = new RegExp(String.raw`(?:^\r?\n)?^[ \t]*${TETE};[ \t]*(?:\r?\n|$)`, 'gm');
284
+
285
+ // The head of an inline test module, `#[cfg(test)] mod tests {`.
286
+ const EN_LIGNE = new RegExp(String.raw`^[ \t]*${TETE}\{`, 'm');
287
+
288
+ // The lexemes of Rust whose braces and quotes are no code, each a sticky expression from its
289
+ // start: a raw string (`r#"…"#`, `br`, `cr`, its hashes captured), a string (`"…"`, `b"`, `c"`),
290
+ // a character or a byte (`'{'`, `b'{'`, `'\''`, `'\u{7B}'`); a lifetime (`'a`) is none.
291
+ const BRUTE = /(?<![\w])[bc]?r(#*)"/y;
292
+ const CHAINE = /(?<![\w])[bc]?"(?:\\[\s\S]|[^\\"])*"/y;
293
+ const CARACTERE = /(?<![\w])b?'(?:\\u\{[0-9a-fA-F]{1,6}\}|\\x[0-9a-fA-F]{2}|\\[\s\S]|[^\\'\n])'/y;
294
+
295
+ // The end of the lexeme of <texte> that starts at <i> and holds no code (a comment, nested ones
296
+ // included, a string, a character), its index past it; null when code starts at <i>. A lexeme
297
+ // left open ends with the text.
298
+ function finDuLexeme(texte, i) {
299
+ if (texte.startsWith('//', i)) {
300
+ const fin = texte.indexOf('\n', i);
301
+ return fin < 0 ? texte.length : fin;
302
+ }
303
+ if (texte.startsWith('/*', i)) {
304
+ let profondeur = 0;
305
+ for (let j = i; j < texte.length; j++) {
306
+ if (texte.startsWith('/*', j)) {
307
+ profondeur++;
308
+ j++;
309
+ } else if (texte.startsWith('*/', j)) {
310
+ j++;
311
+ if (--profondeur === 0) return j + 1;
312
+ }
313
+ }
314
+ return texte.length;
315
+ }
316
+ for (const re of [BRUTE, CHAINE, CARACTERE]) {
317
+ re.lastIndex = i;
318
+ const m = re.exec(texte);
319
+ if (!m) continue;
320
+ if (re !== BRUTE) return m.index + m[0].length;
321
+ const fin = texte.indexOf(`"${m[1]}`, i + m[0].length);
322
+ return fin < 0 ? texte.length : fin + 1 + m[1].length;
323
+ }
324
+ return null;
325
+ }
326
+
327
+ // The inline test module of the Rust text <texte>, from its attribute to its closing brace and the
328
+ // end of that line, with the blank line before it; null for none, or for one never closed. The
329
+ // braces of a comment, a string or a character do not count.
330
+ function moduleEnLigne(texte) {
331
+ const m = EN_LIGNE.exec(texte);
332
+ if (!m) {
333
+ return null;
334
+ }
335
+ let profondeur = 0;
336
+ let i = m.index + m[0].length - 1;
337
+ while (i < texte.length) {
338
+ const fin = finDuLexeme(texte, i);
339
+ if (fin !== null) {
340
+ i = fin;
341
+ continue;
342
+ }
343
+ if (texte[i] === '{') {
344
+ profondeur++;
345
+ } else if (texte[i] === '}' && --profondeur === 0) {
346
+ const ligne = texte.indexOf('\n', i);
347
+ const debut = /\n\r?\n$/.test(texte.slice(0, m.index))
348
+ ? texte.lastIndexOf('\n', m.index - 2) + 1
349
+ : m.index;
350
+ return texte.slice(debut, ligne < 0 ? texte.length : ligne + 1);
351
+ }
352
+ i++;
353
+ }
354
+ return null;
355
+ }
356
+
357
+ /**
358
+ * The parts of a file of code of a crate that change from <avant> (null: no file) to <apres> out
359
+ * of its test module: the declaration `#[cfg(test)] mod tests;` added or removed, an inline
360
+ * `#[cfg(test)] mod tests { … }` removed, as the testwriter moves it into tests.rs. The lines
361
+ * compare as they are, the module's blank line before it apart.
362
+ */
363
+ function codeHorsDuModuleDeTest(avant, apres) {
364
+ const [a, b] = [(avant ?? '').replace(DECLARATION, ''), apres.replace(DECLARATION, '')];
365
+ const [ma, mb] = [moduleEnLigne(a), moduleEnLigne(b)];
366
+ if (mb !== null && mb !== ma) {
367
+ return ['le module de test en ligne, qui va dans tests.rs'];
368
+ }
369
+ const lignes = (texte, m) => (m === null ? texte : texte.replace(m, '')).split('\n');
370
+ const [la, lb] = [lignes(a, ma), lignes(b, mb)];
371
+ const n = Array.from({ length: Math.max(la.length, lb.length) }, (_, k) => k).find(
372
+ k => la[k] !== lb[k]
373
+ );
374
+ if (n === undefined) {
375
+ return [];
376
+ }
377
+ const ligne = (lb[n] ?? la[n]).trim();
378
+ return [`le code hors du module de test (« ${ligne || 'une ligne vide'} »)`];
379
+ }
380
+
381
+ /**
382
+ * The parts of a file of a crate at <chemin> (absolute, or from <racine>) that change from
383
+ * <avant> (null: no file) to <apres> out of the part of its tests: of its Cargo.toml, the tables
384
+ * of its tests; of a file of code of its `src/`, its test module. Null for any other file.
385
+ * @param {string} chemin
386
+ * @param {string} racine
387
+ * @param {string | null} avant
388
+ * @param {string} apres
389
+ */
390
+ function horsDesTests(chemin, racine, avant, apres) {
391
+ const abs = path.resolve(racine, chemin);
392
+ const tous = crates(racine);
393
+ if (abs.endsWith('.rs')) {
394
+ const c = composantDans(
395
+ tous.map(x => x.composant),
396
+ racine,
397
+ abs
398
+ );
399
+ const parts = c ? path.relative(c.dossier, abs).split(path.sep) : [];
400
+ return parts[0] === 'src' && !unitaire(parts) ? codeHorsDuModuleDeTest(avant, apres) : null;
401
+ }
402
+ if (path.basename(abs) !== 'Cargo.toml') return null;
403
+ if (!tous.some(c => path.join(c.composant.dossier, 'Cargo.toml') === abs)) return null;
404
+ const { parse } = require('smol-toml');
405
+ const lire = texte => {
406
+ try {
407
+ return { valeur: parse(texte ?? '') };
408
+ } catch (e) {
409
+ return { faute: `le manifeste entier, illisible (${e.message.split('\n')[0]})` };
410
+ }
411
+ };
412
+ const [a, b] = [lire(avant), lire(apres)];
413
+ if (a.faute || b.faute) return [a.faute ?? b.faute];
414
+ return partiesHors(a.valeur, b.valeur);
415
+ }
416
+
417
+ /** What the testwriter writes of the manifests (scripts/jointure.d.ts, `manifestes`). */
418
+ export const manifestes = { verrous: ['Cargo.lock'], horsDesTests };