@roomi-fields/grillhouse 0.29.0 → 0.31.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.
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +769 -0
- package/agents/developpeur.md +0 -1
- package/agents/explorateur.md +0 -1
- package/agents/questionneur.md +0 -1
- package/agents/testwriter.md +0 -1
- package/bin/grillhouse.mjs +79 -18
- package/cadre/templates/projet/.github/workflows/ci.yml +2 -13
- package/cadre/templates/projet/CLAUDE.md +5 -1
- package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
- package/cadre/templates/projet/package.json +2 -2
- package/charte.md +24 -0
- package/dist/temporal/acte.d.ts +24 -0
- package/dist/temporal/acte.js +139 -0
- package/dist/temporal/acte.js.map +1 -0
- package/dist/temporal/attributs.d.ts +6 -0
- package/dist/temporal/attributs.js +15 -0
- package/dist/temporal/attributs.js.map +1 -0
- package/dist/temporal/circuit/activites.d.ts +13 -0
- package/dist/temporal/circuit/activites.js +33 -0
- package/dist/temporal/circuit/activites.js.map +1 -0
- package/dist/temporal/circuit/client.d.ts +72 -0
- package/dist/temporal/circuit/client.js +247 -0
- package/dist/temporal/circuit/client.js.map +1 -0
- package/dist/temporal/circuit/commande.d.ts +2 -0
- package/dist/temporal/circuit/commande.js +238 -0
- package/dist/temporal/circuit/commande.js.map +1 -0
- package/dist/temporal/circuit/contrat.d.ts +305 -0
- package/dist/temporal/circuit/contrat.js +30 -0
- package/dist/temporal/circuit/contrat.js.map +1 -0
- package/dist/temporal/circuit/deroule.d.ts +3 -0
- package/dist/temporal/circuit/deroule.js +540 -0
- package/dist/temporal/circuit/deroule.js.map +1 -0
- package/dist/temporal/client.d.ts +47 -0
- package/dist/temporal/client.js +69 -0
- package/dist/temporal/client.js.map +1 -0
- package/dist/temporal/commande.d.ts +2 -0
- package/dist/temporal/commande.js +94 -0
- package/dist/temporal/commande.js.map +1 -0
- package/dist/temporal/deroules.d.ts +5 -0
- package/dist/temporal/deroules.js +10 -0
- package/dist/temporal/deroules.js.map +1 -0
- package/dist/temporal/etat.d.ts +33 -0
- package/dist/temporal/etat.js +59 -0
- package/dist/temporal/etat.js.map +1 -0
- package/dist/temporal/file/activites.d.ts +10 -0
- package/dist/temporal/file/activites.js +25 -0
- package/dist/temporal/file/activites.js.map +1 -0
- package/dist/temporal/file/client.d.ts +4 -0
- package/dist/temporal/file/client.js +6 -0
- package/dist/temporal/file/client.js.map +1 -0
- package/dist/temporal/file/contrat.d.ts +158 -0
- package/dist/temporal/file/contrat.js +14 -0
- package/dist/temporal/file/contrat.js.map +1 -0
- package/dist/temporal/file/deroule.d.ts +15 -0
- package/dist/temporal/file/deroule.js +235 -0
- package/dist/temporal/file/deroule.js.map +1 -0
- package/dist/temporal/installation.d.ts +120 -0
- package/dist/temporal/installation.js +386 -0
- package/dist/temporal/installation.js.map +1 -0
- package/dist/temporal/places/activites.d.ts +8 -0
- package/dist/temporal/places/activites.js +13 -0
- package/dist/temporal/places/activites.js.map +1 -0
- package/dist/temporal/places/client.d.ts +28 -0
- package/dist/temporal/places/client.js +64 -0
- package/dist/temporal/places/client.js.map +1 -0
- package/dist/temporal/places/contrat.d.ts +106 -0
- package/dist/temporal/places/contrat.js +21 -0
- package/dist/temporal/places/contrat.js.map +1 -0
- package/dist/temporal/places/deroule.d.ts +3 -0
- package/dist/temporal/places/deroule.js +198 -0
- package/dist/temporal/places/deroule.js.map +1 -0
- package/dist/temporal/sonde/activites.d.ts +6 -0
- package/dist/temporal/sonde/activites.js +52 -0
- package/dist/temporal/sonde/activites.js.map +1 -0
- package/dist/temporal/sonde/contrat.d.ts +35 -0
- package/dist/temporal/sonde/contrat.js +10 -0
- package/dist/temporal/sonde/contrat.js.map +1 -0
- package/dist/temporal/sonde/deroule.d.ts +3 -0
- package/dist/temporal/sonde/deroule.js +39 -0
- package/dist/temporal/sonde/deroule.js.map +1 -0
- package/dist/temporal/tickets/activites.d.ts +7 -0
- package/dist/temporal/tickets/activites.js +81 -0
- package/dist/temporal/tickets/activites.js.map +1 -0
- package/dist/temporal/tickets/client.d.ts +10 -0
- package/dist/temporal/tickets/client.js +31 -0
- package/dist/temporal/tickets/client.js.map +1 -0
- package/dist/temporal/tickets/contrat.d.ts +56 -0
- package/dist/temporal/tickets/contrat.js +13 -0
- package/dist/temporal/tickets/contrat.js.map +1 -0
- package/dist/temporal/tickets/deroule.d.ts +3 -0
- package/dist/temporal/tickets/deroule.js +94 -0
- package/dist/temporal/tickets/deroule.js.map +1 -0
- package/dist/temporal/travailleur.d.ts +2 -0
- package/dist/temporal/travailleur.js +69 -0
- package/dist/temporal/travailleur.js.map +1 -0
- package/docs/ARCHITECTURE.md +646 -87
- package/docs/CADRE.md +27 -0
- package/docs/INTERFACE.md +139 -42
- package/hooks/crochet.mjs +19 -2
- package/hooks/hooks.json +11 -0
- package/package.json +16 -4
- package/scripts/activites.mjs +2255 -0
- package/scripts/aiguillage.d.mts +37 -0
- package/scripts/aiguillage.mjs +40 -14
- package/scripts/avancement.mjs +155 -26
- package/scripts/bilan.mjs +137 -43
- package/scripts/cadre.mjs +16 -4
- package/scripts/circuit.mjs +993 -4075
- package/scripts/circuits-cles.d.mts +4 -0
- package/scripts/circuits-cles.mjs +21 -0
- package/scripts/circuits-du-serveur.mjs +105 -0
- package/scripts/codes-de-sortie.mjs +9 -0
- package/scripts/commandes-composees.mjs +45 -41
- package/scripts/commandes-du-path.d.mts +7 -0
- package/scripts/commandes-du-path.mjs +25 -0
- package/scripts/composants-affectes.mjs +64 -21
- package/scripts/composition-des-langages.mjs +18 -12
- package/scripts/conformite.mjs +56 -28
- package/scripts/copies-finies.mjs +52 -47
- package/scripts/depart-du-ticket.d.mts +53 -0
- package/scripts/depart-du-ticket.mjs +124 -0
- package/scripts/dependances-internes.mjs +121 -0
- package/scripts/dernier-vert.mjs +61 -34
- package/scripts/dette.mjs +32 -11
- package/scripts/donnees-cles.mjs +244 -0
- package/scripts/droits.mjs +51 -16
- package/scripts/effets.mjs +352 -0
- package/scripts/empreinte-d-etape.mjs +17 -0
- package/scripts/engendres.mjs +15 -5
- package/scripts/enveloppe/enveloppe.mjs +259 -55
- package/scripts/enveloppe/lancer.sh +14 -18
- package/scripts/enveloppe/paquets-du-plan.mjs +2 -2
- package/scripts/enveloppe/travail-de-la-copie.mjs +41 -13
- package/scripts/etapes.mjs +5 -2
- package/scripts/faits-du-circuit.mjs +493 -0
- package/scripts/file-des-tickets.d.mts +21 -0
- package/scripts/file-des-tickets.mjs +58 -0
- package/scripts/flux-des-paquets.mjs +201 -0
- package/scripts/gardes-du-cadre.mjs +21 -5
- package/scripts/init.mjs +11 -4
- package/scripts/integration/file.mjs +544 -434
- package/scripts/integration/integrer.mjs +87 -43
- package/scripts/integration/rejeu.mjs +45 -13
- package/scripts/jointure.d.ts +151 -28
- package/scripts/langages/cargo/commandes.mjs +383 -124
- package/scripts/langages/cargo/composants.mjs +154 -42
- package/scripts/langages/cargo/exemples.mjs +12 -21
- package/scripts/langages/cargo/index.mjs +22 -8
- package/scripts/langages/cargo/sccache.mjs +8 -14
- package/scripts/langages/cargo/tests-de-head.mjs +25 -9
- package/scripts/langages/python/commandes.mjs +218 -100
- package/scripts/langages/python/composants.mjs +53 -21
- package/scripts/langages/python/exemples.mjs +6 -16
- package/scripts/langages/python/index.mjs +28 -8
- package/scripts/langages/python/lot.mjs +1 -36
- package/scripts/langages/typescript/chemins-des-tests.mjs +6 -2
- package/scripts/langages/typescript/composants.mjs +9 -3
- package/scripts/langages/typescript/consommateurs-arbitres.mjs +40 -14
- package/scripts/langages/typescript/consommateurs.mjs +39 -14
- package/scripts/langages/typescript/construire.mjs +6 -163
- package/scripts/langages/typescript/elements-du-lot.mjs +36 -12
- package/scripts/langages/typescript/exemples.mjs +3 -11
- package/scripts/langages/typescript/frontieres.mjs +66 -22
- package/scripts/langages/typescript/index-interfaces.mjs +36 -13
- package/scripts/langages/typescript/index.mjs +50 -61
- package/scripts/langages/typescript/interfaces-contre-code.mjs +113 -45
- package/scripts/langages/typescript/lecteurs.mjs +36 -11
- package/scripts/langages/typescript/migrations/0.23.0-config-vitest.mjs +15 -5
- package/scripts/langages/typescript/migrations/0.25.0-chemins-des-tests.mjs +6 -2
- package/scripts/langages/typescript/migrations/0.25.0-tailles-des-tests.mjs +6 -2
- package/scripts/langages/typescript/migrations/0.30.0-prefixe-des-tickets.mjs +63 -0
- package/scripts/langages/typescript/migrations/0.30.0-tailles-des-outils-lourds.mjs +33 -0
- package/scripts/langages/typescript/migrations/0.30.0-titres-nommant-un-ticket.mjs +40 -0
- package/scripts/langages/typescript/mise-a-jour.mjs +1 -2
- package/scripts/langages/typescript/parcours.mjs +12 -4
- package/scripts/langages/typescript/regle-des-tests.mjs +9 -3
- package/scripts/langages/typescript/resumes.mjs +9 -3
- package/scripts/langages/typescript/tailles-des-tests.mjs +93 -20
- package/scripts/langages/typescript/tests-de-nuit.mjs +15 -10
- package/scripts/langages/typescript/tests.mjs +40 -15
- package/scripts/langages/typescript/titres-de-tests.mjs +320 -0
- package/scripts/langages/typescript/turbo-des-paquets.mjs +327 -81
- package/scripts/langages/typescript/verdict.mjs +4 -2
- package/scripts/langages/typescript/verifier.mjs +58 -20
- package/scripts/langages/typescript/vitest-config/avancement.reporter.mjs +15 -5
- package/scripts/langages/typescript/vitest-config/base.mjs +29 -3
- package/scripts/langages/typescript/vitest-config/bornes.mjs +13 -0
- package/scripts/langages/typescript/vitest-config/changements.mjs +21 -8
- package/scripts/langages/typescript/vitest-config/cibles.mjs +36 -14
- package/scripts/langages/typescript/vitest-config/delais.mjs +60 -0
- package/scripts/langages/typescript/vitest-config/delais.setup.mjs +11 -0
- package/scripts/langages/typescript/vitest-config/duree.classement.mjs +108 -0
- package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +56 -59
- package/scripts/langages/typescript/vitest-config/lances.mjs +83 -27
- package/scripts/langages/typescript/vitest-config/machine.setup.mjs +10 -0
- package/scripts/langages/typescript/vitest-config/resultats.mjs +3 -1
- package/scripts/langages/typescript/vitest.nuit.config.mjs +4 -0
- package/scripts/lint-des-scripts.mjs +58 -0
- package/scripts/mesure/base-de-passe.mjs +117 -25
- package/scripts/mesure/pression.mjs +12 -6
- package/scripts/mesure-de-la-machine.d.mts +21 -0
- package/scripts/mesure-de-la-machine.mjs +76 -0
- package/scripts/migrations/0.23.0-charte-importee.mjs +6 -2
- package/scripts/migrations/0.23.0-crochets-de-seance.mjs +25 -8
- package/scripts/migrations/0.23.0-marche-du-projet.mjs +18 -6
- package/scripts/migrations/0.23.2-copies-du-cadre.mjs +56 -18
- package/scripts/migrations/0.24.12-tri-des-decouvertes.mjs +6 -2
- package/scripts/migrations/0.25.0-script-des-tests.mjs +15 -5
- package/scripts/migrations/0.30.0-ci-appelle-la-verification.mjs +124 -0
- package/scripts/migrations/0.31.0-paquets-dans-le-graphe.mjs +81 -0
- package/scripts/migrations.mjs +5 -0
- package/scripts/nuit.sh +25 -3
- package/scripts/outil.mjs +3 -1
- package/scripts/outils-cles.d.mts +24 -0
- package/scripts/outils-cles.mjs +18 -8
- package/scripts/paquet-npm.mjs +157 -0
- package/scripts/paquet.mjs +73 -4
- package/scripts/paquets.mjs +46 -10
- package/scripts/passe-de-la-machine.mjs +71 -0
- package/scripts/places-de-la-machine.mjs +414 -0
- package/scripts/places-du-serveur.mjs +170 -0
- package/scripts/prefixe-des-tickets.mjs +68 -0
- package/scripts/preparation.mjs +25 -8
- package/scripts/registre.mjs +9 -4
- package/scripts/regles-des-places.d.mts +36 -0
- package/scripts/regles-des-places.mjs +70 -0
- package/scripts/reponses-du-circuit.d.mts +6 -0
- package/scripts/reponses-du-circuit.mjs +28 -0
- package/scripts/reprise.mjs +66 -0
- package/scripts/resultats.mjs +112 -46
- package/scripts/retirer-les-copies-finies.mjs +25 -0
- package/scripts/sans-reponse.d.mts +4 -0
- package/scripts/sans-reponse.mjs +13 -0
- package/scripts/seances.mjs +936 -0
- package/scripts/services-du-noyau.mjs +27 -8
- package/scripts/session-start.sh +2 -2
- package/scripts/sortie.mjs +3 -3
- package/scripts/sous-commandes.mjs +41 -10
- package/scripts/style-a-l-ecriture.mjs +260 -0
- package/scripts/superviseur.mjs +122 -111
- package/scripts/tableau.mjs +180 -117
- package/scripts/taches-du-graphe.mjs +348 -0
- package/scripts/ticket-du-circuit.mjs +216 -0
- package/scripts/transitions.d.mts +148 -0
- package/scripts/transitions.mjs +1018 -0
- package/scripts/verrou-de-fichier.mjs +8 -4
- package/scripts/verrou-de-machine.mjs +150 -51
- package/scripts/verrous/commande.mjs +50 -17
- package/scripts/verrous/ticket-du-sous-agent.mjs +9 -3
- package/scripts/verrous/verrou.mjs +42 -14
- package/skills/explorateur/SKILL.md +9 -2
- package/skills/grill/SKILL.md +1 -1
- package/skills/mesure/SKILL.md +3 -0
- package/skills/pitmaster/SKILL.md +17 -18
- package/skills/pitmaster/references/consigne-agent.md +5 -1
- package/skills/release/SKILL.md +3 -3
- package/skills/relecteur/SKILL.md +5 -3
- package/skills/testwriter/SKILL.md +49 -31
- package/scripts/demon.mjs +0 -251
- package/scripts/integration/file-attente.mjs +0 -61
- package/scripts/langages/cargo/touches.mjs +0 -93
- package/scripts/langages/typescript/script-des-tests.mjs +0 -6
package/scripts/paquet.mjs
CHANGED
|
@@ -25,6 +25,11 @@
|
|
|
25
25
|
// and its language written in. Each file absent is written, a file present stays; the manifest
|
|
26
26
|
// of the workspace receives the entry. The command commits nothing: the second and the third
|
|
27
27
|
// times enter one commit, after a green verification.
|
|
28
|
+
// - The entry into the Turborepo graph: a crate or a Python project, whose manifest is not a
|
|
29
|
+
// package.json, receives one beside it (./paquet-npm.mjs: the `name` of its manifest, `private`,
|
|
30
|
+
// the scripts build, test:unit and typecheck that call the module's commands on its path) and
|
|
31
|
+
// its path in the `workspaces` of the root when no pattern selects it (after the `!` pattern
|
|
32
|
+
// that excludes it). A package.json already there is never rewritten: a different name is refused.
|
|
28
33
|
// - The tools of the language, as `nx add` installs them before the first generator: the share
|
|
29
34
|
// of the update of each declared language (`mettreAJour` of ./grillhouse-maj.mjs: its tools at
|
|
30
35
|
// its template's versions, its scripts, its files, `turbo.json` for typescript), then `npm
|
|
@@ -48,6 +53,13 @@ import {
|
|
|
48
53
|
regenerer,
|
|
49
54
|
} from './grillhouse-maj.mjs';
|
|
50
55
|
import { LANGAGES, langage } from './langages.mjs';
|
|
56
|
+
import {
|
|
57
|
+
inscrireAuxEspaces,
|
|
58
|
+
nomDuManifeste,
|
|
59
|
+
packageJsonDuPaquet,
|
|
60
|
+
sansPackageJson,
|
|
61
|
+
} from './paquet-npm.mjs';
|
|
62
|
+
import { paquets } from './paquets.mjs';
|
|
51
63
|
import { hors } from './sources.mjs';
|
|
52
64
|
import {
|
|
53
65
|
ARCHITECTURE,
|
|
@@ -122,6 +134,58 @@ function existants(racine, dossier) {
|
|
|
122
134
|
.sort();
|
|
123
135
|
}
|
|
124
136
|
|
|
137
|
+
// The package.json of the package at <rel> when its language has none of its own (a crate, a
|
|
138
|
+
// project of Python; ./paquet-npm.mjs): `{ fichiers, espace }`, its text when it lacks, and the
|
|
139
|
+
// root package.json with the entry of <rel> in its `workspaces` (null when its patterns select
|
|
140
|
+
// it). A package.json present is never rewritten: refused, by its name, when its `name` is not the
|
|
141
|
+
// manifest's or is already another package's of the workspaces. Nothing for the other languages.
|
|
142
|
+
/**
|
|
143
|
+
* @param {string} racine
|
|
144
|
+
* @param {string} rel
|
|
145
|
+
* @param {string} langage
|
|
146
|
+
* @param {{ manifeste: string }} m
|
|
147
|
+
* @param {{ fichiers: Record<string, string> }} squelette
|
|
148
|
+
* @returns {{ fichiers: Record<string, string>, espace: { fichier: string, texte: string } | null }}
|
|
149
|
+
*/
|
|
150
|
+
function packageJsonDuPaquetNonJs(racine, rel, langage, m, squelette) {
|
|
151
|
+
if (!sansPackageJson().includes(langage)) {
|
|
152
|
+
return { fichiers: {}, espace: null };
|
|
153
|
+
}
|
|
154
|
+
const manifeste = squelette.fichiers[`${rel}/${m.manifeste}`];
|
|
155
|
+
const nom = manifeste === undefined ? null : nomDuManifeste(langage, manifeste);
|
|
156
|
+
if (nom === null) {
|
|
157
|
+
throw new Refus(`${rel}/${m.manifeste} : le squelette du module n'écrit aucun nom de paquet.`);
|
|
158
|
+
}
|
|
159
|
+
const f = `${rel}/package.json`;
|
|
160
|
+
const abs = path.join(racine, f);
|
|
161
|
+
/** @type {Record<string, string>} */
|
|
162
|
+
const fichiers = {};
|
|
163
|
+
if (existsSync(abs)) {
|
|
164
|
+
let present;
|
|
165
|
+
try {
|
|
166
|
+
present = JSON.parse(readFileSync(abs, 'utf8')).name;
|
|
167
|
+
} catch (e) {
|
|
168
|
+
throw new Refus(`${f} : ${e.message} ; la commande ne réécrit pas un package.json.`);
|
|
169
|
+
}
|
|
170
|
+
if (present !== nom) {
|
|
171
|
+
throw new Refus(
|
|
172
|
+
`${f} : son nom est ${JSON.stringify(present)}, celui de ${m.manifeste} est ${JSON.stringify(nom)} ; la commande ne réécrit pas un package.json, le nom s'accorde au manifeste.`
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
fichiers[f] = packageJsonDuPaquet(nom, rel);
|
|
177
|
+
}
|
|
178
|
+
const autre = paquets(racine).find(p => p.pkg.name === nom && p.dossier !== rel);
|
|
179
|
+
if (autre) {
|
|
180
|
+
throw new Refus(
|
|
181
|
+
`${f} : le nom ${JSON.stringify(nom)} est déjà celui de ${autre.dossier}/package.json, un paquet des workspaces ; un nom ne désigne qu'un paquet.`
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
const fr = path.join(racine, 'package.json');
|
|
185
|
+
const texte = existsSync(fr) ? inscrireAuxEspaces(readFileSync(fr, 'utf8'), rel) : null;
|
|
186
|
+
return { fichiers, espace: texte === null ? null : { fichier: 'package.json', texte } };
|
|
187
|
+
}
|
|
188
|
+
|
|
125
189
|
/**
|
|
126
190
|
* The plan of the package at <chemin> of the project at <racine>, nothing written: `{ chemin,
|
|
127
191
|
* langage, fichiers, espace, verrouiller }`, `fichiers` the skeleton of its language and its
|
|
@@ -171,7 +235,9 @@ export function planDuPaquet(racine, chemin, { source = CADRE } = {}) {
|
|
|
171
235
|
} catch (e) {
|
|
172
236
|
throw new Refus(e.message);
|
|
173
237
|
}
|
|
238
|
+
const npm = packageJsonDuPaquetNonJs(racine, rel, l.langage, m, s);
|
|
174
239
|
const nom = path.posix.basename(rel);
|
|
240
|
+
/** @type {Record<string, string>} */
|
|
175
241
|
const documents = Object.fromEntries(
|
|
176
242
|
DOCUMENTS.map(d => [
|
|
177
243
|
`${rel}/${d}`,
|
|
@@ -183,8 +249,9 @@ export function planDuPaquet(racine, chemin, { source = CADRE } = {}) {
|
|
|
183
249
|
return {
|
|
184
250
|
chemin: rel,
|
|
185
251
|
langage: m,
|
|
186
|
-
fichiers: { ...s.fichiers, ...documents },
|
|
252
|
+
fichiers: { ...s.fichiers, ...npm.fichiers, ...documents },
|
|
187
253
|
espace: s.espace,
|
|
254
|
+
espaceNpm: npm.espace,
|
|
188
255
|
verrouiller: s.verrouiller,
|
|
189
256
|
};
|
|
190
257
|
}
|
|
@@ -206,9 +273,11 @@ export function ecrireLePaquet(racine, plan) {
|
|
|
206
273
|
writeFileSync(abs, texte);
|
|
207
274
|
ecrits.push(f);
|
|
208
275
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
276
|
+
for (const espace of [plan.espace, plan.espaceNpm]) {
|
|
277
|
+
if (espace) {
|
|
278
|
+
writeFileSync(path.join(racine, espace.fichier), espace.texte);
|
|
279
|
+
ecrits.push(espace.fichier);
|
|
280
|
+
}
|
|
212
281
|
}
|
|
213
282
|
return ecrits;
|
|
214
283
|
}
|
package/scripts/paquets.mjs
CHANGED
|
@@ -32,11 +32,15 @@ const HORS_CADRE = 'docs/agents/hors-cadre.txt';
|
|
|
32
32
|
// The names listed in <racine>'s `docs/agents/hors-cadre.txt`: a Set, empty without the file.
|
|
33
33
|
export function horsCadre(racine) {
|
|
34
34
|
const liste = path.join(racine, HORS_CADRE);
|
|
35
|
-
if (!existsSync(liste))
|
|
35
|
+
if (!existsSync(liste)) {
|
|
36
|
+
return new Set();
|
|
37
|
+
}
|
|
36
38
|
const noms = new Set();
|
|
37
39
|
for (const ligne of readFileSync(liste, 'utf8').split('\n')) {
|
|
38
40
|
const mot = ligne.trim().split(/\s+/)[0];
|
|
39
|
-
if (mot && !mot.startsWith('#'))
|
|
41
|
+
if (mot && !mot.startsWith('#')) {
|
|
42
|
+
noms.add(mot);
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
45
|
return noms;
|
|
42
46
|
}
|
|
@@ -65,14 +69,19 @@ const lireJson = f => {
|
|
|
65
69
|
}
|
|
66
70
|
};
|
|
67
71
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
/**
|
|
73
|
+
* The patterns of the `workspaces` of the root `package.json` <p> (an array, or its `packages` key):
|
|
74
|
+
* `{ declares, motifs, nies }`, the patterns as written, those that select, and those that take out
|
|
75
|
+
* what the others select, none put back by a later pattern.
|
|
76
|
+
* @param {Record<string, any> | null} p
|
|
77
|
+
*/
|
|
78
|
+
export function motifsDesEspaces(p) {
|
|
79
|
+
const declares = (
|
|
80
|
+
Array.isArray(p?.workspaces) ? p.workspaces : (p?.workspaces?.packages ?? [])
|
|
81
|
+
).map(String);
|
|
73
82
|
const motifs = [];
|
|
74
83
|
let nies = [];
|
|
75
|
-
for (const brut of declares
|
|
84
|
+
for (const brut of declares) {
|
|
76
85
|
const excl = /^!+/.exec(brut)?.[0] ?? '';
|
|
77
86
|
const motif = brut
|
|
78
87
|
.slice(excl.length)
|
|
@@ -86,12 +95,39 @@ export function paquets(racine) {
|
|
|
86
95
|
motifs.push(motif);
|
|
87
96
|
}
|
|
88
97
|
}
|
|
98
|
+
return { declares, motifs, nies };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether the `workspaces` of the root `package.json` <p> select the directory <dossier> (from the
|
|
103
|
+
* root), as `paquets` maps them, whether or not it holds its package.json yet.
|
|
104
|
+
* @param {Record<string, any> | null} p
|
|
105
|
+
* @param {string} dossier
|
|
106
|
+
*/
|
|
107
|
+
export function selectionne(p, dossier) {
|
|
108
|
+
const { motifs, nies } = motifsDesEspaces(p);
|
|
109
|
+
return (
|
|
110
|
+
!dossier.split('/').includes('node_modules') &&
|
|
111
|
+
motifs.some(m => path.matchesGlob(dossier, m)) &&
|
|
112
|
+
!nies.some(n => path.matchesGlob(dossier, n))
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// The packages of the repository at <racine>: [{ dossier, pkg, hors }], sorted by directory;
|
|
117
|
+
// `hors` whether `docs/agents/hors-cadre.txt` lists it (a directory under `packages/` or `src/`).
|
|
118
|
+
export function paquets(racine) {
|
|
119
|
+
const p = lireJson(path.join(racine, 'package.json'));
|
|
120
|
+
const { motifs, nies } = motifsDesEspaces(p);
|
|
89
121
|
const dossiers = new Set();
|
|
90
122
|
for (const motif of motifs) {
|
|
91
123
|
for (const f of globSync(`${motif}/package.json`, { cwd: racine })) {
|
|
92
124
|
const dossier = path.dirname(f);
|
|
93
|
-
if (f.split(path.sep).includes('node_modules'))
|
|
94
|
-
|
|
125
|
+
if (f.split(path.sep).includes('node_modules')) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (nies.some(n => path.matchesGlob(dossier, n))) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
95
131
|
dossiers.add(dossier);
|
|
96
132
|
}
|
|
97
133
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// A pass of the circuit on the machine: each takes a place of the machine, like a session of an
|
|
2
|
+
// agent (scripts/places-de-la-machine.mjs); a heavy pass (the final pass, `npm run verifier`)
|
|
3
|
+
// holds besides the exclusive lock of the machine (scripts/verrou-de-machine.mjs), once its place
|
|
4
|
+
// is given (`avecLaMachineEtUnePlace`). A targeted pass (the proof of the red and the checks,
|
|
5
|
+
// which play the tests of the ticket only) starts while a heavy one holds the lock.
|
|
6
|
+
import { sousNiceEtIonice } from './enveloppe/enveloppe.mjs';
|
|
7
|
+
import {
|
|
8
|
+
VARIABLE_TRAVAILLEURS,
|
|
9
|
+
avecLaMachineEtUnePlace,
|
|
10
|
+
avecUnePlace,
|
|
11
|
+
travailleursDe,
|
|
12
|
+
} from './places-de-la-machine.mjs';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Whether the npm command of a step is a heavy pass: `npm run verifier`, whatever its step.
|
|
16
|
+
* @param {{ etape: string, args: string[] }} o
|
|
17
|
+
*/
|
|
18
|
+
export function passeLourde({ args }) {
|
|
19
|
+
return args.includes('verifier');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* What a pass or a session out of the envelope launches: a heavy pass runs its command as it is,
|
|
24
|
+
* every core kept (no GRILLHOUSE_TRAVAILLEURS, even inherited); any other runs under `nice` and
|
|
25
|
+
* `ionice`, GRILLHOUSE_TRAVAILLEURS set to max(1, cores ÷ places).
|
|
26
|
+
* @param {{ lourde: boolean, cmd: string, args: string[], env: Record<string, string | undefined> }} o
|
|
27
|
+
* @returns {{ cmd: string, args: string[], env: Record<string, string | undefined> }}
|
|
28
|
+
*/
|
|
29
|
+
export function lancementDeLaPasse({ lourde, cmd, args, env }) {
|
|
30
|
+
const { [VARIABLE_TRAVAILLEURS]: _herite, ...sansTravailleurs } = env;
|
|
31
|
+
if (lourde) {
|
|
32
|
+
return { cmd, args, env: sansTravailleurs };
|
|
33
|
+
}
|
|
34
|
+
const [commande, ...arguments_] = sousNiceEtIonice([cmd, ...args]);
|
|
35
|
+
return {
|
|
36
|
+
cmd: commande,
|
|
37
|
+
args: arguments_,
|
|
38
|
+
env: { ...sansTravailleurs, [VARIABLE_TRAVAILLEURS]: String(travailleursDe({ env })) },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Plays <mesure> on a place of the machine, and under its lock besides when it is <lourde>, the
|
|
44
|
+
* environment it receives being the pass's own. The wait of either says its reason and stops at
|
|
45
|
+
* the bound (75).
|
|
46
|
+
* @template T
|
|
47
|
+
* @param {(env: Record<string, string | undefined>) => T} mesure
|
|
48
|
+
* @param {{ lourde: boolean, env?: Record<string, string | undefined>, racine?: string,
|
|
49
|
+
* ticket?: string, sorte?: string, rang?: number, dire?: (l: string) => void,
|
|
50
|
+
* borneMs?: number, rappelMs?: number } & Record<string, unknown>} options
|
|
51
|
+
* @returns {T}
|
|
52
|
+
*/
|
|
53
|
+
export function avecLaPasse(
|
|
54
|
+
mesure,
|
|
55
|
+
{ lourde, env = process.env, racine, ticket, sorte, ...options }
|
|
56
|
+
) {
|
|
57
|
+
if (lourde) {
|
|
58
|
+
const { dire, borneMs, rappelMs, rang } = options;
|
|
59
|
+
return avecLaMachineEtUnePlace(mesure, {
|
|
60
|
+
env,
|
|
61
|
+
racine,
|
|
62
|
+
ticket,
|
|
63
|
+
sorte,
|
|
64
|
+
...(rang !== undefined ? { rang } : {}),
|
|
65
|
+
...(dire ? { dire } : {}),
|
|
66
|
+
...(borneMs !== undefined ? { borneMs } : {}),
|
|
67
|
+
...(rappelMs !== undefined ? { rappelMs } : {}),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return avecUnePlace(place => mesure(place.env), { ...options, env, ticket });
|
|
71
|
+
}
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
// The places of the machine: a fixed number of places for the whole machine, whatever repository a
|
|
2
|
+
// session or a pass plays in, as the executors of Jenkins and the agents of Buildkite are a fixed
|
|
3
|
+
// number, and as the job server of GNU make shares its slots between every make of one build.
|
|
4
|
+
// Each session of an agent (testwriter, developer, reviewer…) takes a place at its start and gives
|
|
5
|
+
// it back at its end; a circuit that waits for a question, or between two sessions, holds none.
|
|
6
|
+
// Each pass takes one too (scripts/passe-de-la-machine.mjs: a targeted pass, and a heavy one
|
|
7
|
+
// besides the exclusive lock of the machine, scripts/verrou-de-machine.mjs). Witness: 2026-11-02,
|
|
8
|
+
// load 39 on 12 cores with five circuits at once (grillhouse-9kq).
|
|
9
|
+
//
|
|
10
|
+
// - The places live on the Temporal server, in the one workflow of the machine
|
|
11
|
+
// (src/temporal/places/deroule.ts), which grants them by the rule of scripts/regles-des-places.mjs
|
|
12
|
+
// (a free place under the ceiling, the turn of the rank of arrival, the admission at the load and
|
|
13
|
+
// the memory as `make -l`'s, the spacing of the starts) and frees the place of a process gone. A
|
|
14
|
+
// synchronous caller reads and takes them by ./places-du-serveur.mjs, in a process of its own.
|
|
15
|
+
// - The server is required on the workstation: one that does not answer stops the taking, named.
|
|
16
|
+
// In the CI (CI set) no place is taken. A trial machine (GRILLHOUSE_VERROU_MACHINE, the base
|
|
17
|
+
// configuration of the tests) takes its places on the server GRILLHOUSE_PLACES_D_ESSAI names,
|
|
18
|
+
// and none without it, so that no test takes a place of the user's machine.
|
|
19
|
+
// - A pass or a session that holds a place carries its mark to its children
|
|
20
|
+
// (GRILLHOUSE_PLACE_TENUE): a pass they play takes no second place. In the envelope of an agent
|
|
21
|
+
// (GRILLHOUSE_ENVELOPPE set, ./enveloppe/paquets-du-plan.mjs) no place is taken, as no lock is
|
|
22
|
+
// (./verrou-de-machine.mjs): the place of the session, taken out of it by the circuit, covers its
|
|
23
|
+
// commands, and the envelope passes on its mark; a number of process there means nothing on
|
|
24
|
+
// the machine.
|
|
25
|
+
// - The ceiling is PLAFOND_PAR_DEFAUT, 3, unless GRILLHOUSE_PLACES names another (a positive
|
|
26
|
+
// integer; any other value is refused by the name of the variable); two starts are spaced by
|
|
27
|
+
// ESPACEMENT_MS (GRILLHOUSE_ESPACEMENT_MS names another, in ms). The workflow reads both when it
|
|
28
|
+
// starts.
|
|
29
|
+
// - A wait says its reason (place, rank, load, memory or spacing) when it begins and every 30 s,
|
|
30
|
+
// and is bounded as the wait for the lock of the machine, GRILLHOUSE_ATTENTE_MACHINE_MS: at the
|
|
31
|
+
// bound, « à repasser » (75), the request withdrawn.
|
|
32
|
+
// - A wait keeps the rank of its arrival, as the queue of a merge train keeps its order: the rank
|
|
33
|
+
// is drawn when the circuit is launched (`prendreUnRang`) and kept from one session to the next.
|
|
34
|
+
// - The number of workers of the tests of a session is `travailleursDe`: max(1, cores ÷ places),
|
|
35
|
+
// passed to the tool of each language (GRILLHOUSE_TRAVAILLEURS).
|
|
36
|
+
import { spawnSync } from 'node:child_process';
|
|
37
|
+
import { availableParallelism } from 'node:os';
|
|
38
|
+
import path from 'node:path';
|
|
39
|
+
import { departDe } from './mesure/base-de-passe.mjs';
|
|
40
|
+
import { A_REPASSER } from './codes-de-sortie.mjs';
|
|
41
|
+
import { paquetsDeLEnveloppe } from './enveloppe/paquets-du-plan.mjs';
|
|
42
|
+
import { mesureDeLaMachine } from './mesure-de-la-machine.mjs';
|
|
43
|
+
import { AttenteDeLaMachine, avecLaMachine, borneDe } from './verrou-de-machine.mjs';
|
|
44
|
+
|
|
45
|
+
export const VARIABLE_PLACES = 'GRILLHOUSE_PLACES';
|
|
46
|
+
export const VARIABLE_ESPACEMENT = 'GRILLHOUSE_ESPACEMENT_MS';
|
|
47
|
+
export const VARIABLE_TRAVAILLEURS = 'GRILLHOUSE_TRAVAILLEURS';
|
|
48
|
+
/** The mark of a place held, which the children of its holder inherit. */
|
|
49
|
+
export const VARIABLE_TENUE = 'GRILLHOUSE_PLACE_TENUE';
|
|
50
|
+
/** The measure of the machine a trial fixes, in JSON `{ coeurs, charge, memoireLibre }`. */
|
|
51
|
+
export const VARIABLE_MESURE_D_ESSAI = 'GRILLHOUSE_MESURE_D_ESSAI';
|
|
52
|
+
// The server of the places of a trial machine.
|
|
53
|
+
const VARIABLE_ESSAI = 'GRILLHOUSE_PLACES_D_ESSAI';
|
|
54
|
+
|
|
55
|
+
/** The ceiling of the places of the machine when GRILLHOUSE_PLACES names none. */
|
|
56
|
+
export const PLAFOND_PAR_DEFAUT = 3;
|
|
57
|
+
/** The gap between two starts when GRILLHOUSE_ESPACEMENT_MS names none, in ms. */
|
|
58
|
+
export const ESPACEMENT_MS = 10_000;
|
|
59
|
+
const RAPPEL_MS = 30_000;
|
|
60
|
+
// The reading and the taking of the places on the server, in a process of their own.
|
|
61
|
+
const PONT = path.join(import.meta.dirname, 'places-du-serveur.mjs');
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The ceiling of the places under <env>.
|
|
65
|
+
* @param {Record<string, string | undefined>} [env]
|
|
66
|
+
* @returns {number}
|
|
67
|
+
* @throws {Error} naming GRILLHOUSE_PLACES when its value is not a positive integer
|
|
68
|
+
*/
|
|
69
|
+
export function plafondDe(env = process.env) {
|
|
70
|
+
const v = env[VARIABLE_PLACES];
|
|
71
|
+
if (v === undefined || v === '') {
|
|
72
|
+
return PLAFOND_PAR_DEFAUT;
|
|
73
|
+
}
|
|
74
|
+
if (!/^[1-9]\d*$/.test(v)) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`${VARIABLE_PLACES} vaut « ${v} » : un entier positif est attendu (3 par défaut).`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return Number(v);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The gap between two starts under <env>, in ms.
|
|
84
|
+
* @param {Record<string, string | undefined>} [env]
|
|
85
|
+
* @returns {number}
|
|
86
|
+
* @throws {Error} naming GRILLHOUSE_ESPACEMENT_MS when its value is not a number of ms
|
|
87
|
+
*/
|
|
88
|
+
export function espacementDe(env = process.env) {
|
|
89
|
+
const v = env[VARIABLE_ESPACEMENT];
|
|
90
|
+
if (v === undefined || v === '') {
|
|
91
|
+
return ESPACEMENT_MS;
|
|
92
|
+
}
|
|
93
|
+
if (!/^\d+$/.test(v)) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`${VARIABLE_ESPACEMENT} vaut « ${v} » : un nombre de millisecondes est attendu.`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return Number(v);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The number of workers of the tests of a session: max(1, cores ÷ places), the division whole.
|
|
103
|
+
* @param {{ coeurs?: number, places?: number, env?: Record<string, string | undefined> }} [o]
|
|
104
|
+
* @returns {number}
|
|
105
|
+
*/
|
|
106
|
+
export function travailleursDe({
|
|
107
|
+
coeurs = availableParallelism(),
|
|
108
|
+
places,
|
|
109
|
+
env = process.env,
|
|
110
|
+
} = {}) {
|
|
111
|
+
return Math.max(1, Math.floor(coeurs / (places ?? plafondDe(env))));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The workers a session of an agent plays its tests on, as its environment gives them
|
|
116
|
+
* (GRILLHOUSE_TRAVAILLEURS, set by the envelope): what the module of each language passes to its
|
|
117
|
+
* tool. Null without the variable (a heavy pass): the tool keeps every core.
|
|
118
|
+
* @param {Record<string, string | undefined>} [env]
|
|
119
|
+
* @returns {number | null}
|
|
120
|
+
* @throws {Error} naming GRILLHOUSE_TRAVAILLEURS when its value is not a positive integer
|
|
121
|
+
*/
|
|
122
|
+
export function travailleursDeLaSeance(env = process.env) {
|
|
123
|
+
const v = env[VARIABLE_TRAVAILLEURS];
|
|
124
|
+
if (v === undefined || v === '') {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
if (!/^[1-9]\d*$/.test(v)) {
|
|
128
|
+
throw new Error(`${VARIABLE_TRAVAILLEURS} vaut « ${v} » : un entier positif est attendu.`);
|
|
129
|
+
}
|
|
130
|
+
return Number(v);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The environment the places are read under on <env>: the address of their server
|
|
135
|
+
* (TEMPORAL_ADDRESS), or null where no place is taken (the CI, the envelope of an agent, a trial
|
|
136
|
+
* machine without its server).
|
|
137
|
+
* @param {Record<string, string | undefined>} env
|
|
138
|
+
* @returns {Record<string, string | undefined> | null}
|
|
139
|
+
*/
|
|
140
|
+
function surLeServeur(env) {
|
|
141
|
+
if (env.CI || paquetsDeLEnveloppe(env)) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
if (env.GRILLHOUSE_VERROU_MACHINE) {
|
|
145
|
+
return env[VARIABLE_ESSAI] ? { ...env, TEMPORAL_ADDRESS: env[VARIABLE_ESSAI] } : null;
|
|
146
|
+
}
|
|
147
|
+
return env;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// The mode <args> of ./places-du-serveur.mjs under <env>, waited for within <ms>: its exit code,
|
|
151
|
+
// its lines in JSON; a server that does not answer, or a call that fails, stops the measure as a
|
|
152
|
+
// wait of the machine does (`AttenteDeLaMachine`, code 1), its reason named.
|
|
153
|
+
function auServeur(env, args, ms = 30_000) {
|
|
154
|
+
const r = spawnSync(process.execPath, [PONT, ...args], {
|
|
155
|
+
env,
|
|
156
|
+
encoding: 'utf8',
|
|
157
|
+
timeout: ms,
|
|
158
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
159
|
+
});
|
|
160
|
+
const lignes = (r.stdout ?? '')
|
|
161
|
+
.split('\n')
|
|
162
|
+
.filter(Boolean)
|
|
163
|
+
.map(l => JSON.parse(l));
|
|
164
|
+
if (r.status !== 0 && r.status !== A_REPASSER) {
|
|
165
|
+
throw new AttenteDeLaMachine(
|
|
166
|
+
`✗ ${(r.stderr || r.error?.message || `les places de la machine ne se lisent pas, code ${r.status}`).trim()}`,
|
|
167
|
+
1
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
return { code: r.status, lignes };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Draws the next rank of arrival of the machine: a circuit draws it when it is launched and keeps
|
|
175
|
+
* it from one session to the next, so a wait for a place keeps its place in the line. Null where no
|
|
176
|
+
* place is taken.
|
|
177
|
+
* @param {{ env?: Record<string, string | undefined> }} [o]
|
|
178
|
+
* @returns {number | null}
|
|
179
|
+
*/
|
|
180
|
+
export function prendreUnRang({ env = process.env } = {}) {
|
|
181
|
+
const e = surLeServeur(env);
|
|
182
|
+
return e ? auServeur(e, ['rang']).lignes[0] : null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Takes a place of the machine, waiting for one, saying why it waits (`dire`), and returns the
|
|
187
|
+
* place. Where no place is taken, or under a place already held (GRILLHOUSE_PLACE_TENUE), the
|
|
188
|
+
* place returned holds nothing.
|
|
189
|
+
* @param {{ env?: Record<string, string | undefined>, ticket?: string | null, rang?: number,
|
|
190
|
+
* pid?: number, depart?: string | null, borneMs?: number, rappelMs?: number,
|
|
191
|
+
* dire?: (l: string) => void }} [o] `pid` and `depart` name the process of the session (the
|
|
192
|
+
* taking process by default); `rang` the rank of the arrival of the circuit (drawn by the server
|
|
193
|
+
* when absent)
|
|
194
|
+
* @returns {{ id: string | null, rang: number | null, env: Record<string, string | undefined>,
|
|
195
|
+
* rendre: () => void, rattacher: (p: { pid: number, depart: string | null }) => void }} `env`,
|
|
196
|
+
* the environment of its holder's children, with the mark of the place; `rattacher` names the
|
|
197
|
+
* process of the session once launched (the taking process held the place until then)
|
|
198
|
+
* @throws {AttenteDeLaMachine} at the bound of the wait (code 75), its reason named
|
|
199
|
+
*/
|
|
200
|
+
export function prendreUnePlace({
|
|
201
|
+
env = process.env,
|
|
202
|
+
ticket = null,
|
|
203
|
+
rang,
|
|
204
|
+
pid = process.pid,
|
|
205
|
+
depart,
|
|
206
|
+
borneMs = borneDe(env),
|
|
207
|
+
rappelMs = RAPPEL_MS,
|
|
208
|
+
dire = l => process.stdout.write(`${l}\n`),
|
|
209
|
+
} = {}) {
|
|
210
|
+
const e = env[VARIABLE_TENUE] ? null : surLeServeur(env);
|
|
211
|
+
if (!e) {
|
|
212
|
+
return { id: null, rang: rang ?? null, env, rendre: () => {}, rattacher: () => {} };
|
|
213
|
+
}
|
|
214
|
+
const demande = {
|
|
215
|
+
pid,
|
|
216
|
+
depart: depart === undefined ? departDe(pid) : depart,
|
|
217
|
+
ticket,
|
|
218
|
+
...(rang === undefined || rang === null ? {} : { rang }),
|
|
219
|
+
borneMs,
|
|
220
|
+
rappelMs,
|
|
221
|
+
};
|
|
222
|
+
const { code, lignes } = auServeur(e, ['prendre', JSON.stringify(demande)], borneMs + 60_000);
|
|
223
|
+
for (const l of lignes) {
|
|
224
|
+
if (l.dire) {
|
|
225
|
+
dire(l.dire);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (code === A_REPASSER) {
|
|
229
|
+
throw new AttenteDeLaMachine(lignes.at(-1)?.dire ?? 'attente de place bornée', A_REPASSER);
|
|
230
|
+
}
|
|
231
|
+
const place = lignes.find(l => l.id);
|
|
232
|
+
return {
|
|
233
|
+
id: place.id,
|
|
234
|
+
rang: place.rang,
|
|
235
|
+
env: { ...env, [VARIABLE_TENUE]: place.id },
|
|
236
|
+
// A place that does not go back is said, and the pass keeps its code: the workflow of the
|
|
237
|
+
// machine frees the place of a process gone.
|
|
238
|
+
rendre: () => {
|
|
239
|
+
try {
|
|
240
|
+
auServeur(e, ['rendre', place.id]);
|
|
241
|
+
} catch (x) {
|
|
242
|
+
if (!(x instanceof AttenteDeLaMachine)) {
|
|
243
|
+
throw x;
|
|
244
|
+
}
|
|
245
|
+
dire(
|
|
246
|
+
`⚠ la place ${place.id} ne se rend pas (${x.message}) : le déroulé de la machine la libère à la fin de son processus.`
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
rattacher: p => {
|
|
251
|
+
auServeur(e, ['rattacher', place.id, String(p.pid), String(p.depart)]);
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Plays <seance> holding a place, given back at its end, whether it returns, throws or (for an
|
|
258
|
+
* asynchronous one) settles; <seance> receives the place, its `env` the environment of its
|
|
259
|
+
* children.
|
|
260
|
+
* @param {(place: ReturnType<typeof prendreUnePlace>) => T} seance
|
|
261
|
+
* @param {Parameters<typeof prendreUnePlace>[0]} [options]
|
|
262
|
+
* @returns {T}
|
|
263
|
+
* @template T
|
|
264
|
+
*/
|
|
265
|
+
export function avecUnePlace(seance, options) {
|
|
266
|
+
const place = prendreUnePlace(options);
|
|
267
|
+
let r;
|
|
268
|
+
try {
|
|
269
|
+
r = seance(place);
|
|
270
|
+
} catch (e) {
|
|
271
|
+
place.rendre();
|
|
272
|
+
throw e;
|
|
273
|
+
}
|
|
274
|
+
if (r && typeof r.then === 'function') {
|
|
275
|
+
return r.then(
|
|
276
|
+
v => {
|
|
277
|
+
place.rendre();
|
|
278
|
+
return v;
|
|
279
|
+
},
|
|
280
|
+
e => {
|
|
281
|
+
place.rendre();
|
|
282
|
+
throw e;
|
|
283
|
+
}
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
place.rendre();
|
|
287
|
+
return r;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Plays the pass <passe> on a place of the machine, as a command a person or an agent runs (`npm
|
|
292
|
+
* test`): its exit code, or, a wait that stops (its bound, 75; a server that does not answer, 1),
|
|
293
|
+
* its reason said and its code. <passe> receives the environment of its children, with the mark
|
|
294
|
+
* of the place.
|
|
295
|
+
* @param {(env: Record<string, string | undefined>) => number} passe
|
|
296
|
+
* @param {{ env?: Record<string, string | undefined>, dire?: (l: string) => void }} [o]
|
|
297
|
+
* @returns {number}
|
|
298
|
+
*/
|
|
299
|
+
export function surUnePlace(
|
|
300
|
+
passe,
|
|
301
|
+
{ env = process.env, dire = l => process.stderr.write(`${l}\n`) } = {}
|
|
302
|
+
) {
|
|
303
|
+
try {
|
|
304
|
+
return avecUnePlace(place => passe(place.env), { env, dire });
|
|
305
|
+
} catch (e) {
|
|
306
|
+
if (!(e instanceof AttenteDeLaMachine)) {
|
|
307
|
+
throw e;
|
|
308
|
+
}
|
|
309
|
+
dire(e.message);
|
|
310
|
+
return e.code;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Plays the heavy measure <mesure> on a place of the machine, then under its exclusive lock
|
|
316
|
+
* (`avecLaMachine` of ./verrou-de-machine.mjs), and returns what it returns: the place first, so
|
|
317
|
+
* that a pass that waits for its place holds no lock. <mesure> receives the environment of its
|
|
318
|
+
* children, which carries the marks of both.
|
|
319
|
+
* @param {(env: Record<string, string | undefined>) => T} mesure
|
|
320
|
+
* @param {Parameters<typeof avecLaMachine>[1] & { rang?: number }} [options] those of the lock,
|
|
321
|
+
* whose `env`, `ticket`, `dire`, `borneMs` and `rappelMs` the place reads too, and `rang`, the
|
|
322
|
+
* rank of the circuit of the pass
|
|
323
|
+
* @returns {T}
|
|
324
|
+
* @template T
|
|
325
|
+
*/
|
|
326
|
+
export function avecLaMachineEtUnePlace(mesure, options = {}) {
|
|
327
|
+
const { env = process.env, ticket, rang, dire, borneMs, rappelMs, ...verrou } = options;
|
|
328
|
+
return avecUnePlace(
|
|
329
|
+
place =>
|
|
330
|
+
avecLaMachine(mesure, {
|
|
331
|
+
...verrou,
|
|
332
|
+
env: place.env,
|
|
333
|
+
...(ticket === undefined ? {} : { ticket }),
|
|
334
|
+
...(dire ? { dire } : {}),
|
|
335
|
+
...(borneMs === undefined ? {} : { borneMs }),
|
|
336
|
+
...(rappelMs === undefined ? {} : { rappelMs }),
|
|
337
|
+
}),
|
|
338
|
+
{
|
|
339
|
+
env,
|
|
340
|
+
ticket: ticket ?? null,
|
|
341
|
+
...(rang === undefined ? {} : { rang }),
|
|
342
|
+
...(dire ? { dire } : {}),
|
|
343
|
+
...(borneMs === undefined ? {} : { borneMs }),
|
|
344
|
+
...(rappelMs === undefined ? {} : { rappelMs }),
|
|
345
|
+
}
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* The places taken and the waits of the machine under <env>, as the server holds them: `{ plafond,
|
|
351
|
+
* prises, attentes }`, `prises` `{ id, pid, depart, ticket, rang, depuis }`, `attentes` in the
|
|
352
|
+
* order of arrival `{ id, pid, ticket, rang, raison, depuis }`; none where no place is taken.
|
|
353
|
+
* @param {{ env?: Record<string, string | undefined> }} [o]
|
|
354
|
+
*/
|
|
355
|
+
export function lirePlaces({ env = process.env } = {}) {
|
|
356
|
+
const e = surLeServeur(env);
|
|
357
|
+
return e
|
|
358
|
+
? auServeur(e, ['lire']).lignes[0]
|
|
359
|
+
: { plafond: plafondDe(env), prises: [], attentes: [] };
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* The machine a trial fixes under <env> (GRILLHOUSE_MESURE_D_ESSAI, JSON `{ coeurs, charge,
|
|
364
|
+
* memoireLibre }`), or null without the variable.
|
|
365
|
+
* @param {Record<string, string | undefined>} env
|
|
366
|
+
* @returns {{ coeurs: number, charge: number, memoireLibre: number } | null}
|
|
367
|
+
* @throws {Error} naming GRILLHOUSE_MESURE_D_ESSAI when its value is not that JSON
|
|
368
|
+
*/
|
|
369
|
+
function mesureDEssai(env) {
|
|
370
|
+
const v = env[VARIABLE_MESURE_D_ESSAI];
|
|
371
|
+
if (v === undefined || v === '') {
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
let m;
|
|
375
|
+
try {
|
|
376
|
+
m = JSON.parse(v);
|
|
377
|
+
} catch {
|
|
378
|
+
m = null;
|
|
379
|
+
}
|
|
380
|
+
if (
|
|
381
|
+
!m ||
|
|
382
|
+
typeof m !== 'object' ||
|
|
383
|
+
['coeurs', 'charge', 'memoireLibre'].some(
|
|
384
|
+
c => typeof m[c] !== 'number' || !Number.isFinite(m[c])
|
|
385
|
+
)
|
|
386
|
+
) {
|
|
387
|
+
throw new Error(
|
|
388
|
+
`${VARIABLE_MESURE_D_ESSAI} vaut « ${v} » : un JSON { coeurs, charge, memoireLibre } de nombres est attendu.`
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
return { coeurs: m.coeurs, charge: m.charge, memoireLibre: m.memoireLibre };
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* The places as the board shows them: taken and ceiling, the load over one minute and the cores,
|
|
396
|
+
* the free memory in whole GB, and the waits (ticket, since when) in the order of arrival. The
|
|
397
|
+
* machine is the one GRILLHOUSE_MESURE_D_ESSAI fixes, else the real one (`mesurer`).
|
|
398
|
+
* @param {{ env?: Record<string, string | undefined>, mesurer?: () => { coeurs: number,
|
|
399
|
+
* charge: number, memoireLibre: number } }} [o]
|
|
400
|
+
* @throws {Error} naming GRILLHOUSE_MESURE_D_ESSAI when its value is faulty
|
|
401
|
+
*/
|
|
402
|
+
export function etatDesPlaces({ env = process.env, mesurer = mesureDeLaMachine } = {}) {
|
|
403
|
+
const fixee = mesureDEssai(env);
|
|
404
|
+
const { plafond, prises, attentes } = lirePlaces({ env });
|
|
405
|
+
const m = fixee ?? mesurer();
|
|
406
|
+
return {
|
|
407
|
+
prises: prises.length,
|
|
408
|
+
plafond,
|
|
409
|
+
charge: Math.round(m.charge * 10) / 10,
|
|
410
|
+
coeurs: m.coeurs,
|
|
411
|
+
memoireGo: Math.floor(m.memoireLibre / 1024 ** 3),
|
|
412
|
+
attentes: attentes.map(a => ({ ticket: a.ticket, depuis: a.depuis })),
|
|
413
|
+
};
|
|
414
|
+
}
|