@roomi-fields/grillhouse 0.24.14 → 0.25.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 +40 -12
- package/cadre/templates/cargo/.config/nextest.toml +8 -0
- package/cadre/templates/cargo/deny.toml +36 -0
- package/cadre/templates/cargo/package.json +15 -0
- package/cadre/templates/cargo/rust-toolchain.toml +6 -0
- package/cadre/templates/projet/package.json +5 -1
- package/cadre/templates/turbo/paquets.json +1 -1
- package/cadre/templates/turbo/sans-paquets.json +1 -1
- package/charte.md +16 -0
- package/docs/ARCHITECTURE.md +167 -17
- package/docs/CADRE.md +47 -0
- package/docs/INTERFACE.md +168 -0
- package/package.json +71 -14
- package/scripts/arbitrages.mjs +23 -0
- package/scripts/avancement.mjs +15 -29
- package/scripts/circuit.mjs +89 -97
- package/scripts/commande-du-langage.mjs +56 -0
- package/scripts/composants-affectes.mjs +47 -170
- package/scripts/conformite.d.ts +27 -0
- package/scripts/conformite.mjs +226 -0
- package/scripts/demon.mjs +1 -1
- package/scripts/dernier-vert.mjs +11 -9
- package/scripts/droits.mjs +27 -21
- package/scripts/enveloppe/enveloppe.mjs +206 -64
- package/scripts/enveloppe/lancer.sh +24 -75
- package/scripts/enveloppe/paquets-du-plan.mjs +24 -2
- package/scripts/etapes.mjs +2 -2
- package/scripts/gardes-du-cadre.mjs +12 -18
- package/scripts/grillhouse-maj.mjs +246 -389
- package/scripts/init.mjs +2 -1
- package/scripts/integration/file.mjs +3 -3
- package/scripts/integration/integrer.mjs +13 -10
- package/scripts/integration/rejeu.mjs +36 -7
- package/scripts/jointure.d.ts +304 -0
- package/scripts/langages/cargo/binaires.json +4 -0
- package/scripts/langages/cargo/binaires.mjs +60 -0
- package/scripts/langages/cargo/clippy.mjs +103 -0
- package/scripts/langages/cargo/commandes.mjs +378 -0
- package/scripts/langages/cargo/composants.mjs +191 -0
- package/scripts/langages/cargo/elements-du-lot.mjs +139 -0
- package/scripts/langages/cargo/exemples.mjs +357 -0
- package/scripts/langages/cargo/frontieres.mjs +84 -0
- package/scripts/langages/cargo/index-interfaces.mjs +138 -0
- package/scripts/langages/cargo/index.mjs +115 -0
- package/scripts/langages/cargo/mise-a-jour.mjs +93 -0
- package/scripts/langages/cargo/nextest.toml +5 -0
- package/scripts/langages/cargo/touches.mjs +93 -0
- package/scripts/langages/cargo/verdict.mjs +85 -0
- package/scripts/langages/typescript/chemins-des-tests.mjs +68 -0
- package/scripts/{code-mort.mjs → langages/typescript/code-mort.mjs} +5 -5
- package/scripts/langages/typescript/composants.mjs +64 -0
- package/scripts/{consommateurs-arbitres.mjs → langages/typescript/consommateurs-arbitres.mjs} +6 -24
- package/scripts/{consommateurs.mjs → langages/typescript/consommateurs.mjs} +13 -71
- package/scripts/langages/typescript/construire.mjs +176 -0
- package/scripts/{elements-du-lot.mjs → langages/typescript/elements-du-lot.mjs} +2 -2
- package/scripts/langages/typescript/exemples.mjs +289 -0
- package/scripts/{frontieres.mjs → langages/typescript/frontieres.mjs} +3 -5
- package/scripts/{index-interfaces.mjs → langages/typescript/index-interfaces.mjs} +3 -3
- package/scripts/langages/typescript/index.mjs +335 -0
- package/scripts/{interfaces-contre-code.mjs → langages/typescript/interfaces-contre-code.mjs} +2 -2
- package/scripts/langages/typescript/lecteurs.mjs +179 -0
- package/scripts/{migrations → langages/typescript/migrations}/0.23.0-config-vitest.mjs +14 -29
- package/scripts/{migrations → langages/typescript/migrations}/0.24.4-noms-declares-inutilises.mjs +2 -2
- package/scripts/{migrations → langages/typescript/migrations}/0.24.6-lignes-mal-formees.mjs +2 -2
- package/scripts/{migrations → langages/typescript/migrations}/0.24.7-matiere-dans-les-tests.mjs +2 -2
- package/scripts/langages/typescript/migrations/0.25.0-chemins-des-tests.mjs +27 -0
- package/scripts/langages/typescript/migrations/0.25.0-tailles-des-tests.mjs +31 -0
- package/scripts/langages/typescript/mise-a-jour.mjs +320 -0
- package/scripts/{references-par-les-types.mjs → langages/typescript/references-par-les-types.mjs} +3 -3
- package/scripts/langages/typescript/regle-des-tests.mjs +39 -0
- package/scripts/{resumes.mjs → langages/typescript/resumes.mjs} +4 -4
- package/scripts/langages/typescript/script-des-tests.mjs +6 -0
- package/scripts/langages/typescript/tailles-des-tests.mjs +219 -0
- package/scripts/langages/typescript/tests-de-nuit.mjs +57 -0
- package/scripts/{tests.mjs → langages/typescript/tests.mjs} +41 -32
- package/scripts/{turbo-des-paquets.mjs → langages/typescript/turbo-des-paquets.mjs} +61 -34
- package/scripts/langages/typescript/verdict.mjs +105 -0
- package/scripts/{verifier.mjs → langages/typescript/verifier.mjs} +53 -34
- package/scripts/{vitest-config → langages/typescript/vitest-config}/avancement.reporter.mjs +10 -2
- package/scripts/{vitest-config → langages/typescript/vitest-config}/base.mjs +63 -9
- package/scripts/{vitest-config → langages/typescript/vitest-config}/changements.mjs +18 -9
- package/scripts/{vitest-config → langages/typescript/vitest-config}/cibles.mjs +7 -6
- package/scripts/{vitest-config → langages/typescript/vitest-config}/duree.reporter.mjs +6 -1
- package/scripts/langages/typescript/vitest-config/lances.mjs +473 -0
- package/scripts/{vitest-config → langages/typescript/vitest-config}/mesure.setup.mjs +1 -1
- package/scripts/{vitest-config → langages/typescript/vitest-config}/resultats.mjs +5 -5
- package/scripts/{vitest-config → langages/typescript/vitest-config}/resultats.setup.mjs +4 -3
- package/scripts/{vitest.nuit.config.mjs → langages/typescript/vitest.nuit.config.mjs} +2 -2
- package/scripts/langages.mjs +85 -0
- package/scripts/{vitest-config → mesure}/avancement.mjs +4 -13
- package/scripts/{vitest-config → mesure}/base-de-passe.mjs +70 -33
- package/scripts/{vitest-config → mesure}/pression.mjs +5 -6
- package/scripts/migrations/0.23.2-copies-du-cadre.mjs +29 -6
- package/scripts/migrations/0.24.0-circuit-simplifie.mjs +13 -6
- package/scripts/migrations/0.25.0-script-des-tests.mjs +92 -0
- package/scripts/migrations.mjs +17 -13
- package/scripts/nuit.sh +59 -63
- package/scripts/paquets.d.ts +5 -0
- package/scripts/paquets.mjs +24 -2
- package/scripts/resultats.mjs +8 -82
- package/scripts/services-du-noyau.mjs +30 -0
- package/scripts/session-start.sh +17 -9
- package/scripts/sources.mjs +35 -13
- package/scripts/sous-commandes.mjs +57 -17
- package/scripts/superviseur.mjs +1 -1
- package/scripts/tableau.mjs +1 -1
- package/scripts/un-commit-par-ticket.mjs +48 -14
- package/scripts/verrou-de-fichier.mjs +1 -1
- package/scripts/verrou-de-machine.mjs +4 -4
- package/scripts/verrous/verrou.mjs +28 -37
- package/skills/developpeur/SKILL.md +2 -2
- package/skills/explorateur/SKILL.md +13 -5
- package/skills/grill/SKILL.md +2 -2
- package/skills/pitmaster/references/cadre.md +1 -1
- package/skills/pitmaster/references/consigne-agent.md +10 -3
- package/skills/redacteur/references/documents-d-un-composant.md +4 -4
- package/skills/relecteur/SKILL.md +4 -1
- package/skills/testwriter/SKILL.md +20 -6
- /package/scripts/{consommateurs.d.ts → langages/typescript/consommateurs.d.ts} +0 -0
- /package/scripts/{vitest-config → langages/typescript/vitest-config}/base.d.ts +0 -0
- /package/scripts/{vitest-config → langages/typescript/vitest-config}/machine.setup.mjs +0 -0
- /package/scripts/{vitest-config → langages/typescript/vitest-config}/mesure.d.ts +0 -0
- /package/scripts/{vitest-config → langages/typescript/vitest-config}/mesure.mjs +0 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The commands of the module cargo, the demand `commandes` of the join (scripts/jointure.d.ts):
|
|
3
|
+
// each one this script with its name first, `{ script, args }`, described, never run, by
|
|
4
|
+
// `commandes`; run by `grillhouse <commande>` in the root of the workspace, its arguments after.
|
|
5
|
+
//
|
|
6
|
+
// npx grillhouse tests [--force] [<chemin>…] [--<option>…] tester
|
|
7
|
+
// npx grillhouse verifier [--tout] verifier
|
|
8
|
+
// node commandes.mjs typer typer
|
|
9
|
+
// npx grillhouse preparer preparer
|
|
10
|
+
// npx grillhouse clippy | frontieres | index-interfaces each guard, its own script
|
|
11
|
+
//
|
|
12
|
+
// - Each guard of structure of the module (./clippy.mjs, ./frontieres.mjs, ./index-interfaces.mjs)
|
|
13
|
+
// is a command by its name too, its own script, as the module typescript's: the line of a red
|
|
14
|
+
// guard (`grillhouse <garde>`, scripts/gardes-du-cadre.mjs) names a command that exists.
|
|
15
|
+
// - `tester` plays the tests of each crate chosen, one crate after the other: `cargo nextest run
|
|
16
|
+
// -p <crate> --no-fail-fast` for a crate that plays tests (./composants.mjs, `joueDesTests`),
|
|
17
|
+
// then `cargo test --doc -p <crate>` for a crate whose library has doctests, which nextest does
|
|
18
|
+
// not play. A path, written from the root, chooses the crate that holds it; the source of a test
|
|
19
|
+
// target (`<crate>/tests/<nom>.rs`) plays that target alone (`--test <nom>`), without the
|
|
20
|
+
// doctests. A path out of every crate, or in a crate without tests, is refused, named, and
|
|
21
|
+
// nothing plays (code 2). Without a path, every crate plays, or, under the circuit's mark
|
|
22
|
+
// (`GRILLHOUSE_DEPUIS_LE_VERT`), the crates the changes since the last green touch and their
|
|
23
|
+
// dependents (./touches.mjs), every crate when no last green counts. `--force` changes nothing:
|
|
24
|
+
// cargo keeps no result of a test to replay. Another option goes to nextest.
|
|
25
|
+
// - `verifier` plays the tests of the crates the changes since the last green touch and of their
|
|
26
|
+
// dependents (every crate with `--tout`, or when no last green counts), as Turborepo's
|
|
27
|
+
// `--filter=...[<commit>]`, then `cargo deny check`; green, it keeps the last green
|
|
28
|
+
// (scripts/dernier-vert.mjs). It plays under the lock of the machine, one heavy measure at a
|
|
29
|
+
// time (`avecLaMachine` of ./jointure, as the module typescript's verifier): a measure that
|
|
30
|
+
// holds it makes it wait, and the bound of the wait reached, it stops at 75 without running
|
|
31
|
+
// cargo.
|
|
32
|
+
// - `tester` and `verifier` play under a temporary directory of their pass, the module's guard of
|
|
33
|
+
// the temporary directory, as the CI of osc-bridge (OB-ud1.3): a base (`ouvrirBase` of
|
|
34
|
+
// ./jointure, genre `tests` or `verification`) in the temporary directory of the environment,
|
|
35
|
+
// named in TMPDIR, TMP and TEMP to cargo, which nextest and the doctests inherit; removed at the
|
|
36
|
+
// end of the pass, green, red or interrupted (SIGINT, SIGTERM, SIGHUP). What the tests left there
|
|
37
|
+
// fails the pass (code 1), each name written on the error stream. A test makes its temporary
|
|
38
|
+
// directory or file with the crate `tempfile` (`TempDir`, `NamedTempFile`), removed when dropped,
|
|
39
|
+
// a failed test included, never a path built by hand under `std::env::temp_dir()`.
|
|
40
|
+
// - `typer`: `cargo check --all-targets`. `preparer`: `cargo fetch --locked`.
|
|
41
|
+
// - Nextest reads the frame's profile `grillhouse` (./nextest.toml, a tool's configuration under
|
|
42
|
+
// the project's own, `--tool-config-file`), whose JUnit report lands at
|
|
43
|
+
// `<target>/nextest/grillhouse/junit.xml`.
|
|
44
|
+
// - While the environment names a results directory (`GRILLHOUSE_RESULTATS`), the run writes
|
|
45
|
+
// there what ./verdict.mjs reads: its tasks, each planned before it plays (`code` null until it
|
|
46
|
+
// ran), and the JUnit report of each run of nextest. A task of the workspace is named after its
|
|
47
|
+
// root, `//`, as Turborepo names the root's tasks.
|
|
48
|
+
// - The exit code: 0 when every task is green, 75 when the only reds are « à repasser », 1
|
|
49
|
+
// otherwise; 2 for a path refused or a command unknown.
|
|
50
|
+
import { spawnSync } from 'node:child_process';
|
|
51
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
52
|
+
import { constants, tmpdir } from 'node:os';
|
|
53
|
+
import path from 'node:path';
|
|
54
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
55
|
+
import { RESULTATS } from '../../resultats.mjs';
|
|
56
|
+
import {
|
|
57
|
+
AttenteDeLaMachine,
|
|
58
|
+
avecLaMachine,
|
|
59
|
+
CHANGEMENTS,
|
|
60
|
+
DEPUIS_LE_VERT,
|
|
61
|
+
garderLeVert,
|
|
62
|
+
ligneDesRestes,
|
|
63
|
+
mesure,
|
|
64
|
+
ouvrirBase,
|
|
65
|
+
retirerALInterruption,
|
|
66
|
+
} from '../../services-du-noyau.mjs';
|
|
67
|
+
import { composantDans, crates, joueDesTests, metadonnees } from './composants.mjs';
|
|
68
|
+
import { touchesDesFichiers } from './touches.mjs';
|
|
69
|
+
import { JUNIT, TACHES } from './verdict.mjs';
|
|
70
|
+
|
|
71
|
+
const ICI = fileURLToPath(import.meta.url);
|
|
72
|
+
const NEXTEST = path.join(path.dirname(ICI), 'nextest.toml');
|
|
73
|
+
const PROFIL = 'grillhouse';
|
|
74
|
+
export const NOMS = ['tester', 'verifier', 'typer', 'preparer'];
|
|
75
|
+
const A_REPASSER = 75;
|
|
76
|
+
const RACINE = '//';
|
|
77
|
+
|
|
78
|
+
/** The guards of structure of the module, in the order they play: each its name, its script beside
|
|
79
|
+
* this one, and its arguments as a guard. */
|
|
80
|
+
export const GARDES = [
|
|
81
|
+
{ nom: 'clippy', args: [] },
|
|
82
|
+
{ nom: 'frontieres', args: [] },
|
|
83
|
+
{ nom: 'index-interfaces', args: ['--verifier'] },
|
|
84
|
+
].map(g => ({ ...g, script: path.join(path.dirname(ICI), `${g.nom}.mjs`) }));
|
|
85
|
+
|
|
86
|
+
/** The commands of the module, each this script and its name, described; then each guard, its
|
|
87
|
+
* script by its name, as `grillhouse <garde>` runs it and the line of a red guard names it. */
|
|
88
|
+
export const commandes = () =>
|
|
89
|
+
Object.fromEntries([
|
|
90
|
+
...NOMS.map(n => [n, { script: ICI, args: [n] }]),
|
|
91
|
+
...GARDES.map(g => [g.nom, { script: g.script, args: [] }]),
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
// The id of each test binary of nextest of <c>, its target's source: the library under the
|
|
95
|
+
// crate's name, the others as `<crate>::<nom>`, a binary, an example or a bench prefixed by kind.
|
|
96
|
+
function binaires(c) {
|
|
97
|
+
return Object.fromEntries(
|
|
98
|
+
c.cibles.map(t => {
|
|
99
|
+
const kind = t.kind[0];
|
|
100
|
+
if (kind === 'test') {
|
|
101
|
+
return [`${c.composant.nom}::${t.name}`, t.src];
|
|
102
|
+
}
|
|
103
|
+
if (['bin', 'example', 'bench'].includes(kind)) {
|
|
104
|
+
return [`${c.composant.nom}::${kind}/${t.name}`, t.src];
|
|
105
|
+
}
|
|
106
|
+
return [c.composant.nom, t.src];
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// The run of the tasks of a command in <racine>: each planned, then played by cargo, written in
|
|
112
|
+
// the results directory <env> names.
|
|
113
|
+
function passe(racine, env) {
|
|
114
|
+
const dossier = env[RESULTATS] || null;
|
|
115
|
+
const id = `${Date.now()}-${process.pid}`;
|
|
116
|
+
const taches = [];
|
|
117
|
+
const cibles = {};
|
|
118
|
+
const ecrire = () => {
|
|
119
|
+
if (!dossier) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
mkdirSync(path.join(dossier, TACHES), { recursive: true });
|
|
123
|
+
writeFileSync(
|
|
124
|
+
path.join(dossier, TACHES, `${id}.json`),
|
|
125
|
+
`${JSON.stringify({ taches, cibles }, null, 2)}\n`
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
cibles,
|
|
130
|
+
prevoir(paquet, dossierDuPaquet, script, tests, args) {
|
|
131
|
+
const t = {
|
|
132
|
+
tache: `${paquet}#${script}`,
|
|
133
|
+
paquet,
|
|
134
|
+
dossier: path.relative(racine, dossierDuPaquet) || '.',
|
|
135
|
+
script,
|
|
136
|
+
tests,
|
|
137
|
+
code: null,
|
|
138
|
+
cache: null,
|
|
139
|
+
journal: null,
|
|
140
|
+
};
|
|
141
|
+
taches.push(t);
|
|
142
|
+
ecrire();
|
|
143
|
+
return { t, args };
|
|
144
|
+
},
|
|
145
|
+
jouer({ t, args }, junit = null) {
|
|
146
|
+
// A report of an earlier run is no report of this one, which may write none.
|
|
147
|
+
if (junit) {
|
|
148
|
+
rmSync(junit, { force: true });
|
|
149
|
+
}
|
|
150
|
+
const r = spawnSync('cargo', args, { cwd: racine, env, stdio: 'inherit' });
|
|
151
|
+
t.code = r.error ? 127 : (r.status ?? 128 + (constants.signals[r.signal] ?? 0));
|
|
152
|
+
if (junit && dossier && existsSync(junit)) {
|
|
153
|
+
mkdirSync(path.join(dossier, JUNIT), { recursive: true });
|
|
154
|
+
copyFileSync(junit, path.join(dossier, JUNIT, `${id}-${t.paquet}.xml`));
|
|
155
|
+
}
|
|
156
|
+
ecrire();
|
|
157
|
+
return t.code;
|
|
158
|
+
},
|
|
159
|
+
code() {
|
|
160
|
+
const rouges = taches.filter(t => t.code !== 0);
|
|
161
|
+
if (rouges.length === 0) {
|
|
162
|
+
return 0;
|
|
163
|
+
}
|
|
164
|
+
return rouges.every(t => t.code === A_REPASSER) ? A_REPASSER : 1;
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// The crates the changes since the last green of <racine> touch, and their dependents; every crate
|
|
170
|
+
// with <tout> or without a last green that counts. `{ choix, m }`, `m` the measure.
|
|
171
|
+
function depuisLeVert(racine, tous, tout, env) {
|
|
172
|
+
const m = mesure(racine, { tout, dans: env.TMPDIR });
|
|
173
|
+
process.stderr.write(`${m.ligne}\n`);
|
|
174
|
+
const f = m.env[CHANGEMENTS];
|
|
175
|
+
if (!f) {
|
|
176
|
+
return { choix: tous, m };
|
|
177
|
+
}
|
|
178
|
+
const ch = JSON.parse(readFileSync(f, 'utf8'));
|
|
179
|
+
const t = touchesDesFichiers(racine, [...ch.fichiers, ...ch.supprimes]);
|
|
180
|
+
const nommes = new Set([...t.touches, ...t.dependants].map(c => c.dossier));
|
|
181
|
+
return { choix: tous.filter(c => nommes.has(c.composant.dossier)), m };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Plans and plays the tests of the crates <choix> (each `{ c, cibles }`, `cibles` the test targets
|
|
185
|
+
// named, empty for the whole crate) in the run <p>.
|
|
186
|
+
function jouerLesTests(racine, p, choix, options) {
|
|
187
|
+
const m = metadonnees(racine);
|
|
188
|
+
const junit = path.join(m.target_directory, 'nextest', PROFIL, 'junit.xml');
|
|
189
|
+
const prevues = [];
|
|
190
|
+
for (const { c, cibles } of choix) {
|
|
191
|
+
Object.assign(p.cibles, binaires(c));
|
|
192
|
+
const d = c.composant.dossier;
|
|
193
|
+
if (joueDesTests(racine, c.composant)) {
|
|
194
|
+
const args = ['nextest', 'run', '--tool-config-file', `${PROFIL}:${NEXTEST}`];
|
|
195
|
+
args.push('--profile', PROFIL, '--no-fail-fast', '-p', c.composant.nom);
|
|
196
|
+
for (const n of cibles) {
|
|
197
|
+
args.push('--test', n);
|
|
198
|
+
}
|
|
199
|
+
prevues.push([p.prevoir(c.composant.nom, d, 'nextest', true, [...args, ...options]), junit]);
|
|
200
|
+
}
|
|
201
|
+
const doctests = c.cibles.some(t => t.kind.includes('lib') && t.doctest !== false);
|
|
202
|
+
if (cibles.length === 0 && doctests) {
|
|
203
|
+
const args = ['test', '--doc', '-p', c.composant.nom];
|
|
204
|
+
prevues.push([p.prevoir(c.composant.nom, d, 'doctest', true, args), null]);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
for (const [t, j] of prevues) {
|
|
208
|
+
p.jouer(t, j);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// The crates the paths <chemins> choose in <racine>: `{ choix }`, or `{ refus }` naming each path
|
|
213
|
+
// refused.
|
|
214
|
+
function choisir(racine, tous, chemins) {
|
|
215
|
+
const parDossier = new Map();
|
|
216
|
+
const refus = [];
|
|
217
|
+
for (const chemin of chemins) {
|
|
218
|
+
const abs = path.resolve(racine, chemin);
|
|
219
|
+
const c = composantDans(
|
|
220
|
+
tous.map(x => x.composant),
|
|
221
|
+
racine,
|
|
222
|
+
abs
|
|
223
|
+
);
|
|
224
|
+
const crate = c && tous.find(x => x.composant === c);
|
|
225
|
+
if (!crate) {
|
|
226
|
+
refus.push(`${chemin} : hors de tout crate`);
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (!joueDesTests(racine, c)) {
|
|
230
|
+
refus.push(`${chemin} : ${c.nom} n'a pas de dossier tests/`);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
const cible = crate.cibles.find(t => t.kind.includes('test') && t.src === abs);
|
|
234
|
+
const deja = parDossier.get(c.dossier);
|
|
235
|
+
if (!cible) {
|
|
236
|
+
parDossier.set(c.dossier, { c: crate, cibles: [] });
|
|
237
|
+
} else if (!deja) {
|
|
238
|
+
parDossier.set(c.dossier, { c: crate, cibles: [cible.name] });
|
|
239
|
+
} else if (deja.cibles.length) {
|
|
240
|
+
deja.cibles.push(cible.name);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (refus.length) {
|
|
244
|
+
return { refus };
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
choix: tous
|
|
248
|
+
.filter(x => parDossier.has(x.composant.dossier))
|
|
249
|
+
.map(x => parDossier.get(x.composant.dossier)),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// The pass of `verifier` in <racine>, under the lock of the machine (<env> carries its mark): the
|
|
254
|
+
// tests of the crates the changes since the last green touch, then cargo deny; green, it keeps the
|
|
255
|
+
// last green.
|
|
256
|
+
function verifier(racine, args, env) {
|
|
257
|
+
const p = passe(racine, env);
|
|
258
|
+
const tous = crates(racine);
|
|
259
|
+
const { choix, m } = depuisLeVert(racine, tous, args.includes('--tout'), env);
|
|
260
|
+
try {
|
|
261
|
+
jouerLesTests(
|
|
262
|
+
racine,
|
|
263
|
+
p,
|
|
264
|
+
choix.map(c => ({ c, cibles: [] })),
|
|
265
|
+
[]
|
|
266
|
+
);
|
|
267
|
+
p.jouer(p.prevoir(RACINE, racine, 'deny', false, ['deny', 'check']));
|
|
268
|
+
const code = p.code();
|
|
269
|
+
if (code === 0 && m.etat) {
|
|
270
|
+
garderLeVert(m.etat);
|
|
271
|
+
}
|
|
272
|
+
return code;
|
|
273
|
+
} finally {
|
|
274
|
+
m.retirer();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Plays <jouer>(env) under the base of a pass of <genre> in the temporary directory of <env>,
|
|
279
|
+
// named to cargo in TMPDIR, TMP and TEMP: its code, 1 when the tests left something there, named.
|
|
280
|
+
// The base goes at the end, or at an interruption.
|
|
281
|
+
function sousLaBase(genre, env, jouer) {
|
|
282
|
+
const base = ouvrirBase(genre, { dans: env.TMPDIR || tmpdir() });
|
|
283
|
+
const lacher = retirerALInterruption(base.fermer);
|
|
284
|
+
try {
|
|
285
|
+
const code = jouer({ ...env, ...base.env });
|
|
286
|
+
const ligne = ligneDesRestes(base.restes());
|
|
287
|
+
if (!ligne) {
|
|
288
|
+
return code;
|
|
289
|
+
}
|
|
290
|
+
process.stderr.write(`${ligne}\n`);
|
|
291
|
+
return code === 0 || code === A_REPASSER ? 1 : code;
|
|
292
|
+
} finally {
|
|
293
|
+
lacher();
|
|
294
|
+
base.fermer();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Runs the command <nom> with <args> in the workspace at <racine>: its exit code.
|
|
300
|
+
* @param {string} nom one of NOMS
|
|
301
|
+
* @param {string[]} args its arguments
|
|
302
|
+
* @param {{ racine?: string, env?: NodeJS.ProcessEnv }} [o]
|
|
303
|
+
*/
|
|
304
|
+
export function lancer(nom, args, { racine = process.cwd(), env = process.env } = {}) {
|
|
305
|
+
const p = passe(racine, env);
|
|
306
|
+
if (nom === 'typer') {
|
|
307
|
+
p.jouer(p.prevoir(RACINE, racine, 'check', false, ['check', '--all-targets']));
|
|
308
|
+
return p.code();
|
|
309
|
+
}
|
|
310
|
+
if (nom === 'preparer') {
|
|
311
|
+
p.jouer(p.prevoir(RACINE, racine, 'fetch', false, ['fetch', '--locked']));
|
|
312
|
+
return p.code();
|
|
313
|
+
}
|
|
314
|
+
if (nom === 'verifier') {
|
|
315
|
+
const dire = l => process.stdout.write(`${l}\n`);
|
|
316
|
+
try {
|
|
317
|
+
return sousLaBase('verification', env, envBase =>
|
|
318
|
+
avecLaMachine(envMachine => verifier(racine, args, envMachine), {
|
|
319
|
+
env: envBase,
|
|
320
|
+
racine,
|
|
321
|
+
dire,
|
|
322
|
+
})
|
|
323
|
+
);
|
|
324
|
+
} catch (e) {
|
|
325
|
+
if (!(e instanceof AttenteDeLaMachine)) {
|
|
326
|
+
throw e;
|
|
327
|
+
}
|
|
328
|
+
dire(e.message);
|
|
329
|
+
return e.code;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const tous = crates(racine);
|
|
333
|
+
if (nom === 'tester') {
|
|
334
|
+
return sousLaBase('tests', env, envBase => tester(racine, tous, args, envBase));
|
|
335
|
+
}
|
|
336
|
+
process.stderr.write(`⛔ commande inconnue du module cargo : ${nom} (${NOMS.join(', ')})\n`);
|
|
337
|
+
return 2;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// The pass of `tester` in <racine>, the crates <tous>, its arguments <args>, under <env>.
|
|
341
|
+
function tester(racine, tous, args, env) {
|
|
342
|
+
const p = passe(racine, env);
|
|
343
|
+
const chemins = args.filter(a => !a.startsWith('-'));
|
|
344
|
+
const options = args.filter(a => a.startsWith('-') && a !== '--force');
|
|
345
|
+
let choix;
|
|
346
|
+
let m = null;
|
|
347
|
+
if (chemins.length) {
|
|
348
|
+
const r = choisir(racine, tous, chemins);
|
|
349
|
+
if (r.refus) {
|
|
350
|
+
for (const l of r.refus) {
|
|
351
|
+
process.stderr.write(`⛔ ${l}\n`);
|
|
352
|
+
}
|
|
353
|
+
return 2;
|
|
354
|
+
}
|
|
355
|
+
choix = r.choix;
|
|
356
|
+
} else if (env[DEPUIS_LE_VERT]) {
|
|
357
|
+
({ choix, m } = depuisLeVert(racine, tous, args.includes('--force'), env));
|
|
358
|
+
choix = choix.map(c => ({ c, cibles: [] }));
|
|
359
|
+
} else {
|
|
360
|
+
choix = tous.map(c => ({ c, cibles: [] }));
|
|
361
|
+
}
|
|
362
|
+
try {
|
|
363
|
+
jouerLesTests(racine, p, choix, options);
|
|
364
|
+
} finally {
|
|
365
|
+
m?.retirer();
|
|
366
|
+
}
|
|
367
|
+
return p.code();
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
371
|
+
const [nom, ...args] = process.argv.slice(2);
|
|
372
|
+
try {
|
|
373
|
+
process.exitCode = lancer(nom, args);
|
|
374
|
+
} catch (e) {
|
|
375
|
+
process.stderr.write(`${e.message}\n`);
|
|
376
|
+
process.exitCode = 1;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// The components of a workspace of cargo, as cargo itself describes them (`cargo metadata
|
|
2
|
+
// --format-version 1 --no-deps --offline`): the crates the module cargo answers the join with
|
|
3
|
+
// (scripts/jointure.d.ts, `composants`, `composantDe`, `matieres`, `joueDesTests`, `lecteurs`,
|
|
4
|
+
// `estUnTest`).
|
|
5
|
+
//
|
|
6
|
+
// - A component is a member of the workspace (`workspace_members`): its folder, the manifest's;
|
|
7
|
+
// its name and its package, the crate's name. A directory without a Cargo.toml at its root holds
|
|
8
|
+
// none, and cargo is not asked. Cargo's paths are read from its `workspace_root`, so that the
|
|
9
|
+
// folders lie under the root the core gives, whatever link leads to it.
|
|
10
|
+
// - The component of a file is the crate of the longest folder that holds it, as cargo finds the
|
|
11
|
+
// manifest of a file by climbing its directories; a file out of every crate (the workspace's own
|
|
12
|
+
// Cargo.toml and Cargo.lock of a virtual workspace, its docs) is out of every component, which
|
|
13
|
+
// ./touches.mjs reads as the whole workspace.
|
|
14
|
+
// - The shared test material: the crates whose manifest says `[package.metadata.grillhouse]
|
|
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).
|
|
18
|
+
// - The readers of a crate: the members that depend on it by its path, of any kind (`normal`,
|
|
19
|
+
// `dev`, `build`), the kind in `par`; a name no member bears is without provider. The types
|
|
20
|
+
// give no survey of their own: `etat` done, no element.
|
|
21
|
+
// - What the testwriter writes: a file of `<crate>/tests/` is a test file; the runner plays the
|
|
22
|
+
// ones cargo makes a test target of, `tests/<nom>.rs` and `tests/<dossier>/main.rs`, and the
|
|
23
|
+
// 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.
|
|
27
|
+
import { spawnSync } from 'node:child_process';
|
|
28
|
+
import { existsSync, statSync } from 'node:fs';
|
|
29
|
+
import path from 'node:path';
|
|
30
|
+
|
|
31
|
+
// The genre of a dependency as cargo names its kind, null for a normal one.
|
|
32
|
+
const genre = kind => kind ?? 'normal';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* What cargo describes of the workspace at <racine>, its dependencies left out; null without a
|
|
36
|
+
* Cargo.toml at its root. Throws, named, when cargo cannot answer.
|
|
37
|
+
* @param {string} racine the root of the workspace
|
|
38
|
+
*/
|
|
39
|
+
export function metadonnees(racine) {
|
|
40
|
+
if (!existsSync(path.join(racine, 'Cargo.toml'))) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const r = spawnSync('cargo', ['metadata', '--format-version', '1', '--no-deps', '--offline'], {
|
|
44
|
+
cwd: racine,
|
|
45
|
+
encoding: 'utf8',
|
|
46
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
47
|
+
});
|
|
48
|
+
if (r.error) {
|
|
49
|
+
throw new Error(`⛔ cargo metadata dans ${racine} : ${r.error.message}`);
|
|
50
|
+
}
|
|
51
|
+
if (r.status !== 0) {
|
|
52
|
+
const fin = r.stderr.trim().split('\n').at(-1) ?? '';
|
|
53
|
+
throw new Error(`⛔ cargo metadata dans ${racine} (code ${r.status}) : ${fin}`);
|
|
54
|
+
}
|
|
55
|
+
return JSON.parse(r.stdout);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The crates of the workspace at <racine>, sorted by name: `{ composant, deps, cibles, matiere }`,
|
|
60
|
+
* `deps` each `{ dossier, genre }` of a dependency by its path, `cibles` each `{ kind, name, src }`
|
|
61
|
+
* of a target of the crate, the paths under <racine>.
|
|
62
|
+
* @param {string} racine the root of the workspace
|
|
63
|
+
*/
|
|
64
|
+
export function crates(racine) {
|
|
65
|
+
const m = metadonnees(racine);
|
|
66
|
+
if (!m) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const sous = p => path.join(racine, path.relative(m.workspace_root, p));
|
|
70
|
+
const membres = new Set(m.workspace_members);
|
|
71
|
+
return m.packages
|
|
72
|
+
.filter(p => membres.has(p.id))
|
|
73
|
+
.map(p => ({
|
|
74
|
+
composant: { dossier: sous(path.dirname(p.manifest_path)), nom: p.name, paquet: p.name },
|
|
75
|
+
deps: (p.dependencies ?? [])
|
|
76
|
+
.filter(d => typeof d.path === 'string')
|
|
77
|
+
.map(d => ({ dossier: sous(d.path), genre: genre(d.kind) })),
|
|
78
|
+
cibles: (p.targets ?? []).map(t => ({ kind: t.kind, name: t.name, src: sous(t.src_path) })),
|
|
79
|
+
matiere: p.metadata?.grillhouse?.matiere === true,
|
|
80
|
+
}))
|
|
81
|
+
.sort((a, b) => a.composant.nom.localeCompare(b.composant.nom));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The components of the workspace at <racine>: its members. */
|
|
85
|
+
export const composants = racine => crates(racine).map(c => c.composant);
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The component of <liste> that holds <fichier> (absolute, or from <racine>), the longest folder;
|
|
89
|
+
* null for none.
|
|
90
|
+
*/
|
|
91
|
+
export function composantDans(liste, racine, fichier) {
|
|
92
|
+
const abs = path.resolve(racine, fichier);
|
|
93
|
+
const tenants = liste.filter(c => abs === c.dossier || abs.startsWith(`${c.dossier}${path.sep}`));
|
|
94
|
+
return tenants.sort((a, b) => b.dossier.length - a.dossier.length)[0] ?? null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The crates of the shared test material of the workspace at <racine>. */
|
|
98
|
+
export const matieres = racine =>
|
|
99
|
+
crates(racine)
|
|
100
|
+
.filter(c => c.matiere)
|
|
101
|
+
.map(c => c.composant);
|
|
102
|
+
|
|
103
|
+
/** Whether the crate <composant> has a folder `tests/`, its integration tests. */
|
|
104
|
+
export function joueDesTests(_racine, composant) {
|
|
105
|
+
const d = path.join(composant.dossier, 'tests');
|
|
106
|
+
return existsSync(d) && statSync(d).isDirectory();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The readers, by their manifests, of the crates <noms> among <composants> of <racine>: each a
|
|
111
|
+
* reader `{ composant, par }`, `par` the kinds of its dependencies on it.
|
|
112
|
+
*/
|
|
113
|
+
export function lecteurs(racine, { composants: liste, noms }) {
|
|
114
|
+
const tous = crates(racine);
|
|
115
|
+
const parDossier = new Map(liste.map(c => [c.dossier, c]));
|
|
116
|
+
const lit = new Map(liste.map(c => [c, new Set()]));
|
|
117
|
+
const genres = new Map(liste.map(c => [c, new Map()]));
|
|
118
|
+
for (const c of tous) {
|
|
119
|
+
const lecteur = parDossier.get(c.composant.dossier);
|
|
120
|
+
if (!lecteur) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
for (const d of c.deps) {
|
|
124
|
+
const lu = parDossier.get(d.dossier);
|
|
125
|
+
if (!lu || lu === lecteur) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
lit.get(lecteur).add(lu);
|
|
129
|
+
const g = genres.get(lu);
|
|
130
|
+
if (!g.has(lecteur)) {
|
|
131
|
+
g.set(lecteur, new Set());
|
|
132
|
+
}
|
|
133
|
+
g.get(lecteur).add(d.genre);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const elements = [];
|
|
137
|
+
const sansFournisseur = [];
|
|
138
|
+
for (const nom of noms) {
|
|
139
|
+
const fournisseur = liste.find(c => c.paquet === nom || c.nom === nom);
|
|
140
|
+
if (!fournisseur) {
|
|
141
|
+
sansFournisseur.push(nom);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const lus = [...genres.get(fournisseur)]
|
|
145
|
+
.sort(([a], [b]) => a.nom.localeCompare(b.nom))
|
|
146
|
+
.map(([composant, par]) => ({ composant, par: [...par].sort() }));
|
|
147
|
+
elements.push({ nom, fournisseur, lecteurs: lus });
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
elements,
|
|
151
|
+
sansFournisseur,
|
|
152
|
+
types: { etat: 'fait', raison: null, elements: [] },
|
|
153
|
+
lit,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// True when <fichier> lies strictly under the directory <dir>.
|
|
158
|
+
const sous = (fichier, dir) => {
|
|
159
|
+
const rel = path.relative(dir, fichier);
|
|
160
|
+
return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* What the testwriter writes in <chemin>, absolute or from the root <racine>: `{ joue, test,
|
|
165
|
+
* matiere }`, or null for a file he does not write.
|
|
166
|
+
*/
|
|
167
|
+
export function estUnTest(chemin, racine) {
|
|
168
|
+
const abs = path.resolve(racine, chemin);
|
|
169
|
+
const tous = crates(racine);
|
|
170
|
+
const c = composantDans(
|
|
171
|
+
tous.map(x => x.composant),
|
|
172
|
+
racine,
|
|
173
|
+
abs
|
|
174
|
+
);
|
|
175
|
+
if (!c) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const matiere = tous.find(x => x.composant === c).matiere;
|
|
179
|
+
const parts = path.relative(c.dossier, abs).split(path.sep);
|
|
180
|
+
if (parts[0] === 'tests' && sous(abs, path.join(c.dossier, 'tests'))) {
|
|
181
|
+
if (parts[1] === 'common' && parts.length > 2) {
|
|
182
|
+
return { joue: false, test: true, matiere: true };
|
|
183
|
+
}
|
|
184
|
+
// The test targets cargo finds: `tests/<nom>.rs`, `tests/<dossier>/main.rs`.
|
|
185
|
+
const joue =
|
|
186
|
+
(parts.length === 2 && parts[1].endsWith('.rs')) ||
|
|
187
|
+
(parts.length === 3 && parts[2] === 'main.rs');
|
|
188
|
+
return { joue, test: true, matiere };
|
|
189
|
+
}
|
|
190
|
+
return matiere ? { joue: false, test: false, matiere: true } : null;
|
|
191
|
+
}
|