@roomi-fields/grillhouse 0.25.3 → 0.25.5

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.
@@ -0,0 +1,206 @@
1
+ #!/usr/bin/env node
2
+ // The removal of the working copies whose content is on main, run by the night once its steps
3
+ // are played (scripts/nuit.sh), as `git worktree prune` and the workspace cleanup at the end of a
4
+ // CI pipeline (Jenkins « Workspace Cleanup »): no copy outlives the entry of its content on main.
5
+ //
6
+ // node scripts/copies-finies.mjs [<copie à garder>…] from the main tree of the repository
7
+ //
8
+ // - First `git worktree prune`: a copy whose folder is gone leaves the list. Then each copy
9
+ // `git worktree list` names, the main tree and the copies named on the command line (the
10
+ // night's) left out, passes through scripts/retirer-copie.sh, without `--jetable`: a copy whose
11
+ // local work has all entered main by its content goes, with its `<copie>.travail`; a refused
12
+ // copy (work that has not entered, a lock) stays, intact, its line naming the refusal.
13
+ // - A copy a running circuit holds stays without passing, even without work: its ticket in
14
+ // progress (the copy's folder bears the ticket's id, `.claude/worktrees/<ticket>`, as the
15
+ // circuit and the launcher name it; read by `bd list --status in_progress`), the working
16
+ // directory of its circuit (`<copie>.travail`, which lives as long as the ticket,
17
+ // scripts/circuit.mjs), or, for the integration copy and the queue copy
18
+ // (`.claude/worktrees/integration`, `.claude/worktrees/file`), their lock in git's common
19
+ // directory (`integration.lock`, `file-integration.lock`, scripts/integration/). Tickets in
20
+ // progress that do not read, or not within a minute, hold every copy: none is removed.
21
+ // - A copy whose commits are not on main stays, its line naming the first path that has not
22
+ // entered: retirer-copie.sh judges the local work alone, so the copy's HEAD is judged first, as
23
+ // the removal judges local work: each path HEAD changed since its base with main holds the
24
+ // content and the mode a commit of main after that base gave it (a cherry-pick or a rebase
25
+ // counts, not the commit's identity). A detached HEAD's commits thus never become unreachable.
26
+ // - The branch of a copy removed goes (`git branch -D`), its content being HEAD's, on main; main
27
+ // and a branch another copy holds stay.
28
+ // - One line per copy removed or kept, on the output, which the night adds to its log. The exit is
29
+ // 0 whatever is removed or kept: the removal never changes the night's verdict.
30
+ import { spawnSync } from 'node:child_process';
31
+ import { existsSync, realpathSync } from 'node:fs';
32
+ import path from 'node:path';
33
+ import { pathToFileURL } from 'node:url';
34
+
35
+ const RETIRER = path.join(import.meta.dirname, 'retirer-copie.sh');
36
+ const PRINCIPALE = 'main';
37
+ // The copies of the integration and of the queue, each held while its lock stands.
38
+ const VERROUS = { integration: 'integration.lock', file: 'file-integration.lock' };
39
+
40
+ const lancer = (dossier, cmd, args) =>
41
+ spawnSync(cmd, args, { cwd: dossier, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
42
+ const git = (dossier, ...args) => lancer(dossier, 'git', args);
43
+ const reel = p => {
44
+ try {
45
+ return realpathSync(p);
46
+ } catch {
47
+ return path.resolve(p);
48
+ }
49
+ };
50
+
51
+ // The copies `git worktree list` names: `{ chemin, tete, branche }`, the main tree first.
52
+ function lesCopies(racine) {
53
+ return git(racine, 'worktree', 'list', '--porcelain')
54
+ .stdout.split('\n\n')
55
+ .map(bloc => bloc.split('\n'))
56
+ .filter(l => l[0]?.startsWith('worktree '))
57
+ .map(l => ({
58
+ chemin: l[0].slice('worktree '.length),
59
+ tete: l.find(x => x.startsWith('HEAD '))?.slice('HEAD '.length),
60
+ branche: l.find(x => x.startsWith('branch refs/heads/'))?.slice('branch refs/heads/'.length),
61
+ }));
62
+ }
63
+
64
+ // What holds <chemin> for a running circuit, or null.
65
+ function tenue(chemin, enCours, commun) {
66
+ const nom = path.basename(chemin);
67
+ if (existsSync(`${chemin}.travail`)) {
68
+ return `son circuit a son dossier ${nom}.travail`;
69
+ }
70
+ if (enCours.has(nom)) {
71
+ return `le ticket ${nom} est en cours`;
72
+ }
73
+ const verrou = VERROUS[nom];
74
+ if (verrou && path.dirname(chemin).endsWith(path.join('.claude', 'worktrees'))) {
75
+ if (existsSync(path.join(commun, verrou))) {
76
+ return `le verrou ${verrou} est posé`;
77
+ }
78
+ }
79
+ return null;
80
+ }
81
+
82
+ // The first path the commit or branch <b> changed since its base with main whose content no commit of main
83
+ // after that base gave, or null when all its content is on main.
84
+ function pasEntre(racine, b) {
85
+ const base = git(racine, 'merge-base', b, PRINCIPALE);
86
+ if (base.status !== 0) {
87
+ return `ses commits n'ont pas de base commune avec ${PRINCIPALE}`;
88
+ }
89
+ const chemins = git(racine, 'diff', '--name-only', '-z', '--no-renames', base.stdout.trim(), b)
90
+ .stdout.split('\0')
91
+ .filter(Boolean);
92
+ for (const p of chemins) {
93
+ const tenu = git(racine, 'ls-tree', b, '--', p).stdout.trim();
94
+ const [mode, , id] = tenu ? tenu.split(/\s+/) : ['000000', '', '0'];
95
+ const donnes = git(
96
+ racine,
97
+ 'log',
98
+ `${b}..${PRINCIPALE}`,
99
+ '--no-renames',
100
+ '--format=',
101
+ '--raw',
102
+ '--no-abbrev',
103
+ '--',
104
+ p
105
+ ).stdout.split('\n');
106
+ const entre = donnes.some(l => {
107
+ const [, m, , i] = l.split(/\s+/);
108
+ return m === mode && (i === id || (id === '0' && /^0+$/.test(i ?? '')));
109
+ });
110
+ if (!entre) {
111
+ return `${p} n'est pas sur ${PRINCIPALE}`;
112
+ }
113
+ }
114
+ return null;
115
+ }
116
+
117
+ /**
118
+ * Removes the copies of the repository at <racine> whose content is on main; returns one line per
119
+ * copy removed or kept. <garder> names the copies left out (the night's); <enCours> the ids of the
120
+ * tickets in progress, null when they do not read.
121
+ */
122
+ export function retirerLesCopiesFinies(racine, { garder = [], enCours }) {
123
+ if (enCours === null) {
124
+ return ['✗ les tickets en cours ne se lisent pas (bd list) : aucune copie n’est retirée.'];
125
+ }
126
+ git(racine, 'worktree', 'prune');
127
+ const commun = git(
128
+ racine,
129
+ 'rev-parse',
130
+ '--path-format=absolute',
131
+ '--git-common-dir'
132
+ ).stdout.trim();
133
+ const [principale, ...copies] = lesCopies(racine);
134
+ const ecartees = new Set([principale?.chemin, ...garder].filter(Boolean).map(reel));
135
+ const ici = reel(racine);
136
+ const vu = c => (path.relative(ici, reel(c)).startsWith('..') ? c : path.relative(ici, reel(c)));
137
+ const lignes = [];
138
+ for (const { chemin, tete, branche } of copies) {
139
+ if (ecartees.has(reel(chemin))) {
140
+ continue;
141
+ }
142
+ const raison = tenue(chemin, enCours, commun);
143
+ if (raison) {
144
+ lignes.push(`· copie gardée : ${vu(chemin)} : ${raison}.`);
145
+ continue;
146
+ }
147
+ const commits = tete ? pasEntre(racine, tete) : null;
148
+ if (commits) {
149
+ lignes.push(`· copie gardée : ${vu(chemin)} : ses commits ne sont pas entrés, ${commits}.`);
150
+ continue;
151
+ }
152
+ const r = lancer(racine, 'bash', [RETIRER, chemin]);
153
+ if (r.status !== 0) {
154
+ const refus = String(r.stderr || r.stdout)
155
+ .trim()
156
+ .split('\n');
157
+ lignes.push(`· copie gardée : ${vu(chemin)} : ${refus.join('\n ')}`);
158
+ continue;
159
+ }
160
+ let ligne = `✓ copie retirée : ${vu(chemin)}`;
161
+ if (branche && branche !== PRINCIPALE) {
162
+ const tenante = lesCopies(racine).find(c => c.branche === branche);
163
+ if (tenante) {
164
+ ligne += ` ; sa branche ${branche} reste : la copie ${vu(tenante.chemin)} la tient`;
165
+ } else {
166
+ const d = git(racine, 'branch', '-D', branche);
167
+ ligne +=
168
+ d.status === 0
169
+ ? ` ; sa branche ${branche} supprimée`
170
+ : ` ; sa branche ${branche} reste : ${d.stderr.trim()}`;
171
+ }
172
+ }
173
+ lignes.push(`${ligne}.`);
174
+ }
175
+ return lignes;
176
+ }
177
+
178
+ // The ids of the tickets in progress, null when they do not read within LECTURE_MS.
179
+ const LECTURE_MS = 60_000;
180
+ function ticketsEnCours(racine) {
181
+ const r = spawnSync('bd', ['list', '--status', 'in_progress', '--limit', '0', '--json'], {
182
+ cwd: racine,
183
+ encoding: 'utf8',
184
+ maxBuffer: 256 * 1024 * 1024,
185
+ timeout: LECTURE_MS,
186
+ });
187
+ if (r.status !== 0) {
188
+ return null;
189
+ }
190
+ try {
191
+ return new Set((JSON.parse(r.stdout || '[]') ?? []).map(t => String(t.id)));
192
+ } catch {
193
+ return null;
194
+ }
195
+ }
196
+
197
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
198
+ const racine = process.cwd();
199
+ const lignes = retirerLesCopiesFinies(racine, {
200
+ garder: process.argv.slice(2),
201
+ enCours: ticketsEnCours(racine),
202
+ });
203
+ if (lignes.length) {
204
+ process.stdout.write(`${lignes.join('\n')}\n`);
205
+ }
206
+ }
@@ -33,20 +33,27 @@ export const paquetsDeLEnveloppe = (env = process.env) =>
33
33
  * The components of the copy <copie>, as the module of its language <langage> gives them
34
34
  * (`composants`, scripts/jointure.d.ts), and the packages out of the frame
35
35
  * (`docs/agents/hors-cadre.txt`, `paquets` of scripts/paquets.mjs), which no module counts but a
36
- * plan may name, in the form the plan reads: each `dossier` relative to the copy, its `pkg.name`
37
- * the package's name, else the component's.
36
+ * plan may name, in the form the plan reads: each `dossier` relative to the copy (`.` for a
37
+ * component at its root, as a crate whose workspace is its own), its `pkg.name` the package's
38
+ * name, else the component's, `hors` whether it is out of the frame.
38
39
  * @param {{ composants(racine: string): { dossier: string, nom: string, paquet: string | null }[] }} langage
39
40
  * @param {string} copie
40
- * @returns {{ dossier: string, pkg: { name: string } }[]}
41
+ * @returns {{ dossier: string, pkg: { name: string }, hors: boolean }[]}
41
42
  */
42
43
  export function paquetsDuLangage(langage, copie) {
43
- const composants = langage
44
- .composants(copie)
45
- .map(c => ({ dossier: path.relative(copie, c.dossier), pkg: { name: c.paquet ?? c.nom } }));
44
+ const composants = langage.composants(copie).map(c => ({
45
+ dossier: path.relative(copie, c.dossier) || '.',
46
+ pkg: { name: c.paquet ?? c.nom },
47
+ hors: false,
48
+ }));
46
49
  const connus = new Set(composants.map(c => c.dossier));
47
50
  const hors = paquets(copie)
48
51
  .filter(p => p.hors && !connus.has(p.dossier))
49
- .map(p => ({ dossier: p.dossier, pkg: { name: p.pkg?.name ?? path.basename(p.dossier) } }));
52
+ .map(p => ({
53
+ dossier: p.dossier,
54
+ pkg: { name: p.pkg?.name ?? path.basename(p.dossier) },
55
+ hors: true,
56
+ }));
50
57
  return [...composants, ...hors];
51
58
  }
52
59
 
@@ -63,7 +63,9 @@
63
63
  // its tests, the frame's package declared where the code or the tests read it, the typing of
64
64
  // each package, the project's first configuration of its task runner. Cargo
65
65
  // (scripts/langages/cargo/mise-a-jour.mjs): the files of its template a project lacks, and its
66
- // test scripts.
66
+ // test scripts. What the share leaves to the project (`aFaire`: for cargo, a Cargo.lock that git
67
+ // does not track) is written on the error stream, the exit code 1, and the verification is not
68
+ // played.
67
69
  // - The languages first (`declarerLangages`): a project that declares none (`grillhouse.langages`
68
70
  // of its package.json) receives the languages the modules of the frame find in it
69
71
  // (`langagesTrouves` of scripts/langages.mjs: typescript, a tsconfig.json at its root or in a
@@ -279,7 +281,7 @@ export function mettreAJour(projet, source, { inscrite = VERSION } = {}) {
279
281
  gardes: null,
280
282
  ligneEtat: false,
281
283
  greffon: false,
282
- duLangage: { lignes: [], installer: false, sansVerifier: null },
284
+ duLangage: { lignes: [], aFaire: [], installer: false, sansVerifier: null },
283
285
  };
284
286
  const pkg = path.join(projet, 'package.json');
285
287
  if (existsSync(pkg)) {
@@ -357,6 +359,7 @@ export function mettreAJour(projet, source, { inscrite = VERSION } = {}) {
357
359
  Object.assign(bilan, part.bilan);
358
360
  bilan.duLangage = {
359
361
  lignes: part.lignes,
362
+ aFaire: part.aFaire,
360
363
  installer: part.installer,
361
364
  sansVerifier: part.sansVerifier,
362
365
  };
@@ -575,6 +578,12 @@ function mettreAJourLeProjet(projet, langages) {
575
578
  }
576
579
  }
577
580
  process.stdout.write(rapport(b));
581
+ // What the language leaves to the project comes first, before any of its tools runs.
582
+ const duLangage = b.duLangage.aFaire;
583
+ for (const l of duLangage) {
584
+ process.stderr.write(`${l}\n`);
585
+ process.exitCode = 1;
586
+ }
578
587
  const binaires = installerBinaires(projet);
579
588
  if (binaires.installes.length > 0) {
580
589
  process.stdout.write(`Binaires installés : ${binaires.installes.join(', ')}.\n`);
@@ -590,7 +599,7 @@ function mettreAJourLeProjet(projet, langages) {
590
599
  );
591
600
  }
592
601
  const v = verifier(projet, {
593
- fichiersAFinir: resteAFaire || echecsDesGeneres.length > 0,
602
+ fichiersAFinir: resteAFaire || duLangage.length > 0 || echecsDesGeneres.length > 0,
594
603
  installer: aInstaller(b),
595
604
  sansVerifier: b.duLangage.sansVerifier,
596
605
  });
@@ -85,7 +85,11 @@ export interface Lecteurs {
85
85
  lecteurs: Map<Composant, Set<string>>;
86
86
  }[];
87
87
  };
88
+ /** What each component reads: its production code, and its dependencies of every kind. */
88
89
  lit: Map<Composant, Set<Composant>>;
90
+ /** What each component's tests read: the components they import, its dependencies of
91
+ * development. */
92
+ parLesTests: Map<Composant, Set<Composant>>;
89
93
  }
90
94
 
91
95
  /** The elements a lot adds, changes or removes between two commits, each with its place. */
@@ -136,9 +140,11 @@ export interface MiseAJour {
136
140
  /** Brings the project at `projet` to the form the module asks: its root package.json `p`, which
137
141
  * the core writes after, and its other files, from the frame's files at `source` (its template's
138
142
  * package.json `modele`; `version`, the frame's). Its share of the update: `bilan`, the changes by
139
- * name, each null when nothing changes; `lignes`, the lines of the report; `installer`, whether
140
- * `npm install` comes before the verification; `sansVerifier`, the line that says why the project
141
- * has no script `verifier`, null for the core's. */
143
+ * name, each null when nothing changes; `lignes`, the lines of the report; `aFaire`, what the
144
+ * update leaves to the project, each line naming its gesture, written on the error stream, the
145
+ * code 1 and the verification not played; `installer`, whether `npm install` comes before the
146
+ * verification; `sansVerifier`, the line that says why the project has no script `verifier`,
147
+ * null for the core's. */
142
148
  appliquer(
143
149
  projet: string,
144
150
  o: {
@@ -150,6 +156,7 @@ export interface MiseAJour {
150
156
  ): {
151
157
  bilan: Record<string, unknown>;
152
158
  lignes: string[];
159
+ aFaire: string[];
153
160
  installer: boolean;
154
161
  sansVerifier: string | null;
155
162
  };
@@ -12,12 +12,18 @@
12
12
  // - Each guard of structure of the module (./clippy.mjs, ./frontieres.mjs, ./index-interfaces.mjs)
13
13
  // is a command by its name too, its own script, as the module typescript's: the line of a red
14
14
  // guard (`grillhouse <garde>`, scripts/gardes-du-cadre.mjs) names a command that exists.
15
- // - `tester` plays the tests of each crate chosen, one crate after the other: `cargo nextest run
16
- // -p <crate> --no-fail-fast` for a crate that plays tests (./composants.mjs, `joueDesTests`),
17
- // then `cargo test --doc -p <crate>` for a crate whose library has doctests, which nextest does
18
- // not play. A path, written from the root, chooses the crate that holds it; the source of a test
19
- // target (`<crate>/tests/<nom>.rs`) plays that target alone (`--test <nom>`), without the
20
- // doctests. A path out of every crate, or in a crate without tests, is refused, named, and
15
+ // - `tester` plays the tests of each crate chosen, one crate after the other. For a crate that
16
+ // plays tests (./composants.mjs, `joueDesTests`): the build of its test targets, `cargo test
17
+ // --no-run -p <crate>`, a task `build` of its own, as Turborepo's `test` depends on `build`
18
+ // (grillhouse-egm); then `cargo nextest run -p <crate> --no-fail-fast`, which finds them built.
19
+ // Then `cargo test --doc -p <crate>` for a crate whose library has doctests, which nextest does
20
+ // not play. A failed build leaves the crate's other tasks not played (`code` null): a test that
21
+ // does not compile is a red of the build, which the proof of the red reads as one (« construction
22
+ // de <crate> », scripts/circuit.mjs), and the tests play at the checks. The output of the build
23
+ // goes to its log, `<target>/grillhouse/<crate>-build.log`, the task's `journal` from the root,
24
+ // then to the error stream. A path, written from the root, chooses the crate that holds it; the
25
+ // source of a test target (`<crate>/tests/<nom>.rs`) builds and plays that target alone
26
+ // (`--test <nom>`), without the doctests. A path out of every crate, or in a crate without tests, is refused, named, and
21
27
  // nothing plays (code 2). Without a path, every crate plays, or, under the circuit's mark
22
28
  // (`GRILLHOUSE_DEPUIS_LE_VERT`), the crates the changes since the last green touch and their
23
29
  // dependents (./touches.mjs), every crate when no last green counts. `--force` changes nothing:
@@ -45,10 +51,26 @@
45
51
  // there what ./verdict.mjs reads: its tasks, each planned before it plays (`code` null until it
46
52
  // ran), and the JUnit report of each run of nextest. A task of the workspace is named after its
47
53
  // root, `//`, as Turborepo names the root's tasks.
54
+ // - `tester`, `verifier` and `preparer` refuse, before any run of cargo, a workspace whose
55
+ // Cargo.lock git does not track (grillhouse-rph), in one line that names the file and the
56
+ // gesture: `git add Cargo.lock`, or `cargo generate-lockfile` first when it is absent. Cargo
57
+ // recommends committing it for every project, and the verification plays the exact versions of
58
+ // the repository (`--locked`, as `npm ci` refuses a project without package-lock.json): a lock
59
+ // ignored passes in the main repository, where it lies on disk, and fails in a copy taken from
60
+ // git, the integration's.
48
61
  // - The exit code: 0 when every task is green, 75 when the only reds are « à repasser », 1
49
- // otherwise; 2 for a path refused or a command unknown.
62
+ // otherwise; 2 for a path refused, a Cargo.lock not tracked or a command unknown.
50
63
  import { spawnSync } from 'node:child_process';
51
- import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
64
+ import {
65
+ closeSync,
66
+ copyFileSync,
67
+ existsSync,
68
+ mkdirSync,
69
+ openSync,
70
+ readFileSync,
71
+ rmSync,
72
+ writeFileSync,
73
+ } from 'node:fs';
52
74
  import { constants, tmpdir } from 'node:os';
53
75
  import path from 'node:path';
54
76
  import { fileURLToPath, pathToFileURL } from 'node:url';
@@ -74,6 +96,9 @@ const PROFIL = 'grillhouse';
74
96
  export const NOMS = ['tester', 'verifier', 'typer', 'preparer'];
75
97
  const A_REPASSER = 75;
76
98
  const RACINE = '//';
99
+ const VERROU = 'Cargo.lock';
100
+ // The commands that play the exact versions of the repository, refused without its Cargo.lock.
101
+ const VERROUILLEES = ['tester', 'verifier', 'preparer'];
77
102
 
78
103
  /** The guards of structure of the module, in the order they play: each its name, its script beside
79
104
  * this one, and its arguments as a guard. */
@@ -142,12 +167,27 @@ function passe(racine, env) {
142
167
  ecrire();
143
168
  return { t, args };
144
169
  },
145
- jouer({ t, args }, junit = null) {
170
+ jouer({ t, args }, { junit = null, journal = null } = {}) {
146
171
  // A report of an earlier run is no report of this one, which may write none.
147
172
  if (junit) {
148
173
  rmSync(junit, { force: true });
149
174
  }
150
- const r = spawnSync('cargo', args, { cwd: racine, env, stdio: 'inherit' });
175
+ let r;
176
+ if (journal) {
177
+ // The output of cargo, both streams in their order, goes to the task's log, then to the
178
+ // command's error stream, where cargo writes it.
179
+ mkdirSync(path.dirname(journal), { recursive: true });
180
+ const fd = openSync(journal, 'w');
181
+ try {
182
+ r = spawnSync('cargo', args, { cwd: racine, env, stdio: ['inherit', fd, fd] });
183
+ } finally {
184
+ closeSync(fd);
185
+ }
186
+ process.stderr.write(readFileSync(journal, 'utf8'));
187
+ t.journal = path.relative(racine, journal);
188
+ } else {
189
+ r = spawnSync('cargo', args, { cwd: racine, env, stdio: 'inherit' });
190
+ }
151
191
  t.code = r.error ? 127 : (r.status ?? 128 + (constants.signals[r.signal] ?? 0));
152
192
  if (junit && dossier && existsSync(junit)) {
153
193
  mkdirSync(path.join(dossier, JUNIT), { recursive: true });
@@ -182,30 +222,40 @@ function depuisLeVert(racine, tous, tout, env) {
182
222
  }
183
223
 
184
224
  // Plans and plays the tests of the crates <choix> (each `{ c, cibles }`, `cibles` the test targets
185
- // named, empty for the whole crate) in the run <p>.
225
+ // named, empty for the whole crate) in the run <p>: for a crate that plays tests, the build of its
226
+ // test targets first, then nextest, then its doctests; a failed build leaves the crate's other
227
+ // tasks not played.
186
228
  function jouerLesTests(racine, p, choix, options) {
187
229
  const m = metadonnees(racine);
188
230
  const junit = path.join(m.target_directory, 'nextest', PROFIL, 'junit.xml');
189
- const prevues = [];
231
+ const parCrate = [];
190
232
  for (const { c, cibles } of choix) {
191
233
  Object.assign(p.cibles, binaires(c));
192
234
  const d = c.composant.dossier;
235
+ const nom = c.composant.nom;
236
+ const prevues = [];
193
237
  if (joueDesTests(racine, c.composant)) {
238
+ const selection = ['-p', nom, ...cibles.flatMap(n => ['--test', n])];
239
+ const journal = path.join(m.target_directory, 'grillhouse', `${nom}-build.log`);
240
+ const construction = ['test', '--no-run', ...selection];
241
+ prevues.push([p.prevoir(nom, d, 'build', false, construction), { journal }]);
194
242
  const args = ['nextest', 'run', '--tool-config-file', `${PROFIL}:${NEXTEST}`];
195
- args.push('--profile', PROFIL, '--no-fail-fast', '-p', c.composant.nom);
196
- for (const n of cibles) {
197
- args.push('--test', n);
198
- }
199
- prevues.push([p.prevoir(c.composant.nom, d, 'nextest', true, [...args, ...options]), junit]);
243
+ args.push('--profile', PROFIL, '--no-fail-fast', ...selection);
244
+ prevues.push([p.prevoir(nom, d, 'nextest', true, [...args, ...options]), { junit }]);
200
245
  }
201
246
  const doctests = c.cibles.some(t => t.kind.includes('lib') && t.doctest !== false);
202
247
  if (cibles.length === 0 && doctests) {
203
- const args = ['test', '--doc', '-p', c.composant.nom];
204
- prevues.push([p.prevoir(c.composant.nom, d, 'doctest', true, args), null]);
248
+ const args = ['test', '--doc', '-p', nom];
249
+ prevues.push([p.prevoir(nom, d, 'doctest', true, args), {}]);
205
250
  }
251
+ parCrate.push(prevues);
206
252
  }
207
- for (const [t, j] of prevues) {
208
- p.jouer(t, j);
253
+ for (const prevues of parCrate) {
254
+ for (const [t, o] of prevues) {
255
+ if (p.jouer(t, o) !== 0 && t.t.script === 'build') {
256
+ break;
257
+ }
258
+ }
209
259
  }
210
260
  }
211
261
 
@@ -295,6 +345,23 @@ function sousLaBase(genre, env, jouer) {
295
345
  }
296
346
  }
297
347
 
348
+ /**
349
+ * The line that refuses the workspace at <racine> whose Cargo.lock git does not track, the
350
+ * gesture named; null when git tracks it.
351
+ * @param {string} racine
352
+ * @returns {string | null}
353
+ */
354
+ export function verrouNonVersionne(racine) {
355
+ if (!existsSync(path.join(racine, VERROU))) {
356
+ return `⛔ ${VERROU} absent : cargo generate-lockfile, puis git add ${VERROU}`;
357
+ }
358
+ const r = spawnSync('git', ['ls-files', '--error-unmatch', '--', VERROU], {
359
+ cwd: racine,
360
+ stdio: 'ignore',
361
+ });
362
+ return r.status === 0 ? null : `⛔ ${VERROU} non versionné : git add ${VERROU}`;
363
+ }
364
+
298
365
  /**
299
366
  * Runs the command <nom> with <args> in the workspace at <racine>: its exit code.
300
367
  * @param {string} nom one of NOMS
@@ -302,6 +369,11 @@ function sousLaBase(genre, env, jouer) {
302
369
  * @param {{ racine?: string, env?: NodeJS.ProcessEnv }} [o]
303
370
  */
304
371
  export function lancer(nom, args, { racine = process.cwd(), env = process.env } = {}) {
372
+ const refus = VERROUILLEES.includes(nom) ? verrouNonVersionne(racine) : null;
373
+ if (refus) {
374
+ process.stderr.write(`${refus}\n`);
375
+ return 2;
376
+ }
305
377
  const p = passe(racine, env);
306
378
  if (nom === 'typer') {
307
379
  p.jouer(p.prevoir(RACINE, racine, 'check', false, ['check', '--all-targets']));
@@ -108,12 +108,14 @@ export function joueDesTests(_racine, composant) {
108
108
 
109
109
  /**
110
110
  * The readers, by their manifests, of the crates <noms> among <composants> of <racine>: each a
111
- * reader `{ composant, par }`, `par` the kinds of its dependencies on it.
111
+ * reader `{ composant, par }`, `par` the kinds of its dependencies on it; what each crate reads
112
+ * (`lit`), every kind; what its tests read (`parLesTests`), its dependencies of development.
112
113
  */
113
114
  export function lecteurs(racine, { composants: liste, noms }) {
114
115
  const tous = crates(racine);
115
116
  const parDossier = new Map(liste.map(c => [c.dossier, c]));
116
117
  const lit = new Map(liste.map(c => [c, new Set()]));
118
+ const parLesTests = new Map(liste.map(c => [c, new Set()]));
117
119
  const genres = new Map(liste.map(c => [c, new Map()]));
118
120
  for (const c of tous) {
119
121
  const lecteur = parDossier.get(c.composant.dossier);
@@ -126,6 +128,9 @@ export function lecteurs(racine, { composants: liste, noms }) {
126
128
  continue;
127
129
  }
128
130
  lit.get(lecteur).add(lu);
131
+ if (d.genre === 'dev') {
132
+ parLesTests.get(lecteur).add(lu);
133
+ }
129
134
  const g = genres.get(lu);
130
135
  if (!g.has(lecteur)) {
131
136
  g.set(lecteur, new Set());
@@ -151,6 +156,7 @@ export function lecteurs(racine, { composants: liste, noms }) {
151
156
  sansFournisseur,
152
157
  types: { etat: 'fait', raison: null, elements: [] },
153
158
  lit,
159
+ parLesTests,
154
160
  };
155
161
  }
156
162
 
@@ -12,6 +12,8 @@
12
12
  // out of every crate added: `change`, measured from its commit; the same with a second commit
13
13
  // that changes `ws-core`, adds the crate `ws-neuf` and removes `ws-outil`: `lot`; the same, the
14
14
  // interface of `ws-core` then changed, its index late: `enRetard`.
15
+ // - Each workspace commits its Cargo.lock, the one cargo writes (grillhouse-rph): the commands
16
+ // tester, verifier and preparer refuse a workspace whose Cargo.lock git does not track.
15
17
  // - A crate at the root, its workspace `members = ["."]`, with its tests, as OSC Bridge: `seul`;
16
18
  // a crate at the root holding a second crate, `crates/aide`, none with tests: `imbrique`.
17
19
  // - A directory without Cargo.toml: `vide`; one with a tsconfig.json alone: `typescript`.
@@ -82,6 +84,35 @@ export const INDEX = [
82
84
  '',
83
85
  ].join('\n');
84
86
 
87
+ // The Cargo.lock that cargo writes for the crates <paquets> (`[nom, [dépendance…]]`), each at
88
+ // 0.1.0, sorted by name, as `cargo generate-lockfile` writes it: every trial commits its own, as
89
+ // Cargo recommends for every project (grillhouse-rph).
90
+ const verrou = paquets =>
91
+ [
92
+ '# This file is automatically @generated by Cargo.',
93
+ '# It is not intended for manual editing.',
94
+ 'version = 4',
95
+ ...[...paquets]
96
+ .sort(([a], [b]) => (a < b ? -1 : 1))
97
+ .map(([nom, deps = []]) =>
98
+ [
99
+ '',
100
+ '[[package]]',
101
+ `name = "${nom}"`,
102
+ 'version = "0.1.0"',
103
+ ...(deps.length ? ['dependencies = [', ...deps.map(x => ` "${x}",`), ']'] : []),
104
+ ].join('\n')
105
+ ),
106
+ '',
107
+ ].join('\n');
108
+ // The lock of the four crates of the workspace, and its dependencies by crate.
109
+ const DEPENDANCES = {
110
+ 'ws-app': ['ws-core'],
111
+ 'ws-core': [],
112
+ 'ws-matiere': [],
113
+ 'ws-outil': ['ws-app', 'ws-core'],
114
+ };
115
+
85
116
  const membres = noms =>
86
117
  `[workspace]\nresolver = "2"\nmembers = [${noms.map(n => `"crates/${n}"`).join(', ')}]\n`;
87
118
 
@@ -90,6 +121,7 @@ function espace(dans) {
90
121
  const racine = mkdtempSync(path.join(dans, 'espace-'));
91
122
  const ecrire = ecrireDans(racine);
92
123
  ecrire('Cargo.toml', membres(Object.keys(CRATES)));
124
+ ecrire('Cargo.lock', verrou(Object.entries(DEPENDANCES)));
93
125
  ecrire('.gitignore', '/target\n');
94
126
  ecrire('README.md', "# L'espace d'essai\n");
95
127
  for (const [n, m] of Object.entries(CRATES)) {
@@ -121,6 +153,7 @@ function aLaRacine(dans, nom, membresEnPlus, fichiers) {
121
153
  'Cargo.toml',
122
154
  `[workspace]\nmembers = [${['.', ...membresEnPlus].map(m => `"${m}"`).join(', ')}]\n\n${manifeste(nom)}`
123
155
  );
156
+ ecrire('Cargo.lock', verrou([nom, ...membresEnPlus.map(m => path.basename(m))].map(n => [n])));
124
157
  ecrire('.gitignore', '/target\n');
125
158
  for (const [f, t] of Object.entries(fichiers)) {
126
159
  ecrire(f, t);
@@ -197,6 +230,10 @@ export default {
197
230
  ecrireLot('crates/neuf/Cargo.toml', manifeste('ws-neuf'));
198
231
  ecrireLot('crates/neuf/src/lib.rs', 'pub fn neuf() {}\n');
199
232
  ecrireLot('Cargo.toml', membres(['core', 'app', 'matiere', 'neuf']));
233
+ ecrireLot(
234
+ 'Cargo.lock',
235
+ verrou([...Object.entries(DEPENDANCES).filter(([n]) => n !== 'ws-outil'), ['ws-neuf']])
236
+ );
200
237
  rmSync(path.join(lot, 'crates/outil'), { recursive: true, force: true });
201
238
  git(lot, 'add', '-A');
202
239
  git(lot, 'commit', '-q', '-m', 'lot');
@@ -319,6 +356,7 @@ export default {
319
356
  valide: { racine: aJour, avant: 'HEAD', apres: 'HEAD' },
320
357
  invalide: { racine: lot, avant: avantLeLot, apres: 'HEAD' },
321
358
  attendu: [
359
+ 'fichier Cargo.lock',
322
360
  'fichier Cargo.toml',
323
361
  'fichier crates/core/src/lib.rs',
324
362
  'fichier crates/neuf/Cargo.toml',
@@ -15,6 +15,9 @@
15
15
  // - The root scripts `test`, `test:forcer` and `verifier` a project lacks become the template's:
16
16
  // the agents run `npm test`, the integration and the night `npm run verifier`. A project's own
17
17
  // script stays.
18
+ // - A Cargo.lock that git does not track is left to the project (`aFaire`, grillhouse-rph): the
19
+ // line of ./commandes.mjs (`verrouNonVersionne`), the gesture named; the core writes it on the
20
+ // error stream and plays no verification, which `--locked` would fail in a copy taken from git.
18
21
  // - The generator: the index of the interfaces (./index-interfaces.mjs), run where the project
19
22
  // holds it, as the module typescript's.
20
23
  // - The installation of its binaries (./binaires.json): the commands of ./binaires.mjs, which list
@@ -22,6 +25,7 @@
22
25
  import { copyFileSync, existsSync, mkdirSync, readdirSync } from 'node:fs';
23
26
  import path from 'node:path';
24
27
  import { fileURLToPath } from 'node:url';
28
+ import { verrouNonVersionne } from './commandes.mjs';
25
29
  import { SORTIE } from './index-interfaces.mjs';
26
30
 
27
31
  const BINAIRES = path.join(path.dirname(fileURLToPath(import.meta.url)), 'binaires.mjs');
@@ -70,12 +74,14 @@ function appliquer(projet, { p, modele, source }) {
70
74
  `Scripts des tests : ${scripts.map(n => `${n} (\`${p.scripts[n]}\`)`).join(', ')} écrits ; les agents lancent \`npm test\`, l'intégration et la nuit \`npm run verifier\`.`
71
75
  );
72
76
  }
77
+ const verrou = verrouNonVersionne(projet);
73
78
  return {
74
79
  bilan: {
75
80
  gabarit: copies.length > 0 ? copies : null,
76
81
  scripts: scripts.length > 0 ? scripts : null,
77
82
  },
78
83
  lignes,
84
+ aFaire: verrou ? [verrou] : [],
79
85
  installer: false,
80
86
  sansVerifier: null,
81
87
  };