@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
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The night command of PC2: `grillhouse nuit-de-pc2`, the one command of the key of PC3 (architecture/entree.md
|
|
3
|
+
// §3.1 « Commande de nuit de PC2 », §3.3 « La passe de PC2 », §4.1; machine.md §5.2 « La part de
|
|
4
|
+
// PC2 »). Run by `command=` of the key of the account grillhouse-nuit, it reads what ssh asked
|
|
5
|
+
// (SSH_ORIGINAL_COMMAND) and does one of two things, nothing else:
|
|
6
|
+
//
|
|
7
|
+
// - a verb: `sonde` (the version of the frame), `lancer <projet> <identifiant>` (starts the
|
|
8
|
+
// pass detached on the pushed copy, or gives back the pass already started under the identifier),
|
|
9
|
+
// `etat` (inconnue, en-cours, finie), `verdict` (the JSON of the verdict, §4.1); each argument
|
|
10
|
+
// is [a-z0-9-] alone, anything else is refused, exit 2, nothing run;
|
|
11
|
+
// - the push of PC3, the one form `rsync --server …` checked as rrsync does: a write only, no
|
|
12
|
+
// program, shell, list, log, daemon nor configuration option, one destination under the deposit
|
|
13
|
+
// folder of PC2 (`<identifiant>/copie/` or `<identifiant>/outil/`), whose arguments are rebuilt
|
|
14
|
+
// from what was checked.
|
|
15
|
+
//
|
|
16
|
+
// The state of a pass lives apart from its copy, in `passes/<identifiant>/` (`etat`,
|
|
17
|
+
// `verdict.json` or `repasser`, a few kB): the end of the pass, even interrupted, removes its
|
|
18
|
+
// copy and its work and keeps both until the `lancer` of a later night, which sweeps those of past
|
|
19
|
+
// nights. No secret is put on PC2: the steps get an environment of an allow list, no token and no
|
|
20
|
+
// session of claude (a test that needs one is @poste). The pass plays under its own reservation
|
|
21
|
+
// (at most 8 threads and 12 GB: the arbiter of PC3 does not cover PC2) and reads the machine
|
|
22
|
+
// again before each tranche, which is often loaded by the CI.
|
|
23
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
24
|
+
import {
|
|
25
|
+
existsSync,
|
|
26
|
+
lstatSync,
|
|
27
|
+
mkdirSync,
|
|
28
|
+
readdirSync,
|
|
29
|
+
readFileSync,
|
|
30
|
+
rmSync,
|
|
31
|
+
writeFileSync,
|
|
32
|
+
} from 'node:fs';
|
|
33
|
+
import { homedir } from 'node:os';
|
|
34
|
+
import path from 'node:path';
|
|
35
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
36
|
+
import { A_REPASSER } from './codes-de-sortie.mjs';
|
|
37
|
+
import { mesureDeLaMachine } from './mesure-de-la-machine.mjs';
|
|
38
|
+
|
|
39
|
+
const GO = 1024 ** 3;
|
|
40
|
+
const MINUTE = 60_000;
|
|
41
|
+
const SAFE = /^[a-z0-9-]+$/;
|
|
42
|
+
/** The most threads and memory, in GB, a pass of PC2 reserves (the limits of the account). */
|
|
43
|
+
const FILS_MAX = 8;
|
|
44
|
+
const MEMOIRE_MAX_GO = 12;
|
|
45
|
+
/** The most the work of a pass weighs, in bytes. */
|
|
46
|
+
const TRAVAIL_MAX = 20 * GO;
|
|
47
|
+
/** The longest wait for the machine before a tranche, in ms. */
|
|
48
|
+
const ATTENTE_MAX_MS = 15 * MINUTE;
|
|
49
|
+
const PAS_D_ATTENTE_MS = 30_000;
|
|
50
|
+
const TRANCHES = 4;
|
|
51
|
+
const SORTIE_MAX = 20_000;
|
|
52
|
+
const DATE = /(\d{4}-\d{2}-\d{2})$/;
|
|
53
|
+
|
|
54
|
+
const VERBES = { sonde: 0, lancer: 2, etat: 2, verdict: 2 };
|
|
55
|
+
const OPTIONS_LONGUES = new Set([
|
|
56
|
+
'--server',
|
|
57
|
+
'--delete',
|
|
58
|
+
'--delete-before',
|
|
59
|
+
'--delete-during',
|
|
60
|
+
'--delete-delay',
|
|
61
|
+
'--delete-after',
|
|
62
|
+
'--delete-excluded',
|
|
63
|
+
'--numeric-ids',
|
|
64
|
+
'--ignore-errors',
|
|
65
|
+
'--partial',
|
|
66
|
+
'--no-r',
|
|
67
|
+
]);
|
|
68
|
+
const OPTIONS_COURTES = /^-[a-zA-Z0-9.]+$/;
|
|
69
|
+
const JETON_SUR = /^[A-Za-z0-9._/=,:+@%-]+$/;
|
|
70
|
+
const DESTINATION = /^nuit-[a-z0-9-]+\/(copie|outil)\/?$/;
|
|
71
|
+
|
|
72
|
+
const refus = raison => ({ genre: 'refus', code: 2, raison });
|
|
73
|
+
|
|
74
|
+
function lireLaPoussee(jetons, depot) {
|
|
75
|
+
if (jetons.some(j => !JETON_SUR.test(j))) {
|
|
76
|
+
return refus('rsync : un argument hors de la forme permise');
|
|
77
|
+
}
|
|
78
|
+
if (jetons[0] !== 'rsync' || jetons[1] !== '--server') {
|
|
79
|
+
return refus('rsync : seule la forme « rsync --server … » est permise');
|
|
80
|
+
}
|
|
81
|
+
const options = [];
|
|
82
|
+
const positionnels = [];
|
|
83
|
+
for (const j of jetons.slice(2)) {
|
|
84
|
+
if (j.startsWith('--')) {
|
|
85
|
+
if (!OPTIONS_LONGUES.has(j)) {
|
|
86
|
+
return refus('rsync : option refusée ' + j);
|
|
87
|
+
}
|
|
88
|
+
options.push(j);
|
|
89
|
+
} else if (j.startsWith('-')) {
|
|
90
|
+
if (
|
|
91
|
+
!OPTIONS_COURTES.test(j) ||
|
|
92
|
+
/^-[a-zA-Z0-9]*[eEMsT]/.test(j.replace(/e\.[A-Za-z0-9.]*$/, ''))
|
|
93
|
+
) {
|
|
94
|
+
return refus('rsync : option refusée ' + j);
|
|
95
|
+
}
|
|
96
|
+
options.push(j);
|
|
97
|
+
} else {
|
|
98
|
+
positionnels.push(j);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (positionnels.length !== 2 || positionnels[0] !== '.') {
|
|
102
|
+
return refus('rsync : la forme est « . <destination> »');
|
|
103
|
+
}
|
|
104
|
+
let relative = positionnels[1];
|
|
105
|
+
const base = depot.replace(/\/+$/, '') + '/';
|
|
106
|
+
if (path.isAbsolute(relative)) {
|
|
107
|
+
if (!relative.startsWith(base)) {
|
|
108
|
+
return refus('rsync : destination hors du dépôt');
|
|
109
|
+
}
|
|
110
|
+
relative = relative.slice(base.length);
|
|
111
|
+
}
|
|
112
|
+
if (relative.split('/').some(s => s === '..' || s === '.') || !DESTINATION.test(relative)) {
|
|
113
|
+
return refus('rsync : destination refusée');
|
|
114
|
+
}
|
|
115
|
+
const cible = path.join(depot, relative) + '/';
|
|
116
|
+
return { genre: 'rsync', argv: ['rsync', '--server', ...options, '.', cible] };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* What ssh asked, read: `{ genre: 'verbe', verbe, args }`, `{ genre: 'rsync', argv }` (the arguments
|
|
121
|
+
* of the rsync to run, its destination absolute under <depot>) or `{ genre: 'refus', code: 2, raison }`.
|
|
122
|
+
* The text ssh gives (<originale>) wins over the command line (<argv>).
|
|
123
|
+
* @param {{ argv: string[], originale?: string, depot: string }} e
|
|
124
|
+
*/
|
|
125
|
+
export function lireLaDemande({ argv, originale, depot }) {
|
|
126
|
+
if (originale === undefined && argv.length === 0) {
|
|
127
|
+
return refus('aucune commande');
|
|
128
|
+
}
|
|
129
|
+
const jetons = originale !== undefined ? originale.split(' ') : argv;
|
|
130
|
+
if (jetons[0] === 'rsync') {
|
|
131
|
+
return lireLaPoussee(jetons, depot);
|
|
132
|
+
}
|
|
133
|
+
const [verbe, ...args] = jetons;
|
|
134
|
+
if (!Object.hasOwn(VERBES, verbe ?? '')) {
|
|
135
|
+
return refus('verbe refusé : ' + String(verbe).slice(0, 40));
|
|
136
|
+
}
|
|
137
|
+
if (args.length !== VERBES[verbe] || args.some(a => !SAFE.test(a))) {
|
|
138
|
+
return refus(
|
|
139
|
+
'arguments refusés pour ' + verbe + ' (attendus : ' + VERBES[verbe] + ', [a-z0-9-])'
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return { genre: 'verbe', verbe, args };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The reservation of PC2 for a machine: its cores and memory, within the limits of the account. */
|
|
146
|
+
export function reservationDePc2(machine) {
|
|
147
|
+
return {
|
|
148
|
+
fils: Math.min(FILS_MAX, machine.coeurs),
|
|
149
|
+
memoireGo: Math.min(MEMOIRE_MAX_GO, machine.memoireGo),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const lire = f => {
|
|
154
|
+
try {
|
|
155
|
+
return readFileSync(f, 'utf8');
|
|
156
|
+
} catch {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const jourDe = nom => DATE.exec(nom)?.[1] ?? null;
|
|
161
|
+
const dossiersDe = (racine, genre) => path.join(racine, genre);
|
|
162
|
+
|
|
163
|
+
function balayer(racine, id) {
|
|
164
|
+
const jour = jourDe(id);
|
|
165
|
+
if (jour === null) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
for (const genre of ['passes', 'depot', 'travail']) {
|
|
169
|
+
let noms = [];
|
|
170
|
+
try {
|
|
171
|
+
noms = readdirSync(dossiersDe(racine, genre));
|
|
172
|
+
} catch {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
for (const nom of noms) {
|
|
176
|
+
const j = /^nuit-[a-z0-9-]+$/.test(nom) ? jourDe(nom) : null;
|
|
177
|
+
if (j !== null && j < jour) {
|
|
178
|
+
rmSync(path.join(racine, genre, nom), { recursive: true, force: true });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function vivant(pid) {
|
|
185
|
+
try {
|
|
186
|
+
process.kill(pid, 0);
|
|
187
|
+
return true;
|
|
188
|
+
} catch {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function ecrireLEtat(passe, texte) {
|
|
194
|
+
mkdirSync(passe, { recursive: true });
|
|
195
|
+
writeFileSync(path.join(passe, 'etat'), texte + '\n');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// The state of a pass: « inconnue » without a folder, « en-cours », « finie »; a pass whose
|
|
199
|
+
// process is gone without having finished is finished, « à repasser ».
|
|
200
|
+
function etatDe(racine, id) {
|
|
201
|
+
const passe = path.join(racine, 'passes', id);
|
|
202
|
+
const texte = lire(path.join(passe, 'etat'));
|
|
203
|
+
if (texte === null) {
|
|
204
|
+
return 'inconnue';
|
|
205
|
+
}
|
|
206
|
+
const etat = texte.trim();
|
|
207
|
+
const pid = Number(lire(path.join(passe, 'pid')));
|
|
208
|
+
if (etat === 'en-cours' && Number.isInteger(pid) && pid > 0 && !vivant(pid)) {
|
|
209
|
+
writeFileSync(path.join(passe, 'repasser'), 'passe interrompue\n');
|
|
210
|
+
rmSync(path.join(passe, 'pid'), { force: true });
|
|
211
|
+
ecrireLEtat(passe, 'finie');
|
|
212
|
+
return 'finie';
|
|
213
|
+
}
|
|
214
|
+
return etat;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Runs a verb. <demarrer> starts the pass detached (`{ id, projet, copie, passe }`; its pid, if
|
|
219
|
+
* it gives one, is kept).
|
|
220
|
+
* @returns {{ code: number, sortie: string }}
|
|
221
|
+
*/
|
|
222
|
+
export function executerLaDemande({ verbe, args, racine, version, demarrer }) {
|
|
223
|
+
if (verbe === 'sonde') {
|
|
224
|
+
return { code: 0, sortie: version + '\n' };
|
|
225
|
+
}
|
|
226
|
+
const [projet, id] = args;
|
|
227
|
+
const passe = path.join(racine, 'passes', id);
|
|
228
|
+
if (verbe === 'etat') {
|
|
229
|
+
return { code: 0, sortie: etatDe(racine, id) + '\n' };
|
|
230
|
+
}
|
|
231
|
+
if (verbe === 'verdict') {
|
|
232
|
+
if (etatDe(racine, id) !== 'finie') {
|
|
233
|
+
return { code: 1, sortie: 'passe non finie\n' };
|
|
234
|
+
}
|
|
235
|
+
const verdict = lire(path.join(passe, 'verdict.json'));
|
|
236
|
+
if (verdict !== null) {
|
|
237
|
+
return { code: 0, sortie: verdict };
|
|
238
|
+
}
|
|
239
|
+
const raison = lire(path.join(passe, 'repasser'));
|
|
240
|
+
return raison === null
|
|
241
|
+
? { code: 1, sortie: 'aucun verdict\n' }
|
|
242
|
+
: { code: A_REPASSER, sortie: raison };
|
|
243
|
+
}
|
|
244
|
+
// lancer
|
|
245
|
+
const etat = etatDe(racine, id);
|
|
246
|
+
if (etat !== 'inconnue') {
|
|
247
|
+
return { code: 0, sortie: etat + '\n' };
|
|
248
|
+
}
|
|
249
|
+
const copie = path.join(racine, 'depot', id, 'copie');
|
|
250
|
+
if (!existsSync(copie)) {
|
|
251
|
+
return { code: 1, sortie: 'aucune copie poussée\n' };
|
|
252
|
+
}
|
|
253
|
+
balayer(racine, id);
|
|
254
|
+
ecrireLEtat(passe, 'en-cours');
|
|
255
|
+
const pid = demarrer({ id, projet, copie, passe });
|
|
256
|
+
if (Number.isInteger(pid)) {
|
|
257
|
+
writeFileSync(path.join(passe, 'pid'), String(pid) + '\n');
|
|
258
|
+
}
|
|
259
|
+
return { code: 0, sortie: 'en-cours\n' };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// The environment an step gets: an allow list, so that no token, key nor session of claude of the
|
|
263
|
+
// environment received reaches it.
|
|
264
|
+
const SURE = /^(PATH|HOME|USER|LOGNAME|SHELL|LANG|LC_[A-Z_]+|TERM|TZ|TMPDIR|XDG_[A-Z_]+)$/;
|
|
265
|
+
function envDeLEtape(env, id) {
|
|
266
|
+
const sain = Object.fromEntries(Object.entries(env).filter(([k]) => SURE.test(k)));
|
|
267
|
+
return { ...sain, GRILLHOUSE_RESERVATION_TENUE: id };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const borne = s => (s.length > SORTIE_MAX ? s.slice(s.length - SORTIE_MAX) : s);
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Plays the pass: the tooling, the tranches of the tests out of the poste, the measures, then the
|
|
274
|
+
* night script of the project when <taches> names it, each step under the reservation, the machine
|
|
275
|
+
* read again before each tranche. Writes the verdict (`verdict.json`) or the reason of a « à repasser »
|
|
276
|
+
* (`repasser`), removes the copy and the work, then says the pass finished. Never throws.
|
|
277
|
+
* @returns {Promise<{ code: number, raison?: string }>}
|
|
278
|
+
*/
|
|
279
|
+
export async function jouerLaPasse(e) {
|
|
280
|
+
const passe = path.join(e.racine, 'passes', e.id);
|
|
281
|
+
const reservation = reservationDePc2(e.libre());
|
|
282
|
+
const env = envDeLEtape(e.env, e.id);
|
|
283
|
+
const resultats = new Map();
|
|
284
|
+
let aRepasser = null;
|
|
285
|
+
let rouge = false;
|
|
286
|
+
const noter = (nom, r) => {
|
|
287
|
+
const avant = resultats.get(nom) ?? { verdict: 'vert', sortie: '' };
|
|
288
|
+
const rougeICI = r.code !== 0;
|
|
289
|
+
resultats.set(nom, {
|
|
290
|
+
verdict: avant.verdict === 'rouge' || rougeICI ? 'rouge' : 'vert',
|
|
291
|
+
sortie: rougeICI ? borne(avant.sortie + r.sortie) : avant.sortie,
|
|
292
|
+
});
|
|
293
|
+
rouge ||= rougeICI;
|
|
294
|
+
};
|
|
295
|
+
const jouer = async etape => {
|
|
296
|
+
const r = await e.jouer({ ...etape, reservation, env });
|
|
297
|
+
if (r.code === A_REPASSER || (etape.genre === 'outillage' && r.code !== 0)) {
|
|
298
|
+
aRepasser = (etape.genre === 'outillage' ? 'outillage : ' : '') + String(r.sortie).trim();
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
if (e.taille() > TRAVAIL_MAX) {
|
|
302
|
+
aRepasser = 'le travail dépasse 20 Go';
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
return r;
|
|
306
|
+
};
|
|
307
|
+
// Waits, within the bound, for the cores and memory the reservation asks to be free.
|
|
308
|
+
const attendreLaMachine = async () => {
|
|
309
|
+
const debut = e.maintenant();
|
|
310
|
+
for (;;) {
|
|
311
|
+
const m = e.libre();
|
|
312
|
+
if (m.coeursLibres >= reservation.fils && m.memoireLibreGo >= reservation.memoireGo) {
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
if (e.maintenant() - debut >= ATTENTE_MAX_MS) {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
await e.attendre(PAS_D_ATTENTE_MS);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
try {
|
|
322
|
+
if ((await jouer({ genre: 'outillage' })) !== null) {
|
|
323
|
+
for (let i = 1; i <= e.tranches && aRepasser === null; i++) {
|
|
324
|
+
if (!(await attendreLaMachine())) {
|
|
325
|
+
aRepasser = 'la machine reste chargée : cœurs ou mémoire libres sous la réservation';
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
const r = await jouer({ genre: 'tranche', tranche: i + '/' + e.tranches });
|
|
329
|
+
if (r !== null) {
|
|
330
|
+
noter('tests-de-nuit', r);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (aRepasser === null) {
|
|
334
|
+
const r = await jouer({ genre: 'mesures' });
|
|
335
|
+
if (r !== null) {
|
|
336
|
+
noter('tests-de-nuit', r);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (aRepasser === null && e.taches.includes('script-de-nuit')) {
|
|
340
|
+
const r = await jouer({ genre: 'script' });
|
|
341
|
+
if (r !== null) {
|
|
342
|
+
noter('script-de-nuit', r);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
} catch (erreur) {
|
|
347
|
+
aRepasser = 'passe interrompue : ' + String(erreur?.message ?? erreur);
|
|
348
|
+
}
|
|
349
|
+
let code;
|
|
350
|
+
try {
|
|
351
|
+
if (aRepasser !== null) {
|
|
352
|
+
writeFileSync(path.join(passe, 'repasser'), borne(aRepasser) + '\n');
|
|
353
|
+
code = A_REPASSER;
|
|
354
|
+
} else {
|
|
355
|
+
const taches = e.taches
|
|
356
|
+
.filter(nom => resultats.has(nom))
|
|
357
|
+
.map(nom => ({ nom, ...resultats.get(nom) }));
|
|
358
|
+
const verdict = {
|
|
359
|
+
identifiant: e.id,
|
|
360
|
+
commit: e.commit,
|
|
361
|
+
verdict: rouge ? 'rouge' : 'vert',
|
|
362
|
+
taches: taches.map(t => ({ nom: t.nom, verdict: t.verdict, sortie: t.sortie })),
|
|
363
|
+
};
|
|
364
|
+
writeFileSync(path.join(passe, 'verdict.json'), JSON.stringify(verdict));
|
|
365
|
+
code = rouge ? 1 : 0;
|
|
366
|
+
}
|
|
367
|
+
} finally {
|
|
368
|
+
rmSync(path.join(e.racine, 'depot', e.id), { recursive: true, force: true });
|
|
369
|
+
rmSync(path.join(e.racine, 'travail', e.id), { recursive: true, force: true });
|
|
370
|
+
rmSync(path.join(passe, 'pid'), { force: true });
|
|
371
|
+
ecrireLEtat(passe, 'finie');
|
|
372
|
+
}
|
|
373
|
+
return { code, raison: aRepasser ?? undefined };
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// ---- The real seams: the process of the pass and its steps. ----
|
|
377
|
+
|
|
378
|
+
function lancer(commande, args, { cwd, env, delaiMs = 4 * 3600_000 }) {
|
|
379
|
+
return new Promise(ok => {
|
|
380
|
+
let sortie = '';
|
|
381
|
+
const p = spawn(commande, args, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
382
|
+
const garder = d => {
|
|
383
|
+
sortie = borne(sortie + d.toString('utf8'));
|
|
384
|
+
};
|
|
385
|
+
p.stdout.on('data', garder);
|
|
386
|
+
p.stderr.on('data', garder);
|
|
387
|
+
const minuteur = setTimeout(() => p.kill('SIGKILL'), delaiMs);
|
|
388
|
+
p.on('error', erreur => {
|
|
389
|
+
clearTimeout(minuteur);
|
|
390
|
+
ok({ code: 1, sortie: String(erreur.message) });
|
|
391
|
+
});
|
|
392
|
+
p.on('close', (code, signal) => {
|
|
393
|
+
clearTimeout(minuteur);
|
|
394
|
+
ok({ code: code ?? (signal ? 128 : 1), sortie });
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function commandeDuCadre(racine, id, copie) {
|
|
400
|
+
const outil = path.join(
|
|
401
|
+
racine,
|
|
402
|
+
'depot',
|
|
403
|
+
id,
|
|
404
|
+
'outil',
|
|
405
|
+
'node_modules',
|
|
406
|
+
'@roomi-fields',
|
|
407
|
+
'grillhouse',
|
|
408
|
+
'bin',
|
|
409
|
+
'grillhouse.mjs'
|
|
410
|
+
);
|
|
411
|
+
return existsSync(outil)
|
|
412
|
+
? [process.execPath, [outil]]
|
|
413
|
+
: [path.join(copie, 'node_modules', '.bin', 'grillhouse'), []];
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
async function jouerUneEtape({ racine, id, copie }, e) {
|
|
417
|
+
const travail = path.join(racine, 'travail', id);
|
|
418
|
+
const env = {
|
|
419
|
+
...e.env,
|
|
420
|
+
TMPDIR: path.join(travail, 'tmp'),
|
|
421
|
+
XDG_CACHE_HOME: path.join(travail, 'cache'),
|
|
422
|
+
npm_config_cache: path.join(travail, 'npm'),
|
|
423
|
+
};
|
|
424
|
+
mkdirSync(env.TMPDIR, { recursive: true });
|
|
425
|
+
const [cadre, debut] = commandeDuCadre(racine, id, copie);
|
|
426
|
+
const g = (...args) => lancer(cadre, [...debut, ...args], { cwd: copie, env });
|
|
427
|
+
const enchaine = async (...appels) => {
|
|
428
|
+
let sortie = '';
|
|
429
|
+
for (const appel of appels) {
|
|
430
|
+
const r = await appel();
|
|
431
|
+
sortie += r.sortie;
|
|
432
|
+
if (r.code !== 0) {
|
|
433
|
+
return { code: r.code, sortie };
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return { code: 0, sortie };
|
|
437
|
+
};
|
|
438
|
+
if (e.genre === 'outillage') {
|
|
439
|
+
const racinePaquet = lire(path.join(copie, 'package.json'));
|
|
440
|
+
const espaces = racinePaquet ? JSON.parse(racinePaquet).workspaces : undefined;
|
|
441
|
+
const enPlus =
|
|
442
|
+
espaces && existsSync(path.join(copie, 'packages', 'grillhouse', 'package.json'))
|
|
443
|
+
? [
|
|
444
|
+
() =>
|
|
445
|
+
lancer('npm', ['run', 'build', '--workspace=@roomi-fields/grillhouse'], {
|
|
446
|
+
cwd: copie,
|
|
447
|
+
env,
|
|
448
|
+
}),
|
|
449
|
+
]
|
|
450
|
+
: [];
|
|
451
|
+
return enchaine(() => lancer('npm', ['ci'], { cwd: copie, env }), ...enPlus);
|
|
452
|
+
}
|
|
453
|
+
if (e.genre === 'tranche') {
|
|
454
|
+
return enchaine(
|
|
455
|
+
() => g('verifier', '--force', '--tranche', e.tranche),
|
|
456
|
+
() => g('tests-de-nuit', '--hors-du-poste', '--tranche', e.tranche)
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
if (e.genre === 'mesures') {
|
|
460
|
+
return g('tests-de-nuit', '--mesures');
|
|
461
|
+
}
|
|
462
|
+
const script = JSON.parse(lire(path.join(copie, 'package.json')) ?? '{}')?.grillhouse?.nuit;
|
|
463
|
+
return lancer('npm', ['run', String(script)], { cwd: copie, env });
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function tailleDe(dossier) {
|
|
467
|
+
let total = 0;
|
|
468
|
+
let entrees = [];
|
|
469
|
+
try {
|
|
470
|
+
entrees = readdirSync(dossier, { withFileTypes: true });
|
|
471
|
+
} catch {
|
|
472
|
+
return 0;
|
|
473
|
+
}
|
|
474
|
+
for (const entree of entrees) {
|
|
475
|
+
const chemin = path.join(dossier, entree.name);
|
|
476
|
+
try {
|
|
477
|
+
total += entree.isDirectory() ? tailleDe(chemin) : lstatSync(chemin).size;
|
|
478
|
+
} catch {
|
|
479
|
+
// A file that goes while it is read weighs nothing.
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return total;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const machineLue = () => {
|
|
486
|
+
const m = mesureDeLaMachine();
|
|
487
|
+
return {
|
|
488
|
+
coeurs: m.coeurs,
|
|
489
|
+
coeursLibres: Math.max(0, m.coeurs - m.charge),
|
|
490
|
+
memoireGo: m.memoireTotale / GO,
|
|
491
|
+
memoireLibreGo: m.memoireLibre / GO,
|
|
492
|
+
};
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
// Takes the lock of file with 'wx' alone; a lock whose tenant is dead is removed, then 'wx' is tried once more.
|
|
496
|
+
export function prendreLeVerrou(verrou, pid) {
|
|
497
|
+
for (let essai = 0; essai < 2; essai++) {
|
|
498
|
+
try {
|
|
499
|
+
writeFileSync(verrou, String(pid), { flag: 'wx' });
|
|
500
|
+
return true;
|
|
501
|
+
} catch {
|
|
502
|
+
const tenant = Number(lire(verrou));
|
|
503
|
+
if (Number.isInteger(tenant) && tenant > 0 && vivant(tenant)) {
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
rmSync(verrou, { force: true });
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// The detached process of a pass: one at a time (a lock of file), its work under travail/<id>.
|
|
513
|
+
async function passeDetachee(racine, projet, id) {
|
|
514
|
+
const passe = path.join(racine, 'passes', id);
|
|
515
|
+
const copie = path.join(racine, 'depot', id, 'copie');
|
|
516
|
+
const verrou = path.join(racine, 'verrou');
|
|
517
|
+
mkdirSync(racine, { recursive: true });
|
|
518
|
+
const pris = prendreLeVerrou(verrou, process.pid);
|
|
519
|
+
const finir = code => {
|
|
520
|
+
if (pris) {
|
|
521
|
+
rmSync(verrou, { force: true });
|
|
522
|
+
}
|
|
523
|
+
return code;
|
|
524
|
+
};
|
|
525
|
+
let interrompre;
|
|
526
|
+
const interruption = new Promise(ok => {
|
|
527
|
+
interrompre = ok;
|
|
528
|
+
});
|
|
529
|
+
for (const signal of ['SIGTERM', 'SIGINT', 'SIGHUP']) {
|
|
530
|
+
process.on(signal, () => {
|
|
531
|
+
writeFileSync(path.join(passe, 'repasser'), 'passe interrompue : ' + signal + '\n');
|
|
532
|
+
rmSync(path.join(racine, 'depot', id), { recursive: true, force: true });
|
|
533
|
+
rmSync(path.join(racine, 'travail', id), { recursive: true, force: true });
|
|
534
|
+
ecrireLEtat(passe, 'finie');
|
|
535
|
+
interrompre(finir(A_REPASSER));
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
const paquet = JSON.parse(lire(path.join(copie, 'package.json')) ?? '{}');
|
|
539
|
+
const taches = ['tests-de-nuit'];
|
|
540
|
+
if (typeof paquet?.grillhouse?.nuit === 'string') {
|
|
541
|
+
taches.push('script-de-nuit');
|
|
542
|
+
}
|
|
543
|
+
const git = spawnSync('git', ['-C', copie, 'rev-parse', 'HEAD'], { encoding: 'utf8' });
|
|
544
|
+
const commit = /^[0-9a-f]{40}$/.test(String(git.stdout).trim())
|
|
545
|
+
? String(git.stdout).trim()
|
|
546
|
+
: '0'.repeat(40);
|
|
547
|
+
if (!pris) {
|
|
548
|
+
writeFileSync(path.join(passe, 'repasser'), 'une autre passe tient PC2 (verrou)\n');
|
|
549
|
+
rmSync(path.join(racine, 'depot', id), { recursive: true, force: true });
|
|
550
|
+
ecrireLEtat(passe, 'finie');
|
|
551
|
+
return A_REPASSER;
|
|
552
|
+
}
|
|
553
|
+
const jeu = jouerLaPasse({
|
|
554
|
+
racine,
|
|
555
|
+
id,
|
|
556
|
+
projet,
|
|
557
|
+
commit,
|
|
558
|
+
tranches: TRANCHES,
|
|
559
|
+
taches,
|
|
560
|
+
env: process.env,
|
|
561
|
+
jouer: e => jouerUneEtape({ racine, id, copie }, e),
|
|
562
|
+
libre: machineLue,
|
|
563
|
+
taille: () => tailleDe(path.join(racine, 'travail', id)),
|
|
564
|
+
attendre: ms => new Promise(ok => setTimeout(ok, ms)),
|
|
565
|
+
maintenant: () => Date.now(),
|
|
566
|
+
}).then(r => finir(r.code));
|
|
567
|
+
return Promise.race([jeu, interruption]);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function demarrerLaPasse({ id, projet }) {
|
|
571
|
+
const fichier = fileURLToPath(import.meta.url);
|
|
572
|
+
const p = spawn(process.execPath, [fichier, projet, id], {
|
|
573
|
+
detached: true,
|
|
574
|
+
stdio: 'ignore',
|
|
575
|
+
env: {
|
|
576
|
+
...Object.fromEntries(Object.entries(process.env).filter(([k]) => SURE.test(k))),
|
|
577
|
+
GRILLHOUSE_NUIT_PC2_PASSE: '1',
|
|
578
|
+
},
|
|
579
|
+
});
|
|
580
|
+
p.unref();
|
|
581
|
+
return p.pid;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
async function main() {
|
|
585
|
+
const racine = homedir();
|
|
586
|
+
if (process.env.GRILLHOUSE_NUIT_PC2_PASSE === '1') {
|
|
587
|
+
const [projet, id] = process.argv.slice(2);
|
|
588
|
+
if (!SAFE.test(projet ?? '') || !SAFE.test(id ?? '')) {
|
|
589
|
+
process.exitCode = 2;
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
process.exitCode = await passeDetachee(racine, projet, id);
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
const depot = path.join(racine, 'depot');
|
|
596
|
+
const d = lireLaDemande({
|
|
597
|
+
argv: process.argv.slice(2),
|
|
598
|
+
originale: process.env.SSH_ORIGINAL_COMMAND,
|
|
599
|
+
depot,
|
|
600
|
+
});
|
|
601
|
+
if (d.genre === 'refus') {
|
|
602
|
+
process.stderr.write('grillhouse nuit-de-pc2 : ' + d.raison + '\n');
|
|
603
|
+
process.exitCode = d.code;
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
if (d.genre === 'rsync') {
|
|
607
|
+
mkdirSync(d.argv[d.argv.length - 1], { recursive: true });
|
|
608
|
+
const r = spawnSync(d.argv[0], d.argv.slice(1), { stdio: 'inherit' });
|
|
609
|
+
process.exitCode = r.status ?? 1;
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
const version = JSON.parse(
|
|
613
|
+
readFileSync(new URL('../package.json', import.meta.url), 'utf8')
|
|
614
|
+
).version;
|
|
615
|
+
const r = executerLaDemande({
|
|
616
|
+
verbe: d.verbe,
|
|
617
|
+
args: d.args,
|
|
618
|
+
racine,
|
|
619
|
+
version,
|
|
620
|
+
demarrer: demarrerLaPasse,
|
|
621
|
+
});
|
|
622
|
+
process.stdout.write(r.sortie);
|
|
623
|
+
process.exitCode = r.code;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
627
|
+
await main();
|
|
628
|
+
}
|