@roomi-fields/grillhouse 0.31.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +40 -0
- package/bin/grillhouse.mjs +6 -4
- package/cadre/templates/projet/.github/workflows/ci.yml +136 -16
- package/cadre/templates/projet/.github/workflows/nuit.yml +111 -0
- package/cadre/templates/projet/deployment/docs/01-INSTALL.md +4 -4
- package/cadre/templates/projet/package.json +2 -2
- package/charte.md +8 -5
- package/dist/temporal/circuit/contrat.d.ts +15 -0
- package/dist/temporal/circuit/deroule.js +37 -14
- package/dist/temporal/circuit/deroule.js.map +1 -1
- package/dist/temporal/deroules.d.ts +1 -0
- package/dist/temporal/deroules.js +3 -1
- package/dist/temporal/deroules.js.map +1 -1
- package/dist/temporal/file/activites.d.ts +1 -0
- package/dist/temporal/file/activites.js +5 -2
- package/dist/temporal/file/activites.js.map +1 -1
- package/dist/temporal/file/contrat.d.ts +50 -33
- package/dist/temporal/file/contrat.js +2 -2
- package/dist/temporal/file/contrat.js.map +1 -1
- package/dist/temporal/file/deroule.d.ts +3 -1
- package/dist/temporal/file/deroule.js +128 -26
- package/dist/temporal/file/deroule.js.map +1 -1
- package/dist/temporal/installation.d.ts +3 -2
- package/dist/temporal/installation.js +7 -4
- package/dist/temporal/installation.js.map +1 -1
- package/dist/temporal/nuits/activites.d.ts +10 -0
- package/dist/temporal/nuits/activites.js +114 -0
- package/dist/temporal/nuits/activites.js.map +1 -0
- package/dist/temporal/nuits/appel.d.ts +23 -0
- package/dist/temporal/nuits/appel.js +40 -0
- package/dist/temporal/nuits/appel.js.map +1 -0
- package/dist/temporal/nuits/choix.d.ts +14 -0
- package/dist/temporal/nuits/choix.js +119 -0
- package/dist/temporal/nuits/choix.js.map +1 -0
- package/dist/temporal/nuits/client.d.ts +28 -0
- package/dist/temporal/nuits/client.js +83 -0
- package/dist/temporal/nuits/client.js.map +1 -0
- package/dist/temporal/nuits/commande.d.ts +2 -0
- package/dist/temporal/nuits/commande.js +107 -0
- package/dist/temporal/nuits/commande.js.map +1 -0
- package/dist/temporal/nuits/contrat.d.ts +98 -0
- package/dist/temporal/nuits/contrat.js +30 -0
- package/dist/temporal/nuits/contrat.js.map +1 -0
- package/dist/temporal/nuits/deroule.d.ts +5 -0
- package/dist/temporal/nuits/deroule.js +100 -0
- package/dist/temporal/nuits/deroule.js.map +1 -0
- package/dist/temporal/tickets/activites.d.ts +1 -0
- package/dist/temporal/tickets/activites.js +5 -0
- package/dist/temporal/tickets/activites.js.map +1 -1
- package/dist/temporal/tickets/contrat.d.ts +10 -0
- package/dist/temporal/tickets/deroule.js +8 -1
- package/dist/temporal/tickets/deroule.js.map +1 -1
- package/dist/temporal/travailleur.js +4 -1
- package/dist/temporal/travailleur.js.map +1 -1
- package/docs/ARCHITECTURE.md +257 -54
- package/docs/CADRE.md +41 -1
- package/docs/INTERFACE.md +54 -7
- package/hooks/hooks.json +4 -0
- package/hooks/register.tsx +11 -3
- package/package.json +4 -1
- package/scripts/abi-des-dependances.mjs +105 -0
- package/scripts/activites.mjs +99 -48
- package/scripts/aiguillage.mjs +3 -0
- package/scripts/attente-au-tour.mjs +99 -0
- package/scripts/avancement.mjs +8 -18
- package/scripts/base-des-workflows.mjs +57 -0
- package/scripts/ci-des-branches.mjs +91 -0
- package/scripts/circuit.mjs +99 -5
- package/scripts/composants-affectes.mjs +24 -7
- package/scripts/composition-des-langages.mjs +3 -0
- package/scripts/copies-finies.mjs +8 -1
- package/scripts/crochets.mjs +4 -0
- package/scripts/dernier-vert.mjs +30 -4
- package/scripts/effets.mjs +9 -0
- package/scripts/enveloppe/enveloppe.mjs +3 -1
- package/scripts/enveloppe/lancer.sh +1 -1
- package/scripts/enveloppe/travail-de-la-copie.mjs +219 -59
- package/scripts/etapes.mjs +19 -2
- package/scripts/faits-du-circuit.mjs +43 -20
- package/scripts/fichier-du-poste.mjs +87 -0
- package/scripts/grillhouse-maj.mjs +15 -1
- package/scripts/integration/file.mjs +215 -275
- package/scripts/integration/integrer.mjs +82 -41
- package/scripts/integration/rejeu.mjs +13 -64
- package/scripts/jointure.d.ts +30 -2
- package/scripts/journal-des-etats.d.mts +41 -0
- package/scripts/journal-des-etats.mjs +273 -0
- package/scripts/journal.mjs +119 -0
- package/scripts/langages/cargo/commandes.mjs +81 -19
- package/scripts/langages/cargo/exemples.mjs +2 -2
- package/scripts/langages/cargo/index.mjs +14 -5
- package/scripts/langages/cargo/tailles-des-tests.mjs +19 -11
- package/scripts/langages/python/commandes.mjs +11 -7
- package/scripts/langages/python/exemples.mjs +1 -1
- package/scripts/langages/python/index.mjs +11 -2
- package/scripts/langages/python/tailles-des-tests.mjs +19 -11
- package/scripts/langages/typescript/code-mort.mjs +41 -24
- package/scripts/langages/typescript/consommateurs.mjs +28 -17
- package/scripts/langages/typescript/exemples.mjs +2 -0
- package/scripts/langages/typescript/frontieres.mjs +46 -0
- package/scripts/langages/typescript/index.mjs +24 -3
- package/scripts/langages/typescript/migrations/0.33.0-binaire-de-jour.mjs +34 -0
- package/scripts/langages/typescript/migrations/0.33.0-tests-du-poste.mjs +31 -0
- package/scripts/langages/typescript/resumes.mjs +17 -7
- package/scripts/langages/typescript/tailles-des-tests.mjs +251 -22
- package/scripts/langages/typescript/tests-de-nuit.mjs +101 -9
- package/scripts/langages/typescript/tests-du-poste.mjs +172 -0
- package/scripts/langages/typescript/tranches.mjs +273 -0
- package/scripts/langages/typescript/verifier.mjs +154 -23
- package/scripts/langages/typescript/vitest-config/base.mjs +3 -0
- package/scripts/langages/typescript/vitest-config/cibles.mjs +78 -7
- package/scripts/langages/typescript/vitest-config/lances.mjs +4 -4
- package/scripts/langages/typescript/vitest-config/machine.setup.mjs +9 -0
- package/scripts/langages/typescript/vitest.nuit.config.mjs +3 -2
- package/scripts/langages.d.mts +20 -0
- package/scripts/lint-des-scripts.mjs +23 -6
- package/scripts/matiere-de-test.d.ts +11 -0
- package/scripts/migrations/0.33.0-cache-distant.mjs +36 -0
- package/scripts/migrations/0.33.0-ci-des-branches-de-ticket.mjs +31 -0
- package/scripts/migrations/0.33.0-ci-du-cadre.mjs +31 -0
- package/scripts/migrations/0.33.0-node-26.mjs +58 -0
- package/scripts/migrations.mjs +8 -0
- package/scripts/newday.mjs +18 -0
- package/scripts/nuit.sh +40 -13
- package/scripts/places-de-la-machine.mjs +6 -0
- package/scripts/registre.d.mts +90 -0
- package/scripts/registre.mjs +28 -3
- package/scripts/reprise.mjs +12 -8
- package/scripts/services-du-noyau.mjs +4 -0
- package/scripts/session-start.sh +28 -32
- package/scripts/sous-commandes.mjs +31 -10
- package/scripts/superviseur.mjs +127 -75
- package/scripts/tableau.mjs +222 -17
- package/scripts/taches-du-graphe.mjs +39 -6
- package/scripts/ticket-du-circuit.mjs +37 -7
- package/scripts/transitions.mjs +60 -8
- package/scripts/verrou-de-machine.mjs +1 -2
- package/scripts/workflows-du-cadre.mjs +75 -0
- package/skills/developpeur/SKILL.md +1 -1
- package/skills/explorateur/SKILL.md +1 -1
- package/skills/grill/SKILL.md +10 -62
- package/skills/grill/references/paquets.md +60 -0
- package/skills/pitmaster/SKILL.md +21 -31
- package/skills/questionneur/SKILL.md +1 -1
- package/skills/relecteur/SKILL.md +1 -1
- package/skills/testwriter/SKILL.md +7 -1
- package/skills/release/SKILL.md +0 -134
- package/skills/release/scripts/update-version.cjs +0 -92
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The night tests that depend on the poste: a night test that needs what a shared machine (a CI
|
|
3
|
+
// runner) does not have bears the tag `@poste` in the comment at its head (`porteLEtiquetteDuPoste`
|
|
4
|
+
// of ./vitest-config/cibles.mjs), as Bazel's tags (`manual`, `exclusive`) and pytest's markers live
|
|
5
|
+
// with the test; the night of a shared machine leaves it out (`tests-de-nuit --hors-du-poste`), the
|
|
6
|
+
// night of the poste plays it. The tag lives in the test, never in a list beside it.
|
|
7
|
+
//
|
|
8
|
+
// npx grillhouse tests-du-poste run from the repository root (a guard of grillhouse:gardes)
|
|
9
|
+
//
|
|
10
|
+
// - The files read are the night tests (`*.nuit.test.*`, `*.nuit.spec.*`) git lists in the
|
|
11
|
+
// repository (`testsDuDepot` of ./tailles-des-tests.mjs), each with the test material it imports
|
|
12
|
+
// by a relative path (a file under a directory `test`, `tests` or `__tests__`, not a test),
|
|
13
|
+
// followed from file to file; a module of the product, or a package imported by its name, is
|
|
14
|
+
// not read.
|
|
15
|
+
// - A file depends on the poste when its code (its comments and imports left out) or its material's
|
|
16
|
+
// shows one of the marks of DEPENDANCES: the envelope (`canWrap`, the program `bwrap`, its module,
|
|
17
|
+
// its night tests played by their name, `'enveloppe.lanceur'`), the real bd (`hasBd`), a Temporal
|
|
18
|
+
// server (the arguments `'server', 'start-dev'`), sccache, the binaries of the module cargo (the
|
|
19
|
+
// template of a project of Rust, `templates/cargo`, whose package's creation installs
|
|
20
|
+
// cargo-nextest, cargo-deny and sccache when the machine lacks them), systemd, the
|
|
21
|
+
// keyring, the session of the user (`/run/user/`), or the command claude started for more than
|
|
22
|
+
// `plugin` or `--version` (a session, a model). A mark the reading does not see (a path built at
|
|
23
|
+
// run time, a dependency of the product's code) escapes it: such a test takes the tag by hand.
|
|
24
|
+
// - A night test that depends on the poste without the tag is a finding,
|
|
25
|
+
// `{ fichier, regle: 'poste-sans-etiquette', message }`, naming its marks; a tag without a mark
|
|
26
|
+
// passes. A finding inscribed in the project's debt (`grillhouse-dette.json`, ../../dette.mjs)
|
|
27
|
+
// passes, and the count never rises.
|
|
28
|
+
// - The guard writes on its error stream the count of the night tests and of those tagged.
|
|
29
|
+
import path from 'node:path';
|
|
30
|
+
import { pathToFileURL } from 'node:url';
|
|
31
|
+
import { MODE, trancher } from '../../dette.mjs';
|
|
32
|
+
import { testsDuDepot } from './tailles-des-tests.mjs';
|
|
33
|
+
import { estUnTestDeNuit, porteLEtiquetteDuPoste } from './vitest-config/cibles.mjs';
|
|
34
|
+
import {
|
|
35
|
+
code,
|
|
36
|
+
IMPORT,
|
|
37
|
+
lireLeDisque,
|
|
38
|
+
MATIERE,
|
|
39
|
+
resoudreRelatif,
|
|
40
|
+
TEST,
|
|
41
|
+
} from './vitest-config/lances.mjs';
|
|
42
|
+
|
|
43
|
+
export const GARDE = 'tests-du-poste';
|
|
44
|
+
export const REGLE = 'poste-sans-etiquette';
|
|
45
|
+
|
|
46
|
+
// A call that starts the command claude, its arguments to the end of the line.
|
|
47
|
+
const CLAUDE =
|
|
48
|
+
/(?<![\w$])(?:spawnSync|spawn|execFileSync|execFile|execaSync|execa)\s*\(\s*['"`]claude['"`]\s*,\s*\[\s*(['"`])?([^'"`\]\s,]*)/g;
|
|
49
|
+
// The subcommands of claude a shared machine plays: the plugins of the frame and its version.
|
|
50
|
+
const CLAUDE_PARTAGE = new Set(['plugin', '--version']);
|
|
51
|
+
|
|
52
|
+
/** The marks of what a shared machine does not have, each `{ nom, voit(code) }`. */
|
|
53
|
+
export const DEPENDANCES = [
|
|
54
|
+
{
|
|
55
|
+
nom: "l'enveloppe bwrap",
|
|
56
|
+
voit: c =>
|
|
57
|
+
/\bcanWrap\b|['"`]bwrap['"`]|['"`/]enveloppe\/(?:lancer\.sh|enveloppe\.mjs)['"`]|['"`/]enveloppe(?:\.[\w-]+)?['"`]/.test(
|
|
58
|
+
c
|
|
59
|
+
),
|
|
60
|
+
},
|
|
61
|
+
{ nom: 'le bd réel', voit: c => /\bhasBd\b/.test(c) },
|
|
62
|
+
{
|
|
63
|
+
nom: 'un serveur Temporal',
|
|
64
|
+
voit: c => /['"`]server['"`]\s*,\s*['"`]start-dev['"`]/.test(c),
|
|
65
|
+
},
|
|
66
|
+
{ nom: 'sccache', voit: c => /['"`]sccache['"`]/.test(c) },
|
|
67
|
+
{ nom: 'les binaires du module cargo', voit: c => /['"`/]templates\/cargo\b/.test(c) },
|
|
68
|
+
{ nom: 'systemd', voit: c => /['"`](?:systemctl|systemd-run)['"`]/.test(c) },
|
|
69
|
+
{ nom: 'le trousseau', voit: c => /\bkeyrings\b/.test(c) },
|
|
70
|
+
{ nom: 'la session de l’utilisateur', voit: c => /\/run\/user\//.test(c) },
|
|
71
|
+
{
|
|
72
|
+
nom: 'une séance de claude',
|
|
73
|
+
voit: c => [...c.matchAll(CLAUDE)].some(m => !m[1] || !CLAUDE_PARTAGE.has(m[2])),
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The marks of the poste the test file <fichier> (absolute) shows, with the test material it
|
|
79
|
+
* imports by a relative path, read by <lire> (a path → its text, null when it does not read), in
|
|
80
|
+
* the repository at <racine>: the names of DEPENDANCES, each once, in their order.
|
|
81
|
+
*/
|
|
82
|
+
export function dependancesDu(fichier, lire = lireLeDisque, racine = path.parse(fichier).root) {
|
|
83
|
+
const vus = new Set();
|
|
84
|
+
const codes = [];
|
|
85
|
+
const suivre = f => {
|
|
86
|
+
if (vus.has(f)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
vus.add(f);
|
|
90
|
+
const texte = lire(f) ?? '';
|
|
91
|
+
codes.push(code(texte));
|
|
92
|
+
for (const m of texte.matchAll(IMPORT)) {
|
|
93
|
+
const spec = m[1] ?? m[2] ?? m[3] ?? m[4];
|
|
94
|
+
if (!spec?.startsWith('.')) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const cible = resoudreRelatif(f, spec, lire);
|
|
98
|
+
const rel = cible && path.relative(racine, cible).split(path.sep).join('/');
|
|
99
|
+
if (rel && MATIERE.test(rel) && !TEST.test(rel)) {
|
|
100
|
+
suivre(cible);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
suivre(fichier);
|
|
105
|
+
const tout = codes.join('\n');
|
|
106
|
+
return DEPENDANCES.filter(d => d.voit(tout)).map(d => d.nom);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Each night test of the repository at <racine>: `[{ fichier, etiquete, dependances }]`, `fichier`
|
|
111
|
+
* from its root, `etiquete` whether it bears the tag `@poste`, `dependances` the marks of the poste
|
|
112
|
+
* it shows.
|
|
113
|
+
*/
|
|
114
|
+
export function testsDeNuitDuDepot(racine) {
|
|
115
|
+
return testsDuDepot(racine)
|
|
116
|
+
.filter(estUnTestDeNuit)
|
|
117
|
+
.map(fichier => {
|
|
118
|
+
const abs = path.join(racine, fichier);
|
|
119
|
+
return {
|
|
120
|
+
fichier,
|
|
121
|
+
etiquete: porteLEtiquetteDuPoste(lireLeDisque(abs) ?? ''),
|
|
122
|
+
dependances: dependancesDu(abs, lireLeDisque, racine),
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The findings of the repository at <racine>, in the debt's form (../../dette.mjs): one
|
|
129
|
+
* `{ fichier, regle, message }` per night test that depends on the poste without the tag `@poste`.
|
|
130
|
+
*/
|
|
131
|
+
export function verifier(racine, tous = testsDeNuitDuDepot(racine)) {
|
|
132
|
+
return tous
|
|
133
|
+
.filter(t => !t.etiquete && t.dependances.length > 0)
|
|
134
|
+
.map(({ fichier, dependances }) => ({
|
|
135
|
+
fichier,
|
|
136
|
+
regle: REGLE,
|
|
137
|
+
message: `${fichier} : ce test de nuit dépend du poste (${dependances.join(', ')}), qu'une machine partagée n'a pas ; il porte l'étiquette « // @poste: <raison> » dans le commentaire de sa tête, et la nuit de la CI le laisse au poste.`,
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The guard on the repository at <racine>: `{ lignes, code }`, the refusals then the lines of the
|
|
143
|
+
* debt and the count, 1 when a finding is refused, else 0.
|
|
144
|
+
* @param {string} racine the root of the repository
|
|
145
|
+
* @param {NodeJS.ProcessEnv} [env] the environment (the debt's mode, the results directory)
|
|
146
|
+
*/
|
|
147
|
+
export function rapport(racine, env = process.env) {
|
|
148
|
+
const tous = testsDeNuitDuDepot(racine);
|
|
149
|
+
const { refus, lignes } = trancher(
|
|
150
|
+
racine,
|
|
151
|
+
GARDE,
|
|
152
|
+
verifier(racine, tous),
|
|
153
|
+
env[MODE] || undefined,
|
|
154
|
+
env
|
|
155
|
+
);
|
|
156
|
+
return {
|
|
157
|
+
lignes: [
|
|
158
|
+
...refus.map(r => `⛔ ${r.message}`),
|
|
159
|
+
...lignes,
|
|
160
|
+
`ℹ️ ${GARDE} : ${tous.length} test(s) de nuit, ${tous.filter(t => t.etiquete).length} laissé(s) au poste (@poste).`,
|
|
161
|
+
],
|
|
162
|
+
code: refus.length ? 1 : 0,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
167
|
+
const { lignes, code: sortie } = rapport(process.cwd());
|
|
168
|
+
for (const l of lignes) {
|
|
169
|
+
process.stderr.write(`${l}\n`);
|
|
170
|
+
}
|
|
171
|
+
process.exitCode = sortie;
|
|
172
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// The tranches of a pass (`npm run verifier -- --tranche i/n`, ./verifier.mjs), as Vitest shards
|
|
2
|
+
// a run (`--shard=i/n`, `--reporter=blob`, then `--merge-reports`: https://vitest.dev/guide/improving-performance#sharding),
|
|
3
|
+
// and the command `fusion-des-tranches` of the module typescript, which merges them.
|
|
4
|
+
//
|
|
5
|
+
// npx grillhouse fusion-des-tranches from the root of the project, once every tranche played
|
|
6
|
+
//
|
|
7
|
+
// - A tranche `i/n` (LA_FORME: 1 ≤ i ≤ n, both whole) plays, in each package of Vitest, the i-th of
|
|
8
|
+
// n parts of its test files, Vitest's own split (its sequencer's `shard`, by the hash of each
|
|
9
|
+
// file's path): the n tranches together play each file of the pass once.
|
|
10
|
+
// - The other languages play their part of the same tranche in their task of tests, which reads it
|
|
11
|
+
// from the variable `GRILLHOUSE_TESTS` (`cheminsDeLaTache` of scripts/taches-du-graphe.mjs):
|
|
12
|
+
// cargo by nextest's own split (`--partition hash:i/n`), its doctests in the first tranche
|
|
13
|
+
// alone; python, which pytest does not split, all its tests in the first tranche alone. The
|
|
14
|
+
// merge below reads Vitest's reports only: a red of theirs is the red of its tranche's job.
|
|
15
|
+
// - The plugin of the day (./vitest-config/cibles.mjs) applies the tranche the variable
|
|
16
|
+
// `GRILLHOUSE_TESTS` carries (`trancher`): the shard, a blob reporter beside the configuration's
|
|
17
|
+
// reporters, writing `<rapports>/blobs/<paquet>-<i>-<n>.json`, and a sequencer that writes, in
|
|
18
|
+
// `<rapports>/fichiers/<paquet>-<i>-<n>.json`, the files of the pass the split received and the
|
|
19
|
+
// files of its tranche (`{ paquet, tranche, passe, joues }`, each path relative to the package).
|
|
20
|
+
// <rapports> is RAPPORTS under the root of the project, Vitest's own directory of the blobs.
|
|
21
|
+
// - `fusion-des-tranches` reads the files of RAPPORTS: each package must hold the n tranches, the
|
|
22
|
+
// same files of the pass in each, and each file of the pass played by one tranche exactly; each
|
|
23
|
+
// fault is named (`controlerLesTranches`). It then merges the blobs into one report,
|
|
24
|
+
// `vitest run --merge-reports <rapports>/blobs --reporter=default`, from the root. Its code: 0
|
|
25
|
+
// when the tranches hold and the merged report is green; 1 otherwise. A pass with no test file
|
|
26
|
+
// (a push whose changes no test relates to: Vitest writes no blob then) has neither blob nor
|
|
27
|
+
// file of tranche, and merges nothing, green; blobs without any file of tranche are a fault (the
|
|
28
|
+
// tranche did not reach Vitest, which played every file in each tranche).
|
|
29
|
+
import { spawnSync } from 'node:child_process';
|
|
30
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
31
|
+
import path from 'node:path';
|
|
32
|
+
import { pathToFileURL } from 'node:url';
|
|
33
|
+
import { LA_FORME, lireLaTranche } from '../../services-du-noyau.mjs';
|
|
34
|
+
|
|
35
|
+
/** The directory of the reports of the tranches, under the root of the project: Vitest's own. */
|
|
36
|
+
export const RAPPORTS = '.vitest-reports';
|
|
37
|
+
const BLOBS = 'blobs';
|
|
38
|
+
const FICHIERS = 'fichiers';
|
|
39
|
+
// The name of the files of the package <paquet> for the tranche <t>.
|
|
40
|
+
const nomDuFichier = (paquet, t) =>
|
|
41
|
+
`${paquet.replace(/[^A-Za-z0-9._-]+/g, '_')}-${t.index}-${t.count}.json`;
|
|
42
|
+
|
|
43
|
+
// The name a package.json at <racine> gives its package, else the name of its directory.
|
|
44
|
+
function paquetDe(racine) {
|
|
45
|
+
try {
|
|
46
|
+
const nom = JSON.parse(readFileSync(path.join(racine, 'package.json'), 'utf8')).name;
|
|
47
|
+
if (typeof nom === 'string' && nom) {
|
|
48
|
+
return nom;
|
|
49
|
+
}
|
|
50
|
+
} catch {
|
|
51
|
+
// no package.json: the directory names it
|
|
52
|
+
}
|
|
53
|
+
return path.basename(racine);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The sequencer that splits as <Parent> does and writes in <fichier> the files of the pass it
|
|
58
|
+
* received and those of its tranche, each relative to <racine>, sorted; called once per pool, it
|
|
59
|
+
* keeps every call's.
|
|
60
|
+
* @param {new (ctx: any) => { shard(files: any[]): Promise<any[]> }} Parent
|
|
61
|
+
* @param {{ fichier: string, racine: string, paquet: string, tranche: string }} o
|
|
62
|
+
*/
|
|
63
|
+
export function enregistreur(Parent, { fichier, racine, paquet, tranche }) {
|
|
64
|
+
const passe = [];
|
|
65
|
+
const joues = [];
|
|
66
|
+
const relatif = s =>
|
|
67
|
+
path
|
|
68
|
+
.relative(racine, s?.moduleId ?? s?.[1] ?? String(s))
|
|
69
|
+
.split(path.sep)
|
|
70
|
+
.join('/');
|
|
71
|
+
return class extends Parent {
|
|
72
|
+
async shard(files) {
|
|
73
|
+
const siens = await super.shard(files);
|
|
74
|
+
passe.push(...files.map(relatif));
|
|
75
|
+
joues.push(...siens.map(relatif));
|
|
76
|
+
mkdirSync(path.dirname(fichier), { recursive: true });
|
|
77
|
+
writeFileSync(
|
|
78
|
+
fichier,
|
|
79
|
+
`${JSON.stringify({ paquet, tranche, passe: [...passe].sort(), joues: [...joues].sort() }, null, 2)}\n`
|
|
80
|
+
);
|
|
81
|
+
return siens;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Applies to the test options <test> of the configuration <config> the tranche of <valeur> (the
|
|
88
|
+
* content of `GRILLHOUSE_TESTS`: `tranche`, `i/n`, and `rapports`, the directory of the reports):
|
|
89
|
+
* the shard, the blob reporter beside the configuration's, and the sequencer that writes the files.
|
|
90
|
+
* @param {{ root?: string }} config
|
|
91
|
+
* @param {Record<string, any>} test
|
|
92
|
+
* @param {{ tranche: string, rapports: string }} valeur
|
|
93
|
+
*/
|
|
94
|
+
export async function trancher(config, test, { tranche, rapports }) {
|
|
95
|
+
const t = lireLaTranche(tranche);
|
|
96
|
+
if (!t) {
|
|
97
|
+
throw new Error(`⛔ la tranche « ${tranche} » n'a pas la forme ${LA_FORME} (1 ≤ i ≤ n).`);
|
|
98
|
+
}
|
|
99
|
+
const racine = path.resolve(config.root ?? process.cwd());
|
|
100
|
+
const paquet = paquetDe(racine);
|
|
101
|
+
const nom = nomDuFichier(paquet, t);
|
|
102
|
+
test.shard = `${t.index}/${t.count}`;
|
|
103
|
+
const actuels = test.reporters ?? ['default'];
|
|
104
|
+
test.reporters = [
|
|
105
|
+
...(Array.isArray(actuels) ? actuels : [actuels]),
|
|
106
|
+
['blob', { outputFile: path.join(rapports, BLOBS, nom) }],
|
|
107
|
+
];
|
|
108
|
+
const { BaseSequencer } = await import('vitest/node');
|
|
109
|
+
test.sequence = {
|
|
110
|
+
...test.sequence,
|
|
111
|
+
sequencer: enregistreur(test.sequence?.sequencer ?? BaseSequencer, {
|
|
112
|
+
fichier: path.join(rapports, FICHIERS, nom),
|
|
113
|
+
racine,
|
|
114
|
+
paquet,
|
|
115
|
+
tranche: test.shard,
|
|
116
|
+
}),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The files of the reports of the tranche <tranche> under <rapports>: the blobs and the files each
|
|
122
|
+
* package wrote, which a new run of that tranche replaces.
|
|
123
|
+
* @param {string} rapports
|
|
124
|
+
* @param {{ index: number, count: number }} tranche
|
|
125
|
+
* @returns {string[]}
|
|
126
|
+
*/
|
|
127
|
+
export function fichiersDeLaTranche(rapports, tranche) {
|
|
128
|
+
const fin = `-${tranche.index}-${tranche.count}.json`;
|
|
129
|
+
return [BLOBS, FICHIERS].flatMap(d => {
|
|
130
|
+
const dossier = path.join(rapports, d);
|
|
131
|
+
return existsSync(dossier)
|
|
132
|
+
? readdirSync(dossier)
|
|
133
|
+
.filter(f => f.endsWith(fin))
|
|
134
|
+
.map(f => path.join(dossier, f))
|
|
135
|
+
: [];
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The faults of the tranches <enregistrements> (each `{ paquet, tranche, passe, joues }`), each a
|
|
141
|
+
* line: none when every package holds its n tranches, the same files of the pass in each, and
|
|
142
|
+
* each file of the pass played by one tranche exactly; none either when there is no tranche.
|
|
143
|
+
* @param {{ paquet: string, tranche: string, passe: string[], joues: string[] }[]} enregistrements
|
|
144
|
+
* @returns {string[]}
|
|
145
|
+
*/
|
|
146
|
+
export function controlerLesTranches(enregistrements) {
|
|
147
|
+
if (enregistrements.length === 0) {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
const fautes = [];
|
|
151
|
+
const comptes = new Set(enregistrements.map(e => lireLaTranche(e.tranche)?.count));
|
|
152
|
+
if (comptes.size !== 1 || comptes.has(undefined)) {
|
|
153
|
+
return [
|
|
154
|
+
`⛔ les tranches ne découpent pas la passe en un même nombre : ${[...new Set(enregistrements.map(e => e.tranche))].sort().join(', ')}.`,
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
const [n] = comptes;
|
|
158
|
+
const parPaquet = new Map();
|
|
159
|
+
for (const e of enregistrements) {
|
|
160
|
+
parPaquet.set(e.paquet, [...(parPaquet.get(e.paquet) ?? []), e]);
|
|
161
|
+
}
|
|
162
|
+
for (const [paquet, liste] of [...parPaquet].sort(([a], [b]) => a.localeCompare(b, 'en'))) {
|
|
163
|
+
const index = liste.map(e => lireLaTranche(e.tranche).index);
|
|
164
|
+
for (let i = 1; i <= n; i++) {
|
|
165
|
+
const fois = index.filter(x => x === i).length;
|
|
166
|
+
if (fois === 0) {
|
|
167
|
+
fautes.push(`⛔ ${paquet} : la tranche ${i}/${n} manque.`);
|
|
168
|
+
} else if (fois > 1) {
|
|
169
|
+
fautes.push(`⛔ ${paquet} : la tranche ${i}/${n} se répète.`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const passe = JSON.stringify([...liste[0].passe].sort());
|
|
173
|
+
if (liste.some(e => JSON.stringify([...e.passe].sort()) !== passe)) {
|
|
174
|
+
fautes.push(`⛔ ${paquet} : les tranches ne découpent pas les mêmes fichiers de la passe.`);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const parFichier = new Map(liste[0].passe.map(f => [f, []]));
|
|
178
|
+
for (const e of liste) {
|
|
179
|
+
for (const f of e.joues) {
|
|
180
|
+
if (!parFichier.has(f)) {
|
|
181
|
+
fautes.push(
|
|
182
|
+
`⛔ ${paquet} : ${f}, joué par la tranche ${e.tranche}, n'est pas de la passe.`
|
|
183
|
+
);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
parFichier.get(f).push(e.tranche);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
for (const [f, tranches] of parFichier) {
|
|
190
|
+
if (tranches.length === 0) {
|
|
191
|
+
fautes.push(`⛔ ${paquet} : ${f} n'est joué par aucune tranche.`);
|
|
192
|
+
} else if (tranches.length > 1) {
|
|
193
|
+
fautes.push(
|
|
194
|
+
`⛔ ${paquet} : ${f} est joué par plusieurs tranches (${tranches.join(', ')}).`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return fautes;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The files the tranches wrote under <rapports>, read.
|
|
204
|
+
* @param {string} rapports
|
|
205
|
+
*/
|
|
206
|
+
export function lireLesTranches(rapports) {
|
|
207
|
+
const dossier = path.join(rapports, FICHIERS);
|
|
208
|
+
if (!existsSync(dossier)) {
|
|
209
|
+
return [];
|
|
210
|
+
}
|
|
211
|
+
return readdirSync(dossier)
|
|
212
|
+
.filter(f => f.endsWith('.json'))
|
|
213
|
+
.sort()
|
|
214
|
+
.map(f => JSON.parse(readFileSync(path.join(dossier, f), 'utf8')));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Merges the tranches of the project at <racine>: their faults named, then their blobs merged in
|
|
219
|
+
* one report by Vitest (<fusionner>, given the directory of the blobs, its exit code); 0 or 1.
|
|
220
|
+
* @param {{ racine?: string, dire?: (l: string) => void,
|
|
221
|
+
* fusionner?: (blobs: string, racine: string) => number | null }} o
|
|
222
|
+
*/
|
|
223
|
+
export function fusionDesTranches({
|
|
224
|
+
racine = process.cwd(),
|
|
225
|
+
dire = l => process.stdout.write(`${l}\n`),
|
|
226
|
+
fusionner = (blobs, cwd) =>
|
|
227
|
+
spawnSync(
|
|
228
|
+
'npx',
|
|
229
|
+
['--no-install', 'vitest', 'run', '--merge-reports', blobs, '--reporter=default'],
|
|
230
|
+
{
|
|
231
|
+
cwd,
|
|
232
|
+
stdio: 'inherit',
|
|
233
|
+
}
|
|
234
|
+
).status,
|
|
235
|
+
}) {
|
|
236
|
+
const rapports = path.join(racine, RAPPORTS);
|
|
237
|
+
const enregistrements = lireLesTranches(rapports);
|
|
238
|
+
const blobs = path.join(rapports, BLOBS);
|
|
239
|
+
const avecBlobs = existsSync(blobs) && readdirSync(blobs).length > 0;
|
|
240
|
+
if (enregistrements.length === 0) {
|
|
241
|
+
if (avecBlobs) {
|
|
242
|
+
dire(
|
|
243
|
+
`⛔ des rapports sans fichier de tranche sous ${RAPPORTS}/${FICHIERS} : la tranche n'a pas atteint Vitest.`
|
|
244
|
+
);
|
|
245
|
+
return 1;
|
|
246
|
+
}
|
|
247
|
+
dire('↳ aucun fichier de test dans la passe : rien à fusionner.');
|
|
248
|
+
return 0;
|
|
249
|
+
}
|
|
250
|
+
const fautes = controlerLesTranches(enregistrements);
|
|
251
|
+
const code = avecBlobs ? fusionner(blobs, racine) : null;
|
|
252
|
+
for (const f of fautes) {
|
|
253
|
+
dire(f);
|
|
254
|
+
}
|
|
255
|
+
if (fautes.length === 0 && code === 0) {
|
|
256
|
+
dire(
|
|
257
|
+
'✅ les tranches réunies jouent chaque fichier de la passe une fois, et leur rapport est vert.'
|
|
258
|
+
);
|
|
259
|
+
return 0;
|
|
260
|
+
}
|
|
261
|
+
if (code !== 0) {
|
|
262
|
+
dire(
|
|
263
|
+
code === null
|
|
264
|
+
? `⛔ aucun rapport blob sous ${RAPPORTS}/${BLOBS}.`
|
|
265
|
+
: `⛔ la fusion des rapports des tranches sort en ${code}.`
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
return 1;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
272
|
+
process.exitCode = fusionDesTranches({});
|
|
273
|
+
}
|