@roomi-fields/grillhouse 0.32.0 → 0.33.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 (116) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +22 -0
  3. package/bin/grillhouse.mjs +6 -4
  4. package/cadre/templates/projet/.github/workflows/ci.yml +136 -16
  5. package/cadre/templates/projet/.github/workflows/nuit.yml +111 -0
  6. package/cadre/templates/projet/deployment/docs/01-INSTALL.md +4 -4
  7. package/cadre/templates/projet/package.json +2 -2
  8. package/charte.md +8 -5
  9. package/dist/temporal/circuit/contrat.d.ts +15 -0
  10. package/dist/temporal/circuit/deroule.js +37 -14
  11. package/dist/temporal/circuit/deroule.js.map +1 -1
  12. package/dist/temporal/deroules.d.ts +1 -0
  13. package/dist/temporal/deroules.js +3 -1
  14. package/dist/temporal/deroules.js.map +1 -1
  15. package/dist/temporal/file/activites.d.ts +1 -0
  16. package/dist/temporal/file/activites.js +5 -2
  17. package/dist/temporal/file/activites.js.map +1 -1
  18. package/dist/temporal/file/contrat.d.ts +50 -33
  19. package/dist/temporal/file/contrat.js +2 -2
  20. package/dist/temporal/file/contrat.js.map +1 -1
  21. package/dist/temporal/file/deroule.d.ts +3 -1
  22. package/dist/temporal/file/deroule.js +128 -26
  23. package/dist/temporal/file/deroule.js.map +1 -1
  24. package/dist/temporal/nuits/activites.d.ts +10 -0
  25. package/dist/temporal/nuits/activites.js +114 -0
  26. package/dist/temporal/nuits/activites.js.map +1 -0
  27. package/dist/temporal/nuits/appel.d.ts +23 -0
  28. package/dist/temporal/nuits/appel.js +40 -0
  29. package/dist/temporal/nuits/appel.js.map +1 -0
  30. package/dist/temporal/nuits/choix.d.ts +14 -0
  31. package/dist/temporal/nuits/choix.js +119 -0
  32. package/dist/temporal/nuits/choix.js.map +1 -0
  33. package/dist/temporal/nuits/client.d.ts +28 -0
  34. package/dist/temporal/nuits/client.js +83 -0
  35. package/dist/temporal/nuits/client.js.map +1 -0
  36. package/dist/temporal/nuits/commande.d.ts +2 -0
  37. package/dist/temporal/nuits/commande.js +107 -0
  38. package/dist/temporal/nuits/commande.js.map +1 -0
  39. package/dist/temporal/nuits/contrat.d.ts +98 -0
  40. package/dist/temporal/nuits/contrat.js +30 -0
  41. package/dist/temporal/nuits/contrat.js.map +1 -0
  42. package/dist/temporal/nuits/deroule.d.ts +5 -0
  43. package/dist/temporal/nuits/deroule.js +100 -0
  44. package/dist/temporal/nuits/deroule.js.map +1 -0
  45. package/dist/temporal/travailleur.js +4 -1
  46. package/dist/temporal/travailleur.js.map +1 -1
  47. package/docs/ARCHITECTURE.md +186 -45
  48. package/docs/CADRE.md +31 -1
  49. package/docs/INTERFACE.md +45 -6
  50. package/hooks/register.tsx +11 -3
  51. package/package.json +4 -1
  52. package/scripts/abi-des-dependances.mjs +105 -0
  53. package/scripts/activites.mjs +94 -41
  54. package/scripts/aiguillage.mjs +1 -0
  55. package/scripts/avancement.mjs +8 -18
  56. package/scripts/ci-des-branches.mjs +91 -0
  57. package/scripts/circuit.mjs +79 -4
  58. package/scripts/composants-affectes.mjs +24 -7
  59. package/scripts/composition-des-langages.mjs +3 -0
  60. package/scripts/crochets.mjs +4 -0
  61. package/scripts/enveloppe/enveloppe.mjs +3 -1
  62. package/scripts/enveloppe/lancer.sh +1 -1
  63. package/scripts/enveloppe/travail-de-la-copie.mjs +219 -59
  64. package/scripts/etapes.mjs +18 -1
  65. package/scripts/faits-du-circuit.mjs +43 -20
  66. package/scripts/fichier-du-poste.mjs +87 -0
  67. package/scripts/grillhouse-maj.mjs +15 -1
  68. package/scripts/integration/file.mjs +215 -275
  69. package/scripts/integration/integrer.mjs +82 -41
  70. package/scripts/integration/rejeu.mjs +13 -64
  71. package/scripts/jointure.d.ts +26 -2
  72. package/scripts/langages/cargo/commandes.mjs +81 -19
  73. package/scripts/langages/cargo/exemples.mjs +2 -2
  74. package/scripts/langages/cargo/index.mjs +11 -5
  75. package/scripts/langages/cargo/tailles-des-tests.mjs +19 -11
  76. package/scripts/langages/python/commandes.mjs +11 -7
  77. package/scripts/langages/python/exemples.mjs +1 -1
  78. package/scripts/langages/python/index.mjs +9 -2
  79. package/scripts/langages/python/tailles-des-tests.mjs +19 -11
  80. package/scripts/langages/typescript/code-mort.mjs +41 -24
  81. package/scripts/langages/typescript/consommateurs.mjs +28 -17
  82. package/scripts/langages/typescript/exemples.mjs +2 -0
  83. package/scripts/langages/typescript/index.mjs +22 -3
  84. package/scripts/langages/typescript/migrations/0.33.0-binaire-de-jour.mjs +34 -0
  85. package/scripts/langages/typescript/migrations/0.33.0-tests-du-poste.mjs +31 -0
  86. package/scripts/langages/typescript/resumes.mjs +17 -7
  87. package/scripts/langages/typescript/tailles-des-tests.mjs +251 -22
  88. package/scripts/langages/typescript/tests-de-nuit.mjs +101 -9
  89. package/scripts/langages/typescript/tests-du-poste.mjs +172 -0
  90. package/scripts/langages/typescript/tranches.mjs +273 -0
  91. package/scripts/langages/typescript/verifier.mjs +131 -29
  92. package/scripts/langages/typescript/vitest-config/cibles.mjs +78 -7
  93. package/scripts/langages/typescript/vitest-config/lances.mjs +4 -4
  94. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +9 -0
  95. package/scripts/langages/typescript/vitest.nuit.config.mjs +3 -2
  96. package/scripts/lint-des-scripts.mjs +23 -6
  97. package/scripts/migrations/0.33.0-cache-distant.mjs +36 -0
  98. package/scripts/migrations/0.33.0-ci-des-branches-de-ticket.mjs +31 -0
  99. package/scripts/migrations/0.33.0-ci-du-cadre.mjs +31 -0
  100. package/scripts/migrations/0.33.0-node-26.mjs +58 -0
  101. package/scripts/migrations.mjs +8 -0
  102. package/scripts/newday.mjs +18 -0
  103. package/scripts/nuit.sh +35 -17
  104. package/scripts/registre.d.mts +90 -0
  105. package/scripts/registre.mjs +28 -3
  106. package/scripts/reprise.mjs +12 -8
  107. package/scripts/services-du-noyau.mjs +4 -0
  108. package/scripts/session-start.sh +28 -32
  109. package/scripts/sous-commandes.mjs +29 -10
  110. package/scripts/tableau.mjs +124 -17
  111. package/scripts/taches-du-graphe.mjs +39 -6
  112. package/scripts/transitions.mjs +42 -3
  113. package/scripts/verrou-de-machine.mjs +1 -2
  114. package/scripts/workflows-du-cadre.mjs +75 -0
  115. package/skills/grill/SKILL.md +8 -6
  116. package/skills/pitmaster/SKILL.md +5 -4
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+ // The version of Node a project's dependencies were installed under, as Yarn's integrity file
3
+ // keeps the system it installed for: a native module built for one binary interface of Node
4
+ // (`process.versions.modules`, the NODE_MODULE_VERSION) refuses to load under another, and npm
5
+ // rebuilds nothing when Node changes.
6
+ //
7
+ // node abi-des-dependances.mjs --marquer <projet> writes the mark of the current Node
8
+ // node abi-des-dependances.mjs --a-jour <projet> exit 0 when the mark is the current Node's,
9
+ // 1 otherwise (no mark, another one)
10
+ // node abi-des-dependances.mjs --manque <projet> prints the line « Manque » of the session
11
+ // start, nothing when nothing is missing
12
+ //
13
+ // - The mark is the file MARQUE under the project's node_modules, which holds the binary
14
+ // interface of the Node that installed the whole tree. A complete installation writes it: the
15
+ // project's `prepare` under `npm ci` (scripts/crochets.mjs), and the night after its own
16
+ // `npm ci` (scripts/nuit.sh). `npm install` leaves it as it stands: it rebuilds nothing already
17
+ // installed, so the mark keeps the interface of the last complete installation.
18
+ // - A project without node_modules has nothing to mark and lacks nothing here (the session start
19
+ // names the missing dependencies by its own line).
20
+ // - Without a mark (a tree installed by a former version of the frame, or by `npm install`
21
+ // alone), the night installs again, and the session start says nothing: it names a known gap.
22
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
23
+ import path from 'node:path';
24
+ import { pathToFileURL } from 'node:url';
25
+
26
+ /** The mark, from the root of the project. */
27
+ export const MARQUE = path.join('node_modules', '.grillhouse-abi');
28
+
29
+ /**
30
+ * Writes the mark of the binary interface <abi> in the project at <racine>, which has node_modules.
31
+ * @param {string} racine
32
+ * @param {string} [abi]
33
+ */
34
+ export function marquerLesDependances(racine, abi = process.versions.modules) {
35
+ writeFileSync(path.join(racine, MARQUE), `${abi}\n`);
36
+ }
37
+
38
+ /**
39
+ * Writes the mark when <env> is the environment of a script that `npm ci` runs (`npm_command`),
40
+ * the one installation that builds the whole tree again; true when it wrote it.
41
+ * @param {string} racine
42
+ * @param {NodeJS.ProcessEnv} [env]
43
+ * @param {string} [abi]
44
+ */
45
+ export function marquerApresInstallation(
46
+ racine,
47
+ env = process.env,
48
+ abi = process.versions.modules
49
+ ) {
50
+ if (env.npm_command !== 'ci' || !existsSync(path.join(racine, 'node_modules'))) {
51
+ return false;
52
+ }
53
+ marquerLesDependances(racine, abi);
54
+ return true;
55
+ }
56
+
57
+ /**
58
+ * The gap between the dependencies of the project at <racine> and the Node of <abi>: null when it
59
+ * has no node_modules or its mark is <abi>; otherwise the mark it holds, null for none.
60
+ * @param {string} racine
61
+ * @param {string} [abi]
62
+ * @returns {{ marquee: string | null } | null}
63
+ */
64
+ export function ecartDesDependances(racine, abi = process.versions.modules) {
65
+ if (!existsSync(path.join(racine, 'node_modules'))) {
66
+ return null;
67
+ }
68
+ const f = path.join(racine, MARQUE);
69
+ const marquee = existsSync(f) ? readFileSync(f, 'utf8').trim() || null : null;
70
+ return marquee === String(abi) ? null : { marquee };
71
+ }
72
+
73
+ /**
74
+ * The item of « Manque » of the session start for the project at <racine> under the Node of
75
+ * <abi> and <version>, with the command that rebuilds the tree; null when nothing is missing or
76
+ * when no mark says under which Node the tree was installed.
77
+ * @param {string} racine
78
+ * @param {string} [abi]
79
+ * @param {string} [version]
80
+ */
81
+ export function ligneDuManque(racine, abi = process.versions.modules, version = process.version) {
82
+ const ecart = ecartDesDependances(racine, abi);
83
+ if (ecart === null || ecart.marquee === null) {
84
+ return null;
85
+ }
86
+ return `les dépendances npm réinstallées sous le Node courant (${version}, interface binaire ${abi}) : elles ont été installées sous une autre version de Node (interface binaire ${ecart.marquee}), où un module natif ne charge plus (\`npm ci\`)`;
87
+ }
88
+
89
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
90
+ const [option, projet] = process.argv.slice(2);
91
+ const racine = path.resolve(projet ?? '.');
92
+ if (option === '--marquer') {
93
+ marquerLesDependances(racine);
94
+ } else if (option === '--a-jour') {
95
+ process.exitCode = ecartDesDependances(racine) === null ? 0 : 1;
96
+ } else if (option === '--manque') {
97
+ const ligne = ligneDuManque(racine);
98
+ if (ligne !== null) {
99
+ process.stdout.write(`${ligne}\n`);
100
+ }
101
+ } else {
102
+ process.stderr.write('usage : abi-des-dependances.mjs --marquer|--a-jour|--manque <projet>\n');
103
+ process.exitCode = 2;
104
+ }
105
+ }
@@ -33,11 +33,14 @@ import { DEPUIS_LE_VERT } from './dernier-vert.mjs';
33
33
  import { empreinteDEtape } from './empreinte-d-etape.mjs';
34
34
  import { FICHIER as DETTE } from './dette.mjs';
35
35
  import { commandesPermises, optionsDuRole } from './droits.mjs';
36
+ import { cheminsLus } from './composants-affectes.mjs';
36
37
  import { couvertPar } from './engendres.mjs';
37
38
  import { ecrireLaListe, VARIABLE as VARIABLE_ENVELOPPE } from './enveloppe/paquets-du-plan.mjs';
38
39
  import { etapeDuCircuit, EXPLORATEUR, SUITE } from './etapes.mjs';
39
40
  import { nomsDesGardes } from './gardes-du-cadre.mjs';
40
41
  import { INTEGRE } from './integration/file.mjs';
42
+ import { lotSurMain, refusLotAbsent } from './integration/integrer.mjs';
43
+ import { RETIRER_COPIE } from './integration/rejeu.mjs';
41
44
  import { AUTEUR_DU_VERDICT } from './integration/verdict.mjs';
42
45
  import { langageDe } from './langages.mjs';
43
46
  import { avecUneLecture } from './lecture-unique.mjs';
@@ -536,6 +539,29 @@ export function laPasseFinale(ctx) {
536
539
  return { arbre, restreinte: { avant: lot.base, apres: lot.commit } };
537
540
  }
538
541
 
542
+ // The filters of Turborepo the band <restreinte> (`{ avant, apres }`, two lots kept) plays at the
543
+ // final pass: the packages that changed from one to the other and their dependents, each package
544
+ // of <liste> whose tests declare they read a path the band changes (`grillhouse.lit`,
545
+ // `cheminsLus`: the `data` of Bazel, which Turborepo's graph does not see) and its dependents, then
546
+ // the root's tasks, the guards.
547
+ export function filtresDeLaBande(ctx, liste, restreinte) {
548
+ const fichiers = differenceDesLots(ctx, restreinte.avant, restreinte.apres);
549
+ const lecteurs = liste
550
+ .filter(
551
+ p =>
552
+ p.pkg?.name &&
553
+ fichiers.some(f => couvertPar(cheminsLus(path.join(ctx.copie, p.dossier)), f))
554
+ )
555
+ .map(p => p.pkg.name)
556
+ .sort();
557
+ return [
558
+ '--',
559
+ `--filter=...[${restreinte.avant}...${restreinte.apres}]`,
560
+ ...lecteurs.map(n => `--filter=...${n}`),
561
+ '--filter=//',
562
+ ];
563
+ }
564
+
539
565
  // The references of the circuit: those the project declares in the package.json of the copy
540
566
  // (`grillhouse.references`), each `{ nom, commande, fichiers, tests, lit, gardes }` with a name, a
541
567
  // command and files, `tests`, `lit` and `gardes` arrays when given, empty when not, `entiers` empty;
@@ -879,21 +905,63 @@ export const sectionMisDeCote = fichiers =>
879
905
 
880
906
  // The integration of the lot: its two patches, its message and the references that write files in
881
907
  // full (`--references`, from `lesReferences`, the one list), written from the copy, then
882
- // scripts/integration/integrer.mjs from the main tree, its output added to the log. A run « à
883
- // repasser » (75) plays once more, the gesture `rejeu`. `{ code, sortie, args }`.
908
+ // scripts/integration/integrer.mjs from the main tree, its output added to the log. `{ code,
909
+ // sortie, args }`.
884
910
  export function integrer(ctx) {
885
- // A lot already committed: its ticket is labelled `en-file` (scripts/integration/integrer.mjs)
886
- // until the queue takes it off, as a job of a CI keyed by its commit is not run twice. The
887
- // integration plays again without a second commit.
888
911
  const branche = `agent/${ctx.ticket}`;
912
+ const commande = `node ${INTEGRER}`;
889
913
  const show = ctx.bd('show', ctx.ticket, '--json');
890
914
  const etiquettes = show.status === 0 ? (JSON.parse(show.stdout)[0]?.labels ?? []) : [];
891
- if (etiquettes.includes('en-file')) {
892
- const sortie = `la branche ${branche} est déjà en file : le lot est déjà commité, aucun second commit.\n`;
915
+ const enFile = etiquettes.includes('en-file');
916
+ const { tests, code } = fichiersDuLot(ctx);
917
+ const finir = (sortie, suite) => {
893
918
  appendFileSync(ctx.journal, sortie);
894
- return { code: 0, sortie, args: [], commande: `node ${INTEGRER}`, deja: true };
919
+ return { args: [], commande, sortie, ...suite };
920
+ };
921
+ // The integration is not played when the lot is already on main or the copy holds no file to
922
+ // commit: one check, as a merge queue closes an entry already merged (Zuul). It is looked for
923
+ // when the ticket is labelled `en-file` (the queue takes it off) or the copy holds no file of the
924
+ // lot (a copy that holds one still has a lot to commit — a second commit of a reopened ticket, for
925
+ // example).
926
+ if (enFile || !(tests.length || code.length)) {
927
+ // A lot already on main (`lotSurMain`, the one rule the integrator publishes): the ticket
928
+ // finishes at integre, and its copy goes with its working directory, as the integrator removes
929
+ // the copy after a commit (here the ticket is done, so `.travail` goes too — no `--garder-travail`).
930
+ // A removal that fails stops under its name `copie-gardee`, the copy kept, and a new resumption
931
+ // plays the removal again.
932
+ const commit = lotSurMain({ racine: ctx.racine, bd: ctx.bd }, ctx.ticket);
933
+ if (commit) {
934
+ let retrait = { status: 0, stderr: '' };
935
+ if (existsSync(ctx.copie) && ctx.copie !== ctx.racine) {
936
+ retrait = spawnSync('bash', [RETIRER_COPIE, ctx.copie], {
937
+ cwd: ctx.racine,
938
+ encoding: 'utf8',
939
+ });
940
+ }
941
+ if (retrait.status !== 0) {
942
+ return finir(
943
+ `copie-gardee : le commit ${commit.slice(0, 7)} de ${branche} est déjà sur main, mais la copie ${ctx.copie} n'est pas retirée : ${retrait.stderr.trim()}\n`,
944
+ { code: 1, nom: 'copie-gardee' }
945
+ );
946
+ }
947
+ return finir(
948
+ `le commit ${commit.slice(0, 7)} de ${branche} est déjà sur main : aucun second commit, la copie ${ctx.copie} et son dossier de travail sont retirés.\n`,
949
+ { code: 0, deja: true }
950
+ );
951
+ }
952
+ // A lot already committed but not yet on main: its ticket is labelled `en-file`
953
+ // (scripts/integration/integrer.mjs) until the queue takes it off, as a job of a CI keyed by its
954
+ // commit is not run twice. The integration plays again without a second commit, then the queue.
955
+ if (enFile) {
956
+ return finir(
957
+ `la branche ${branche} est déjà en file : le lot est déjà commité, aucun second commit.\n`,
958
+ { code: 0, deja: true, enFile: true }
959
+ );
960
+ }
961
+ // No lot to apply and no commit on main: refused by its name, as the integrator refuses a direct
962
+ // call in the same case (the one rule `lotSurMain` deciding).
963
+ return finir(`${refusLotAbsent(ctx.ticket)}\n`, { code: 1, nom: 'lot-absent' });
895
964
  }
896
- const { tests, code } = fichiersDuLot(ctx);
897
965
  const dansCopie = (...a) =>
898
966
  spawnSync('git', ['-C', ctx.copie, ...a], { encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 });
899
967
  // Each file against HEAD, a new one against nothing: the index of the copy is not written.
@@ -936,35 +1004,20 @@ export function integrer(ctx) {
936
1004
  writeFileSync(f, `${JSON.stringify(entieres)}\n`);
937
1005
  args.push('--references', f);
938
1006
  }
939
- let r;
940
- for (let essai = 1; essai <= 2; essai++) {
941
- entete(ctx, 'integration');
942
- appendFileSync(ctx.journal, `$ node ${INTEGRER} ${args.join(' ')}\n`);
943
- const x = avecLAvancementDuTravail(
944
- ctx.tmp,
945
- { racine: ctx.copie, genre: 'integration' },
946
- avancement =>
947
- spawnSync(process.execPath, [INTEGRER, ...args], {
948
- cwd: ctx.racine,
949
- encoding: 'utf8',
950
- maxBuffer: 256 * 1024 * 1024,
951
- env: { ...process.env, [AVANCEMENT]: avancement },
952
- })
953
- );
954
- r = {
955
- code: x.status ?? 1,
956
- sortie: `${x.stdout ?? ''}${x.stderr ?? ''}`,
957
- args,
958
- commande: `node ${INTEGRER} ${args.join(' ')}`,
959
- };
960
- appendFileSync(ctx.journal, r.sortie);
961
- if (r.code !== A_REPASSER) {
962
- break;
963
- }
964
- if (essai === 1) {
965
- geste(ctx, 'rejeu');
966
- }
967
- }
1007
+ entete(ctx, 'integration');
1008
+ appendFileSync(ctx.journal, `$ node ${INTEGRER} ${args.join(' ')}\n`);
1009
+ const x = spawnSync(process.execPath, [INTEGRER, ...args], {
1010
+ cwd: ctx.racine,
1011
+ encoding: 'utf8',
1012
+ maxBuffer: 256 * 1024 * 1024,
1013
+ });
1014
+ const r = {
1015
+ code: x.status ?? 1,
1016
+ sortie: `${x.stdout ?? ''}${x.stderr ?? ''}`,
1017
+ args,
1018
+ commande: `node ${INTEGRER} ${args.join(' ')}`,
1019
+ };
1020
+ appendFileSync(ctx.journal, r.sortie);
968
1021
  return r;
969
1022
  }
970
1023
 
@@ -1925,8 +1978,8 @@ const ligneDeCommande = c =>
1925
1978
 
1926
1979
  // The checks after the developpeur: those of the plan (3.1), or, when <finale>, `npm run
1927
1980
  // verifier`, what the integration plays (4.1), restricted by <restreinte> (`{ avant, apres }`, two
1928
- // lots kept) to the packages that changed from one to the other and their dependents, with the
1929
- // root's tasks, the guards (`--filter=...[<avant>...<apres>] --filter=//`). After a regeneration,
1981
+ // lots kept) to the packages that changed from one to the other and their dependents, the readers
1982
+ // of a path it changes, with the root's tasks, the guards (`filtresDeLaBande`). After a regeneration,
1930
1983
  // <reportes> (`{ rouges, rejouee }`) carries the reds of the pass before it, the final pass or the
1931
1984
  // checks of the plan: each one in a package the pass after the regeneration does not play again
1932
1985
  // stands, as a CI keeps the verdict of a job it does not run again; when the regeneration changes
@@ -1955,7 +2008,7 @@ export function controles(ctx, finale, restreinte = null, reportes = null, fichi
1955
2008
  const filtres = duReprise
1956
2009
  ? ['--', ...duReprise.map(n => `--filter=${n}`), '--filter=//']
1957
2010
  : restreinte
1958
- ? ['--', `--filter=...[${restreinte.avant}...${restreinte.apres}]`, '--filter=//']
2011
+ ? filtresDeLaBande(ctx, liste, restreinte)
1959
2012
  : [];
1960
2013
  const commandes =
1961
2014
  reportes && !reportes.rejouee
@@ -68,6 +68,7 @@ export const REDIRIGEES = new Set([
68
68
  'journal',
69
69
  'lancer',
70
70
  'ligne-etat',
71
+ 'newday',
71
72
  'nuit',
72
73
  'registre',
73
74
  'resultats',
@@ -30,7 +30,7 @@
30
30
  // total of the last pass of each kind and the files planned of each task by its hash (the
31
31
  // latest TACHES_GARDEES); each pass keeps its own at its end (`garderLeTotal`).
32
32
  // - The holder of the lock of the machine (scripts/verrou-de-machine.mjs: a measure out of a
33
- // ticket, `npm run verifier` of a supervisor or of an integration, or a heavy pass of the
33
+ // ticket, `npm run verifier` of a supervisor, or a heavy pass of the
34
34
  // circuit of a ticket) names its progress directory beside the lock (`nommerLAvancement`); the
35
35
  // board reads the holder with its progress, and the waits for the lock or for room
36
36
  // (`lireLaMesure`).
@@ -231,23 +231,18 @@ export function avancementDeLaCI(travail, { nouvelle = false, debut = Date.now()
231
231
  /**
232
232
  * Runs <passe> under a progress directory of the kind <genre> (null: none kept) opened in the
233
233
  * working directory <travail> of a ticket's circuit, where the board reads it
234
- * (`avancementDuTravail`): each automatic pass of the circuit (scripts/activites.mjs) and the
235
- * replay of the ticket's branch by the queue (scripts/faits-du-circuit.mjs `avancer`), one pass at
236
- * a time. The directories a killed pass left there go first, a lot that goes through the queue
237
- * again included. The directory is given to <passe> and named to it and its children by
234
+ * (`avancementDuTravail`): each automatic pass of the circuit (scripts/activites.mjs), one pass
235
+ * at a time. The directories a killed pass left there go first. The directory is given to <passe> and named to it and its children by
238
236
  * GRILLHOUSE_AVANCEMENT (`AVANCEMENT`); then its total is kept in the repository at <racine> and
239
- * it is removed, unless <garder> holds for what <passe> returns: a lot entered on main keeps it
240
- * until the queue is done with the ticket closed, which removes the working directory whole
241
- * (`retirerLeTravail` of scripts/integration/file.mjs), as the circuit kept its progress for its
242
- * whole step of the queue. Without the working directory, <passe> runs without one (null).
237
+ * it is removed. Without the working directory, <passe> runs without one (null).
243
238
  * Returns what <passe> returns.
244
239
  * @template T
245
240
  * @param {string} travail
246
- * @param {{ racine: string, genre: string | null, garder?: (valeur: T) => boolean }} o
241
+ * @param {{ racine: string, genre: string | null }} o
247
242
  * @param {(dossier: string | null) => T} passe
248
243
  * @returns {T}
249
244
  */
250
- export function avecLAvancementDuTravail(travail, { racine, genre, garder = () => false }, passe) {
245
+ export function avecLAvancementDuTravail(travail, { racine, genre }, passe) {
251
246
  if (!existsSync(travail)) {
252
247
  return passe(null);
253
248
  }
@@ -257,11 +252,8 @@ export function avecLAvancementDuTravail(travail, { racine, genre, garder = () =
257
252
  const dossier = ouvrirAvancement({ racine, genre, dans: travail });
258
253
  const avant = process.env[AVANCEMENT];
259
254
  process.env[AVANCEMENT] = dossier;
260
- let garde = false;
261
255
  try {
262
- const valeur = passe(dossier);
263
- garde = garder(valeur);
264
- return valeur;
256
+ return passe(dossier);
265
257
  } finally {
266
258
  if (avant === undefined) {
267
259
  delete process.env[AVANCEMENT];
@@ -269,9 +261,7 @@ export function avecLAvancementDuTravail(travail, { racine, genre, garder = () =
269
261
  process.env[AVANCEMENT] = avant;
270
262
  }
271
263
  garderLeTotal(dossier);
272
- if (!garde) {
273
- rmSync(dossier, { recursive: true, force: true });
274
- }
264
+ rmSync(dossier, { recursive: true, force: true });
275
265
  }
276
266
  }
277
267
 
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+ // The CI of a project's ticket branches: the queue enters a lot on main only once the CI of its
3
+ // branch `agent/<ticket>` judged it green (scripts/integration/file.mjs), so the project's CI must
4
+ // run on a push to `agent/**`, as bors needs a status on its staging branch.
5
+ //
6
+ // node ci-des-branches.mjs --absente <project> prints one line when no workflow of the project
7
+ // runs on a push to a ticket's branch
8
+ //
9
+ // - Whether a workflow runs on a push to a ticket's branch is the queue's own reading of the
10
+ // workflows (`fluxDeLaBranche` of scripts/integration/file.mjs), here on the working tree's
11
+ // `.github/workflows/*.yml` and `*.yaml`, for the branch `agent/ticket`.
12
+ // - `ajouterLesBranchesDeTicket` adds `agent/**` to the `on.push.branches` list of each workflow
13
+ // that runs on a push to the branch main is pushed to (`grillhouse.poussee.commit`, `main` by
14
+ // default), the CI of the lots, its comments and its layout kept (the library yaml's document);
15
+ // a project already listening, or none to judge, is left as it is, `GESTE` the line left to it.
16
+ import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
17
+ import path from 'node:path';
18
+ import { pathToFileURL } from 'node:url';
19
+ import { parseDocument } from 'yaml';
20
+ import { fluxDeLaBranche } from './integration/file.mjs';
21
+ import { lireCommit } from './poussee-cles.mjs';
22
+
23
+ /** The pattern of the ticket branches the queue pushes. */
24
+ export const BRANCHES_DE_TICKET = 'agent/**';
25
+ // A branch of a ticket, which the pattern matches.
26
+ const TEMOIN = 'agent/ticket';
27
+ const DOSSIER = '.github/workflows';
28
+ /** The gesture left to a project none of whose workflows runs on a push to `agent/**`. */
29
+ export const GESTE = `aucun flux de ${DOSSIER} ne se lance sur un push vers les branches de ticket : la file n'entre un lot sur main qu'une fois la CI de sa branche verte ; ajoute '${BRANCHES_DE_TICKET}' aux branches du push du flux de la CI du projet.`;
30
+
31
+ // The workflows of the working tree of <racine>: `{ chemin, texte }`.
32
+ function lesFlux(racine) {
33
+ const dossier = path.join(racine, DOSSIER);
34
+ if (!existsSync(dossier)) {
35
+ return [];
36
+ }
37
+ return readdirSync(dossier)
38
+ .filter(n => /\.ya?ml$/.test(n))
39
+ .sort()
40
+ .map(n => ({ chemin: `${DOSSIER}/${n}`, texte: readFileSync(path.join(dossier, n), 'utf8') }));
41
+ }
42
+
43
+ /** Whether a workflow of the project at <racine> runs on a push to a ticket's branch. */
44
+ export function ecouteLesBranchesDeTicket(racine) {
45
+ return fluxDeLaBranche(lesFlux(racine), TEMOIN).length > 0;
46
+ }
47
+
48
+ // The branch main is pushed to, from the package.json of <racine>; `main` without it.
49
+ function principale(racine) {
50
+ const f = path.join(racine, 'package.json');
51
+ try {
52
+ return lireCommit(JSON.parse(readFileSync(f, 'utf8'))).commit ?? 'main';
53
+ } catch {
54
+ return 'main';
55
+ }
56
+ }
57
+
58
+ /**
59
+ * `agent/**` added to the push of the CI of the lots of the project at <racine>: the workflows
60
+ * written, none when the project already listens or has no workflow that runs on a push to main
61
+ * with a list of branches to add it to.
62
+ */
63
+ export function ajouterLesBranchesDeTicket(racine) {
64
+ const flux = lesFlux(racine);
65
+ if (fluxDeLaBranche(flux, TEMOIN).length > 0) {
66
+ return [];
67
+ }
68
+ const surMain = new Set(fluxDeLaBranche(flux, principale(racine)));
69
+ const ajoutes = [];
70
+ for (const { chemin, texte } of flux.filter(f => surMain.has(f.chemin))) {
71
+ const doc = parseDocument(texte);
72
+ const branches = doc.getIn(['on', 'push', 'branches'], true);
73
+ if (!branches || typeof branches.add !== 'function') {
74
+ continue;
75
+ }
76
+ branches.add(doc.createNode(BRANCHES_DE_TICKET));
77
+ writeFileSync(path.join(racine, chemin), doc.toString());
78
+ ajoutes.push(chemin);
79
+ }
80
+ return ajoutes;
81
+ }
82
+
83
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
84
+ const [option, racine] = process.argv.slice(2);
85
+ if (option !== '--absente' || !racine) {
86
+ process.stderr.write('usage: ci-des-branches.mjs --absente <projet>\n');
87
+ process.exitCode = 2;
88
+ } else if (!ecouteLesBranchesDeTicket(racine)) {
89
+ process.stdout.write(`${BRANCHES_DE_TICKET}\n`);
90
+ }
91
+ }
@@ -595,7 +595,9 @@
595
595
  // the developpeur's same sending to the testwriter twice in a row, on the same red output of the
596
596
  // checks, no green checks between them), 16 relecture-arret (a finding without a valid agent, one to the testwriter the plan skips,
597
597
  // one on a criterion, the third RENDU), 17 integration (the integration script refuses the lot, or the queue reopens the
598
- // ticket), 19 hors-portee (a testwriter or developpeur whose sheet says BLOQUÉ, without a
598
+ // ticket; at the same code, two stops of the resumption of the integration under their own
599
+ // names: lot-absent, a lot neither on main nor in the copy, and copie-gardee, a lot on main
600
+ // whose copy does not get removed), 19 hors-portee (a testwriter or developpeur whose sheet says BLOQUÉ, without a
599
601
  // sending to the testwriter, or a developpeur's FAIT with criteria out of the plan), 20 besoin (a testwriter or developpeur whose sheet says BESOIN, a
600
602
  // reviewer whose sheet carries a `question`, or a ticket labelled `arbitrage` whose arbitrage
601
603
  // `refusArbitrage` of scripts/integration/integrer.mjs refuses, at the launch or a resumption,
@@ -704,7 +706,7 @@ import {
704
706
  reponsesAuxQuestions,
705
707
  sorteDuPlan,
706
708
  } from './resultats.mjs';
707
- import { preparer } from './enveloppe/travail-de-la-copie.mjs';
709
+ import { preparer, rolesDuConflit } from './enveloppe/travail-de-la-copie.mjs';
708
710
  import { refusArbitrage } from './integration/integrer.mjs';
709
711
  import { prendreUnRang } from './places-de-la-machine.mjs';
710
712
  import { langageDe } from './langages.mjs';
@@ -912,6 +914,18 @@ function inscrireEtape(ctx, { etape, debut }) {
912
914
  });
913
915
  }
914
916
 
917
+ // The rule of a test file of the module of the language of the copy of <ctx> (`estUnTest`); a copy
918
+ // the module does not read judges every file the developpeur's.
919
+ function rouleDeTest(ctx) {
920
+ return fichier => {
921
+ try {
922
+ return langageDe(ctx.copie).estUnTest(fichier, ctx.copie);
923
+ } catch {
924
+ return null;
925
+ }
926
+ };
927
+ }
928
+
915
929
  // The steps whose pass judges the lot, 3.1 and 4.1 (one state, `finale` apart): the copy is
916
930
  // prepared on the tip of main before each of them.
917
931
  export const SUR_LA_POINTE = new Set([CONTROLES]);
@@ -930,7 +944,8 @@ export function avantLaPasse(
930
944
  ctx,
931
945
  etape,
932
946
  regeneration,
933
- env = environnementDeLaPasse(ctx, process.env)
947
+ env = environnementDeLaPasse(ctx, process.env),
948
+ { estUnTest = rouleDeTest(ctx) } = {}
934
949
  ) {
935
950
  if (!SUR_LA_POINTE.has(etape)) {
936
951
  return { avancee: false, regeneration };
@@ -948,7 +963,11 @@ export function avantLaPasse(
948
963
  );
949
964
  const fd = openSync(ctx.journal, 'a');
950
965
  try {
951
- r = preparer(ctx.copie, cible.stdout.trim(), { env, sortie: fd });
966
+ r = preparer(ctx.copie, cible.stdout.trim(), {
967
+ env,
968
+ sortie: fd,
969
+ suspects: ctx.fichiersDuConflit ?? [],
970
+ });
952
971
  } finally {
953
972
  closeSync(fd);
954
973
  }
@@ -959,6 +978,30 @@ export function avantLaPasse(
959
978
  const avancee = tete(ctx.copie).stdout.trim() !== avant.stdout.trim();
960
979
  return { avancee, regeneration: avancee ? null : regeneration };
961
980
  }
981
+ const fichiers = [...(r.conflits ?? []), ...(r.enAttente ?? [])];
982
+ if (fichiers.length) {
983
+ // The files in conflict, or kept in the lot, go to the role that writes them, the testwriter
984
+ // first; a role already relaunched for them that left one of its files is not relaunched: the
985
+ // stop goes up.
986
+ const { testwriter, developpeur, roles } = rolesDuConflit(fichiers, estUnTest);
987
+ const relances = ctx.conflitsRelances ?? [];
988
+ const restants = roles.filter(role => !relances.includes(role));
989
+ if (restants.length && restants.length === roles.length) {
990
+ const deRestants = restants.flatMap(role =>
991
+ role === 'testwriter' ? testwriter : developpeur
992
+ );
993
+ const siens = restants[0] === 'testwriter' ? testwriter : developpeur;
994
+ return {
995
+ avancee: false,
996
+ regeneration,
997
+ conflit: {
998
+ fichiers: deRestants,
999
+ roles: restants,
1000
+ rapport: `${r.message}\n\nL'avance de la copie sur la pointe de main a laissé ces fichiers à ton rôle : ${siens.join(', ')}.\nLes marques de conflit sont dans la copie (\`<<<<<<<\`, \`=======\`, \`>>>>>>>\`) : tu résous chaque fichier, marques retirées ; un fichier du lot gardé (\`grillhouse-travail.patch\`, dans le dossier git de la copie) se reprend à la main dans la copie, un fichier supprimé par le lot se supprime. Les fichiers de l'autre rôle restent à sa séance.`,
1001
+ },
1002
+ };
1003
+ }
1004
+ }
962
1005
  return {
963
1006
  arret: {
964
1007
  nom: 'lancement',
@@ -969,6 +1012,35 @@ export function avantLaPasse(
969
1012
  };
970
1013
  }
971
1014
 
1015
+ /**
1016
+ * What the circuit keeps of the conflict <conflit> (`avantLaPasse`) its pass at the state <etat>
1017
+ * met: the role relaunched, the first of `conflit.roles`, and the memory: the roles relaunched,
1018
+ * the files of the conflict, whose marks the next advance looks for again (`fichiersDuConflit`),
1019
+ * and the state of the pass the role's session comes back to (`retourDuConflit`), not the step
1020
+ * that follows the role, so no build plays while a file carries marks.
1021
+ * @param {{ conflitsRelances?: string[] | null, fichiersDuConflit?: string[] | null }} ctx
1022
+ * @param {object} etat
1023
+ * @param {{ fichiers: string[], roles: string[] }} conflit
1024
+ */
1025
+ export function suiteDuConflit(ctx, etat, conflit) {
1026
+ const [role] = conflit.roles;
1027
+ return {
1028
+ role,
1029
+ memoire: {
1030
+ conflitsRelances: [...(ctx.conflitsRelances ?? []), role],
1031
+ fichiersDuConflit: [...new Set([...(ctx.fichiersDuConflit ?? []), ...conflit.fichiers])],
1032
+ retourDuConflit: etat,
1033
+ },
1034
+ };
1035
+ }
1036
+
1037
+ // The memory of a conflict once its pass prepares the copy without one: dropped.
1038
+ export const SANS_CONFLIT = Object.freeze({
1039
+ conflitsRelances: null,
1040
+ fichiersDuConflit: null,
1041
+ retourDuConflit: null,
1042
+ });
1043
+
972
1044
  // The tools of the project whose main tree is <racine>, read at the launch of a run:
973
1045
  // `{ outils }`, or `{ arret }`, the stop « lancement » that goes up to the supervisor before any
974
1046
  // session (its code, name, report, piece and question), the faults of the key named.
@@ -1282,6 +1354,9 @@ export const MEMOIRE = [
1282
1354
  'verts',
1283
1355
  'reprise',
1284
1356
  'relancesTestwriter',
1357
+ 'conflitsRelances',
1358
+ 'fichiersDuConflit',
1359
+ 'retourDuConflit',
1285
1360
  ];
1286
1361
 
1287
1362
  // The fact <fait> of the circuit of <ctx>, with its <parametres>, the facts <faits> of the step
@@ -385,23 +385,40 @@ export function texteDuReleve(r) {
385
385
  return out.join('\n');
386
386
  }
387
387
 
388
- // The command: its exit code.
389
- function commande(racine, args) {
388
+ // The survey of the draft description in the file <fichier> (from <racine>), as text; the command
389
+ // `--description` writes it on its standard output.
390
+ export function rapportDescription(racine, fichier) {
391
+ return texteDuReleve(releve(racine, readFileSync(path.resolve(racine, fichier), 'utf8')));
392
+ }
393
+
394
+ const USAGE = 'usage: npx grillhouse composants-affectes <ticket> | --description <fichier>\n';
395
+
396
+ // The command: its exit code. `-h`/`--help` writes the usage, exit 0; any other option than
397
+ // `--description`, the usage on the error stream, exit 2.
398
+ export function commande(racine, args) {
399
+ if (args.includes('-h') || args.includes('--help')) {
400
+ process.stdout.write(USAGE);
401
+ return 0;
402
+ }
403
+ const inconnue = args.find(
404
+ (a, k) => a.startsWith('-') && a !== '--description' && args[k - 1] !== '--description'
405
+ );
406
+ if (inconnue) {
407
+ process.stderr.write(`⛔ option inconnue : ${inconnue}\n${USAGE}`);
408
+ return 2;
409
+ }
390
410
  const i = args.indexOf('--description');
391
411
  if (i >= 0) {
392
412
  if (!args[i + 1]) {
393
413
  process.stderr.write('usage: npx grillhouse composants-affectes --description <fichier>\n');
394
414
  return 2;
395
415
  }
396
- const r = releve(racine, readFileSync(path.resolve(racine, args[i + 1]), 'utf8'));
397
- process.stdout.write(`${texteDuReleve(r)}\n`);
416
+ process.stdout.write(`${rapportDescription(racine, args[i + 1])}\n`);
398
417
  return 0;
399
418
  }
400
419
  const [ticket] = args;
401
420
  if (!ticket) {
402
- process.stderr.write(
403
- 'usage: npx grillhouse composants-affectes <ticket> | --description <fichier>\n'
404
- );
421
+ process.stderr.write(USAGE);
405
422
  return 2;
406
423
  }
407
424
  const show = spawnSync('bd', ['show', ticket, '--json'], {
@@ -18,6 +18,8 @@
18
18
  // when one module cannot read it, its reason named with its language.
19
19
  // - The verdict of a run is every module's, read in the same results directory, where each module
20
20
  // writes under names of its own (scripts/resultats.mjs).
21
+ // - The environment of the poste is each module's, applied one after the other: a module that
22
+ // finds its file's variables already set (by the one before) leaves the environment as it is.
21
23
  // - Each command a module describes is the composed command by its name
22
24
  // (./commandes-composees.mjs), which plays it in each module that describes it and joins their
23
25
  // codes.
@@ -196,6 +198,7 @@ export function composer(modules) {
196
198
  matieres: racine => modules.flatMap(m => m.matieres(racine)),
197
199
  joueDesTests: (racine, composant) =>
198
200
  moduleDuComposant(racine, composant)?.joueDesTests(racine, composant) ?? false,
201
+ environnementDuPoste: env => modules.reduce((e, m) => m.environnementDuPoste(e), env),
199
202
  empreintes(racine, noms) {
200
203
  const parts = modules.map(m => m.empreintes(racine, noms));
201
204
  return parts.some(p => p === null) ? null : Object.assign({}, ...parts);