@roomi-fields/grillhouse 0.26.0 → 0.28.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/agents/explorateur.md +1 -1
- package/cadre/templates/paquet/docs/CADRE.md +36 -0
- package/cadre/templates/paquet/docs/INTERFACE.md +10 -0
- package/cadre/templates/projet/CLAUDE.md +7 -0
- package/cadre/templates/projet/docs/ARCHITECTURE.md +15 -0
- package/cadre/templates/python/package.json +18 -0
- package/charte.md +48 -1
- package/docs/ARCHITECTURE.md +113 -20
- package/docs/CADRE.md +7 -6
- package/docs/INTERFACE.md +111 -32
- package/package.json +1 -1
- package/scripts/circuit.mjs +304 -40
- package/scripts/commande-du-langage.mjs +2 -2
- package/scripts/commandes-composees.mjs +156 -0
- package/scripts/composition-des-langages.mjs +306 -0
- package/scripts/conformite.mjs +1 -3
- package/scripts/dernier-vert.mjs +15 -2
- package/scripts/engendres.mjs +170 -0
- package/scripts/enveloppe/lancer.sh +10 -6
- package/scripts/enveloppe/travail-de-la-copie.mjs +82 -8
- package/scripts/etapes.mjs +18 -5
- package/scripts/gardes-du-cadre.mjs +7 -4
- package/scripts/grillhouse-maj.mjs +157 -103
- package/scripts/index-interfaces.mjs +78 -0
- package/scripts/init.mjs +5 -5
- package/scripts/integration/file.mjs +74 -13
- package/scripts/integration/integrer.mjs +50 -62
- package/scripts/jointure.d.ts +44 -13
- package/scripts/langages/cargo/binaires.mjs +29 -6
- package/scripts/langages/cargo/clippy.mjs +4 -2
- package/scripts/langages/cargo/commandes.mjs +45 -7
- package/scripts/langages/cargo/exemples.mjs +1 -15
- package/scripts/langages/cargo/index-interfaces.mjs +20 -3
- package/scripts/langages/cargo/index.mjs +12 -10
- package/scripts/langages/cargo/mise-a-jour.mjs +2 -1
- package/scripts/langages/cargo/sccache.mjs +29 -0
- package/scripts/langages/cargo/squelette.mjs +111 -0
- package/scripts/langages/python/binaires.json +3 -0
- package/scripts/langages/python/binaires.mjs +59 -0
- package/scripts/langages/python/commandes.mjs +411 -0
- package/scripts/langages/python/composants.mjs +272 -0
- package/scripts/langages/python/exemples.mjs +260 -0
- package/scripts/langages/python/index-interfaces.mjs +77 -0
- package/scripts/langages/python/index.mjs +97 -0
- package/scripts/langages/python/lot.mjs +76 -0
- package/scripts/langages/python/mise-a-jour.mjs +54 -0
- package/scripts/langages/python/squelette.mjs +66 -0
- package/scripts/langages/python/tailles-des-tests.mjs +102 -0
- package/scripts/langages/python/verdict.mjs +85 -0
- package/scripts/langages/typescript/exemples.mjs +1 -20
- package/scripts/langages/typescript/frontieres.mjs +14 -1
- package/scripts/langages/typescript/index-interfaces.mjs +10 -3
- package/scripts/langages/typescript/index.mjs +14 -15
- package/scripts/langages/typescript/squelette.mjs +120 -0
- package/scripts/langages-des-paquets.mjs +171 -0
- package/scripts/langages.mjs +60 -41
- package/scripts/migrations/0.27.0-langages-dans-l-architecture.mjs +182 -0
- package/scripts/migrations.mjs +2 -0
- package/scripts/outils-cles.mjs +1 -1
- package/scripts/paquet.mjs +261 -0
- package/scripts/resultats.mjs +54 -1
- package/scripts/session-start.sh +34 -9
- package/scripts/sources.mjs +2 -1
- package/scripts/sous-commandes.mjs +6 -3
- package/scripts/tableau-des-composants.mjs +140 -0
- package/scripts/verrous/verrou.mjs +3 -2
- package/skills/explorateur/SKILL.md +33 -4
- package/skills/grill/SKILL.md +14 -1
- package/skills/pitmaster/SKILL.md +34 -4
- package/skills/pitmaster/references/consigne-agent.md +33 -4
- package/skills/redacteur/references/documents-d-un-composant.md +12 -0
- package/skills/relecteur/SKILL.md +12 -0
- package/skills/testwriter/SKILL.md +6 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// The module of language python: what the core asks of a language (scripts/jointure.d.ts,
|
|
2
|
+
// docs/INTERFACE.md), answered for the packages of Python by uv and pytest, as Pants's Python
|
|
3
|
+
// backend reads a pyproject.toml. The core loads it by scripts/langages.mjs, and this module
|
|
4
|
+
// imports of the core its published entries alone.
|
|
5
|
+
//
|
|
6
|
+
// - The manifest of its package, which the guard of the languages asks of a package the
|
|
7
|
+
// architecture declares python (`manifeste`): a pyproject.toml (PEP 621), its group `test` of
|
|
8
|
+
// `[dependency-groups]` (PEP 735) and its uv.lock. Its one tool of npm is smol-toml, the reader
|
|
9
|
+
// of a pyproject.toml (`outils`); uv lives on the machine, installed by the update at its exact
|
|
10
|
+
// version (`binaires`, ./binaires.json). What uv, pytest and Python write in a project: `.venv`,
|
|
11
|
+
// `.pytest_cache`, `__pycache__` (`ignorer`).
|
|
12
|
+
// - Where they write, which the envelope opens to a session (`sorties`): in writing, `.venv` and
|
|
13
|
+
// `.pytest_cache` at the root, where the commands make uv and pytest write for each package
|
|
14
|
+
// (./commandes.mjs), and uv's cache, `~/.cache/uv`; proper to the session, the
|
|
15
|
+
// tree of the bytecode at the root, `__pycache__` (PYTHONPYCACHEPREFIX, ./commandes.mjs); read,
|
|
16
|
+
// the Pythons uv installs, `~/.local/share/uv/python`. The version of Python is uv's choice, from
|
|
17
|
+
// `requires-python` and `.python-version`. The rules that refuse a role that writes pytest run
|
|
18
|
+
// directly (`droits`).
|
|
19
|
+
// - The packages, a file's, the test files, what the testwriter writes, of the manifests too, the
|
|
20
|
+
// readers, the entries of the index of the interfaces (./composants.mjs); the packages touched
|
|
21
|
+
// since a commit and the elements of a lot (./lot.mjs).
|
|
22
|
+
// - The commands `tester`, `verifier`, `typer`, `preparer` and `tests-de-nuit` (./commandes.mjs),
|
|
23
|
+
// each described, never run, and the verdict of a run (./verdict.mjs); the guard of the sizes of
|
|
24
|
+
// the tests (./tailles-des-tests.mjs) and the index of the interfaces up to date, each a command
|
|
25
|
+
// by its name too. The generated file, the index of the interfaces (./index-interfaces.mjs), its
|
|
26
|
+
// command and its check, which the core's takes the place of in a project of several languages.
|
|
27
|
+
// No migration yet.
|
|
28
|
+
// - Its share of the update (./mise-a-jour.mjs): the template `templates/python/`, its test
|
|
29
|
+
// scripts, the generator of the index and the installation of uv.
|
|
30
|
+
// - The skeleton of a new package (./squelette.mjs, `squelette`), which `grillhouse paquet` writes.
|
|
31
|
+
import { readFileSync } from 'node:fs';
|
|
32
|
+
import path from 'node:path';
|
|
33
|
+
import { fileURLToPath } from 'node:url';
|
|
34
|
+
import { commandes, GARDES, PYCACHE } from './commandes.mjs';
|
|
35
|
+
import {
|
|
36
|
+
composantDans,
|
|
37
|
+
composants,
|
|
38
|
+
entreesDeLIndex,
|
|
39
|
+
estUnTest,
|
|
40
|
+
joueDesTests,
|
|
41
|
+
lecteurs,
|
|
42
|
+
manifestes,
|
|
43
|
+
} from './composants.mjs';
|
|
44
|
+
import { enRetard, SORTIE } from './index-interfaces.mjs';
|
|
45
|
+
import { elementsDuLot, touches } from './lot.mjs';
|
|
46
|
+
import { miseAJour } from './mise-a-jour.mjs';
|
|
47
|
+
import { squelette } from './squelette.mjs';
|
|
48
|
+
import { verdict } from './verdict.mjs';
|
|
49
|
+
|
|
50
|
+
const ici = nom => path.join(path.dirname(fileURLToPath(import.meta.url)), nom);
|
|
51
|
+
|
|
52
|
+
export default {
|
|
53
|
+
nom: 'python',
|
|
54
|
+
manifeste: 'pyproject.toml',
|
|
55
|
+
outils: ['smol-toml'],
|
|
56
|
+
binaires: JSON.parse(readFileSync(ici('binaires.json'), 'utf8')),
|
|
57
|
+
ignorer: ['.venv', '.pytest_cache', PYCACHE],
|
|
58
|
+
sorties: {
|
|
59
|
+
ecrites: ['.venv/', '.pytest_cache/', '~/.cache/uv/'],
|
|
60
|
+
propres: [PYCACHE],
|
|
61
|
+
lues: ['~/.local/share/uv/python/'],
|
|
62
|
+
},
|
|
63
|
+
// pytest run directly, by itself, by Python or by uv: `npm test` and `npm run verifier` play it.
|
|
64
|
+
droits: [
|
|
65
|
+
'Bash(pytest*)',
|
|
66
|
+
'Bash(python -m pytest*)',
|
|
67
|
+
'Bash(python3 -m pytest*)',
|
|
68
|
+
'Bash(uv run*pytest*)',
|
|
69
|
+
],
|
|
70
|
+
composants,
|
|
71
|
+
composantDe: (racine, fichier) => composantDans(composants(racine), racine, fichier),
|
|
72
|
+
matieres: () => [],
|
|
73
|
+
joueDesTests,
|
|
74
|
+
lecteurs,
|
|
75
|
+
touches,
|
|
76
|
+
elementsDuLot,
|
|
77
|
+
commandes,
|
|
78
|
+
verdict,
|
|
79
|
+
estUnTest,
|
|
80
|
+
manifestes,
|
|
81
|
+
fichiersEngendres: () => [
|
|
82
|
+
{
|
|
83
|
+
nom: "l'index des interfaces",
|
|
84
|
+
commande: `node ${JSON.stringify(ici('index-interfaces.mjs'))}`,
|
|
85
|
+
fichiers: [SORTIE],
|
|
86
|
+
lit: ['docs/INTERFACE.md', '**/docs/INTERFACE.md'],
|
|
87
|
+
gardes: ['index-interfaces'],
|
|
88
|
+
entiers: [SORTIE],
|
|
89
|
+
verifier: enRetard,
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
entreesDeLIndex,
|
|
93
|
+
gardes: () => GARDES.map(({ script, args }) => [script, ...args]),
|
|
94
|
+
migrations: [],
|
|
95
|
+
miseAJour,
|
|
96
|
+
squelette,
|
|
97
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// The changes of a project of Python read by git: the packages touched since a commit (`touches`
|
|
2
|
+
// of the join, scripts/jointure.d.ts) and the elements of a lot (`elementsDuLot`).
|
|
3
|
+
//
|
|
4
|
+
// - The files changed since a commit: what git sees changed, the working tree and the untracked
|
|
5
|
+
// files included (`git diff --name-only --no-renames <depuis>`, `git ls-files -o
|
|
6
|
+
// --exclude-standard`). Each touches the package of the longest folder that holds it
|
|
7
|
+
// (./composants.mjs); a file out of every package is out of the graph. No dependent: the module
|
|
8
|
+
// reads no dependency between packages of Python.
|
|
9
|
+
// - The lot between two commits (`git diff --name-only --no-renames <avant> <apres>`): every file
|
|
10
|
+
// it changes in `fichiers`; the module reads no element of a source of Python, so each `.py` is
|
|
11
|
+
// named in `horsDuService`, which the reviewer surveys himself.
|
|
12
|
+
import { spawnSync } from 'node:child_process';
|
|
13
|
+
import { composantDans, composants } from './composants.mjs';
|
|
14
|
+
|
|
15
|
+
const lignesDeGit = (racine, args) => {
|
|
16
|
+
const r = spawnSync('git', ['-C', racine, ...args, '-z'], {
|
|
17
|
+
encoding: 'utf8',
|
|
18
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
19
|
+
});
|
|
20
|
+
if (r.status !== 0) {
|
|
21
|
+
throw new Error(`⛔ git ${args.join(' ')} : ${r.stderr.trim()}`);
|
|
22
|
+
}
|
|
23
|
+
return r.stdout.split('\0').filter(Boolean);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** The packages the files <fichiers> (from <racine>) touch, and the files out of the graph. */
|
|
27
|
+
export function touchesDesFichiers(racine, fichiers) {
|
|
28
|
+
const liste = composants(racine);
|
|
29
|
+
const touches = new Set();
|
|
30
|
+
const horsGraphe = [];
|
|
31
|
+
for (const f of new Set(fichiers)) {
|
|
32
|
+
const c = composantDans(liste, racine, f);
|
|
33
|
+
if (c) {
|
|
34
|
+
touches.add(c);
|
|
35
|
+
} else {
|
|
36
|
+
horsGraphe.push(f);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
touches: [...touches].sort((a, b) => a.nom.localeCompare(b.nom)),
|
|
41
|
+
dependants: [],
|
|
42
|
+
horsGraphe: horsGraphe.sort(),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The packages touched in <racine> since the commit <depuis>, and the files out of the graph. */
|
|
47
|
+
export function touches(racine, { depuis }) {
|
|
48
|
+
return touchesDesFichiers(racine, [
|
|
49
|
+
...lignesDeGit(racine, ['diff', '--name-only', '--no-renames', depuis]),
|
|
50
|
+
...lignesDeGit(racine, ['ls-files', '-o', '--exclude-standard']),
|
|
51
|
+
]);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The elements of the lot of <racine> between <avant> and <apres>. */
|
|
55
|
+
export function elementsDuLot(racine, { avant, apres }) {
|
|
56
|
+
try {
|
|
57
|
+
const fichiers = [
|
|
58
|
+
...new Set(lignesDeGit(racine, ['diff', '--name-only', '--no-renames', avant, apres])),
|
|
59
|
+
].sort();
|
|
60
|
+
return {
|
|
61
|
+
etat: 'fait',
|
|
62
|
+
raison: null,
|
|
63
|
+
elements: [],
|
|
64
|
+
horsDuService: fichiers.filter(f => f.endsWith('.py')),
|
|
65
|
+
fichiers,
|
|
66
|
+
};
|
|
67
|
+
} catch (e) {
|
|
68
|
+
return {
|
|
69
|
+
etat: 'impossible',
|
|
70
|
+
raison: `erreur : ${String(e.message).split('\n')[0]}`,
|
|
71
|
+
elements: [],
|
|
72
|
+
horsDuService: [],
|
|
73
|
+
fichiers: [],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// What the module python brings to the update of a project (`grillhouse maj`,
|
|
2
|
+
// scripts/grillhouse-maj.mjs), the demand `miseAJour` of the join (scripts/jointure.d.ts).
|
|
3
|
+
//
|
|
4
|
+
// - The template: `templates/python/` of the frame's files. Its package.json gives the frame's
|
|
5
|
+
// scripts, which run the frame's commands, and smol-toml, the reader of a pyproject.toml.
|
|
6
|
+
// - The root scripts `test`, `test:forcer` and `verifier` a project lacks become the template's;
|
|
7
|
+
// a project's own script stays.
|
|
8
|
+
// - The generator: the index of the interfaces (./index-interfaces.mjs), run where the project
|
|
9
|
+
// holds it, as the module cargo's.
|
|
10
|
+
// - The installation of uv (./binaires.json) by the commands of ./binaires.mjs, which the core runs.
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import { SORTIE } from './index-interfaces.mjs';
|
|
14
|
+
|
|
15
|
+
const BINAIRES = path.join(path.dirname(fileURLToPath(import.meta.url)), 'binaires.mjs');
|
|
16
|
+
const GABARIT = 'templates/python';
|
|
17
|
+
const SCRIPTS_DES_TESTS = ['test', 'test:forcer', 'verifier'];
|
|
18
|
+
|
|
19
|
+
/** @type {import('../../jointure.js').MiseAJour['appliquer']} */
|
|
20
|
+
function appliquer(_projet, { p, modele }) {
|
|
21
|
+
p.scripts ??= {};
|
|
22
|
+
const scripts = [];
|
|
23
|
+
for (const nom of SCRIPTS_DES_TESTS) {
|
|
24
|
+
const script = modele.scripts?.[nom];
|
|
25
|
+
if (typeof script !== 'string' || typeof p.scripts[nom] === 'string') {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
p.scripts[nom] = script;
|
|
29
|
+
scripts.push(nom);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
bilan: { scripts: scripts.length > 0 ? scripts : null },
|
|
33
|
+
lignes:
|
|
34
|
+
scripts.length > 0
|
|
35
|
+
? [
|
|
36
|
+
`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\`.`,
|
|
37
|
+
]
|
|
38
|
+
: [],
|
|
39
|
+
aFaire: [],
|
|
40
|
+
installer: false,
|
|
41
|
+
sansVerifier: null,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The share of the module python in the update. */
|
|
46
|
+
export const miseAJour = {
|
|
47
|
+
gabarit: GABARIT,
|
|
48
|
+
appliquer,
|
|
49
|
+
generateurs: [{ commande: 'index-interfaces', args: [], sortie: SORTIE }],
|
|
50
|
+
installation: {
|
|
51
|
+
liste: { script: BINAIRES, args: ['liste'] },
|
|
52
|
+
installer: (nom, version) => ({ script: BINAIRES, args: ['installer', `${nom}@${version}`] }),
|
|
53
|
+
},
|
|
54
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// The skeleton of a new package of the module python, the demand `squelette` of the join
|
|
2
|
+
// (scripts/jointure.d.ts), which `grillhouse paquet` writes (scripts/paquet.mjs), as `uv init`
|
|
3
|
+
// writes one: no behaviour, no test.
|
|
4
|
+
//
|
|
5
|
+
// - Its files: its pyproject.toml (PEP 621: its name, the folder's, its version 0.1.0, the Python
|
|
6
|
+
// it requires, no dependency; its group `test` of `[dependency-groups]`, PEP 735, pytest, which
|
|
7
|
+
// the module runs by `uv run --group test pytest`; the configuration of pytest,
|
|
8
|
+
// `[tool.pytest.ini_options]`, its tests under `tests/` and its code importable from `src/`, as
|
|
9
|
+
// uv's layout of a library has it); `src/<module>/__init__.py`, the module named after the
|
|
10
|
+
// package (`-` read `_`), without code; `tests/.gitkeep`, its folder of tests. The typing is
|
|
11
|
+
// `python -m compileall`, which needs no configuration. No build system: uv neither builds nor
|
|
12
|
+
// installs the package to run its tests.
|
|
13
|
+
// - The workspace: a root pyproject.toml whose `[tool.uv.workspace]` names its `members` receives
|
|
14
|
+
// the package's path there, as `uv init` adds a project under a workspace to its members; without
|
|
15
|
+
// one, the package is its own project of uv, as the module plays each package (./commandes.mjs).
|
|
16
|
+
// - The lock of the versions: `uv lock`, at the workspace's root, else in the package.
|
|
17
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
18
|
+
import { createRequire } from 'node:module';
|
|
19
|
+
import path from 'node:path';
|
|
20
|
+
|
|
21
|
+
const require = createRequire(import.meta.url);
|
|
22
|
+
|
|
23
|
+
/** @type {import('../../jointure.js').Langage['squelette']} */
|
|
24
|
+
export function squelette(racine, { chemin }) {
|
|
25
|
+
const nom = path.posix.basename(chemin);
|
|
26
|
+
const module = nom.replace(/-/g, '_');
|
|
27
|
+
const manifeste = [
|
|
28
|
+
'[project]',
|
|
29
|
+
`name = ${JSON.stringify(nom)}`,
|
|
30
|
+
'version = "0.1.0"',
|
|
31
|
+
'requires-python = ">=3.12"',
|
|
32
|
+
'dependencies = []',
|
|
33
|
+
'',
|
|
34
|
+
'[dependency-groups]',
|
|
35
|
+
'test = ["pytest>=8"]',
|
|
36
|
+
'',
|
|
37
|
+
'[tool.pytest.ini_options]',
|
|
38
|
+
'testpaths = ["tests"]',
|
|
39
|
+
'pythonpath = ["src"]',
|
|
40
|
+
'',
|
|
41
|
+
].join('\n');
|
|
42
|
+
const fichiers = {
|
|
43
|
+
[`${chemin}/pyproject.toml`]: manifeste,
|
|
44
|
+
[`${chemin}/src/${module}/__init__.py`]: `"""The package ${nom}: its interface, docs/INTERFACE.md, says what it offers."""\n`,
|
|
45
|
+
[`${chemin}/tests/.gitkeep`]: '',
|
|
46
|
+
};
|
|
47
|
+
const f = path.join(racine, 'pyproject.toml');
|
|
48
|
+
const texte = existsSync(f) ? readFileSync(f, 'utf8') : null;
|
|
49
|
+
const espace =
|
|
50
|
+
texte === null ? null : (require('smol-toml').parse(texte).tool?.uv?.workspace ?? null);
|
|
51
|
+
const membres = Array.isArray(espace?.members) ? espace.members : null;
|
|
52
|
+
let entree = null;
|
|
53
|
+
if (membres && !membres.some(m => typeof m === 'string' && path.matchesGlob(chemin, m))) {
|
|
54
|
+
const m = /^(\s*members\s*=\s*\[)([\s\S]*?)(\])/m.exec(
|
|
55
|
+
texte.slice(texte.search(/^\s*\[tool\.uv\.workspace\]/m))
|
|
56
|
+
);
|
|
57
|
+
const corps = m[2].replace(/\s*$/, '').replace(/,$/, '');
|
|
58
|
+
const ajout = `${m[1]}${corps.trim() ? `${corps}, ` : ''}${JSON.stringify(chemin)}${m[3]}`;
|
|
59
|
+
entree = { fichier: 'pyproject.toml', texte: texte.replace(m[0], ajout) };
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
fichiers,
|
|
63
|
+
espace: entree,
|
|
64
|
+
verrouiller: { commande: 'uv', args: ['lock'], dossier: membres ? '.' : chemin },
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The size of each test of Python, on the model of the test pyramid of Google and of Bazel's
|
|
3
|
+
// `size`, as the module typescript's guard (../typescript/tailles-des-tests.mjs): a large test of
|
|
4
|
+
// the day is refused, as it belongs to the night.
|
|
5
|
+
//
|
|
6
|
+
// npx grillhouse tailles-des-tests run from the repository root (a guard of grillhouse:gardes)
|
|
7
|
+
//
|
|
8
|
+
// - The test files are those of each package (./composants.mjs, `fichiersDeTest`): `test_*.py`
|
|
9
|
+
// and `*_test.py`, a night test `*_nuit_test.py`.
|
|
10
|
+
// - A test is classed by a static reading of its text and of its package's `conftest.py` files on
|
|
11
|
+
// its path, which pytest loads with it:
|
|
12
|
+
// - large (`grand`): it starts a process (it imports `subprocess`), mounts a trial repository
|
|
13
|
+
// (git's `init`, `clone` or `worktree add`) and starts there something else than git;
|
|
14
|
+
// - medium (`moyen`): it starts a process;
|
|
15
|
+
// - small (`petit`): it starts none.
|
|
16
|
+
// - A large test of the day is a finding, `{ fichier, regle: 'grand-de-jour', message }`; a night
|
|
17
|
+
// test never is one. A finding inscribed in the project's debt (`grillhouse-dette.json`,
|
|
18
|
+
// ../../dette.mjs) passes, and a new one is refused.
|
|
19
|
+
// - The guard writes on its error stream the count of each size, the night's included.
|
|
20
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
import { pathToFileURL } from 'node:url';
|
|
23
|
+
import { trancher } from '../../dette.mjs';
|
|
24
|
+
import { composants, estDeNuit, fichiersDeTest } from './composants.mjs';
|
|
25
|
+
|
|
26
|
+
// The name of its findings and of its debt, apart from the module typescript's guard of the same
|
|
27
|
+
// command, whose section of the debt it never writes.
|
|
28
|
+
export const GARDE = 'tailles-des-tests-python';
|
|
29
|
+
export const GRAND_DE_JOUR = 'grand-de-jour';
|
|
30
|
+
|
|
31
|
+
// The import of the module that starts a process.
|
|
32
|
+
const PROCESSUS = /^\s*(?:import\s+subprocess\b|from\s+subprocess\s+import\b)/m;
|
|
33
|
+
// A trial repository mounted: git's `init`, `clone` or `worktree add`, as an argument or a command.
|
|
34
|
+
const DEPOT_D_ESSAI =
|
|
35
|
+
/['"](?:init|clone)['"]|\bgit\s+(?:-C\s+\S+\s+)?(?:init|clone)\b|['"]worktree['"]\s*,\s*['"]add['"]|\bworktree\s+add\b/;
|
|
36
|
+
// A call of subprocess, its first argument captured.
|
|
37
|
+
const APPEL = /\bsubprocess\.(?:run|Popen|call|check_call|check_output)\s*\(\s*\[?\s*([^,\])\n]*)/g;
|
|
38
|
+
// A first argument that names git.
|
|
39
|
+
const GIT = /^['"]git(?:['"]|\s)/;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The size of the test file <fichier> (absolute) of the package at <dossier>: `petit`, `moyen` or
|
|
43
|
+
* `grand`.
|
|
44
|
+
*/
|
|
45
|
+
export function classer(fichier, dossier) {
|
|
46
|
+
const textes = [readFileSync(fichier, 'utf8')];
|
|
47
|
+
for (let d = path.dirname(fichier); ; d = path.dirname(d)) {
|
|
48
|
+
const conftest = path.join(d, 'conftest.py');
|
|
49
|
+
if (existsSync(conftest)) {
|
|
50
|
+
textes.push(readFileSync(conftest, 'utf8'));
|
|
51
|
+
}
|
|
52
|
+
if (d === dossier || path.dirname(d) === d) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const tout = textes.join('\n');
|
|
57
|
+
const processus = PROCESSUS.test(tout);
|
|
58
|
+
const autreQueGit = [...tout.matchAll(APPEL)].some(m => !GIT.test(m[1].trim()));
|
|
59
|
+
if (processus && autreQueGit && DEPOT_D_ESSAI.test(tout)) {
|
|
60
|
+
return 'grand';
|
|
61
|
+
}
|
|
62
|
+
return processus ? 'moyen' : 'petit';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Each test file of the project at <racine> and its size: `[{ fichier, taille, nuit }]`. */
|
|
66
|
+
export function tailles(racine) {
|
|
67
|
+
return composants(racine).flatMap(c =>
|
|
68
|
+
fichiersDeTest(c.dossier).map(f => ({
|
|
69
|
+
fichier: path.relative(racine, f).split(path.sep).join('/'),
|
|
70
|
+
taille: classer(f, c.dossier),
|
|
71
|
+
nuit: estDeNuit(path.basename(f)),
|
|
72
|
+
}))
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The findings of the project at <racine>: one per large test of the day. */
|
|
77
|
+
export function verifier(racine) {
|
|
78
|
+
return tailles(racine)
|
|
79
|
+
.filter(t => t.taille === 'grand' && !t.nuit)
|
|
80
|
+
.map(({ fichier }) => ({
|
|
81
|
+
fichier,
|
|
82
|
+
regle: GRAND_DE_JOUR,
|
|
83
|
+
message: `${fichier} : un grand test (il monte un dépôt d'essai et y lance le produit ou le cadre) est un test de nuit, jamais joué au fil du travail ; il se renomme en *_nuit_test.py, ou il se réduit à la plus petite taille qui prouve son critère.`,
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
88
|
+
const racine = process.cwd();
|
|
89
|
+
const toutes = tailles(racine);
|
|
90
|
+
const compte = t => toutes.filter(x => x.taille === t).length;
|
|
91
|
+
const { refus, lignes } = trancher(racine, GARDE, verifier(racine));
|
|
92
|
+
for (const r of refus) {
|
|
93
|
+
process.stderr.write(`⛔ ${r.message}\n`);
|
|
94
|
+
}
|
|
95
|
+
for (const l of lignes) {
|
|
96
|
+
process.stderr.write(`${l}\n`);
|
|
97
|
+
}
|
|
98
|
+
process.stderr.write(
|
|
99
|
+
`ℹ️ ${GARDE} : ${toutes.length} fichier(s) de tests, ${compte('petit')} petit(s), ${compte('moyen')} moyen(s), ${compte('grand')} grand(s) ; ${toutes.filter(x => x.nuit).length} de nuit.\n`
|
|
100
|
+
);
|
|
101
|
+
process.exitCode = refus.length ? 1 : 0;
|
|
102
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// The verdict of a run of the module python, the demand `verdict` of the join
|
|
2
|
+
// (scripts/jointure.d.ts): what ./commandes.mjs left in the results directory of a pass
|
|
3
|
+
// (`GRILLHOUSE_RESULTATS`, scripts/resultats.mjs).
|
|
4
|
+
//
|
|
5
|
+
// - `<dossier>/python/<run>.json`, one per run: `{ taches, rapports }`, each task as the join types
|
|
6
|
+
// it (`code` null for a task planned that did not run; `tests` true for a run of pytest), and the
|
|
7
|
+
// folder of the package of each JUnit report by its file's name.
|
|
8
|
+
// - `<dossier>/pytest/<run>-<paquet>.xml`, the JUnit report of each run of pytest, in the family
|
|
9
|
+
// `xunit1`, whose `testcase` names its file (`file`, from the package's folder): each file gives
|
|
10
|
+
// a test file, each `testcase` a test, failed when it holds a `failure` or an `error`, skipped
|
|
11
|
+
// when it holds `skipped`; its message, the failure's.
|
|
12
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
|
|
15
|
+
export const TACHES = 'python';
|
|
16
|
+
export const JUNIT = 'pytest';
|
|
17
|
+
|
|
18
|
+
const fichiers = (dossier, extension) =>
|
|
19
|
+
existsSync(dossier)
|
|
20
|
+
? readdirSync(dossier)
|
|
21
|
+
.filter(f => f.endsWith(extension))
|
|
22
|
+
.sort()
|
|
23
|
+
: [];
|
|
24
|
+
const lireJson = f => {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(readFileSync(f, 'utf8'));
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const ENTITES = { lt: '<', gt: '>', amp: '&', quot: '"', apos: "'" };
|
|
33
|
+
// The text <t> of XML, its entities read.
|
|
34
|
+
const texte = t =>
|
|
35
|
+
t.replace(/&(#x[0-9a-f]+|#\d+|\w+);/gi, (m, e) => {
|
|
36
|
+
if (e[0] === '#') {
|
|
37
|
+
return String.fromCodePoint(e[1] === 'x' ? parseInt(e.slice(2), 16) : Number(e.slice(1)));
|
|
38
|
+
}
|
|
39
|
+
return ENTITES[e] ?? m;
|
|
40
|
+
});
|
|
41
|
+
// The attribute <nom> of the opening tag <balise>, its text, or null.
|
|
42
|
+
const attribut = (balise, nom) => {
|
|
43
|
+
const m = new RegExp(`\\s${nom}="([^"]*)"`).exec(balise);
|
|
44
|
+
return m ? texte(m[1]) : null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// The test files of the JUnit report <xml> of the package at <dossier>.
|
|
48
|
+
function rapportsDe(xml, dossier) {
|
|
49
|
+
const parFichier = new Map();
|
|
50
|
+
for (const c of xml.matchAll(/<testcase\b([^>]*?)(?:\/>|>([\s\S]*?)<\/testcase>)/g)) {
|
|
51
|
+
const corps = c[2] ?? '';
|
|
52
|
+
const echec = /<(failure|error)\b([^>]*?)(?:\/>|>([\s\S]*?)<\/\1>)/.exec(corps);
|
|
53
|
+
const etat = echec ? 'failed' : /<skipped\b/.test(corps) ? 'skipped' : 'passed';
|
|
54
|
+
const message = echec ? (attribut(echec[2], 'message') ?? texte(echec[3] ?? '')) : '';
|
|
55
|
+
const titre = attribut(c[1], 'name') ?? '';
|
|
56
|
+
const fichier = path.resolve(dossier, attribut(c[1], 'file') ?? '');
|
|
57
|
+
if (!parFichier.has(fichier)) {
|
|
58
|
+
parFichier.set(fichier, []);
|
|
59
|
+
}
|
|
60
|
+
parFichier.get(fichier).push({ titre, nom: titre, etat, message });
|
|
61
|
+
}
|
|
62
|
+
return [...parFichier].map(([fichier, tests]) => ({
|
|
63
|
+
fichier,
|
|
64
|
+
etat: tests.some(t => t.etat === 'failed') ? 'failed' : 'passed',
|
|
65
|
+
message: '',
|
|
66
|
+
tests,
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The verdict the results directory <dossier> holds: `{ rapports, taches }`.
|
|
72
|
+
* @param {string} dossier the results directory of a pass
|
|
73
|
+
*/
|
|
74
|
+
export function verdict(dossier) {
|
|
75
|
+
const runs = fichiers(path.join(dossier, TACHES), '.json')
|
|
76
|
+
.map(f => lireJson(path.join(dossier, TACHES, f)))
|
|
77
|
+
.filter(Boolean);
|
|
78
|
+
const dossiers = Object.assign({}, ...runs.map(r => r.rapports ?? {}));
|
|
79
|
+
return {
|
|
80
|
+
rapports: fichiers(path.join(dossier, JUNIT), '.xml')
|
|
81
|
+
.filter(f => dossiers[f])
|
|
82
|
+
.flatMap(f => rapportsDe(readFileSync(path.join(dossier, JUNIT, f), 'utf8'), dossiers[f])),
|
|
83
|
+
taches: runs.flatMap(r => r.taches ?? []),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -11,8 +11,7 @@
|
|
|
11
11
|
// `enRetard`; the same, committed, a file of `a` then changed and a file out of every package
|
|
12
12
|
// added: `change`, measured from its commit; the same where the code of `b` imports `a` and the
|
|
13
13
|
// code of `c` imports `b`: `lus`; the same with a second commit that changes a file of `a`:
|
|
14
|
-
// `lot`. A directory whose package.json names no package: `vide`. A
|
|
15
|
-
// a directory, and in a package of a repository of packages: `aLaRacine`, `dansUnPaquet`. A
|
|
14
|
+
// `lot`. A directory whose package.json names no package: `vide`. A
|
|
16
15
|
// repository of two packages, one with the script of the tests (`test:unit`): `avecTests`.
|
|
17
16
|
// - Two results directories of a run: every task and test green (`vert`); `a` at 75, `b` red, a
|
|
18
17
|
// test of `b` failed (`defaut`).
|
|
@@ -113,13 +112,6 @@ export default {
|
|
|
113
112
|
const aJour = depot(dans);
|
|
114
113
|
const vide = mkdtempSync(path.join(dans, 'vide-'));
|
|
115
114
|
writeFileSync(path.join(vide, 'package.json'), json({ name: 'vide', private: true }));
|
|
116
|
-
const aLaRacine = mkdtempSync(path.join(dans, 'tsconfig-'));
|
|
117
|
-
writeFileSync(path.join(aLaRacine, 'package.json'), json({ name: 'r', private: true }));
|
|
118
|
-
writeFileSync(path.join(aLaRacine, 'tsconfig.json'), json({}));
|
|
119
|
-
const dansUnPaquet = mkdtempSync(path.join(dans, 'tsconfig-'));
|
|
120
|
-
ecrireDans(dansUnPaquet)('package.json', json({ name: 'p', workspaces: ['packages/*'] }));
|
|
121
|
-
ecrireDans(dansUnPaquet)('packages/a/package.json', json({ name: '@p/a' }));
|
|
122
|
-
ecrireDans(dansUnPaquet)('packages/a/tsconfig.json', json({}));
|
|
123
115
|
// A repository of two packages, `a` with the script of the tests, `b` without.
|
|
124
116
|
const avecTests = mkdtempSync(path.join(dans, 'tests-'));
|
|
125
117
|
ecrireDans(avecTests)('package.json', json({ name: 't', workspaces: ['packages/*'] }));
|
|
@@ -273,17 +265,6 @@ export default {
|
|
|
273
265
|
},
|
|
274
266
|
matieres: { valide: vide, invalide: aJour, attendu: ['m (@e/m)'] },
|
|
275
267
|
joueDesTests: { valide: aJour, invalide: avecTests, attendu: ['a (@t/a) : joue des tests'] },
|
|
276
|
-
trouve: {
|
|
277
|
-
valide: [
|
|
278
|
-
{ nom: 'vide', racine: vide },
|
|
279
|
-
{ nom: 'paquets sans tsconfig', racine: aJour },
|
|
280
|
-
],
|
|
281
|
-
invalide: [
|
|
282
|
-
{ nom: 'à la racine', racine: aLaRacine },
|
|
283
|
-
{ nom: 'dans un paquet', racine: dansUnPaquet },
|
|
284
|
-
],
|
|
285
|
-
attendu: ['à la racine : trouvé', 'dans un paquet : trouvé'],
|
|
286
|
-
},
|
|
287
268
|
};
|
|
288
269
|
},
|
|
289
270
|
};
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
// other option replaces the frame's at its first level, as the `extends` of dependency-cruiser does.
|
|
10
10
|
//
|
|
11
11
|
// npx grillhouse frontieres refuses a stale configuration, then runs dependency-cruiser
|
|
12
|
-
// npx grillhouse frontieres --ecrire writes the configuration
|
|
12
|
+
// npx grillhouse frontieres --ecrire writes the configuration, and `.dependency-cruiser.projet.cjs`
|
|
13
|
+
// empty when the project has none, so that knip resolves
|
|
14
|
+
// the require of the configuration (grillhouse-b32)
|
|
13
15
|
//
|
|
14
16
|
// The rules: no cycle; a package reaches another by its name, never by a path into its tree; a
|
|
15
17
|
// module of `src/` reaches another by its entry (`index`); the code of `src/` imports no test; the
|
|
@@ -46,6 +48,13 @@ import { CODE, horsCadre } from '../../paquets.mjs';
|
|
|
46
48
|
import { trancher } from '../../dette.mjs';
|
|
47
49
|
|
|
48
50
|
export const CONFIGURATION = '.dependency-cruiser.cjs';
|
|
51
|
+
// The project's own rules and options, which the configuration requires, and their text when
|
|
52
|
+
// `--ecrire` writes them for a project that has none.
|
|
53
|
+
const REGLES_DU_PROJET = '.dependency-cruiser.projet.cjs';
|
|
54
|
+
const REGLES_VIDES = `// The project's own rules and options of dependency-cruiser, which the generated
|
|
55
|
+
// ${CONFIGURATION} reads (\`npx grillhouse frontieres\`); written empty once, the project's own after.
|
|
56
|
+
module.exports = {};
|
|
57
|
+
`;
|
|
49
58
|
export const RACINES = ['src', 'packages'];
|
|
50
59
|
/** The test files, as a pattern of a path from the repository's root. */
|
|
51
60
|
export const TESTS = '(^|/)(test|tests|__tests__)/|[.](test|spec)[.][a-z]+$';
|
|
@@ -391,6 +400,10 @@ function frontieres(racine, args) {
|
|
|
391
400
|
const cible = path.join(racine, CONFIGURATION);
|
|
392
401
|
if (args.includes('--ecrire')) {
|
|
393
402
|
writeFileSync(cible, attendu);
|
|
403
|
+
const propres = path.join(racine, REGLES_DU_PROJET);
|
|
404
|
+
if (!existsSync(propres)) {
|
|
405
|
+
writeFileSync(propres, REGLES_VIDES);
|
|
406
|
+
}
|
|
394
407
|
return 0;
|
|
395
408
|
}
|
|
396
409
|
const present = existsSync(cible) ? readFileSync(cible, 'utf8') : '';
|
|
@@ -261,10 +261,17 @@ export function publie(racine, composant) {
|
|
|
261
261
|
return out.join('\n');
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
+
// The entries of the index of each interface of the repository at <racine>, `{ rel, lignes }`, in
|
|
265
|
+
// the order of `interfaces`: what the module gives the core's index of a project of several
|
|
266
|
+
// languages (`entreesDeLIndex` of the join).
|
|
267
|
+
export const entreesDeLIndex = racine =>
|
|
268
|
+
interfaces(racine).map(rel => ({
|
|
269
|
+
rel,
|
|
270
|
+
lignes: entrees(rel, readFileSync(path.join(racine, rel), 'utf8')),
|
|
271
|
+
}));
|
|
272
|
+
|
|
264
273
|
export function index(racine) {
|
|
265
|
-
const corps =
|
|
266
|
-
entrees(rel, readFileSync(path.join(racine, rel), 'utf8'))
|
|
267
|
-
);
|
|
274
|
+
const corps = entreesDeLIndex(racine).flatMap(e => e.lignes);
|
|
268
275
|
return [
|
|
269
276
|
'# Index des interfaces',
|
|
270
277
|
'',
|