@roomi-fields/grillhouse 0.29.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +769 -0
  3. package/agents/developpeur.md +0 -1
  4. package/agents/explorateur.md +0 -1
  5. package/agents/questionneur.md +0 -1
  6. package/agents/testwriter.md +0 -1
  7. package/bin/grillhouse.mjs +79 -18
  8. package/cadre/templates/projet/.github/workflows/ci.yml +2 -13
  9. package/cadre/templates/projet/CLAUDE.md +5 -1
  10. package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
  11. package/cadre/templates/projet/package.json +2 -2
  12. package/charte.md +24 -0
  13. package/dist/temporal/acte.d.ts +24 -0
  14. package/dist/temporal/acte.js +139 -0
  15. package/dist/temporal/acte.js.map +1 -0
  16. package/dist/temporal/attributs.d.ts +6 -0
  17. package/dist/temporal/attributs.js +15 -0
  18. package/dist/temporal/attributs.js.map +1 -0
  19. package/dist/temporal/circuit/activites.d.ts +13 -0
  20. package/dist/temporal/circuit/activites.js +33 -0
  21. package/dist/temporal/circuit/activites.js.map +1 -0
  22. package/dist/temporal/circuit/client.d.ts +72 -0
  23. package/dist/temporal/circuit/client.js +247 -0
  24. package/dist/temporal/circuit/client.js.map +1 -0
  25. package/dist/temporal/circuit/commande.d.ts +2 -0
  26. package/dist/temporal/circuit/commande.js +238 -0
  27. package/dist/temporal/circuit/commande.js.map +1 -0
  28. package/dist/temporal/circuit/contrat.d.ts +305 -0
  29. package/dist/temporal/circuit/contrat.js +30 -0
  30. package/dist/temporal/circuit/contrat.js.map +1 -0
  31. package/dist/temporal/circuit/deroule.d.ts +3 -0
  32. package/dist/temporal/circuit/deroule.js +540 -0
  33. package/dist/temporal/circuit/deroule.js.map +1 -0
  34. package/dist/temporal/client.d.ts +47 -0
  35. package/dist/temporal/client.js +69 -0
  36. package/dist/temporal/client.js.map +1 -0
  37. package/dist/temporal/commande.d.ts +2 -0
  38. package/dist/temporal/commande.js +94 -0
  39. package/dist/temporal/commande.js.map +1 -0
  40. package/dist/temporal/deroules.d.ts +5 -0
  41. package/dist/temporal/deroules.js +10 -0
  42. package/dist/temporal/deroules.js.map +1 -0
  43. package/dist/temporal/etat.d.ts +33 -0
  44. package/dist/temporal/etat.js +59 -0
  45. package/dist/temporal/etat.js.map +1 -0
  46. package/dist/temporal/file/activites.d.ts +10 -0
  47. package/dist/temporal/file/activites.js +25 -0
  48. package/dist/temporal/file/activites.js.map +1 -0
  49. package/dist/temporal/file/client.d.ts +4 -0
  50. package/dist/temporal/file/client.js +6 -0
  51. package/dist/temporal/file/client.js.map +1 -0
  52. package/dist/temporal/file/contrat.d.ts +158 -0
  53. package/dist/temporal/file/contrat.js +14 -0
  54. package/dist/temporal/file/contrat.js.map +1 -0
  55. package/dist/temporal/file/deroule.d.ts +15 -0
  56. package/dist/temporal/file/deroule.js +235 -0
  57. package/dist/temporal/file/deroule.js.map +1 -0
  58. package/dist/temporal/installation.d.ts +120 -0
  59. package/dist/temporal/installation.js +386 -0
  60. package/dist/temporal/installation.js.map +1 -0
  61. package/dist/temporal/places/activites.d.ts +8 -0
  62. package/dist/temporal/places/activites.js +13 -0
  63. package/dist/temporal/places/activites.js.map +1 -0
  64. package/dist/temporal/places/client.d.ts +28 -0
  65. package/dist/temporal/places/client.js +64 -0
  66. package/dist/temporal/places/client.js.map +1 -0
  67. package/dist/temporal/places/contrat.d.ts +106 -0
  68. package/dist/temporal/places/contrat.js +21 -0
  69. package/dist/temporal/places/contrat.js.map +1 -0
  70. package/dist/temporal/places/deroule.d.ts +3 -0
  71. package/dist/temporal/places/deroule.js +198 -0
  72. package/dist/temporal/places/deroule.js.map +1 -0
  73. package/dist/temporal/sonde/activites.d.ts +6 -0
  74. package/dist/temporal/sonde/activites.js +52 -0
  75. package/dist/temporal/sonde/activites.js.map +1 -0
  76. package/dist/temporal/sonde/contrat.d.ts +35 -0
  77. package/dist/temporal/sonde/contrat.js +10 -0
  78. package/dist/temporal/sonde/contrat.js.map +1 -0
  79. package/dist/temporal/sonde/deroule.d.ts +3 -0
  80. package/dist/temporal/sonde/deroule.js +39 -0
  81. package/dist/temporal/sonde/deroule.js.map +1 -0
  82. package/dist/temporal/tickets/activites.d.ts +7 -0
  83. package/dist/temporal/tickets/activites.js +81 -0
  84. package/dist/temporal/tickets/activites.js.map +1 -0
  85. package/dist/temporal/tickets/client.d.ts +10 -0
  86. package/dist/temporal/tickets/client.js +31 -0
  87. package/dist/temporal/tickets/client.js.map +1 -0
  88. package/dist/temporal/tickets/contrat.d.ts +56 -0
  89. package/dist/temporal/tickets/contrat.js +13 -0
  90. package/dist/temporal/tickets/contrat.js.map +1 -0
  91. package/dist/temporal/tickets/deroule.d.ts +3 -0
  92. package/dist/temporal/tickets/deroule.js +94 -0
  93. package/dist/temporal/tickets/deroule.js.map +1 -0
  94. package/dist/temporal/travailleur.d.ts +2 -0
  95. package/dist/temporal/travailleur.js +69 -0
  96. package/dist/temporal/travailleur.js.map +1 -0
  97. package/docs/ARCHITECTURE.md +646 -87
  98. package/docs/CADRE.md +27 -0
  99. package/docs/INTERFACE.md +139 -42
  100. package/hooks/crochet.mjs +19 -2
  101. package/hooks/hooks.json +11 -0
  102. package/package.json +16 -4
  103. package/scripts/activites.mjs +2255 -0
  104. package/scripts/aiguillage.d.mts +37 -0
  105. package/scripts/aiguillage.mjs +40 -14
  106. package/scripts/avancement.mjs +155 -26
  107. package/scripts/bilan.mjs +137 -43
  108. package/scripts/cadre.mjs +16 -4
  109. package/scripts/circuit.mjs +993 -4075
  110. package/scripts/circuits-cles.d.mts +4 -0
  111. package/scripts/circuits-cles.mjs +21 -0
  112. package/scripts/circuits-du-serveur.mjs +105 -0
  113. package/scripts/codes-de-sortie.mjs +9 -0
  114. package/scripts/commandes-composees.mjs +45 -41
  115. package/scripts/commandes-du-path.d.mts +7 -0
  116. package/scripts/commandes-du-path.mjs +25 -0
  117. package/scripts/composants-affectes.mjs +64 -21
  118. package/scripts/composition-des-langages.mjs +18 -12
  119. package/scripts/conformite.mjs +56 -28
  120. package/scripts/copies-finies.mjs +52 -47
  121. package/scripts/depart-du-ticket.d.mts +53 -0
  122. package/scripts/depart-du-ticket.mjs +124 -0
  123. package/scripts/dependances-internes.mjs +121 -0
  124. package/scripts/dernier-vert.mjs +61 -34
  125. package/scripts/dette.mjs +32 -11
  126. package/scripts/donnees-cles.mjs +244 -0
  127. package/scripts/droits.mjs +51 -16
  128. package/scripts/effets.mjs +352 -0
  129. package/scripts/empreinte-d-etape.mjs +17 -0
  130. package/scripts/engendres.mjs +15 -5
  131. package/scripts/enveloppe/enveloppe.mjs +259 -55
  132. package/scripts/enveloppe/lancer.sh +14 -18
  133. package/scripts/enveloppe/paquets-du-plan.mjs +2 -2
  134. package/scripts/enveloppe/travail-de-la-copie.mjs +41 -13
  135. package/scripts/etapes.mjs +5 -2
  136. package/scripts/faits-du-circuit.mjs +493 -0
  137. package/scripts/file-des-tickets.d.mts +21 -0
  138. package/scripts/file-des-tickets.mjs +58 -0
  139. package/scripts/flux-des-paquets.mjs +201 -0
  140. package/scripts/gardes-du-cadre.mjs +21 -5
  141. package/scripts/init.mjs +11 -4
  142. package/scripts/integration/file.mjs +544 -434
  143. package/scripts/integration/integrer.mjs +87 -43
  144. package/scripts/integration/rejeu.mjs +45 -13
  145. package/scripts/jointure.d.ts +151 -28
  146. package/scripts/langages/cargo/commandes.mjs +383 -124
  147. package/scripts/langages/cargo/composants.mjs +154 -42
  148. package/scripts/langages/cargo/exemples.mjs +12 -21
  149. package/scripts/langages/cargo/index.mjs +22 -8
  150. package/scripts/langages/cargo/sccache.mjs +8 -14
  151. package/scripts/langages/cargo/tests-de-head.mjs +25 -9
  152. package/scripts/langages/python/commandes.mjs +218 -100
  153. package/scripts/langages/python/composants.mjs +53 -21
  154. package/scripts/langages/python/exemples.mjs +6 -16
  155. package/scripts/langages/python/index.mjs +28 -8
  156. package/scripts/langages/python/lot.mjs +1 -36
  157. package/scripts/langages/typescript/chemins-des-tests.mjs +6 -2
  158. package/scripts/langages/typescript/composants.mjs +9 -3
  159. package/scripts/langages/typescript/consommateurs-arbitres.mjs +40 -14
  160. package/scripts/langages/typescript/consommateurs.mjs +39 -14
  161. package/scripts/langages/typescript/construire.mjs +6 -163
  162. package/scripts/langages/typescript/elements-du-lot.mjs +36 -12
  163. package/scripts/langages/typescript/exemples.mjs +3 -11
  164. package/scripts/langages/typescript/frontieres.mjs +66 -22
  165. package/scripts/langages/typescript/index-interfaces.mjs +36 -13
  166. package/scripts/langages/typescript/index.mjs +50 -61
  167. package/scripts/langages/typescript/interfaces-contre-code.mjs +113 -45
  168. package/scripts/langages/typescript/lecteurs.mjs +36 -11
  169. package/scripts/langages/typescript/migrations/0.23.0-config-vitest.mjs +15 -5
  170. package/scripts/langages/typescript/migrations/0.25.0-chemins-des-tests.mjs +6 -2
  171. package/scripts/langages/typescript/migrations/0.25.0-tailles-des-tests.mjs +6 -2
  172. package/scripts/langages/typescript/migrations/0.30.0-prefixe-des-tickets.mjs +63 -0
  173. package/scripts/langages/typescript/migrations/0.30.0-tailles-des-outils-lourds.mjs +33 -0
  174. package/scripts/langages/typescript/migrations/0.30.0-titres-nommant-un-ticket.mjs +40 -0
  175. package/scripts/langages/typescript/mise-a-jour.mjs +1 -2
  176. package/scripts/langages/typescript/parcours.mjs +12 -4
  177. package/scripts/langages/typescript/regle-des-tests.mjs +9 -3
  178. package/scripts/langages/typescript/resumes.mjs +9 -3
  179. package/scripts/langages/typescript/tailles-des-tests.mjs +93 -20
  180. package/scripts/langages/typescript/tests-de-nuit.mjs +15 -10
  181. package/scripts/langages/typescript/tests.mjs +40 -15
  182. package/scripts/langages/typescript/titres-de-tests.mjs +320 -0
  183. package/scripts/langages/typescript/turbo-des-paquets.mjs +327 -81
  184. package/scripts/langages/typescript/verdict.mjs +4 -2
  185. package/scripts/langages/typescript/verifier.mjs +58 -20
  186. package/scripts/langages/typescript/vitest-config/avancement.reporter.mjs +15 -5
  187. package/scripts/langages/typescript/vitest-config/base.mjs +29 -3
  188. package/scripts/langages/typescript/vitest-config/bornes.mjs +13 -0
  189. package/scripts/langages/typescript/vitest-config/changements.mjs +21 -8
  190. package/scripts/langages/typescript/vitest-config/cibles.mjs +36 -14
  191. package/scripts/langages/typescript/vitest-config/delais.mjs +60 -0
  192. package/scripts/langages/typescript/vitest-config/delais.setup.mjs +11 -0
  193. package/scripts/langages/typescript/vitest-config/duree.classement.mjs +108 -0
  194. package/scripts/langages/typescript/vitest-config/duree.reporter.mjs +56 -59
  195. package/scripts/langages/typescript/vitest-config/lances.mjs +83 -27
  196. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +10 -0
  197. package/scripts/langages/typescript/vitest-config/resultats.mjs +3 -1
  198. package/scripts/langages/typescript/vitest.nuit.config.mjs +4 -0
  199. package/scripts/lint-des-scripts.mjs +58 -0
  200. package/scripts/mesure/base-de-passe.mjs +117 -25
  201. package/scripts/mesure/pression.mjs +12 -6
  202. package/scripts/mesure-de-la-machine.d.mts +21 -0
  203. package/scripts/mesure-de-la-machine.mjs +76 -0
  204. package/scripts/migrations/0.23.0-charte-importee.mjs +6 -2
  205. package/scripts/migrations/0.23.0-crochets-de-seance.mjs +25 -8
  206. package/scripts/migrations/0.23.0-marche-du-projet.mjs +18 -6
  207. package/scripts/migrations/0.23.2-copies-du-cadre.mjs +56 -18
  208. package/scripts/migrations/0.24.12-tri-des-decouvertes.mjs +6 -2
  209. package/scripts/migrations/0.25.0-script-des-tests.mjs +15 -5
  210. package/scripts/migrations/0.30.0-ci-appelle-la-verification.mjs +124 -0
  211. package/scripts/migrations/0.31.0-paquets-dans-le-graphe.mjs +81 -0
  212. package/scripts/migrations.mjs +5 -0
  213. package/scripts/nuit.sh +25 -3
  214. package/scripts/outil.mjs +3 -1
  215. package/scripts/outils-cles.d.mts +24 -0
  216. package/scripts/outils-cles.mjs +18 -8
  217. package/scripts/paquet-npm.mjs +157 -0
  218. package/scripts/paquet.mjs +73 -4
  219. package/scripts/paquets.mjs +46 -10
  220. package/scripts/passe-de-la-machine.mjs +71 -0
  221. package/scripts/places-de-la-machine.mjs +414 -0
  222. package/scripts/places-du-serveur.mjs +170 -0
  223. package/scripts/prefixe-des-tickets.mjs +68 -0
  224. package/scripts/preparation.mjs +25 -8
  225. package/scripts/registre.mjs +9 -4
  226. package/scripts/regles-des-places.d.mts +36 -0
  227. package/scripts/regles-des-places.mjs +70 -0
  228. package/scripts/reponses-du-circuit.d.mts +6 -0
  229. package/scripts/reponses-du-circuit.mjs +28 -0
  230. package/scripts/reprise.mjs +66 -0
  231. package/scripts/resultats.mjs +112 -46
  232. package/scripts/retirer-les-copies-finies.mjs +25 -0
  233. package/scripts/sans-reponse.d.mts +4 -0
  234. package/scripts/sans-reponse.mjs +13 -0
  235. package/scripts/seances.mjs +936 -0
  236. package/scripts/services-du-noyau.mjs +27 -8
  237. package/scripts/session-start.sh +2 -2
  238. package/scripts/sortie.mjs +3 -3
  239. package/scripts/sous-commandes.mjs +41 -10
  240. package/scripts/style-a-l-ecriture.mjs +260 -0
  241. package/scripts/superviseur.mjs +122 -111
  242. package/scripts/tableau.mjs +180 -117
  243. package/scripts/taches-du-graphe.mjs +348 -0
  244. package/scripts/ticket-du-circuit.mjs +216 -0
  245. package/scripts/transitions.d.mts +148 -0
  246. package/scripts/transitions.mjs +1018 -0
  247. package/scripts/verrou-de-fichier.mjs +8 -4
  248. package/scripts/verrou-de-machine.mjs +150 -51
  249. package/scripts/verrous/commande.mjs +50 -17
  250. package/scripts/verrous/ticket-du-sous-agent.mjs +9 -3
  251. package/scripts/verrous/verrou.mjs +42 -14
  252. package/skills/explorateur/SKILL.md +9 -2
  253. package/skills/grill/SKILL.md +1 -1
  254. package/skills/mesure/SKILL.md +3 -0
  255. package/skills/pitmaster/SKILL.md +17 -18
  256. package/skills/pitmaster/references/consigne-agent.md +5 -1
  257. package/skills/release/SKILL.md +3 -3
  258. package/skills/relecteur/SKILL.md +5 -3
  259. package/skills/testwriter/SKILL.md +49 -31
  260. package/scripts/demon.mjs +0 -251
  261. package/scripts/integration/file-attente.mjs +0 -61
  262. package/scripts/langages/cargo/touches.mjs +0 -93
  263. package/scripts/langages/typescript/script-des-tests.mjs +0 -6
@@ -0,0 +1,348 @@
1
+ // The tasks of the graph of the packages, which the modules of every language run the same way: the
2
+ // tests of the packages of a language, and the build of a copy for the plan of a session. A package
3
+ // of any language is a node of the graph the project's task runner reads (a `package.json` beside
4
+ // its manifest, scripts/paquet-npm.mjs), so the cache of its tasks selects what plays again, as
5
+ // Bazel's cache of a test target does, with no choice of the frame's own.
6
+ //
7
+ // The module gives <outil>, the name of the task runner, which this file does not name: the core
8
+ // names no tool (tests/unit/jointure.spec.ts).
9
+ //
10
+ // - `lancerLesTaches` runs `<outil> run <tâche>… --filter=<paquet>… --continue=dependencies-successful`
11
+ // in the project: every task whose dependencies succeed plays to its end, a red hides no other.
12
+ // The paths a targeted run names, and its options, reach the task in the variable
13
+ // `GRILLHOUSE_TESTS` (`TESTS_CIBLES`), JSON `{ arguments, rejouer? }`, which the `env` of the task
14
+ // `test:unit` names: it enters that task's hash alone, so a run by path of a package unchanged
15
+ // replays from the cache, and another path moves the hash. `rejouer`, the moment of the run, is a
16
+ // value no cached run holds: the task plays for real. The variable of the caller never passes on.
17
+ // - `construireDuPlan` is the command `construire --echec <fichier> <plan>` of every module, which
18
+ // the launcher (scripts/enveloppe/lancer.sh) runs in the prepared copy: the session finds built
19
+ // what it reads out of its plan. As Bazel builds the dependencies of a target before the target:
20
+ // for a plan whose every path is a package of the graph, their providers are built first (the
21
+ // builds their builds wait for, read in the runner's plan `run build --filter=<paquet>…
22
+ // --dry=json`), and a failure stops the launch; then the traces of other packages their tests
23
+ // wait for (`grillhouse.traces`, read in the plan of their tests), which the envelope shows
24
+ // read-only, and a failure stops the launch. A task of either step that waits, directly or not,
25
+ // for a task of a package of the plan (`attendentLePlan`) is not played there: as with Bazel's
26
+ // --keep_going, a package of the plan stays a target of the plan even as another's provider, and
27
+ // goes with the plan. Then the packages, the traces of the plan or that wait for it, and what
28
+ // their tests read (`run build <those traces> --filter=<paquet>… --continue=dependencies-successful`),
29
+ // whose failure does not stop the launch. Any other plan, the whole repository (`.`) included, or
30
+ // a path that is no package of the graph, reads the graph of the whole copy dry (`run build
31
+ // --dry=json`), whose failure stops the launch, then builds the copy whole as far as it builds
32
+ // (`run build --continue=dependencies-successful`), whose failure does not stop the launch either.
33
+ // A build that fails without stopping the launch writes in <fichier> the line that says which
34
+ // build failed and what was built, then its output, which the launcher puts in the session's
35
+ // instruction. The exit code: 0 when the launch goes on, a build failure included; 1 for a step
36
+ // that stops it; 2 for a malformed call.
37
+ import { spawnSync } from 'node:child_process';
38
+ import { closeSync, openSync, readFileSync, writeFileSync } from 'node:fs';
39
+ import path from 'node:path';
40
+ import { lireLaListe } from './enveloppe/paquets-du-plan.mjs';
41
+ import { paquets } from './paquets.mjs';
42
+
43
+ /** The name of the script and of the task of the tests of a package, the same for every language. */
44
+ export const SCRIPT_DES_TESTS = 'test:unit';
45
+ // The variable that carries the paths and the options of a targeted run to the task of the tests.
46
+ export const TESTS_CIBLES = 'GRILLHOUSE_TESTS';
47
+ /**
48
+ * Set by the composed command (./commandes-composees.mjs) to the modules of a `verifier` that
49
+ * plays beside the module whose manifest is a package.json: that one passes over the whole graph
50
+ * (`verifier.mjs` of typescript), so the others play no task of the graph again.
51
+ */
52
+ export const GRAPHE_JOUE = 'GRILLHOUSE_GRAPHE_JOUE';
53
+ /** The variable that tells a module it plays after a red one: that pass keeps no green. */
54
+ export const PASSE_ROUGE = 'GRILLHOUSE_PASSE_ROUGE';
55
+ /** The beginning of the name of a trace task, the output of a package that another's tests read. */
56
+ export const TRACE = 'trace:';
57
+ const SANS_INSTALLER = '--no-install';
58
+ const ENTIERE =
59
+ "La construction de la copie entière échoue ; ce qui n'attend pas la construction en échec est construit.";
60
+ const DU_PLAN =
61
+ "La construction des paquets de ton plan échoue ; leurs fournisseurs et ce que leurs tests lisent sans dépendre d'eux sont construits.";
62
+
63
+ /**
64
+ * The name of the package of the graph whose folder is <dossier> (absolute) in <racine>, the
65
+ * `name` of its package.json; null when that folder is no package of the graph, or is out of the
66
+ * frame.
67
+ * @param {string} racine
68
+ * @param {string} dossier
69
+ * @returns {string | null}
70
+ */
71
+ export function nomDuPaquet(racine, dossier) {
72
+ const p = paquets(racine).find(x => !x.hors && path.join(racine, x.dossier) === dossier);
73
+ return typeof p?.pkg?.name === 'string' ? p.pkg.name : null;
74
+ }
75
+
76
+ /**
77
+ * Runs the tasks <taches> of the packages <noms> (all of them when <noms> is empty) with <outil> in
78
+ * <racine>, each task whose dependencies succeed played to its end: its exit code, the runner's.
79
+ * <tests>, when given, is the content of the variable `TESTS_CIBLES` of the run (`{ arguments,
80
+ * rejouer? }`); the variable of <env> never passes on.
81
+ * @param {{ outil: string, racine: string, taches: string[], noms?: Iterable<string>,
82
+ * tests?: { arguments: string[], rejouer?: string }, env?: NodeJS.ProcessEnv }} o
83
+ * @returns {number}
84
+ */
85
+ export function lancerLesTaches({ outil, racine, taches, noms = [], tests, env = process.env }) {
86
+ const e = { ...env };
87
+ delete e[TESTS_CIBLES];
88
+ if (tests) {
89
+ e[TESTS_CIBLES] = JSON.stringify(tests);
90
+ }
91
+ const filtres = [...new Set(noms)].sort().map(n => `--filter=${n}`);
92
+ const r = spawnSync(outil, ['run', ...taches, ...filtres, '--continue=dependencies-successful'], {
93
+ cwd: racine,
94
+ stdio: 'inherit',
95
+ env: e,
96
+ });
97
+ return r.status ?? 1;
98
+ }
99
+
100
+ /**
101
+ * The content of the variable `TESTS_CIBLES` for a targeted run: the paths and options
102
+ * <arguments> it names, and the moment of the run when <force> (the task plays for real); undefined
103
+ * when there is nothing to carry, the variable then unset.
104
+ * @param {{ arguments: string[], force?: boolean }} o
105
+ * @returns {{ arguments: string[], rejouer?: string } | undefined}
106
+ */
107
+ export function testsCibles({ arguments: donnes, force = false }) {
108
+ if (donnes.length === 0 && !force) {
109
+ return undefined;
110
+ }
111
+ return { arguments: donnes, ...(force ? { rejouer: new Date().toISOString() } : {}) };
112
+ }
113
+
114
+ /**
115
+ * The paths and the options of a task of the tests of a package, run by its script: the paths
116
+ * <donnes> its script names (its own folder), each replaced by the paths of the variable
117
+ * `TESTS_CIBLES` of <env> that lie in the same component (<dossierDe>, from an absolute path, the
118
+ * folder of its component or null), and the options of the variable. A task with no path of the
119
+ * variable in its component plays whole what its script names.
120
+ * @param {{ racine: string, donnes: string[], env?: NodeJS.ProcessEnv,
121
+ * dossierDe: (absolu: string) => string | null }} o
122
+ * @returns {{ chemins: string[], options: string[] }}
123
+ */
124
+ export function cheminsDeLaTache({ racine, donnes, env = process.env, dossierDe }) {
125
+ let variable = [];
126
+ try {
127
+ const lu = JSON.parse(env[TESTS_CIBLES] ?? '{}')?.arguments;
128
+ variable = Array.isArray(lu) ? lu.map(String) : [];
129
+ } catch {
130
+ variable = [];
131
+ }
132
+ const nommes = variable.filter(a => !a.startsWith('-'));
133
+ const dossier = chemin => dossierDe(path.resolve(racine, chemin));
134
+ const chemins = donnes.flatMap(g => {
135
+ const d = dossier(g);
136
+ const siens = d === null ? [] : nommes.filter(n => dossier(n) === d);
137
+ return siens.length ? siens : [g];
138
+ });
139
+ return { chemins: [...new Set(chemins)], options: variable.filter(a => a.startsWith('-')) };
140
+ }
141
+
142
+ /**
143
+ * The trace tasks of a plan of the runner (`run … --dry=json`, parsed), its tasks that <garder>
144
+ * keeps: their task ids (`<producer>#trace:<name>`), sorted.
145
+ * @param {{ tasks: { task: string, taskId: string }[] }} plan
146
+ * @param {(t: any) => boolean} [garder]
147
+ * @returns {string[]}
148
+ */
149
+ export const tracesDuPlan = (plan, garder = () => true) =>
150
+ plan.tasks
151
+ .filter(t => t.task.startsWith(TRACE) && garder(t))
152
+ .map(t => t.taskId)
153
+ .sort();
154
+
155
+ /**
156
+ * The tasks of a plan of the runner (`run … --dry=json`, parsed) that wait, directly or not, for a
157
+ * task of one of the packages <paquets>, those tasks included: their task ids. As Bazel under
158
+ * --keep_going, a task that waits for a target of the plan goes with the plan, whose failure is the
159
+ * session's work; the others are the plan's providers.
160
+ * @param {{ tasks: { taskId: string, package: string, dependencies?: string[] }[] }} plan
161
+ * @param {string[]} paquets
162
+ * @returns {Set<string>}
163
+ */
164
+ function attendentLePlan(plan, paquets) {
165
+ const parId = new Map(plan.tasks.map(t => [t.taskId, t]));
166
+ const verdicts = new Map();
167
+ const attend = id => {
168
+ if (verdicts.has(id)) {
169
+ return verdicts.get(id);
170
+ }
171
+ // A cycle of tasks is no wait on the plan by itself; the runner refuses it anyway.
172
+ verdicts.set(id, false);
173
+ const t = parId.get(id);
174
+ const v =
175
+ t !== undefined && (paquets.includes(t.package) || (t.dependencies ?? []).some(attend));
176
+ verdicts.set(id, v);
177
+ return v;
178
+ };
179
+ return new Set(plan.tasks.map(t => t.taskId).filter(attend));
180
+ }
181
+
182
+ class Arret extends Error {}
183
+
184
+ // The runner with <args> in <racine>, its output on this process's; throws Arret on a failure.
185
+ function jouer(outil, racine, args) {
186
+ const r = spawnSync('npx', [SANS_INSTALLER, outil, ...args], { cwd: racine, stdio: 'inherit' });
187
+ if (r.status !== 0) {
188
+ throw new Arret(`${outil} ${args.join(' ')}`);
189
+ }
190
+ }
191
+
192
+ // The plan of the runner of <args> in <racine>, parsed; throws Arret on a failure.
193
+ function plan(outil, racine, args) {
194
+ const r = spawnSync('npx', [SANS_INSTALLER, outil, ...args, '--dry=json'], {
195
+ cwd: racine,
196
+ encoding: 'utf8',
197
+ maxBuffer: 256 * 1024 * 1024,
198
+ stdio: ['ignore', 'pipe', 'inherit'],
199
+ });
200
+ if (r.status !== 0) {
201
+ throw new Arret(`${outil} ${args.join(' ')} --dry=json`);
202
+ }
203
+ return JSON.parse(r.stdout);
204
+ }
205
+
206
+ /**
207
+ * The hashes of the inputs of the tests tasks of the packages <noms> (by their package name) and
208
+ * of their dependents, as the runner <outil> plans them in <racine> (the hash of a task covers the
209
+ * content of the files it reads and of the tasks it waits for): `{ <paquet>: <hash> }`; null when
210
+ * the runner gives no plan. The fingerprint of a step of the circuit reads it
211
+ * (scripts/reprise.mjs).
212
+ * @param {string} outil the task runner
213
+ * @param {string} racine
214
+ * @param {string[]} noms
215
+ * @returns {Record<string, string> | null}
216
+ */
217
+ export function empreintesDesTaches(outil, racine, noms) {
218
+ if (!noms.length) {
219
+ return {};
220
+ }
221
+ try {
222
+ const graphe = plan(outil, racine, [
223
+ 'run',
224
+ SCRIPT_DES_TESTS,
225
+ ...noms.map(n => `--filter=...${n}`),
226
+ ]);
227
+ return Object.fromEntries((graphe.tasks ?? []).map(t => [t.package, t.hash]));
228
+ } catch {
229
+ return null;
230
+ }
231
+ }
232
+
233
+ // The build <args> in <racine>, its output in <echec> then on this process's: when it fails,
234
+ // <echec> holds <ligne> then that output, and the warning <alerte> follows it.
235
+ function construireJusquOuIlConstruit(outil, racine, args, echec, ligne, alerte) {
236
+ const fd = openSync(echec, 'w');
237
+ let r;
238
+ try {
239
+ r = spawnSync('npx', [SANS_INSTALLER, outil, ...args], {
240
+ cwd: racine,
241
+ stdio: ['ignore', fd, fd],
242
+ });
243
+ } finally {
244
+ closeSync(fd);
245
+ }
246
+ const sortie = readFileSync(echec, 'utf8');
247
+ process.stdout.write(sortie);
248
+ if (r.status === 0) {
249
+ writeFileSync(echec, '');
250
+ return;
251
+ }
252
+ process.stdout.write(`${alerte}\n`);
253
+ writeFileSync(echec, `${ligne}\n${sortie}`);
254
+ }
255
+
256
+ /**
257
+ * Builds the copy at <racine> for the plan <liste> with <outil>, the failure of a build that does
258
+ * not stop the launch written in <echec>: the exit code (see the header).
259
+ * @param {string} outil the task runner
260
+ * @param {string} racine the root of the copy
261
+ * @param {string} liste the plan, in the form of the envelope's variable
262
+ * @param {string} echec the file of a build that fails
263
+ * @returns {number}
264
+ */
265
+ function construire(outil, racine, liste, echec) {
266
+ writeFileSync(echec, '');
267
+ const tous = paquets(racine).filter(p => !p.hors);
268
+ const noms = lireLaListe(liste).map(
269
+ d => tous.find(p => p.dossier === path.normalize(d).replace(/\/$/, ''))?.pkg.name ?? null
270
+ );
271
+ try {
272
+ if (noms.length === 0 || !noms.every(Boolean)) {
273
+ plan(outil, racine, ['run', 'build']);
274
+ construireJusquOuIlConstruit(
275
+ outil,
276
+ racine,
277
+ ['run', 'build', '--continue=dependencies-successful'],
278
+ echec,
279
+ ENTIERE,
280
+ "⚠️ La construction de la copie échoue : la séance s'ouvre, la consigne porte l'erreur."
281
+ );
282
+ return 0;
283
+ }
284
+ const cibles = noms.map(n => `--filter=${n}`);
285
+ // Their providers: the builds their own builds wait for, save those that wait for a package
286
+ // of the plan, which go with the plan below.
287
+ const graphe = plan(outil, racine, ['run', 'build', ...cibles]);
288
+ const avecLePlan = attendentLePlan(graphe, noms);
289
+ const fournisseurs = graphe.tasks
290
+ .map(t => t.taskId)
291
+ .filter(id => !avecLePlan.has(id))
292
+ .sort();
293
+ if (fournisseurs.length) {
294
+ jouer(outil, racine, ['run', ...fournisseurs]);
295
+ }
296
+ // The traces their tests wait for: another package's trace that waits for no package of the
297
+ // plan is produced here, a failure stopping the launch, as a provider's; a trace of the plan,
298
+ // or one that waits for it, is produced with the plan below.
299
+ const tests = plan(outil, racine, ['run', SCRIPT_DES_TESTS, ...cibles]);
300
+ const attend = attendentLePlan(tests, noms);
301
+ const autres = tracesDuPlan(tests, t => !attend.has(t.taskId));
302
+ if (autres.length) {
303
+ jouer(outil, racine, ['run', ...autres]);
304
+ }
305
+ const avec = tracesDuPlan(tests, t => attend.has(t.taskId));
306
+ construireJusquOuIlConstruit(
307
+ outil,
308
+ racine,
309
+ [
310
+ 'run',
311
+ 'build',
312
+ ...avec,
313
+ ...noms.map(n => `--filter=${n}...`),
314
+ '--continue=dependencies-successful',
315
+ ],
316
+ echec,
317
+ DU_PLAN,
318
+ `⚠️ La construction du plan (${noms.join(' ')}) échoue : la séance s'ouvre, la consigne porte l'erreur.`
319
+ );
320
+ return 0;
321
+ } catch (e) {
322
+ if (!(e instanceof Arret)) {
323
+ throw e;
324
+ }
325
+ process.stderr.write(`⛔ ${e.message} échoue.\n`);
326
+ return 1;
327
+ }
328
+ }
329
+
330
+ /**
331
+ * The command `construire --echec <fichier> <plan>` of a module, run from the root of the copy:
332
+ * its exit code. <args> are the arguments after the command's name; a call without the file of a
333
+ * failure and a plan is refused (2).
334
+ * @param {string} outil the task runner
335
+ * @param {string[]} args
336
+ * @param {string} [racine]
337
+ * @returns {number}
338
+ */
339
+ export function construireDepuisLesArguments(outil, args, racine = process.cwd()) {
340
+ const i = args.indexOf('--echec');
341
+ const echec = i >= 0 ? args[i + 1] : undefined;
342
+ const reste = i >= 0 ? [...args.slice(0, i), ...args.slice(i + 2)] : args;
343
+ if (!echec || reste.length !== 1) {
344
+ process.stderr.write('usage: construire --echec <fichier> <plan>\n');
345
+ return 2;
346
+ }
347
+ return construire(outil, racine, reste[0], echec);
348
+ }
@@ -0,0 +1,216 @@
1
+ // The ticket of a circuit, read and written as the circuit and its activities share it
2
+ // (scripts/circuit.mjs, scripts/seances.mjs): its comments and its description in Beads, the
3
+ // sheets and the results of its sessions (`<ticket>.fiches.jsonl`), its log, the components of its
4
+ // repository, and the stop of the circuit (`Arret`). Every function takes the circuit's context
5
+ // <ctx> (`contexte` of scripts/circuit.mjs: `bd`, `ticket`, `fiches`, `journal`, `copie`,
6
+ // `racine`) and holds no state of its own. Its writings at the ticket and among the sheets are
7
+ // effects (scripts/effets.mjs `emettre`), and its readings see those an act of the workflow
8
+ // emitted and has not yet played (`rendusDe`).
9
+ import { appendFileSync, existsSync, readFileSync } from 'node:fs';
10
+ import { gesteDe } from './etapes.mjs';
11
+ import { paquetsDuLangage } from './enveloppe/paquets-du-plan.mjs';
12
+ import { langageDe } from './langages.mjs';
13
+ import { AUTEUR_DU_CIRCUIT, PREFIXE, emettre, rendusDe, sansCouleurs } from './effets.mjs';
14
+
15
+ // The author of a comment, the circuit's, and the start of its lines: those of its one writer.
16
+ export { ACTEUR, AUTEUR_DU_CIRCUIT, PREFIXE, premiereLigne, sansCouleurs } from './effets.mjs';
17
+
18
+ // A stop of the circuit: its name (a key of ARRETS) and its report; for a stop of the checks, its
19
+ // reds read in the structured results (`{ paquet, texte, detail }`) and its motive, the report
20
+ // without their list; the outcome of the step it stops, when it has one (a proof's, the checks'
21
+ // with their reds), which the bilan reads; and what its montée carries beyond the question of its kind (scripts/etapes.mjs,
22
+ // MONTEES): its `piece` (file:line, or command and output), its own `question`, and who must
23
+ // answer it (`qui`, the owner for the reviewer's question).
24
+ export class Arret extends Error {
25
+ constructor(
26
+ nom,
27
+ rapport,
28
+ {
29
+ rouges = null,
30
+ motif = null,
31
+ resultat = null,
32
+ piece = null,
33
+ question = null,
34
+ qui = null,
35
+ etape = null,
36
+ } = {}
37
+ ) {
38
+ super(nom);
39
+ this.nom = nom;
40
+ this.rapport = rapport;
41
+ this.rouges = rouges;
42
+ this.motif = motif;
43
+ this.resultat = resultat;
44
+ this.piece = piece;
45
+ this.question = question;
46
+ this.qui = qui;
47
+ // The step the stop stands at, when it is not the step that throws it.
48
+ this.etape = etape;
49
+ }
50
+ }
51
+
52
+ export const fin = (t, n) => sansCouleurs(t).split('\n').slice(-n).join('\n');
53
+ export const enUneLigne = t =>
54
+ sansCouleurs(t)
55
+ .split('\n')
56
+ .map(l => l.trim())
57
+ .filter(Boolean)
58
+ .join(' ')
59
+ .slice(0, 300);
60
+
61
+ // The components of the repository at <racine> as the module of its language gives them, and the
62
+ // packages out of the frame a plan may name (`paquetsDuLangage`, as the envelope reads them):
63
+ // `{ dossier, pkg: { name }, hors }`, `dossier` relative to <racine>, `.` for a component at its
64
+ // root (a crate whose workspace is its own, as OSC Bridge's).
65
+ export const composantsDe = racine => paquetsDuLangage(langageDe(racine), racine);
66
+
67
+ // Every comment at the ticket, in their order, `{ author, text }` as Beads gives them, then those
68
+ // emitted and not yet played; a failed read throws.
69
+ export function lesCommentaires(ctx) {
70
+ const r = ctx.bd('comments', ctx.ticket, '--json');
71
+ if (r.status !== 0) {
72
+ throw new Error(
73
+ `commentaires de ${ctx.ticket} illisibles : ${r.error?.message ?? r.stderr ?? ''}`.trim()
74
+ );
75
+ }
76
+ return [
77
+ ...(JSON.parse(r.stdout || '[]') ?? []).map(c => ({
78
+ author: String(c.author ?? ''),
79
+ text: String(c.text ?? ''),
80
+ })),
81
+ ...rendusDe(ctx, 'commentaire')
82
+ .filter(e => e.ticket === ctx.ticket)
83
+ .map(e => ({ author: e.auteur ?? AUTEUR_DU_CIRCUIT, text: e.texte })),
84
+ ];
85
+ }
86
+
87
+ // The ticket's description (its criteria), notes, title and labels as Beads holds them at this
88
+ // moment, read at the launch of each session, the plan emitted and not yet played written over
89
+ // them: `{ description, notes, titre, labels }`; a failed read throws.
90
+ export function leTicket(ctx) {
91
+ const r = ctx.bd('show', ctx.ticket, '--json');
92
+ if (r.status !== 0) {
93
+ throw new Error(
94
+ `ticket ${ctx.ticket} illisible : ${r.error?.message ?? r.stderr ?? ''}`.trim()
95
+ );
96
+ }
97
+ const t = JSON.parse(r.stdout || '[]')[0] ?? {};
98
+ const lu = {
99
+ description: String(t.description ?? ''),
100
+ notes: String(t.notes ?? ''),
101
+ titre: String(t.title ?? ''),
102
+ labels: Array.isArray(t.labels) ? t.labels.map(String) : [],
103
+ };
104
+ for (const p of rendusDe(ctx, 'plan')) {
105
+ if (p.titre !== null) {
106
+ lu.titre = p.titre;
107
+ }
108
+ if (p.description !== null) {
109
+ lu.description = p.description;
110
+ }
111
+ }
112
+ return lu;
113
+ }
114
+
115
+ // The comments of the agents at the ticket, `{ author, text }`: every comment but the circuit's
116
+ // own. The circuit reads none of them: it hands an agent's last one to the next session of its
117
+ // author, and names it in a stop.
118
+ export const passations = ctx => lesCommentaires(ctx).filter(c => c.author !== AUTEUR_DU_CIRCUIT);
119
+
120
+ // The last handover at the ticket of the author <qui>, or null.
121
+ export const derniereDe = (ctx, qui) =>
122
+ passations(ctx)
123
+ .filter(c => c.author === qui)
124
+ .at(-1) ?? null;
125
+
126
+ // The sheets of the ticket's sessions and the circuit's reports, in their order
127
+ // (`<ticket>.fiches.jsonl`, beside the copy): `{ date, role, fiche }` for the sheet of a session,
128
+ // `{ date, role: 'circuit', etape, rapport }` for the report of a proof or of checks, which the
129
+ // reviewer receives; then those emitted and not yet played.
130
+ export function lesFiches(ctx) {
131
+ return [
132
+ ...lire(ctx.fiches)
133
+ .split('\n')
134
+ .filter(Boolean)
135
+ .flatMap(l => {
136
+ try {
137
+ return [JSON.parse(l)];
138
+ } catch {
139
+ return [];
140
+ }
141
+ }),
142
+ ...rendusDe(ctx, 'fiche').map(e => e.entree),
143
+ ];
144
+ }
145
+
146
+ // A result kept among the sheets of <ctx>, dated: the effect `fiche`.
147
+ export const inscrire = (ctx, entree) =>
148
+ emettre(ctx, { genre: 'fiche', entree: { date: new Date().toISOString(), ...entree } });
149
+
150
+ // The sheets of <role>, in their order.
151
+ export const fichesDe = (ctx, role) =>
152
+ lesFiches(ctx)
153
+ .filter(e => e.role === role)
154
+ .map(e => e.fiche);
155
+
156
+ // Whether the code of the behaviour is already in the copy: a developpeur session ran after the
157
+ // last testwriter session (a resume past the code, a replay after the developpeur worked a red).
158
+ // A testwriter session after his lowers it, and a new lot with no developpeur since never raises it.
159
+ export const codeDejaPresent = ctx => {
160
+ const roles = lesFiches(ctx)
161
+ .map(e => e.role)
162
+ .filter(r => r === 'testwriter' || r === 'developpeur');
163
+ return roles.at(-1) === 'developpeur';
164
+ };
165
+
166
+ // One line of the circuit's history at the ticket: `Circuit · <étape> : <texte>`, the effect
167
+ // `commentaire`; one not written is said, and the circuit goes on (`ecrireLEffet`).
168
+ export function commenter(ctx, etape, texte) {
169
+ emettre(ctx, {
170
+ genre: 'commentaire',
171
+ ticket: ctx.ticket,
172
+ texte: `${PREFIXE}${etape} : ${texte}`,
173
+ auteur: AUTEUR_DU_CIRCUIT,
174
+ });
175
+ }
176
+
177
+ // The time <d> in local time with its offset, to the second, as ISO 8601 writes it and as the
178
+ // envelope dates the header of a session (`date -Iseconds`): « 2026-10-25T12:42:11+01:00 ».
179
+ export function heureLocale(d = new Date()) {
180
+ const deux = n => String(n).padStart(2, '0');
181
+ const decalage = -d.getTimezoneOffset();
182
+ const a = Math.abs(decalage);
183
+ return `${d.getFullYear()}-${deux(d.getMonth() + 1)}-${deux(d.getDate())}T${deux(d.getHours())}:${deux(d.getMinutes())}:${deux(d.getSeconds())}${decalage < 0 ? '-' : '+'}${deux(Math.floor(a / 60))}:${deux(a % 60)}`;
184
+ }
185
+
186
+ // The header line of a step or a session in the ticket's log, in local time, as the envelope
187
+ // dates a session's.
188
+ export const entete = (ctx, etape) =>
189
+ appendFileSync(ctx.journal, `=== ${heureLocale()} · circuit · ${etape} ===\n`);
190
+
191
+ // The name of each package of <dossiers> as a title writes it: its component's name, or its path.
192
+ export function nomsDe(ctx, dossiers) {
193
+ const liste = composantsDe(existsSync(ctx.copie) ? ctx.copie : ctx.racine);
194
+ return dossiers.map(d => liste.find(p => p.dossier === d)?.pkg.name ?? d);
195
+ }
196
+
197
+ export const lire = f => (existsSync(f) ? readFileSync(f, 'utf8') : '');
198
+
199
+ // The gesture <genre> of the circuit (scripts/etapes.mjs, GESTES), with no session: its line at
200
+ // the ticket and in the log, with its rule.
201
+ export function geste(ctx, genre) {
202
+ const g = gesteDe(genre);
203
+ const texte = `${genre} → ${g.geste} (règle : ${g.regle})`;
204
+ commenter(ctx, 'geste', texte);
205
+ entete(ctx, 'geste');
206
+ appendFileSync(ctx.journal, `geste : ${texte}\n`);
207
+ }
208
+
209
+ // The JSON of the file <f>, or null when it does not read.
210
+ export const lireJson = f => {
211
+ try {
212
+ return JSON.parse(readFileSync(f, 'utf8'));
213
+ } catch {
214
+ return null;
215
+ }
216
+ };