@roomi-fields/grillhouse 0.54.0 → 0.55.1

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 (237) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +75 -0
  3. package/cadre/templates/projet/.github/workflows/ci.yml +4 -2
  4. package/cadre/templates/projet/.github/workflows/machine-vierge.yml +5 -42
  5. package/cadre/templates/projet/CONTRIBUTING.md +0 -5
  6. package/cadre/templates/projet/README.md +0 -126
  7. package/cadre/templates/projet/_npmignore +1 -6
  8. package/cadre/templates/projet/package.json +5 -32
  9. package/cadre/templates/projet/tsconfig.json +4 -4
  10. package/cadre/templates/projet/vitest.config.cjs +3 -2
  11. package/charte/tests.md +14 -0
  12. package/dist/machine/part-par-sorte.d.ts +9 -9
  13. package/dist/machine/part-par-sorte.js +20 -24
  14. package/dist/machine/part-par-sorte.js.map +1 -1
  15. package/dist/machine/table-des-consommations.d.ts +65 -0
  16. package/dist/machine/table-des-consommations.js +94 -0
  17. package/dist/machine/table-des-consommations.js.map +1 -0
  18. package/dist/temporal/circuit/activites.d.ts +2 -0
  19. package/dist/temporal/circuit/activites.js +87 -3
  20. package/dist/temporal/circuit/activites.js.map +1 -1
  21. package/dist/temporal/circuit/client.js +9 -4
  22. package/dist/temporal/circuit/client.js.map +1 -1
  23. package/dist/temporal/circuit/contrat.d.ts +32 -4
  24. package/dist/temporal/circuit/deroule.js +54 -4
  25. package/dist/temporal/circuit/deroule.js.map +1 -1
  26. package/dist/temporal/circuit/versions.d.ts +12 -0
  27. package/dist/temporal/circuit/versions.js +22 -0
  28. package/dist/temporal/circuit/versions.js.map +1 -0
  29. package/dist/temporal/consommation/activites.d.ts +2 -0
  30. package/dist/temporal/consommation/activites.js +9 -0
  31. package/dist/temporal/consommation/activites.js.map +1 -0
  32. package/dist/temporal/consommation/actualisation.d.ts +2 -0
  33. package/dist/temporal/consommation/actualisation.js +71 -0
  34. package/dist/temporal/consommation/actualisation.js.map +1 -0
  35. package/dist/temporal/consommation/client.d.ts +12 -0
  36. package/dist/temporal/consommation/client.js +28 -0
  37. package/dist/temporal/consommation/client.js.map +1 -0
  38. package/dist/temporal/consommation/commande.d.ts +5 -0
  39. package/dist/temporal/consommation/commande.js +32 -0
  40. package/dist/temporal/consommation/commande.js.map +1 -0
  41. package/dist/temporal/consommation/contrat.d.ts +15 -0
  42. package/dist/temporal/consommation/contrat.js +13 -0
  43. package/dist/temporal/consommation/contrat.js.map +1 -0
  44. package/dist/temporal/consommation/deroule.d.ts +2 -0
  45. package/dist/temporal/consommation/deroule.js +14 -0
  46. package/dist/temporal/consommation/deroule.js.map +1 -0
  47. package/dist/temporal/deroules.d.ts +2 -1
  48. package/dist/temporal/deroules.js +3 -2
  49. package/dist/temporal/deroules.js.map +1 -1
  50. package/dist/temporal/file/contrat.d.ts +2 -0
  51. package/dist/temporal/file/deroule.js +14 -4
  52. package/dist/temporal/file/deroule.js.map +1 -1
  53. package/dist/temporal/installation.d.ts +6 -0
  54. package/dist/temporal/installation.js +15 -0
  55. package/dist/temporal/installation.js.map +1 -1
  56. package/dist/temporal/nuits/activites.d.ts +2 -1
  57. package/dist/temporal/nuits/activites.js +127 -3
  58. package/dist/temporal/nuits/activites.js.map +1 -1
  59. package/dist/temporal/nuits/client.d.ts +19 -5
  60. package/dist/temporal/nuits/client.js +33 -23
  61. package/dist/temporal/nuits/client.js.map +1 -1
  62. package/dist/temporal/nuits/commande.js +16 -11
  63. package/dist/temporal/nuits/commande.js.map +1 -1
  64. package/dist/temporal/nuits/contrat.d.ts +29 -0
  65. package/dist/temporal/nuits/contrat.js +10 -0
  66. package/dist/temporal/nuits/contrat.js.map +1 -1
  67. package/dist/temporal/nuits/deroule.d.ts +5 -0
  68. package/dist/temporal/nuits/deroule.js +18 -1
  69. package/dist/temporal/nuits/deroule.js.map +1 -1
  70. package/dist/temporal/nuits/pc2.d.ts +72 -0
  71. package/dist/temporal/nuits/pc2.js +206 -0
  72. package/dist/temporal/nuits/pc2.js.map +1 -0
  73. package/dist/temporal/places/activites.d.ts +23 -1
  74. package/dist/temporal/places/activites.js +38 -2
  75. package/dist/temporal/places/activites.js.map +1 -1
  76. package/dist/temporal/places/client.d.ts +16 -0
  77. package/dist/temporal/places/client.js +25 -1
  78. package/dist/temporal/places/client.js.map +1 -1
  79. package/dist/temporal/places/contrat.d.ts +79 -14
  80. package/dist/temporal/places/contrat.js +7 -0
  81. package/dist/temporal/places/contrat.js.map +1 -1
  82. package/dist/temporal/places/deroule.js +159 -23
  83. package/dist/temporal/places/deroule.js.map +1 -1
  84. package/dist/temporal/places/reservation.d.ts +54 -0
  85. package/dist/temporal/places/reservation.js +69 -0
  86. package/dist/temporal/places/reservation.js.map +1 -0
  87. package/dist/temporal/planification.d.ts +6 -0
  88. package/dist/temporal/planification.js +26 -0
  89. package/dist/temporal/planification.js.map +1 -0
  90. package/dist/temporal/tickets/activites.d.ts +0 -2
  91. package/dist/temporal/tickets/activites.js +2 -52
  92. package/dist/temporal/tickets/activites.js.map +1 -1
  93. package/dist/temporal/tickets/contrat.d.ts +7 -26
  94. package/dist/temporal/tickets/deroule.js +35 -23
  95. package/dist/temporal/tickets/deroule.js.map +1 -1
  96. package/dist/temporal/travailleur.js +2 -0
  97. package/dist/temporal/travailleur.js.map +1 -1
  98. package/docs/ARCHITECTURE.md +2 -2
  99. package/docs/CADRE.md +1 -1
  100. package/docs/INTERFACE.md +16 -11
  101. package/docs/architecture/circuit.md +62 -58
  102. package/docs/architecture/entree.md +87 -63
  103. package/docs/architecture/greffon.md +32 -27
  104. package/docs/architecture/installation.md +43 -32
  105. package/docs/architecture/machine.md +48 -40
  106. package/docs/architecture/tests.md +37 -33
  107. package/docs/lexique.md +4 -3
  108. package/package.json +1 -1
  109. package/scripts/activites.mjs +351 -180
  110. package/scripts/aiguillage.mjs +1 -0
  111. package/scripts/attente-de-la-machine.mjs +3 -22
  112. package/scripts/avancement.mjs +21 -30
  113. package/scripts/bilan.mjs +22 -2
  114. package/scripts/branche-de-nuit.mjs +1 -1
  115. package/scripts/circuit.mjs +75 -39
  116. package/scripts/codes-de-sortie.mjs +0 -6
  117. package/scripts/consommation-des-passes.mjs +67 -31
  118. package/scripts/consommation.mjs +152 -24
  119. package/scripts/copies-finies.mjs +15 -35
  120. package/scripts/dernier-vert.mjs +4 -5
  121. package/scripts/dette.mjs +5 -3
  122. package/scripts/droits.mjs +2 -2
  123. package/scripts/echantillonneur-de-la-passe.mjs +7 -31
  124. package/scripts/engendres.mjs +5 -61
  125. package/scripts/enveloppe/enveloppe.mjs +30 -34
  126. package/scripts/enveloppe/travail-de-la-copie.mjs +5 -0
  127. package/scripts/etapes.mjs +21 -7
  128. package/scripts/etat-du-depot.mjs +61 -0
  129. package/scripts/faits-du-circuit.mjs +7 -4
  130. package/scripts/fermeture-de-la-machine.d.mts +6 -4
  131. package/scripts/fermeture-de-la-machine.mjs +12 -16
  132. package/scripts/fichier-du-poste.d.mts +9 -0
  133. package/scripts/file-des-tickets.d.mts +0 -18
  134. package/scripts/file-des-tickets.mjs +0 -42
  135. package/scripts/fusion-du-changelog.mjs +1 -1
  136. package/scripts/greffons.mjs +282 -17
  137. package/scripts/grillhouse-maj.mjs +1 -1
  138. package/scripts/index-des-rouges.d.mts +40 -0
  139. package/scripts/index-des-rouges.mjs +104 -0
  140. package/scripts/integration/file.mjs +13 -63
  141. package/scripts/integration/integrer.mjs +157 -424
  142. package/scripts/integration/jugement.mjs +109 -0
  143. package/scripts/integration/rejeu.mjs +94 -71
  144. package/scripts/jointure.d.ts +34 -27
  145. package/scripts/journal-des-etats.d.mts +1 -1
  146. package/scripts/langages/c/commandes.mjs +27 -12
  147. package/scripts/langages/cargo/commandes.mjs +148 -94
  148. package/scripts/langages/cargo/index.mjs +2 -1
  149. package/scripts/langages/cargo/lectures-des-tests.mjs +132 -0
  150. package/scripts/langages/cargo/migrations/lectures-des-tests.mjs +31 -0
  151. package/scripts/langages/python/commandes.mjs +31 -15
  152. package/scripts/langages/python/index.mjs +2 -1
  153. package/scripts/langages/python/lectures-des-tests.mjs +148 -0
  154. package/scripts/langages/python/migrations/lectures-des-tests.mjs +31 -0
  155. package/scripts/langages/typescript/consommateurs-arbitres.mjs +2 -2
  156. package/scripts/langages/typescript/index.mjs +4 -0
  157. package/scripts/langages/typescript/lectures-des-tests.mjs +95 -0
  158. package/scripts/langages/typescript/migrations/lectures-des-tests.mjs +31 -0
  159. package/scripts/langages/typescript/tests-de-nuit.mjs +9 -15
  160. package/scripts/langages/typescript/tests.mjs +11 -37
  161. package/scripts/langages/typescript/titres-de-tests.mjs +5 -4
  162. package/scripts/langages/typescript/verifier.mjs +74 -44
  163. package/scripts/langages/typescript/vitest-config/base.mjs +3 -3
  164. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +6 -25
  165. package/scripts/lectures-communes.mjs +234 -0
  166. package/scripts/machine.mjs +11 -18
  167. package/scripts/mesure/base-de-passe.mjs +1 -2
  168. package/scripts/mesure-de-la-machine.d.mts +40 -3
  169. package/scripts/mesure-de-la-machine.mjs +201 -11
  170. package/scripts/migrations/0.33.0-ci-du-cadre.mjs +3 -3
  171. package/scripts/migrations/nuit-yml-retire.mjs +25 -0
  172. package/scripts/migrations/part-retiree.mjs +31 -0
  173. package/scripts/migrations.mjs +4 -0
  174. package/scripts/montee.mjs +22 -1
  175. package/scripts/nuit-de-pc2.mjs +628 -0
  176. package/scripts/nuit.sh +8 -131
  177. package/scripts/paquets.mjs +1 -1
  178. package/scripts/passe-de-la-machine.mjs +340 -103
  179. package/scripts/place-du-circuit.d.mts +15 -0
  180. package/scripts/place-du-circuit.mjs +32 -0
  181. package/scripts/places-de-la-machine.mjs +148 -626
  182. package/scripts/places-du-serveur.mjs +26 -13
  183. package/scripts/plafond-de-la-machine.d.mts +8 -13
  184. package/scripts/plafond-de-la-machine.mjs +26 -56
  185. package/scripts/registre-des-entrees.mjs +57 -0
  186. package/scripts/regles-des-places.d.mts +82 -50
  187. package/scripts/regles-des-places.mjs +192 -156
  188. package/scripts/retirer-copie.sh +9 -2
  189. package/scripts/seances.mjs +181 -63
  190. package/scripts/secours.mjs +95 -0
  191. package/scripts/services-du-noyau.mjs +11 -19
  192. package/scripts/sous-commandes.mjs +1 -0
  193. package/scripts/sous-modules.sh +1 -1
  194. package/scripts/superviseur.mjs +98 -20
  195. package/scripts/table-des-consommations.d.mts +9 -0
  196. package/scripts/table-des-consommations.mjs +35 -0
  197. package/scripts/tableau.mjs +33 -19
  198. package/scripts/taches-du-graphe.mjs +124 -2
  199. package/scripts/transitions.d.mts +27 -5
  200. package/scripts/transitions.mjs +122 -104
  201. package/scripts/verdict-de-la-nuit.d.mts +13 -0
  202. package/scripts/verdict-de-la-nuit.mjs +34 -7
  203. package/scripts/verrou-de-fichier.mjs +1 -2
  204. package/scripts/workflows-du-cadre.mjs +2 -2
  205. package/skills/developpeur/SKILL.md +8 -2
  206. package/skills/direct/SKILL.md +5 -0
  207. package/skills/explorateur/SKILL.md +10 -1
  208. package/skills/grill/SKILL.md +2 -4
  209. package/skills/pitmaster/SKILL.md +14 -7
  210. package/skills/pitmaster/references/consigne-agent.md +1 -1
  211. package/skills/relecteur/SKILL.md +4 -1
  212. package/skills/testwriter/SKILL.md +15 -2
  213. package/cadre/templates/projet/.env.example +0 -57
  214. package/cadre/templates/projet/.github/workflows/nuit.yml +0 -139
  215. package/cadre/templates/projet/deployment/README.md +0 -98
  216. package/cadre/templates/projet/deployment/docs/01-INSTALL.md +0 -145
  217. package/cadre/templates/projet/deployment/docs/02-CONFIGURATION.md +0 -117
  218. package/cadre/templates/projet/deployment/docs/03-API.md +0 -264
  219. package/cadre/templates/projet/deployment/docs/04-TROUBLESHOOTING.md +0 -262
  220. package/cadre/templates/projet/deployment/scripts/install.ps1 +0 -100
  221. package/cadre/templates/projet/deployment/scripts/start.ps1 +0 -61
  222. package/cadre/templates/projet/deployment/scripts/stop.ps1 +0 -37
  223. package/cadre/templates/projet/deployment/scripts/test.ps1 +0 -118
  224. package/cadre/templates/projet/ecosystem.config.cjs +0 -73
  225. package/cadre/templates/projet/src/config.ts +0 -68
  226. package/cadre/templates/projet/src/errors.ts +0 -102
  227. package/cadre/templates/projet/src/index.ts +0 -46
  228. package/cadre/templates/projet/src/services/.gitkeep +0 -8
  229. package/cadre/templates/projet/src/types/index.ts +0 -24
  230. package/cadre/templates/projet/src/utils/logger.ts +0 -106
  231. package/cadre/templates/projet/tests/unit/config.spec.ts +0 -68
  232. package/cadre/templates/projet/tests/unit/errors.spec.ts +0 -132
  233. package/cadre/templates/projet/tests/unit/types.spec.ts +0 -73
  234. package/cadre/templates/projet/tsconfig.build.json +0 -14
  235. package/scripts/flux-de-la-nuit.mjs +0 -39
  236. package/scripts/garde-de-la-memoire.mjs +0 -231
  237. package/scripts/repli-de-la-nuit.mjs +0 -184
@@ -1,90 +1,55 @@
1
- // The places and the parts of the machine, taken by a synchronous caller: a place is held by a
2
- // session of an agent or a circuit, a part by a pass. Architecture: docs/architecture/machine.md
3
- // (§3.1, §5.1, §5.2, §5.4).
1
+ // The places of the machine and the reservations of the passes, taken by a synchronous caller: a
2
+ // place is held by a circuit or a pass, a reservation is what the arbiter grants it. Architecture:
3
+ // docs/architecture/machine.md (§3.1, §5.1, §5.2, §5.4).
4
4
  //
5
- // - The places live on the Temporal server, in the workflow of the machine
6
- // (src/temporal/places/deroule.ts), which grants them by the rule of ./regles-des-places.mjs
7
- // and frees the place of a process gone; this module reads and takes them by
8
- // ./places-du-serveur.mjs, in a process of its own. A session takes a place at its start and
9
- // gives it back at its end.
5
+ // - The arbiter is the workflow of the machine on the Temporal server
6
+ // (src/temporal/places/deroule.ts): it grants each request, in its order of arrival, by the rule
7
+ // of ./regles-des-places.mjs (`refusDeLaReservation`), and frees the reservation of a process
8
+ // gone; this module reads and takes the reservations by ./places-du-serveur.mjs, in a process of
9
+ // its own: the bridge `prendre` / `laDemande` / `rendre` of a process out of a circuit. The
10
+ // session of an agent a circuit launches takes none: the workflow of its circuit reserves its
11
+ // step (src/temporal/circuit/deroule.ts) and the environment of the session carries the
12
+ // reservation (VARIABLE_RESERVATION_D_ETAPE).
13
+ // - A pass asks the arbiter its reservation like a step (./passe-de-la-machine.mjs `avecLaPasse`):
14
+ // the cores and the memory the table of the consumptions gives its phase (`reservationDeLaPasse`),
15
+ // with its project, its ticket and its sort, which the board reads in the view of the arbiter
16
+ // (`lirePlaces`), the only state of the machine.
10
17
  // - The server is required on the workstation: one that does not answer stops the taking, named.
11
- // In the CI (CI set) no place is taken. A trial machine (GRILLHOUSE_PARTS_DE_LA_MACHINE) takes
12
- // its places on the server GRILLHOUSE_PLACES_D_ESSAI names, and none without it.
13
- // - A session that holds a place carries its mark to its children (GRILLHOUSE_PLACE_TENUE). In
14
- // the envelope of an agent (GRILLHOUSE_ENVELOPPE set, ./enveloppe/paquets-du-plan.mjs) no place
15
- // and no part is taken: the envelope passes on the mark of the session's place.
18
+ // In the CI (CI set) nothing is asked. A trial machine (GRILLHOUSE_MESURE_D_ESSAI) asks the
19
+ // server GRILLHOUSE_PLACES_D_ESSAI names, and none without it.
20
+ // - A reservation held carries its mark to its children (GRILLHOUSE_PLACE_TENUE). In the envelope
21
+ // of an agent (GRILLHOUSE_ENVELOPPE set, ./enveloppe/paquets-du-plan.mjs) nothing is asked: the
22
+ // envelope passes on the mark of the session's reservation.
16
23
  // - The ceiling of the places is `plafondDe` of ./plafond-de-la-machine.mjs (3 without a
17
- // setting), read again at each judgement; two starts are spaced by ESPACEMENT_MS
18
- // (GRILLHOUSE_ESPACEMENT_MS names another, in ms), read when the workflow starts.
19
- // - A wait says its reason (place, rank, load, memory or spacing) when it begins and every 30 s,
20
- // and is bounded by GRILLHOUSE_ATTENTE_MACHINE_MS: at the bound, « à repasser » (75), the
21
- // request withdrawn. It keeps the rank of its arrival (`prendreUnRang`), kept from one session
22
- // to the next.
24
+ // setting), read again at each judgement.
25
+ // - A wait says its reason (place, rank, load or memory) when it begins and every 30 s, and is
26
+ // bounded by GRILLHOUSE_ATTENTE_MACHINE_MS: at the bound, « à repasser » (75), the request
27
+ // withdrawn. It keeps the rank of its arrival (`prendreUnRang`), the order of arrival alone.
23
28
  // - The workers of the tests of a session are `travailleursDe`: max(1, cores ÷ places), passed
24
29
  // to the tool of each language (GRILLHOUSE_TRAVAILLEURS).
25
- // - A part is the share of the budget (./plafond-de-la-machine.mjs) that every pass takes: the
26
- // heavy pass of a circuit, `npm run verifier`, a targeted `npm test`, the CI on a machine of
27
- // ours, the night. A pass starts when its part fits in what the parts held leave of the budget
28
- // and the machine admits it (`admissionDePart` of ./regles-des-places.mjs); else it waits, says
29
- // what for when it begins and every 30 s, keeps its rank (the measure of the frame before a
30
- // project's, then the order of arrival) and stops at « à repasser » (75) at the bound.
31
- // - The memory of a part is that of its sort (`partDeLaPasse`): at 20 peaks or more of the sort in
32
- // the register, a reservation the admission counts and a limit where its group is cut.
33
- // - The parts are one file per pass in `${XDG_STATE_HOME:-~/.local/state}/grillhouse/parts`
34
- // (GRILLHOUSE_PARTS_DE_LA_MACHINE names another): the part held or waited for, its project,
35
- // ticket, kind, rank and progress directory, which the board reads (`lireLesParts`). A pass
36
- // whose process is gone frees its part.
37
- // - A part holds precise threads (`fils` of its file), chosen on the topology by
38
- // ./coeurs-dedies.mjs `choisirLesCoeurs`, none held by another. A measure of time (`mesure`)
39
- // takes physical cores whole, the number its project declares (`grillhouse.mesure`) or the
40
- // default part of the budget; it waits for its cores, then for the load of the others to be
41
- // under 10 %, within the bound of the wait.
42
- // - A pass that holds a part carries its mark to its children (GRILLHOUSE_PART_TENUE): a pass
43
- // they play takes no second part, and the workers of its tools are the cores of its part
44
- // (GRILLHOUSE_TRAVAILLEURS).
45
- import { randomUUID } from 'node:crypto';
46
30
  import { spawnSync } from 'node:child_process';
47
- import { mkdirSync, readdirSync, readFileSync, rmdirSync, rmSync } from 'node:fs';
48
- import { createRequire } from 'node:module';
49
- import { availableParallelism, homedir } from 'node:os';
31
+ import { readFileSync } from 'node:fs';
32
+ import { availableParallelism } from 'node:os';
50
33
  import path from 'node:path';
51
34
  import { departDe } from './mesure/base-de-passe.mjs';
52
- import { lireLaConsommation, sorteDeLaPasse } from './consommation-des-passes.mjs';
53
- import { ecrireAtomique } from './mesure/avancement.mjs';
35
+ import { coeursDeLaMesureDe, mesureDeclareeDe } from './coeurs-dedies.mjs';
54
36
  import { A_REPASSER } from './codes-de-sortie.mjs';
55
- import {
56
- AttenteDeLaMachine,
57
- attendreDeLaPlace,
58
- borneDe,
59
- racineDeLaCopie,
60
- racineDuDepot,
61
- rangDeLaMesure,
62
- } from './attente-de-la-machine.mjs';
63
- import {
64
- budgetEnFils,
65
- chargeDesCoeursDuSysteme,
66
- choisirLesCoeurs,
67
- coeursDeLaMesureDe,
68
- filsDeLaMesure,
69
- lireLaTopologie,
70
- mesureDeclareeDe,
71
- SEUIL_DE_CHARGE,
72
- } from './coeurs-dedies.mjs';
37
+ import { AttenteDeLaMachine, borneDe, racineDuDepot } from './attente-de-la-machine.mjs';
73
38
  import { paquetsDeLEnveloppe } from './enveloppe/paquets-du-plan.mjs';
74
39
  import { ecrireLaTrace, traceDesPlaces } from './journal-des-etats.mjs';
75
- import { mesureDeLaMachine, processusVivant } from './mesure-de-la-machine.mjs';
40
+ import { mesureDeLaMachine } from './mesure-de-la-machine.mjs';
76
41
  import {
77
42
  budgetDe,
78
43
  partDe,
79
- partDeclareeDe,
80
44
  plafondDe,
45
+ plafondDeDepart,
81
46
  reserveDe,
82
47
  } from './plafond-de-la-machine.mjs';
83
- import { duree, refusDePart } from './regles-des-places.mjs';
84
- import { attendreUnPeu, lacherVerrou, prendreVerrou } from './verrou-de-fichier.mjs';
48
+ import { SORTE_DE_LA_MONTEE } from './regles-des-places.mjs';
49
+ import { lireLaTable } from './table-des-consommations.mjs';
50
+
51
+ export { SORTE_DE_LA_MONTEE };
85
52
 
86
- // The spacing is a rule (./regles-des-places.mjs), published here too.
87
- export { ESPACEMENT_MS, espacementDe, VARIABLE_ESPACEMENT } from './regles-des-places.mjs';
88
53
  export const VARIABLE_TRAVAILLEURS = 'GRILLHOUSE_TRAVAILLEURS';
89
54
 
90
55
  /**
@@ -96,17 +61,54 @@ export const VARIABLE_TRAVAILLEURS = 'GRILLHOUSE_TRAVAILLEURS';
96
61
  export function sousNiceEtIonice(commande) {
97
62
  return ['nice', '-n', '10', 'ionice', '-c', '2', '-n', '7', ...commande];
98
63
  }
64
+ /**
65
+ * The reservation of the step a session plays (`{ id, coeurs, memoire, limite, limiteCoeurs }` in JSON), which the circuit
66
+ * gives the envelope of the session: the arbiter granted it to the step (src/temporal/places/).
67
+ */
68
+ export const VARIABLE_RESERVATION_D_ETAPE = 'GRILLHOUSE_RESERVATION_D_ETAPE';
69
+
70
+ /**
71
+ * The reservation of the step a session plays, as its environment <env> gives it, null without
72
+ * one.
73
+ * @param {Record<string, string | undefined>} [env]
74
+ * @returns {{ id?: string, coeurs: number, memoire: number, limite?: number,
75
+ * limiteCoeurs?: number } | null} `id`, the id of the reservation, which names the group of the
76
+ * step; `limite` and `limiteCoeurs`, the ceiling of its phase
77
+ * @throws {Error} naming the variable when its value is not a reservation
78
+ */
79
+ export function reservationDeLEtape(env = process.env) {
80
+ const v = env[VARIABLE_RESERVATION_D_ETAPE];
81
+ if (v === undefined || v === '') {
82
+ return null;
83
+ }
84
+ try {
85
+ const { id, coeurs, memoire, limite, limiteCoeurs } = JSON.parse(v);
86
+ if (Number.isInteger(coeurs) && coeurs >= 1 && typeof memoire === 'number' && memoire >= 0) {
87
+ return {
88
+ ...(typeof id === 'string' ? { id } : {}),
89
+ coeurs,
90
+ memoire,
91
+ ...(typeof limite === 'number' ? { limite } : {}),
92
+ ...(Number.isInteger(limiteCoeurs) && limiteCoeurs >= 1 ? { limiteCoeurs } : {}),
93
+ };
94
+ }
95
+ } catch {
96
+ // named below
97
+ }
98
+ throw new Error(
99
+ `${VARIABLE_RESERVATION_D_ETAPE} vaut « ${v} » : { "coeurs": <entier ≥ 1>, "memoire": <octets> } est attendu.`
100
+ );
101
+ }
102
+
99
103
  /** The mark of a place held, which the children of its holder inherit. */
100
104
  export const VARIABLE_TENUE = 'GRILLHOUSE_PLACE_TENUE';
101
105
 
102
- /** The sort of the verification of the update (scripts/grillhouse-maj.mjs), a gesture of the maintenance. */
103
- export const SORTE_DE_LA_MONTEE = 'Montée';
104
106
  /** The measure of the machine a trial fixes, in JSON `{ coeurs, charge, memoireLibre, memoireTotale }`. */
105
107
  export const VARIABLE_MESURE_D_ESSAI = 'GRILLHOUSE_MESURE_D_ESSAI';
106
- /** The directory of the state of the parts a trial names, in place of the user's. */
107
- export const VARIABLE_PARTS = 'GRILLHOUSE_PARTS_DE_LA_MACHINE';
108
- /** The mark of a part held, which the children of its holder inherit. */
109
- export const VARIABLE_PART_TENUE = 'GRILLHOUSE_PART_TENUE';
108
+ /** The phase of the register a caller gives the verification it launches (the queue's). */
109
+ export const VARIABLE_PHASE_DE_VERIFICATION = 'GRILLHOUSE_VERIFICATION_PHASE';
110
+ /** The phase of the register of the session of an agent, which the circuit names to it. */
111
+ export const VARIABLE_PHASE_DE_SEANCE = 'GRILLHOUSE_PHASE_DE_SEANCE';
110
112
  // The server of the places of a trial machine.
111
113
  const VARIABLE_ESSAI = 'GRILLHOUSE_PLACES_D_ESSAI';
112
114
 
@@ -158,7 +160,7 @@ export function surLeServeur(env) {
158
160
  if (env.CI || paquetsDeLEnveloppe(env)) {
159
161
  return null;
160
162
  }
161
- if (env[VARIABLE_PARTS]) {
163
+ if (env[VARIABLE_MESURE_D_ESSAI]) {
162
164
  return env[VARIABLE_ESSAI] ? { ...env, TEMPORAL_ADDRESS: env[VARIABLE_ESSAI] } : null;
163
165
  }
164
166
  return env;
@@ -208,16 +210,19 @@ export function prendreUnRang({ env = process.env } = {}) {
208
210
  }
209
211
 
210
212
  /**
211
- * The request of a place for the process <pid>: its start, its ticket, the root of its project,
212
- * and the rank of its circuit.
213
+ * The request of a reservation for the process <pid>: its start, its ticket, the root of its
214
+ * project, the rank of its circuit, what it reserves (<reservation>) and its sort (a pass's).
213
215
  * @param {{ pid: number, depart?: string | null,
214
- * ticket?: string | null, racine?: string, rang?: number | null }} o
216
+ * ticket?: string | null, racine?: string, rang?: number | null,
217
+ * reservation?: { coeurs: number, memoire: number }, sorte?: string }} o
215
218
  * @returns {{ pid: number, depart: string | null, ticket: string | null, racine?: string | null,
216
- * rang?: number }}
219
+ * rang?: number, coeurs?: number, memoire?: number, sorte?: string }}
217
220
  */
218
- export function demandeDePlace({ pid, depart, ticket = null, racine, rang }) {
221
+ export function demandeDePlace({ pid, depart, ticket = null, racine, rang, reservation, sorte }) {
219
222
  return {
220
223
  pid,
224
+ ...(reservation ? { coeurs: reservation.coeurs, memoire: reservation.memoire } : {}),
225
+ ...(sorte ? { sorte } : {}),
221
226
  depart: depart === undefined ? departDe(pid) : depart,
222
227
  ticket,
223
228
  ...(racine === undefined ? {} : { racine: racineDuDepot(racine) }),
@@ -228,10 +233,10 @@ export function demandeDePlace({ pid, depart, ticket = null, racine, rang }) {
228
233
  /**
229
234
  * Takes a place of the machine, waiting for one, saying why it waits (`dire`), and returns the
230
235
  * place. Where no place is taken, or under a place already held (GRILLHOUSE_PLACE_TENUE), the
231
- * place returned holds nothing.
236
+ * place returned holds nothing. A pass gives its <sorte>, which the board reads.
232
237
  * @param {{ env?: Record<string, string | undefined>, ticket?: string | null, rang?: number,
233
238
  * pid?: number, depart?: string | null, borneMs?: number, rappelMs?: number,
234
- * dire?: (l: string) => void }} [o] `pid` and `depart` name the process of the session (the
239
+ * reservation?: { coeurs: number, memoire: number }, dire?: (l: string) => void }} [o] `pid` and `depart` name the process of the session (the
235
240
  * taking process by default); `rang` the rank of the arrival of the circuit (drawn by the server
236
241
  * when absent)
237
242
  * @returns {{ id: string | null, rang: number | null, env: Record<string, string | undefined>,
@@ -250,13 +255,15 @@ export function prendreUnePlace({
250
255
  rappelMs = RAPPEL_MS,
251
256
  dire = l => process.stdout.write(`${l}\n`),
252
257
  racine = process.cwd(),
258
+ reservation,
259
+ sorte,
253
260
  } = {}) {
254
261
  const e = env[VARIABLE_TENUE] ? null : surLeServeur(env);
255
262
  if (!e) {
256
263
  return { id: null, rang: rang ?? null, env, rendre: () => {}, rattacher: () => {} };
257
264
  }
258
265
  const demande = {
259
- ...demandeDePlace({ pid, depart, ticket, racine, rang }),
266
+ ...demandeDePlace({ pid, depart, ticket, racine, rang, reservation, sorte }),
260
267
  borneMs,
261
268
  rappelMs,
262
269
  };
@@ -274,7 +281,18 @@ export function prendreUnePlace({
274
281
  throw new AttenteDeLaMachine(lignes.at(-1)?.dire ?? 'attente de place bornée', A_REPASSER);
275
282
  }
276
283
  const place = lignes.find(l => l.id);
277
- ecrireLaTrace(racine, traceDesPlaces({ evenement: 'prise', ticket, place: place.id }));
284
+ // The reservation of a pass (cores, memory, who) is written at its taking and its return, so
285
+ // that the reservations held at an instant are read back from the journal alone.
286
+ const tracee = reservation
287
+ ? {
288
+ reservation: {
289
+ coeurs: reservation.coeurs,
290
+ memoireGo: Math.round((reservation.memoire / 2 ** 30) * 100) / 100,
291
+ qui: [ticket, sorte].filter(Boolean).join(' ') || 'passe',
292
+ },
293
+ }
294
+ : {};
295
+ ecrireLaTrace(racine, traceDesPlaces({ evenement: 'prise', ticket, place: place.id, ...tracee }));
278
296
  return {
279
297
  id: place.id,
280
298
  rang: place.rang,
@@ -284,7 +302,10 @@ export function prendreUnePlace({
284
302
  rendre: () => {
285
303
  try {
286
304
  auServeur(e, ['rendre', place.id]);
287
- ecrireLaTrace(racine, traceDesPlaces({ evenement: 'rendue', ticket, place: place.id }));
305
+ ecrireLaTrace(
306
+ racine,
307
+ traceDesPlaces({ evenement: 'rendue', ticket, place: place.id, ...tracee })
308
+ );
288
309
  } catch (x) {
289
310
  if (!(x instanceof AttenteDeLaMachine)) {
290
311
  throw x;
@@ -334,99 +355,12 @@ export function avecUnePlace(seance, options) {
334
355
  return r;
335
356
  }
336
357
 
337
- /**
338
- * The directory of the state of the parts under <env>: GRILLHOUSE_PARTS_DE_LA_MACHINE, else
339
- * `grillhouse/parts` under the state directory of the user (`XDG_STATE_HOME`, else
340
- * `~/.local/state`), common to every project of the machine.
341
- * @param {Record<string, string | undefined>} [env]
342
- * @returns {string}
343
- */
344
- export function dossierDesParts(env = process.env) {
345
- if (env[VARIABLE_PARTS]) {
346
- return env[VARIABLE_PARTS];
347
- }
348
- const etat = env.XDG_STATE_HOME || path.join(env.HOME || homedir(), '.local', 'state');
349
- return path.join(etat, 'grillhouse', 'parts');
350
- }
351
-
352
- /**
353
- * The state of a pass in its file of the parts: `etat` « tient » (its part is held) or « attend »
354
- * (`raison`: what it waits for), and what the board reads besides (`depot`, `copie`, `depuis`,
355
- * `dossier` its progress directory, `depasse` what it consumes beyond its part).
356
- * @typedef {{ id: string, pid: number, depart: any, projet: string, ticket: string | null,
357
- * sorte: string, rang: number, coeurs: number, memoire: number, etat: string, raison?: string,
358
- * depot?: string, copie?: string, depuis?: number, dossier?: string | null,
359
- * depasse?: string | null }} PartDUnePasse
360
- */
361
-
362
- /**
363
- * Writes the state of the pass <passe> in its file of <dossier>, whole or not at all. The file of a
364
- * pass is one: a new state replaces it.
365
- * @param {string} dossier
366
- * @param {{ id: string } & Record<string, unknown>} passe
367
- */
368
- export function poserLaPart(dossier, passe) {
369
- ecrireAtomique(path.join(dossier, `${passe.id}.json`), passe);
370
- }
371
-
372
- /**
373
- * Gives back the part of the pass <id>: its file goes, and the directory when it is empty. A part
374
- * that is not there changes nothing.
375
- * @param {string} dossier
376
- * @param {string} id
377
- */
378
- export function rendreLaPart(dossier, id) {
379
- rmSync(path.join(dossier, `${id}.json`), { force: true });
380
- try {
381
- rmdirSync(dossier);
382
- } catch {
383
- // other parts stand there, or the directory is gone
384
- }
385
- }
386
-
387
- /**
388
- * The parts of <dossier> as the machine holds them: `prises` (the passes that hold their part)
389
- * and `attentes` (those that wait, in the order of their rank). A pass whose process is gone
390
- * (`vivant`, `processusVivant` by default: its pid and its start) frees its part, its file
391
- * removed. A directory that is not there holds none.
392
- * @param {string} dossier
393
- * @param {{ vivant?: (p: PartDUnePasse) => boolean }} [o]
394
- * @returns {{ prises: PartDUnePasse[], attentes: PartDUnePasse[] }}
395
- */
396
- export function lireLesParts(dossier, { vivant = processusVivant } = {}) {
397
- let noms;
398
- try {
399
- noms = readdirSync(dossier).filter(n => n.endsWith('.json'));
400
- } catch {
401
- return { prises: [], attentes: [] };
402
- }
403
- const prises = [];
404
- const attentes = [];
405
- for (const nom of noms) {
406
- let p;
407
- try {
408
- p = JSON.parse(readFileSync(path.join(dossier, nom), 'utf8'));
409
- } catch {
410
- continue;
411
- }
412
- if (!p || typeof p.id !== 'string') {
413
- continue;
414
- }
415
- if (!vivant(p)) {
416
- rmSync(path.join(dossier, nom), { force: true });
417
- continue;
418
- }
419
- (p.etat === 'attend' ? attentes : prises).push(p);
420
- }
421
- return { prises, attentes: attentes.sort((a, b) => a.rang - b.rang) };
422
- }
423
-
424
358
  /**
425
359
  * The machine a pass is judged on under <env>: the one a trial fixes (GRILLHOUSE_MESURE_D_ESSAI),
426
360
  * else the real one.
427
361
  * @param {Record<string, string | undefined>} env
428
362
  */
429
- const machineDe = env => mesureDEssai(env) ?? mesureDeLaMachine();
363
+ export const machineDe = env => mesureDEssai(env) ?? mesureDeLaMachine();
430
364
 
431
365
  /**
432
366
  * The budget of the machine under <env>: its hardware (the one a trial fixes, else the real one)
@@ -437,87 +371,52 @@ const machineDe = env => mesureDEssai(env) ?? mesureDeLaMachine();
437
371
  */
438
372
  export function budgetDeLaPasse(env = process.env) {
439
373
  const m = machineDe(env);
440
- return budgetDe({ coeurs: m.coeurs, memoireTotale: m.memoireTotale }, reserveDe(env, { coeurs: m.coeurs }));
441
- }
442
-
443
- // The memory of a part by its sort, from the build of src/machine/part-par-sorte.ts; null in a
444
- // tree not built (a fresh clone before its build), where the part of the project stands.
445
- function calculParSorte() {
446
- try {
447
- return createRequire(import.meta.url)('../dist/machine/part-par-sorte.js');
448
- } catch (e) {
449
- if (e?.code === 'MODULE_NOT_FOUND') {
450
- return null;
451
- }
452
- throw e;
453
- }
374
+ return budgetDe(
375
+ { coeurs: m.coeurs, memoireTotale: m.memoireTotale },
376
+ reserveDe(env, { coeurs: m.coeurs })
377
+ );
454
378
  }
455
379
 
456
380
  /**
457
- * The part of a pass of the sort <sorte> of the project at <racine> under <env>. Its cores are
458
- * those the key `grillhouse.part` of its main tree's `package.json` declares, else the default
459
- * ones. Its memory comes from the measure of its sort in the register, at 20 peaks or more:
460
- * `memoire`, the reservation the admission counts (their 95th percentile), and `limite`, the
461
- * ceiling of its group (their maximum plus a quarter). Under 20, `memoire` is the declared one,
462
- * else the default, and stands for both: no `limite`.
463
- * @param {{ racine: string, env?: Record<string, string | undefined>,
464
- * sorte?: string }} o <sorte> as the caller names the pass (« Vérification », « séance direct »)
465
- * @returns {{ coeurs: number, memoire: number, limite?: number }}
466
- * @throws {AttenteDeLaMachine} naming the key (code 1) when its value is faulty, before any work
381
+ * The reservation of a pass of the phase <phase> of the project at <racine> under <env>: the cores
382
+ * and the memory the table of the consumptions of the project gives that phase, else the default
383
+ * reservation of the budget (`partDe`: 3 cores); and its ceiling (`limite` in bytes,
384
+ * `limiteCoeurs`: where the group of the step is cut), that of the line of its phase, else its
385
+ * reservation plus a quarter; all within the budget of the machine. No key of the `package.json`
386
+ * of the project enters it.
387
+ * @param {{ racine: string, env?: Record<string, string | undefined>, phase: string }} o
388
+ * @returns {{ coeurs: number, memoire: number, limite: number, limiteCoeurs: number }}
389
+ * @throws {Error} naming the variable of the reserve when it is faulty or leaves nothing
467
390
  */
468
- export function partDeLaPasse({ racine, env = process.env, sorte }) {
469
- const { declaree, faute } = partDeclareeDe(packageDuDepot(racine));
470
- if (faute) {
471
- throw new AttenteDeLaMachine(`✗ ${faute}`, 1);
472
- }
391
+ export function reservationDeLaPasse({ racine, env = process.env, phase }) {
473
392
  const budget = budgetDeLaPasse(env);
474
- const depot = racineDuDepot(racine);
475
- const lignes = lireLaConsommation(depot);
476
- const part = partDe({
477
- declaree,
478
- budget,
479
- pic: plusGrandPicDeJour(lignes),
480
- });
481
- const mesure = sorte
482
- ? calculParSorte()?.memoireDeLaSorte(lignes, sorteDeLaPasse(sorte), budget.memoire)
483
- : null;
484
- return mesure
485
- ? { coeurs: part.coeurs, memoire: mesure.reservation, limite: mesure.limite }
486
- : part;
487
- }
488
-
489
- // The kinds of line the night and the measures of time write are not those of a day, nor are the
490
- // sessions of the agents (« seance-<role> »).
491
- const SORTES_HORS_JOUR = new Set(['nuit', 'tests-de-nuit', 'mesure']);
492
-
493
- /**
494
- * The largest peak of memory (bytes) of the day passes among the <lignes> of a register;
495
- * undefined without one. A line without a readable peak and those of the night, of the measures
496
- * of time and of the sessions do not count.
497
- * @param {Record<string, any>[]} lignes
498
- * @returns {number | undefined}
499
- */
500
- function plusGrandPicDeJour(lignes) {
501
- let pic;
502
- for (const l of lignes) {
503
- const p = l.memoirePic;
504
- if (
505
- SORTES_HORS_JOUR.has(l.sorte) ||
506
- l.sorte.startsWith('mesure') ||
507
- l.sorte.startsWith('seance') ||
508
- typeof p !== 'number' ||
509
- !Number.isFinite(p) ||
510
- p <= 0
511
- ) {
512
- continue;
513
- }
514
- pic = Math.max(pic ?? 0, p);
515
- }
516
- return pic;
393
+ const voulue = lireLaTable(racine)?.phases?.[phase];
394
+ const { coeurs, memoire } = voulue
395
+ ? {
396
+ coeurs: Math.max(1, Math.min(budget.coeurs, voulue.coeurs)),
397
+ memoire: Math.min(budget.memoire, voulue.memoire),
398
+ }
399
+ : partDe({ budget });
400
+ const depart = plafondDeDepart({ coeurs, memoire }, budget);
401
+ return {
402
+ coeurs,
403
+ memoire,
404
+ limite: Math.min(
405
+ budget.memoire,
406
+ typeof voulue?.limite === 'number' ? voulue.limite : depart.limite
407
+ ),
408
+ limiteCoeurs: Math.max(
409
+ 1,
410
+ Math.min(
411
+ budget.coeurs,
412
+ typeof voulue?.limiteCoeurs === 'number' ? voulue.limiteCoeurs : depart.limiteCoeurs
413
+ )
414
+ ),
415
+ };
517
416
  }
518
417
 
519
418
  // The `package.json` of the main tree of the repository at <racine>; empty without one (a
520
- // repository without a package.json declares neither part nor measure).
419
+ // repository without a package.json declares no measure).
521
420
  function packageDuDepot(racine) {
522
421
  try {
523
422
  return JSON.parse(readFileSync(path.join(racineDuDepot(racine), 'package.json'), 'utf8'));
@@ -528,12 +427,12 @@ function packageDuDepot(racine) {
528
427
 
529
428
  /**
530
429
  * The cores a measure of time of the project at <racine> asks for, in threads: the key
531
- * `grillhouse.mesure` of its main tree's `package.json`, else the default part of the budget.
430
+ * `grillhouse.mesure` of its main tree's `package.json`, else the default reservation of the budget.
532
431
  * @param {{ racine: string, budget: { coeurs: number } }} o
533
432
  * @returns {number}
534
433
  * @throws {AttenteDeLaMachine} naming the key (code 1) when its value is faulty, before any work
535
434
  */
536
- function coeursDeLaMesure({ racine, budget }) {
435
+ export function coeursDeLaMesure({ racine, budget }) {
537
436
  const { declaree, faute } = mesureDeclareeDe(packageDuDepot(racine));
538
437
  if (faute) {
539
438
  throw new AttenteDeLaMachine(`✗ ${faute}`, 1);
@@ -541,383 +440,6 @@ function coeursDeLaMesure({ racine, budget }) {
541
440
  return coeursDeLaMesureDe({ declaree, budget });
542
441
  }
543
442
 
544
- // What a part asks of the memory, as the waiting line says it: « 4,3 Go réservés, limite 7,5 Go ».
545
- const memoireDite = ({ memoire, limite }) => {
546
- const go = o => String(Math.round((o / 1024 ** 3) * 10) / 10).replace('.', ',');
547
- return `${go(memoire)} Go réservés, ${limite === null ? 'sans limite' : `limite ${go(limite)} Go`}`;
548
- };
549
-
550
- const RANGS = { 1: 'mesure du cadre', 2: "mesure d'un projet" };
551
- // The rank of a pass among the parts: the kind of its measure first (the frame's before a
552
- // project's), then its time of arrival, so that a smaller rank passes first.
553
- const ECHELLE_DES_RANGS = 1e14;
554
-
555
- // Plays <f> holding the short lock of the admission of <dossier>, so that two passes never judge
556
- // the same free budget at once. The directory is made again when it goes between its making and
557
- // the lock: another pass that gives its part back removes it while it is empty (`rendreLaPart`).
558
- // Once the lock lies in it, it stays.
559
- function sousLAdmission(dossier, f) {
560
- const verrou = path.join(dossier, '.admission');
561
- for (;;) {
562
- mkdirSync(dossier, { recursive: true });
563
- try {
564
- prendreVerrou(verrou, { attendre: true });
565
- break;
566
- } catch (e) {
567
- if (e?.code !== 'ENOENT') {
568
- throw e;
569
- }
570
- }
571
- }
572
- try {
573
- return f();
574
- } finally {
575
- lacherVerrou(verrou);
576
- }
577
- }
578
-
579
- /**
580
- * How a measure reads the load of the threads it was given under <env>: on the machine a trial
581
- * fixes (GRILLHOUSE_MESURE_D_ESSAI) they are at rest, no trial reading the load of the user's
582
- * machine; else the load the system gives (<systeme>).
583
- * @param {Record<string, string | undefined>} [env]
584
- * @param {(fils: number[]) => number | null} [systeme]
585
- * @returns {(fils: number[]) => number | null}
586
- */
587
- export function lecteurDeLaCharge(env = process.env, systeme = chargeDesCoeursDuSysteme) {
588
- return env[VARIABLE_MESURE_D_ESSAI] ? () => 0 : systeme;
589
- }
590
-
591
- /**
592
- * Takes the part of a pass of the project at <racine>, waiting for it, saying what it waits for
593
- * (`dire`) when it begins and every <rappelMs>, and returns it. Room first on the disks the pass
594
- * writes on (`attendreDeLaPlace`), then the part: it is taken once it fits in what the parts held
595
- * leave of the budget and the load and the memory of the machine admit it, the waits of a smaller
596
- * rank passing first. Its state is one file of the parts (`poserLaPart`), « attend » then
597
- * « tient ». The night of a project is a pass like another, of the sort « Nuit »: it takes the part of
598
- * its project. A <mesure> of time takes dedicated cores (`fils`, whole physical
599
- * cores), waits for them and for their rest (<chargeDesCoeurs>: the load of the threads it gives,
600
- * null without a reading, by default `lecteurDeLaCharge`; <topologie>, the topology of the system, for a trial).
601
- * The reservation of the machine (<lireLaReservation>, the places of the server by default) is read at each
602
- * turn of the wait, before the admission lock: under the supervisor's closure the pass waits without bound
603
- * (« machine fermée par le superviseur »); a reading that fails stands for no reservation. Where no part is taken (the envelope of an agent, a part already
604
- * held: GRILLHOUSE_PART_TENUE) the part returned holds nothing. <bornee> false (a session of an
605
- * agent) reserves the memory without a limit.
606
- * @param {{ env?: Record<string, string | undefined>, racine?: string, ticket?: string | null,
607
- * sorte?: string, mesure?: boolean, bornee?: boolean,
608
- * borneMs?: number, rappelMs?: number,
609
- * dire?: (l: string) => void, maintenant?: () => number, dormir?: (ms: number) => void,
610
- * libre?: (d: string) => number, occupe?: (d: string) => string,
611
- * occupeLaCopie?: (r: string) => string }} [o]
612
- * @returns {{ id: string | null,
613
- * part: { coeurs: number, memoire: number, limite?: number | null } | null,
614
- * env: Record<string, string | undefined>, rendre: () => void, raison: string | null }}
615
- * `env`, the environment of its holder's children, with the mark of the part and the workers of
616
- * its tools; `raison`, why no part is held, null when one is
617
- * @throws {AttenteDeLaMachine} at the bound of the wait (code 75), or on a faulty key or reserve
618
- * (code 1), its reason named
619
- */
620
- export function prendreUnePart({
621
- env = process.env,
622
- racine = process.cwd(),
623
- ticket,
624
- sorte,
625
- mesure = false,
626
- bornee = true,
627
- topologie,
628
- chargeDesCoeurs = lecteurDeLaCharge(env),
629
- borneMs = borneDe(env),
630
- rappelMs = RAPPEL_MS,
631
- dire = l => process.stdout.write(`${l}\n`),
632
- maintenant = Date.now,
633
- dormir = attendreUnPeu,
634
- lireLaReservation = () => lirePlaces({ env }).reservation ?? null,
635
- ...disques
636
- } = {}) {
637
- const sans = raison => ({ id: null, part: null, fils: null, env, rendre: () => {}, raison });
638
- if (paquetsDeLEnveloppe(env)) {
639
- return sans("dans l'enveloppe d'un agent");
640
- }
641
- if (env[VARIABLE_PART_TENUE]) {
642
- return sans('sous la part de son parent');
643
- }
644
- // The caller names who the pass is, else its environment does (GRILLHOUSE_VERIFICATION_TICKET,
645
- // GRILLHOUSE_VERIFICATION_SORTE, empty as absent), else « Vérification » and no ticket.
646
- ticket = ticket ?? (env.GRILLHOUSE_VERIFICATION_TICKET || null);
647
- sorte = sorte ?? (env.GRILLHOUSE_VERIFICATION_SORTE || 'Vérification');
648
- const dossier = dossierDesParts(env);
649
- let budget;
650
- let part;
651
- // The precise threads of the budget and the topology they are chosen on.
652
- let budgetFils;
653
- let topo;
654
- try {
655
- budget = budgetDeLaPasse(env);
656
- topo = topologie ?? lireLaTopologie({ nombreDeFils: machineDe(env).coeurs });
657
- budgetFils = budgetEnFils({ topologie: topo, budget: budget.coeurs });
658
- if (mesure) {
659
- const demande = coeursDeLaMesure({ racine, budget });
660
- let fils = filsDeLaMesure({ budget: budgetFils, topologie: topo, demande });
661
- if (fils === null || !topo.lisible) {
662
- // No whole core in the budget, or a topology that does not read: each thread is a core.
663
- topo = { lisible: false, coeurs: topo.coeurs.flatMap(c => c.fils.map(f => ({ fils: [f], noeud: c.noeud }))) };
664
- fils = filsDeLaMesure({ budget: budgetFils, topologie: topo, demande });
665
- dire('la topologie des cœurs ne se lit pas : chaque fil compte pour un cœur.');
666
- }
667
- part = { coeurs: fils, memoire: Math.floor((budget.memoire * fils) / budget.coeurs) };
668
- } else {
669
- part = partDeLaPasse({ racine, env, sorte });
670
- }
671
- } catch (e) {
672
- throw e instanceof AttenteDeLaMachine ? e : new AttenteDeLaMachine(`✗ ${e.message}`, 1);
673
- }
674
- const depot = racineDuDepot(racine);
675
- const rangDeLaPasse = rangDeLaMesure(racine);
676
- const moi = {
677
- id: randomUUID(),
678
- pid: process.pid,
679
- depart: departDe(process.pid),
680
- projet: path.basename(depot),
681
- depot,
682
- copie: racineDeLaCopie(racine),
683
- ticket,
684
- sorte,
685
- rang: rangDeLaPasse * ECHELLE_DES_RANGS + maintenant(),
686
- coeurs: part.coeurs,
687
- memoire: part.memoire,
688
- // Where the group of the pass is cut; null, a session, whose group has no memory bound.
689
- limite: bornee ? (part.limite ?? part.memoire) : null,
690
- dediee: mesure,
691
- depuis: maintenant(),
692
- };
693
- let tenus = null;
694
- try {
695
- attendreDeLaPlace({
696
- env,
697
- dire,
698
- borneMs,
699
- rappelMs,
700
- racine,
701
- maintenant,
702
- dormir,
703
- ...disques,
704
- inscrire: raison => {
705
- poserLaPart(dossier, { ...moi, etat: 'attend', raison });
706
- return () => {};
707
- },
708
- });
709
- let debut = maintenant();
710
- let dit = null;
711
- for (;;) {
712
- // The reservation of the machine is read each turn, before the admission lock, bounded by
713
- // the delay of a call to the server; a reading that fails stands for « no reservation ».
714
- // A pass already admitted (a place held: GRILLHOUSE_PLACE_TENUE) or of the update (sort
715
- // « Montée ») is no new work: the closure does not refuse it, as a drain keeps the pods of
716
- // the system.
717
- let reservation = null;
718
- if (!env[VARIABLE_TENUE] && sorte !== SORTE_DE_LA_MONTEE) {
719
- try {
720
- reservation = lireLaReservation() ?? null;
721
- } catch {
722
- reservation = null;
723
- }
724
- }
725
- const fermee = reservation?.auteur === 'superviseur';
726
- const refus = sousLAdmission(dossier, () => {
727
- const { prises, attentes } = lireLesParts(dossier);
728
- let r = refusDePart(
729
- { prises, attentes },
730
- {
731
- id: moi.id,
732
- rang: moi.rang,
733
- part,
734
- budget,
735
- mesurer: () => machineDe(env),
736
- dediee: mesure,
737
- reservation,
738
- }
739
- );
740
- let fils = null;
741
- if (r === null) {
742
- // The count fits: the precise threads, none held by another pass (a measure's whole
743
- // cores, a free core cut by an ordinary pass's threads does not give one).
744
- fils = choisirLesCoeurs({
745
- budget: budgetFils,
746
- topologie: topo,
747
- tenus: prises.filter(p => p.id !== moi.id).flatMap(p => p.fils ?? []),
748
- demande: part.coeurs,
749
- dedies: mesure,
750
- });
751
- if (fils === null) {
752
- r = mesure
753
- ? `cœurs dédiés : ${part.coeurs} demandés, aucun cœur entier libre`
754
- : `cœurs : ${part.coeurs} demandés, pas assez de fils libres`;
755
- }
756
- }
757
- poserLaPart(
758
- dossier,
759
- r === null ? { ...moi, fils, etat: 'tient' } : { ...moi, etat: 'attend', raison: r }
760
- );
761
- tenus = r === null ? fils : null;
762
- return r;
763
- });
764
- if (refus === null) {
765
- break;
766
- }
767
- const t = maintenant();
768
- if (fermee) {
769
- // The supervisor's order lasts until its contrary: no bound, the wait counts from the reopening.
770
- debut = t;
771
- }
772
- if (t - debut >= borneMs) {
773
- throw new AttenteDeLaMachine(
774
- `⏱ attente de la part bornée à ${duree(borneMs)} (GRILLHOUSE_ATTENTE_MACHINE_MS), ${RANGS[rangDeLaPasse]} : ${refus} ; à repasser (code ${A_REPASSER}).`,
775
- A_REPASSER
776
- );
777
- }
778
- if (dit === null) {
779
- dire(
780
- `⏳ ${RANGS[rangDeLaPasse]}, la passe attend sa part (${part.coeurs} cœurs, ${memoireDite(moi)}) : ${refus}${fermee ? ' ; sans borne, jusqu’à la réouverture.' : ` ; ${duree(borneMs)} au plus.`}`
781
- );
782
- } else if (t - dit >= rappelMs) {
783
- dire(
784
- `⏳ la passe attend sa part (${memoireDite(moi)}) depuis ${duree(t - debut)} : ${refus}.`
785
- );
786
- }
787
- if (dit === null || t - dit >= rappelMs) {
788
- dit = t;
789
- }
790
- dormir(Math.max(1, Math.min(200, borneMs - (maintenant() - debut))));
791
- }
792
- // The rest of the dedicated cores: a measure goes once their load, out of it, is under the
793
- // threshold, within the bound of the wait; without a reading it does not judge that load.
794
- if (mesure) {
795
- let ditCharge = null;
796
- for (;;) {
797
- const charge = chargeDesCoeurs(tenus);
798
- if (charge === null) {
799
- dire('la charge des cœurs dédiés ne se lit pas : la mesure ne la juge pas.');
800
- break;
801
- }
802
- if (charge < SEUIL_DE_CHARGE) {
803
- break;
804
- }
805
- const t = maintenant();
806
- const pct = `${Math.round(charge * 100)} %`;
807
- if (t - debut >= borneMs) {
808
- throw new AttenteDeLaMachine(
809
- `⏱ attente du repos des cœurs dédiés bornée à ${duree(borneMs)} (GRILLHOUSE_ATTENTE_MACHINE_MS), ${RANGS[rangDeLaPasse]} : charge de ${pct} des cœurs dédiés hors la mesure, ${Math.round(SEUIL_DE_CHARGE * 100)} % au plus ; à repasser (code ${A_REPASSER}).`,
810
- A_REPASSER
811
- );
812
- }
813
- if (ditCharge === null || t - ditCharge >= rappelMs) {
814
- dire(`⏳ les cœurs dédiés ne sont pas au repos : charge de ${pct} hors la mesure, ${Math.round(SEUIL_DE_CHARGE * 100)} % au plus.`);
815
- ditCharge = t;
816
- }
817
- dormir(Math.max(1, Math.min(200, borneMs - (maintenant() - debut))));
818
- }
819
- }
820
- if (dit !== null) {
821
- dire(`✓ part prise après ${duree(maintenant() - debut)}.`);
822
- }
823
- } catch (e) {
824
- rendreLaPart(dossier, moi.id);
825
- throw e;
826
- }
827
- const {
828
- GRILLHOUSE_VERIFICATION_SORTE: _sorte,
829
- GRILLHOUSE_VERIFICATION_TICKET: _ticket,
830
- ...enfant
831
- } = env;
832
- // The reservation of the part (cores, memory, who), written at its taking and its return, so
833
- // that the parts held at an instant are read back from the journal alone.
834
- const reservation = {
835
- coeurs: part.coeurs,
836
- memoireGo: Math.round((part.memoire / 2 ** 30) * 100) / 100,
837
- qui: [ticket, sorte].filter(Boolean).join(' ') || 'passe',
838
- };
839
- const tracer = evenement =>
840
- ecrireLaTrace(
841
- racine,
842
- traceDesPlaces({ evenement, ticket: ticket ?? null, place: moi.id, reservation })
843
- );
844
- tracer('prise');
845
- return {
846
- id: moi.id,
847
- part: bornee ? part : { ...part, limite: null },
848
- fils: tenus,
849
- dediee: mesure,
850
- budgetFils,
851
- topologie: topo,
852
- env: {
853
- ...enfant,
854
- [VARIABLE_PART_TENUE]: moi.id,
855
- [VARIABLE_TRAVAILLEURS]: String(part.coeurs),
856
- },
857
- rendre: () => {
858
- rendreLaPart(dossier, moi.id);
859
- tracer('rendue');
860
- },
861
- raison: null,
862
- };
863
- }
864
-
865
- /**
866
- * Names the progress directory <dossier> of the pass that holds the part its environment
867
- * <env> marks (GRILLHOUSE_PART_TENUE), in its file of the parts, where the board reads it; a
868
- * function that takes it out. Nothing without a part held (the envelope of an agent).
869
- * @param {{ env?: Record<string, string | undefined>, dossier: string }} o
870
- * @returns {() => void}
871
- */
872
- export function nommerLAvancement({ env = process.env, dossier }) {
873
- const id = env[VARIABLE_PART_TENUE];
874
- if (!id) {
875
- return () => {};
876
- }
877
- const f = path.join(dossierDesParts(env), `${id}.json`);
878
- const ecrire = d => {
879
- try {
880
- const p = JSON.parse(readFileSync(f, 'utf8'));
881
- ecrireAtomique(f, { ...p, dossier: d });
882
- return true;
883
- } catch {
884
- return false;
885
- }
886
- };
887
- return ecrire(dossier) ? () => void ecrire(null) : () => {};
888
- }
889
-
890
- /**
891
- * Plays <passe> holding a part of the machine, given back at its end, whether it returns or
892
- * throws: its exit code, or, a wait that stops (its bound, 75; a faulty key, 1), its reason said
893
- * and its code. <passe> receives the environment of its children and the part (null where none is
894
- * held); the pass is a command a person runs (`npm test`) and the process itself.
895
- * @param {(env: Record<string, string | undefined>, part: { coeurs: number, memoire: number } | null) => number} passe
896
- * @param {{ env?: Record<string, string | undefined>, racine?: string,
897
- * dire?: (l: string) => void }} [o]
898
- * @returns {number}
899
- */
900
- export function surUnePart(
901
- passe,
902
- { env = process.env, racine = process.cwd(), dire = l => process.stderr.write(`${l}\n`) } = {}
903
- ) {
904
- let prise;
905
- try {
906
- prise = prendreUnePart({ env, racine, dire, sorte: 'Tests' });
907
- } catch (e) {
908
- if (!(e instanceof AttenteDeLaMachine)) {
909
- throw e;
910
- }
911
- dire(e.message);
912
- return e.code;
913
- }
914
- try {
915
- return passe(prise.env, prise.part);
916
- } finally {
917
- prise.rendre();
918
- }
919
- }
920
-
921
443
  /**
922
444
  * The places taken and the waits of the machine under <env>, as the server holds them: `{ plafond,
923
445
  * faute, prises, attentes, circuits }` (`faute`, a value of the ceiling the poste names and the