poad 2.42.0 → 2.46.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.
@@ -0,0 +1,90 @@
1
+ // Groupe « Services » de la console locale : poad/data/console/services.json
2
+ // liste Mailpit et Keycloak seulement s'ils sont activés dans config.toml, avec
3
+ // les ports de cette machine, sans aucun secret.
4
+ const test = require('node:test');
5
+ const assert = require('node:assert');
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const { tmpdir } = require('./helpers');
9
+ const services = require('../utils/console-services');
10
+ const shared = require('../utils/keycloak-shared');
11
+
12
+ const project = (t) => {
13
+ const dir = tmpdir(t);
14
+ fs.mkdirSync(path.join(dir, 'poad'));
15
+ const root = path.join(dir, 'poad', 'config.toml');
16
+ fs.writeFileSync(root, '');
17
+ return root;
18
+ };
19
+ const base = (extra = {}) => ({ project_id: 'demo', project_uuid: 'poad-test-not-a-container', db: { port: 54322 }, mail: { port: 54324 }, ...extra });
20
+ const DB = { id: 'db', port: 54322 };
21
+ const MAIL = { id: 'mail', url: 'http://localhost:54324/', smtp: 'mail:1025' };
22
+ const ids = (list) => list.map((s) => s.id);
23
+
24
+ test('projet neuf : PostgreSQL et Mailpit (pas de [smtp]), ni Keycloak ni Valkey', (t) => {
25
+ assert.deepStrictEqual(services.list(project(t), base()), [DB, MAIL]);
26
+ });
27
+
28
+ test('Valkey configuré : port de la machine et adresse vue depuis l’engine', (t) => {
29
+ assert.deepStrictEqual(services.list(project(t), base({ valkey: { port: 6390 } })).at(-1), { id: 'valkey', port: 6390, engine_url: 'redis://valkey:6379' });
30
+ assert.deepStrictEqual(ids(services.list(project(t), base({ valkey: { autostart: true } }))), ['db', 'mail']);
31
+ });
32
+
33
+ test('un vrai serveur SMTP ([smtp] host) : pas de serveur de mail à ouvrir', (t) => {
34
+ assert.deepStrictEqual(services.list(project(t), base({ smtp: { host: 'smtp.example.com', pass: 'x' } })), [DB]);
35
+ });
36
+
37
+ test('Keycloak configuré (port) : console d’administration sur le realm du projet', (t) => {
38
+ const out = services.list(project(t), base({ keycloak: { port: 8081 } }));
39
+ assert.deepStrictEqual(out, [DB, MAIL, { id: 'keycloak', url: 'http://localhost:8081/admin/master/console/#/demo', realm: 'demo', shared: false }]);
40
+ });
41
+
42
+ test('[keycloak] sans port ni shared (jamais lancé) : absent', (t) => {
43
+ assert.deepStrictEqual(ids(services.list(project(t), base({ keycloak: { autostart: false } }))), ['db', 'mail']);
44
+ });
45
+
46
+ test('Keycloak partagé : port de la machine, realm propre au projet ; absent tant que le partagé n’a pas de port', (t) => {
47
+ const real = shared.readState;
48
+ t.after(() => (shared.readState = real));
49
+ shared.readState = () => ({ port: 8099, admin_password: 'NeSortJamais' });
50
+ const root = project(t);
51
+ const out = services.list(root, base({ keycloak: { shared: true } }));
52
+ const realm = shared.realmFor({ project_uuid: 'poad-test-not-a-container' }, 'demo');
53
+ assert.deepStrictEqual(out[2], { id: 'keycloak', url: `http://localhost:8099/admin/master/console/#/${realm}`, realm, shared: true });
54
+ assert.ok(!JSON.stringify(out).includes('NeSortJamais'));
55
+ shared.readState = () => null;
56
+ assert.deepStrictEqual(ids(services.list(root, base({ keycloak: { shared: true } }))), ['db', 'mail']);
57
+ });
58
+
59
+ test('write : data/console/services.json, sans secret, réécrit à chaque appel', (t) => {
60
+ const root = project(t);
61
+ const config = base({ keycloak: { port: 8081 }, auth: { secret: 'jwt-secret-x', service: 'svc-key-x', anon: 'anon-x' } });
62
+ assert.ok(services.write(root, config));
63
+ const file = path.join(path.dirname(root), 'data', 'console', 'services.json');
64
+ assert.strictEqual(services.file(root), file);
65
+ const text = fs.readFileSync(file, 'utf8');
66
+ for (const secret of ['jwt-secret-x', 'svc-key-x', 'anon-x']) assert.ok(!text.includes(secret));
67
+ assert.deepStrictEqual(ids(JSON.parse(text)), ['db', 'mail', 'keycloak']);
68
+ assert.ok(!/password|secret/i.test(text));
69
+ services.write(root, base({ smtp: { host: 'smtp.example.com' } }));
70
+ assert.deepStrictEqual(JSON.parse(fs.readFileSync(file, 'utf8')), [DB]);
71
+ assert.deepStrictEqual(fs.readdirSync(path.dirname(file)), ['services.json']);
72
+ });
73
+
74
+ test('Keycloak partagé : mot de passe recopié dans data/keycloak/shared-admin.json (0600), retiré ensuite', (t) => {
75
+ const kc = require('../utils/keycloak');
76
+ const root = project(t);
77
+ kc.writeSharedAdmin(root, 'AbcDef123456');
78
+ const file = kc.sharedAdminFile(root);
79
+ assert.strictEqual(file, path.join(path.dirname(root), 'data', 'keycloak', 'shared-admin.json'));
80
+ assert.deepStrictEqual(JSON.parse(fs.readFileSync(file, 'utf8')), { admin_password: 'AbcDef123456' });
81
+ assert.strictEqual(fs.statSync(file).mode & 0o777, 0o600);
82
+ kc.removeSharedAdmin(root);
83
+ assert.ok(!fs.existsSync(file));
84
+ });
85
+
86
+ test('sessions longues du realm master : 30 jours et « Se souvenir de moi »', () => {
87
+ const { MASTER_SESSIONS } = require('../utils/keycloak');
88
+ assert.strictEqual(MASTER_SESSIONS.rememberMe, true);
89
+ for (const k of ['ssoSessionIdleTimeout', 'ssoSessionMaxLifespan', 'ssoSessionIdleTimeoutRememberMe', 'ssoSessionMaxLifespanRememberMe']) assert.strictEqual(MASTER_SESSIONS[k], 30 * 24 * 3600);
90
+ });
@@ -0,0 +1,233 @@
1
+ {
2
+ "engine": {
3
+ "stable": "0.30.0"
4
+ },
5
+ "ai": {
6
+ "schema": 1,
7
+ "checked_on": "2026-11-25",
8
+ "sources": {
9
+ "anthropic": "https://platform.claude.com/docs/en/about-claude/pricing",
10
+ "openai": "https://developers.openai.com/api/docs/pricing",
11
+ "mistral": "https://docs.mistral.ai/inference/pricing?currency=usd",
12
+ "gemini": "https://aistudio.google.com/docs/pricing"
13
+ },
14
+ "providers": {
15
+ "anthropic": {
16
+ "default": "claude-opus-5-5",
17
+ "models": [
18
+ {
19
+ "id": "claude-fable-5-2",
20
+ "label": "Claude Fable 5.2",
21
+ "input": 8,
22
+ "output": 40
23
+ },
24
+ {
25
+ "id": "claude-opus-5-5",
26
+ "label": "Claude Opus 5.5",
27
+ "input": 4,
28
+ "output": 20
29
+ },
30
+ {
31
+ "id": "claude-opus-5",
32
+ "label": "Claude Opus 5",
33
+ "input": 5,
34
+ "output": 25
35
+ },
36
+ {
37
+ "id": "claude-opus-4-8",
38
+ "label": "Claude Opus 4.8",
39
+ "input": 5,
40
+ "output": 25
41
+ },
42
+ {
43
+ "id": "claude-sonnet-5-5",
44
+ "label": "Claude Sonnet 5.5",
45
+ "input": 2,
46
+ "output": 10
47
+ },
48
+ {
49
+ "id": "claude-sonnet-5",
50
+ "label": "Claude Sonnet 5",
51
+ "input": 2,
52
+ "output": 10
53
+ },
54
+ {
55
+ "id": "claude-sonnet-4-6",
56
+ "label": "Claude Sonnet 4.6",
57
+ "input": 3,
58
+ "output": 15
59
+ },
60
+ {
61
+ "id": "claude-haiku-5-5",
62
+ "label": "Claude Haiku 5.5",
63
+ "input": 0.1,
64
+ "output": 0.5
65
+ },
66
+ {
67
+ "id": "claude-haiku-4-5",
68
+ "label": "Claude Haiku 4.5",
69
+ "input": 1,
70
+ "output": 5
71
+ }
72
+ ]
73
+ },
74
+ "openai": {
75
+ "default": "gpt-6.2-sol",
76
+ "models": [
77
+ {
78
+ "id": "gpt-6.2-astra",
79
+ "label": "GPT-6.2 Astra",
80
+ "input": 8,
81
+ "output": 40
82
+ },
83
+ {
84
+ "id": "gpt-6.2-sol",
85
+ "label": "GPT-6.2 Sol",
86
+ "input": 2,
87
+ "output": 10
88
+ },
89
+ {
90
+ "id": "gpt-6.1-sol",
91
+ "label": "GPT-6.1 Sol",
92
+ "input": 2,
93
+ "output": 10
94
+ },
95
+ {
96
+ "id": "gpt-6.1-terra",
97
+ "label": "GPT-6.1 Terra",
98
+ "input": 1,
99
+ "output": 5
100
+ },
101
+ {
102
+ "id": "gpt-6-luna",
103
+ "label": "GPT-6 Luna",
104
+ "input": 0.1,
105
+ "output": 0.5
106
+ },
107
+ {
108
+ "id": "gpt-5.5",
109
+ "label": "GPT-5.5",
110
+ "input": 5,
111
+ "output": 30
112
+ },
113
+ {
114
+ "id": "gpt-5.4",
115
+ "label": "GPT-5.4",
116
+ "input": 2.5,
117
+ "output": 15
118
+ },
119
+ {
120
+ "id": "gpt-5.4-mini",
121
+ "label": "GPT-5.4 mini",
122
+ "input": 0.75,
123
+ "output": 4.5
124
+ },
125
+ {
126
+ "id": "gpt-5",
127
+ "label": "GPT-5",
128
+ "input": 1.25,
129
+ "output": 10
130
+ },
131
+ {
132
+ "id": "gpt-5-mini",
133
+ "label": "GPT-5 mini",
134
+ "input": 0.25,
135
+ "output": 2
136
+ },
137
+ {
138
+ "id": "gpt-4.1",
139
+ "label": "GPT-4.1",
140
+ "input": 2,
141
+ "output": 8
142
+ },
143
+ {
144
+ "id": "gpt-4o-mini",
145
+ "label": "GPT-4o mini",
146
+ "input": 0.15,
147
+ "output": 0.6
148
+ }
149
+ ]
150
+ },
151
+ "mistral": {
152
+ "default": "mistral-large-4",
153
+ "models": [
154
+ {
155
+ "id": "mistral-large-4",
156
+ "label": "Mistral Large 4",
157
+ "input": 0.7,
158
+ "output": 2.1,
159
+ "status": "preview"
160
+ },
161
+ {
162
+ "id": "mistral-small-2603",
163
+ "label": "Mistral Small 4",
164
+ "input": 0.15,
165
+ "output": 0.6
166
+ },
167
+ {
168
+ "id": "mistral-small-latest",
169
+ "label": "Mistral Small (latest)",
170
+ "input": 0.15,
171
+ "output": 0.6
172
+ }
173
+ ]
174
+ },
175
+ "gemini": {
176
+ "default": "gemini-4-neon",
177
+ "models": [
178
+ {
179
+ "id": "gemini-4-neon",
180
+ "label": "Gemini 4 Neon",
181
+ "input": 3,
182
+ "output": 15
183
+ },
184
+ {
185
+ "id": "gemini-4-hydrogen",
186
+ "label": "Gemini 4 Hydrogen",
187
+ "input": 1.5,
188
+ "output": 7.5
189
+ },
190
+ {
191
+ "id": "gemini-3.5-flash-lite",
192
+ "label": "Gemini 3.5 Flash-Lite",
193
+ "input": 0.3,
194
+ "output": 2.5
195
+ },
196
+ {
197
+ "id": "gemini-3.1-pro-preview",
198
+ "label": "Gemini 3.1 Pro (preview)",
199
+ "input": 2,
200
+ "output": 12,
201
+ "status": "preview"
202
+ },
203
+ {
204
+ "id": "gemini-3.1-flash-lite",
205
+ "label": "Gemini 3.1 Flash-Lite",
206
+ "input": 0.25,
207
+ "output": 1.5
208
+ },
209
+ {
210
+ "id": "gemini-2.5-pro",
211
+ "label": "Gemini 2.5 Pro",
212
+ "input": 1.25,
213
+ "output": 10,
214
+ "status": "deprecated"
215
+ },
216
+ {
217
+ "id": "gemini-2.5-flash",
218
+ "label": "Gemini 2.5 Flash",
219
+ "input": 0.3,
220
+ "output": 2.5,
221
+ "status": "deprecated"
222
+ },
223
+ {
224
+ "id": "gemini-2.5-flash-lite",
225
+ "label": "Gemini 2.5 Flash-Lite",
226
+ "input": 0.1,
227
+ "output": 0.4
228
+ }
229
+ ]
230
+ }
231
+ }
232
+ }
233
+ }
package/test/help.test.js CHANGED
@@ -122,3 +122,17 @@ test('unknown command with --help: error and command list, exit 1', (t) => {
122
122
  assert.match(r.stdout + r.stderr, /Unknown command : nope/);
123
123
  assert.ok(!fs.existsSync(box.calls));
124
124
  });
125
+
126
+ test('--help : une description qui contient [section] plus loin n’est pas coupée, seul un [Libellé] en tête en est un', (t) => {
127
+ const { entries } = require('../utils/banner');
128
+ const [start, beta] = entries({ start: 'Start the project. [gateway] max_body of poad/config.toml', x: { description: '[BETA] Something new', a: 'sub' } });
129
+ assert.strictEqual(start.label, null);
130
+ assert.strictEqual(start.description, 'Start the project. [gateway] max_body of poad/config.toml');
131
+ assert.strictEqual(beta.label, 'beta');
132
+ assert.strictEqual(beta.description, 'Something new');
133
+ assert.deepStrictEqual(beta.subs, ['a']);
134
+ const box = sandbox(t);
135
+ const r = poad(box, ['--help']);
136
+ assert.match(r.stdout, /start \.+\s+Start the project: engine, migrations/);
137
+ assert.match(r.stdout, /create \.+\s+Create a poad project/);
138
+ });
@@ -0,0 +1,176 @@
1
+ // Mise en page de l'aide : coupure aux espaces, retrait suspendu, largeur du
2
+ // terminal ; vue courte de « poad » et liste complète de « poad --help ».
3
+ const test = require('node:test');
4
+ const assert = require('node:assert');
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const { spawnSync } = require('child_process');
8
+ const { tmpdir } = require('./helpers');
9
+ const { wrap, row, paragraph, terminalColumns, visible } = require('../utils/layout');
10
+ const banner = require('../utils/banner');
11
+
12
+ const chalk = require('chalk-v2');
13
+ const colored = new chalk.Instance({ level: 1 });
14
+ const POAD = path.join(__dirname, '..', 'poad.js');
15
+ const STUB = path.join(__dirname, 'help-stub.js');
16
+ const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
17
+
18
+ test('wrap: word boundaries, never wider than the width', () => {
19
+ const text = 'Start the project, apply migrations, start the services chosen with poad setup, then show its state';
20
+ for (const width of [12, 20, 33, 50, 80]) {
21
+ const lines = wrap(text, width);
22
+ assert.ok(lines.every((l) => l.length <= width), `${width}: ${JSON.stringify(lines)}`);
23
+ assert.strictEqual(lines.join(' '), text, `${width}: no word lost or cut`);
24
+ }
25
+ assert.deepStrictEqual(wrap('a b c', 100), ['a b c']);
26
+ assert.deepStrictEqual(wrap('', 20), []);
27
+ });
28
+
29
+ test('wrap: a word longer than the width is cut into pieces of that width', () => {
30
+ assert.deepStrictEqual(wrap('go abcdefghijklmnop end', 6), ['go', 'abcdef', 'ghijkl', 'mnop', 'end']);
31
+ });
32
+
33
+ test('row: hanging indent under the description column, dotted leader', () => {
34
+ const lines = row({ name: 'start', nameWidth: 12, columns: 50, segments: 'Start the project, apply migrations, start the services chosen with poad setup' });
35
+ const column = 3 + 12 + 2;
36
+ assert.match(lines[0], /^ {3}start \.{6} {2}Start/);
37
+ assert.strictEqual(lines[0].indexOf('Start'), column);
38
+ for (const l of lines.slice(1)) {
39
+ assert.strictEqual(l.length - l.trimStart().length, column, JSON.stringify(l));
40
+ }
41
+ assert.ok(lines.every((l) => l.length <= 50));
42
+ });
43
+
44
+ test('row: colour codes do not count in the width, a label stays in front', () => {
45
+ const segs = [
46
+ { text: '(AI)', style: colored.yellow },
47
+ { text: 'AI providers: keys of this machine and their copy into a project', style: colored.white },
48
+ { text: '(subcommands:', style: colored.grey },
49
+ { text: 'login,', style: colored.cyan },
50
+ { text: 'models)', style: colored.cyan },
51
+ ];
52
+ const lines = row({ name: 'ai', nameStyle: colored.cyanBright, dotStyle: colored.grey, nameWidth: 10, columns: 60, segments: segs });
53
+ assert.ok(lines[0].includes('\x1b['), 'coloured');
54
+ assert.ok(lines.every((l) => visible(l) <= 60), lines.map(strip).join('\n'));
55
+ assert.match(strip(lines[0]), /^ {3}ai \.{7} {2}\(AI\) AI providers/);
56
+ for (const l of lines.slice(1)) assert.match(strip(l), /^ {15}\S/);
57
+ assert.match(strip(lines.join(" ")).replace(/\s+/g, " "), /\(subcommands: login, models\)/);
58
+ });
59
+
60
+ test('row: too narrow for two columns, the description goes under the command', () => {
61
+ const lines = row({ name: 'client <subcommand>', nameWidth: 23, columns: 44, segments: 'Front-end of the project: client init, kept as an alias' });
62
+ assert.strictEqual(lines[0], ' client <subcommand>');
63
+ assert.ok(lines.slice(1).every((l) => /^ {7}\S/.test(l) && l.length <= 44), lines.join('\n'));
64
+ });
65
+
66
+ test('paragraph and terminalColumns', () => {
67
+ assert.ok(paragraph('one two three four five six', { columns: 12, indent: 3 }).every((l) => l.startsWith(' ') && l.length <= 12));
68
+ assert.strictEqual(terminalColumns({ isTTY: true, columns: 132 }, {}), 132);
69
+ assert.strictEqual(terminalColumns({ isTTY: false }, {}), 100);
70
+ assert.strictEqual(terminalColumns({ isTTY: false }, { COLUMNS: '80' }), 80);
71
+ assert.strictEqual(terminalColumns({ isTTY: true, columns: 12 }, {}), 40);
72
+ });
73
+
74
+ test('short view: only the commands of SHORT, each on one line at 100 columns', () => {
75
+ const lines = banner.render({ full: false, columns: 100, version: '9.9.9', chalk: colored });
76
+ const plain = lines.map(strip);
77
+ assert.ok(plain.length <= 36, `${plain.length} lines`);
78
+ assert.ok(plain.every((l) => l.length <= 100));
79
+ const listed = plain.filter((l) => /^ {3}\S+ \.+ {2}/.test(l)).map((l) => l.trim().split(' ')[0]);
80
+ assert.deepStrictEqual(listed, [...Object.keys(banner.SHORT.global), ...Object.keys(banner.SHORT.project)]);
81
+ for (const hidden of ['flows', 'flow', 'functions', 'function', 'gen', 'kc', 'migration', 'migrate', 'client', 'install']) {
82
+ assert.ok(!listed.includes(hidden), hidden);
83
+ }
84
+ assert.ok(plain.some((l) => /poad --help +every command/.test(l)));
85
+ assert.ok(plain.some((l) => /poad <command> --help +details of a command/.test(l)));
86
+ });
87
+
88
+ test('SHORT names only existing commands', () => {
89
+ for (const scope of ['global', 'project']) {
90
+ const table = require(`../${scope}/cli`);
91
+ for (const name of Object.keys(banner.SHORT[scope])) assert.ok(table[name], `${scope} ${name}`);
92
+ }
93
+ });
94
+
95
+ test('full list: every line within the width, at 100, 80 and 50 columns', () => {
96
+ for (const columns of [100, 80, 50]) {
97
+ const plain = banner.render({ full: true, columns, version: '9.9.9', chalk: colored }).map(strip);
98
+ assert.ok(plain.every((l) => l.length <= columns || /^[ _|.'\\/()`,-]+$/.test(l)), `${columns}: ${plain.find((l) => l.length > columns)}`);
99
+ }
100
+ });
101
+
102
+ /** Projet factice ; version déjà vérifiée pour que « poad » sans argument n'appelle pas npm */
103
+ function sandbox(t) {
104
+ const dir = tmpdir(t);
105
+ fs.mkdirSync(path.join(dir, 'poad'));
106
+ fs.writeFileSync(path.join(dir, 'poad', 'config.toml'), 'project_id = "t"\nproject_uuid = "poad-layout-test"\nengine = "0.28.0"\n');
107
+ fs.mkdirSync(path.join(dir, 'home'));
108
+ fs.writeFileSync(path.join(dir, 'home', '.poad_last_check.json'), JSON.stringify({ date: new Date(), version: require('../package.json').version }));
109
+ return dir;
110
+ }
111
+ const poad = (dir, args, columns = 100) =>
112
+ spawnSync(process.execPath, ['--require', STUB, POAD, ...args], {
113
+ cwd: dir,
114
+ encoding: 'utf8',
115
+ input: '',
116
+ timeout: 15000,
117
+ env: { ...process.env, HOME: path.join(dir, 'home'), POAD_TEST_CALLS: path.join(dir, 'calls.log'), COLUMNS: String(columns), NODE_OPTIONS: '', FORCE_COLOR: '0' },
118
+ });
119
+
120
+ test('poad --help, -h and help: every command and subcommand listed, no colour codes when piped', (t) => {
121
+ const dir = sandbox(t);
122
+ const full = poad(dir, ['--help']);
123
+ assert.strictEqual(full.status, 0, full.stderr);
124
+ assert.ok(!full.stdout.includes('\x1b['), 'no colour codes');
125
+ assert.strictEqual(poad(dir, ['-h']).stdout, full.stdout);
126
+ assert.strictEqual(poad(dir, ['help']).stdout, full.stdout);
127
+ const text = full.stdout.replace(/\s+/g, ' ');
128
+ for (const scope of ['global', 'project']) {
129
+ for (const [name, v] of Object.entries(require(`../${scope}/cli`))) {
130
+ assert.match(full.stdout, new RegExp(`^ {3}${name}( <subcommand>)? \\.`, 'm'), name);
131
+ if (v && typeof v === 'object') {
132
+ const subs = Object.keys(v).filter((k) => k !== 'description');
133
+ assert.ok(text.includes(`(subcommands: ${subs.join(', ')})`), `${name}: ${subs}`);
134
+ }
135
+ }
136
+ }
137
+ assert.ok(full.stdout.split('\n').every((l) => l.length <= 100 || /^[ _|.'\\/()`,-]+$/.test(l)));
138
+ assert.ok(!fs.existsSync(path.join(dir, 'calls.log')));
139
+ });
140
+
141
+ test('plain poad: the short view, under 36 lines at 100 columns', (t) => {
142
+ const dir = sandbox(t);
143
+ const r = poad(dir, []);
144
+ assert.strictEqual(r.status, 0, r.stderr);
145
+ const lines = r.stdout.replace(/\n+$/, '').split('\n');
146
+ assert.ok(lines.length <= 36, `${lines.length} lines`);
147
+ assert.match(r.stdout, /version /);
148
+ assert.doesNotMatch(r.stdout, /^ {3}flows /m);
149
+ assert.ok(!fs.existsSync(path.join(dir, 'calls.log')));
150
+ });
151
+
152
+ test('poad <command> --help: the details moved out of the list are there, wrapped', (t) => {
153
+ const dir = sandbox(t);
154
+ const expect = {
155
+ start: ['--bare', '--quiet', 'max_body', 'replaced by a free one', 'poad info --secrets'],
156
+ stop: ['runner', 'valkey (or redis)'],
157
+ logs: ['level=warn', 'since=15m', 'run=<id>', 'token=<name>', 'event=<event>', 'provider=<provider>', '--json'],
158
+ upgrade: ['to=<version>', 'channel=beta', 'POAD_CHANNEL=beta', '--rollback', '--list'],
159
+ setup: ['kc=shared', '--none', '--list', 'migrate=off'],
160
+ clean: ['--dry-run', '--yes'],
161
+ flows: ['input=<file.json>', '--no-wait', 'cancel <run_id>'],
162
+ functions: ['new <name>', 'types'],
163
+ db: ['poad db reset', 'diff --discard'],
164
+ };
165
+ for (const [cmd, words] of Object.entries(expect)) {
166
+ for (const columns of [100, 60]) {
167
+ const r = poad(dir, [cmd, '--help'], columns);
168
+ assert.strictEqual(r.status, 0, r.stderr);
169
+ const flat = r.stdout.replace(/\s+/g, ' ');
170
+ for (const w of words) assert.ok(flat.includes(w), `${cmd} --help (${columns}): ${w}`);
171
+ // seules les lignes « Usage » peuvent dépasser (une commande ne se coupe pas)
172
+ const long = r.stdout.split('\n').filter((l) => l.length > columns && !/^ (Usage : | {8})poad /.test(l));
173
+ assert.deepStrictEqual(long, [], `${cmd} at ${columns}`);
174
+ }
175
+ }
176
+ });
@@ -0,0 +1,148 @@
1
+ // Catalogue des modèles d'IA (engine 0.31.0+) : par fournisseur, le modèle par défaut et les modèles proposés,
2
+ // avec leur prix (USD par million de jetons) et leur statut. Il vit dans poadio/permalink (poad.json, public),
3
+ // sous la clé « ai » : on y ajoute un modèle sans republier le CLI ni l'engine. Un CLI plus ancien ne lit que
4
+ // la clé « engine » et ignore celle-ci.
5
+ //
6
+ // { "engine": { … },
7
+ // "ai": { "schema": 1, "checked_on": "2026-11-25",
8
+ // "providers": { "anthropic": { "default": "claude-opus-5-5",
9
+ // "models": [{ "id": "claude-opus-5-5", "label": "Claude Opus 5.5",
10
+ // "input": 4, "output": 20, "status": "preview" }] } } } }
11
+ //
12
+ // L'engine ne va jamais sur internet : poad start écrit le catalogue dans poad/data/ai/catalog.json (monté en
13
+ // /data), que le service ai valide à son tour ; sans fichier, la table de l'engine sert. Cache de 6 h dans
14
+ // ~/.poad/ai-catalog.json ; hors ligne, le dernier catalogue connu.
15
+ const fs = require('fs');
16
+ const os = require('os');
17
+ const path = require('path');
18
+
19
+ const PERMALINK_URL = 'https://raw.githubusercontent.com/poadio/permalink/main/poad.json';
20
+ const SCHEMA = 1;
21
+ const CACHE_TTL = 6 * 3600 * 1000;
22
+ const PROVIDERS = ['anthropic', 'openai', 'mistral', 'gemini'];
23
+ const MODEL_ID_RE = /^[A-Za-z0-9._:-]{1,100}$/;
24
+ const STATUSES = ['preview', 'deprecated'];
25
+
26
+ const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
27
+ const priceOk = (n) => typeof n === 'number' && Number.isFinite(n) && n >= 0 && n < 100000;
28
+
29
+ /**
30
+ * Catalogue validé tiré de la clé « ai » de poad.json, mêmes règles que l'engine (services/ai/src/catalog.ts) :
31
+ * { catalog, warnings } ; catalog null si le schéma est inconnu ou si aucun fournisseur n'est utilisable.
32
+ */
33
+ const parseCatalog = (raw) => {
34
+ const warnings = [];
35
+ if (!isObj(raw)) return { catalog: null, warnings: ['no "ai" key in poad.json'] };
36
+ if (raw.schema !== SCHEMA) return { catalog: null, warnings: [`AI catalog schema ${JSON.stringify(raw.schema)} is not supported by this CLI (expected ${SCHEMA}): update poad`] };
37
+ if (!isObj(raw.providers)) return { catalog: null, warnings: ['AI catalog: providers must be an object'] };
38
+ const providers = {};
39
+ for (const [p, v] of Object.entries(raw.providers)) {
40
+ if (!PROVIDERS.includes(p)) {
41
+ warnings.push(`unknown provider "${p.slice(0, 40)}" ignored`);
42
+ continue;
43
+ }
44
+ if (!isObj(v) || !Array.isArray(v.models) || typeof v.default !== 'string') {
45
+ warnings.push(`${p}: { default, models } expected, ignored`);
46
+ continue;
47
+ }
48
+ const models = [];
49
+ for (const m of v.models.slice(0, 200)) {
50
+ if (!isObj(m) || typeof m.id !== 'string' || !MODEL_ID_RE.test(m.id) || !priceOk(m.input) || !priceOk(m.output)) {
51
+ warnings.push(`${p}: a model without a valid id, input or output is ignored`);
52
+ continue;
53
+ }
54
+ if (m.status !== undefined && !STATUSES.includes(m.status)) {
55
+ warnings.push(`${p}/${m.id}: status must be preview or deprecated, ignored`);
56
+ continue;
57
+ }
58
+ if (models.some((x) => x.id === m.id)) continue;
59
+ const label = typeof m.label === 'string' && m.label.trim() ? m.label.trim().slice(0, 80) : m.id;
60
+ models.push({ id: m.id, label, input: m.input, output: m.output, ...(m.status ? { status: m.status } : {}) });
61
+ }
62
+ if (!models.some((m) => m.id === v.default)) {
63
+ warnings.push(`${p}: default "${String(v.default).slice(0, 80)}" is not in its models, ignored`);
64
+ continue;
65
+ }
66
+ providers[p] = { default: v.default, models };
67
+ }
68
+ if (!Object.keys(providers).length) return { catalog: null, warnings: [...warnings, 'AI catalog: no usable provider'] };
69
+ const checked = typeof raw.checked_on === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(raw.checked_on) ? raw.checked_on : null;
70
+ return { catalog: { schema: SCHEMA, checked_on: checked, providers }, warnings };
71
+ };
72
+
73
+ const cacheFile = () => process.env.POAD_AI_CATALOG_CACHE || path.join(os.homedir(), '.poad', 'ai-catalog.json');
74
+
75
+ const readCache = () => {
76
+ try {
77
+ const c = JSON.parse(fs.readFileSync(cacheFile(), 'utf8'));
78
+ return c && typeof c.at === 'number' && c.catalog ? c : null;
79
+ } catch {
80
+ return null;
81
+ }
82
+ };
83
+
84
+ const writeCache = (catalog) => {
85
+ try {
86
+ fs.mkdirSync(path.dirname(cacheFile()), { recursive: true, mode: 0o700 });
87
+ fs.writeFileSync(cacheFile(), JSON.stringify({ at: Date.now(), catalog }));
88
+ } catch {
89
+ // cache facultatif
90
+ }
91
+ };
92
+
93
+ /** Corps de poad.json, ou null (hors ligne, illisible) */
94
+ const fetchPermalink = async (timeout) => {
95
+ try {
96
+ const res = await fetch(PERMALINK_URL, { signal: AbortSignal.timeout(timeout), headers: { 'cache-control': 'no-cache' } });
97
+ return res.ok ? await res.json() : null;
98
+ } catch {
99
+ return null;
100
+ }
101
+ };
102
+
103
+ /**
104
+ * { catalog, source, fetched_at, warnings } ; source : permalink (lu à l'instant), cache, ou none (rien de
105
+ * connu : l'engine prendra sa table). fresh : ignorer le cache récent. fetcher : pour les essais.
106
+ */
107
+ const loadCatalog = async ({ fresh = false, timeout = 2500, fetcher = fetchPermalink } = {}) => {
108
+ const cached = readCache();
109
+ if (!fresh && cached && Date.now() - cached.at < CACHE_TTL) return { catalog: cached.catalog, source: 'cache', fetched_at: new Date(cached.at).toISOString(), warnings: [] };
110
+ const body = await fetcher(timeout);
111
+ if (body) {
112
+ const { catalog, warnings } = parseCatalog(isObj(body) ? body.ai : null);
113
+ if (catalog) {
114
+ writeCache(catalog);
115
+ return { catalog, source: 'permalink', fetched_at: new Date().toISOString(), warnings };
116
+ }
117
+ if (cached) return { catalog: cached.catalog, source: 'cache', fetched_at: new Date(cached.at).toISOString(), warnings };
118
+ return { catalog: null, source: 'none', fetched_at: null, warnings };
119
+ }
120
+ if (cached) return { catalog: cached.catalog, source: 'cache', fetched_at: new Date(cached.at).toISOString(), warnings: [] };
121
+ return { catalog: null, source: 'none', fetched_at: null, warnings: [] };
122
+ };
123
+
124
+ /** poad/data/ai/catalog.json du projet (monté en /data/ai/catalog.json dans l'engine) */
125
+ const engineFile = (root) => path.join(path.dirname(root), 'data', 'ai', 'catalog.json');
126
+
127
+ /**
128
+ * Écrit le catalogue pour l'engine (remplacement atomique), ou retire le fichier s'il n'y a pas de catalogue :
129
+ * l'engine prend alors sa table. Rend le chemin écrit, ou null.
130
+ */
131
+ const writeForEngine = (root, loaded) => {
132
+ const file = engineFile(root);
133
+ if (!loaded || !loaded.catalog) {
134
+ try {
135
+ fs.unlinkSync(file);
136
+ } catch {
137
+ // rien à retirer
138
+ }
139
+ return null;
140
+ }
141
+ fs.mkdirSync(path.dirname(file), { recursive: true });
142
+ const tmp = `${file}.${process.pid}.tmp`;
143
+ fs.writeFileSync(tmp, `${JSON.stringify({ ...loaded.catalog, fetched_at: loaded.fetched_at }, null, 2)}\n`);
144
+ fs.renameSync(tmp, file);
145
+ return file;
146
+ };
147
+
148
+ module.exports = { PERMALINK_URL, SCHEMA, parseCatalog, loadCatalog, writeForEngine, engineFile, cacheFile };