@roomi-fields/grillhouse 0.48.0 → 0.49.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 (147) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +68 -0
  3. package/agents/direct.md +9 -0
  4. package/cadre/templates/projet/.github/workflows/ci.yml +6 -0
  5. package/cadre/templates/projet/.github/workflows/nuit.yml +9 -2
  6. package/cadre/templates/projet/CLAUDE.md +9 -5
  7. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  8. package/cadre/templates/turbo/paquets.json +3 -1
  9. package/cadre/templates/turbo/sans-paquets.json +3 -1
  10. package/charte.md +40 -14
  11. package/dist/temporal/circuit/appel.d.ts +4 -1
  12. package/dist/temporal/circuit/appel.js +15 -1
  13. package/dist/temporal/circuit/appel.js.map +1 -1
  14. package/dist/temporal/circuit/client.d.ts +7 -1
  15. package/dist/temporal/circuit/client.js +54 -1
  16. package/dist/temporal/circuit/client.js.map +1 -1
  17. package/dist/temporal/circuit/commande.js +30 -57
  18. package/dist/temporal/circuit/commande.js.map +1 -1
  19. package/dist/temporal/circuit/contrat.d.ts +2 -1
  20. package/dist/temporal/circuit/contrat.js +2 -1
  21. package/dist/temporal/circuit/contrat.js.map +1 -1
  22. package/dist/temporal/circuit/deroule.js +9 -2
  23. package/dist/temporal/circuit/deroule.js.map +1 -1
  24. package/dist/temporal/file/contrat.d.ts +16 -2
  25. package/dist/temporal/file/contrat.js +27 -3
  26. package/dist/temporal/file/contrat.js.map +1 -1
  27. package/dist/temporal/file/deroule.js +4 -4
  28. package/dist/temporal/file/deroule.js.map +1 -1
  29. package/dist/temporal/nuits/activites.d.ts +1 -15
  30. package/dist/temporal/nuits/activites.js +3 -62
  31. package/dist/temporal/nuits/activites.js.map +1 -1
  32. package/dist/temporal/nuits/contrat.d.ts +3 -21
  33. package/dist/temporal/nuits/deroule.js +38 -74
  34. package/dist/temporal/nuits/deroule.js.map +1 -1
  35. package/dist/temporal/places/client.d.ts +3 -16
  36. package/dist/temporal/places/client.js +3 -26
  37. package/dist/temporal/places/client.js.map +1 -1
  38. package/dist/temporal/places/contrat.d.ts +15 -51
  39. package/dist/temporal/places/contrat.js +3 -13
  40. package/dist/temporal/places/contrat.js.map +1 -1
  41. package/dist/temporal/places/deroule.js +11 -61
  42. package/dist/temporal/places/deroule.js.map +1 -1
  43. package/dist/temporal/tickets/activites.js +4 -2
  44. package/dist/temporal/tickets/activites.js.map +1 -1
  45. package/dist/temporal/tickets/contrat.d.ts +2 -1
  46. package/docs/ARCHITECTURE.md +310 -115
  47. package/docs/CADRE.md +16 -13
  48. package/docs/INTERFACE.md +90 -25
  49. package/hooks/hooks.json +9 -0
  50. package/hooks/register.tsx +59 -5
  51. package/package.json +1 -1
  52. package/scripts/activites.mjs +271 -42
  53. package/scripts/aiguillage.mjs +4 -1
  54. package/scripts/bilan.mjs +125 -2
  55. package/scripts/circuit.mjs +233 -159
  56. package/scripts/circuits-cles.d.mts +3 -3
  57. package/scripts/circuits-cles.mjs +6 -5
  58. package/scripts/coeurs-dedies.mjs +4 -4
  59. package/scripts/commandes-composees.mjs +12 -5
  60. package/scripts/dette.d.ts +2 -1
  61. package/scripts/dette.mjs +49 -6
  62. package/scripts/direct.mjs +343 -0
  63. package/scripts/droits.mjs +19 -0
  64. package/scripts/effets.mjs +4 -4
  65. package/scripts/engendres.mjs +2 -1
  66. package/scripts/enveloppe/enveloppe.mjs +67 -13
  67. package/scripts/enveloppe/lancer.sh +14 -3
  68. package/scripts/enveloppe/paquets-du-plan.mjs +9 -0
  69. package/scripts/enveloppe/travail-de-la-copie.mjs +119 -21
  70. package/scripts/etapes.mjs +3 -3
  71. package/scripts/faits-du-circuit.mjs +12 -11
  72. package/scripts/fermeture-de-la-machine.d.mts +4 -4
  73. package/scripts/fermeture-de-la-machine.mjs +10 -20
  74. package/scripts/fichiers-nommes.mjs +27 -1
  75. package/scripts/file-des-tickets.d.mts +18 -1
  76. package/scripts/file-des-tickets.mjs +63 -15
  77. package/scripts/grillhouse-maj.mjs +13 -25
  78. package/scripts/groupe-cles.d.mts +6 -0
  79. package/scripts/groupe-cles.mjs +29 -1
  80. package/scripts/integration/file.mjs +148 -37
  81. package/scripts/jointure.d.ts +17 -3
  82. package/scripts/journal-des-etats.d.mts +16 -0
  83. package/scripts/journal-des-etats.mjs +44 -2
  84. package/scripts/journal.mjs +3 -0
  85. package/scripts/langages/c/commandes.mjs +5 -5
  86. package/scripts/langages/c/composants.mjs +13 -5
  87. package/scripts/langages/cargo/commandes.mjs +5 -6
  88. package/scripts/langages/python/commandes.mjs +5 -5
  89. package/scripts/langages/python/composants.mjs +10 -2
  90. package/scripts/langages/typescript/composants.mjs +10 -3
  91. package/scripts/langages/typescript/construire.mjs +2 -0
  92. package/scripts/langages/typescript/exemples.mjs +33 -1
  93. package/scripts/langages/typescript/index.mjs +19 -0
  94. package/scripts/langages/typescript/migrations/0.49.0-tests-equipes.mjs +32 -0
  95. package/scripts/langages/typescript/tests-de-nuit.mjs +152 -32
  96. package/scripts/langages/typescript/tests-du-poste.mjs +65 -23
  97. package/scripts/langages/typescript/titres-de-tests.mjs +11 -7
  98. package/scripts/langages/typescript/turbo-des-paquets.mjs +21 -4
  99. package/scripts/langages/typescript/verifier.mjs +3 -5
  100. package/scripts/langages/typescript/verrou-des-dependances.mjs +161 -0
  101. package/scripts/langages/typescript/vitest-config/cibles.mjs +57 -6
  102. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +11 -5
  103. package/scripts/langages/typescript/vitest.nuit.config.mjs +53 -5
  104. package/scripts/machine.mjs +1 -1
  105. package/scripts/mesure/base-de-passe.mjs +2 -1
  106. package/scripts/migrations/0.49.0-reservation-de-trois-coeurs.mjs +30 -0
  107. package/scripts/migrations.mjs +2 -0
  108. package/scripts/nuit.sh +97 -2
  109. package/scripts/paquet.mjs +16 -5
  110. package/scripts/paquets.d.ts +4 -0
  111. package/scripts/paquets.mjs +57 -0
  112. package/scripts/passe-de-la-machine.mjs +4 -7
  113. package/scripts/places-de-la-machine.mjs +55 -42
  114. package/scripts/places-du-serveur.mjs +2 -2
  115. package/scripts/plafond-de-la-machine.d.mts +7 -13
  116. package/scripts/plafond-de-la-machine.mjs +19 -35
  117. package/scripts/prefixe-des-tickets.mjs +1 -1
  118. package/scripts/references-changees.mjs +159 -0
  119. package/scripts/regles-des-places.d.mts +8 -31
  120. package/scripts/regles-des-places.mjs +14 -64
  121. package/scripts/repli-de-la-nuit.mjs +112 -0
  122. package/scripts/reponses-du-circuit.d.mts +2 -2
  123. package/scripts/reponses-du-circuit.mjs +21 -12
  124. package/scripts/reprise.mjs +27 -8
  125. package/scripts/resultats.mjs +21 -9
  126. package/scripts/seances.mjs +258 -40
  127. package/scripts/services-du-noyau.mjs +3 -0
  128. package/scripts/sous-commandes.mjs +24 -7
  129. package/scripts/superviseur.mjs +185 -39
  130. package/scripts/tableau.mjs +220 -89
  131. package/scripts/taches-du-graphe.mjs +84 -4
  132. package/scripts/ticket.mjs +345 -0
  133. package/scripts/transitions.d.mts +44 -0
  134. package/scripts/transitions.mjs +173 -13
  135. package/scripts/un-commit-par-ticket.mjs +4 -3
  136. package/scripts/verdict-de-la-nuit.mjs +47 -20
  137. package/scripts/verrou-de-fichier.mjs +2 -2
  138. package/scripts/verrous/ecriture-hors-enveloppe.mjs +86 -0
  139. package/scripts/verrous/verrou.mjs +17 -1
  140. package/skills/developpeur/SKILL.md +1 -1
  141. package/skills/direct/SKILL.md +57 -0
  142. package/skills/explorateur/SKILL.md +10 -6
  143. package/skills/pitmaster/SKILL.md +34 -14
  144. package/skills/pitmaster/references/consigne-agent.md +7 -1
  145. package/skills/relecteur/SKILL.md +8 -0
  146. package/skills/testwriter/SKILL.md +10 -0
  147. package/scripts/ticket.sh +0 -25
@@ -46,8 +46,12 @@ export const PLAFOND_PAR_DEFAUT = 3;
46
46
  export const RESERVE_COEURS_PAR_DEFAUT = 4;
47
47
  /** The memory the reserve of the user keeps when nothing names another, in GB. */
48
48
  export const RESERVE_MEMOIRE_GO_PAR_DEFAUT = 4;
49
- /** The cores a default part holds at least. */
50
- export const MIN_COEURS_DE_LA_PART = 4;
49
+ /** The cores the reservation of an ordinary pass holds when its project declares none. */
50
+ export const COEURS_PAR_DEFAUT = 3;
51
+ /** The cores the reservation of a direct pass holds, fixed. */
52
+ export const COEURS_DU_DIRECT = 2;
53
+ // The cores the reserve of the user leaves the passes at least; the floor of the memory.
54
+ const COEURS_LAISSES_AUX_PASSES = 4;
51
55
 
52
56
  /**
53
57
  * The ceiling of the places under <env>: GRILLHOUSE_PLACES of the environment, else of the file
@@ -121,7 +125,7 @@ export function reserveDe(env = process.env, o = {}) {
121
125
  const coeursDeLaMachine = o.coeurs ?? cpus().length;
122
126
  const parDefaut = Math.min(
123
127
  RESERVE_COEURS_PAR_DEFAUT,
124
- Math.max(0, coeursDeLaMachine - MIN_COEURS_DE_LA_PART)
128
+ Math.max(0, coeursDeLaMachine - COEURS_LAISSES_AUX_PASSES)
125
129
  );
126
130
  return {
127
131
  coeurs: entierDuPoste(env, VARIABLE_RESERVE_COEURS, parDefaut, o.lire),
@@ -155,54 +159,34 @@ export function budgetDe({ coeurs, memoireTotale }, reserve) {
155
159
  /** The margin over the largest measured peak of memory: a quarter. */
156
160
  const MARGE_DE_LA_MEMOIRE = 1.25;
157
161
 
158
- /**
159
- * The part of a pass when its project declares none, pure: the budget divided by the <places> of
160
- * the machine in cores (whole division, 2 at least, within the budget and one core at least), and
161
- * in memory the largest measured peak <pic> plus a quarter (the hard ceiling of the group kills a
162
- * pass above it, so a percentile would not do), within the budget and never under its floor, the
163
- * proportion of the cores of a part before the division (a third of the budget): the peak raises
164
- * the memory, it does not lower it; the floor alone when <pic> is absent.
165
- * @param {{ coeurs: number, memoire: number }} budget
166
- * @param {number} places
167
- * @param {number | undefined} pic the largest peak of memory of the day passes, absent unmeasured
168
- * @returns {{ coeurs: number, memoire: number }}
169
- */
170
- export function partParDefautDe(budget, places, pic) {
171
- const coeurs = Math.max(
172
- 1,
173
- Math.min(budget.coeurs, Math.max(2, Math.floor(budget.coeurs / places)))
174
- );
175
- return { coeurs, memoire: memoireParDefautDe(budget, pic) };
176
- }
177
-
178
- // The default memory, independent of the division by the places: its floor, the proportion of the
179
- // cores a part had before the division (MIN_COEURS_DE_LA_PART, or a third of the budget rounded up
180
- // when that is more), raised to the peak plus a quarter when the register measured more. A
162
+ // The default memory: its floor, the proportion of the budget a part of 4 cores held (or a third
163
+ // of the budget rounded up when that is more), raised to the largest measured peak <pic> plus a
164
+ // quarter (the hard ceiling of the group kills a pass above it) when the register measured more. A
181
165
  // register that holds light passes alone (the guards, a pass of 50 ms: a peak of 16 Mo) would
182
166
  // else give the next pass a ceiling its kernel kills it under, as the Vertical Pod Autoscaler
183
167
  // bounds its recommendation by a minimum (`minAllowed`).
184
168
  function memoireParDefautDe(budget, pic) {
185
169
  const coeursDAvant = Math.max(
186
170
  1,
187
- Math.min(budget.coeurs, Math.max(MIN_COEURS_DE_LA_PART, Math.ceil(budget.coeurs / 3)))
171
+ Math.min(budget.coeurs, Math.max(COEURS_LAISSES_AUX_PASSES, Math.ceil(budget.coeurs / 3)))
188
172
  );
189
173
  const plancher = Math.floor((budget.memoire * coeursDAvant) / budget.coeurs);
190
174
  return Math.min(budget.memoire, Math.max(plancher, Math.floor((pic ?? 0) * MARGE_DE_LA_MEMOIRE)));
191
175
  }
192
176
 
193
177
  /**
194
- * The part of a pass: the one its project declares (`partDeclareeDe`), its missing values from the
195
- * default part, within the budget and one core at least.
178
+ * The reservation of a pass: the cores its project declares (`partDeclareeDe`), else 3, within the
179
+ * budget and one core at least; a direct pass reserves 2 cores, fixed. Its memory is the declared
180
+ * one, else the default memory, within the budget.
196
181
  * @param {{ declaree: { coeurs?: number, memoire?: number } | null,
197
- * budget: { coeurs: number, memoire: number }, places: number, pic: number | undefined }} o
182
+ * budget: { coeurs: number, memoire: number }, pic: number | undefined, direct?: boolean }} o
198
183
  * @returns {{ coeurs: number, memoire: number }}
199
184
  */
200
- export function partDe({ declaree, budget, places, pic }) {
201
- const defaut = partParDefautDe(budget, places, pic);
202
- const coeurs = Math.max(1, Math.min(budget.coeurs, declaree?.coeurs ?? defaut.coeurs));
185
+ export function partDe({ declaree, budget, pic, direct = false }) {
186
+ const voulus = direct ? COEURS_DU_DIRECT : (declaree?.coeurs ?? COEURS_PAR_DEFAUT);
203
187
  return {
204
- coeurs,
205
- memoire: Math.min(budget.memoire, declaree?.memoire ?? defaut.memoire),
188
+ coeurs: Math.max(1, Math.min(budget.coeurs, voulus)),
189
+ memoire: Math.min(budget.memoire, declaree?.memoire ?? memoireParDefautDe(budget, pic)),
206
190
  };
207
191
  }
208
192
 
@@ -82,7 +82,7 @@ export function ecrireLePrefixe(racine, valeur) {
82
82
  return ligne;
83
83
  }
84
84
 
85
- // Run as `node prefixe-des-tickets.mjs <racine>`, the shell scripts (ticket.sh, nuit.sh) read the
85
+ // Run as `node prefixe-des-tickets.mjs <racine>`, the shell scripts (nuit.sh) read the
86
86
  // prefix by the same function: it prints the prefix, or the message of the refusal with exit 1.
87
87
  if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
88
88
  try {
@@ -0,0 +1,159 @@
1
+ // The difference of the reference files a lot changes, as the review of a snapshot (the snapshots
2
+ // of Jest and insta, the review of the goldens of Chromium) shows the difference of each file:
3
+ // measured by git between the base of the lot and the lot kept (`git diff --numstat`), summarised
4
+ // by name of field for a JSON file, so that the reviewer judges the change of a reference on the
5
+ // tree, not on what the agent declares.
6
+ import { spawnSync } from 'node:child_process';
7
+ import { couvertPar } from './engendres.mjs';
8
+
9
+ // The most fields the text of a difference lists per file, the rest counted.
10
+ const CHAMPS_MAX = 40;
11
+
12
+ const objet = v => v !== null && typeof v === 'object' && !Array.isArray(v);
13
+
14
+ const egales = (a, b) => JSON.stringify(a) === JSON.stringify(b);
15
+
16
+ /**
17
+ * The difference of two JSON texts by name of field: `[{ champ, changees, ajoutees, retirees }]`,
18
+ * the fields whose values changed, were added or removed (an object descended into by its keys, a
19
+ * list by its positions, its extra or missing elements counted under the name of the list), in the
20
+ * order they first appear; an empty list for two equal documents; null when a text is no JSON.
21
+ * @param {string} avant
22
+ * @param {string} apres
23
+ * @returns {{ champ: string, changees: number, ajoutees: number, retirees: number }[] | null}
24
+ */
25
+ export function resumeJson(avant, apres) {
26
+ let a;
27
+ let b;
28
+ try {
29
+ a = JSON.parse(avant);
30
+ b = JSON.parse(apres);
31
+ } catch {
32
+ return null;
33
+ }
34
+ const champs = new Map();
35
+ const compter = (nom, sorte, n = 1) => {
36
+ const c = champs.get(nom) ?? { champ: nom, changees: 0, ajoutees: 0, retirees: 0 };
37
+ c[sorte] += n;
38
+ champs.set(nom, c);
39
+ };
40
+ const descendre = (x, y, nom) => {
41
+ if (Array.isArray(x) && Array.isArray(y)) {
42
+ for (let i = 0; i < Math.min(x.length, y.length); i++) {
43
+ descendre(x[i], y[i], nom);
44
+ }
45
+ if (y.length > x.length) {
46
+ compter(nom, 'ajoutees', y.length - x.length);
47
+ } else if (x.length > y.length) {
48
+ compter(nom, 'retirees', x.length - y.length);
49
+ }
50
+ } else if (objet(x) && objet(y)) {
51
+ for (const k of new Set([...Object.keys(x), ...Object.keys(y)])) {
52
+ if (!(k in y)) {
53
+ compter(k, 'retirees');
54
+ } else if (!(k in x)) {
55
+ compter(k, 'ajoutees');
56
+ } else {
57
+ descendre(x[k], y[k], k);
58
+ }
59
+ }
60
+ } else if (!egales(x, y)) {
61
+ compter(nom, 'changees');
62
+ }
63
+ };
64
+ descendre(a, b, '(racine)');
65
+ return [...champs.values()];
66
+ }
67
+
68
+ const git = (copie, args) =>
69
+ spawnSync('git', ['-C', copie, ...args], { encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 });
70
+
71
+ // The text of <fichier> at <commit>, or null when it is not there.
72
+ const texteA = (copie, commit, fichier) => {
73
+ const r = git(copie, ['show', `${commit}:${fichier}`]);
74
+ return r.status === 0 ? r.stdout : null;
75
+ };
76
+
77
+ /**
78
+ * The reference files the lot changes, measured by git between <base> and <lot> in <copie>: each
79
+ * `{ fichier, ajoutees, retirees, champs }`, its lines added and removed, and for a JSON file
80
+ * present on both sides its fields (`resumeJson`), else null. A reference file is one that a
81
+ * reference of <references> (`lesReferences`: `fichiers` and `entiers`) covers.
82
+ * @param {{ copie: string, references: { fichiers: string[], entiers?: string[] }[], base: string, lot: string }} o
83
+ * @returns {{ fichier: string, ajoutees: number, retirees: number, champs: { champ: string, changees: number, ajoutees: number, retirees: number }[] | null }[]}
84
+ */
85
+ export function differencesDesReferences({ copie, references, base, lot }) {
86
+ const motifs = references.flatMap(r => [...(r.fichiers ?? []), ...(r.entiers ?? [])]);
87
+ if (!motifs.length) {
88
+ return [];
89
+ }
90
+ const r = git(copie, ['diff', '--numstat', '--no-renames', '-z', base, lot]);
91
+ if (r.status !== 0) {
92
+ return [];
93
+ }
94
+ const sorties = [];
95
+ for (const entree of r.stdout.split('\0')) {
96
+ const m = /^(\d+|-)\t(\d+|-)\t(.+)$/s.exec(entree);
97
+ if (!m || !couvertPar(motifs, m[3])) {
98
+ continue;
99
+ }
100
+ const fichier = m[3];
101
+ let champs = null;
102
+ if (fichier.endsWith('.json')) {
103
+ const avant = texteA(copie, base, fichier);
104
+ const apres = texteA(copie, lot, fichier);
105
+ champs = avant !== null && apres !== null ? resumeJson(avant, apres) : null;
106
+ }
107
+ sorties.push({
108
+ fichier,
109
+ ajoutees: m[1] === '-' ? 0 : Number(m[1]),
110
+ retirees: m[2] === '-' ? 0 : Number(m[2]),
111
+ champs,
112
+ });
113
+ }
114
+ return sorties.sort((x, y) => x.fichier.localeCompare(y.fichier));
115
+ }
116
+
117
+ const ligneDuChamp = c =>
118
+ `${c.champ} : ${[
119
+ c.changees && `${c.changees} changées`,
120
+ c.ajoutees && `${c.ajoutees} ajoutées`,
121
+ c.retirees && `${c.retirees} retirées`,
122
+ ]
123
+ .filter(Boolean)
124
+ .join(', ')}`;
125
+
126
+ /**
127
+ * The text the reviewer reads: each changed reference file with its lines (`+a −b`) and, for a
128
+ * JSON file, a line per field; « aucun » when the lot changes no reference.
129
+ * @param {{ fichier: string, ajoutees: number, retirees: number, champs: any[] | null }[]} diffs
130
+ */
131
+ export function texteDesDifferences(diffs) {
132
+ if (!diffs.length) {
133
+ return 'aucun';
134
+ }
135
+ return diffs
136
+ .map(d => {
137
+ const champs = d.champs ?? [];
138
+ const reste = champs.length - CHAMPS_MAX;
139
+ return [
140
+ `- ${d.fichier} (+${d.ajoutees} −${d.retirees})`,
141
+ ...champs.slice(0, CHAMPS_MAX).map(c => ` - ${ligneDuChamp(c)}`),
142
+ ...(reste > 0 ? [` - … ${reste} autres champs`] : []),
143
+ ].join('\n');
144
+ })
145
+ .join('\n');
146
+ }
147
+
148
+ /**
149
+ * The line of the commit message: « Références changées (N) : <fichier> (+a −b), … », empty when
150
+ * the lot changes no reference.
151
+ * @param {{ fichier: string, ajoutees: number, retirees: number }[]} diffs
152
+ */
153
+ export function ligneDesReferences(diffs) {
154
+ return diffs.length
155
+ ? `Références changées (${diffs.length}) : ${diffs
156
+ .map(d => `${d.fichier} (+${d.ajoutees} −${d.retirees})`)
157
+ .join(', ')}`
158
+ : '';
159
+ }
@@ -5,8 +5,6 @@
5
5
  export const MEMOIRE_MIN: number;
6
6
 
7
7
  export const VARIABLE_ESPACEMENT: string;
8
- /** The jeton of the reservation of the machine by the night, which the passes of the night carry. */
9
- export const VARIABLE_JETON: string;
10
8
  /** The gap between two starts when GRILLHOUSE_ESPACEMENT_MS names none, in ms. */
11
9
  export const ESPACEMENT_MS: number;
12
10
  /** The gap between two starts under <env>, in ms. */
@@ -35,10 +33,9 @@ export function refusDeLaPlace(
35
33
  rang: number;
36
34
  ticket?: string | null;
37
35
  raison?: string;
38
- jeton?: string | null;
39
36
  }[];
40
37
  dernier: number;
41
- reservation?: { jeton: string; auteur?: 'nuit' | 'superviseur' } | null;
38
+ reservation?: ReservationDeLaMachine | null;
42
39
  },
43
40
  o: {
44
41
  id: string;
@@ -47,7 +44,6 @@ export function refusDeLaPlace(
47
44
  espacementMs: number;
48
45
  maintenant: number;
49
46
  mesurer: () => MesureDeLaMachine;
50
- jeton?: string | null;
51
47
  }
52
48
  ): string | null;
53
49
 
@@ -90,46 +86,27 @@ export function refusDePart(
90
86
  mesurer: () => MesureDeLaMachine;
91
87
  dediee?: boolean;
92
88
  /** The reservation of the machine read this turn, null without. */
93
- reservation?: { auteur?: 'nuit' | 'superviseur'; jeton: string } | null;
94
- /** The jeton of the night the pass carries (its variable), null without. */
95
- jeton?: string | null;
89
+ reservation?: ReservationDeLaMachine | null;
96
90
  }
97
91
  ): string | null;
98
92
 
99
93
  /** Why a pass waits under the supervisor's closure of the machine. */
100
94
  export const RAISON_DE_LA_FERMETURE: string;
101
- /** Why a pass without the jeton of the night waits under its reservation. */
102
- export const RAISON_DE_LA_NUIT: string;
103
95
 
104
96
  /** A place of a circuit not given by its project's queue for this long is gone, in ms: 10 min. */
105
97
  export const PERIME_MS: number;
106
98
 
107
- /** The reservation of the machine: the night's (absent author) or the supervisor's closure. */
99
+ /** The reservation of the machine: the supervisor's closure, the only one. */
108
100
  export interface ReservationDeLaMachine {
109
- auteur?: 'nuit' | 'superviseur';
110
- jeton: string;
101
+ auteur?: 'superviseur';
111
102
  depuis: number;
112
- /** The night's last beat; the supervisor's closure has none. */
113
- battement?: number;
114
103
  }
115
104
 
116
- /** The phase of a reservation: none without one, waiting, under way (night) or empty (closure). */
105
+ /** The phase of the closure: none without one, waiting (a place is held) or empty. */
117
106
  export function phaseDeLaReservation(etat: {
118
- prises: readonly { id?: string; jeton?: string | null }[];
119
- reservation?: { jeton: string; auteur?: 'nuit' | 'superviseur' } | null;
120
- }): 'attend' | 'en cours' | 'vide' | null;
121
-
122
- /** The phase of the night on the places: none without a reservation or under a closure. */
123
- export function phaseDeLaNuit(etat: {
124
- prises: readonly { id?: string; jeton?: string | null }[];
125
- reservation?: { jeton: string; auteur?: 'nuit' | 'superviseur' } | null;
126
- }): 'attend' | 'en cours' | null;
127
-
128
- /** Whether a reservation's last beat is PERIME_MS old at <maintenant>; a closure never is. */
129
- export function reservationPerimee(
130
- reservation: { battement?: number; auteur?: 'nuit' | 'superviseur' },
131
- maintenant: number
132
- ): boolean;
107
+ prises: readonly object[];
108
+ reservation?: ReservationDeLaMachine | null;
109
+ }): 'attend' | 'vide' | null;
133
110
 
134
111
  /** Why a place waits under the supervisor's closure. */
135
112
  export const RAISON_FERMEE: string;
@@ -10,8 +10,6 @@
10
10
  export const MEMOIRE_MIN = 4 * 1024 ** 3;
11
11
 
12
12
  export const VARIABLE_ESPACEMENT = 'GRILLHOUSE_ESPACEMENT_MS';
13
- /** The jeton of the reservation of the machine by the night, which the passes of the night carry. */
14
- export const VARIABLE_JETON = 'GRILLHOUSE_JETON_DE_LA_NUIT';
15
13
  /** Why a place waits under the closure of the machine by the supervisor (`cordon` of kubectl). */
16
14
  export const RAISON_FERMEE =
17
15
  'machine fermée par le superviseur : la place est donnée à la réouverture';
@@ -81,24 +79,16 @@ export function admission({ coeurs, charge, memoireLibre }) {
81
79
  */
82
80
  export function refusDeLaPlace(
83
81
  etat,
84
- { id, rang, plafond, espacementMs, maintenant, mesurer, jeton = null }
82
+ { id, rang, plafond, espacementMs, maintenant, mesurer }
85
83
  ) {
86
- const reservation = etat.reservation ?? null;
87
- // The supervisor's closure gives no place to anyone, its own jeton included: no pass nor session
88
- // carries it.
89
- if (reservation?.auteur === 'superviseur') {
84
+ // The supervisor's closure, the only reservation of the machine, gives no place to anyone.
85
+ if (etat.reservation) {
90
86
  return RAISON_FERMEE;
91
87
  }
92
- if (reservation && jeton !== reservation.jeton) {
93
- return 'la nuit tient la machine : la place est donnée à la fin des nuits';
94
- }
95
88
  if (etat.prises.length >= plafond) {
96
89
  return `aucune place libre : ${etat.prises.length} prises sur ${plafond}`;
97
90
  }
98
- // Under a reservation, only the waits of the night count for the turn: the others wait for it.
99
- const avant = etat.attentes.find(
100
- a => a.id !== id && a.rang < rang && (!reservation || (a.jeton ?? null) === reservation.jeton)
101
- );
91
+ const avant = etat.attentes.find(a => a.id !== id && a.rang < rang);
102
92
  if (avant) {
103
93
  return `place réservée : ${avant.ticket ?? 'un départ'} est arrivé avant et attend (${avant.raison})`;
104
94
  }
@@ -166,16 +156,13 @@ export function admissionDePart({ part, budget, prises, mesure }) {
166
156
 
167
157
  /** Why a pass waits under the supervisor's closure of the machine. */
168
158
  export const RAISON_DE_LA_FERMETURE = 'machine fermée par le superviseur';
169
- /** Why a pass without the jeton of the night waits under its reservation. */
170
- export const RAISON_DE_LA_NUIT = 'la nuit tient la machine';
171
159
 
172
160
  /**
173
161
  * Why the pass <id> of the rank <rang> does not take its part <part> now on the state <etat>
174
162
  * (`prises`, `attentes`), null when it does: its part does not fit in the <budget>; a wait of a
175
163
  * lower rank, alive, which keeps its turn (the measure of the frame has the lower rank of a
176
164
  * project's, then the order of arrival); the admission at the load and the memory <mesurer> gives
177
- * (read only when the part and the turn pass). The night asks for the whole budget as its part: it
178
- * plays alone. A measure of time (<dediee>) asks for dedicated cores: when they lack, its refusal
165
+ * (read only when the part and the turn pass). A measure of time (<dediee>) asks for dedicated cores: when they lack, its refusal
179
166
  * says « cœurs dédiés » and names the passes that hold them; a pass that comes after it waits
180
167
  * behind it, its rank reserved, and one measure plays at a time, whatever its part would fit in the free cores; once it plays, an
181
168
  * ordinary pass whose part fits in the cores left goes on.
@@ -188,17 +175,11 @@ export const RAISON_DE_LA_NUIT = 'la nuit tient la machine';
188
175
  */
189
176
  export function refusDePart(
190
177
  etat,
191
- { id, rang, part, budget, mesurer, dediee = false, reservation = null, jeton = null }
178
+ { id, rang, part, budget, mesurer, dediee = false, reservation = null }
192
179
  ) {
193
- // A closed machine gives no new work (`cordon` of kubectl): the supervisor's closure refuses
194
- // every pass, whatever its jeton; the night's reservation refuses the pass without its jeton.
180
+ // A closed machine gives no new work (`cordon` of kubectl): the supervisor's closure refuses every pass.
195
181
  if (reservation) {
196
- if (reservation.auteur === 'superviseur') {
197
- return RAISON_DE_LA_FERMETURE;
198
- }
199
- if (jeton !== reservation.jeton) {
200
- return RAISON_DE_LA_NUIT;
201
- }
182
+ return RAISON_DE_LA_FERMETURE;
202
183
  }
203
184
  const prises = etat.prises.filter(p => p.id !== id);
204
185
  // Two measures of time never play side by side: each would be the load the other is judged on.
@@ -226,50 +207,19 @@ export function refusDePart(
226
207
  export const PERIME_MS = 10 * 60_000;
227
208
 
228
209
  /**
229
- * The phase of a reservation of the machine, whoever its author: null without a reservation;
230
- * `'attend'` while a place is held that is not one of the night's passes (the stages under way
231
- * finish); then `'en cours'` for the night, `'vide'` for the supervisor's closure (it holds no
232
- * place itself: every place held waits to be given back).
233
- * @param {{ prises: { jeton?: string | null }[],
234
- * reservation?: { jeton: string, auteur?: 'nuit' | 'superviseur' } | null }} etat
235
- * @returns {'attend' | 'en cours' | 'vide' | null}
210
+ * The phase of the supervisor's closure of the machine: null without one; `'attend'` while a place
211
+ * is held (the stages under way finish); then `'vide'` (it holds no place itself: every place held
212
+ * waits to be given back).
213
+ * @param {{ prises: object[], reservation?: object | null }} etat
214
+ * @returns {'attend' | 'vide' | null}
236
215
  */
237
216
  export function phaseDeLaReservation({ prises, reservation = null }) {
238
217
  if (!reservation) {
239
218
  return null;
240
219
  }
241
- if (reservation.auteur === 'superviseur') {
242
- return prises.length > 0 ? 'attend' : 'vide';
243
- }
244
- return prises.some(p => (p.jeton ?? null) !== reservation.jeton) ? 'attend' : 'en cours';
220
+ return prises.length > 0 ? 'attend' : 'vide';
245
221
  }
246
222
 
247
- /**
248
- * The phase of the night on a state of the places: that of its reservation, null without one or
249
- * when the reservation is the supervisor's closure, which is not a night.
250
- * @param {{ prises: { jeton?: string | null }[],
251
- * reservation?: { jeton: string, auteur?: 'nuit' | 'superviseur' } | null }} etat
252
- * @returns {'attend' | 'en cours' | null}
253
- */
254
- export function phaseDeLaNuit(etat) {
255
- if (etat.reservation?.auteur === 'superviseur') {
256
- return null;
257
- }
258
- const phase = phaseDeLaReservation(etat);
259
- return phase === 'vide' ? null : phase;
260
- }
261
-
262
- /**
263
- * Whether a reservation of the machine is out of date at <maintenant>: its last beat, the one the
264
- * workflow of the nights renews, is PERIME_MS old, as a place of a circuit is. The supervisor's
265
- * closure has no beat and never goes out of date, as `cordon` has no delay.
266
- * @param {{ battement?: number, auteur?: 'nuit' | 'superviseur' }} reservation
267
- * @param {number} maintenant
268
- * @returns {boolean}
269
- */
270
- export const reservationPerimee = (reservation, maintenant) =>
271
- reservation.auteur !== 'superviseur' && maintenant - (reservation.battement ?? 0) >= PERIME_MS;
272
-
273
223
  /**
274
224
  * The places of the circuits of the machine once a demand comes, as Buildkite bounds its pipelines
275
225
  * in one fleet of agents. The queue of the project <racine> gives its circuits active <vivants>
@@ -0,0 +1,112 @@
1
+ // The fallback of the night of Grillhouse: the night of PC3 (scripts/nuit.sh) reads, by `gh`, the jobs
2
+ // of the day's Nuit flow, and decides tranche by tranche what PC3 plays in place of PC2, as a queue
3
+ // of agents falls back on another capacity (Buildkite) when no agent takes the job in time.
4
+ //
5
+ // - A tranche finished on PC2, green or red, is never replayed.
6
+ // - A tranche whose job has not started 60 minutes after the hour of the flow is cancelled and
7
+ // played on PC3, on its part; a tranche started then interrupted (cancelled, a runner lost, never
8
+ // started) counts as not played and plays whole again.
9
+ // - A tranche that runs, or waits for less than 60 minutes, stays at PC2.
10
+ // - The statement says which tranches played where: `pc2` the finished ones, `pc3` the replayed.
11
+ //
12
+ // node repli-de-la-nuit.mjs <dépôt owner/nom> <nombre de tranches> [<identifiant du flux>] the
13
+ // decision as JSON, the run cancelled (`gh run cancel`) when a tranche waited too long; a run that
14
+ // waits for its group of concurrence, with no job yet, counts every tranche as not started
15
+ import { spawnSync } from 'node:child_process';
16
+ import { fileURLToPath } from 'node:url';
17
+ import path from 'node:path';
18
+
19
+ /** The minutes a tranche may wait for its job to start before PC3 plays it. */
20
+ export const ATTENTE_MAX_MINUTES = 60;
21
+
22
+ const TRANCHE = /^tranches\b.*?(\d+)\)\s*$/;
23
+ // The conclusions of a job that started or was cancelled without finishing its tranche.
24
+ const INTERROMPUES = new Set(['cancelled', 'skipped', 'startup_failure']);
25
+
26
+ /**
27
+ * The decision on the tranches of a Nuit flow.
28
+ * @param {{ jobs: { name: string, status: string, conclusion: string | null, startedAt: string | null }[], heureDuFlux: string, maintenant: string }} o
29
+ * `jobs` the jobs of the run as `gh run view --json jobs` gives them, `heureDuFlux` the hour the
30
+ * flow was created, `maintenant` the present hour, both ISO.
31
+ * @returns {{ aRejouer: number[], aAnnuler: number[], enAttente: number[], pc2: number[], pc3: number[] }}
32
+ */
33
+ export function choisirLeRepli({ jobs, heureDuFlux, maintenant }) {
34
+ const attente = Date.parse(maintenant) - Date.parse(heureDuFlux);
35
+ const d = { aRejouer: [], aAnnuler: [], enAttente: [], enCours: [], rouges: [], pc2: [], pc3: [] };
36
+ const tranches = jobs
37
+ .map(j => ({ j, n: Number(TRANCHE.exec(j.name)?.[1]) }))
38
+ .filter(({ n }) => Number.isInteger(n) && n > 0)
39
+ .sort((a, b) => a.n - b.n);
40
+ for (const { j, n } of tranches) {
41
+ if (j.status === 'completed') {
42
+ if (INTERROMPUES.has(j.conclusion ?? '')) {
43
+ d.aRejouer.push(n);
44
+ } else {
45
+ d.pc2.push(n);
46
+ if (j.conclusion !== 'success') {
47
+ d.rouges.push(n);
48
+ }
49
+ }
50
+ } else if (j.startedAt || j.status === 'in_progress') {
51
+ d.pc2.push(n);
52
+ d.enCours.push(n);
53
+ } else if (attente >= ATTENTE_MAX_MINUTES * 60_000) {
54
+ d.aAnnuler.push(n);
55
+ d.aRejouer.push(n);
56
+ } else {
57
+ d.enAttente.push(n);
58
+ }
59
+ }
60
+ d.pc3 = [...d.aRejouer];
61
+ return d;
62
+ }
63
+
64
+ function gh(args) {
65
+ const r = spawnSync('gh', args, { encoding: 'utf8' });
66
+ if (r.status !== 0) {
67
+ throw new Error(`gh ${args.join(' ')} : ${r.stderr || r.error?.message || r.status}`);
68
+ }
69
+ return r.stdout;
70
+ }
71
+
72
+ if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
73
+ const [depot, tranches, identifiant] = process.argv.slice(2);
74
+ const vide = { aRejouer: [], aAnnuler: [], enAttente: [], enCours: [], rouges: [], pc2: [], pc3: [] };
75
+ try {
76
+ const id =
77
+ identifiant ||
78
+ JSON.parse(
79
+ gh(['run', 'list', '-R', depot, '--workflow', 'nuit.yml', '--limit', '1', '--json', 'databaseId'])
80
+ )[0]?.databaseId;
81
+ if (!id) {
82
+ process.stdout.write(`${JSON.stringify(vide)}\n`);
83
+ } else {
84
+ const run = JSON.parse(
85
+ gh(['run', 'view', String(id), '-R', depot, '--json', 'jobs,createdAt,status'])
86
+ );
87
+ // A run that waits for the group of concurrence has no job yet: each of its tranches is
88
+ // a job not started.
89
+ const jobs =
90
+ run.jobs.length === 0 && run.status !== 'completed'
91
+ ? Array.from({ length: Number(tranches) || 0 }, (_, i) => ({
92
+ name: `tranches (26.x, ${i + 1})`,
93
+ status: 'queued',
94
+ conclusion: null,
95
+ startedAt: null,
96
+ }))
97
+ : run.jobs;
98
+ const d = choisirLeRepli({
99
+ jobs,
100
+ heureDuFlux: run.createdAt,
101
+ maintenant: new Date().toISOString(),
102
+ });
103
+ if (d.aAnnuler.length > 0) {
104
+ gh(['run', 'cancel', String(id), '-R', depot]);
105
+ }
106
+ process.stdout.write(`${JSON.stringify({ ...d, flux: id })}\n`);
107
+ }
108
+ } catch (e) {
109
+ process.stderr.write(`⛔ repli de la nuit : ${e.message}\n`);
110
+ process.exitCode = 1;
111
+ }
112
+ }
@@ -6,8 +6,8 @@ export const SANS_ISSUE: Set<string>;
6
6
  export function lesReponses(ticket: string, statut: string, ecrit: boolean): string;
7
7
  /** The hour `bd update --defer` receives for `--reporter <heure>`, and the phrase of its texts. */
8
8
  export function heureDuReport(heure: string, maintenant: Date): { defer: string; quand: string };
9
- /** The stops of the testwriter that `--mecanique` answers. */
10
- export const ARRETS_DU_TESTWRITER: string[];
9
+ /** The stops `--mecanique` answers, by the step they stand at: the testwriter's, the proof's. */
10
+ export const ARRETS_DE_LA_BASCULE: Record<string, string[]>;
11
11
  /** The sort of a ticket, as the plan says it (scripts/resultats.mjs `sorteDuPlan`). */
12
12
  export interface SorteDuTicket {
13
13
  genre: string;