@roomi-fields/grillhouse 0.54.0 → 0.55.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +75 -0
- package/cadre/templates/projet/.github/workflows/ci.yml +4 -2
- package/cadre/templates/projet/.github/workflows/machine-vierge.yml +5 -42
- package/cadre/templates/projet/CONTRIBUTING.md +0 -5
- package/cadre/templates/projet/README.md +0 -126
- package/cadre/templates/projet/_npmignore +1 -6
- package/cadre/templates/projet/package.json +5 -32
- package/cadre/templates/projet/tsconfig.json +4 -4
- package/cadre/templates/projet/vitest.config.cjs +3 -2
- package/charte/tests.md +14 -0
- package/dist/machine/part-par-sorte.d.ts +9 -9
- package/dist/machine/part-par-sorte.js +20 -24
- package/dist/machine/part-par-sorte.js.map +1 -1
- package/dist/machine/table-des-consommations.d.ts +65 -0
- package/dist/machine/table-des-consommations.js +94 -0
- package/dist/machine/table-des-consommations.js.map +1 -0
- package/dist/temporal/circuit/activites.d.ts +2 -0
- package/dist/temporal/circuit/activites.js +87 -3
- package/dist/temporal/circuit/activites.js.map +1 -1
- package/dist/temporal/circuit/client.js +9 -4
- package/dist/temporal/circuit/client.js.map +1 -1
- package/dist/temporal/circuit/contrat.d.ts +32 -4
- package/dist/temporal/circuit/deroule.js +54 -4
- package/dist/temporal/circuit/deroule.js.map +1 -1
- package/dist/temporal/circuit/versions.d.ts +12 -0
- package/dist/temporal/circuit/versions.js +22 -0
- package/dist/temporal/circuit/versions.js.map +1 -0
- package/dist/temporal/consommation/activites.d.ts +2 -0
- package/dist/temporal/consommation/activites.js +9 -0
- package/dist/temporal/consommation/activites.js.map +1 -0
- package/dist/temporal/consommation/actualisation.d.ts +2 -0
- package/dist/temporal/consommation/actualisation.js +71 -0
- package/dist/temporal/consommation/actualisation.js.map +1 -0
- package/dist/temporal/consommation/client.d.ts +12 -0
- package/dist/temporal/consommation/client.js +28 -0
- package/dist/temporal/consommation/client.js.map +1 -0
- package/dist/temporal/consommation/commande.d.ts +5 -0
- package/dist/temporal/consommation/commande.js +32 -0
- package/dist/temporal/consommation/commande.js.map +1 -0
- package/dist/temporal/consommation/contrat.d.ts +15 -0
- package/dist/temporal/consommation/contrat.js +13 -0
- package/dist/temporal/consommation/contrat.js.map +1 -0
- package/dist/temporal/consommation/deroule.d.ts +2 -0
- package/dist/temporal/consommation/deroule.js +14 -0
- package/dist/temporal/consommation/deroule.js.map +1 -0
- package/dist/temporal/deroules.d.ts +2 -1
- package/dist/temporal/deroules.js +3 -2
- package/dist/temporal/deroules.js.map +1 -1
- package/dist/temporal/file/contrat.d.ts +2 -0
- package/dist/temporal/file/deroule.js +14 -4
- package/dist/temporal/file/deroule.js.map +1 -1
- package/dist/temporal/installation.d.ts +6 -0
- package/dist/temporal/installation.js +15 -0
- package/dist/temporal/installation.js.map +1 -1
- package/dist/temporal/nuits/activites.d.ts +2 -1
- package/dist/temporal/nuits/activites.js +127 -3
- package/dist/temporal/nuits/activites.js.map +1 -1
- package/dist/temporal/nuits/client.d.ts +19 -5
- package/dist/temporal/nuits/client.js +33 -23
- package/dist/temporal/nuits/client.js.map +1 -1
- package/dist/temporal/nuits/commande.js +16 -11
- package/dist/temporal/nuits/commande.js.map +1 -1
- package/dist/temporal/nuits/contrat.d.ts +29 -0
- package/dist/temporal/nuits/contrat.js +10 -0
- package/dist/temporal/nuits/contrat.js.map +1 -1
- package/dist/temporal/nuits/deroule.d.ts +5 -0
- package/dist/temporal/nuits/deroule.js +18 -1
- package/dist/temporal/nuits/deroule.js.map +1 -1
- package/dist/temporal/nuits/pc2.d.ts +72 -0
- package/dist/temporal/nuits/pc2.js +206 -0
- package/dist/temporal/nuits/pc2.js.map +1 -0
- package/dist/temporal/places/activites.d.ts +23 -1
- package/dist/temporal/places/activites.js +38 -2
- package/dist/temporal/places/activites.js.map +1 -1
- package/dist/temporal/places/client.d.ts +16 -0
- package/dist/temporal/places/client.js +25 -1
- package/dist/temporal/places/client.js.map +1 -1
- package/dist/temporal/places/contrat.d.ts +79 -14
- package/dist/temporal/places/contrat.js +7 -0
- package/dist/temporal/places/contrat.js.map +1 -1
- package/dist/temporal/places/deroule.js +159 -23
- package/dist/temporal/places/deroule.js.map +1 -1
- package/dist/temporal/places/reservation.d.ts +54 -0
- package/dist/temporal/places/reservation.js +69 -0
- package/dist/temporal/places/reservation.js.map +1 -0
- package/dist/temporal/planification.d.ts +6 -0
- package/dist/temporal/planification.js +26 -0
- package/dist/temporal/planification.js.map +1 -0
- package/dist/temporal/tickets/activites.d.ts +0 -2
- package/dist/temporal/tickets/activites.js +2 -52
- package/dist/temporal/tickets/activites.js.map +1 -1
- package/dist/temporal/tickets/contrat.d.ts +7 -26
- package/dist/temporal/tickets/deroule.js +35 -23
- package/dist/temporal/tickets/deroule.js.map +1 -1
- package/dist/temporal/travailleur.js +2 -0
- package/dist/temporal/travailleur.js.map +1 -1
- package/docs/ARCHITECTURE.md +2 -2
- package/docs/CADRE.md +1 -1
- package/docs/INTERFACE.md +16 -11
- package/docs/architecture/circuit.md +62 -58
- package/docs/architecture/entree.md +87 -63
- package/docs/architecture/greffon.md +32 -27
- package/docs/architecture/installation.md +43 -32
- package/docs/architecture/machine.md +48 -40
- package/docs/architecture/tests.md +37 -33
- package/docs/lexique.md +4 -3
- package/package.json +1 -1
- package/scripts/activites.mjs +351 -180
- package/scripts/aiguillage.mjs +1 -0
- package/scripts/attente-de-la-machine.mjs +3 -22
- package/scripts/avancement.mjs +21 -30
- package/scripts/bilan.mjs +22 -2
- package/scripts/branche-de-nuit.mjs +1 -1
- package/scripts/circuit.mjs +75 -39
- package/scripts/codes-de-sortie.mjs +0 -6
- package/scripts/consommation-des-passes.mjs +67 -31
- package/scripts/consommation.mjs +152 -24
- package/scripts/copies-finies.mjs +15 -35
- package/scripts/dernier-vert.mjs +4 -5
- package/scripts/dette.mjs +5 -3
- package/scripts/droits.mjs +2 -2
- package/scripts/echantillonneur-de-la-passe.mjs +7 -31
- package/scripts/engendres.mjs +5 -61
- package/scripts/enveloppe/enveloppe.mjs +30 -34
- package/scripts/enveloppe/travail-de-la-copie.mjs +5 -0
- package/scripts/etapes.mjs +21 -7
- package/scripts/etat-du-depot.mjs +61 -0
- package/scripts/faits-du-circuit.mjs +7 -4
- package/scripts/fermeture-de-la-machine.d.mts +6 -4
- package/scripts/fermeture-de-la-machine.mjs +12 -16
- package/scripts/fichier-du-poste.d.mts +9 -0
- package/scripts/file-des-tickets.d.mts +0 -18
- package/scripts/file-des-tickets.mjs +0 -42
- package/scripts/fusion-du-changelog.mjs +1 -1
- package/scripts/greffons.mjs +282 -17
- package/scripts/grillhouse-maj.mjs +1 -1
- package/scripts/index-des-rouges.d.mts +40 -0
- package/scripts/index-des-rouges.mjs +104 -0
- package/scripts/integration/file.mjs +13 -63
- package/scripts/integration/integrer.mjs +157 -424
- package/scripts/integration/jugement.mjs +109 -0
- package/scripts/integration/rejeu.mjs +94 -71
- package/scripts/jointure.d.ts +34 -27
- package/scripts/journal-des-etats.d.mts +1 -1
- package/scripts/langages/c/commandes.mjs +27 -12
- package/scripts/langages/cargo/commandes.mjs +148 -94
- package/scripts/langages/cargo/index.mjs +2 -1
- package/scripts/langages/cargo/lectures-des-tests.mjs +132 -0
- package/scripts/langages/cargo/migrations/lectures-des-tests.mjs +31 -0
- package/scripts/langages/python/commandes.mjs +31 -15
- package/scripts/langages/python/index.mjs +2 -1
- package/scripts/langages/python/lectures-des-tests.mjs +148 -0
- package/scripts/langages/python/migrations/lectures-des-tests.mjs +31 -0
- package/scripts/langages/typescript/consommateurs-arbitres.mjs +2 -2
- package/scripts/langages/typescript/index.mjs +4 -0
- package/scripts/langages/typescript/lectures-des-tests.mjs +95 -0
- package/scripts/langages/typescript/migrations/lectures-des-tests.mjs +31 -0
- package/scripts/langages/typescript/tests-de-nuit.mjs +9 -15
- package/scripts/langages/typescript/tests.mjs +11 -37
- package/scripts/langages/typescript/titres-de-tests.mjs +5 -4
- package/scripts/langages/typescript/verifier.mjs +74 -44
- package/scripts/langages/typescript/vitest-config/base.mjs +3 -3
- package/scripts/langages/typescript/vitest-config/machine.setup.mjs +6 -25
- package/scripts/lectures-communes.mjs +234 -0
- package/scripts/machine.mjs +11 -18
- package/scripts/mesure/base-de-passe.mjs +1 -2
- package/scripts/mesure-de-la-machine.d.mts +40 -3
- package/scripts/mesure-de-la-machine.mjs +201 -11
- package/scripts/migrations/0.33.0-ci-du-cadre.mjs +3 -3
- package/scripts/migrations/nuit-yml-retire.mjs +25 -0
- package/scripts/migrations/part-retiree.mjs +31 -0
- package/scripts/migrations.mjs +4 -0
- package/scripts/montee.mjs +22 -1
- package/scripts/nuit-de-pc2.mjs +628 -0
- package/scripts/nuit.sh +8 -131
- package/scripts/paquets.mjs +1 -1
- package/scripts/passe-de-la-machine.mjs +340 -103
- package/scripts/place-du-circuit.d.mts +15 -0
- package/scripts/place-du-circuit.mjs +32 -0
- package/scripts/places-de-la-machine.mjs +148 -626
- package/scripts/places-du-serveur.mjs +26 -13
- package/scripts/plafond-de-la-machine.d.mts +8 -13
- package/scripts/plafond-de-la-machine.mjs +26 -56
- package/scripts/registre-des-entrees.mjs +57 -0
- package/scripts/regles-des-places.d.mts +82 -50
- package/scripts/regles-des-places.mjs +192 -156
- package/scripts/retirer-copie.sh +9 -2
- package/scripts/seances.mjs +181 -63
- package/scripts/secours.mjs +95 -0
- package/scripts/services-du-noyau.mjs +11 -19
- package/scripts/sous-commandes.mjs +1 -0
- package/scripts/sous-modules.sh +1 -1
- package/scripts/superviseur.mjs +98 -20
- package/scripts/table-des-consommations.d.mts +9 -0
- package/scripts/table-des-consommations.mjs +35 -0
- package/scripts/tableau.mjs +33 -19
- package/scripts/taches-du-graphe.mjs +124 -2
- package/scripts/transitions.d.mts +27 -5
- package/scripts/transitions.mjs +122 -104
- package/scripts/verdict-de-la-nuit.d.mts +13 -0
- package/scripts/verdict-de-la-nuit.mjs +34 -7
- package/scripts/verrou-de-fichier.mjs +1 -2
- package/scripts/workflows-du-cadre.mjs +2 -2
- package/skills/developpeur/SKILL.md +8 -2
- package/skills/direct/SKILL.md +5 -0
- package/skills/explorateur/SKILL.md +10 -1
- package/skills/grill/SKILL.md +2 -4
- package/skills/pitmaster/SKILL.md +14 -7
- package/skills/pitmaster/references/consigne-agent.md +1 -1
- package/skills/relecteur/SKILL.md +4 -1
- package/skills/testwriter/SKILL.md +15 -2
- package/cadre/templates/projet/.env.example +0 -57
- package/cadre/templates/projet/.github/workflows/nuit.yml +0 -139
- package/cadre/templates/projet/deployment/README.md +0 -98
- package/cadre/templates/projet/deployment/docs/01-INSTALL.md +0 -145
- package/cadre/templates/projet/deployment/docs/02-CONFIGURATION.md +0 -117
- package/cadre/templates/projet/deployment/docs/03-API.md +0 -264
- package/cadre/templates/projet/deployment/docs/04-TROUBLESHOOTING.md +0 -262
- package/cadre/templates/projet/deployment/scripts/install.ps1 +0 -100
- package/cadre/templates/projet/deployment/scripts/start.ps1 +0 -61
- package/cadre/templates/projet/deployment/scripts/stop.ps1 +0 -37
- package/cadre/templates/projet/deployment/scripts/test.ps1 +0 -118
- package/cadre/templates/projet/ecosystem.config.cjs +0 -73
- package/cadre/templates/projet/src/config.ts +0 -68
- package/cadre/templates/projet/src/errors.ts +0 -102
- package/cadre/templates/projet/src/index.ts +0 -46
- package/cadre/templates/projet/src/services/.gitkeep +0 -8
- package/cadre/templates/projet/src/types/index.ts +0 -24
- package/cadre/templates/projet/src/utils/logger.ts +0 -106
- package/cadre/templates/projet/tests/unit/config.spec.ts +0 -68
- package/cadre/templates/projet/tests/unit/errors.spec.ts +0 -132
- package/cadre/templates/projet/tests/unit/types.spec.ts +0 -73
- package/cadre/templates/projet/tsconfig.build.json +0 -14
- package/scripts/flux-de-la-nuit.mjs +0 -39
- package/scripts/garde-de-la-memoire.mjs +0 -231
- package/scripts/repli-de-la-nuit.mjs +0 -184
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Config module tests
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
6
|
-
|
|
7
|
-
describe('Config', () => {
|
|
8
|
-
const originalEnv = process.env;
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
// Reset modules to get fresh config
|
|
12
|
-
vi.resetModules();
|
|
13
|
-
process.env = { ...originalEnv };
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
process.env = originalEnv;
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe('environment detection', () => {
|
|
21
|
-
it('should default to development', async () => {
|
|
22
|
-
delete process.env.NODE_ENV;
|
|
23
|
-
const { config } = await import('../../src/config.js');
|
|
24
|
-
expect(config.isDev).toBe(true);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should detect production environment', async () => {
|
|
28
|
-
process.env.NODE_ENV = 'production';
|
|
29
|
-
const { config } = await import('../../src/config.js');
|
|
30
|
-
expect(config.isProd).toBe(true);
|
|
31
|
-
expect(config.isDev).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should detect test environment', async () => {
|
|
35
|
-
process.env.NODE_ENV = 'test';
|
|
36
|
-
const { config } = await import('../../src/config.js');
|
|
37
|
-
expect(config.isTest).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('server configuration', () => {
|
|
42
|
-
it('should use default port', async () => {
|
|
43
|
-
delete process.env.PORT;
|
|
44
|
-
const { config } = await import('../../src/config.js');
|
|
45
|
-
expect(config.server.port).toBe(3000);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should use custom port from environment', async () => {
|
|
49
|
-
process.env.PORT = '8080';
|
|
50
|
-
const { config } = await import('../../src/config.js');
|
|
51
|
-
expect(config.server.port).toBe(8080);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('logging configuration', () => {
|
|
56
|
-
it('should default to info log level', async () => {
|
|
57
|
-
delete process.env.LOG_LEVEL;
|
|
58
|
-
const { config } = await import('../../src/config.js');
|
|
59
|
-
expect(config.logging.level).toBe('info');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should use custom log level', async () => {
|
|
63
|
-
process.env.LOG_LEVEL = 'debug';
|
|
64
|
-
const { config } = await import('../../src/config.js');
|
|
65
|
-
expect(config.logging.level).toBe('debug');
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
@@ -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
|
-
}
|