@roomi-fields/grillhouse 0.25.5 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/agents/testwriter.md +1 -1
- package/bin/grillhouse.mjs +20 -3
- package/cadre/templates/cargo/package.json +3 -0
- package/cadre/templates/projet/.gitattributes +1 -0
- package/cadre/templates/projet/CLAUDE.md +13 -0
- package/cadre/templates/projet/docs/ARCHITECTURE.md +15 -0
- package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
- package/cadre/templates/python/package.json +18 -0
- package/charte.md +32 -1
- package/docs/ARCHITECTURE.md +146 -40
- package/docs/CADRE.md +7 -6
- package/docs/INTERFACE.md +108 -32
- package/hooks/register.tsx +57 -16
- package/package.json +9 -3
- package/scripts/circuit.mjs +165 -27
- package/scripts/commande-du-langage.mjs +2 -2
- package/scripts/commandes-composees.mjs +156 -0
- package/scripts/composition-des-langages.mjs +306 -0
- package/scripts/conformite.mjs +1 -3
- package/scripts/copies-finies.mjs +167 -28
- package/scripts/crochets.mjs +9 -3
- package/scripts/dernier-vert.mjs +15 -2
- package/scripts/engendres.mjs +170 -0
- package/scripts/enveloppe/enveloppe.mjs +59 -17
- package/scripts/enveloppe/lancer.sh +15 -22
- package/scripts/enveloppe/travail-de-la-copie.mjs +262 -0
- package/scripts/etapes.mjs +1 -1
- package/scripts/fusion-du-changelog.mjs +120 -0
- package/scripts/gardes-du-cadre.mjs +7 -4
- package/scripts/grillhouse-maj.mjs +171 -99
- package/scripts/index-interfaces.mjs +78 -0
- package/scripts/init.mjs +5 -5
- package/scripts/integration/file.mjs +270 -117
- package/scripts/integration/integrer.mjs +50 -62
- package/scripts/jointure.d.ts +48 -14
- package/scripts/langages/cargo/binaires.json +2 -1
- package/scripts/langages/cargo/binaires.mjs +29 -6
- package/scripts/langages/cargo/clippy.mjs +12 -2
- package/scripts/langages/cargo/commandes.mjs +60 -7
- package/scripts/langages/cargo/composants.mjs +229 -8
- package/scripts/langages/cargo/exemples.mjs +1 -15
- package/scripts/langages/cargo/index-interfaces.mjs +20 -3
- package/scripts/langages/cargo/index.mjs +25 -17
- package/scripts/langages/cargo/mise-a-jour.mjs +2 -1
- package/scripts/langages/cargo/sccache.mjs +172 -0
- package/scripts/langages/cargo/verdict.mjs +50 -10
- package/scripts/langages/python/binaires.json +3 -0
- package/scripts/langages/python/binaires.mjs +59 -0
- package/scripts/langages/python/commandes.mjs +411 -0
- package/scripts/langages/python/composants.mjs +272 -0
- package/scripts/langages/python/exemples.mjs +260 -0
- package/scripts/langages/python/index-interfaces.mjs +77 -0
- package/scripts/langages/python/index.mjs +94 -0
- package/scripts/langages/python/lot.mjs +76 -0
- package/scripts/langages/python/mise-a-jour.mjs +54 -0
- package/scripts/langages/python/tailles-des-tests.mjs +102 -0
- package/scripts/langages/python/verdict.mjs +85 -0
- package/scripts/langages/typescript/exemples.mjs +1 -20
- package/scripts/langages/typescript/index-interfaces.mjs +10 -3
- package/scripts/langages/typescript/index.mjs +15 -17
- package/scripts/langages/typescript/regle-des-tests.mjs +37 -0
- package/scripts/langages-des-paquets.mjs +171 -0
- package/scripts/langages.mjs +60 -41
- package/scripts/migrations/0.27.0-langages-dans-l-architecture.mjs +182 -0
- package/scripts/migrations.mjs +2 -0
- package/scripts/nuit.sh +15 -1
- package/scripts/outils-cles.mjs +188 -0
- package/scripts/resultats.mjs +22 -6
- package/scripts/session-start.sh +34 -9
- package/scripts/sources.mjs +2 -1
- package/scripts/sous-commandes.mjs +21 -3
- package/scripts/tableau-des-composants.mjs +138 -0
- package/scripts/verrou-de-machine.mjs +14 -13
- package/scripts/verrous/verrou.mjs +53 -16
- package/skills/developpeur/SKILL.md +4 -0
- package/skills/explorateur/SKILL.md +3 -1
- package/skills/grill/SKILL.md +9 -1
- package/skills/pitmaster/SKILL.md +12 -3
- package/skills/pitmaster/references/consigne-agent.md +3 -3
- package/skills/redacteur/references/documents-d-un-composant.md +12 -0
- package/skills/relecteur/SKILL.md +6 -2
- package/skills/testwriter/SKILL.md +29 -6
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The commands of the module python, 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 project, its arguments after.
|
|
5
|
+
//
|
|
6
|
+
// npx grillhouse tests [--force] [<chemin>…] [--<option>…] tester
|
|
7
|
+
// npx grillhouse verifier [--tout | --gardes] verifier
|
|
8
|
+
// node commandes.mjs typer typer
|
|
9
|
+
// npx grillhouse preparer preparer
|
|
10
|
+
// npx grillhouse tests-de-nuit tests-de-nuit
|
|
11
|
+
// npx grillhouse tailles-des-tests | index-interfaces each guard, its own script
|
|
12
|
+
//
|
|
13
|
+
// - Each command plays in the folder of each package (./composants.mjs), one after the other, by
|
|
14
|
+
// uv, which reads its pyproject.toml, its uv.lock (`--locked`: a lock out of date is refused, as
|
|
15
|
+
// `npm ci`), and the Python its `requires-python` and its `.python-version` ask.
|
|
16
|
+
// - `tester` plays pytest in each package that plays tests: `uv run --locked --group test pytest`,
|
|
17
|
+
// the group `test` holding pytest and what the tests depend on, its JUnit report in the family
|
|
18
|
+
// `xunit1` (./verdict.mjs). A path, written from the root, chooses the package that holds it,
|
|
19
|
+
// and pytest plays that path alone; a path out of every package is refused, named, and nothing
|
|
20
|
+
// plays (code 2). Without a path, every package that plays tests plays, or, under the circuit's
|
|
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.
|
|
25
|
+
// - `verifier` plays, in each package the changes since the last green touch (every package with
|
|
26
|
+
// `--tout`, or when no last green counts), the typing then the tests of the day; green, it keeps
|
|
27
|
+
// the last green (scripts/dernier-vert.mjs). It plays under the lock of the machine
|
|
28
|
+
// (`avecLaMachine` of ./jointure), as the module cargo's. `verifier --gardes` plays the guards
|
|
29
|
+
// alone: the project's root scripts `grillhouse:gardes` then `gardes` the package.json holds.
|
|
30
|
+
// - `typer`: `uv run --locked python -m compileall`, the folders whose name begins with a dot (the
|
|
31
|
+
// `.venv`) left out. `preparer`: `uv sync --locked --group test`.
|
|
32
|
+
// - `tests-de-nuit`: pytest on the night tests of each package that holds some; none, nothing
|
|
33
|
+
// plays and the code is 0. The night (scripts/nuit.sh) runs it.
|
|
34
|
+
// - Each command plays under a temporary directory of its pass, the guard of the temporary
|
|
35
|
+
// directory: a base (`ouvrirBase` of ./jointure) named in TMPDIR, TMP and TEMP, removed at the
|
|
36
|
+
// end of the pass, green, red or interrupted; what the tests left there fails the pass (code 1),
|
|
37
|
+
// each name written on the error stream, the lock files uv takes there (`uv-<hash>.lock`) apart,
|
|
38
|
+
// which the base removes with the rest. A test makes its temporary
|
|
39
|
+
// directory or file with `tempfile` (`TemporaryDirectory`, `NamedTemporaryFile`), removed at
|
|
40
|
+
// its end, a failed test included, never `mkdtemp` by hand.
|
|
41
|
+
// - Python writes its bytecode under one tree at the root, `__pycache__` (PYTHONPYCACHEPREFIX),
|
|
42
|
+
// which the envelope makes proper to the session (`sorties.propres` of ./index.mjs); uv the
|
|
43
|
+
// environment of each package under `.venv/<dossier>` at the root (UV_PROJECT_ENVIRONMENT), and
|
|
44
|
+
// pytest its cache under `.pytest_cache/<dossier>` (`cache_dir`), where the envelope opens them
|
|
45
|
+
// in writing, rather than in the package's folder, which a session whose plan does not write the
|
|
46
|
+
// package could not write.
|
|
47
|
+
// - While the environment names a results directory (`GRILLHOUSE_RESULTATS`), the run writes
|
|
48
|
+
// there what ./verdict.mjs reads: its tasks, each planned before it plays, and the JUnit report
|
|
49
|
+
// of each run of pytest.
|
|
50
|
+
// - uv absent from the PATH: one line that names it and `npx grillhouse maj`, which installs it.
|
|
51
|
+
// - The exit code: 0 when every task is green, 75 when the only reds are « à repasser », 1
|
|
52
|
+
// otherwise; 2 for a path refused or a command unknown.
|
|
53
|
+
import { spawnSync } from 'node:child_process';
|
|
54
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
55
|
+
import { constants, tmpdir } from 'node:os';
|
|
56
|
+
import path from 'node:path';
|
|
57
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
58
|
+
import { RESULTATS } from '../../resultats.mjs';
|
|
59
|
+
import {
|
|
60
|
+
AttenteDeLaMachine,
|
|
61
|
+
avecLaMachine,
|
|
62
|
+
CHANGEMENTS,
|
|
63
|
+
DEPUIS_LE_VERT,
|
|
64
|
+
garderLeVert,
|
|
65
|
+
ligneDesRestes,
|
|
66
|
+
mesure,
|
|
67
|
+
ouvrirBase,
|
|
68
|
+
retirerALInterruption,
|
|
69
|
+
} from '../../services-du-noyau.mjs';
|
|
70
|
+
import {
|
|
71
|
+
composantDans,
|
|
72
|
+
composants,
|
|
73
|
+
estDeNuit,
|
|
74
|
+
fichiersDeTest,
|
|
75
|
+
GROUPE,
|
|
76
|
+
joueDesTests,
|
|
77
|
+
} from './composants.mjs';
|
|
78
|
+
import { touchesDesFichiers } from './lot.mjs';
|
|
79
|
+
import { JUNIT, TACHES } from './verdict.mjs';
|
|
80
|
+
|
|
81
|
+
const ICI = fileURLToPath(import.meta.url);
|
|
82
|
+
export const NOMS = ['tester', 'verifier', 'typer', 'preparer', 'tests-de-nuit'];
|
|
83
|
+
const A_REPASSER = 75;
|
|
84
|
+
const RACINE = '//';
|
|
85
|
+
/** The night tests, which the day leaves out. */
|
|
86
|
+
export const DE_NUIT = '*_nuit_test.py';
|
|
87
|
+
/** The tree of the bytecode of Python, at the root. */
|
|
88
|
+
export const PYCACHE = '__pycache__';
|
|
89
|
+
/** The environments of uv and the caches of pytest, one per package, at the root. */
|
|
90
|
+
export const VENV = '.venv';
|
|
91
|
+
export const CACHE_DE_PYTEST = '.pytest_cache';
|
|
92
|
+
|
|
93
|
+
/** The guards of the module: each its name and its script beside this one. */
|
|
94
|
+
export const GARDES = [
|
|
95
|
+
{ nom: 'tailles-des-tests', args: [] },
|
|
96
|
+
{ nom: 'index-interfaces', args: ['--verifier'] },
|
|
97
|
+
].map(g => ({
|
|
98
|
+
...g,
|
|
99
|
+
script: path.join(path.dirname(ICI), `${g.nom}.mjs`),
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
/** The commands of the module, each this script and its name; then each guard, its script. */
|
|
103
|
+
export const commandes = () =>
|
|
104
|
+
Object.fromEntries([
|
|
105
|
+
...NOMS.map(n => [n, { script: ICI, args: [n] }]),
|
|
106
|
+
...GARDES.map(g => [g.nom, { script: g.script, args: [] }]),
|
|
107
|
+
]);
|
|
108
|
+
|
|
109
|
+
// The run of the tasks of a command in <racine>: each planned, then played, written in the
|
|
110
|
+
// results directory <env> names.
|
|
111
|
+
function passe(racine, env) {
|
|
112
|
+
const dossier = env[RESULTATS] || null;
|
|
113
|
+
const id = `${Date.now()}-${process.pid}`;
|
|
114
|
+
const taches = [];
|
|
115
|
+
const rapports = {};
|
|
116
|
+
const environnement = { ...env, PYTHONPYCACHEPREFIX: path.join(racine, PYCACHE) };
|
|
117
|
+
const ecrire = () => {
|
|
118
|
+
if (!dossier) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
mkdirSync(path.join(dossier, TACHES), { recursive: true });
|
|
122
|
+
writeFileSync(
|
|
123
|
+
path.join(dossier, TACHES, `${id}.json`),
|
|
124
|
+
`${JSON.stringify({ taches, rapports }, null, 2)}\n`
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
racine,
|
|
129
|
+
prevoir(paquet, dossierDuPaquet, script, tests, args, programme = 'uv') {
|
|
130
|
+
const t = {
|
|
131
|
+
tache: `${paquet}#${script}`,
|
|
132
|
+
paquet,
|
|
133
|
+
dossier: path.relative(racine, dossierDuPaquet) || '.',
|
|
134
|
+
script,
|
|
135
|
+
tests,
|
|
136
|
+
code: null,
|
|
137
|
+
cache: null,
|
|
138
|
+
journal: null,
|
|
139
|
+
};
|
|
140
|
+
taches.push(t);
|
|
141
|
+
ecrire();
|
|
142
|
+
return { t, args, cwd: dossierDuPaquet, programme };
|
|
143
|
+
},
|
|
144
|
+
// The JUnit report of a run of pytest of the package <nom> at <dossierDuPaquet>, its option;
|
|
145
|
+
// none without a results directory.
|
|
146
|
+
junit(nom, dossierDuPaquet) {
|
|
147
|
+
if (!dossier) {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
const f = `${id}-${nom}.xml`;
|
|
151
|
+
rapports[f] = dossierDuPaquet;
|
|
152
|
+
return ['-o', 'junit_family=xunit1', `--junit-xml=${path.join(dossier, JUNIT, f)}`];
|
|
153
|
+
},
|
|
154
|
+
jouer({ t, args, cwd, programme }) {
|
|
155
|
+
// The environment of uv of the package, at the root (`sorties` of ./index.mjs).
|
|
156
|
+
const venv = path.join(racine, VENV, path.relative(racine, cwd));
|
|
157
|
+
const r = spawnSync(programme, args, {
|
|
158
|
+
cwd,
|
|
159
|
+
env: { ...environnement, UV_PROJECT_ENVIRONMENT: venv },
|
|
160
|
+
stdio: 'inherit',
|
|
161
|
+
});
|
|
162
|
+
if (r.error?.code === 'ENOENT' && programme === 'uv') {
|
|
163
|
+
process.stderr.write("⛔ uv absent du PATH : `npx grillhouse maj` l'installe.\n");
|
|
164
|
+
}
|
|
165
|
+
t.code = r.error ? 127 : (r.status ?? 128 + (constants.signals[r.signal] ?? 0));
|
|
166
|
+
ecrire();
|
|
167
|
+
return t.code;
|
|
168
|
+
},
|
|
169
|
+
code() {
|
|
170
|
+
const rouges = taches.filter(t => t.code !== 0);
|
|
171
|
+
if (rouges.length === 0) {
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
return rouges.every(t => t.code === A_REPASSER) ? A_REPASSER : 1;
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const UV_RUN = ['run', '--locked'];
|
|
180
|
+
|
|
181
|
+
// Plays pytest in the run <p> for each `{ c, chemins }` of <choix>, `chemins` from the package's
|
|
182
|
+
// folder (empty: the whole package, the night left out), <options> given to pytest.
|
|
183
|
+
function jouerLesTests(p, choix, options) {
|
|
184
|
+
for (const { c, chemins } of choix) {
|
|
185
|
+
const selection = chemins.length ? chemins : [`--ignore-glob=${DE_NUIT}`];
|
|
186
|
+
const cache = path.join(p.racine, CACHE_DE_PYTEST, path.relative(p.racine, c.dossier));
|
|
187
|
+
const args = [...UV_RUN, '--group', GROUPE, 'pytest', '-o', `cache_dir=${cache}`];
|
|
188
|
+
args.push(...p.junit(c.nom, c.dossier));
|
|
189
|
+
p.jouer(p.prevoir(c.nom, c.dossier, 'pytest', true, [...args, ...selection, ...options]));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// The packages the changes since the last green of <racine> touch; every package with <tout> or
|
|
194
|
+
// without a last green that counts. `{ choix, m }`, `m` the measure.
|
|
195
|
+
function depuisLeVert(racine, tous, tout, env) {
|
|
196
|
+
const m = mesure(racine, { tout, dans: env.TMPDIR });
|
|
197
|
+
process.stderr.write(`${m.ligne}\n`);
|
|
198
|
+
const f = m.env[CHANGEMENTS];
|
|
199
|
+
if (!f) {
|
|
200
|
+
return { choix: tous, m };
|
|
201
|
+
}
|
|
202
|
+
const ch = JSON.parse(readFileSync(f, 'utf8'));
|
|
203
|
+
const t = touchesDesFichiers(racine, [...ch.fichiers, ...ch.supprimes]);
|
|
204
|
+
const nommes = new Set(t.touches.map(c => c.dossier));
|
|
205
|
+
return { choix: tous.filter(c => nommes.has(c.dossier)), m };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// The packages the paths <chemins> choose in <racine>: `{ choix }`, or `{ refus }`.
|
|
209
|
+
function choisir(racine, tous, chemins) {
|
|
210
|
+
const parDossier = new Map();
|
|
211
|
+
const refus = [];
|
|
212
|
+
for (const chemin of chemins) {
|
|
213
|
+
const c = composantDans(tous, racine, chemin);
|
|
214
|
+
if (!c) {
|
|
215
|
+
refus.push(`${chemin} : hors de tout paquet Python (pyproject.toml)`);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
const rel = path.relative(c.dossier, path.resolve(racine, chemin)) || '.';
|
|
219
|
+
const deja = parDossier.get(c.dossier) ?? { c, chemins: [] };
|
|
220
|
+
deja.chemins.push(rel);
|
|
221
|
+
parDossier.set(c.dossier, deja);
|
|
222
|
+
}
|
|
223
|
+
return refus.length ? { refus } : { choix: [...parDossier.values()] };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// The pass of `tester` in <racine>, its arguments <args>, under <env>.
|
|
227
|
+
function tester(racine, args, env) {
|
|
228
|
+
const p = passe(racine, env);
|
|
229
|
+
const tous = composants(racine);
|
|
230
|
+
const chemins = args.filter(a => !a.startsWith('-'));
|
|
231
|
+
const options = args.filter(a => a.startsWith('-') && a !== '--force');
|
|
232
|
+
if (chemins.length) {
|
|
233
|
+
const r = choisir(racine, tous, chemins);
|
|
234
|
+
if (r.refus) {
|
|
235
|
+
for (const l of r.refus) {
|
|
236
|
+
process.stderr.write(`⛔ ${l}\n`);
|
|
237
|
+
}
|
|
238
|
+
return 2;
|
|
239
|
+
}
|
|
240
|
+
jouerLesTests(p, r.choix, options);
|
|
241
|
+
return p.code();
|
|
242
|
+
}
|
|
243
|
+
let m = null;
|
|
244
|
+
let choix = tous;
|
|
245
|
+
if (env[DEPUIS_LE_VERT]) {
|
|
246
|
+
({ choix, m } = depuisLeVert(racine, tous, args.includes('--force'), env));
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
const avec = choix.filter(c => joueDesTests(racine, c)).map(c => ({ c, chemins: [] }));
|
|
250
|
+
jouerLesTests(p, avec, options);
|
|
251
|
+
} finally {
|
|
252
|
+
m?.retirer();
|
|
253
|
+
}
|
|
254
|
+
return p.code();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// The pass of `verifier` in <racine>, under the lock of the machine: the typing and the tests of
|
|
258
|
+
// the packages the changes since the last green touch; green, it keeps the last green.
|
|
259
|
+
function verifier(racine, args, env) {
|
|
260
|
+
const p = passe(racine, env);
|
|
261
|
+
if (args.includes('--gardes')) {
|
|
262
|
+
return gardes(racine, p);
|
|
263
|
+
}
|
|
264
|
+
const { choix, m } = depuisLeVert(racine, composants(racine), args.includes('--tout'), env);
|
|
265
|
+
try {
|
|
266
|
+
for (const c of choix) {
|
|
267
|
+
typerLePaquet(p, c);
|
|
268
|
+
}
|
|
269
|
+
jouerLesTests(
|
|
270
|
+
p,
|
|
271
|
+
choix.filter(c => joueDesTests(racine, c)).map(c => ({ c, chemins: [] })),
|
|
272
|
+
[]
|
|
273
|
+
);
|
|
274
|
+
const code = p.code();
|
|
275
|
+
if (code === 0 && m.etat) {
|
|
276
|
+
garderLeVert(m.etat);
|
|
277
|
+
}
|
|
278
|
+
return code;
|
|
279
|
+
} finally {
|
|
280
|
+
m.retirer();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// The typing of the package <c> in the run <p>: compileall, the folders of a dot left out.
|
|
285
|
+
const typerLePaquet = (p, c) =>
|
|
286
|
+
p.jouer(
|
|
287
|
+
p.prevoir(c.nom, c.dossier, 'compileall', false, [
|
|
288
|
+
...UV_RUN,
|
|
289
|
+
'python',
|
|
290
|
+
'-m',
|
|
291
|
+
'compileall',
|
|
292
|
+
'-q',
|
|
293
|
+
'-x',
|
|
294
|
+
String.raw`/\.`,
|
|
295
|
+
'.',
|
|
296
|
+
])
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
// The scripts of guards of the project, in the order they play: the frame's, then its own.
|
|
300
|
+
const SCRIPTS_DE_GARDES = ['grillhouse:gardes', 'gardes'];
|
|
301
|
+
|
|
302
|
+
// The pass of `verifier --gardes` in <racine>: each script of SCRIPTS_DE_GARDES the root
|
|
303
|
+
// package.json holds, a task of the root; no test.
|
|
304
|
+
function gardes(racine, p) {
|
|
305
|
+
let scripts = {};
|
|
306
|
+
try {
|
|
307
|
+
scripts = JSON.parse(readFileSync(path.join(racine, 'package.json'), 'utf8')).scripts ?? {};
|
|
308
|
+
} catch {
|
|
309
|
+
scripts = {};
|
|
310
|
+
}
|
|
311
|
+
for (const nom of SCRIPTS_DE_GARDES.filter(n => typeof scripts[n] === 'string')) {
|
|
312
|
+
p.jouer(p.prevoir(RACINE, racine, nom, false, ['run', '--silent', nom], 'npm'));
|
|
313
|
+
}
|
|
314
|
+
return p.code();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// What the tools write at the root of the temporary directory, which the guard of the base
|
|
318
|
+
// tolerates and the base removes with the rest: Node's compile cache, which npm enables; the lock
|
|
319
|
+
// file uv takes on the environment of a project (`uv-<hash>.lock`, measured with uv 0.10.4).
|
|
320
|
+
const DES_OUTILS = n => n === 'node-compile-cache' || /^uv-[0-9a-f]+\.lock$/.test(n);
|
|
321
|
+
|
|
322
|
+
// Plays <jouer>(env) under the base of a pass of <genre> in the temporary directory of <env>,
|
|
323
|
+
// named in TMPDIR, TMP and TEMP: its code, 1 when the tests left something there, named.
|
|
324
|
+
function sousLaBase(genre, env, jouer) {
|
|
325
|
+
const base = ouvrirBase(genre, { dans: env.TMPDIR || tmpdir() });
|
|
326
|
+
const lacher = retirerALInterruption(base.fermer);
|
|
327
|
+
try {
|
|
328
|
+
const code = jouer({ ...env, ...base.env });
|
|
329
|
+
const ligne = ligneDesRestes(base.restes().filter(n => !DES_OUTILS(n)));
|
|
330
|
+
if (!ligne) {
|
|
331
|
+
return code;
|
|
332
|
+
}
|
|
333
|
+
process.stderr.write(`${ligne}\n`);
|
|
334
|
+
return code === 0 || code === A_REPASSER ? 1 : code;
|
|
335
|
+
} finally {
|
|
336
|
+
lacher();
|
|
337
|
+
base.fermer();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Runs the command <nom> with <args> in the project at <racine>: its exit code.
|
|
343
|
+
* @param {string} nom one of NOMS
|
|
344
|
+
* @param {string[]} args its arguments
|
|
345
|
+
* @param {{ racine?: string, env?: NodeJS.ProcessEnv }} [o]
|
|
346
|
+
*/
|
|
347
|
+
export function lancer(nom, args, { racine = process.cwd(), env = process.env } = {}) {
|
|
348
|
+
if (nom === 'tester') {
|
|
349
|
+
return sousLaBase('tests', env, e => tester(racine, args, e));
|
|
350
|
+
}
|
|
351
|
+
if (nom === 'tests-de-nuit') {
|
|
352
|
+
return sousLaBase('tests', env, e => {
|
|
353
|
+
const p = passe(racine, e);
|
|
354
|
+
const choix = composants(racine)
|
|
355
|
+
.map(c => ({
|
|
356
|
+
c,
|
|
357
|
+
chemins: fichiersDeTest(c.dossier)
|
|
358
|
+
.filter(f => estDeNuit(path.basename(f)))
|
|
359
|
+
.map(f => path.relative(c.dossier, f)),
|
|
360
|
+
}))
|
|
361
|
+
.filter(x => x.chemins.length);
|
|
362
|
+
jouerLesTests(p, choix, []);
|
|
363
|
+
return p.code();
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
if (nom === 'verifier') {
|
|
367
|
+
const dire = l => process.stdout.write(`${l}\n`);
|
|
368
|
+
try {
|
|
369
|
+
return sousLaBase('verification', env, envBase =>
|
|
370
|
+
avecLaMachine(envMachine => verifier(racine, args, envMachine), {
|
|
371
|
+
env: envBase,
|
|
372
|
+
racine,
|
|
373
|
+
dire,
|
|
374
|
+
})
|
|
375
|
+
);
|
|
376
|
+
} catch (e) {
|
|
377
|
+
if (!(e instanceof AttenteDeLaMachine)) {
|
|
378
|
+
throw e;
|
|
379
|
+
}
|
|
380
|
+
dire(e.message);
|
|
381
|
+
return e.code;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (nom === 'typer' || nom === 'preparer') {
|
|
385
|
+
return sousLaBase('tests', env, e => {
|
|
386
|
+
const p = passe(racine, e);
|
|
387
|
+
for (const c of composants(racine)) {
|
|
388
|
+
if (nom === 'typer') {
|
|
389
|
+
typerLePaquet(p, c);
|
|
390
|
+
} else {
|
|
391
|
+
p.jouer(
|
|
392
|
+
p.prevoir(c.nom, c.dossier, 'sync', false, ['sync', '--locked', '--group', GROUPE])
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return p.code();
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
process.stderr.write(`⛔ commande inconnue du module python : ${nom} (${NOMS.join(', ')})\n`);
|
|
400
|
+
return 2;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
404
|
+
const [nom, ...args] = process.argv.slice(2);
|
|
405
|
+
try {
|
|
406
|
+
process.exitCode = lancer(nom, args);
|
|
407
|
+
} catch (e) {
|
|
408
|
+
process.stderr.write(`${e.message}\n`);
|
|
409
|
+
process.exitCode = 1;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// The components of a project of Python, as uv finds a project (PEP 621, `pyproject.toml`): the
|
|
2
|
+
// packages the module python answers the join with (scripts/jointure.d.ts, `composants`,
|
|
3
|
+
// `composantDe`, `matieres`, `joueDesTests`, `lecteurs`, `estUnTest`, `manifestes`,
|
|
4
|
+
// `entreesDeLIndex`).
|
|
5
|
+
//
|
|
6
|
+
// - A component is a folder that holds a pyproject.toml, found under the root, the folders whose
|
|
7
|
+
// name begins with a dot and those of LAISSES left out: its folder, its name the folder's, its
|
|
8
|
+
// package the `name` of its table `[project]`, null without one. The language of a package is
|
|
9
|
+
// declared in the architecture (decision D2 of grillhouse-1zu); its pyproject.toml, its group
|
|
10
|
+
// `test` and its uv.lock are there because uv asks them.
|
|
11
|
+
// - The component of a file is the one of the longest folder that holds it, as uv finds the
|
|
12
|
+
// project of a file by climbing its directories.
|
|
13
|
+
// - No shared test material: a package of Python shares its helpers with its tests by its
|
|
14
|
+
// `conftest.py`, pytest's own.
|
|
15
|
+
// - A test file is one pytest collects by default (`python_files`): `test_*.py`, `*_test.py`; a
|
|
16
|
+
// night test, `*_nuit_test.py`, is one too, played at night (./commandes.mjs). A component plays
|
|
17
|
+
// tests when it holds a test file out of the night.
|
|
18
|
+
// - What the testwriter writes: a test file, its runner plays it (`joue`); a `conftest.py`, and
|
|
19
|
+
// any file under a folder `tests/` of a component, his helpers and his data. Of the manifests
|
|
20
|
+
// (`manifestes`): the group `test` of the table `[dependency-groups]` of a pyproject.toml (PEP
|
|
21
|
+
// 735), what the tests depend on, and the uv.lock of a component, which uv brings in line with
|
|
22
|
+
// it; a change of any other part of a pyproject.toml is named by it. The pyproject.toml is read
|
|
23
|
+
// with smol-toml, a tool of this module (`outils`), an optional peer of the package loaded when a
|
|
24
|
+
// manifest is judged.
|
|
25
|
+
// - The readers of a package: none read by the module (a dependency between two packages of
|
|
26
|
+
// Python is no part of this ticket); a name no component bears is without provider.
|
|
27
|
+
// - The entries of the index of the interfaces: one per component that holds a
|
|
28
|
+
// `docs/INTERFACE.md`, and the root's, its title and the first sentence under it, as the module
|
|
29
|
+
// cargo's.
|
|
30
|
+
// - A manifest (pyproject.toml, uv.lock) is never a test file, even under `tests/`.
|
|
31
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
32
|
+
import { createRequire } from 'node:module';
|
|
33
|
+
import path from 'node:path';
|
|
34
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
35
|
+
|
|
36
|
+
const require = createRequire(import.meta.url);
|
|
37
|
+
|
|
38
|
+
export const MANIFESTE = 'pyproject.toml';
|
|
39
|
+
export const VERROU = 'uv.lock';
|
|
40
|
+
/** The group of `[dependency-groups]` that holds what the tests depend on. */
|
|
41
|
+
export const GROUPE = 'test';
|
|
42
|
+
// The folders the search of the components leaves out, beside those that begin with a dot.
|
|
43
|
+
const LAISSES = new Set(['node_modules', 'target', 'dist', '__pycache__']);
|
|
44
|
+
|
|
45
|
+
/** Whether <nom>, a file's name, is a test file pytest collects. */
|
|
46
|
+
export const estUnFichierDeTest = nom => /^test_.*\.py$|_test\.py$/.test(nom);
|
|
47
|
+
/** Whether <nom>, a file's name, is a night test. */
|
|
48
|
+
export const estDeNuit = nom => nom.endsWith('_nuit_test.py');
|
|
49
|
+
|
|
50
|
+
// The name of the table `[project]` of the manifest <texte>, null for none.
|
|
51
|
+
function nomDuProjet(texte) {
|
|
52
|
+
let section = null;
|
|
53
|
+
for (const l of texte.split('\n')) {
|
|
54
|
+
const s = /^\s*\[([^\]]+)\]\s*(?:#.*)?$/.exec(l);
|
|
55
|
+
if (s) {
|
|
56
|
+
section = s[1].trim();
|
|
57
|
+
}
|
|
58
|
+
const n = /^\s*name\s*=\s*["']([^"']+)["']/.exec(l);
|
|
59
|
+
if (section === 'project' && n) {
|
|
60
|
+
return n[1];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The folders under <dossier> that hold a pyproject.toml, <dossier> included.
|
|
67
|
+
function dossiersAvecManifeste(dossier) {
|
|
68
|
+
const out = existsSync(path.join(dossier, MANIFESTE)) ? [dossier] : [];
|
|
69
|
+
for (const e of readdirSync(dossier, { withFileTypes: true })) {
|
|
70
|
+
if (e.isDirectory() && !e.name.startsWith('.') && !LAISSES.has(e.name)) {
|
|
71
|
+
out.push(...dossiersAvecManifeste(path.join(dossier, e.name)));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The components of the project at <racine>, sorted by folder. */
|
|
78
|
+
export function composants(racine) {
|
|
79
|
+
return dossiersAvecManifeste(racine)
|
|
80
|
+
.sort()
|
|
81
|
+
.map(dossier => ({
|
|
82
|
+
dossier,
|
|
83
|
+
nom: path.basename(dossier),
|
|
84
|
+
paquet: nomDuProjet(readFileSync(path.join(dossier, MANIFESTE), 'utf8')),
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The component of <liste> that holds <fichier> (absolute, or from <racine>), the longest folder. */
|
|
89
|
+
export function composantDans(liste, racine, fichier) {
|
|
90
|
+
const abs = path.resolve(racine, fichier);
|
|
91
|
+
const tenants = liste.filter(c => abs === c.dossier || abs.startsWith(`${c.dossier}${path.sep}`));
|
|
92
|
+
return tenants.sort((a, b) => b.dossier.length - a.dossier.length)[0] ?? null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The test files of <dossier> (absolute), its .venv and the folders of LAISSES left out. */
|
|
96
|
+
export function fichiersDeTest(dossier) {
|
|
97
|
+
const out = [];
|
|
98
|
+
for (const e of readdirSync(dossier, { withFileTypes: true })) {
|
|
99
|
+
const f = path.join(dossier, e.name);
|
|
100
|
+
if (e.isDirectory() && !e.name.startsWith('.') && !LAISSES.has(e.name)) {
|
|
101
|
+
if (!existsSync(path.join(f, MANIFESTE))) {
|
|
102
|
+
out.push(...fichiersDeTest(f));
|
|
103
|
+
}
|
|
104
|
+
} else if (e.isFile() && estUnFichierDeTest(e.name)) {
|
|
105
|
+
out.push(f);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return out.sort();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Whether the component <composant> plays tests: a test file out of the night. */
|
|
112
|
+
export const joueDesTests = (_racine, composant) =>
|
|
113
|
+
fichiersDeTest(composant.dossier).some(f => !estDeNuit(path.basename(f)));
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* What the testwriter writes in <chemin>, absolute or from <racine>: `{ joue, test, matiere }`, or
|
|
117
|
+
* null for a file he does not write.
|
|
118
|
+
*/
|
|
119
|
+
export function estUnTest(chemin, racine) {
|
|
120
|
+
const abs = path.resolve(racine, chemin);
|
|
121
|
+
const c = composantDans(composants(racine), racine, abs);
|
|
122
|
+
if (!c) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const parts = path.relative(c.dossier, abs).split(path.sep);
|
|
126
|
+
const nom = parts.at(-1);
|
|
127
|
+
if (estUnFichierDeTest(nom)) {
|
|
128
|
+
return { joue: true, test: true, matiere: false };
|
|
129
|
+
}
|
|
130
|
+
// A manifest is never a test file: under `tests/`, it would make a package of its own.
|
|
131
|
+
if ([MANIFESTE, VERROU].includes(nom)) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
if (nom === 'conftest.py' || parts.slice(0, -1).includes('tests')) {
|
|
135
|
+
return { joue: false, test: true, matiere: false };
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// The parts of the parsed manifests <a> and <b> that differ, out of the group of the tests: each
|
|
141
|
+
// `[<table>]`, a group of `[dependency-groups]` as `[dependency-groups].<groupe>`, a key out of
|
|
142
|
+
// every table bare.
|
|
143
|
+
function partiesHors(a, b) {
|
|
144
|
+
const cles = (x, y) => [...new Set([...Object.keys(x ?? {}), ...Object.keys(y ?? {})])].sort();
|
|
145
|
+
const out = [];
|
|
146
|
+
for (const k of cles(a, b)) {
|
|
147
|
+
if (isDeepStrictEqual(a[k], b[k])) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (k === 'dependency-groups') {
|
|
151
|
+
for (const g of cles(a[k], b[k])) {
|
|
152
|
+
if (g !== GROUPE && !isDeepStrictEqual(a[k]?.[g], b[k]?.[g])) {
|
|
153
|
+
out.push(`[dependency-groups].${g}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const tableau = [a[k], b[k]].some(v => v !== null && typeof v === 'object');
|
|
159
|
+
out.push(tableau ? `[${k}]` : k);
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The parts of a file of a component at <chemin> (absolute, or from <racine>) that change from
|
|
166
|
+
* <avant> (null: no file) to <apres> out of the part of its tests: of its pyproject.toml, every
|
|
167
|
+
* part but the group `test` of `[dependency-groups]`; of its uv.lock, none. Null for any other file.
|
|
168
|
+
*/
|
|
169
|
+
function horsDesTests(chemin, racine, avant, apres) {
|
|
170
|
+
const abs = path.resolve(racine, chemin);
|
|
171
|
+
const c = composants(racine).find(x => x.dossier === path.dirname(abs));
|
|
172
|
+
const nom = path.basename(abs);
|
|
173
|
+
if (!c || ![MANIFESTE, VERROU].includes(nom)) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
if (nom === VERROU) {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
const { parse } = require('smol-toml');
|
|
180
|
+
const lire = texte => {
|
|
181
|
+
try {
|
|
182
|
+
return { valeur: parse(texte ?? '') };
|
|
183
|
+
} catch (e) {
|
|
184
|
+
return { faute: `le manifeste entier, illisible (${e.message.split('\n')[0]})` };
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const [x, y] = [lire(avant), lire(apres)];
|
|
188
|
+
if (x.faute || y.faute) {
|
|
189
|
+
return [x.faute ?? y.faute];
|
|
190
|
+
}
|
|
191
|
+
return partiesHors(x.valeur, y.valeur);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** What the testwriter writes of the manifests (scripts/jointure.d.ts, `manifestes`). */
|
|
195
|
+
export const manifestes = { verrous: [VERROU], horsDesTests };
|
|
196
|
+
|
|
197
|
+
/** The readers of the packages <noms>: none; a name no component bears, without provider. */
|
|
198
|
+
export function lecteurs(_racine, { composants: liste, noms }) {
|
|
199
|
+
const elements = [];
|
|
200
|
+
const sansFournisseur = [];
|
|
201
|
+
for (const nom of noms) {
|
|
202
|
+
const fournisseur = liste.find(c => c.paquet === nom || c.nom === nom);
|
|
203
|
+
if (fournisseur) {
|
|
204
|
+
elements.push({ nom, fournisseur, lecteurs: [] });
|
|
205
|
+
} else {
|
|
206
|
+
sansFournisseur.push(nom);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
elements,
|
|
211
|
+
sansFournisseur,
|
|
212
|
+
types: { etat: 'fait', raison: null, elements: [] },
|
|
213
|
+
lit: new Map(liste.map(c => [c, new Set()])),
|
|
214
|
+
parLesTests: new Map(liste.map(c => [c, new Set()])),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const premierePhrase = lignes => {
|
|
219
|
+
const texte = lignes.join(' ').replace(/\s+/g, ' ').trim();
|
|
220
|
+
return /^(.+?[.!?])(\s|$)/.exec(texte)?.[1] ?? texte;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// The interface of the root.
|
|
224
|
+
const RACINE = 'docs/INTERFACE.md';
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* The entries of the index of the interfaces of <racine> (`entreesDeLIndex`): `{ rel, lignes }`
|
|
228
|
+
* for each `<composant>/docs/INTERFACE.md`, and for the root's `docs/INTERFACE.md`, by path; the
|
|
229
|
+
* heading the title alone when it begins with the component's name, else `<composant> — <titre>`,
|
|
230
|
+
* the root's `(racine)` when no package lies at the root, as the module cargo's.
|
|
231
|
+
*/
|
|
232
|
+
export function entreesDeLIndex(racine) {
|
|
233
|
+
const parRel = new Map();
|
|
234
|
+
for (const c of composants(racine)) {
|
|
235
|
+
const rel = path.relative(racine, path.join(c.dossier, 'docs', 'INTERFACE.md'));
|
|
236
|
+
if (existsSync(path.join(racine, rel))) {
|
|
237
|
+
parRel.set(rel.split(path.sep).join('/'), c.nom);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (existsSync(path.join(racine, RACINE)) && !parRel.has(RACINE)) {
|
|
241
|
+
parRel.set(RACINE, '(racine)');
|
|
242
|
+
}
|
|
243
|
+
return [...parRel]
|
|
244
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
245
|
+
.map(([rel, nom]) => {
|
|
246
|
+
const lignes = readFileSync(path.join(racine, rel), 'utf8').split('\n');
|
|
247
|
+
const t = lignes.findIndex(l => l.startsWith('# '));
|
|
248
|
+
const titre = t >= 0 ? lignes[t].slice(2).trim() : nom;
|
|
249
|
+
const paragraphe = [];
|
|
250
|
+
for (const l of lignes.slice(t + 1)) {
|
|
251
|
+
if (/^#{1,6} /.test(l) || (!l.trim() && paragraphe.length)) {
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
if (l.trim()) {
|
|
255
|
+
paragraphe.push(l.trim());
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const parSonNom =
|
|
259
|
+
nom !== '(racine)' &&
|
|
260
|
+
titre.startsWith(nom) &&
|
|
261
|
+
(titre.length === nom.length || /\s/.test(titre[nom.length]));
|
|
262
|
+
return {
|
|
263
|
+
rel,
|
|
264
|
+
lignes: [
|
|
265
|
+
`## ${parSonNom ? titre : `${nom} — ${titre}`}`,
|
|
266
|
+
'',
|
|
267
|
+
`${premierePhrase(paragraphe)} (\`${rel}\`)`,
|
|
268
|
+
'',
|
|
269
|
+
],
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
}
|