@roomi-fields/grillhouse 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/cadre/templates/projet/CLAUDE.md +7 -0
  3. package/cadre/templates/projet/docs/ARCHITECTURE.md +15 -0
  4. package/cadre/templates/python/package.json +18 -0
  5. package/charte.md +22 -0
  6. package/docs/ARCHITECTURE.md +58 -17
  7. package/docs/CADRE.md +7 -6
  8. package/docs/INTERFACE.md +96 -32
  9. package/package.json +1 -1
  10. package/scripts/circuit.mjs +44 -8
  11. package/scripts/commande-du-langage.mjs +2 -2
  12. package/scripts/commandes-composees.mjs +156 -0
  13. package/scripts/composition-des-langages.mjs +306 -0
  14. package/scripts/conformite.mjs +1 -3
  15. package/scripts/dernier-vert.mjs +15 -2
  16. package/scripts/engendres.mjs +170 -0
  17. package/scripts/enveloppe/travail-de-la-copie.mjs +82 -8
  18. package/scripts/gardes-du-cadre.mjs +7 -4
  19. package/scripts/grillhouse-maj.mjs +152 -99
  20. package/scripts/index-interfaces.mjs +78 -0
  21. package/scripts/init.mjs +5 -5
  22. package/scripts/integration/file.mjs +74 -13
  23. package/scripts/integration/integrer.mjs +50 -62
  24. package/scripts/jointure.d.ts +26 -13
  25. package/scripts/langages/cargo/binaires.mjs +29 -6
  26. package/scripts/langages/cargo/clippy.mjs +4 -2
  27. package/scripts/langages/cargo/commandes.mjs +45 -7
  28. package/scripts/langages/cargo/exemples.mjs +1 -15
  29. package/scripts/langages/cargo/index-interfaces.mjs +20 -3
  30. package/scripts/langages/cargo/index.mjs +9 -10
  31. package/scripts/langages/cargo/mise-a-jour.mjs +2 -1
  32. package/scripts/langages/cargo/sccache.mjs +29 -0
  33. package/scripts/langages/python/binaires.json +3 -0
  34. package/scripts/langages/python/binaires.mjs +59 -0
  35. package/scripts/langages/python/commandes.mjs +411 -0
  36. package/scripts/langages/python/composants.mjs +272 -0
  37. package/scripts/langages/python/exemples.mjs +260 -0
  38. package/scripts/langages/python/index-interfaces.mjs +77 -0
  39. package/scripts/langages/python/index.mjs +94 -0
  40. package/scripts/langages/python/lot.mjs +76 -0
  41. package/scripts/langages/python/mise-a-jour.mjs +54 -0
  42. package/scripts/langages/python/tailles-des-tests.mjs +102 -0
  43. package/scripts/langages/python/verdict.mjs +85 -0
  44. package/scripts/langages/typescript/exemples.mjs +1 -20
  45. package/scripts/langages/typescript/index-interfaces.mjs +10 -3
  46. package/scripts/langages/typescript/index.mjs +11 -15
  47. package/scripts/langages-des-paquets.mjs +171 -0
  48. package/scripts/langages.mjs +60 -41
  49. package/scripts/migrations/0.27.0-langages-dans-l-architecture.mjs +182 -0
  50. package/scripts/migrations.mjs +2 -0
  51. package/scripts/outils-cles.mjs +1 -1
  52. package/scripts/session-start.sh +34 -9
  53. package/scripts/sources.mjs +2 -1
  54. package/scripts/sous-commandes.mjs +5 -3
  55. package/scripts/tableau-des-composants.mjs +138 -0
  56. package/scripts/verrous/verrou.mjs +3 -2
  57. package/skills/grill/SKILL.md +9 -1
  58. package/skills/pitmaster/SKILL.md +6 -1
  59. package/skills/redacteur/references/documents-d-un-composant.md +12 -0
  60. package/skills/testwriter/SKILL.md +6 -0
@@ -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
+ }
@@ -0,0 +1,260 @@
1
+ // The entries of the suite of conformity (scripts/conformite.mjs) for the module python, as the
2
+ // valid and invalid cases a rule of ESLint gives its RuleTester: each a trial, built under the
3
+ // directory the suite gives, with what a sound module answers on it.
4
+ //
5
+ // - A project of two packages, declared python in its architecture: `site` (its project
6
+ // `generateur`, a test of the day `pages/test_pages.py`, a night test, a `conftest.py`, its
7
+ // interface) and `outil` (its project `outil`, no test); the root's interface, and the index of
8
+ // the interfaces they give, up to date. Committed: `projet`; the same, a source of `site` then
9
+ // changed and a file out of every package added: `change`, measured from its commit; the same
10
+ // with a second commit that changes `site`, adds the package `neuf` and removes `outil`: `lot`;
11
+ // the same, the interface of `site` then changed, its index late: `enRetard`.
12
+ // - A directory without pyproject.toml: `vide`.
13
+ // - Two results directories of a run: every task and test green (`vert`); `site` red with a test
14
+ // failed, `outil` at 75, a task not played (`defaut`).
15
+ // - `depots`: the repositories, for the tests of the module beside the suite.
16
+ import { execFileSync } from 'node:child_process';
17
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
18
+ import path from 'node:path';
19
+
20
+ const ecrireDans = racine => (rel, texte) => {
21
+ mkdirSync(path.dirname(path.join(racine, rel)), { recursive: true });
22
+ writeFileSync(path.join(racine, rel), texte);
23
+ };
24
+ const git = (racine, ...args) => execFileSync('git', ['-C', racine, ...args], { stdio: 'pipe' });
25
+ const tete = racine =>
26
+ execFileSync('git', ['-C', racine, 'rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
27
+
28
+ // Commits every file of <racine>, a new repository.
29
+ function engager(racine) {
30
+ git(racine, 'init', '-q', '-b', 'main');
31
+ git(racine, 'config', 'user.email', 'essai@example.com');
32
+ git(racine, 'config', 'user.name', 'essai');
33
+ git(racine, 'config', 'commit.gpgsign', 'false');
34
+ git(racine, 'add', '-A');
35
+ git(racine, 'commit', '-q', '-m', 'essai');
36
+ return racine;
37
+ }
38
+
39
+ // The pyproject.toml of the project <nom>.
40
+ const manifeste = nom =>
41
+ `[project]\nname = "${nom}"\nversion = "0.1.0"\nrequires-python = ">=3.10"\ndependencies = []\n\n[dependency-groups]\ntest = ["pytest>=8"]\n`;
42
+
43
+ const ARCHITECTURE =
44
+ '# Architecture\n\n| Composant | Langage |\n| --- | --- |\n| `site` | python |\n| `outil` | python |\n| `neuf` | python |\n';
45
+ const INTERFACES = {
46
+ 'site/docs/INTERFACE.md': '# site — interface\n\n`site` génère les pages. Une seconde phrase.\n',
47
+ 'docs/INTERFACE.md': "# Le projet d'essai\n\nDeux paquets Python.\n",
48
+ };
49
+ /** The index of the interfaces the trial gives (./index-interfaces.mjs). */
50
+ export const INDEX = [
51
+ '# Index des interfaces',
52
+ '',
53
+ 'Généré depuis les `INTERFACE.md` des paquets Python ; ne pas éditer.',
54
+ "Une ligne par composant ; l'interface donne le détail.",
55
+ '',
56
+ "## (racine) — Le projet d'essai",
57
+ '',
58
+ 'Deux paquets Python. (`docs/INTERFACE.md`)',
59
+ '',
60
+ '## site — interface',
61
+ '',
62
+ '`site` génère les pages. (`site/docs/INTERFACE.md`)',
63
+ '',
64
+ ].join('\n');
65
+
66
+ // The project of the two packages in a new directory under <dans>, committed.
67
+ function projet(dans) {
68
+ const racine = mkdtempSync(path.join(dans, 'projet-'));
69
+ const ecrire = ecrireDans(racine);
70
+ ecrire('package.json', JSON.stringify({ name: 'essai', private: true }));
71
+ ecrire('docs/ARCHITECTURE.md', ARCHITECTURE);
72
+ ecrire('README.md', "# Le projet d'essai\n");
73
+ ecrire('.gitignore', '.venv\n.pytest_cache\n__pycache__\n');
74
+ ecrire('site/pyproject.toml', manifeste('generateur'));
75
+ ecrire('site/uv.lock', 'version = 1\n');
76
+ ecrire('site/pages/generer.py', 'def generer():\n return 1\n');
77
+ ecrire('site/pages/test_pages.py', 'def test_generer():\n assert True\n');
78
+ ecrire('site/pages/site_nuit_test.py', 'def test_tout():\n assert True\n');
79
+ ecrire('site/conftest.py', '');
80
+ ecrire('outil/pyproject.toml', manifeste('outil'));
81
+ ecrire('outil/uv.lock', 'version = 1\n');
82
+ ecrire('outil/outil.py', 'def outil():\n return 1\n');
83
+ for (const [f, t] of Object.entries(INTERFACES)) {
84
+ ecrire(f, t);
85
+ }
86
+ ecrire('docs/agents/index-des-interfaces.md', INDEX);
87
+ return engager(racine);
88
+ }
89
+
90
+ // A results directory under <dans>: the tasks <taches> (`[paquet, script, code]`), and the JUnit
91
+ // report of `site` (`[[fichier, test, echoue]…]`), its folder <dossier>.
92
+ function resultats(dans, taches, cas, dossier) {
93
+ const d = mkdtempSync(path.join(dans, 'resultats-'));
94
+ const ecrire = ecrireDans(d);
95
+ ecrire(
96
+ 'python/1-1.json',
97
+ `${JSON.stringify({
98
+ taches: taches.map(([paquet, script, code]) => ({
99
+ tache: `${paquet}#${script}`,
100
+ paquet,
101
+ dossier: paquet,
102
+ script,
103
+ tests: script === 'pytest',
104
+ code,
105
+ cache: null,
106
+ journal: null,
107
+ })),
108
+ rapports: { '1-1-site.xml': dossier },
109
+ })}\n`
110
+ );
111
+ const corps = cas
112
+ .map(
113
+ ([fichier, test, echoue]) =>
114
+ `<testcase classname="x" name="${test}" file="${fichier}" line="1">${
115
+ echoue ? '<failure message="assert 1 == 2">assert 1 == 2</failure>' : ''
116
+ }</testcase>`
117
+ )
118
+ .join('');
119
+ ecrire(
120
+ 'pytest/1-1-site.xml',
121
+ `<?xml version="1.0"?><testsuites><testsuite name="pytest">${corps}</testsuite></testsuites>`
122
+ );
123
+ return d;
124
+ }
125
+
126
+ export default {
127
+ // The trials under <dans>.
128
+ preparer(dans) {
129
+ const aJour = projet(dans);
130
+ const vide = mkdtempSync(path.join(dans, 'vide-'));
131
+ writeFileSync(path.join(vide, 'README.md'), 'aucun paquet\n');
132
+ const change = projet(dans);
133
+ const depuis = tete(change);
134
+ writeFileSync(path.join(change, 'site/pages/generer.py'), 'def generer():\n return 2\n');
135
+ writeFileSync(path.join(change, 'notes.txt'), 'hors des paquets\n');
136
+ const lot = projet(dans);
137
+ const avantLeLot = tete(lot);
138
+ const ecrireLot = ecrireDans(lot);
139
+ ecrireLot('site/pages/generer.py', 'def generer():\n return 3\n');
140
+ ecrireLot('neuf/pyproject.toml', manifeste('neuf'));
141
+ ecrireLot('neuf/neuf.py', 'def neuf():\n return 1\n');
142
+ rmSync(path.join(lot, 'outil'), { recursive: true, force: true });
143
+ git(lot, 'add', '-A');
144
+ git(lot, 'commit', '-q', '-m', 'lot');
145
+ const enRetard = projet(dans);
146
+ writeFileSync(
147
+ path.join(enRetard, 'site/docs/INTERFACE.md'),
148
+ '# site — interface\n\n`site` génère d’autres pages.\n'
149
+ );
150
+ const site = path.join(aJour, 'site');
151
+ return {
152
+ racine: aJour,
153
+ depots: { projet: aJour, change, depuis, lot, avantLeLot, enRetard, vide },
154
+ composants: {
155
+ valide: vide,
156
+ invalide: aJour,
157
+ attendu: ['outil (outil)', 'site (generateur)'],
158
+ },
159
+ composantDe: {
160
+ valide: [
161
+ { fichier: 'site/pages/generer.py', composant: 'site' },
162
+ { fichier: 'outil/outil.py', composant: 'outil' },
163
+ { fichier: path.join(aJour, 'site/pyproject.toml'), composant: 'site' },
164
+ ],
165
+ invalide: [{ fichier: 'README.md' }, { fichier: 'docs/INTERFACE.md' }],
166
+ attendu: [
167
+ 'README.md : hors de tout composant',
168
+ 'docs/INTERFACE.md : hors de tout composant',
169
+ ],
170
+ },
171
+ lecteurs: {
172
+ valide: { racine: vide, noms: [] },
173
+ invalide: { racine: aJour, noms: ['generateur', 'absent'] },
174
+ attendu: ['absent : sans fournisseur'],
175
+ },
176
+ touches: {
177
+ valide: { racine: aJour, depuis: 'HEAD' },
178
+ invalide: { racine: change, depuis },
179
+ attendu: ['touché site', 'hors notes.txt'],
180
+ },
181
+ commandes: {
182
+ valide: ['tester', 'verifier', 'typer', 'preparer', 'tests-de-nuit', 'index-interfaces'],
183
+ invalide: ['tester', 'deployer'],
184
+ attendu: ['deployer : absente'],
185
+ },
186
+ verdict: {
187
+ valide: resultats(
188
+ dans,
189
+ [
190
+ ['site', 'compileall', 0],
191
+ ['site', 'pytest', 0],
192
+ ],
193
+ [['pages/test_pages.py', 'test_generer', false]],
194
+ site
195
+ ),
196
+ invalide: resultats(
197
+ dans,
198
+ [
199
+ ['outil', 'compileall', 75],
200
+ ['site', 'pytest', 1],
201
+ ['neuf', 'pytest', null],
202
+ ],
203
+ [
204
+ ['pages/test_pages.py', 'test_generer', false],
205
+ ['pages/test_pages.py', 'test_rendu', true],
206
+ ],
207
+ site
208
+ ),
209
+ attendu: [
210
+ 'outil#compileall à repasser',
211
+ 'site#pytest rouge (1), tests',
212
+ 'test test_pages.py › test_rendu',
213
+ ],
214
+ },
215
+ estUnTest: {
216
+ valide: [
217
+ 'site/pages/generer.py',
218
+ 'site/pyproject.toml',
219
+ 'site/uv.lock',
220
+ 'outil/outil.py',
221
+ 'README.md',
222
+ ],
223
+ invalide: ['site/pages/test_pages.py', 'site/conftest.py', 'site/tests/donnees.json'],
224
+ attendu: [
225
+ 'site/pages/test_pages.py : joue, test',
226
+ 'site/conftest.py : test',
227
+ 'site/tests/donnees.json : test',
228
+ ],
229
+ },
230
+ fichiersEngendres: {
231
+ valide: aJour,
232
+ invalide: enRetard,
233
+ attendu: ["l'index des interfaces : en retard"],
234
+ },
235
+ gardes: { valide: ['tailles-des-tests', 'index-interfaces'] },
236
+ elementsDuLot: {
237
+ valide: { racine: aJour, avant: 'HEAD', apres: 'HEAD' },
238
+ invalide: { racine: lot, avant: avantLeLot, apres: 'HEAD' },
239
+ attendu: [
240
+ 'fichier neuf/neuf.py',
241
+ 'fichier neuf/pyproject.toml',
242
+ 'fichier outil/outil.py',
243
+ 'fichier outil/pyproject.toml',
244
+ 'fichier outil/uv.lock',
245
+ 'fichier site/pages/generer.py',
246
+ 'hors du service neuf/neuf.py',
247
+ 'hors du service outil/outil.py',
248
+ 'hors du service site/pages/generer.py',
249
+ ],
250
+ },
251
+ // No shared test material in Python (./composants.mjs): the case has no defective entry.
252
+ matieres: { valide: aJour, invalide: aJour, attendu: [] },
253
+ joueDesTests: {
254
+ valide: vide,
255
+ invalide: aJour,
256
+ attendu: ['site (generateur) : joue des tests'],
257
+ },
258
+ };
259
+ },
260
+ };
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ // The index of the interfaces of a project of Python: one line per package, from its
3
+ // `docs/INTERFACE.md`, and one for the root's, which an agent loads at start before opening an
4
+ // interface; a generated file of the module (`fichiersEngendres` of ./index.mjs), as the module
5
+ // cargo's (../cargo/index-interfaces.mjs), whose file and form it keeps. In a project of several
6
+ // languages the core's index takes its place, assembled from each module's entries.
7
+ //
8
+ // node index-interfaces.mjs writes docs/agents/index-des-interfaces.md
9
+ // node index-interfaces.mjs --verifier refuses (exit 1) when that file is out of date, its
10
+ // finding in SARIF too (../../resultats.mjs)
11
+ // node index-interfaces.mjs --publie <composant>
12
+ // prints nothing: a package's interface names no
13
+ // consumer, which the launcher reads (lancer.sh)
14
+ //
15
+ // - The entries are those of ./composants.mjs (`entreesDeLIndex`), in their paths' order.
16
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
17
+ import path from 'node:path';
18
+ import { fileURLToPath, pathToFileURL } from 'node:url';
19
+ import { ecrireSarif } from '../../resultats.mjs';
20
+ import { entreesDeLIndex } from './composants.mjs';
21
+
22
+ export const SORTIE = 'docs/agents/index-des-interfaces.md';
23
+ export const GARDE = 'index-interfaces';
24
+ const ICI = fileURLToPath(import.meta.url);
25
+
26
+ /** The index of the interfaces of the project at <racine>, as its file holds it. */
27
+ export function index(racine) {
28
+ return [
29
+ '# Index des interfaces',
30
+ '',
31
+ 'Généré depuis les `INTERFACE.md` des paquets Python ; ne pas éditer.',
32
+ "Une ligne par composant ; l'interface donne le détail.",
33
+ '',
34
+ ...entreesDeLIndex(racine).flatMap(e => e.lignes),
35
+ ].join('\n');
36
+ }
37
+
38
+ /** The findings of the check of the index at <racine>: none when its file is up to date. */
39
+ export function enRetard(racine) {
40
+ const cible = path.join(racine, SORTIE);
41
+ const present = existsSync(cible) ? readFileSync(cible, 'utf8') : '';
42
+ return present === index(racine)
43
+ ? []
44
+ : [
45
+ {
46
+ fichier: SORTIE,
47
+ message: `${SORTIE} n'est pas à jour avec les interfaces : sa commande le régénère (node ${JSON.stringify(ICI)}).`,
48
+ },
49
+ ];
50
+ }
51
+
52
+ /**
53
+ * Runs the command in the project at <racine> with <args>: its exit code.
54
+ * @param {string} racine
55
+ * @param {string[]} args `--verifier` to check, `--publie` to print nothing, nothing to write
56
+ * @param {{ env?: NodeJS.ProcessEnv }} [o]
57
+ */
58
+ export function commande(racine, args, { env = process.env } = {}) {
59
+ if (args.includes('--publie')) {
60
+ return 0;
61
+ }
62
+ if (!args.includes('--verifier')) {
63
+ mkdirSync(path.dirname(path.join(racine, SORTIE)), { recursive: true });
64
+ writeFileSync(path.join(racine, SORTIE), index(racine));
65
+ return 0;
66
+ }
67
+ const refus = enRetard(racine);
68
+ for (const r of refus) {
69
+ process.stderr.write(`⛔ ${r.message}\n`);
70
+ }
71
+ ecrireSarif({ garde: GARDE, racine, constats: refus, env });
72
+ return refus.length ? 1 : 0;
73
+ }
74
+
75
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
76
+ process.exitCode = commande(process.cwd(), process.argv.slice(2));
77
+ }