@roomi-fields/grillhouse 0.54.1 → 0.55.2

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 (238) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +73 -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 +18 -2
  77. package/dist/temporal/places/client.js +28 -3
  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 +24 -21
  104. package/docs/architecture/installation.md +35 -30
  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/coeurs-dedies.mjs +19 -2
  118. package/scripts/consommation-des-passes.mjs +67 -35
  119. package/scripts/consommation.mjs +152 -24
  120. package/scripts/copies-finies.mjs +15 -35
  121. package/scripts/dernier-vert.mjs +4 -5
  122. package/scripts/dette.mjs +5 -3
  123. package/scripts/droits.mjs +2 -2
  124. package/scripts/echantillonneur-de-la-passe.mjs +7 -31
  125. package/scripts/engendres.mjs +5 -61
  126. package/scripts/enveloppe/enveloppe.mjs +30 -34
  127. package/scripts/enveloppe/travail-de-la-copie.mjs +5 -0
  128. package/scripts/etapes.mjs +21 -7
  129. package/scripts/etat-du-depot.mjs +61 -0
  130. package/scripts/faits-du-circuit.mjs +7 -4
  131. package/scripts/fermeture-de-la-machine.d.mts +6 -4
  132. package/scripts/fermeture-de-la-machine.mjs +12 -16
  133. package/scripts/fichier-du-poste.d.mts +9 -0
  134. package/scripts/file-des-tickets.d.mts +0 -18
  135. package/scripts/file-des-tickets.mjs +0 -42
  136. package/scripts/fusion-du-changelog.mjs +1 -1
  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 +43 -3
  169. package/scripts/mesure-de-la-machine.mjs +209 -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/table-des-consommations.mjs +36 -0
  174. package/scripts/migrations.mjs +6 -0
  175. package/scripts/montee.mjs +9 -0
  176. package/scripts/nuit-de-pc2.mjs +628 -0
  177. package/scripts/nuit.sh +8 -131
  178. package/scripts/paquets.mjs +1 -1
  179. package/scripts/passe-de-la-machine.mjs +365 -105
  180. package/scripts/place-du-circuit.d.mts +15 -0
  181. package/scripts/place-du-circuit.mjs +32 -0
  182. package/scripts/places-de-la-machine.mjs +148 -627
  183. package/scripts/places-du-serveur.mjs +43 -16
  184. package/scripts/plafond-de-la-machine.d.mts +8 -13
  185. package/scripts/plafond-de-la-machine.mjs +37 -69
  186. package/scripts/registre-des-entrees.mjs +57 -0
  187. package/scripts/regles-des-places.d.mts +84 -50
  188. package/scripts/regles-des-places.mjs +200 -156
  189. package/scripts/retirer-copie.sh +2 -2
  190. package/scripts/seances.mjs +181 -63
  191. package/scripts/secours.mjs +95 -0
  192. package/scripts/services-du-noyau.mjs +11 -19
  193. package/scripts/sous-commandes.mjs +1 -0
  194. package/scripts/sous-modules.sh +1 -1
  195. package/scripts/superviseur.mjs +16 -7
  196. package/scripts/table-des-consommations.d.mts +9 -0
  197. package/scripts/table-des-consommations.mjs +35 -0
  198. package/scripts/tableau.mjs +33 -19
  199. package/scripts/taches-du-graphe.mjs +124 -2
  200. package/scripts/transitions.d.mts +27 -5
  201. package/scripts/transitions.mjs +125 -104
  202. package/scripts/verdict-de-la-nuit.d.mts +13 -0
  203. package/scripts/verdict-de-la-nuit.mjs +34 -7
  204. package/scripts/verrou-de-fichier.mjs +1 -2
  205. package/scripts/workflows-du-cadre.mjs +2 -2
  206. package/skills/developpeur/SKILL.md +8 -2
  207. package/skills/direct/SKILL.md +5 -0
  208. package/skills/explorateur/SKILL.md +10 -1
  209. package/skills/grill/SKILL.md +2 -4
  210. package/skills/pitmaster/SKILL.md +7 -5
  211. package/skills/pitmaster/references/consigne-agent.md +1 -1
  212. package/skills/relecteur/SKILL.md +4 -1
  213. package/skills/testwriter/SKILL.md +15 -2
  214. package/cadre/templates/projet/.env.example +0 -57
  215. package/cadre/templates/projet/.github/workflows/nuit.yml +0 -139
  216. package/cadre/templates/projet/deployment/README.md +0 -98
  217. package/cadre/templates/projet/deployment/docs/01-INSTALL.md +0 -145
  218. package/cadre/templates/projet/deployment/docs/02-CONFIGURATION.md +0 -117
  219. package/cadre/templates/projet/deployment/docs/03-API.md +0 -264
  220. package/cadre/templates/projet/deployment/docs/04-TROUBLESHOOTING.md +0 -262
  221. package/cadre/templates/projet/deployment/scripts/install.ps1 +0 -100
  222. package/cadre/templates/projet/deployment/scripts/start.ps1 +0 -61
  223. package/cadre/templates/projet/deployment/scripts/stop.ps1 +0 -37
  224. package/cadre/templates/projet/deployment/scripts/test.ps1 +0 -118
  225. package/cadre/templates/projet/ecosystem.config.cjs +0 -73
  226. package/cadre/templates/projet/src/config.ts +0 -68
  227. package/cadre/templates/projet/src/errors.ts +0 -102
  228. package/cadre/templates/projet/src/index.ts +0 -46
  229. package/cadre/templates/projet/src/services/.gitkeep +0 -8
  230. package/cadre/templates/projet/src/types/index.ts +0 -24
  231. package/cadre/templates/projet/src/utils/logger.ts +0 -106
  232. package/cadre/templates/projet/tests/unit/config.spec.ts +0 -68
  233. package/cadre/templates/projet/tests/unit/errors.spec.ts +0 -132
  234. package/cadre/templates/projet/tests/unit/types.spec.ts +0 -73
  235. package/cadre/templates/projet/tsconfig.build.json +0 -14
  236. package/scripts/flux-de-la-nuit.mjs +0 -39
  237. package/scripts/garde-de-la-memoire.mjs +0 -231
  238. package/scripts/repli-de-la-nuit.mjs +0 -184
@@ -1,90 +1,54 @@
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';
50
32
  import path from 'node:path';
51
33
  import { departDe } from './mesure/base-de-passe.mjs';
52
- import { lireLaConsommation, sorteDeLaPasse } from './consommation-des-passes.mjs';
53
- import { ecrireAtomique } from './mesure/avancement.mjs';
34
+ import { coeursDeLaMesureDe, mesureDeclareeDe } from './coeurs-dedies.mjs';
54
35
  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';
36
+ import { AttenteDeLaMachine, borneDe, racineDuDepot } from './attente-de-la-machine.mjs';
73
37
  import { paquetsDeLEnveloppe } from './enveloppe/paquets-du-plan.mjs';
74
38
  import { ecrireLaTrace, traceDesPlaces } from './journal-des-etats.mjs';
75
- import { mesureDeLaMachine, processusVivant } from './mesure-de-la-machine.mjs';
39
+ import { coeursDeLaMachine, mesureDeLaMachine } from './mesure-de-la-machine.mjs';
76
40
  import {
77
41
  budgetDe,
78
42
  partDe,
79
- partDeclareeDe,
80
43
  plafondDe,
44
+ plafondDeDepart,
81
45
  reserveDe,
82
46
  } 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';
47
+ import { SORTE_DE_LA_MONTEE } from './regles-des-places.mjs';
48
+ import { lireLaTable } from './table-des-consommations.mjs';
49
+
50
+ export { SORTE_DE_LA_MONTEE };
85
51
 
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
52
  export const VARIABLE_TRAVAILLEURS = 'GRILLHOUSE_TRAVAILLEURS';
89
53
 
90
54
  /**
@@ -96,17 +60,54 @@ export const VARIABLE_TRAVAILLEURS = 'GRILLHOUSE_TRAVAILLEURS';
96
60
  export function sousNiceEtIonice(commande) {
97
61
  return ['nice', '-n', '10', 'ionice', '-c', '2', '-n', '7', ...commande];
98
62
  }
63
+ /**
64
+ * The reservation of the step a session plays (`{ id, coeurs, memoire, limite, limiteCoeurs }` in JSON), which the circuit
65
+ * gives the envelope of the session: the arbiter granted it to the step (src/temporal/places/).
66
+ */
67
+ export const VARIABLE_RESERVATION_D_ETAPE = 'GRILLHOUSE_RESERVATION_D_ETAPE';
68
+
69
+ /**
70
+ * The reservation of the step a session plays, as its environment <env> gives it, null without
71
+ * one.
72
+ * @param {Record<string, string | undefined>} [env]
73
+ * @returns {{ id?: string, coeurs: number, memoire: number, limite?: number,
74
+ * limiteCoeurs?: number } | null} `id`, the id of the reservation, which names the group of the
75
+ * step; `limite` and `limiteCoeurs`, the ceiling of its phase
76
+ * @throws {Error} naming the variable when its value is not a reservation
77
+ */
78
+ export function reservationDeLEtape(env = process.env) {
79
+ const v = env[VARIABLE_RESERVATION_D_ETAPE];
80
+ if (v === undefined || v === '') {
81
+ return null;
82
+ }
83
+ try {
84
+ const { id, coeurs, memoire, limite, limiteCoeurs } = JSON.parse(v);
85
+ if (Number.isInteger(coeurs) && coeurs >= 1 && typeof memoire === 'number' && memoire >= 0) {
86
+ return {
87
+ ...(typeof id === 'string' ? { id } : {}),
88
+ coeurs,
89
+ memoire,
90
+ ...(typeof limite === 'number' ? { limite } : {}),
91
+ ...(Number.isInteger(limiteCoeurs) && limiteCoeurs >= 1 ? { limiteCoeurs } : {}),
92
+ };
93
+ }
94
+ } catch {
95
+ // named below
96
+ }
97
+ throw new Error(
98
+ `${VARIABLE_RESERVATION_D_ETAPE} vaut « ${v} » : { "coeurs": <entier ≥ 1>, "memoire": <octets> } est attendu.`
99
+ );
100
+ }
101
+
99
102
  /** The mark of a place held, which the children of its holder inherit. */
100
103
  export const VARIABLE_TENUE = 'GRILLHOUSE_PLACE_TENUE';
101
104
 
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
105
  /** The measure of the machine a trial fixes, in JSON `{ coeurs, charge, memoireLibre, memoireTotale }`. */
105
106
  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';
107
+ /** The phase of the register a caller gives the verification it launches (the queue's). */
108
+ export const VARIABLE_PHASE_DE_VERIFICATION = 'GRILLHOUSE_VERIFICATION_PHASE';
109
+ /** The phase of the register of the session of an agent, which the circuit names to it. */
110
+ export const VARIABLE_PHASE_DE_SEANCE = 'GRILLHOUSE_PHASE_DE_SEANCE';
110
111
  // The server of the places of a trial machine.
111
112
  const VARIABLE_ESSAI = 'GRILLHOUSE_PLACES_D_ESSAI';
112
113
 
@@ -120,7 +121,7 @@ const PONT = path.join(import.meta.dirname, 'places-du-serveur.mjs');
120
121
  * @returns {number}
121
122
  */
122
123
  export function travailleursDe({
123
- coeurs = availableParallelism(),
124
+ coeurs = coeursDeLaMachine(),
124
125
  places,
125
126
  env = process.env,
126
127
  } = {}) {
@@ -158,7 +159,7 @@ export function surLeServeur(env) {
158
159
  if (env.CI || paquetsDeLEnveloppe(env)) {
159
160
  return null;
160
161
  }
161
- if (env[VARIABLE_PARTS]) {
162
+ if (env[VARIABLE_MESURE_D_ESSAI]) {
162
163
  return env[VARIABLE_ESSAI] ? { ...env, TEMPORAL_ADDRESS: env[VARIABLE_ESSAI] } : null;
163
164
  }
164
165
  return env;
@@ -208,16 +209,19 @@ export function prendreUnRang({ env = process.env } = {}) {
208
209
  }
209
210
 
210
211
  /**
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.
212
+ * The request of a reservation for the process <pid>: its start, its ticket, the root of its
213
+ * project, the rank of its circuit, what it reserves (<reservation>) and its sort (a pass's).
213
214
  * @param {{ pid: number, depart?: string | null,
214
- * ticket?: string | null, racine?: string, rang?: number | null }} o
215
+ * ticket?: string | null, racine?: string, rang?: number | null,
216
+ * reservation?: { coeurs: number, memoire: number }, sorte?: string }} o
215
217
  * @returns {{ pid: number, depart: string | null, ticket: string | null, racine?: string | null,
216
- * rang?: number }}
218
+ * rang?: number, coeurs?: number, memoire?: number, sorte?: string }}
217
219
  */
218
- export function demandeDePlace({ pid, depart, ticket = null, racine, rang }) {
220
+ export function demandeDePlace({ pid, depart, ticket = null, racine, rang, reservation, sorte }) {
219
221
  return {
220
222
  pid,
223
+ ...(reservation ? { coeurs: reservation.coeurs, memoire: reservation.memoire } : {}),
224
+ ...(sorte ? { sorte } : {}),
221
225
  depart: depart === undefined ? departDe(pid) : depart,
222
226
  ticket,
223
227
  ...(racine === undefined ? {} : { racine: racineDuDepot(racine) }),
@@ -228,10 +232,10 @@ export function demandeDePlace({ pid, depart, ticket = null, racine, rang }) {
228
232
  /**
229
233
  * Takes a place of the machine, waiting for one, saying why it waits (`dire`), and returns the
230
234
  * place. Where no place is taken, or under a place already held (GRILLHOUSE_PLACE_TENUE), the
231
- * place returned holds nothing.
235
+ * place returned holds nothing. A pass gives its <sorte>, which the board reads.
232
236
  * @param {{ env?: Record<string, string | undefined>, ticket?: string | null, rang?: number,
233
237
  * 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
238
+ * reservation?: { coeurs: number, memoire: number }, dire?: (l: string) => void }} [o] `pid` and `depart` name the process of the session (the
235
239
  * taking process by default); `rang` the rank of the arrival of the circuit (drawn by the server
236
240
  * when absent)
237
241
  * @returns {{ id: string | null, rang: number | null, env: Record<string, string | undefined>,
@@ -250,13 +254,15 @@ export function prendreUnePlace({
250
254
  rappelMs = RAPPEL_MS,
251
255
  dire = l => process.stdout.write(`${l}\n`),
252
256
  racine = process.cwd(),
257
+ reservation,
258
+ sorte,
253
259
  } = {}) {
254
260
  const e = env[VARIABLE_TENUE] ? null : surLeServeur(env);
255
261
  if (!e) {
256
262
  return { id: null, rang: rang ?? null, env, rendre: () => {}, rattacher: () => {} };
257
263
  }
258
264
  const demande = {
259
- ...demandeDePlace({ pid, depart, ticket, racine, rang }),
265
+ ...demandeDePlace({ pid, depart, ticket, racine, rang, reservation, sorte }),
260
266
  borneMs,
261
267
  rappelMs,
262
268
  };
@@ -274,7 +280,18 @@ export function prendreUnePlace({
274
280
  throw new AttenteDeLaMachine(lignes.at(-1)?.dire ?? 'attente de place bornée', A_REPASSER);
275
281
  }
276
282
  const place = lignes.find(l => l.id);
277
- ecrireLaTrace(racine, traceDesPlaces({ evenement: 'prise', ticket, place: place.id }));
283
+ // The reservation of a pass (cores, memory, who) is written at its taking and its return, so
284
+ // that the reservations held at an instant are read back from the journal alone.
285
+ const tracee = reservation
286
+ ? {
287
+ reservation: {
288
+ coeurs: reservation.coeurs,
289
+ memoireGo: Math.round((reservation.memoire / 2 ** 30) * 100) / 100,
290
+ qui: [ticket, sorte].filter(Boolean).join(' ') || 'passe',
291
+ },
292
+ }
293
+ : {};
294
+ ecrireLaTrace(racine, traceDesPlaces({ evenement: 'prise', ticket, place: place.id, ...tracee }));
278
295
  return {
279
296
  id: place.id,
280
297
  rang: place.rang,
@@ -284,7 +301,10 @@ export function prendreUnePlace({
284
301
  rendre: () => {
285
302
  try {
286
303
  auServeur(e, ['rendre', place.id]);
287
- ecrireLaTrace(racine, traceDesPlaces({ evenement: 'rendue', ticket, place: place.id }));
304
+ ecrireLaTrace(
305
+ racine,
306
+ traceDesPlaces({ evenement: 'rendue', ticket, place: place.id, ...tracee })
307
+ );
288
308
  } catch (x) {
289
309
  if (!(x instanceof AttenteDeLaMachine)) {
290
310
  throw x;
@@ -334,99 +354,12 @@ export function avecUnePlace(seance, options) {
334
354
  return r;
335
355
  }
336
356
 
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
357
  /**
425
358
  * The machine a pass is judged on under <env>: the one a trial fixes (GRILLHOUSE_MESURE_D_ESSAI),
426
359
  * else the real one.
427
360
  * @param {Record<string, string | undefined>} env
428
361
  */
429
- const machineDe = env => mesureDEssai(env) ?? mesureDeLaMachine();
362
+ export const machineDe = env => mesureDEssai(env) ?? mesureDeLaMachine();
430
363
 
431
364
  /**
432
365
  * The budget of the machine under <env>: its hardware (the one a trial fixes, else the real one)
@@ -437,87 +370,52 @@ const machineDe = env => mesureDEssai(env) ?? mesureDeLaMachine();
437
370
  */
438
371
  export function budgetDeLaPasse(env = process.env) {
439
372
  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
- }
373
+ return budgetDe(
374
+ { coeurs: m.coeurs, memoireTotale: m.memoireTotale },
375
+ reserveDe(env, { coeurs: m.coeurs })
376
+ );
454
377
  }
455
378
 
456
379
  /**
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
380
+ * The reservation of a pass of the phase <phase> of the project at <racine> under <env>: the cores
381
+ * and the memory the table of the consumptions of the project gives that phase, else the default
382
+ * reservation of the budget (`partDe`: 3 cores, the budget divided by the places); and its ceiling (`limite` in bytes,
383
+ * `limiteCoeurs`: where the group of the step is cut), that of the line of its phase, else its
384
+ * reservation plus a quarter; all within the budget of the machine. No key of the `package.json`
385
+ * of the project enters it.
386
+ * @param {{ racine: string, env?: Record<string, string | undefined>, phase: string }} o
387
+ * @returns {{ coeurs: number, memoire: number, limite: number, limiteCoeurs: number }}
388
+ * @throws {Error} naming the variable of the reserve when it is faulty or leaves nothing
467
389
  */
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
- }
390
+ export function reservationDeLaPasse({ racine, env = process.env, phase }) {
473
391
  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;
392
+ const voulue = lireLaTable(racine)?.phases?.[phase];
393
+ const { coeurs, memoire } = voulue
394
+ ? {
395
+ coeurs: Math.max(1, Math.min(budget.coeurs, voulue.coeurs)),
396
+ memoire: Math.min(budget.memoire, voulue.memoire),
397
+ }
398
+ : partDe({ budget, places: plafondDe(env) });
399
+ const depart = plafondDeDepart({ coeurs, memoire }, budget);
400
+ return {
401
+ coeurs,
402
+ memoire,
403
+ limite: Math.min(
404
+ budget.memoire,
405
+ typeof voulue?.limite === 'number' ? voulue.limite : depart.limite
406
+ ),
407
+ limiteCoeurs: Math.max(
408
+ 1,
409
+ Math.min(
410
+ budget.coeurs,
411
+ typeof voulue?.limiteCoeurs === 'number' ? voulue.limiteCoeurs : depart.limiteCoeurs
412
+ )
413
+ ),
414
+ };
517
415
  }
518
416
 
519
417
  // 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).
418
+ // repository without a package.json declares no measure).
521
419
  function packageDuDepot(racine) {
522
420
  try {
523
421
  return JSON.parse(readFileSync(path.join(racineDuDepot(racine), 'package.json'), 'utf8'));
@@ -528,12 +426,12 @@ function packageDuDepot(racine) {
528
426
 
529
427
  /**
530
428
  * 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.
429
+ * `grillhouse.mesure` of its main tree's `package.json`, else the default reservation of the budget.
532
430
  * @param {{ racine: string, budget: { coeurs: number } }} o
533
431
  * @returns {number}
534
432
  * @throws {AttenteDeLaMachine} naming the key (code 1) when its value is faulty, before any work
535
433
  */
536
- function coeursDeLaMesure({ racine, budget }) {
434
+ export function coeursDeLaMesure({ racine, budget }) {
537
435
  const { declaree, faute } = mesureDeclareeDe(packageDuDepot(racine));
538
436
  if (faute) {
539
437
  throw new AttenteDeLaMachine(`✗ ${faute}`, 1);
@@ -541,383 +439,6 @@ function coeursDeLaMesure({ racine, budget }) {
541
439
  return coeursDeLaMesureDe({ declaree, budget });
542
440
  }
543
441
 
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
442
  /**
922
443
  * The places taken and the waits of the machine under <env>, as the server holds them: `{ plafond,
923
444
  * faute, prises, attentes, circuits }` (`faute`, a value of the ceiling the poste names and the