@roomi-fields/grillhouse 0.28.2 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/bin/grillhouse.mjs +55 -14
  3. package/cadre/templates/projet/CLAUDE.md +1 -1
  4. package/cadre/templates/projet/README.md +11 -11
  5. package/cadre/templates/projet/_gitignore +2 -5
  6. package/charte.md +24 -3
  7. package/docs/ARCHITECTURE.md +279 -31
  8. package/docs/INTERFACE.md +59 -11
  9. package/package.json +1 -1
  10. package/scripts/aiguillage.mjs +324 -0
  11. package/scripts/avancement.mjs +33 -50
  12. package/scripts/circuit.mjs +558 -146
  13. package/scripts/composition-des-langages.mjs +16 -1
  14. package/scripts/conformite.mjs +16 -0
  15. package/scripts/copies-finies.mjs +181 -29
  16. package/scripts/demon.mjs +134 -21
  17. package/scripts/enveloppe/enveloppe.mjs +8 -5
  18. package/scripts/enveloppe/lancer.sh +24 -15
  19. package/scripts/enveloppe/travail-de-la-copie.mjs +94 -11
  20. package/scripts/etapes.mjs +1 -1
  21. package/scripts/fusion-du-changelog.mjs +0 -1
  22. package/scripts/grillhouse-maj.mjs +16 -7
  23. package/scripts/integration/file.mjs +3 -3
  24. package/scripts/integration/integrer.mjs +3 -3
  25. package/scripts/jointure.d.ts +53 -17
  26. package/scripts/langages/cargo/commandes.mjs +152 -25
  27. package/scripts/langages/cargo/composants.mjs +94 -2
  28. package/scripts/langages/cargo/exemples.mjs +68 -1
  29. package/scripts/langages/cargo/index.mjs +21 -10
  30. package/scripts/langages/cargo/migrations/0.28.4-tailles-des-tests.mjs +35 -0
  31. package/scripts/langages/cargo/sccache.mjs +89 -6
  32. package/scripts/langages/cargo/squelette.mjs +72 -3
  33. package/scripts/langages/cargo/tailles-des-tests.mjs +195 -0
  34. package/scripts/langages/cargo/tests-de-head.mjs +159 -0
  35. package/scripts/langages/python/commandes.mjs +53 -9
  36. package/scripts/langages/python/composants.mjs +33 -3
  37. package/scripts/langages/python/exemples.mjs +19 -0
  38. package/scripts/langages/python/index.mjs +7 -2
  39. package/scripts/langages/python/squelette.mjs +119 -17
  40. package/scripts/langages/typescript/exemples.mjs +16 -0
  41. package/scripts/langages/typescript/index.mjs +6 -3
  42. package/scripts/langages/typescript/regle-des-tests.mjs +13 -0
  43. package/scripts/langages/typescript/squelette.mjs +18 -2
  44. package/scripts/langages/typescript/tests-de-nuit.mjs +50 -20
  45. package/scripts/langages/typescript/verifier.mjs +82 -288
  46. package/scripts/langages/typescript/vitest-config/base.mjs +8 -9
  47. package/scripts/langages/typescript/vitest-config/cibles.mjs +92 -53
  48. package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +11 -5
  49. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +6 -1
  50. package/scripts/langages/typescript/vitest-config/mesure.mjs +3 -2
  51. package/scripts/langages/typescript/vitest.nuit.config.mjs +18 -13
  52. package/scripts/lecture-unique.mjs +51 -0
  53. package/scripts/mesure/base-de-passe.mjs +202 -9
  54. package/scripts/mesure/pression.mjs +9 -7
  55. package/scripts/nuit.sh +19 -12
  56. package/scripts/outil.mjs +72 -0
  57. package/scripts/paquet.mjs +39 -10
  58. package/scripts/resultats.mjs +22 -5
  59. package/scripts/services-du-noyau.mjs +16 -10
  60. package/scripts/session-start.sh +10 -1
  61. package/scripts/sortie.mjs +20 -1
  62. package/scripts/sources.mjs +3 -3
  63. package/scripts/sous-commandes.mjs +2 -0
  64. package/scripts/superviseur.mjs +369 -14
  65. package/scripts/tableau.mjs +219 -58
  66. package/scripts/verrou-de-machine.mjs +425 -37
  67. package/skills/developpeur/SKILL.md +11 -3
  68. package/skills/pitmaster/SKILL.md +64 -23
  69. package/skills/pitmaster/references/consigne-agent.md +4 -0
  70. package/skills/relecteur/SKILL.md +18 -6
  71. package/skills/testwriter/SKILL.md +11 -15
@@ -19,9 +19,17 @@
19
19
  // and pytest plays that path alone; a path out of every package is refused, named, and nothing
20
20
  // plays (code 2). Without a path, every package that plays tests plays, or, under the circuit's
21
21
  // mark (`GRILLHOUSE_DEPUIS_LE_VERT`), the packages the changes since the last green touch
22
- // (./lot.mjs), every package when no last green counts; the night tests (`*_nuit_test.py`) are
23
- // left out (`--ignore-glob`), and a night test plays when its own file is named. `--force`
24
- // changes nothing: pytest keeps no result to replay. Another option goes to pytest.
22
+ // (./lot.mjs), every package when no last green counts. The night tests (`*_nuit_test.py`, the
23
+ // one class out of the day: Python has no time budget bench) are left out of every folder,
24
+ // played whole or named (`--ignore-glob`), and a night test plays when its own file is named,
25
+ // as the module cargo's: pytest never ignores a path named, and a folder named that holds a
26
+ // night file named gives its tests of the day file by file, since pytest would collect that
27
+ // file through the folder (grillhouse-1ic.1). `--force`
28
+ // changes nothing: pytest keeps no result to replay. Another option goes to pytest. A package
29
+ // played whole (no path, or its own folder named) whose pytest collects no test (code 5) is
30
+ // green, as `cargo test` on a crate without a test and the skeleton typescript's
31
+ // `passWithNoTests`; a path within the package that collects no test stays red, as a run whose
32
+ // paths name no test fails in every language.
25
33
  // - `verifier` plays, in each package the changes since the last green touch (every package with
26
34
  // `--tout`, or when no last green counts), the typing then the tests of the day; green, it keeps
27
35
  // the last green (scripts/dernier-vert.mjs). It plays under the lock of the machine
@@ -43,7 +51,8 @@
43
51
  // environment of each package under `.venv/<dossier>` at the root (UV_PROJECT_ENVIRONMENT), and
44
52
  // pytest its cache under `.pytest_cache/<dossier>` (`cache_dir`), where the envelope opens them
45
53
  // in writing, rather than in the package's folder, which a session whose plan does not write the
46
- // package could not write.
54
+ // package could not write; uv its cache under ~/.cache/grillhouse/uv (UV_CACHE_DIR), the frame's
55
+ // caches of compilation, never in the temporary directory.
47
56
  // - While the environment names a results directory (`GRILLHOUSE_RESULTATS`), the run writes
48
57
  // there what ./verdict.mjs reads: its tasks, each planned before it plays, and the JUnit report
49
58
  // of each run of pytest.
@@ -59,6 +68,7 @@ import { RESULTATS } from '../../resultats.mjs';
59
68
  import {
60
69
  AttenteDeLaMachine,
61
70
  avecLaMachine,
71
+ cacheDeCompilation,
62
72
  CHANGEMENTS,
63
73
  DEPUIS_LE_VERT,
64
74
  garderLeVert,
@@ -113,7 +123,12 @@ function passe(racine, env) {
113
123
  const id = `${Date.now()}-${process.pid}`;
114
124
  const taches = [];
115
125
  const rapports = {};
116
- const environnement = { ...env, PYTHONPYCACHEPREFIX: path.join(racine, PYCACHE) };
126
+ // uv keeps its cache with the frame's caches of compilation, out of the temporary directory.
127
+ const environnement = {
128
+ ...env,
129
+ PYTHONPYCACHEPREFIX: path.join(racine, PYCACHE),
130
+ UV_CACHE_DIR: cacheDeCompilation('uv', env),
131
+ };
117
132
  const ecrire = () => {
118
133
  if (!dossier) {
119
134
  return;
@@ -151,7 +166,8 @@ function passe(racine, env) {
151
166
  rapports[f] = dossierDuPaquet;
152
167
  return ['-o', 'junit_family=xunit1', `--junit-xml=${path.join(dossier, JUNIT, f)}`];
153
168
  },
154
- jouer({ t, args, cwd, programme }) {
169
+ // <vert>, the codes that count green beside 0.
170
+ jouer({ t, args, cwd, programme }, vert = []) {
155
171
  // The environment of uv of the package, at the root (`sorties` of ./index.mjs).
156
172
  const venv = path.join(racine, VENV, path.relative(racine, cwd));
157
173
  const r = spawnSync(programme, args, {
@@ -163,6 +179,9 @@ function passe(racine, env) {
163
179
  process.stderr.write("⛔ uv absent du PATH : `npx grillhouse maj` l'installe.\n");
164
180
  }
165
181
  t.code = r.error ? 127 : (r.status ?? 128 + (constants.signals[r.signal] ?? 0));
182
+ if (vert.includes(t.code)) {
183
+ t.code = 0;
184
+ }
166
185
  ecrire();
167
186
  return t.code;
168
187
  },
@@ -177,16 +196,41 @@ function passe(racine, env) {
177
196
  }
178
197
 
179
198
  const UV_RUN = ['run', '--locked'];
199
+ // The code of pytest for « no tests collected », distinct from a failure (1).
200
+ const AUCUN_TEST = 5;
201
+
202
+ // The selection of pytest for the paths <chemins> of the package <c>, from its folder (empty: the
203
+ // whole package): the night left out of every folder (`--ignore-glob`), as the module cargo's;
204
+ // a night file named plays, pytest never ignoring a path named, unless a folder named holds it,
205
+ // through which pytest collects it: that folder then gives its tests of the day, file by file.
206
+ function selection(c, chemins) {
207
+ const nuits = chemins.filter(ch => estDeNuit(path.basename(ch)));
208
+ const tient = (d, f) => d !== f && !path.relative(d, f).startsWith('..');
209
+ const nommes = chemins.flatMap(ch => {
210
+ if (!nuits.some(n => tient(ch, n))) {
211
+ return [ch];
212
+ }
213
+ return fichiersDeTest(path.join(c.dossier, ch))
214
+ .filter(f => !estDeNuit(path.basename(f)))
215
+ .map(f => path.relative(c.dossier, f));
216
+ });
217
+ return [`--ignore-glob=${DE_NUIT}`, ...nommes];
218
+ }
180
219
 
181
220
  // 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.
221
+ // folder (empty: the whole package), the night left out (`selection`), <options> given to pytest.
222
+ // The package played whole (no path, or its own folder) that collects no test is green, as
223
+ // `cargo test` on a crate without a test; a path within it that collects none stays red.
183
224
  function jouerLesTests(p, choix, options) {
184
225
  for (const { c, chemins } of choix) {
185
- const selection = chemins.length ? chemins : [`--ignore-glob=${DE_NUIT}`];
186
226
  const cache = path.join(p.racine, CACHE_DE_PYTEST, path.relative(p.racine, c.dossier));
187
227
  const args = [...UV_RUN, '--group', GROUPE, 'pytest', '-o', `cache_dir=${cache}`];
188
228
  args.push(...p.junit(c.nom, c.dossier));
189
- p.jouer(p.prevoir(c.nom, c.dossier, 'pytest', true, [...args, ...selection, ...options]));
229
+ const entier = chemins.every(ch => ch === '.');
230
+ p.jouer(
231
+ p.prevoir(c.nom, c.dossier, 'pytest', true, [...args, ...selection(c, chemins), ...options]),
232
+ entier ? [AUCUN_TEST] : []
233
+ );
190
234
  }
191
235
  }
192
236
 
@@ -1,6 +1,6 @@
1
1
  // The components of a project of Python, as uv finds a project (PEP 621, `pyproject.toml`): the
2
2
  // packages the module python answers the join with (scripts/jointure.d.ts, `composants`,
3
- // `composantDe`, `matieres`, `joueDesTests`, `lecteurs`, `estUnTest`, `manifestes`,
3
+ // `composantDe`, `matieres`, `joueDesTests`, `lecteurs`, `estUnTest`, `soeurDAvant`, `manifestes`,
4
4
  // `entreesDeLIndex`).
5
5
  //
6
6
  // - A component is a folder that holds a pyproject.toml, found under the root, the folders whose
@@ -19,7 +19,10 @@
19
19
  // any file under a folder `tests/` of a component, his helpers and his data. Of the manifests
20
20
  // (`manifestes`): the group `test` of the table `[dependency-groups]` of a pyproject.toml (PEP
21
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
22
+ // it; a change of any other part of a pyproject.toml is named by it. The sibling of HEAD's
23
+ // version of a test file (`soeurDAvant`), which the proof of the red plays beside it, is a name
24
+ // pytest collects, of its file's kind: `test_<nom>_circuit_avant.py`, `<nom>_circuit_avant_test.py`,
25
+ // `<nom>_circuit_avant_nuit_test.py`. The pyproject.toml is read
23
26
  // with smol-toml, a tool of this module (`outils`), an optional peer of the package loaded when a
24
27
  // manifest is judged.
25
28
  // - The readers of a package: none read by the module (a dependency between two packages of
@@ -32,6 +35,7 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs';
32
35
  import { createRequire } from 'node:module';
33
36
  import path from 'node:path';
34
37
  import { isDeepStrictEqual } from 'node:util';
38
+ import { luUneFois } from '../../services-du-noyau.mjs';
35
39
 
36
40
  const require = createRequire(import.meta.url);
37
41
 
@@ -74,8 +78,14 @@ function dossiersAvecManifeste(dossier) {
74
78
  return out;
75
79
  }
76
80
 
77
- /** The components of the project at <racine>, sorted by folder. */
81
+ /** The components of the project at <racine>, sorted by folder; read once in a scope of the core
82
+ * (`luUneFois`): a sweep asks it of every file of a folder. */
78
83
  export function composants(racine) {
84
+ return luUneFois(`python composants ${path.resolve(racine)}`, () => lireLesComposants(racine));
85
+ }
86
+
87
+ // The components of `composants`, read at each call.
88
+ function lireLesComposants(racine) {
79
89
  return dossiersAvecManifeste(racine)
80
90
  .sort()
81
91
  .map(dossier => ({
@@ -137,6 +147,26 @@ export function estUnTest(chemin, racine) {
137
147
  return null;
138
148
  }
139
149
 
150
+ /**
151
+ * The sibling of HEAD's version of the test file <chemin> (from <racine>), which pytest collects
152
+ * and plays in the same run: `test_<nom>_circuit_avant.py` beside `test_<nom>.py`,
153
+ * `<nom>_circuit_avant_test.py` beside `<nom>_test.py`, `<nom>_circuit_avant_nuit_test.py`
154
+ * beside a night test `<nom>_nuit_test.py`, so that it stays one; a name pytest collects by
155
+ * default (`python_files`), its tests named in its report as the file's; null for a file pytest
156
+ * does not play.
157
+ */
158
+ export function soeurDAvant(chemin, racine) {
159
+ if (!estUnTest(chemin, racine)?.joue) {
160
+ return null;
161
+ }
162
+ if (estDeNuit(path.basename(chemin))) {
163
+ return chemin.replace(/_nuit_test\.py$/, '_circuit_avant_nuit_test.py');
164
+ }
165
+ return chemin.endsWith('_test.py')
166
+ ? chemin.replace(/_test\.py$/, '_circuit_avant_test.py')
167
+ : chemin.replace(/\.py$/, '_circuit_avant.py');
168
+ }
169
+
140
170
  // The parts of the parsed manifests <a> and <b> that differ, out of the group of the tests: each
141
171
  // `[<table>]`, a group of `[dependency-groups]` as `[dependency-groups].<groupe>`, a key out of
142
172
  // every table bare.
@@ -227,6 +227,25 @@ export default {
227
227
  'site/tests/donnees.json : test',
228
228
  ],
229
229
  },
230
+ versionDeHead: {
231
+ valide: [
232
+ 'site/pages/generer.py',
233
+ 'site/conftest.py',
234
+ 'site/tests/donnees.json',
235
+ 'README.md',
236
+ ],
237
+ // A night test keeps its end, so that its sibling stays one.
238
+ invalide: [
239
+ 'site/pages/test_pages.py',
240
+ 'site/pages/pages_test.py',
241
+ 'site/pages/site_nuit_test.py',
242
+ ],
243
+ attendu: [
244
+ 'site/pages/test_pages.py → site/pages/test_pages_circuit_avant.py',
245
+ 'site/pages/pages_test.py → site/pages/pages_circuit_avant_test.py',
246
+ 'site/pages/site_nuit_test.py → site/pages/site_circuit_avant_nuit_test.py',
247
+ ],
248
+ },
230
249
  fichiersEngendres: {
231
250
  valide: aJour,
232
251
  invalide: enRetard,
@@ -11,7 +11,8 @@
11
11
  // `.pytest_cache`, `__pycache__` (`ignorer`).
12
12
  // - Where they write, which the envelope opens to a session (`sorties`): in writing, `.venv` and
13
13
  // `.pytest_cache` at the root, where the commands make uv and pytest write for each package
14
- // (./commandes.mjs), and uv's cache, `~/.cache/uv`; proper to the session, the
14
+ // (./commandes.mjs), and uv's cache, `~/.cache/grillhouse/uv` (UV_CACHE_DIR, ./commandes.mjs: the
15
+ // frame's caches of compilation, never in the temporary directory); proper to the session, the
15
16
  // tree of the bytecode at the root, `__pycache__` (PYTHONPYCACHEPREFIX, ./commandes.mjs); read,
16
17
  // the Pythons uv installs, `~/.local/share/uv/python`. The version of Python is uv's choice, from
17
18
  // `requires-python` and `.python-version`. The rules that refuse a role that writes pytest run
@@ -37,6 +38,7 @@ import {
37
38
  composants,
38
39
  entreesDeLIndex,
39
40
  estUnTest,
41
+ soeurDAvant,
40
42
  joueDesTests,
41
43
  lecteurs,
42
44
  manifestes,
@@ -56,7 +58,7 @@ export default {
56
58
  binaires: JSON.parse(readFileSync(ici('binaires.json'), 'utf8')),
57
59
  ignorer: ['.venv', '.pytest_cache', PYCACHE],
58
60
  sorties: {
59
- ecrites: ['.venv/', '.pytest_cache/', '~/.cache/uv/'],
61
+ ecrites: ['.venv/', '.pytest_cache/', '~/.cache/grillhouse/uv/'],
60
62
  propres: [PYCACHE],
61
63
  lues: ['~/.local/share/uv/python/'],
62
64
  },
@@ -77,6 +79,9 @@ export default {
77
79
  commandes,
78
80
  verdict,
79
81
  estUnTest,
82
+ soeurDAvant,
83
+ // Its tool plays HEAD's version of each test file beside it (`soeurDAvant`): no name to read.
84
+ testsDeHead: () => null,
80
85
  manifestes,
81
86
  fichiersEngendres: () => [
82
87
  {
@@ -2,52 +2,152 @@
2
2
  // (scripts/jointure.d.ts), which `grillhouse paquet` writes (scripts/paquet.mjs), as `uv init`
3
3
  // writes one: no behaviour, no test.
4
4
  //
5
- // - Its files: its pyproject.toml (PEP 621: its name, the folder's, its version 0.1.0, the Python
6
- // it requires, no dependency; its group `test` of `[dependency-groups]`, PEP 735, pytest, which
7
- // the module runs by `uv run --group test pytest`; the configuration of pytest,
8
- // `[tool.pytest.ini_options]`, its tests under `tests/` and its code importable from `src/`, as
9
- // uv's layout of a library has it); `src/<module>/__init__.py`, the module named after the
10
- // package (`-` read `_`), without code; `tests/.gitkeep`, its folder of tests. The typing is
5
+ // - Its name: the folder's, prefixed by the project's name when the root declares one (the
6
+ // `[project].name` of its pyproject.toml, else the `name` of its package.json, its scope when it
7
+ // has one), as the module typescript prefixes a package with the root's scope and Nx names a
8
+ // library after the workspace's scope; normalized as uv writes the name of a project (PEP 503:
9
+ // lowercase, each run of `-`, `_` or `.` read `-`), its module the name with `-` read `_`.
10
+ // - A module that would bear the name of a module of the standard library of Python is refused,
11
+ // by its name, nothing written, the name to give named (the root folder's name before the
12
+ // package's), as `cargo new` refuses a name Rust reserves: `import site` reaches the standard
13
+ // module, never the package. The list is the interpreter's own, `sys.stdlib_module_names`, of
14
+ // the Python the package requires, which uv provides; without uv, the refusal names `npx
15
+ // grillhouse maj`, which installs it.
16
+ // - Its files: its pyproject.toml (PEP 621: its name, its version 0.1.0, the Python it requires, no
17
+ // dependency; its group `test` of `[dependency-groups]`, PEP 735, pytest, which the module runs
18
+ // by `uv run --group test pytest`; the configuration of pytest, `[tool.pytest.ini_options]`, its
19
+ // tests under `tests/` and its code importable from `src/`, as uv's layout of a library has it);
20
+ // `src/<module>/__init__.py`, without code; `tests/.gitkeep`, its folder of tests. The typing is
11
21
  // `python -m compileall`, which needs no configuration. No build system: uv neither builds nor
12
22
  // installs the package to run its tests.
13
23
  // - The workspace: a root pyproject.toml whose `[tool.uv.workspace]` names its `members` receives
14
24
  // the package's path there, as `uv init` adds a project under a workspace to its members; without
15
25
  // one, the package is its own project of uv, as the module plays each package (./commandes.mjs).
16
26
  // - The lock of the versions: `uv lock`, at the workspace's root, else in the package.
27
+ // - A folder that already holds Python code is taken as it is, as `cargo init` takes the code in
28
+ // place: its tests (`test_*.py`, `*_test.py`, pytest's names) are collected where they are, its
29
+ // testpaths the folders that hold them and `tests`, each once, the package itself for a test at
30
+ // its root; no `src/<module>/` beside its code, and no `pythonpath` for code out of `src/`
31
+ // (code under `src/` keeps `pythonpath = ["src"]`); each `requirements.txt` is
32
+ // taken by `uv add -r`, in the order of its path, run in the package, which declares its
33
+ // dependencies and locks them, in place of `uv lock`. A manifest the module does not read
34
+ // (`setup.py`, `setup.cfg`, `Pipfile`) is refused by its name, nothing written, what to do named.
35
+ import { spawnSync } from 'node:child_process';
17
36
  import { existsSync, readFileSync } from 'node:fs';
18
37
  import { createRequire } from 'node:module';
19
38
  import path from 'node:path';
39
+ import { estUnFichierDeTest } from './composants.mjs';
20
40
 
21
41
  const require = createRequire(import.meta.url);
22
42
 
43
+ // The Python a package requires.
44
+ const PYTHON = '>=3.12';
45
+
46
+ // The manifests of Python the module does not read.
47
+ const ETRANGERS = new Set(['setup.py', 'setup.cfg', 'Pipfile']);
48
+
49
+ // The testpaths of a package whose files of tests lie in <fichiers> (from the package): the
50
+ // folders that hold them and `tests`, each once, a folder under another left out; the package
51
+ // itself, `.`, for a test at its root.
52
+ function cheminsDesTests(fichiers) {
53
+ const dossiers = new Set(
54
+ fichiers.filter(f => estUnFichierDeTest(path.posix.basename(f))).map(f => path.posix.dirname(f))
55
+ );
56
+ if (dossiers.has('.')) {
57
+ return ['.'];
58
+ }
59
+ const tous = [...dossiers, 'tests'].filter((d, i, l) => l.indexOf(d) === i).sort();
60
+ return tous.filter(d => !tous.some(o => d.startsWith(`${o}/`)));
61
+ }
62
+
63
+ // <n> normalized as uv writes the name of a project (PEP 503).
64
+ const normaliser = n => n.toLowerCase().replace(/[-_.]+/g, '-');
65
+
66
+ // The project's name the root at <racine> declares (see the header), null for none; <racinePy>
67
+ // its pyproject.toml read, null without one.
68
+ function nomDuProjet(racine, racinePy) {
69
+ const py = racinePy?.project?.name;
70
+ if (typeof py === 'string' && py.trim()) {
71
+ return py;
72
+ }
73
+ const f = path.join(racine, 'package.json');
74
+ const n = existsSync(f) ? JSON.parse(readFileSync(f, 'utf8')).name : undefined;
75
+ return typeof n === 'string' && n.trim() ? (/^@([^/]+)\//.exec(n)?.[1] ?? n) : null;
76
+ }
77
+
78
+ // The modules of the standard library of Python, `sys.stdlib_module_names`, of the interpreter uv
79
+ // provides for PYTHON; throws, uv named, when uv cannot give them.
80
+ function modulesStandard(racine) {
81
+ const code = 'import sys; print("\\n".join(sorted(sys.stdlib_module_names)))';
82
+ const r = spawnSync(
83
+ 'uv',
84
+ ['run', '--no-project', '--quiet', '--python', PYTHON, 'python', '-c', code],
85
+ { cwd: racine, encoding: 'utf8' }
86
+ );
87
+ if (r.status !== 0) {
88
+ throw new Error(
89
+ `uv ne donne pas les modules de la bibliothèque standard de Python (${String(r.error?.message ?? r.stderr).trim()}) ; \`npx grillhouse maj\` installe uv, puis relance la commande.`
90
+ );
91
+ }
92
+ return new Set(r.stdout.split('\n').filter(Boolean));
93
+ }
94
+
23
95
  /** @type {import('../../jointure.js').Langage['squelette']} */
24
- export function squelette(racine, { chemin }) {
25
- const nom = path.posix.basename(chemin);
96
+ export function squelette(racine, { chemin, existants }) {
97
+ const etrangers = existants.filter(e => ETRANGERS.has(path.posix.basename(e)));
98
+ if (etrangers.length) {
99
+ throw new Error(
100
+ `${chemin} : ${etrangers.join(', ')} déclare un paquet Python que le module python ne lit pas. Reprends ses dépendances dans un requirements.txt, que le paquet reprend par \`uv add -r\`, retire-le, puis relance la commande.`
101
+ );
102
+ }
103
+ const code = existants.some(e => e.endsWith('.py'));
104
+ // Code out of src/ and tests/, which `pythonpath = ["src"]` would not reach.
105
+ const aPlat = existants.some(
106
+ e =>
107
+ e.endsWith('.py') &&
108
+ !e.startsWith('src/') &&
109
+ !e.startsWith('tests/') &&
110
+ !estUnFichierDeTest(path.posix.basename(e))
111
+ );
112
+ const exigences = existants.filter(e => path.posix.basename(e) === 'requirements.txt');
113
+ const f = path.join(racine, 'pyproject.toml');
114
+ const texte = existsSync(f) ? readFileSync(f, 'utf8') : null;
115
+ const racinePy = texte === null ? null : require('smol-toml').parse(texte);
116
+ const dossier = path.posix.basename(chemin);
117
+ const projet = nomDuProjet(racine, racinePy);
118
+ const nom = normaliser(projet ? `${projet}-${dossier}` : dossier);
26
119
  const module = nom.replace(/-/g, '_');
120
+ if (modulesStandard(racine).has(module)) {
121
+ const autre = normaliser(`${path.basename(racine)}-${nom}`);
122
+ throw new Error(
123
+ `${chemin} : son module, ${module}, est un module de la bibliothèque standard de Python ; \`import ${module}\` le trouverait, jamais le paquet. Nomme-le ${autre} (le dossier et sa ligne du tableau des composants), ou déclare le nom du projet à la racine (le \`name\` de son package.json), qui préfixe le paquet.`
124
+ );
125
+ }
27
126
  const manifeste = [
28
127
  '[project]',
29
128
  `name = ${JSON.stringify(nom)}`,
30
129
  'version = "0.1.0"',
31
- 'requires-python = ">=3.12"',
130
+ `requires-python = ${JSON.stringify(PYTHON)}`,
32
131
  'dependencies = []',
33
132
  '',
34
133
  '[dependency-groups]',
35
134
  'test = ["pytest>=8"]',
36
135
  '',
37
136
  '[tool.pytest.ini_options]',
38
- 'testpaths = ["tests"]',
39
- 'pythonpath = ["src"]',
137
+ `testpaths = ${JSON.stringify(cheminsDesTests(existants)).replaceAll(',', ', ')}`,
138
+ ...(aPlat ? [] : ['pythonpath = ["src"]']),
40
139
  '',
41
140
  ].join('\n');
42
141
  const fichiers = {
43
142
  [`${chemin}/pyproject.toml`]: manifeste,
44
- [`${chemin}/src/${module}/__init__.py`]: `"""The package ${nom}: its interface, docs/INTERFACE.md, says what it offers."""\n`,
143
+ ...(code
144
+ ? {}
145
+ : {
146
+ [`${chemin}/src/${module}/__init__.py`]: `"""The package ${nom}: its interface, docs/INTERFACE.md, says what it offers."""\n`,
147
+ }),
45
148
  [`${chemin}/tests/.gitkeep`]: '',
46
149
  };
47
- const f = path.join(racine, 'pyproject.toml');
48
- const texte = existsSync(f) ? readFileSync(f, 'utf8') : null;
49
- const espace =
50
- texte === null ? null : (require('smol-toml').parse(texte).tool?.uv?.workspace ?? null);
150
+ const espace = racinePy?.tool?.uv?.workspace ?? null;
51
151
  const membres = Array.isArray(espace?.members) ? espace.members : null;
52
152
  let entree = null;
53
153
  if (membres && !membres.some(m => typeof m === 'string' && path.matchesGlob(chemin, m))) {
@@ -61,6 +161,8 @@ export function squelette(racine, { chemin }) {
61
161
  return {
62
162
  fichiers,
63
163
  espace: entree,
64
- verrouiller: { commande: 'uv', args: ['lock'], dossier: membres ? '.' : chemin },
164
+ verrouiller: exigences.length
165
+ ? exigences.map(e => ({ commande: 'uv', args: ['add', '-r', e], dossier: chemin }))
166
+ : [{ commande: 'uv', args: ['lock'], dossier: membres ? '.' : chemin }],
65
167
  };
66
168
  }
@@ -235,6 +235,22 @@ export default {
235
235
  'packages/m/src/index.ts : matiere',
236
236
  ],
237
237
  },
238
+ versionDeHead: {
239
+ valide: ['packages/a/src/index.ts', 'packages/a/tests/aide.ts', 'README.md'],
240
+ // A night test and a bench keep their mark, so that their sibling plays as they do.
241
+ invalide: [
242
+ 'packages/a/src/index.test.ts',
243
+ 'packages/a/src/index.spec.mjs',
244
+ 'packages/a/tests/tout.nuit.test.ts',
245
+ 'packages/a/tests/vitesse.budget.test.ts',
246
+ ],
247
+ attendu: [
248
+ 'packages/a/src/index.test.ts → packages/a/src/index.circuit-avant.test.ts',
249
+ 'packages/a/src/index.spec.mjs → packages/a/src/index.circuit-avant.spec.mjs',
250
+ 'packages/a/tests/tout.nuit.test.ts → packages/a/tests/tout.circuit-avant.nuit.test.ts',
251
+ 'packages/a/tests/vitesse.budget.test.ts → packages/a/tests/vitesse.circuit-avant.budget.test.ts',
252
+ ],
253
+ },
238
254
  fichiersEngendres: {
239
255
  valide: aJour,
240
256
  invalide: enRetard,
@@ -32,8 +32,8 @@
32
32
  // (./vitest-config/base.mjs).
33
33
  // - The verdict: the summaries of Turborepo and the reports of Vitest of a results directory
34
34
  // (./verdict.mjs).
35
- // - The rule of a test file and what the testwriter writes of the manifests
36
- // (./regle-des-tests.mjs).
35
+ // - The rule of a test file, the sibling of HEAD's version of a test file and what the testwriter
36
+ // writes of the manifests (./regle-des-tests.mjs).
37
37
  // - The generated files, each its command, the guard that checks it and the names its findings
38
38
  // carry: the index of the interfaces, the turbo.json of the packages, the reports of API.
39
39
  // - The entries of the index of each interface (`entreesDeLIndex`, ./index-interfaces.mjs), which
@@ -56,7 +56,7 @@ import { composants as lesComposants, matieres } from './consommateurs.mjs';
56
56
  import { elementsDuLot } from './elements-du-lot.mjs';
57
57
  import { A_ELAGUER, lireSarif, RESULTATS } from '../../resultats.mjs';
58
58
  import { lecteurs } from './lecteurs.mjs';
59
- import { estUnTest, manifestes } from './regle-des-tests.mjs';
59
+ import { estUnTest, manifestes, soeurDAvant } from './regle-des-tests.mjs';
60
60
  import { SCRIPT_DES_TESTS } from './script-des-tests.mjs';
61
61
  import { verdict } from './verdict.mjs';
62
62
  import { miseAJour } from './mise-a-jour.mjs';
@@ -264,6 +264,9 @@ export default {
264
264
  }),
265
265
  verdict,
266
266
  estUnTest,
267
+ soeurDAvant,
268
+ // Its tool plays HEAD's version of each test file beside it (`soeurDAvant`): no name to read.
269
+ testsDeHead: () => null,
267
270
  manifestes,
268
271
  fichiersEngendres: () => [
269
272
  engendre(
@@ -11,6 +11,10 @@
11
11
  //
12
12
  // Any other file is none of them: null.
13
13
  //
14
+ // The sibling of HEAD's version of a test file Vitest plays (`soeurDAvant`), which the proof of
15
+ // the red plays beside it: `<nom>.circuit-avant.<test|spec>.<ext>`, the mark of a night test or of
16
+ // a bench kept before it (`<nom>.circuit-avant.nuit.test.<ext>`), so that it plays as its file.
17
+ //
14
18
  // What the testwriter writes of the manifests (`manifestes`): the field that declares what the
15
19
  // tests of a package depend on, `devDependencies` of its package.json (npm's docs,
16
20
  // « devDependencies »), as the author of a test of Bazel declares the deps of its target; and
@@ -46,6 +50,15 @@ export function estUnTest(chemin, racine) {
46
50
  return joue || test || matiere ? { joue, test, matiere } : null;
47
51
  }
48
52
 
53
+ // The sibling of HEAD's version of the test file <chemin> (from the root <racine>), which Vitest
54
+ // plays in the same run: `<nom>.circuit-avant.<test|spec>.<ext>` beside it, a name of NOM_DE_TEST,
55
+ // of its file's kind (`.nuit` or `.budget` kept before `.test`);
56
+ // null for a file Vitest does not play.
57
+ export function soeurDAvant(chemin, racine) {
58
+ if (!estUnTest(chemin, racine)?.joue) return null;
59
+ return chemin.replace(/((?:\.nuit|\.budget)?\.(?:test|spec)\.[cm]?[jt]sx?)$/, '.circuit-avant$1');
60
+ }
61
+
49
62
  // The field of a manifest that declares what its tests depend on.
50
63
  const DES_TESTS = 'devDependencies';
51
64
 
@@ -17,9 +17,17 @@
17
17
  // - The workspace: the root package.json receives the package's path in its `workspaces` (created
18
18
  // when the root has none), unless a pattern there covers it already.
19
19
  // - The lock of the versions: `npm install`, at the root.
20
+ // - A folder that already holds code is taken as it is when its code lies under `src/` and
21
+ // `tests/`, which its tsconfig.json and its vitest.config.ts cover, each file present kept; a
22
+ // file of code out of them (`.ts`, `.tsx`, `.mts`, `.cts`, `.js`, `.jsx`, `.mjs`, `.cjs`), which
23
+ // neither its typing nor its tests would reach, is refused by its name, nothing written, the
24
+ // layout named, in place of a skeleton beside it.
20
25
  import { existsSync, readFileSync } from 'node:fs';
21
26
  import path from 'node:path';
22
27
 
28
+ // A file of code of TypeScript or JavaScript.
29
+ const CODE = /\.(?:[cm]?[jt]s|[jt]sx)$/;
30
+
23
31
  const CHAMPS = ['dependencies', 'devDependencies', 'optionalDependencies'];
24
32
  // The tools of a package's tests and of its typing, at the versions of the module's template.
25
33
  const OUTILS_DU_PAQUET = ['@types/node', 'typescript', 'vitest'];
@@ -68,12 +76,20 @@ export default mergeConfig(
68
76
  `;
69
77
 
70
78
  /** @type {import('../../jointure.js').Langage['squelette']} */
71
- export function squelette(racine, { chemin, modele }) {
79
+ export function squelette(racine, { chemin, modele, existants }) {
72
80
  if (!/^packages\/[^/]+$/.test(chemin)) {
73
81
  throw new Error(
74
82
  `${chemin} : un paquet typescript vit sous packages/<nom>, où le module trouve ses composants.`
75
83
  );
76
84
  }
85
+ const hors = existants.filter(
86
+ f => CODE.test(f) && !f.startsWith('src/') && !f.startsWith('tests/')
87
+ );
88
+ if (hors.length) {
89
+ throw new Error(
90
+ `${chemin} : ${hors.join(', ')} hors de la disposition du module typescript : son code sous src/, ses tests sous tests/, que son typage et ses tests couvrent. Range le code ainsi, puis relance la commande.`
91
+ );
92
+ }
77
93
  const racinePkg = lireJson(path.join(racine, 'package.json')) ?? {};
78
94
  const nom = path.posix.basename(chemin);
79
95
  const portee = /^(@[^/]+)\//.exec(String(racinePkg.name ?? ''))?.[1];
@@ -116,5 +132,5 @@ export function squelette(racine, { chemin, modele }) {
116
132
  }
117
133
  espace = { fichier: 'package.json', texte: json(p) };
118
134
  }
119
- return { fichiers, espace, verrouiller: { commande: 'npm', args: ['install'], dossier: '.' } };
135
+ return { fichiers, espace, verrouiller: [{ commande: 'npm', args: ['install'], dossier: '.' }] };
120
136
  }