@roomi-fields/grillhouse 0.28.3 → 0.29.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 (68) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/bin/grillhouse.mjs +55 -14
  3. package/cadre/templates/projet/CLAUDE.md +1 -1
  4. package/cadre/templates/projet/README.md +11 -11
  5. package/cadre/templates/projet/_gitignore +2 -5
  6. package/charte.md +13 -4
  7. package/docs/ARCHITECTURE.md +260 -29
  8. package/docs/INTERFACE.md +51 -12
  9. package/package.json +1 -1
  10. package/scripts/aiguillage.mjs +324 -0
  11. package/scripts/avancement.mjs +33 -50
  12. package/scripts/circuit.mjs +558 -146
  13. package/scripts/composition-des-langages.mjs +16 -1
  14. package/scripts/conformite.mjs +16 -0
  15. package/scripts/copies-finies.mjs +171 -30
  16. package/scripts/demon.mjs +134 -21
  17. package/scripts/enveloppe/lancer.sh +13 -14
  18. package/scripts/enveloppe/travail-de-la-copie.mjs +94 -11
  19. package/scripts/etapes.mjs +1 -1
  20. package/scripts/fusion-du-changelog.mjs +0 -1
  21. package/scripts/grillhouse-maj.mjs +16 -7
  22. package/scripts/integration/file.mjs +3 -3
  23. package/scripts/integration/integrer.mjs +3 -3
  24. package/scripts/jointure.d.ts +39 -17
  25. package/scripts/langages/cargo/commandes.mjs +152 -25
  26. package/scripts/langages/cargo/composants.mjs +90 -2
  27. package/scripts/langages/cargo/exemples.mjs +68 -1
  28. package/scripts/langages/cargo/index.mjs +17 -8
  29. package/scripts/langages/cargo/migrations/0.28.4-tailles-des-tests.mjs +35 -0
  30. package/scripts/langages/cargo/sccache.mjs +54 -2
  31. package/scripts/langages/cargo/squelette.mjs +72 -3
  32. package/scripts/langages/cargo/tailles-des-tests.mjs +195 -0
  33. package/scripts/langages/cargo/tests-de-head.mjs +159 -0
  34. package/scripts/langages/python/commandes.mjs +44 -7
  35. package/scripts/langages/python/composants.mjs +33 -3
  36. package/scripts/langages/python/exemples.mjs +19 -0
  37. package/scripts/langages/python/index.mjs +4 -0
  38. package/scripts/langages/python/squelette.mjs +119 -17
  39. package/scripts/langages/typescript/exemples.mjs +16 -0
  40. package/scripts/langages/typescript/index.mjs +6 -3
  41. package/scripts/langages/typescript/regle-des-tests.mjs +13 -0
  42. package/scripts/langages/typescript/squelette.mjs +18 -2
  43. package/scripts/langages/typescript/tests-de-nuit.mjs +41 -21
  44. package/scripts/langages/typescript/verifier.mjs +82 -288
  45. package/scripts/langages/typescript/vitest-config/base.mjs +8 -9
  46. package/scripts/langages/typescript/vitest-config/cibles.mjs +92 -53
  47. package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +11 -5
  48. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +4 -2
  49. package/scripts/langages/typescript/vitest-config/mesure.mjs +3 -2
  50. package/scripts/langages/typescript/vitest.nuit.config.mjs +18 -13
  51. package/scripts/lecture-unique.mjs +51 -0
  52. package/scripts/mesure/pression.mjs +9 -7
  53. package/scripts/nuit.sh +19 -12
  54. package/scripts/outil.mjs +72 -0
  55. package/scripts/paquet.mjs +39 -10
  56. package/scripts/resultats.mjs +22 -5
  57. package/scripts/services-du-noyau.mjs +8 -9
  58. package/scripts/session-start.sh +10 -1
  59. package/scripts/sortie.mjs +20 -1
  60. package/scripts/sources.mjs +3 -3
  61. package/scripts/sous-commandes.mjs +1 -0
  62. package/scripts/superviseur.mjs +369 -14
  63. package/scripts/tableau.mjs +219 -58
  64. package/scripts/verrou-de-machine.mjs +303 -58
  65. package/skills/developpeur/SKILL.md +11 -3
  66. package/skills/pitmaster/SKILL.md +58 -23
  67. package/skills/relecteur/SKILL.md +18 -6
  68. package/skills/testwriter/SKILL.md +11 -15
@@ -10,6 +10,16 @@
10
10
  // (`cacheDeLaRacine`), swept once the root is gone, as Bazel keeps its output_base under
11
11
  // ~/.cache and never on a disk in memory; a `CARGO_TARGET_DIR` already set stays
12
12
  // (`cibleDeCompilation`).
13
+ // - Cargo compiles without incremental compilation (`CARGO_INCREMENTAL=0`), as the CI of Rust and
14
+ // the usual continuous integrations do: a copy of a ticket compiles once and seldom again, and
15
+ // its `target/debug/incremental` held up to 1.1 GB of a target of 5.0 GB (SyntHub, SH-ae6.2.7,
16
+ // grillhouse-k5y); sccache caches no incremental compilation either. Whoever decides it keeps
17
+ // it, as cargo reads it, which lets each of them override every profile: the caller, by
18
+ // `CARGO_INCREMENTAL` (an agent or a person who debugs, `CARGO_INCREMENTAL=1`),
19
+ // `CARGO_BUILD_INCREMENTAL` or a `CARGO_PROFILE_<nom>_INCREMENTAL` of the environment; the
20
+ // project, by `incremental` in a `[profile.*]` of its Cargo.toml, or `build.incremental` or a
21
+ // profile of a `.cargo/config.toml` from the project up to the root, then of `$CARGO_HOME`. The
22
+ // frame writes no other setting of a profile.
13
23
  // Every command of the module that compiles (tests, verification, typing, clippy) runs cargo
14
24
  // under this environment, in a copy as in an agent's envelope.
15
25
  //
@@ -180,16 +190,58 @@ export function cibleDeCompilation(racine, env, { creer = true } = {}) {
180
190
  return { CARGO_TARGET_DIR: cacheDeLaRacine('cargo', racine, env, { creer }) };
181
191
  }
182
192
 
193
+ // Whether a TOML document <toml> sets `incremental` in one of its profiles (`[profile.<nom>]`),
194
+ // or, with <build>, in its `[build]` table.
195
+ const poseLIncremental = (toml, build) =>
196
+ Object.values(toml?.profile ?? {}).some(p => p && Object.hasOwn(p, 'incremental')) ||
197
+ (build && Object.hasOwn(toml?.build ?? {}, 'incremental'));
198
+
199
+ // Whether the caller or the project at <racine> under <env> decides incremental compilation, as
200
+ // cargo reads it (see the header): the environment (`CARGO_INCREMENTAL`, `CARGO_BUILD_INCREMENTAL`,
201
+ // a `CARGO_PROFILE_<nom>_INCREMENTAL`), the profiles of the Cargo.toml at <racine>, then
202
+ // `build.incremental` and the profiles of each `.cargo/config.toml` (or `.cargo/config`).
203
+ function incrementalDecide(racine, env) {
204
+ if (
205
+ Object.keys(env).some(
206
+ k =>
207
+ k === 'CARGO_INCREMENTAL' ||
208
+ k === 'CARGO_BUILD_INCREMENTAL' ||
209
+ /^CARGO_PROFILE_\w+_INCREMENTAL$/.test(k)
210
+ )
211
+ ) {
212
+ return true;
213
+ }
214
+ const { parse } = require('smol-toml');
215
+ const lu = f => {
216
+ try {
217
+ return parse(readFileSync(f, 'utf8'));
218
+ } catch {
219
+ // An absent or unreadable file decides nothing.
220
+ return null;
221
+ }
222
+ };
223
+ if (poseLIncremental(lu(path.join(racine, 'Cargo.toml')), false)) {
224
+ return true;
225
+ }
226
+ return dossiersDeConfiguration(racine, env).some(d =>
227
+ ['config.toml', 'config'].some(nom => poseLIncremental(lu(path.join(d, nom)), true))
228
+ );
229
+ }
230
+
183
231
  /**
184
232
  * <env> with rustc wrapped by sccache for the copy at <racine>, its cache the home's, its server
185
233
  * the copy's, its target out of the temporary directory (`cibleDeCompilation`); without sccache
186
- * when the project sets its own wrapper.
234
+ * when the project sets its own wrapper. Incremental compilation is off (`CARGO_INCREMENTAL=0`)
235
+ * unless the caller or the project decides it (`incrementalDecide`).
187
236
  * @param {string} racine
188
237
  * @param {NodeJS.ProcessEnv} env
189
238
  * @returns {NodeJS.ProcessEnv}
190
239
  */
191
240
  export function avecSccache(racine, env) {
192
- const cible = cibleDeCompilation(racine, env);
241
+ const cible = {
242
+ ...cibleDeCompilation(racine, env),
243
+ ...(incrementalDecide(racine, env) ? {} : { CARGO_INCREMENTAL: '0' }),
244
+ };
193
245
  if (lanceurDuProjet(racine, env)) {
194
246
  return { ...env, ...cible };
195
247
  }
@@ -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
+ }
@@ -19,9 +19,17 @@
19
19
  // and pytest plays that path alone; a path out of every package is refused, named, and nothing
20
20
  // plays (code 2). Without a path, every package that plays tests plays, or, under the circuit's
21
21
  // mark (`GRILLHOUSE_DEPUIS_LE_VERT`), the packages the changes since the last green touch
22
- // (./lot.mjs), every package when no last green counts; the night tests (`*_nuit_test.py`) are
23
- // left out (`--ignore-glob`), and a night test plays when its own file is named. `--force`
24
- // changes nothing: pytest keeps no result to replay. Another option goes to pytest.
22
+ // (./lot.mjs), every package when no last green counts. The night tests (`*_nuit_test.py`, the
23
+ // one class out of the day: Python has no time budget bench) are left out of every folder,
24
+ // played whole or named (`--ignore-glob`), and a night test plays when its own file is named,
25
+ // as the module cargo's: pytest never ignores a path named, and a folder named that holds a
26
+ // night file named gives its tests of the day file by file, since pytest would collect that
27
+ // file through the folder (grillhouse-1ic.1). `--force`
28
+ // changes nothing: pytest keeps no result to replay. Another option goes to pytest. A package
29
+ // played whole (no path, or its own folder named) whose pytest collects no test (code 5) is
30
+ // green, as `cargo test` on a crate without a test and the skeleton typescript's
31
+ // `passWithNoTests`; a path within the package that collects no test stays red, as a run whose
32
+ // paths name no test fails in every language.
25
33
  // - `verifier` plays, in each package the changes since the last green touch (every package with
26
34
  // `--tout`, or when no last green counts), the typing then the tests of the day; green, it keeps
27
35
  // the last green (scripts/dernier-vert.mjs). It plays under the lock of the machine
@@ -158,7 +166,8 @@ function passe(racine, env) {
158
166
  rapports[f] = dossierDuPaquet;
159
167
  return ['-o', 'junit_family=xunit1', `--junit-xml=${path.join(dossier, JUNIT, f)}`];
160
168
  },
161
- jouer({ t, args, cwd, programme }) {
169
+ // <vert>, the codes that count green beside 0.
170
+ jouer({ t, args, cwd, programme }, vert = []) {
162
171
  // The environment of uv of the package, at the root (`sorties` of ./index.mjs).
163
172
  const venv = path.join(racine, VENV, path.relative(racine, cwd));
164
173
  const r = spawnSync(programme, args, {
@@ -170,6 +179,9 @@ function passe(racine, env) {
170
179
  process.stderr.write("⛔ uv absent du PATH : `npx grillhouse maj` l'installe.\n");
171
180
  }
172
181
  t.code = r.error ? 127 : (r.status ?? 128 + (constants.signals[r.signal] ?? 0));
182
+ if (vert.includes(t.code)) {
183
+ t.code = 0;
184
+ }
173
185
  ecrire();
174
186
  return t.code;
175
187
  },
@@ -184,16 +196,41 @@ function passe(racine, env) {
184
196
  }
185
197
 
186
198
  const UV_RUN = ['run', '--locked'];
199
+ // The code of pytest for « no tests collected », distinct from a failure (1).
200
+ const AUCUN_TEST = 5;
201
+
202
+ // The selection of pytest for the paths <chemins> of the package <c>, from its folder (empty: the
203
+ // whole package): the night left out of every folder (`--ignore-glob`), as the module cargo's;
204
+ // a night file named plays, pytest never ignoring a path named, unless a folder named holds it,
205
+ // through which pytest collects it: that folder then gives its tests of the day, file by file.
206
+ function selection(c, chemins) {
207
+ const nuits = chemins.filter(ch => estDeNuit(path.basename(ch)));
208
+ const tient = (d, f) => d !== f && !path.relative(d, f).startsWith('..');
209
+ const nommes = chemins.flatMap(ch => {
210
+ if (!nuits.some(n => tient(ch, n))) {
211
+ return [ch];
212
+ }
213
+ return fichiersDeTest(path.join(c.dossier, ch))
214
+ .filter(f => !estDeNuit(path.basename(f)))
215
+ .map(f => path.relative(c.dossier, f));
216
+ });
217
+ return [`--ignore-glob=${DE_NUIT}`, ...nommes];
218
+ }
187
219
 
188
220
  // Plays pytest in the run <p> for each `{ c, chemins }` of <choix>, `chemins` from the package's
189
- // folder (empty: the whole package, the night left out), <options> given to pytest.
221
+ // folder (empty: the whole package), the night left out (`selection`), <options> given to pytest.
222
+ // The package played whole (no path, or its own folder) that collects no test is green, as
223
+ // `cargo test` on a crate without a test; a path within it that collects none stays red.
190
224
  function jouerLesTests(p, choix, options) {
191
225
  for (const { c, chemins } of choix) {
192
- const selection = chemins.length ? chemins : [`--ignore-glob=${DE_NUIT}`];
193
226
  const cache = path.join(p.racine, CACHE_DE_PYTEST, path.relative(p.racine, c.dossier));
194
227
  const args = [...UV_RUN, '--group', GROUPE, 'pytest', '-o', `cache_dir=${cache}`];
195
228
  args.push(...p.junit(c.nom, c.dossier));
196
- p.jouer(p.prevoir(c.nom, c.dossier, 'pytest', true, [...args, ...selection, ...options]));
229
+ const entier = chemins.every(ch => ch === '.');
230
+ p.jouer(
231
+ p.prevoir(c.nom, c.dossier, 'pytest', true, [...args, ...selection(c, chemins), ...options]),
232
+ entier ? [AUCUN_TEST] : []
233
+ );
197
234
  }
198
235
  }
199
236