@roomi-fields/grillhouse 0.28.2 → 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.
- package/.claude-plugin/plugin.json +1 -1
- package/bin/grillhouse.mjs +55 -14
- package/cadre/templates/projet/CLAUDE.md +1 -1
- package/cadre/templates/projet/README.md +11 -11
- package/cadre/templates/projet/_gitignore +2 -5
- package/charte.md +24 -3
- package/docs/ARCHITECTURE.md +279 -31
- package/docs/INTERFACE.md +59 -11
- package/package.json +1 -1
- package/scripts/aiguillage.mjs +324 -0
- package/scripts/avancement.mjs +33 -50
- package/scripts/circuit.mjs +558 -146
- package/scripts/composition-des-langages.mjs +16 -1
- package/scripts/conformite.mjs +16 -0
- package/scripts/copies-finies.mjs +181 -29
- package/scripts/demon.mjs +134 -21
- package/scripts/enveloppe/enveloppe.mjs +8 -5
- package/scripts/enveloppe/lancer.sh +24 -15
- package/scripts/enveloppe/travail-de-la-copie.mjs +94 -11
- package/scripts/etapes.mjs +1 -1
- package/scripts/fusion-du-changelog.mjs +0 -1
- package/scripts/grillhouse-maj.mjs +16 -7
- package/scripts/integration/file.mjs +3 -3
- package/scripts/integration/integrer.mjs +3 -3
- package/scripts/jointure.d.ts +53 -17
- package/scripts/langages/cargo/commandes.mjs +152 -25
- package/scripts/langages/cargo/composants.mjs +94 -2
- package/scripts/langages/cargo/exemples.mjs +68 -1
- package/scripts/langages/cargo/index.mjs +21 -10
- package/scripts/langages/cargo/migrations/0.28.4-tailles-des-tests.mjs +35 -0
- package/scripts/langages/cargo/sccache.mjs +89 -6
- package/scripts/langages/cargo/squelette.mjs +72 -3
- package/scripts/langages/cargo/tailles-des-tests.mjs +195 -0
- package/scripts/langages/cargo/tests-de-head.mjs +159 -0
- package/scripts/langages/python/commandes.mjs +53 -9
- package/scripts/langages/python/composants.mjs +33 -3
- package/scripts/langages/python/exemples.mjs +19 -0
- package/scripts/langages/python/index.mjs +7 -2
- package/scripts/langages/python/squelette.mjs +119 -17
- package/scripts/langages/typescript/exemples.mjs +16 -0
- package/scripts/langages/typescript/index.mjs +6 -3
- package/scripts/langages/typescript/regle-des-tests.mjs +13 -0
- package/scripts/langages/typescript/squelette.mjs +18 -2
- package/scripts/langages/typescript/tests-de-nuit.mjs +50 -20
- package/scripts/langages/typescript/verifier.mjs +82 -288
- package/scripts/langages/typescript/vitest-config/base.mjs +8 -9
- package/scripts/langages/typescript/vitest-config/cibles.mjs +92 -53
- package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +11 -5
- package/scripts/langages/typescript/vitest-config/machine.setup.mjs +6 -1
- package/scripts/langages/typescript/vitest-config/mesure.mjs +3 -2
- package/scripts/langages/typescript/vitest.nuit.config.mjs +18 -13
- package/scripts/lecture-unique.mjs +51 -0
- package/scripts/mesure/base-de-passe.mjs +202 -9
- package/scripts/mesure/pression.mjs +9 -7
- package/scripts/nuit.sh +19 -12
- package/scripts/outil.mjs +72 -0
- package/scripts/paquet.mjs +39 -10
- package/scripts/resultats.mjs +22 -5
- package/scripts/services-du-noyau.mjs +16 -10
- package/scripts/session-start.sh +10 -1
- package/scripts/sortie.mjs +20 -1
- package/scripts/sources.mjs +3 -3
- package/scripts/sous-commandes.mjs +2 -0
- package/scripts/superviseur.mjs +369 -14
- package/scripts/tableau.mjs +219 -58
- package/scripts/verrou-de-machine.mjs +425 -37
- package/skills/developpeur/SKILL.md +11 -3
- package/skills/pitmaster/SKILL.md +64 -23
- package/skills/pitmaster/references/consigne-agent.md +4 -0
- package/skills/relecteur/SKILL.md +18 -6
- package/skills/testwriter/SKILL.md +11 -15
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// From 0.28.4 the guard of the sizes of the tests in Rust (scripts/langages/cargo/tailles-des-tests.mjs)
|
|
2
|
+
// refuses a large test of the day, one that mounts a trial repository and starts the product
|
|
3
|
+
// there, as the module typescript's guard does since 0.25.0. A project of cargo that updates may
|
|
4
|
+
// hold such tests already (SyntHub, OSC Bridge), and its main would turn red at its next pass. As
|
|
5
|
+
// the module typescript's migration (../../typescript/migrations/0.25.0-tailles-des-tests.mjs) and
|
|
6
|
+
// ESLint's `--suppress-all` do once at the passage of a rule, the update inscribes them as the
|
|
7
|
+
// project's known debt (scripts/dette.mjs), frozen: the count never rises, a new large test of the
|
|
8
|
+
// day is refused, and its verification does not change that day.
|
|
9
|
+
//
|
|
10
|
+
// - The migration writes the section of the guard in `grillhouse-dette.json` when the guard finds a
|
|
11
|
+
// large test of the day and the file holds no section of it yet; the rest of the debt stays.
|
|
12
|
+
// - It rewrites no test of the project: the project moves each one to the night
|
|
13
|
+
// (`tests/<nom>_nuit.rs`) or reduces it, and the debt comes down with it.
|
|
14
|
+
// - Replayable without effect: once the section is written, nothing (a debt lowered since never
|
|
15
|
+
// rises again).
|
|
16
|
+
import { FICHIER, lire, trancher } from '../../../dette.mjs';
|
|
17
|
+
import { GARDE, verifier } from '../tailles-des-tests.mjs';
|
|
18
|
+
|
|
19
|
+
export const version = '0.28.4';
|
|
20
|
+
export const nom = 'tailles des tests';
|
|
21
|
+
|
|
22
|
+
/** Inscribes the large tests of the day of the project at <projet> in its debt; what it did. */
|
|
23
|
+
export function migrer(projet) {
|
|
24
|
+
if (lire(projet)[GARDE]) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
const constats = verifier(projet);
|
|
28
|
+
if (constats.length === 0) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
trancher(projet, GARDE, constats, 'inscrire', {});
|
|
32
|
+
return [
|
|
33
|
+
`${FICHIER} : ${constats.length} grand(s) test(s) de jour inscrit(s) dans la dette de ${GARDE}, gelée ; un grand test de jour neuf est refusé, et chacun passe à la nuit (tests/<nom>_nuit.rs) ou se réduit`,
|
|
34
|
+
];
|
|
35
|
+
}
|
|
@@ -2,8 +2,24 @@
|
|
|
2
2
|
// (`RUSTC_WRAPPER=sccache`) that Firefox and the CI of Rust use, which the update installs
|
|
3
3
|
// (./binaires.json). Each copy keeps its own target directory, so that two compilations never wait
|
|
4
4
|
// on the lock cargo takes on a target directory; sccache shares their compilations, its cache one
|
|
5
|
-
// directory of the home (`SCCACHE_DIR`, ~/.cache/sccache,
|
|
6
|
-
//
|
|
5
|
+
// directory of the home (`SCCACHE_DIR`, ~/.cache/grillhouse/sccache, the frame's caches of
|
|
6
|
+
// compilation, `cacheDeCompilation` of scripts/mesure/base-de-passe.mjs, named so that the envelope
|
|
7
|
+
// opens the same, ./index.mjs `sorties`), common to every copy of the machine.
|
|
8
|
+
// - A workspace rooted in the temporary directory (a project of trial) builds out of it: its
|
|
9
|
+
// target directory is `CARGO_TARGET_DIR`, a cache of the root under ~/.cache/grillhouse/cargo/
|
|
10
|
+
// (`cacheDeLaRacine`), swept once the root is gone, as Bazel keeps its output_base under
|
|
11
|
+
// ~/.cache and never on a disk in memory; a `CARGO_TARGET_DIR` already set stays
|
|
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.
|
|
7
23
|
// Every command of the module that compiles (tests, verification, typing, clippy) runs cargo
|
|
8
24
|
// under this environment, in a copy as in an agent's envelope.
|
|
9
25
|
//
|
|
@@ -37,12 +53,17 @@ import { accessSync, constants, readFileSync, readlinkSync, realpathSync } from
|
|
|
37
53
|
import { createRequire } from 'node:module';
|
|
38
54
|
import { homedir } from 'node:os';
|
|
39
55
|
import path from 'node:path';
|
|
56
|
+
import { cacheDeCompilation, cacheDeLaRacine, dansLeTemporaire } from '../../services-du-noyau.mjs';
|
|
40
57
|
|
|
41
58
|
// The loader of smol-toml, an optional peer of the package, a tool of this module.
|
|
42
59
|
const require = createRequire(import.meta.url);
|
|
43
60
|
|
|
44
61
|
/** The cache of sccache, from the home: what the envelope opens in writing. */
|
|
45
|
-
export const CACHE = '~/.cache/sccache/';
|
|
62
|
+
export const CACHE = '~/.cache/grillhouse/sccache/';
|
|
63
|
+
|
|
64
|
+
/** The targets of the workspaces rooted in the temporary directory, from the home: what the
|
|
65
|
+
* envelope opens in writing (`cibleDeCompilation`). */
|
|
66
|
+
export const CIBLES = '~/.cache/grillhouse/cargo/';
|
|
46
67
|
|
|
47
68
|
// The machine's temporary directory, short whatever the copy: the one the server of sccache starts
|
|
48
69
|
// under (`demarrerLeServeur`), an empty one proper to the session in an envelope.
|
|
@@ -152,21 +173,83 @@ export function demarrerLeServeur(racine, env) {
|
|
|
152
173
|
});
|
|
153
174
|
}
|
|
154
175
|
|
|
176
|
+
/**
|
|
177
|
+
* The target directory of the workspace at <racine> under <env>, out of the temporary directory:
|
|
178
|
+
* `{ CARGO_TARGET_DIR }`, a cache of the root (`cacheDeLaRacine`), for a root in the temporary
|
|
179
|
+
* directory; nothing otherwise, or when <env> sets one already. With `creer` false, a reading
|
|
180
|
+
* (`cargo metadata`): the path alone, nothing written.
|
|
181
|
+
* @param {string} racine
|
|
182
|
+
* @param {NodeJS.ProcessEnv} env
|
|
183
|
+
* @param {{ creer?: boolean }} [options]
|
|
184
|
+
* @returns {{ CARGO_TARGET_DIR?: string }}
|
|
185
|
+
*/
|
|
186
|
+
export function cibleDeCompilation(racine, env, { creer = true } = {}) {
|
|
187
|
+
if (env.CARGO_TARGET_DIR || !dansLeTemporaire(racine, env)) {
|
|
188
|
+
return {};
|
|
189
|
+
}
|
|
190
|
+
return { CARGO_TARGET_DIR: cacheDeLaRacine('cargo', racine, env, { creer }) };
|
|
191
|
+
}
|
|
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
|
+
|
|
155
231
|
/**
|
|
156
232
|
* <env> with rustc wrapped by sccache for the copy at <racine>, its cache the home's, its server
|
|
157
|
-
* the copy's
|
|
233
|
+
* the copy's, its target out of the temporary directory (`cibleDeCompilation`); without sccache
|
|
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`).
|
|
158
236
|
* @param {string} racine
|
|
159
237
|
* @param {NodeJS.ProcessEnv} env
|
|
160
238
|
* @returns {NodeJS.ProcessEnv}
|
|
161
239
|
*/
|
|
162
240
|
export function avecSccache(racine, env) {
|
|
241
|
+
const cible = {
|
|
242
|
+
...cibleDeCompilation(racine, env),
|
|
243
|
+
...(incrementalDecide(racine, env) ? {} : { CARGO_INCREMENTAL: '0' }),
|
|
244
|
+
};
|
|
163
245
|
if (lanceurDuProjet(racine, env)) {
|
|
164
|
-
return env;
|
|
246
|
+
return { ...env, ...cible };
|
|
165
247
|
}
|
|
166
248
|
return {
|
|
167
249
|
...env,
|
|
250
|
+
...cible,
|
|
168
251
|
RUSTC_WRAPPER: 'sccache',
|
|
169
|
-
SCCACHE_DIR:
|
|
252
|
+
SCCACHE_DIR: cacheDeCompilation('sccache', env),
|
|
170
253
|
SCCACHE_SERVER_UDS: socketDuServeur(racine),
|
|
171
254
|
};
|
|
172
255
|
}
|
|
@@ -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 {
|
|
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
|
+
}
|