@roomi-fields/grillhouse 0.54.1 → 0.55.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +69 -0
  3. package/cadre/templates/projet/.github/workflows/ci.yml +4 -2
  4. package/cadre/templates/projet/.github/workflows/machine-vierge.yml +5 -42
  5. package/cadre/templates/projet/CONTRIBUTING.md +0 -5
  6. package/cadre/templates/projet/README.md +0 -126
  7. package/cadre/templates/projet/_npmignore +1 -6
  8. package/cadre/templates/projet/package.json +5 -32
  9. package/cadre/templates/projet/tsconfig.json +4 -4
  10. package/cadre/templates/projet/vitest.config.cjs +3 -2
  11. package/charte/tests.md +14 -0
  12. package/dist/machine/part-par-sorte.d.ts +9 -9
  13. package/dist/machine/part-par-sorte.js +20 -24
  14. package/dist/machine/part-par-sorte.js.map +1 -1
  15. package/dist/machine/table-des-consommations.d.ts +65 -0
  16. package/dist/machine/table-des-consommations.js +94 -0
  17. package/dist/machine/table-des-consommations.js.map +1 -0
  18. package/dist/temporal/circuit/activites.d.ts +2 -0
  19. package/dist/temporal/circuit/activites.js +87 -3
  20. package/dist/temporal/circuit/activites.js.map +1 -1
  21. package/dist/temporal/circuit/client.js +9 -4
  22. package/dist/temporal/circuit/client.js.map +1 -1
  23. package/dist/temporal/circuit/contrat.d.ts +32 -4
  24. package/dist/temporal/circuit/deroule.js +54 -4
  25. package/dist/temporal/circuit/deroule.js.map +1 -1
  26. package/dist/temporal/circuit/versions.d.ts +12 -0
  27. package/dist/temporal/circuit/versions.js +22 -0
  28. package/dist/temporal/circuit/versions.js.map +1 -0
  29. package/dist/temporal/consommation/activites.d.ts +2 -0
  30. package/dist/temporal/consommation/activites.js +9 -0
  31. package/dist/temporal/consommation/activites.js.map +1 -0
  32. package/dist/temporal/consommation/actualisation.d.ts +2 -0
  33. package/dist/temporal/consommation/actualisation.js +71 -0
  34. package/dist/temporal/consommation/actualisation.js.map +1 -0
  35. package/dist/temporal/consommation/client.d.ts +12 -0
  36. package/dist/temporal/consommation/client.js +28 -0
  37. package/dist/temporal/consommation/client.js.map +1 -0
  38. package/dist/temporal/consommation/commande.d.ts +5 -0
  39. package/dist/temporal/consommation/commande.js +32 -0
  40. package/dist/temporal/consommation/commande.js.map +1 -0
  41. package/dist/temporal/consommation/contrat.d.ts +15 -0
  42. package/dist/temporal/consommation/contrat.js +13 -0
  43. package/dist/temporal/consommation/contrat.js.map +1 -0
  44. package/dist/temporal/consommation/deroule.d.ts +2 -0
  45. package/dist/temporal/consommation/deroule.js +14 -0
  46. package/dist/temporal/consommation/deroule.js.map +1 -0
  47. package/dist/temporal/deroules.d.ts +2 -1
  48. package/dist/temporal/deroules.js +3 -2
  49. package/dist/temporal/deroules.js.map +1 -1
  50. package/dist/temporal/file/contrat.d.ts +2 -0
  51. package/dist/temporal/file/deroule.js +14 -4
  52. package/dist/temporal/file/deroule.js.map +1 -1
  53. package/dist/temporal/installation.d.ts +6 -0
  54. package/dist/temporal/installation.js +15 -0
  55. package/dist/temporal/installation.js.map +1 -1
  56. package/dist/temporal/nuits/activites.d.ts +2 -1
  57. package/dist/temporal/nuits/activites.js +127 -3
  58. package/dist/temporal/nuits/activites.js.map +1 -1
  59. package/dist/temporal/nuits/client.d.ts +19 -5
  60. package/dist/temporal/nuits/client.js +33 -23
  61. package/dist/temporal/nuits/client.js.map +1 -1
  62. package/dist/temporal/nuits/commande.js +16 -11
  63. package/dist/temporal/nuits/commande.js.map +1 -1
  64. package/dist/temporal/nuits/contrat.d.ts +29 -0
  65. package/dist/temporal/nuits/contrat.js +10 -0
  66. package/dist/temporal/nuits/contrat.js.map +1 -1
  67. package/dist/temporal/nuits/deroule.d.ts +5 -0
  68. package/dist/temporal/nuits/deroule.js +18 -1
  69. package/dist/temporal/nuits/deroule.js.map +1 -1
  70. package/dist/temporal/nuits/pc2.d.ts +72 -0
  71. package/dist/temporal/nuits/pc2.js +206 -0
  72. package/dist/temporal/nuits/pc2.js.map +1 -0
  73. package/dist/temporal/places/activites.d.ts +23 -1
  74. package/dist/temporal/places/activites.js +38 -2
  75. package/dist/temporal/places/activites.js.map +1 -1
  76. package/dist/temporal/places/client.d.ts +16 -0
  77. package/dist/temporal/places/client.js +25 -1
  78. package/dist/temporal/places/client.js.map +1 -1
  79. package/dist/temporal/places/contrat.d.ts +79 -14
  80. package/dist/temporal/places/contrat.js +7 -0
  81. package/dist/temporal/places/contrat.js.map +1 -1
  82. package/dist/temporal/places/deroule.js +159 -23
  83. package/dist/temporal/places/deroule.js.map +1 -1
  84. package/dist/temporal/places/reservation.d.ts +54 -0
  85. package/dist/temporal/places/reservation.js +69 -0
  86. package/dist/temporal/places/reservation.js.map +1 -0
  87. package/dist/temporal/planification.d.ts +6 -0
  88. package/dist/temporal/planification.js +26 -0
  89. package/dist/temporal/planification.js.map +1 -0
  90. package/dist/temporal/tickets/activites.d.ts +0 -2
  91. package/dist/temporal/tickets/activites.js +2 -52
  92. package/dist/temporal/tickets/activites.js.map +1 -1
  93. package/dist/temporal/tickets/contrat.d.ts +7 -26
  94. package/dist/temporal/tickets/deroule.js +35 -23
  95. package/dist/temporal/tickets/deroule.js.map +1 -1
  96. package/dist/temporal/travailleur.js +2 -0
  97. package/dist/temporal/travailleur.js.map +1 -1
  98. package/docs/ARCHITECTURE.md +2 -2
  99. package/docs/CADRE.md +1 -1
  100. package/docs/INTERFACE.md +16 -11
  101. package/docs/architecture/circuit.md +62 -58
  102. package/docs/architecture/entree.md +87 -63
  103. package/docs/architecture/greffon.md +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/consommation-des-passes.mjs +67 -31
  118. package/scripts/consommation.mjs +152 -24
  119. package/scripts/copies-finies.mjs +15 -35
  120. package/scripts/dernier-vert.mjs +4 -5
  121. package/scripts/dette.mjs +5 -3
  122. package/scripts/droits.mjs +2 -2
  123. package/scripts/echantillonneur-de-la-passe.mjs +7 -31
  124. package/scripts/engendres.mjs +5 -61
  125. package/scripts/enveloppe/enveloppe.mjs +30 -34
  126. package/scripts/enveloppe/travail-de-la-copie.mjs +5 -0
  127. package/scripts/etapes.mjs +21 -7
  128. package/scripts/etat-du-depot.mjs +61 -0
  129. package/scripts/faits-du-circuit.mjs +7 -4
  130. package/scripts/fermeture-de-la-machine.d.mts +6 -4
  131. package/scripts/fermeture-de-la-machine.mjs +12 -16
  132. package/scripts/fichier-du-poste.d.mts +9 -0
  133. package/scripts/file-des-tickets.d.mts +0 -18
  134. package/scripts/file-des-tickets.mjs +0 -42
  135. package/scripts/fusion-du-changelog.mjs +1 -1
  136. package/scripts/grillhouse-maj.mjs +1 -1
  137. package/scripts/index-des-rouges.d.mts +40 -0
  138. package/scripts/index-des-rouges.mjs +104 -0
  139. package/scripts/integration/file.mjs +13 -63
  140. package/scripts/integration/integrer.mjs +157 -424
  141. package/scripts/integration/jugement.mjs +109 -0
  142. package/scripts/integration/rejeu.mjs +94 -71
  143. package/scripts/jointure.d.ts +34 -27
  144. package/scripts/journal-des-etats.d.mts +1 -1
  145. package/scripts/langages/c/commandes.mjs +27 -12
  146. package/scripts/langages/cargo/commandes.mjs +148 -94
  147. package/scripts/langages/cargo/index.mjs +2 -1
  148. package/scripts/langages/cargo/lectures-des-tests.mjs +132 -0
  149. package/scripts/langages/cargo/migrations/lectures-des-tests.mjs +31 -0
  150. package/scripts/langages/python/commandes.mjs +31 -15
  151. package/scripts/langages/python/index.mjs +2 -1
  152. package/scripts/langages/python/lectures-des-tests.mjs +148 -0
  153. package/scripts/langages/python/migrations/lectures-des-tests.mjs +31 -0
  154. package/scripts/langages/typescript/consommateurs-arbitres.mjs +2 -2
  155. package/scripts/langages/typescript/index.mjs +4 -0
  156. package/scripts/langages/typescript/lectures-des-tests.mjs +95 -0
  157. package/scripts/langages/typescript/migrations/lectures-des-tests.mjs +31 -0
  158. package/scripts/langages/typescript/tests-de-nuit.mjs +9 -15
  159. package/scripts/langages/typescript/tests.mjs +11 -37
  160. package/scripts/langages/typescript/titres-de-tests.mjs +5 -4
  161. package/scripts/langages/typescript/verifier.mjs +74 -44
  162. package/scripts/langages/typescript/vitest-config/base.mjs +3 -3
  163. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +6 -25
  164. package/scripts/lectures-communes.mjs +234 -0
  165. package/scripts/machine.mjs +11 -18
  166. package/scripts/mesure/base-de-passe.mjs +1 -2
  167. package/scripts/mesure-de-la-machine.d.mts +40 -3
  168. package/scripts/mesure-de-la-machine.mjs +201 -11
  169. package/scripts/migrations/0.33.0-ci-du-cadre.mjs +3 -3
  170. package/scripts/migrations/nuit-yml-retire.mjs +25 -0
  171. package/scripts/migrations/part-retiree.mjs +31 -0
  172. package/scripts/migrations.mjs +4 -0
  173. package/scripts/montee.mjs +9 -0
  174. package/scripts/nuit-de-pc2.mjs +628 -0
  175. package/scripts/nuit.sh +8 -131
  176. package/scripts/paquets.mjs +1 -1
  177. package/scripts/passe-de-la-machine.mjs +340 -103
  178. package/scripts/place-du-circuit.d.mts +15 -0
  179. package/scripts/place-du-circuit.mjs +32 -0
  180. package/scripts/places-de-la-machine.mjs +148 -626
  181. package/scripts/places-du-serveur.mjs +26 -13
  182. package/scripts/plafond-de-la-machine.d.mts +8 -13
  183. package/scripts/plafond-de-la-machine.mjs +26 -56
  184. package/scripts/registre-des-entrees.mjs +57 -0
  185. package/scripts/regles-des-places.d.mts +82 -50
  186. package/scripts/regles-des-places.mjs +192 -156
  187. package/scripts/retirer-copie.sh +2 -2
  188. package/scripts/seances.mjs +181 -63
  189. package/scripts/secours.mjs +95 -0
  190. package/scripts/services-du-noyau.mjs +11 -19
  191. package/scripts/sous-commandes.mjs +1 -0
  192. package/scripts/sous-modules.sh +1 -1
  193. package/scripts/superviseur.mjs +16 -7
  194. package/scripts/table-des-consommations.d.mts +9 -0
  195. package/scripts/table-des-consommations.mjs +35 -0
  196. package/scripts/tableau.mjs +33 -19
  197. package/scripts/taches-du-graphe.mjs +124 -2
  198. package/scripts/transitions.d.mts +27 -5
  199. package/scripts/transitions.mjs +122 -104
  200. package/scripts/verdict-de-la-nuit.d.mts +13 -0
  201. package/scripts/verdict-de-la-nuit.mjs +34 -7
  202. package/scripts/verrou-de-fichier.mjs +1 -2
  203. package/scripts/workflows-du-cadre.mjs +2 -2
  204. package/skills/developpeur/SKILL.md +8 -2
  205. package/skills/direct/SKILL.md +5 -0
  206. package/skills/explorateur/SKILL.md +10 -1
  207. package/skills/grill/SKILL.md +2 -4
  208. package/skills/pitmaster/SKILL.md +7 -5
  209. package/skills/pitmaster/references/consigne-agent.md +1 -1
  210. package/skills/relecteur/SKILL.md +4 -1
  211. package/skills/testwriter/SKILL.md +15 -2
  212. package/cadre/templates/projet/.env.example +0 -57
  213. package/cadre/templates/projet/.github/workflows/nuit.yml +0 -139
  214. package/cadre/templates/projet/deployment/README.md +0 -98
  215. package/cadre/templates/projet/deployment/docs/01-INSTALL.md +0 -145
  216. package/cadre/templates/projet/deployment/docs/02-CONFIGURATION.md +0 -117
  217. package/cadre/templates/projet/deployment/docs/03-API.md +0 -264
  218. package/cadre/templates/projet/deployment/docs/04-TROUBLESHOOTING.md +0 -262
  219. package/cadre/templates/projet/deployment/scripts/install.ps1 +0 -100
  220. package/cadre/templates/projet/deployment/scripts/start.ps1 +0 -61
  221. package/cadre/templates/projet/deployment/scripts/stop.ps1 +0 -37
  222. package/cadre/templates/projet/deployment/scripts/test.ps1 +0 -118
  223. package/cadre/templates/projet/ecosystem.config.cjs +0 -73
  224. package/cadre/templates/projet/src/config.ts +0 -68
  225. package/cadre/templates/projet/src/errors.ts +0 -102
  226. package/cadre/templates/projet/src/index.ts +0 -46
  227. package/cadre/templates/projet/src/services/.gitkeep +0 -8
  228. package/cadre/templates/projet/src/types/index.ts +0 -24
  229. package/cadre/templates/projet/src/utils/logger.ts +0 -106
  230. package/cadre/templates/projet/tests/unit/config.spec.ts +0 -68
  231. package/cadre/templates/projet/tests/unit/errors.spec.ts +0 -132
  232. package/cadre/templates/projet/tests/unit/types.spec.ts +0 -73
  233. package/cadre/templates/projet/tsconfig.build.json +0 -14
  234. package/scripts/flux-de-la-nuit.mjs +0 -39
  235. package/scripts/garde-de-la-memoire.mjs +0 -231
  236. package/scripts/repli-de-la-nuit.mjs +0 -184
@@ -1,132 +0,0 @@
1
- /**
2
- * Error classes tests
3
- */
4
-
5
- import { describe, it, expect } from 'vitest';
6
- import {
7
- AppError,
8
- ValidationError,
9
- NotFoundError,
10
- AuthenticationError,
11
- AuthorizationError,
12
- ConflictError,
13
- RateLimitError,
14
- ExternalServiceError,
15
- isOperationalError,
16
- } from '../../src/errors.js';
17
-
18
- describe('Error Classes', () => {
19
- describe('AppError', () => {
20
- it('should create error with default values', () => {
21
- const error = new AppError('Test error');
22
- expect(error.message).toBe('Test error');
23
- expect(error.code).toBe('INTERNAL_ERROR');
24
- expect(error.statusCode).toBe(500);
25
- expect(error.isOperational).toBe(true);
26
- });
27
-
28
- it('should create error with custom values', () => {
29
- const error = new AppError('Custom error', 'CUSTOM_CODE', 418, false);
30
- expect(error.message).toBe('Custom error');
31
- expect(error.code).toBe('CUSTOM_CODE');
32
- expect(error.statusCode).toBe(418);
33
- expect(error.isOperational).toBe(false);
34
- });
35
-
36
- it('should have proper stack trace', () => {
37
- const error = new AppError('Test');
38
- expect(error.stack).toBeDefined();
39
- expect(error.stack).toContain('AppError');
40
- });
41
- });
42
-
43
- describe('ValidationError', () => {
44
- it('should create validation error', () => {
45
- const error = new ValidationError('Invalid input');
46
- expect(error.message).toBe('Invalid input');
47
- expect(error.code).toBe('VALIDATION_ERROR');
48
- expect(error.statusCode).toBe(400);
49
- });
50
- });
51
-
52
- describe('NotFoundError', () => {
53
- it('should create not found error', () => {
54
- const error = new NotFoundError('User');
55
- expect(error.message).toBe('User not found');
56
- expect(error.code).toBe('NOT_FOUND');
57
- expect(error.statusCode).toBe(404);
58
- });
59
- });
60
-
61
- describe('AuthenticationError', () => {
62
- it('should create authentication error with default message', () => {
63
- const error = new AuthenticationError();
64
- expect(error.message).toBe('Authentication required');
65
- expect(error.statusCode).toBe(401);
66
- });
67
-
68
- it('should create authentication error with custom message', () => {
69
- const error = new AuthenticationError('Invalid token');
70
- expect(error.message).toBe('Invalid token');
71
- });
72
- });
73
-
74
- describe('AuthorizationError', () => {
75
- it('should create authorization error', () => {
76
- const error = new AuthorizationError();
77
- expect(error.message).toBe('Permission denied');
78
- expect(error.statusCode).toBe(403);
79
- });
80
- });
81
-
82
- describe('ConflictError', () => {
83
- it('should create conflict error', () => {
84
- const error = new ConflictError('Resource already exists');
85
- expect(error.statusCode).toBe(409);
86
- });
87
- });
88
-
89
- describe('RateLimitError', () => {
90
- it('should create rate limit error', () => {
91
- const error = new RateLimitError();
92
- expect(error.statusCode).toBe(429);
93
- });
94
- });
95
-
96
- describe('ExternalServiceError', () => {
97
- it('should create external service error', () => {
98
- const error = new ExternalServiceError('PaymentAPI');
99
- expect(error.message).toBe('External service error: PaymentAPI');
100
- expect(error.statusCode).toBe(502);
101
- });
102
-
103
- it('should include original error message', () => {
104
- const original = new Error('Connection timeout');
105
- const error = new ExternalServiceError('PaymentAPI', original);
106
- expect(error.message).toBe('External service error: PaymentAPI - Connection timeout');
107
- });
108
- });
109
-
110
- describe('isOperationalError', () => {
111
- it('should return true for operational errors', () => {
112
- const error = new AppError('Test', 'TEST', 400, true);
113
- expect(isOperationalError(error)).toBe(true);
114
- });
115
-
116
- it('should return false for non-operational errors', () => {
117
- const error = new AppError('Test', 'TEST', 500, false);
118
- expect(isOperationalError(error)).toBe(false);
119
- });
120
-
121
- it('should return false for standard errors', () => {
122
- const error = new Error('Standard error');
123
- expect(isOperationalError(error)).toBe(false);
124
- });
125
-
126
- it('should return false for non-error values', () => {
127
- expect(isOperationalError(null)).toBe(false);
128
- expect(isOperationalError(undefined)).toBe(false);
129
- expect(isOperationalError('string')).toBe(false);
130
- });
131
- });
132
- });
@@ -1,73 +0,0 @@
1
- /**
2
- * Types module tests
3
- */
4
-
5
- import { describe, it, expect } from 'vitest';
6
- import { success, failure, type Result } from '../../src/types/index.js';
7
-
8
- describe('Types', () => {
9
- describe('Result type', () => {
10
- describe('success', () => {
11
- it('should create a success result', () => {
12
- const result = success(42);
13
- expect(result.success).toBe(true);
14
- if (result.success) {
15
- expect(result.data).toBe(42);
16
- }
17
- });
18
-
19
- it('should work with objects', () => {
20
- const data = { id: 1, name: 'Test' };
21
- const result = success(data);
22
- expect(result.success).toBe(true);
23
- if (result.success) {
24
- expect(result.data).toEqual(data);
25
- }
26
- });
27
-
28
- it('should work with arrays', () => {
29
- const data = [1, 2, 3];
30
- const result = success(data);
31
- expect(result.success).toBe(true);
32
- if (result.success) {
33
- expect(result.data).toEqual(data);
34
- }
35
- });
36
- });
37
-
38
- describe('failure', () => {
39
- it('should create a failure result', () => {
40
- const error = new Error('Something went wrong');
41
- const result = failure(error);
42
- expect(result.success).toBe(false);
43
- if (!result.success) {
44
- expect(result.error).toBe(error);
45
- }
46
- });
47
-
48
- it('should work with custom error types', () => {
49
- const customError = { code: 'CUSTOM', message: 'Custom error' };
50
- const result = failure(customError);
51
- expect(result.success).toBe(false);
52
- if (!result.success) {
53
- expect(result.error).toEqual(customError);
54
- }
55
- });
56
- });
57
-
58
- describe('type narrowing', () => {
59
- it('should narrow types correctly', () => {
60
- function processResult(result: Result<number, string>): string {
61
- if (result.success) {
62
- return `Value: ${result.data}`;
63
- } else {
64
- return `Error: ${result.error}`;
65
- }
66
- }
67
-
68
- expect(processResult(success(42))).toBe('Value: 42');
69
- expect(processResult(failure('oops'))).toBe('Error: oops');
70
- });
71
- });
72
- });
73
- });
@@ -1,14 +0,0 @@
1
- {
2
- // The build of the project: src/ into dist/, its tests left out (`npm run build`).
3
- "extends": "./tsconfig.json",
4
- "compilerOptions": {
5
- "noEmit": false,
6
- "outDir": "./dist",
7
- "rootDir": "./src",
8
- "declaration": true,
9
- "declarationMap": true,
10
- "sourceMap": true
11
- },
12
- "include": ["src/**/*"],
13
- "exclude": ["node_modules", "dist", "**/*.{test,spec}.{ts,js,mjs}"]
14
- }
@@ -1,39 +0,0 @@
1
- // What the Nuit flow of a project plays (packages/grillhouse/docs/architecture/entree.md §3.1
2
- // « Repli de la nuit », §5.3 « Les deux parts »; `.github/workflows/nuit.yml`), read from the flow's own
3
- // commands and never from a word of it: the night of the poste (scripts/nuit.sh) leaves the flow
4
- // what the flow declares it plays, and plays the rest (the frame's charter, « Une mesure de temps
5
- // joue la nuit »: the measures of time play on dedicated cores, which a shared flow lacks unless it
6
- // declares a job that plays them).
7
- import { existsSync, readFileSync } from 'node:fs';
8
- import path from 'node:path';
9
- import { fileURLToPath } from 'node:url';
10
-
11
- /** The path of the Nuit flow in a copy. */
12
- export const FLUX_DE_LA_NUIT = '.github/workflows/nuit.yml';
13
-
14
- /**
15
- * Whether the flow written in <texte> plays the measures of time: one of its commands (a line that
16
- * is not a comment) runs `tests-de-nuit` with `--mesures`.
17
- * @param {string} texte
18
- */
19
- export function leFluxJoueLesMesures(texte) {
20
- return texte
21
- .split('\n')
22
- .filter(ligne => !ligne.trim().startsWith('#'))
23
- .some(ligne => /\btests-de-nuit\b.*(?:^|\s)--mesures(?:\s|$)/.test(ligne));
24
- }
25
-
26
- /**
27
- * Whether the Nuit flow of the copy at <racine> plays the measures of time; false without a flow.
28
- * @param {string} racine
29
- */
30
- export function fluxDuProjetJoueLesMesures(racine) {
31
- const f = path.join(racine, FLUX_DE_LA_NUIT);
32
- return existsSync(f) && leFluxJoueLesMesures(readFileSync(f, 'utf8'));
33
- }
34
-
35
- // node flux-de-la-nuit.mjs mesures <copie> exit 0 when the flow of the copy plays the measures
36
- if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
37
- const [commande, copie] = process.argv.slice(2);
38
- process.exitCode = commande === 'mesures' && copie && fluxDuProjetJoueLesMesures(copie) ? 0 : 1;
39
- }
@@ -1,231 +0,0 @@
1
- // The watch of the memory of a pass: a heavy pass runs its command under it, and is cut before the
2
- // kernel kills. Architecture: docs/architecture/machine.md (§3.1, §5.3).
3
- //
4
- // node garde-de-la-memoire.mjs --temoin <file> -- <command> [<argument>…]
5
- //
6
- // - The command runs in the process group of the watch, its streams the caller's: a signal sent
7
- // to the group of a pass (the stop of an act, of a night, of a session) reaches it as it reaches
8
- // the watch.
9
- // - Every PAS ms the watch reads what the machine still gives (`memoireRestante` of
10
- // scripts/mesure-de-la-machine.mjs: the memory available and the free swap) and the pressure of
11
- // the memory (`/proc/pressure/memory`, line `full`, field `avg10`: the share of the last ten
12
- // seconds in which every task waited for memory, in %). The pass is cut (`memoireEpuisee`) under
13
- // MEMOIRE_MIN for memory and swap together, or at SEUIL_PRESSION_MEMOIRE of pressure, which a
14
- // swap held in memory (zram) reaches first.
15
- // - Cut, the watch ends the command and each process born of it (SIGTERM, then SIGKILL after DELAI
16
- // ms for those still alive), writes why in <file>, and exits at 75, « à repasser », once they are
17
- // dead: the pass was not judged, and holds no memory when it gives the machine back.
18
- // - Otherwise it exits with the command's own code; a command a signal ended gives 1, the signal
19
- // said on the error output.
20
- // - A machine that says neither its memory nor its pressure is not watched: the command runs as
21
- // it is.
22
- import { spawn } from 'node:child_process';
23
- import { readdirSync, readFileSync, writeFileSync } from 'node:fs';
24
- import { fileURLToPath, pathToFileURL } from 'node:url';
25
- import { A_REPASSER } from './codes-de-sortie.mjs';
26
- import { departDe, memoireRestante, processusVivant } from './mesure-de-la-machine.mjs';
27
- import { MEMOIRE_MIN } from './regles-des-places.mjs';
28
-
29
- /** This script. */
30
- export const SCRIPT = fileURLToPath(import.meta.url);
31
- /** The variable a trial fixes what the machine gives under: JSON `{ disponible, echange, pression }`. */
32
- export const VARIABLE_MEMOIRE_D_ESSAI = 'GRILLHOUSE_MEMOIRE_D_ESSAI';
33
- /** The pressure of the memory a pass is cut at, in %. */
34
- export const SEUIL_PRESSION_MEMOIRE = 50;
35
- const FICHIER_PRESSION = '/proc/pressure/memory';
36
- const PAS = 2000;
37
- const DELAI = 5000;
38
-
39
- const go = n => (n / 1024 ** 3).toFixed(1).replace('.', ',');
40
-
41
- /**
42
- * The pressure `full avg10` of the memory in <texte> (/proc/pressure/memory), in %; null when it
43
- * does not say it.
44
- * @param {string} texte
45
- * @returns {number | null}
46
- */
47
- export function lireLaPressionDeLaMemoire(texte) {
48
- const m = /^full\b.*\bavg10=(\d+(?:\.\d+)?)/m.exec(texte);
49
- return m ? Number(m[1]) : null;
50
- }
51
-
52
- /**
53
- * Why a pass is cut at this memory, null while it may go on: the memory available and the free
54
- * swap together under MEMOIRE_MIN, or the pressure of the memory at SEUIL_PRESSION_MEMOIRE.
55
- * @param {{ disponible: number | null, echange: number, pression: number | null }} m bytes, %
56
- * @returns {string | null}
57
- */
58
- export function memoireEpuisee({ disponible, echange, pression }) {
59
- const suite =
60
- 'la passe est coupée avant que le système ne tue, à repasser quand la machine a de la place.';
61
- if (disponible !== null && disponible + echange < MEMOIRE_MIN) {
62
- return `mémoire épuisée : ${go(disponible)} Go disponibles et ${go(echange)} Go d'échange libres, sous les ${go(MEMOIRE_MIN)} Go gardés ; ${suite}`;
63
- }
64
- if (pression !== null && pression >= SEUIL_PRESSION_MEMOIRE) {
65
- return `mémoire épuisée : la machine attend sa mémoire ${String(pression).replace('.', ',')} % du temps (seuil ${SEUIL_PRESSION_MEMOIRE} %) ; ${suite}`;
66
- }
67
- return null;
68
- }
69
-
70
- /**
71
- * What the machine gives now under <env>: a trial's, else the kernel's.
72
- * @param {Record<string, string | undefined>} [env]
73
- * @returns {{ disponible: number | null, echange: number, pression: number | null }}
74
- */
75
- export function mesurerLaMemoire(env = process.env) {
76
- if (env[VARIABLE_MEMOIRE_D_ESSAI]) {
77
- return { pression: null, ...JSON.parse(env[VARIABLE_MEMOIRE_D_ESSAI]) };
78
- }
79
- let pression = null;
80
- try {
81
- pression = lireLaPressionDeLaMemoire(readFileSync(FICHIER_PRESSION, 'utf8'));
82
- } catch {
83
- // no pressure stall information on the machine
84
- }
85
- return { ...memoireRestante(), pression };
86
- }
87
-
88
- // The processes born of <pid>, itself left out, as /proc says them now.
89
- function descendants(pid) {
90
- /** @type {Map<number, number[]>} */
91
- const enfants = new Map();
92
- for (const n of readdirSync('/proc')) {
93
- if (!/^\d+$/.test(n)) {
94
- continue;
95
- }
96
- try {
97
- // The fields after the name, which may hold spaces and parentheses: state, then parent.
98
- const stat = readFileSync(`/proc/${n}/stat`, 'utf8');
99
- const parent = Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[1]);
100
- enfants.set(parent, [...(enfants.get(parent) ?? []), Number(n)]);
101
- } catch {
102
- // gone meanwhile
103
- }
104
- }
105
- const nes = [];
106
- for (const file = [pid]; file.length;) {
107
- for (const e of enfants.get(file.shift()) ?? []) {
108
- nes.push(e);
109
- file.push(e);
110
- }
111
- }
112
- return nes;
113
- }
114
-
115
- // <signal> to each process of <relevés> (`{ pid, depart }`) that still is the one relevé.
116
- const signaler = (releves, signal) => {
117
- for (const r of releves) {
118
- if (!processusVivant(r)) {
119
- continue;
120
- }
121
- try {
122
- process.kill(r.pid, signal);
123
- } catch {
124
- // gone
125
- }
126
- }
127
- };
128
-
129
- // The processes <pids> as relevés now: each with its start, which tells it from another process
130
- // that takes its number later.
131
- const relever = pids => pids.map(pid => ({ pid, depart: departDe(pid) })).filter(r => r.depart);
132
-
133
- /**
134
- * Runs <cmd> <args> under the watch: its exit code, 75 when the watch cut it, its witness
135
- * <temoin> then saying why. A cut ends only once the command and every process relevé are dead,
136
- * SIGKILL sent after <delai> ms to those SIGTERM did not end.
137
- * @param {{ cmd: string, args: string[], temoin: string, mesurer?: () => { disponible: number | null, echange: number, pression: number | null }, pas?: number, delai?: number, stdio?: import('node:child_process').StdioOptions, env?: NodeJS.ProcessEnv, cwd?: string }} o
138
- * @returns {Promise<number>}
139
- */
140
- export function veiller({
141
- cmd,
142
- args,
143
- temoin,
144
- mesurer = () => mesurerLaMemoire(),
145
- pas = PAS,
146
- delai = DELAI,
147
- stdio = 'inherit',
148
- env = process.env,
149
- cwd,
150
- }) {
151
- return new Promise(resolve => {
152
- const enfant = spawn(cmd, args, { stdio, env, cwd });
153
- // The processes relevés at the cut, and its end: all dead, or SIGKILL sent at the delay.
154
- let releves = null;
155
- let finDeLaCoupe = null;
156
- const couper = raison => {
157
- // Relevés twice, the command still their ancestor: one born between the two is caught.
158
- const nes = new Set([enfant.pid, ...descendants(enfant.pid)]);
159
- for (const p of descendants(enfant.pid)) {
160
- nes.add(p);
161
- }
162
- releves = relever([...nes]);
163
- signaler(releves, 'SIGTERM');
164
- finDeLaCoupe = new Promise(fin => {
165
- // SIGKILL at the delay to those SIGTERM did not end; the end once none lives, or as long
166
- // again after SIGKILL at the latest.
167
- const limite = Date.now() + delai;
168
- let tues = false;
169
- const voir = setInterval(() => {
170
- const vivants = releves.filter(processusVivant);
171
- if (vivants.length && !tues && Date.now() >= limite) {
172
- tues = true;
173
- signaler(vivants, 'SIGKILL');
174
- }
175
- if (vivants.length === 0 || Date.now() >= limite + delai) {
176
- clearInterval(voir);
177
- fin();
178
- }
179
- }, 100);
180
- });
181
- try {
182
- writeFileSync(temoin, `${raison}\n`);
183
- } catch {
184
- // the exit code alone says the cut
185
- }
186
- };
187
- const veille = setInterval(() => {
188
- if (releves) {
189
- return;
190
- }
191
- let raison = null;
192
- try {
193
- raison = memoireEpuisee(mesurer());
194
- } catch {
195
- // a measure that does not read cuts nothing
196
- }
197
- if (raison) {
198
- couper(raison);
199
- }
200
- }, pas);
201
- enfant.on('error', e => {
202
- clearInterval(veille);
203
- process.stderr.write(`⛔ ${cmd} ne se lance pas : ${e.message}\n`);
204
- resolve(1);
205
- });
206
- enfant.on('exit', (code, signal) => {
207
- clearInterval(veille);
208
- if (finDeLaCoupe) {
209
- void finDeLaCoupe.then(() => resolve(A_REPASSER));
210
- return;
211
- }
212
- if (code === null) {
213
- process.stderr.write(`⛔ ${cmd} est arrêté par le signal ${signal}.\n`);
214
- }
215
- resolve(code ?? 1);
216
- });
217
- });
218
- }
219
-
220
- if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
221
- const args = process.argv.slice(2);
222
- if (args[0] !== '--temoin' || args[2] !== '--' || args.length < 4) {
223
- process.stderr.write(
224
- 'usage: garde-de-la-memoire.mjs --temoin <fichier> -- <commande> [<argument>…]\n'
225
- );
226
- process.exitCode = 2;
227
- } else {
228
- const [cmd, ...reste] = args.slice(3);
229
- process.exitCode = await veiller({ cmd, args: reste, temoin: args[1] });
230
- }
231
- }
@@ -1,184 +0,0 @@
1
- // The fallback of the night (packages/grillhouse/docs/architecture/entree.md §3.1 « Repli de la
2
- // nuit », §5.3 « Les deux parts »): the night of PC3 (scripts/nuit.sh) reads, by `gh`, the jobs
3
- // of the day's Nuit flow, and decides tranche by tranche what PC3 plays in place of PC2, as a queue
4
- // of agents falls back on another capacity (Buildkite) when no agent takes the job in time.
5
- //
6
- // - A tranche finished on PC2, green or red, is never replayed.
7
- // - A tranche whose job has not started 60 minutes after the hour of the flow is cancelled and
8
- // played on PC3, on its part; a tranche started then interrupted (cancelled, a runner lost, never
9
- // started) counts as not played and plays whole again.
10
- // - A tranche that runs, or waits for less than 60 minutes, stays at PC2.
11
- // - The statement says which tranches played where: `pc2` the finished ones, `pc3` the replayed.
12
- // - The measures of time: when the project's flow declares a job that plays them (`mesures`, see
13
- // scripts/flux-de-la-nuit.mjs), the statement says its state (`mesures`: `verte`, `rouge`, `en-cours`,
14
- // or `a-rejouer` when the job was interrupted or never came and the flow is over: PC3 plays them).
15
- // - The flow read is the one of the commit the night plays: a run of another commit counts for none,
16
- // and with no run of that commit every tranche, and the measures, play on PC3.
17
- //
18
- // node repli-de-la-nuit.mjs <dépôt owner/nom> <nombre de tranches> [<identifiant du flux>] [<commit>] the
19
- // decision as JSON, the run cancelled (`gh run cancel`) when a tranche waited too long; a run that
20
- // waits for its group of concurrence, with no job yet, counts every tranche as not started
21
- import { spawnSync } from 'node:child_process';
22
- import { fileURLToPath } from 'node:url';
23
- import path from 'node:path';
24
-
25
- /** The minutes a tranche may wait for its job to start before PC3 plays it. */
26
- export const ATTENTE_MAX_MINUTES = 60;
27
-
28
- const MESURES = /^mesures\b/;
29
- const TRANCHE = /^tranches\b.*?(\d+)\)\s*$/;
30
- // The conclusions of a job that started or was cancelled without finishing its tranche.
31
- const INTERROMPUES = new Set(['cancelled', 'skipped', 'startup_failure']);
32
-
33
- /**
34
- * The decision on the tranches of a Nuit flow.
35
- * @param {{ jobs: { name: string, status: string, conclusion: string | null, startedAt: string | null }[], heureDuFlux: string, maintenant: string, fluxTermine?: boolean }} o
36
- * `jobs` the jobs of the run as `gh run view --json jobs` gives them, `heureDuFlux` the hour the
37
- * flow was created, `maintenant` the present hour, both ISO, `fluxTermine` whether the run is over.
38
- * @returns {{ aRejouer: number[], aAnnuler: number[], enAttente: number[], pc2: number[], pc3: number[], mesures: 'verte' | 'rouge' | 'en-cours' | 'a-rejouer' }}
39
- */
40
- export function choisirLeRepli({ jobs, heureDuFlux, maintenant, fluxTermine = false }) {
41
- const attente = Date.parse(maintenant) - Date.parse(heureDuFlux);
42
- const d = {
43
- aRejouer: [],
44
- aAnnuler: [],
45
- enAttente: [],
46
- enCours: [],
47
- rouges: [],
48
- pc2: [],
49
- pc3: [],
50
- };
51
- const tranches = jobs
52
- .map(j => ({ j, n: Number(TRANCHE.exec(j.name)?.[1]) }))
53
- .filter(({ n }) => Number.isInteger(n) && n > 0)
54
- .sort((a, b) => a.n - b.n);
55
- for (const { j, n } of tranches) {
56
- if (j.status === 'completed') {
57
- if (INTERROMPUES.has(j.conclusion ?? '')) {
58
- d.aRejouer.push(n);
59
- } else {
60
- d.pc2.push(n);
61
- if (j.conclusion !== 'success') {
62
- d.rouges.push(n);
63
- }
64
- }
65
- } else if (j.startedAt || j.status === 'in_progress') {
66
- d.pc2.push(n);
67
- d.enCours.push(n);
68
- } else if (attente >= ATTENTE_MAX_MINUTES * 60_000) {
69
- d.aAnnuler.push(n);
70
- d.aRejouer.push(n);
71
- } else {
72
- d.enAttente.push(n);
73
- }
74
- }
75
- d.pc3 = [...d.aRejouer];
76
- d.mesures = etatDesMesures(
77
- jobs.find(j => MESURES.test(j.name)),
78
- d.aAnnuler.length > 0 || fluxTermine
79
- );
80
- return d;
81
- }
82
-
83
- // The state of the measures job <j> of the flow: its verdict once finished, `en-cours` while it
84
- // waits or runs, `a-rejouer` when it was interrupted, or never came and <termine> (the flow is over
85
- // or cancelled).
86
- function etatDesMesures(j, termine) {
87
- if (!j) {
88
- return termine ? 'a-rejouer' : 'en-cours';
89
- }
90
- if (j.status !== 'completed') {
91
- return termine ? 'a-rejouer' : 'en-cours';
92
- }
93
- if (INTERROMPUES.has(j.conclusion ?? '')) {
94
- return 'a-rejouer';
95
- }
96
- return j.conclusion === 'success' ? 'verte' : 'rouge';
97
- }
98
-
99
- function gh(args) {
100
- const r = spawnSync('gh', args, { encoding: 'utf8' });
101
- if (r.status !== 0) {
102
- throw new Error(`gh ${args.join(' ')} : ${r.stderr || r.error?.message || r.status}`);
103
- }
104
- return r.stdout;
105
- }
106
-
107
- /**
108
- * The id of the latest Nuit run of <commit> (any latest run when <commit> is empty), undefined when
109
- * the flow has none for it.
110
- */
111
- function fluxDuCommit(depot, commit) {
112
- const runs = JSON.parse(
113
- gh([
114
- 'run',
115
- 'list',
116
- '-R',
117
- depot,
118
- '--workflow',
119
- 'nuit.yml',
120
- '--limit',
121
- '20',
122
- '--json',
123
- 'databaseId,headSha',
124
- ])
125
- );
126
- return runs.find(r => !commit || r.headSha === commit)?.databaseId;
127
- }
128
-
129
- if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
130
- const [depot, tranches, identifiant, commit] = process.argv.slice(2);
131
- const n = Number(tranches) || 0;
132
- // No run of the commit the night plays: the flow played none of it, PC3 plays every tranche.
133
- const rien = () => {
134
- const toutes = Array.from({ length: n }, (_, i) => i + 1);
135
- return {
136
- aRejouer: toutes,
137
- aAnnuler: [],
138
- enAttente: [],
139
- enCours: [],
140
- rouges: [],
141
- pc2: [],
142
- pc3: toutes,
143
- mesures: 'a-rejouer',
144
- };
145
- };
146
- try {
147
- const id = identifiant || fluxDuCommit(depot, commit);
148
- if (!id) {
149
- process.stdout.write(`${JSON.stringify({ ...rien(), flux: null })}\n`);
150
- } else {
151
- const run = JSON.parse(
152
- gh(['run', 'view', String(id), '-R', depot, '--json', 'jobs,createdAt,status,headSha'])
153
- );
154
- if (commit && run.headSha !== commit) {
155
- process.stdout.write(`${JSON.stringify({ ...rien(), flux: null })}\n`);
156
- } else {
157
- // A run that waits for the group of concurrence has no job yet: each of its tranches is
158
- // a job not started.
159
- const jobs =
160
- run.jobs.length === 0 && run.status !== 'completed'
161
- ? Array.from({ length: Number(tranches) || 0 }, (_, i) => ({
162
- name: `tranches (26.x, ${i + 1})`,
163
- status: 'queued',
164
- conclusion: null,
165
- startedAt: null,
166
- }))
167
- : run.jobs;
168
- const d = choisirLeRepli({
169
- jobs,
170
- heureDuFlux: run.createdAt,
171
- maintenant: new Date().toISOString(),
172
- fluxTermine: run.status === 'completed',
173
- });
174
- if (d.aAnnuler.length > 0) {
175
- gh(['run', 'cancel', String(id), '-R', depot]);
176
- }
177
- process.stdout.write(`${JSON.stringify({ ...d, flux: id })}\n`);
178
- }
179
- }
180
- } catch (e) {
181
- process.stderr.write(`⛔ repli de la nuit : ${e.message}\n`);
182
- process.exitCode = 1;
183
- }
184
- }