poad 2.41.0 → 2.45.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/global/ai/index.js +279 -0
- package/global/ai/list.js +5 -0
- package/global/ai/login.js +5 -0
- package/global/ai/logout.js +5 -0
- package/global/ai/models.js +5 -0
- package/global/ai/use.js +5 -0
- package/global/cli.js +8 -0
- package/global/run.js +7 -0
- package/global/start.js +17 -0
- package/global/stop.js +1 -0
- package/package.json +1 -1
- package/poad.js +12 -8
- package/project/cli.js +1 -1
- package/project/logs.js +29 -7
- package/project/setup.js +2 -0
- package/test/ai-catalog.test.js +117 -0
- package/test/ai.test.js +187 -0
- package/test/console-services.test.js +90 -0
- package/test/fixtures-permalink-ai.json +233 -0
- package/test/help.test.js +7 -0
- package/test/logs.test.js +192 -0
- package/utils/ai-catalog.js +148 -0
- package/utils/ai.js +178 -0
- package/utils/console-services.js +70 -0
- package/utils/keycloak.js +46 -0
- package/utils/logline.js +169 -7
- package/utils/mail.js +1 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Catalogue des modèles d'IA (clé « ai » de poadio/permalink) : validation, cache, repli hors ligne, fichier
|
|
2
|
+
// écrit pour l'engine, [ai.models], et poad ai models. Sans réseau : la lecture de permalink est remplacée.
|
|
3
|
+
// test/fixtures-permalink-ai.json : le poad.json proposé pour poadio/permalink.
|
|
4
|
+
const test = require('node:test');
|
|
5
|
+
const assert = require('node:assert');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { spawnSync } = require('child_process');
|
|
9
|
+
const { tmpdir } = require('./helpers');
|
|
10
|
+
const cat = require('../utils/ai-catalog');
|
|
11
|
+
const ai = require('../utils/ai');
|
|
12
|
+
|
|
13
|
+
const POAD = path.join(__dirname, '..', 'poad.js');
|
|
14
|
+
const STUB = path.join(__dirname, 'help-stub.js');
|
|
15
|
+
const FIXTURE = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures-permalink-ai.json'), 'utf8'));
|
|
16
|
+
|
|
17
|
+
test('le poad.json proposé : un ancien CLI n’y lit que engine, le catalogue est valide et chaque défaut est listé', () => {
|
|
18
|
+
// Ce que lisent les CLI ≥ 2.38 (utils/latest.js) : la clé engine, inchangée
|
|
19
|
+
assert.deepStrictEqual(Object.keys(FIXTURE.engine), ['stable']);
|
|
20
|
+
const { catalog, warnings } = cat.parseCatalog(FIXTURE.ai);
|
|
21
|
+
assert.deepStrictEqual(warnings, []);
|
|
22
|
+
assert.deepStrictEqual(Object.keys(catalog.providers), ['anthropic', 'openai', 'mistral', 'gemini']);
|
|
23
|
+
assert.strictEqual(catalog.providers.anthropic.default, 'claude-opus-5-5');
|
|
24
|
+
assert.strictEqual(catalog.providers.openai.default, 'gpt-6.2-sol');
|
|
25
|
+
assert.strictEqual(catalog.providers.mistral.default, 'mistral-large-4');
|
|
26
|
+
assert.strictEqual(catalog.providers.gemini.default, 'gemini-4-neon');
|
|
27
|
+
assert.strictEqual(catalog.checked_on, '2026-11-25');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('validation : schéma inconnu, fournisseur inconnu, modèle faux, défaut absent', () => {
|
|
31
|
+
assert.strictEqual(cat.parseCatalog({ ...FIXTURE.ai, schema: 2 }).catalog, null);
|
|
32
|
+
assert.match(cat.parseCatalog({ ...FIXTURE.ai, schema: 2 }).warnings[0], /update poad/);
|
|
33
|
+
const r = cat.parseCatalog({
|
|
34
|
+
schema: 1,
|
|
35
|
+
providers: {
|
|
36
|
+
llama: { default: 'x', models: [] },
|
|
37
|
+
openai: { default: 'a', models: [{ id: 'a', input: 1, output: 2 }, { id: 'b b', input: 1, output: 1 }, { id: 'c', input: -1, output: 1 }, { id: 'd', input: 1, output: 1, status: 'beta' }] },
|
|
38
|
+
mistral: { default: 'absent', models: [{ id: 'm', input: 1, output: 1 }] },
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
assert.deepStrictEqual(Object.keys(r.catalog.providers), ['openai']);
|
|
42
|
+
assert.deepStrictEqual(r.catalog.providers.openai.models, [{ id: 'a', label: 'a', input: 1, output: 2 }]);
|
|
43
|
+
assert.strictEqual(r.warnings.length, 5);
|
|
44
|
+
assert.strictEqual(cat.parseCatalog(undefined).catalog, null);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('cache de 6 h, permalink lu au besoin, repli sur le cache hors ligne, rien sans cache', async (t) => {
|
|
48
|
+
const dir = tmpdir(t);
|
|
49
|
+
process.env.POAD_AI_CATALOG_CACHE = path.join(dir, 'ai-catalog.json');
|
|
50
|
+
t.after(() => delete process.env.POAD_AI_CATALOG_CACHE);
|
|
51
|
+
let calls = 0;
|
|
52
|
+
const online = async () => (calls++, FIXTURE);
|
|
53
|
+
const offline = async () => null;
|
|
54
|
+
assert.deepStrictEqual((await cat.loadCatalog({ fetcher: offline })).source, 'none');
|
|
55
|
+
const first = await cat.loadCatalog({ fetcher: online });
|
|
56
|
+
assert.strictEqual(first.source, 'permalink');
|
|
57
|
+
assert.strictEqual((await cat.loadCatalog({ fetcher: online })).source, 'cache');
|
|
58
|
+
assert.strictEqual(calls, 1);
|
|
59
|
+
const off = await cat.loadCatalog({ fresh: true, fetcher: offline });
|
|
60
|
+
assert.strictEqual(off.source, 'cache');
|
|
61
|
+
assert.ok(off.catalog.providers.anthropic);
|
|
62
|
+
// permalink sans clé ai (ou d'un schéma inconnu) : le dernier catalogue connu reste
|
|
63
|
+
assert.strictEqual((await cat.loadCatalog({ fresh: true, fetcher: async () => ({ engine: { stable: '0.29.1' } }) })).source, 'cache');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('fichier pour l’engine : poad/data/ai/catalog.json, retiré sans catalogue', (t) => {
|
|
67
|
+
const dir = tmpdir(t);
|
|
68
|
+
fs.mkdirSync(path.join(dir, 'poad'));
|
|
69
|
+
const root = path.join(dir, 'poad', 'config.toml');
|
|
70
|
+
const file = cat.writeForEngine(root, { catalog: cat.parseCatalog(FIXTURE.ai).catalog, fetched_at: '2026-11-25T09:00:00.000Z' });
|
|
71
|
+
assert.strictEqual(file, path.join(dir, 'poad', 'data', 'ai', 'catalog.json'));
|
|
72
|
+
const doc = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
73
|
+
assert.strictEqual(doc.schema, 1);
|
|
74
|
+
assert.strictEqual(doc.fetched_at, '2026-11-25T09:00:00.000Z');
|
|
75
|
+
assert.strictEqual(cat.writeForEngine(root, { catalog: null }), null);
|
|
76
|
+
assert.ok(!fs.existsSync(file));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('[ai.models] → POAD_AI_MODELS ; entrées fausses signalées', () => {
|
|
80
|
+
const { env, warnings } = ai.engineEnv({ ai: { models: { anthropic: 'claude-sonnet-5-5', llama: 'x', openai: 'a b' } } });
|
|
81
|
+
assert.deepStrictEqual(env, ['POAD_AI_MODELS={"anthropic":"claude-sonnet-5-5"}']);
|
|
82
|
+
assert.strictEqual(warnings.length, 2);
|
|
83
|
+
assert.match(ai.engineEnv({ ai: { models: 'x' } }).warnings[0], /must be a table/);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('poad ai models : le catalogue en cache, hors ligne, sans réseau ni Docker', (t) => {
|
|
87
|
+
const dir = tmpdir(t);
|
|
88
|
+
const home = path.join(dir, 'home');
|
|
89
|
+
fs.mkdirSync(path.join(home, '.poad'), { recursive: true });
|
|
90
|
+
fs.writeFileSync(path.join(home, '.poad_last_check.json'), JSON.stringify({ date: new Date(), version: require('../package.json').version }));
|
|
91
|
+
fs.writeFileSync(path.join(home, '.poad', 'ai-catalog.json'), JSON.stringify({ at: Date.now(), catalog: cat.parseCatalog(FIXTURE.ai).catalog }));
|
|
92
|
+
const r = spawnSync(process.execPath, ['--require', STUB, POAD, 'ai', 'models', 'mistral'], {
|
|
93
|
+
cwd: dir,
|
|
94
|
+
encoding: 'utf8',
|
|
95
|
+
input: '',
|
|
96
|
+
timeout: 15000,
|
|
97
|
+
env: { ...process.env, HOME: home, POAD_TEST_CALLS: path.join(dir, 'calls.log'), NODE_OPTIONS: '', POAD_AI_CATALOG_CACHE: '' },
|
|
98
|
+
});
|
|
99
|
+
assert.strictEqual(r.status, 0, r.stderr);
|
|
100
|
+
assert.match(r.stdout, /Model catalog of 2026-11-25, from cache/);
|
|
101
|
+
assert.match(r.stdout, /mistral-large-4\s+0\.7 \/ 2\.1\s+Mistral Large 4 default preview/);
|
|
102
|
+
assert.ok(!/gpt-6/.test(r.stdout), 'seulement le fournisseur demandé');
|
|
103
|
+
assert.ok(!fs.existsSync(path.join(dir, 'calls.log')), 'le cache suffit : aucun appel');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('logs : changement du modèle par défaut (qui, avant, après)', () => {
|
|
107
|
+
const { formatLine } = require('../utils/logline');
|
|
108
|
+
const plain = new Proxy(function () {}, { get: () => plain, apply: (t, self, [s]) => String(s) });
|
|
109
|
+
const line = formatLine({ ts: '2026-11-25T10:00:00.000Z', level: 'info', service: 'ai', msg: 'default model of anthropic: (project setting) → claude-sonnet-5-5', attrs: { event: 'ai_default_model_changed', provider: 'anthropic', actor: 'console' } }, plain);
|
|
110
|
+
assert.match(line, /default model of anthropic: \(project setting\) → claude-sonnet-5-5 by console$/);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('catalogue et [ai.models] : seulement pour l’engine 0.31.0 et plus', () => {
|
|
114
|
+
assert.strictEqual(ai.supportsAiModels({ engine: '0.31.0' }), true);
|
|
115
|
+
assert.strictEqual(ai.supportsAiModels({ engine: '0.30.0' }), false);
|
|
116
|
+
assert.strictEqual(ai.supportsAiModels({ engine: '1.0.0' }), true);
|
|
117
|
+
});
|
package/test/ai.test.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// poad ai : clés de la machine (~/.poad/ai.json, 0600), réglages [ai], filtres et rendu de poad logs ai.
|
|
2
|
+
// Sans réseau ni Docker : la commande tourne avec test/help-stub.js (tout appel à Docker, au réseau ou à un
|
|
3
|
+
// processus est refusé et noté) et un HOME à part. Fausses clés seulement.
|
|
4
|
+
const test = require('node:test');
|
|
5
|
+
const assert = require('node:assert');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { spawnSync } = require('child_process');
|
|
9
|
+
const { tmpdir } = require('./helpers');
|
|
10
|
+
const ai = require('../utils/ai');
|
|
11
|
+
const { attrConditions, formatLine } = require('../utils/logline');
|
|
12
|
+
|
|
13
|
+
const POAD = path.join(__dirname, '..', 'poad.js');
|
|
14
|
+
const STUB = path.join(__dirname, 'help-stub.js');
|
|
15
|
+
const FAKE = 'sk-ant-FAKE-test-key-0000000000wxyz';
|
|
16
|
+
const plain = new Proxy(function () {}, { get: () => plain, apply: (t, self, [s]) => String(s) });
|
|
17
|
+
|
|
18
|
+
function sandbox(t) {
|
|
19
|
+
const dir = tmpdir(t);
|
|
20
|
+
const home = path.join(dir, 'home');
|
|
21
|
+
fs.mkdirSync(home);
|
|
22
|
+
// Pas de vérification de version (npm view) pendant l'essai
|
|
23
|
+
fs.writeFileSync(path.join(home, '.poad_last_check.json'), JSON.stringify({ date: new Date(), version: require('../package.json').version }));
|
|
24
|
+
return { dir, home, calls: path.join(dir, 'calls.log'), file: path.join(home, '.poad', 'ai.json') };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const poad = (box, args, input = '') =>
|
|
28
|
+
spawnSync(process.execPath, ['--require', STUB, POAD, ...args], {
|
|
29
|
+
cwd: box.dir,
|
|
30
|
+
encoding: 'utf8',
|
|
31
|
+
input,
|
|
32
|
+
timeout: 15000,
|
|
33
|
+
env: { ...process.env, HOME: box.home, POAD_TEST_CALLS: box.calls, NODE_OPTIONS: '', POAD_AI_KEYS_FILE: '' },
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('ai login : clé lue sur l’entrée standard, fichier 0600 dans un dossier 0700, jamais affichée', (t) => {
|
|
37
|
+
const box = sandbox(t);
|
|
38
|
+
const r = poad(box, ['ai', 'login', 'anthropic'], `${FAKE}\n`);
|
|
39
|
+
assert.strictEqual(r.status, 0, r.stderr);
|
|
40
|
+
assert.match(r.stdout, /key saved for this machine \(…wxyz\)/);
|
|
41
|
+
assert.ok(!r.stdout.includes(FAKE) && !r.stderr.includes(FAKE), 'la clé ne s’affiche jamais');
|
|
42
|
+
assert.strictEqual(fs.statSync(box.file).mode & 0o777, 0o600);
|
|
43
|
+
assert.strictEqual(fs.statSync(path.dirname(box.file)).mode & 0o777, 0o700);
|
|
44
|
+
assert.strictEqual(JSON.parse(fs.readFileSync(box.file, 'utf8')).providers.anthropic.key, FAKE);
|
|
45
|
+
assert.ok(!fs.existsSync(box.calls), 'ni Docker, ni réseau, ni processus');
|
|
46
|
+
|
|
47
|
+
const list = poad(box, ['ai', 'list']);
|
|
48
|
+
assert.match(list.stdout, /anthropic\s+…wxyz/);
|
|
49
|
+
assert.match(list.stdout, /openai\s+no key/);
|
|
50
|
+
assert.ok(!list.stdout.includes(FAKE));
|
|
51
|
+
|
|
52
|
+
const out = poad(box, ['ai', 'logout', 'anthropic']);
|
|
53
|
+
assert.match(out.stdout, /removed/);
|
|
54
|
+
assert.deepStrictEqual(JSON.parse(fs.readFileSync(box.file, 'utf8')).providers, {});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('ai login : refus d’une clé vide ou mal formée, d’un fournisseur inconnu ; une clé en argument est signalée', (t) => {
|
|
58
|
+
const box = sandbox(t);
|
|
59
|
+
assert.match(poad(box, ['ai', 'login', 'openai'], 'a b c d e f g h\n').stdout, /Key refused \(a key has no spaces\)/);
|
|
60
|
+
assert.match(poad(box, ['ai', 'login', 'openai'], '').stdout, /Key refused \(empty key\)/);
|
|
61
|
+
assert.ok(!fs.existsSync(box.file));
|
|
62
|
+
assert.match(poad(box, ['ai', 'login', 'llama']).stdout, /Usage: poad ai login/);
|
|
63
|
+
const arg = poad(box, ['ai', 'login', FAKE]);
|
|
64
|
+
assert.match(arg.stdout, /Never pass a key as an argument/);
|
|
65
|
+
assert.ok(!arg.stdout.includes(FAKE));
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('ai use : hors d’un projet, le dit sans rien appeler', (t) => {
|
|
69
|
+
const box = sandbox(t);
|
|
70
|
+
poad(box, ['ai', 'login', 'mistral'], 'mistral-fake-key-123456\n');
|
|
71
|
+
const r = poad(box, ['ai', 'use', 'mistral']);
|
|
72
|
+
assert.match(r.stdout, /not in a poad project/);
|
|
73
|
+
assert.ok(!fs.existsSync(box.calls));
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('readKeys : un fichier lisible par d’autres est ramené à 0600 ; un fichier abîmé est signalé sans contenu', (t) => {
|
|
77
|
+
const box = sandbox(t);
|
|
78
|
+
fs.mkdirSync(path.dirname(box.file), { recursive: true });
|
|
79
|
+
fs.writeFileSync(box.file, JSON.stringify({ providers: { gemini: { key: 'AIzaFAKEFAKEFAKE1234' } } }), { mode: 0o644 });
|
|
80
|
+
fs.chmodSync(box.file, 0o644);
|
|
81
|
+
const k = ai.readKeys(box.file);
|
|
82
|
+
assert.strictEqual(k.fixed, true);
|
|
83
|
+
assert.strictEqual(fs.statSync(box.file).mode & 0o777, 0o600);
|
|
84
|
+
assert.strictEqual(k.providers.gemini.key, 'AIzaFAKEFAKEFAKE1234');
|
|
85
|
+
fs.writeFileSync(box.file, `{ "providers": ${FAKE}`);
|
|
86
|
+
const broken = ai.readKeys(box.file);
|
|
87
|
+
assert.match(broken.broken, /not valid JSON/);
|
|
88
|
+
assert.ok(!broken.broken.includes(FAKE));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('masque et forme des clés', () => {
|
|
92
|
+
assert.strictEqual(ai.mask(FAKE), '…wxyz');
|
|
93
|
+
assert.strictEqual(ai.mask('court'), '…');
|
|
94
|
+
assert.strictEqual(ai.mask(''), '');
|
|
95
|
+
assert.strictEqual(ai.keyProblem(FAKE), null);
|
|
96
|
+
assert.match(ai.keyProblem('abc'), /8 to 512/);
|
|
97
|
+
assert.match(ai.keyProblem('clé-é-é-é-é'), /ASCII/);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('[ai] de config.toml → variables de l’engine ; une valeur fausse est dite et pas transmise', () => {
|
|
101
|
+
const { env, warnings } = ai.engineEnv({
|
|
102
|
+
ai: { default_provider: 'mistral', default_model: 'mistral-small-latest', max_tokens: 2048, monthly_budget_usd: 12.5, log_content: true, prices: { 'openai/gpt-x': { input: 1, output: 2 } } },
|
|
103
|
+
});
|
|
104
|
+
assert.deepStrictEqual(env, [
|
|
105
|
+
'POAD_AI_DEFAULT_PROVIDER=mistral',
|
|
106
|
+
'POAD_AI_DEFAULT_MODEL=mistral-small-latest',
|
|
107
|
+
'POAD_AI_MAX_TOKENS=2048',
|
|
108
|
+
'POAD_AI_MONTHLY_BUDGET_USD=12.5',
|
|
109
|
+
'POAD_AI_LOG_CONTENT=true',
|
|
110
|
+
'POAD_AI_PRICES={"openai/gpt-x":{"input":1,"output":2}}',
|
|
111
|
+
]);
|
|
112
|
+
assert.deepStrictEqual(warnings, []);
|
|
113
|
+
const bad = ai.engineEnv({ ai: { default_provider: 'llama', max_tokens: -1, monthly_budget_usd: 'beaucoup', default_model: 'a b' } });
|
|
114
|
+
assert.deepStrictEqual(bad.env, []);
|
|
115
|
+
assert.strictEqual(bad.warnings.length, 4);
|
|
116
|
+
assert.deepStrictEqual(ai.engineEnv({}), { env: [], warnings: [] });
|
|
117
|
+
assert.strictEqual(ai.supportsAi({ engine: '0.30.0' }), true);
|
|
118
|
+
assert.strictEqual(ai.supportsAi({ engine: '0.30.0-ai.1' }), true);
|
|
119
|
+
assert.strictEqual(ai.supportsAi({ engine: '0.29.2' }), false);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('logs : provider= et model= portent sur les attributs du même nom', () => {
|
|
123
|
+
const r = attrConditions({ provider: 'openai', model: 'gpt-5', outcome: 'budget_exceeded' });
|
|
124
|
+
assert.deepStrictEqual(r.conditions, [
|
|
125
|
+
["attrs->>'outcome' = ?", 'budget_exceeded'],
|
|
126
|
+
["attrs->>'provider' = ?", 'openai'],
|
|
127
|
+
["attrs->>'model' = ?", 'gpt-5'],
|
|
128
|
+
]);
|
|
129
|
+
assert.match(attrConditions({ provider: true }).error, /provider=<name>: a value is expected, such as provider=anthropic/);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('logs : rendu d’une ligne ai (résultat, jetons, coût estimé ; une seule durée)', () => {
|
|
133
|
+
const line = formatLine(
|
|
134
|
+
{
|
|
135
|
+
ts: '2026-11-25T10:00:00.000Z',
|
|
136
|
+
level: 'info',
|
|
137
|
+
service: 'ai',
|
|
138
|
+
request_id: 'abcdef1234567890',
|
|
139
|
+
msg: 'chat anthropic/claude-opus-5-5 ok (812 ms)',
|
|
140
|
+
attrs: { provider: 'anthropic', model: 'claude-opus-5-5', outcome: 'ok', input_tokens: 1000, output_tokens: 500, cost_usd: 0.014, duration_ms: 812, function: 'resume' },
|
|
141
|
+
},
|
|
142
|
+
plain,
|
|
143
|
+
);
|
|
144
|
+
assert.match(line, /ai\s+info\s+\[resume\] chat anthropic\/claude-opus-5-5 ok \(812 ms\) 1000→500 tok ~\$0\.0140 ·abcdef12$/);
|
|
145
|
+
const refused = formatLine(
|
|
146
|
+
{ ts: '2026-11-25T10:00:00.000Z', level: 'warn', service: 'ai', msg: 'chat openai/gpt-5 provider_error (40 ms)', attrs: { outcome: 'provider_error', provider_status: 401, error_code: 'provider_error', error: 'openai refused the call (HTTP 401)', duration_ms: 40 } },
|
|
147
|
+
plain,
|
|
148
|
+
);
|
|
149
|
+
assert.match(refused, /provider_error \(40 ms\) HTTP 401 provider_error: openai refused the call \(HTTP 401\)$/);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('logs : un appel ai sans prix connu dit « cost unknown », jamais $0', () => {
|
|
153
|
+
const line = formatLine(
|
|
154
|
+
{ ts: '2026-11-25T10:00:00.000Z', level: 'info', service: 'ai', msg: 'chat mistral/mistral-large-latest ok (9 ms)', attrs: { outcome: 'ok', input_tokens: 10, output_tokens: 5, cost_usd: null, price: 'unknown' } },
|
|
155
|
+
plain,
|
|
156
|
+
);
|
|
157
|
+
assert.match(line, /10→5 tok cost unknown \(no price: \[ai\.prices\]\)$/);
|
|
158
|
+
assert.ok(!line.includes('$0'));
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('ai login : un ~/.poad déjà là en 0755 est ramené à 0700, ses autres fichiers gardent leurs droits', (t) => {
|
|
162
|
+
const box = sandbox(t);
|
|
163
|
+
const dir = path.dirname(box.file);
|
|
164
|
+
fs.mkdirSync(dir, { mode: 0o755 });
|
|
165
|
+
fs.chmodSync(dir, 0o755);
|
|
166
|
+
const other = path.join(dir, 'engine-latest.json');
|
|
167
|
+
fs.writeFileSync(other, '{}', { mode: 0o644 });
|
|
168
|
+
fs.chmodSync(other, 0o644);
|
|
169
|
+
const r = poad(box, ['ai', 'login', 'openai'], 'sk-proj-abcdefghijklmnopqrstuvwxyz\n');
|
|
170
|
+
assert.strictEqual(r.status, 0, r.stderr);
|
|
171
|
+
assert.strictEqual(fs.statSync(dir).mode & 0o777, 0o700);
|
|
172
|
+
assert.strictEqual(fs.statSync(box.file).mode & 0o777, 0o600);
|
|
173
|
+
assert.strictEqual(fs.statSync(other).mode & 0o777, 0o644);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('coût : un montant positif sous 0,0001 $ s’écrit « < $0.0001 », jamais $0.0000', () => {
|
|
177
|
+
assert.strictEqual(ai.usdText(0.000018), '< $0.0001');
|
|
178
|
+
assert.strictEqual(ai.usdText(0.0002), '~$0.0002');
|
|
179
|
+
assert.strictEqual(ai.usdText(0), '~$0.0000');
|
|
180
|
+
assert.strictEqual(ai.usdText(null), null);
|
|
181
|
+
const line = formatLine(
|
|
182
|
+
{ ts: '2026-11-25T10:00:00.000Z', level: 'info', service: 'ai', msg: 'chat mistral/mistral-large-4 ok (1 ms)', attrs: { outcome: 'ok', input_tokens: 11, output_tokens: 5, cost_usd: 0.000018 } },
|
|
183
|
+
plain,
|
|
184
|
+
);
|
|
185
|
+
assert.match(line, /11→5 tok < \$0\.0001$/);
|
|
186
|
+
assert.ok(!line.includes('0.0000'));
|
|
187
|
+
});
|
|
@@ -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,10 @@ 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 (start, create)', (t) => {
|
|
127
|
+
const box = sandbox(t);
|
|
128
|
+
const r = poad(box, ['--help']);
|
|
129
|
+
assert.match(r.stdout, /start \.+\s+Start the project, apply migrations/);
|
|
130
|
+
assert.match(r.stdout, /create \.+\s+Create a poad project/);
|
|
131
|
+
});
|