@roomi-fields/grillhouse 0.24.12 → 0.24.14

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.
@@ -55,16 +55,26 @@
55
55
  // `node scripts/integration/gardes.mjs`); what remains is the project's own guards, which move to
56
56
  // `gardes` when the project has none (the report says so), else stay where nothing plays them
57
57
  // (the report names both); nothing remaining, the script goes.
58
+ // - The typing: each package of TypeScript (a `tsconfig.json`) that has no `typecheck` script
59
+ // receives the template's, `tsc -p tsconfig.json --noEmit` (its tsconfig.json types its sources
60
+ // and its tests, nothing emitted, as the template's does; its tsconfig.build.json builds), as a
61
+ // package of the examples of create-turbo types itself (`check-types`): each package of the frame
62
+ // in a project with `workspaces` (a package out of the frame is not touched, the root's
63
+ // `typecheck` stays the project's), the root in a project without. `npm run verifier` plays it,
64
+ // the task `typecheck` of Turborepo, which the generator keeps in the root's turbo.json
65
+ // (scripts/turbo-des-paquets.mjs). The report names the packages that received it. Witness:
66
+ // BPScript 320.21.4, whose type errors in test/ showed only at night.
58
67
  // - `turbo.json` is the project's own file, as every repository run by Turborepo writes its own. A
59
68
  // project with a `package.json` and no `turbo.json` receives the frame's template of its form:
60
69
  // `templates/turbo/paquets.json` when its `package.json` declares
61
70
  // `workspaces` (the tasks of each package, and the root's guards, `//#grillhouse:gardes` and
62
- // `//#gardes`; the tests live in the packages, the root has no `test:vitest`; the `build` of each
63
- // package is set by its own generated `turbo.json`, below), else
64
- // `templates/turbo/sans-paquets.json` (`build`, then the guards and the tests beside each other).
71
+ // `//#gardes`, and `typecheck`, after the build of each package and of its dependencies; the
72
+ // tests live in the packages, the root has no `test:vitest`; the `build` of each package is set by its own
73
+ // generated `turbo.json`, below), else `templates/turbo/sans-paquets.json` (`build`, then the
74
+ // guards, the tests and `typecheck` beside each other).
65
75
  // A `turbo.json` present is never written again by the update; only the generator of the
66
76
  // packages' turbo.json (below) writes in it the `dependsOn` of the guard tasks, and adds one it
67
- // lacks.
77
+ // lacks, and the typing task.
68
78
  // - The tools the frame's checks run as commands (dependency-cruiser, knip, Turborepo) are added
69
79
  // to the project's `devDependencies` at the version the template's `devDependencies` give; a
70
80
  // tool the project already declares in `dependencies`, `devDependencies` or
@@ -89,7 +99,7 @@
89
99
  // the range the template's package.json declares for `vitest`. Where the root resolves no Vitest or
90
100
  // another version, the project's scripts stay (the frame's included) and the report names the
91
101
  // version found and the range required. A `test` that runs anything else stays. The scripts of
92
- // the packages of a monorepo are not written.
102
+ // the packages of a monorepo are not written, but their `typecheck` (above).
93
103
  // - The frame's base configuration of Vitest is the package's (`@roomi-fields/grillhouse/vitest-config`,
94
104
  // scripts/vitest-config/), which each Vitest configuration imports by its name
95
105
  // (`import base from '@roomi-fields/grillhouse/vitest-config'`), as the examples of Turborepo
@@ -156,6 +166,7 @@ import { migrer, restesAuProjet } from './migrations.mjs';
156
166
  import { CODE, TESTS } from './frontieres.mjs';
157
167
  import { paquets } from './paquets.mjs';
158
168
  import { sources } from './sources.mjs';
169
+ import { TYPAGE } from './turbo-des-paquets.mjs';
159
170
 
160
171
  const SCRIPTS = {
161
172
  tableau: 'grillhouse tableau --texte',
@@ -328,6 +339,38 @@ function poserConfigVitest(projet, p) {
328
339
  return declarants.length > 0 ? { nom: PAQUET_DU_CADRE, paquets: declarants } : null;
329
340
  }
330
341
 
342
+ // Gives the typing script of the template, <script> (`tsc -p tsconfig.json --noEmit`: its
343
+ // tsconfig.json types its sources and its tests, nothing emitted), to each package of TypeScript
344
+ // (a `tsconfig.json`) of the project at <projet> (root package.json <p>) that has no `typecheck`:
345
+ // each package of the frame in a project of packages, written in its package.json (a package out
346
+ // of the frame is not touched, and the root's `typecheck` stays the project's); the root itself in
347
+ // a project without packages, set in <p>, which the caller writes. `npm run verifier` plays it, a
348
+ // task of Turborepo (scripts/turbo-des-paquets.mjs). Returns { script, paquets } (paquets: each
349
+ // package's directory, `.` for the root), or null when nothing changes.
350
+ function poserTypage(projet, p, script) {
351
+ if (typeof script !== 'string') return null;
352
+ const types = dossier => existsSync(path.join(projet, dossier, 'tsconfig.json'));
353
+ const sans = pkg => typeof pkg.scripts?.[TYPAGE] !== 'string';
354
+ const declarants = [];
355
+ if (p.workspaces === undefined) {
356
+ if (types('.') && sans(p)) {
357
+ p.scripts = { ...(p.scripts ?? {}), [TYPAGE]: script };
358
+ declarants.push('.');
359
+ }
360
+ } else {
361
+ for (const { dossier, pkg, hors } of paquets(projet)) {
362
+ if (hors || !types(dossier) || !sans(pkg)) continue;
363
+ pkg.scripts = { ...(pkg.scripts ?? {}), [TYPAGE]: script };
364
+ writeFileSync(
365
+ path.join(projet, dossier, 'package.json'),
366
+ `${JSON.stringify(pkg, null, 2)}\n`
367
+ );
368
+ declarants.push(dossier);
369
+ }
370
+ }
371
+ return declarants.length > 0 ? { script, paquets: declarants } : null;
372
+ }
373
+
331
374
  // Writes the frame's status line in the settings of the project at <projet>, when they exist and
332
375
  // hold none or the frame's (see the header); their other keys keep their order. Returns whether
333
376
  // they changed.
@@ -386,6 +429,7 @@ export function mettreAJour(projet, source, { inscrite = VERSION } = {}) {
386
429
  turbo: null,
387
430
  configVitest: null,
388
431
  dependanceDuCadre: null,
432
+ typage: null,
389
433
  gardes: null,
390
434
  ligneEtat: false,
391
435
  greffon: false,
@@ -486,6 +530,7 @@ export function mettreAJour(projet, source, { inscrite = VERSION } = {}) {
486
530
  }
487
531
  bilan.dependanceDuCadre = declarerDependanceDuCadre(projet, p);
488
532
  bilan.configVitest = poserConfigVitest(projet, p);
533
+ bilan.typage = poserTypage(projet, p, pkgSource.scripts?.[TYPAGE]);
489
534
  writeFileSync(pkg, `${JSON.stringify(p, null, 2)}\n`);
490
535
  }
491
536
  bilan.turbo = poserTurbo(projet, source);
@@ -550,6 +595,11 @@ export function rapport(b) {
550
595
  `Dépendance d'exécution : ${nom} déclaré dans les dependencies de ${declarants.join(', ')}, dont le code hors des tests importe une entrée du paquet. \`npm install\` relie le paquet.`
551
596
  );
552
597
  }
598
+ if (b.typage) {
599
+ lignes.push(
600
+ `Typage : \`${b.typage.script}\` écrit dans ${b.typage.paquets.join(', ')} (le script typecheck, ses sources et ses tests, que son tsconfig.json inclut) ; \`npm run verifier\` le joue à côté des gardes et des tests.`
601
+ );
602
+ }
553
603
  if (b.turbo) {
554
604
  lignes.push(
555
605
  `turbo.json écrit depuis le gabarit du cadre ${b.turbo} ; il est au projet, la mise à jour n'y touche plus.`
@@ -7,7 +7,7 @@
7
7
  // common directory.
8
8
  //
9
9
  // npx grillhouse integrer --ticket <id>
10
- // [--tests <patch>] [--code <patch>] --message <file>
10
+ // [--tests <patch>] [--code <patch>] --message <file> [--references <file>]
11
11
  //
12
12
  // One delivery is one ticket: the ticket gives its branch `agent/<ticket>` and its copy
13
13
  // (`.claude/worktrees/<ticket>`, the one the lot was written in, when it exists); a second
@@ -26,11 +26,13 @@
26
26
  // 4. a clean integration copy (`.claude/worktrees/integration`) on HEAD, made ready by the
27
27
  // replay (scripts/integration/rejeu.mjs: submodules by scripts/sous-modules.sh, dependencies
28
28
  // in agreement with the lock file and the manifests, mounts);
29
- // 5. the lots, applied in three ways in the copy, tests first; the files of the lot in the
29
+ // 5. the lots, applied in three ways in the copy, tests first, without the files a reference
30
+ // writes in full; the files of the lot in the
30
31
  // ticket's copy are compared with the copy's own base plus the lot, not with the integration
31
32
  // copy. Once the lots are in the copy, the replay makes the dependencies agree with the lock
32
33
  // file and the manifests the lot leaves (`npm ci`, as the continuous integration runs it); an
33
34
  // install that fails refuses the lot, « Les dépendances de la copie ne s'installent pas. »;
35
+ // then the references regenerate (below);
34
36
  // 6. the tests: `npm run verifier` in the copy, one command (Turborepo: the build, then the
35
37
  // guards, the frame's and the project's own (its root script `gardes`), and every test of the
36
38
  // day beside each other, each task replayed from the cache of the
@@ -52,6 +54,19 @@
52
54
  // `en-file` and the branch takes its place at the end of the queue
53
55
  // (scripts/integration/file-attente.mjs). main does not move here.
54
56
  //
57
+ // The references are the circuit's (`--references`, a JSON file the circuit writes from its one
58
+ // list, `lesReferences` of scripts/circuit.mjs): each `{ nom, commande, fichiers, entiers, cadre }`,
59
+ // `entiers` the files of `fichiers` its command writes in full (paths, directories or glob
60
+ // patterns, as `couvertPar` reads them). As a genrule of Bazel writes its output again on the
61
+ // merged tree, and npm install writes package-lock.json again after a merge, a file of the lot a
62
+ // reference writes in full is not applied: the reference that writes it plays in the copy, on main
63
+ // of the moment, after the install and before the tests, through the mounts, and what it writes
64
+ // enters the commit (BPScript 320.30: refused twice for the one conflict on the index of the
65
+ // interfaces, which another ticket had regenerated on main in the meantime). A command of the
66
+ // project at another code than 0, one of the frame on a real failure (126, 127, a signal), or a
67
+ // file it changes that its `fichiers` do not cover, refuses the lot. A conflict on any other file
68
+ // refuses it, as the three-way application says.
69
+ //
55
70
  // What steps 2, 3 and 5 read of a lot is its files: each file added, modified or deleted, a
56
71
  // rename counting its source and its destination (named as the file is, not as git quotes it in
57
72
  // the patch), a copy its destination only. Step 2 judges them against the testwriter's files, step 3
@@ -101,6 +116,16 @@ function nomDeGit(ecrit) {
101
116
  return Buffer.from(octets).toString('utf8');
102
117
  }
103
118
 
119
+ // Whether one of <motifs> covers the file <fichier>, both from the root of the copy, as the
120
+ // inputs of Turborepo read them: a path names that file, a directory every file under it, a glob
121
+ // pattern (`*`, `**`) the files it matches (`path.matchesGlob` of Node).
122
+ export function couvertPar(motifs, fichier) {
123
+ return motifs.some(m => {
124
+ const dossier = m.replace(/\/+$/, '');
125
+ return fichier === dossier || fichier.startsWith(`${dossier}/`) || path.matchesGlob(fichier, m);
126
+ });
127
+ }
128
+
104
129
  // The refusal for the verdicts of one ticket, or null. `ticket` and `comments` are Beads' JSON.
105
130
  export function refusVerdicts(ticket, comments) {
106
131
  const id = ticket.id;
@@ -145,7 +170,7 @@ export function refusLots(tests, code, racine) {
145
170
 
146
171
  // The options, or { faute } for a usage error.
147
172
  function lire(argv) {
148
- const o = { ticket: null, tests: null, code: null, message: null };
173
+ const o = { ticket: null, tests: null, code: null, message: null, references: null };
149
174
  for (let i = 0; i < argv.length; i++) {
150
175
  const v = argv[i + 1];
151
176
  switch (argv[i]) {
@@ -169,6 +194,10 @@ function lire(argv) {
169
194
  o.message = v;
170
195
  i++;
171
196
  break;
197
+ case '--references':
198
+ o.references = v;
199
+ i++;
200
+ break;
172
201
  default:
173
202
  return { faute: null };
174
203
  }
@@ -209,11 +238,47 @@ function differents(copieTicket, lots, fichiers, tmp) {
209
238
  return r.stdout.split('\0').filter(Boolean);
210
239
  }
211
240
 
241
+ // The regeneration of the references <refs> in the integration copy <copie>, each command run by
242
+ // the shell at its root through the mounts (`monter`), its output written; then every file they
243
+ // changed staged. Null, or the refusal: a command of the project at another code than 0, one of
244
+ // the frame on a real failure (126, 127, a signal, 128 + its number), a file changed that their
245
+ // `fichiers` do not cover.
246
+ function regenerer(copie, refs, monter, dansCopie) {
247
+ for (const r of refs) {
248
+ const x = spawnSync('bash', monter('sh', '-c', r.commande), {
249
+ cwd: copie,
250
+ encoding: 'utf8',
251
+ maxBuffer: 256 * 1024 * 1024,
252
+ });
253
+ process.stdout.write(`${x.stdout ?? ''}${x.stderr ?? ''}`);
254
+ const code = x.status ?? 1;
255
+ const panne =
256
+ x.signal !== null || x.error !== undefined || code === 126 || code === 127 || code > 128;
257
+ if (panne || (!r.cadre && code !== 0)) {
258
+ return `La référence « ${r.nom} » (\`${r.commande}\`) rend le code ${code} dans la copie d'intégration.`;
259
+ }
260
+ }
261
+ const etat = dansCopie('status', '--porcelain=v1', '-z', '-uall', '--no-renames');
262
+ if (etat.status !== 0) return "L'état de la copie d'intégration ne se lit pas.";
263
+ const ecrits = etat.stdout
264
+ .split('\0')
265
+ .filter(l => l && (l[1] !== ' ' || l.startsWith('??')))
266
+ .map(l => l.slice(3));
267
+ const horsDeclaration = ecrits.filter(f => !refs.some(r => couvertPar(r.fichiers, f)));
268
+ if (horsDeclaration.length) {
269
+ return `La régénération des références change des fichiers qu'aucune n'écrit :\n${horsDeclaration.map(f => ` ${f}`).join('\n')}`;
270
+ }
271
+ if (ecrits.length && dansCopie('add', '-A', '--', ...ecrits).status !== 0) {
272
+ return "Les fichiers des références ne s'ajoutent pas au commit.";
273
+ }
274
+ return null;
275
+ }
276
+
212
277
  function main(argv) {
213
278
  const o = lire(argv);
214
279
  if ('faute' in o) {
215
280
  process.stderr.write(
216
- 'usage: integrer.mjs --ticket <id> [--tests <patch>] [--code <patch>] --message <file>\n' +
281
+ 'usage: integrer.mjs --ticket <id> [--tests <patch>] [--code <patch>] --message <file> [--references <file>]\n' +
217
282
  (o.faute ? `⛔ ${o.faute}\n` : '')
218
283
  );
219
284
  return 2;
@@ -276,6 +341,17 @@ function main(argv) {
276
341
  if (r2) return refuser(r2);
277
342
  const fichiers = [...new Set([...tests, ...code])];
278
343
  dire(`✓ lots : ${fichiers.length} fichiers`);
344
+ let references = [];
345
+ if (o.references) {
346
+ try {
347
+ references = JSON.parse(readFileSync(absolu(o.references), 'utf8'));
348
+ } catch (e) {
349
+ return refuser(`Les références ${o.references} ne se lisent pas : ${e.message}`);
350
+ }
351
+ }
352
+ // The files of the lot a reference writes in full, and the references that write them.
353
+ const entiers = fichiers.filter(f => references.some(r => couvertPar(r.entiers, f)));
354
+ const aRegenerer = references.filter(r => entiers.some(f => couvertPar(r.entiers, f)));
279
355
 
280
356
  // 3. The main tree: the lots' files are free there, so the queue can bring them. The ticket's
281
357
  // copy holds the lot and nothing else.
@@ -312,9 +388,11 @@ function main(argv) {
312
388
  if (ouverte.refus) return refuser(ouverte.refus);
313
389
  const { dansCopie, monter, installer, tester } = ouverte;
314
390
 
315
- // 5. The lots, applied in the copy, then installed.
391
+ // 5. The lots, applied in the copy without the files a reference writes in full, then
392
+ // installed, then the references regenerated.
393
+ const sansEntiers = entiers.map(f => `--exclude=${f}`);
316
394
  for (const p of lots) {
317
- const r = dansCopie('apply', '--3way', '--index', p);
395
+ const r = dansCopie('apply', '--3way', '--index', ...sansEntiers, p);
318
396
  if (r.status !== 0) return refuser(`Le lot ${p} ne s'applique pas :\n${r.stdout}${r.stderr}`);
319
397
  }
320
398
  const divergents = avecCopie ? differents(copieTicket, lots, fichiers, tmp) : [];
@@ -326,6 +404,11 @@ function main(argv) {
326
404
  dire('✓ lots appliqués');
327
405
  const installation = installer();
328
406
  if (installation) return refuser(installation);
407
+ if (aRegenerer.length) {
408
+ const refus = regenerer(copie, aRegenerer, monter, dansCopie);
409
+ if (refus) return refuser(refus);
410
+ dire(`✓ références régénérées sur main à jour : ${aRegenerer.map(r => r.nom).join(', ')}`);
411
+ }
329
412
 
330
413
  // 6. The tests: the build, the guards and every test of the day, green required.
331
414
  dire('— npm run verifier (construction, gardes, tests)');
package/scripts/nuit.sh CHANGED
@@ -5,8 +5,12 @@
5
5
  # to the files changed since the last green (scripts/integration/integrer.mjs,
6
6
  # scripts/dernier-vert.mjs).
7
7
  #
8
- # npx grillhouse nuit from the root of the project, by the crontab of the machine, e.g.
9
- # « 0 3 * * * cd <root> && node_modules/.bin/grillhouse nuit »
8
+ # npx grillhouse nuit from the root of the project, by the crontab of the machine, as the
9
+ # session start proposes it, with the directory of its Node, e.g.
10
+ # « 0 3 * * * export PATH=<node dir>:$PATH; cd <root> &&
11
+ # node_modules/.bin/grillhouse nuit »
12
+ # npx grillhouse nuit --help the usage on the output (also -h), exit 0; any other argument is
13
+ # refused, the usage on the error stream, exit 2: nothing runs.
10
14
  #
11
15
  # - It plays main's HEAD in its own clean copy (.claude/worktrees/nuit): detached, every untracked
12
16
  # file removed, its submodules set at the commit of HEAD (scripts/sous-modules.sh, a local
@@ -18,8 +22,10 @@
18
22
  # played for real (`--force`, no log replayed from the cache, no measure against the last
19
23
  # green: the complete pass, scripts/verifier.mjs), its result written to the cache again; green,
20
24
  # its tree becomes the last green of the day's passes.
21
- # A full pass « à repasser » (75, scripts/verifier.mjs: a failure of duration under load, which
22
- # found no rest in its bound) makes the night « à repasser », below.
25
+ # Its three steps (the full pass, the night tests, the project's night script) each play even
26
+ # when one before is red, as a CI plays its independent jobs; the night is red when one of them
27
+ # is. A full pass « à repasser » (75, scripts/verifier.mjs: a failure of duration under load,
28
+ # which found no rest in its bound) ends the night there, « à repasser », below.
23
29
  # An existing copy that does not get ready (its move onto HEAD, its cleaning or the setting of
24
30
  # its submodules fails) is removed by `scripts/retirer-copie.sh --jetable` (local work does not
25
31
  # hold it, a lock does) and created again, once; a copy that does not get ready the second time
@@ -29,17 +35,17 @@
29
35
  # read-only, its working tree and its git repository (the list the preparation's pose printed,
30
36
  # whatever a command rewrites afterwards): a write into it fails. With a shared submodule and no possible mount (bwrap absent
31
37
  # or refused), the night turns red, the log saying so, before any command runs.
32
- # - The night tests: after a green full pass, the files `*.nuit.test.*`, `*.nuit.spec.*`,
38
+ # - The night tests: after the full pass, the files `*.nuit.test.*`, `*.nuit.spec.*`,
33
39
  # `*.budget.test.*` and `*.budget.spec.*` of the copy (outside node_modules, dist and .git): the
34
40
  # night tests and the time budget benches, which `npm test` and the integration leave out
35
41
  # (the package @roomi-fields/grillhouse/vitest-config, scripts/vitest-config/, which every day configuration
36
42
  # extends), run by Vitest with the frame's configuration (scripts/vitest.nuit.config.mjs, beside
37
43
  # this script), bench or night test alone as well. A red turns the night red, with a log line that says so, and the
38
- # project's night script does not run. A copy with neither plays none. A run « à repasser » (75:
44
+ # project's night script still plays. A copy with neither plays none. A run « à repasser » (75:
39
45
  # every failure depended on a duration, one under load, scripts/vitest-config/duree.reporter.mjs)
40
46
  # waits for rest (`npx grillhouse pression attendre`, bound 15 min) and plays
41
47
  # once more; green then, the night goes on; à repasser again, or no rest in the bound, the night
42
- # is « à repasser ».
48
+ # ends there, « à repasser », red if the full pass is.
43
49
  # - « À repasser » (exit 75): neither green nor red. The last green stays, no ticket opens, nothing
44
50
  # is pushed, the log says so; the next night plays again.
45
51
  # - The project's night script: `grillhouse.nuit` in the package.json of the commit it plays names
@@ -57,19 +63,47 @@
57
63
  # keys are read as written, before any work: a grillhouse.poussee that is neither null nor an
58
64
  # object, or a grillhouse.poussee.nuit that is not a non-blank string, turns the night red with
59
65
  # a log line that cites it, one line per faulty key. A refused push keeps the last green, opens
60
- # (or completes) the night ticket « La poussée de la nuit est refusée sur <commit> », and exits
61
- # 1; a remote already at the commit accepts the push.
66
+ # the night ticket « La poussée de la nuit est refusée sur <commit> vers « origin/<branch> » »
67
+ # (or comments the open one that names « origin/<branch> »), and exits 1; a remote already at
68
+ # the commit accepts the push.
62
69
  # - It takes no lock of the integration or of the queue (scripts/integration/file.mjs): an
63
70
  # integration and the queue run during the night, each in its own copy.
64
71
  # - Its log is <git common dir>/nuit/<date>.log. Green: HEAD becomes the last green commit
65
- # (<git common dir>/nuit/dernier-vert). Red: a ticket labelled `nuit`, with the commits since the
66
- # last green, where `git bisect` looks for the culprit; an open one gets a comment instead.
67
- # With a last green, each red task of the full pass (the file GRILLHOUSE_ROUGES names, which
68
- # scripts/verifier.mjs writes: `<package>#<task>` per line, no task à repasser among them) gets
69
- # its line, the command that looks for the culprit with that task alone:
72
+ # (<git common dir>/nuit/dernier-vert). Red: the red tasks, each grouped by its cause as an
73
+ # alerting system groups by fingerprint: each red task of the full pass (the file
74
+ # GRILLHOUSE_ROUGES names, which scripts/verifier.mjs writes: `<package>#<task>` per line, no
75
+ # task à repasser among them), else the full pass by its command, the night tests, the project's
76
+ # night script by its command, or the preparation when the night is red before any step. Each
77
+ # red task comments the open ticket labelled `nuit` whose title names it (« <task> »), once per
78
+ # ticket, or opens its own, « La nuit est rouge sur « <task> » depuis la nuit du <date> ». The
79
+ # text, the same for each, gives the commits since the last green, where `git bisect` looks for
80
+ # the culprit, each red step and each red task, with or without a last green, then the end of
81
+ # the log. With a last green, each red task of the full pass gets the command that looks for the
82
+ # culprit with that task alone:
70
83
  # `git bisect start <head> <last green> && git bisect run npx turbo run <task> --filter=<package>`
71
84
  # (`--filter=//` for the root), Turborepo's hash replaying at each step only what changed.
72
85
  set -u
86
+ usage() {
87
+ echo "Usage : grillhouse nuit"
88
+ echo "La nuit : la passe complète jouée pour de vrai, puis les tests de nuit et les bancs de budget,"
89
+ echo "sur le HEAD de main, dans sa copie (.claude/worktrees/nuit). Se lance depuis la racine du projet."
90
+ echo "Options :"
91
+ echo " -h, --help affiche cette aide, sans lancer la nuit"
92
+ }
93
+ for argument in "$@"; do
94
+ case "$argument" in
95
+ -h | --help) ;;
96
+ *)
97
+ echo "⛔ grillhouse nuit : argument inconnu : $argument" >&2
98
+ usage >&2
99
+ exit 2
100
+ ;;
101
+ esac
102
+ done
103
+ if [ $# -gt 0 ]; then
104
+ usage
105
+ exit 0
106
+ fi
73
107
  # The project is the working directory; the frame's scripts are this one's neighbours.
74
108
  racine="$PWD"
75
109
  ici="$(cd "$(dirname "$0")" && pwd)"
@@ -84,6 +118,11 @@ rm -f "$rouges"
84
118
  tete="$(git -C "$racine" rev-parse HEAD)"
85
119
  copie="$racine/.claude/worktrees/nuit"
86
120
  branche=
121
+ # The red steps of the night, and its red tasks: those of the full pass (turbo 1, which a bisect
122
+ # replays alone), then a step red without a task of its own, named by its command (turbo 0).
123
+ etapes=()
124
+ taches=()
125
+ turbo=()
87
126
  # Gets the copy ready on HEAD: detached, cleaned, its submodules set; `partages` holds the list the
88
127
  # pose fixes, which every mount gets. Prints the reason on failure.
89
128
  partages=
@@ -162,15 +201,31 @@ jouer() {
162
201
  monter npm --prefix "$copie" ci --no-audit --no-fund --silent || return 1
163
202
  cp "$copie/package-lock.json" "$copie/node_modules/.nuit-lock"
164
203
  fi
165
- # The full pass, played for real: the night replays no log of the cache.
166
- local code
204
+ # The full pass, played for real: the night replays no log of the cache. Each step plays even
205
+ # when one before it is red; a step à repasser ends the night there, red if a step before it is.
206
+ local code tache avant
167
207
  GRILLHOUSE_ROUGES="$rouges" monter npm --prefix "$copie" run verifier -- --force
168
208
  code=$?
169
209
  if [ "$code" -eq 75 ]; then
170
210
  echo "⏱ la passe complète est à repasser (code 75) : un échec de durée sous charge, sans repos dans la borne."
171
211
  return 75
172
212
  fi
173
- [ "$code" -eq 0 ] || return 1
213
+ if [ "$code" -ne 0 ]; then
214
+ echo "✗ la passe complète (npm run verifier -- --force) a échoué."
215
+ etapes+=("la passe complète (npm run verifier -- --force)")
216
+ avant=${#taches[@]}
217
+ if [ -s "$rouges" ]; then
218
+ while IFS= read -r tache; do
219
+ [ -n "$tache" ] || continue
220
+ taches+=("$tache")
221
+ turbo+=(1)
222
+ done < "$rouges"
223
+ fi
224
+ if [ "${#taches[@]}" -eq "$avant" ]; then
225
+ taches+=("npm run verifier -- --force")
226
+ turbo+=(0)
227
+ fi
228
+ fi
174
229
  if [ -n "$(find "$copie" \( -name node_modules -o -name dist -o -name .git \) -prune -o \
175
230
  -type f -regextype posix-extended -regex '.*\.(nuit|budget)\.(test|spec)\.(c|m)?[jt]sx?' -print -quit)" ]; then
176
231
  bancs() { (cd "$copie" && monter npx --no-install vitest run --root "$copie" \
@@ -181,25 +236,36 @@ jouer() {
181
236
  echo "⏱ les bancs de temps ou les tests de nuit sont à repasser (code 75) : attente du repos, puis une relance."
182
237
  if ! node "$ici/vitest-config/pression.mjs" attendre; then
183
238
  echo "⏱ à repasser : pas de repos dans la borne."
184
- return 75
239
+ fin 75
240
+ return
185
241
  fi
186
242
  bancs
187
243
  code=$?
188
244
  if [ "$code" -eq 75 ]; then
189
245
  echo "⏱ à repasser : les bancs échouent encore sous charge après la relance."
190
- return 75
246
+ fin 75
247
+ return
191
248
  fi
192
249
  fi
193
250
  if [ "$code" -ne 0 ]; then
194
251
  echo "✗ les bancs de temps ou les tests de nuit (*.budget.*, *.nuit.*) ont échoué."
195
- return 1
252
+ etapes+=("les bancs de temps et les tests de nuit (*.budget.*, *.nuit.*)")
253
+ taches+=("les bancs de temps et les tests de nuit")
254
+ turbo+=(0)
196
255
  fi
197
256
  fi
198
- [ -n "$nuit" ] || return 0
199
- if ! monter npm --prefix "$copie" run "$nuit"; then
257
+ if [ -n "$nuit" ] && ! monter npm --prefix "$copie" run "$nuit"; then
200
258
  echo "✗ le script de nuit du projet \`npm run $nuit\` (grillhouse.nuit) a échoué."
201
- return 1
259
+ etapes+=("le script de nuit du projet (npm run $nuit, grillhouse.nuit)")
260
+ taches+=("npm run $nuit")
261
+ turbo+=(0)
202
262
  fi
263
+ fin 0
264
+ }
265
+ # The night's verdict once its steps are played: red when a step is red, else <code>.
266
+ fin() {
267
+ [ "${#etapes[@]}" -eq 0 ] || return 1
268
+ return "$1"
203
269
  }
204
270
  jouer >> "$journal" 2>&1
205
271
  verdict=$?
@@ -209,19 +275,30 @@ if [ "$verdict" -eq 75 ]; then
209
275
  exit 75
210
276
  fi
211
277
 
212
- # Opens the night ticket (subject « number — subject — parent », the number being the id without the
213
- # project's prefix as `bd config get issue_prefix` gives it), or comments the open one; prints its id.
278
+ # The open night tickets, read once; a ticket names a cause when its title holds « <cause> ».
279
+ ouverts=
280
+ commentes=" "
281
+ # Reports one cause: comments the open night ticket whose title names it (once a night), or opens
282
+ # its own (title « number — subject — parent », the number being the id without the project's
283
+ # prefix as `bd config get issue_prefix` gives it, the subject naming « <cause> »); its id goes to
284
+ # `numero`.
214
285
  signaler() {
215
- local sujet="$1" texte="$2" ouvert neuf= prefixe
216
- ouvert="$(cd "$racine" && bd list --status open --label nuit --json 2>/dev/null | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{const l=JSON.parse(s);process.stdout.write(l[0]?.id??"")}catch{}})')"
286
+ local cause="$1" sujet="$2" texte="$3" ouvert neuf= prefixe
287
+ [ -n "$ouverts" ] || ouverts="$(cd "$racine" && bd list --status open --label nuit --json 2>/dev/null)"
288
+ ouvert="$(printf '%s' "$ouverts" | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{const c=`« ${process.argv[1]} »`;process.stdout.write(JSON.parse(s).find(t=>String(t.title??"").includes(c))?.id??"")}catch{}})' "$cause")"
217
289
  if [ -n "$ouvert" ]; then
218
- (cd "$racine" && bd comments add "$ouvert" "$texte" >/dev/null)
290
+ case "$commentes" in
291
+ *" $ouvert "*) ;;
292
+ *)
293
+ (cd "$racine" && bd comments add "$ouvert" "$texte" >/dev/null)
294
+ commentes="$commentes$ouvert " ;;
295
+ esac
219
296
  else
220
297
  neuf="$(cd "$racine" && bd create "$sujet" -t bug -p 1 -l nuit -d "$texte" --silent)"
221
298
  prefixe="$(cd "$racine" && bd config get issue_prefix 2>/dev/null)"
222
299
  [ -n "$neuf" ] && (cd "$racine" && bd update "$neuf" --title "${neuf#"$prefixe"-} — $sujet — parent" >/dev/null)
223
300
  fi
224
- echo "${ouvert:-$neuf}"
301
+ numero="${ouvert:-$neuf}"
225
302
  }
226
303
 
227
304
  if [ "$verdict" -eq 0 ]; then
@@ -237,7 +314,7 @@ Le dernier vert reste ${tete:0:7}.
237
314
  Journal : $journal
238
315
  Fin du journal :
239
316
  $(tail -40 "$journal")"
240
- numero="$(signaler "La poussée de la nuit est refusée sur ${tete:0:7}" "$texte")"
317
+ signaler "origin/$branche" "La poussée de la nuit est refusée sur ${tete:0:7} vers « origin/$branche »" "$texte"
241
318
  echo "✗ vert, poussée refusée : ticket ${numero:-neuf} (étiquette nuit)." >> "$journal"
242
319
  exit 1
243
320
  fi
@@ -247,23 +324,39 @@ fi
247
324
 
248
325
  vert="$(cat "$dossier/dernier-vert" 2>/dev/null || true)"
249
326
  intervalle="${vert:+${vert:0:7}..}${tete:0:7}"
250
- bissections=
251
- if [ -n "$vert" ] && [ -s "$rouges" ]; then
252
- bissections="Pour chaque tâche rouge, la commande qui cherche le commit fautif :"
253
- while IFS= read -r tache; do
254
- [ -n "$tache" ] || continue
255
- bissections="$bissections
256
- - $tache : git bisect start ${tete:0:7} ${vert:0:7} && git bisect run npx turbo run ${tache#*#} --filter=${tache%%#*}"
257
- done < "$rouges"
258
- bissections="$bissections
259
- "
327
+ # A red before any step (the copy, its mount, the keys, the installation) is the preparation's.
328
+ if [ "${#etapes[@]}" -eq 0 ]; then
329
+ etapes=("la préparation (la copie, ses sous-modules, les clés grillhouse, l'installation)")
330
+ taches=("la préparation")
331
+ turbo=(0)
260
332
  fi
333
+ liste="Étapes rouges :"
334
+ for e in "${etapes[@]}"; do
335
+ liste="$liste
336
+ - $e"
337
+ done
338
+ liste="$liste
339
+ Tâches rouges"
340
+ [ -n "$vert" ] && liste="$liste, avec pour une tâche de la passe complète la commande qui cherche le commit fautif"
341
+ liste="$liste :"
342
+ for i in "${!taches[@]}"; do
343
+ tache="${taches[$i]}"
344
+ if [ -n "$vert" ] && [ "${turbo[$i]}" -eq 1 ]; then
345
+ tache="$tache : git bisect start ${tete:0:7} ${vert:0:7} && git bisect run npx turbo run ${tache#*#} --filter=${tache%%#*}"
346
+ fi
347
+ liste="$liste
348
+ - $tache"
349
+ done
261
350
  texte="La nuit du $(date +%Y-%m-%d) est rouge sur ${tete:0:7}.
262
351
  Commits à chercher (git bisect) : $intervalle.
263
- ${bissections}Journal : $journal
352
+ $liste
353
+ Journal : $journal
264
354
  Fin du journal :
265
355
  $(tail -40 "$journal")"
266
- # A night ticket is the mother of its fixes.
267
- numero="$(signaler "La nuit est rouge depuis la nuit du $(date +%Y-%m-%d)" "$texte")"
268
- echo "✗ rouge : ticket ${numero:-neuf} (étiquette nuit)." >> "$journal"
356
+ # Each red task reports on the night ticket that names it, else on its own; a night ticket is the
357
+ # mother of its fixes.
358
+ for tache in "${taches[@]}"; do
359
+ signaler "$tache" "La nuit est rouge sur « $tache » depuis la nuit du $(date +%Y-%m-%d)" "$texte"
360
+ echo "✗ rouge : ticket ${numero:-neuf} (étiquette nuit) sur « $tache »." >> "$journal"
361
+ done
269
362
  exit 1