poad 2.75.0 → 2.75.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poad",
3
- "version": "2.75.0",
3
+ "version": "2.75.1",
4
4
  "engine": "0.28.0",
5
5
  "runner": "0.5.0",
6
6
  "main": "index.js",
package/project/deploy.js CHANGED
@@ -148,7 +148,7 @@ module.exports = (args, raw) =>
148
148
  if (b.deps && b.deps.packages.length) out.log(chalk.grey(` npm packages of the functions: ${b.deps.packages.join(', ')} (${b.deps.files} file(s) of poad/functions/node_modules)`));
149
149
  for (const m of (b.deps && b.deps.missing) || []) out.log(chalk.yellowBright(` ⚠ ${m.from} imports "${m.spec}", not installed in poad/functions/node_modules: run "npm install ${m.spec}" in poad/functions, or this function will not build on poad.io.`));
150
150
  if (b.deps && b.deps.outside.length) out.log(chalk.yellowBright(` ⚠ ${b.deps.outside.join(', ')}: installed above poad/functions, not sent. Install in poad/functions (npm install there).`));
151
- for (const f of large) out.log(chalk.grey(` ${f.rel} (${kb(f.size)}): too large for git: reference store, sent and loaded only if it changed (sha256)`));
151
+ for (const f of large) out.log(chalk.grey(` ${f.rel} (${kb(f.size)}): too large for git: reference store, sent only if it changed (sha256), loaded if not yet loaded in ${env.branch}`));
152
152
  for (const f of ignored.tracked) out.log(chalk.yellowBright(` ⚠ poad/${f.rel} is tracked by git although it is too large: git rm --cached poad/${f.rel}`));
153
153
 
154
154
  if (env.production && !dryRun) {
@@ -88,9 +88,21 @@ async function startAndWait(id, branch, targets, opts, out) {
88
88
  try {
89
89
  started = await api.call('POST', `v1/projects/${api.enc(id)}/seeds/load`, { body: { branch, targets }, what: 'reference load' });
90
90
  } catch (e) {
91
- throw e;
91
+ // Place insuffisante, même table par table : rien n'est lancé ; chaque table dite (refusée, en attente)
92
+ if (e.code !== 'seed_no_space') throw e;
93
+ const d = e.details || {};
94
+ const tables = Array.isArray(d.tables) && d.tables.length ? d.tables : targets.map((t) => ({ target: t, status: 'refused' }));
95
+ out.log(`${chalk.redBright('✖')} Reference load refused on ${branch}: ${d.message || e.message}`);
96
+ for (const t of tables) {
97
+ if (t.status === 'refused') out.log(` ${chalk.redBright('✖')} ${t.target}: refused, not enough room${t.need ? ` (about ${S.fmt(t.need)} + 10 %)` : ''}`);
98
+ else out.log(` ${chalk.yellow('○')} ${t.target}: pending, not loaded`);
99
+ }
100
+ out.log(chalk.grey(' Nothing was loaded. The next "poad deploy" loads them once there is room (no need to send them again).'));
101
+ return { status: 'failed', refused: true, error: d.message || e.message, steps: tables.map((t) => ({ target: t.target, status: t.status === 'refused' ? 'failed' : 'skipped', reason: 'space' })), space: { required: d.required, free: d.free, limit: d.limit, margin: d.margin } };
92
102
  }
93
- out.log(chalk.grey(` Loading into ${branch} (${started.targets.length} table(s))…`));
103
+ const plan = started.plan || {};
104
+ if (plan.mode === 'stepwise') out.log(chalk.grey(` Loading into ${branch} table by table (${plan.order.length} tables, not enough room for all at once): ${plan.order.join(', ')}…`));
105
+ else out.log(chalk.grey(` Loading into ${branch} (${started.targets.length} table(s))…`));
94
106
  const done = new Set();
95
107
  const l = await S.waitLoad(id, started.load_id, {
96
108
  onStep: (st) => {
@@ -105,6 +117,8 @@ async function startAndWait(id, branch, targets, opts, out) {
105
117
  }
106
118
  },
107
119
  });
120
+ // Tables pas chargées (une précédente refusée ou en échec) : le prochain poad deploy les reprend
121
+ for (const s of l.steps || []) if (s.status === 'skipped' || s.status === 'pending') out.log(`${chalk.yellow('○')} ${s.target}: pending, not loaded into ${branch}; the next "poad deploy" loads it`);
108
122
  if (l.status === 'failed') out.log(chalk.grey(' Nothing was half-loaded: each table is all or nothing.'));
109
123
  return l;
110
124
  }
@@ -0,0 +1,113 @@
1
+ // poad deploy et les grosses références : une table envoyée mais jamais chargée dans cet environnement
2
+ // est chargée au deploy suivant (sans renvoi) ; refus de place de poad.io dit table par table.
3
+ const { test } = require('node:test');
4
+ const assert = require('node:assert');
5
+ const fs = require('fs');
6
+ const os = require('os');
7
+ const path = require('path');
8
+ const api = require('../utils/cloud/api');
9
+ const store = require('../utils/reference-store');
10
+
11
+ const SHA = 'a'.repeat(64);
12
+ const chalk = new Proxy({}, { get: () => { const f = (s) => s; return new Proxy(f, { get: () => f }); } });
13
+
14
+ function project() {
15
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'poad-reload-'));
16
+ fs.mkdirSync(path.join(dir, 'reference'));
17
+ fs.writeFileSync(path.join(dir, 'reference', 'public.commune.jsonl'), '{"id":1}\n'.repeat(4));
18
+ const files = store.largeFiles(dir, 5);
19
+ // Déjà envoyée par un deploy précédent : la mémoire locale garde son empreinte
20
+ fs.mkdirSync(path.join(dir, 'data'));
21
+ const f = files[0];
22
+ fs.writeFileSync(path.join(dir, 'data', 'reference-store.json'), JSON.stringify({ [f.file]: { size: f.size, mtimeMs: f.mtimeMs, sha256: SHA, target: f.target } }));
23
+ return { dir, files };
24
+ }
25
+
26
+ function fakeApi(t, routes) {
27
+ const calls = [];
28
+ const orig = api.call;
29
+ api.call = async (method, route, o = {}) => {
30
+ calls.push([method, route, o.body]);
31
+ for (const [re, fn] of routes) if (re.test(`${method} ${route}`)) return fn(o);
32
+ throw new Error(`route inattendue ${method} ${route}`);
33
+ };
34
+ t.after(() => (api.call = orig));
35
+ return calls;
36
+ }
37
+ const output = () => {
38
+ const lines = [];
39
+ return { lines, out: { chalk, json: false, log: (l) => lines.push(String(l)) } };
40
+ };
41
+
42
+ test('envoyée, jamais chargée dans cet environnement → chargée au deploy suivant, sans renvoi', async (t) => {
43
+ const { dir, files } = project();
44
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
45
+ let polls = 0;
46
+ const calls = fakeApi(t, [
47
+ [/^GET .*\/seeds$/, () => ({ store: true, items: [{ target: 'public.commune', sha256: SHA }], applied: { dev: { 'public.commune': { sha256: SHA } } } })],
48
+ [/^POST .*\/seeds\/load$/, () => ({ load_id: 'l1', targets: ['public.commune'], plan: { mode: 'together', order: ['public.commune'] } })],
49
+ [/^GET .*\/seeds\/loads\/l1$/, () => (++polls < 2 ? { status: 'running', steps: [{ target: 'public.commune', status: 'running' }] } : { status: 'done', steps: [{ target: 'public.commune', status: 'done', written: 4, deleted: 0, duration_ms: 1200 }] })],
50
+ ]);
51
+ const { lines, out } = output();
52
+ // Chargée en dev, pas en main : main la charge
53
+ const r = await store.sendAndLoad('abcdefghijkl', 'main', dir, files, {}, out);
54
+ assert.strictEqual(r.failed, false);
55
+ assert.deepStrictEqual(r.tables.map((x) => [x.target, x.action, x.state]), [['public.commune', 'load', 'loaded']]);
56
+ assert.ok(!calls.some(([, route]) => /seeds\/upload/.test(route)), 'rien renvoyé');
57
+ assert.deepStrictEqual(calls.find(([, route]) => /seeds\/load$/.test(route))[2], { branch: 'main', targets: ['public.commune'] });
58
+ assert.ok(lines.some((l) => /public\.commune loaded into main: 4 rows/.test(l)), lines.join('\n'));
59
+ });
60
+
61
+ test('déjà chargée dans cet environnement : ni envoi ni chargement', async (t) => {
62
+ const { dir, files } = project();
63
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
64
+ const calls = fakeApi(t, [[/^GET .*\/seeds$/, () => ({ store: true, items: [{ target: 'public.commune', sha256: SHA }], applied: { main: { 'public.commune': { sha256: SHA } } } })]]);
65
+ const { out } = output();
66
+ const r = await store.sendAndLoad('abcdefghijkl', 'main', dir, files, {}, out);
67
+ assert.deepStrictEqual(r.tables.map((x) => [x.action, x.state]), [['unchanged', 'loaded']]);
68
+ assert.strictEqual(calls.length, 1);
69
+ });
70
+
71
+ test('poad.io refuse faute de place (aucun ordre ne tient) : chaque table dite, deploy en échec, rien lancé', async (t) => {
72
+ const { dir, files } = project();
73
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
74
+ const message = 'place insuffisante, même table par table : public.commune demande à elle seule environ 700.0 Mio, + 10 % de marge = 770.0 Mio, plus 256.0 Mio pour le journal (il manquerait 76.3 Mio). Pour passer : poad ref inspect public.commune, --exclude, ou une offre plus grande.';
75
+ fakeApi(t, [
76
+ [/^GET .*\/seeds$/, () => ({ store: true, items: [{ target: 'public.commune', sha256: SHA }], applied: {} })],
77
+ [/^POST .*\/seeds\/load$/, () => {
78
+ throw new api.CloudError(`reference load: ${message} (seed_no_space)`, { status: 413, code: 'seed_no_space', details: { code: 'seed_no_space', message, margin: 1.1, required: 1100, free: 1000, limit: 1024, tables: [{ target: 'public.commune', need: 734003200, status: 'refused' }, { target: 'public.region', need: 1, status: 'pending' }] } });
79
+ }],
80
+ ]);
81
+ const { lines, out } = output();
82
+ const r = await store.sendAndLoad('abcdefghijkl', 'main', dir, files, {}, out);
83
+ assert.strictEqual(r.failed, true);
84
+ assert.deepStrictEqual(r.tables.map((x) => [x.target, x.state]), [['public.commune', 'refused']]);
85
+ const text = lines.join('\n');
86
+ assert.match(text, /Reference load refused on main: place insuffisante/);
87
+ assert.match(text, /public\.commune: refused, not enough room \(about 700\.0 M/);
88
+ assert.match(text, /public\.region: pending, not loaded/);
89
+ assert.match(text, /next "poad deploy" loads them/);
90
+ });
91
+
92
+ test('chargement table par table : annoncé, puis une table refusée en cours et la suivante en attente', async (t) => {
93
+ const { dir, files } = project();
94
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
95
+ fakeApi(t, [
96
+ [/^GET .*\/seeds$/, () => ({ store: true, items: [{ target: 'public.commune', sha256: SHA }], applied: {} })],
97
+ [/^POST .*\/seeds\/load$/, () => ({ load_id: 'l2', targets: ['public.commune'], plan: { mode: 'stepwise', order: ['public.a', 'public.commune', 'public.c'] } })],
98
+ [/^GET .*\/seeds\/loads\/l2$/, () => ({ status: 'failed', steps: [
99
+ { target: 'public.a', status: 'done', written: 1, deleted: 0, duration_ms: 10, warnings: ['place restante faible sur l’engine main : 200.0 Mio libres sur 1.00 Gio (20 %)'] },
100
+ { target: 'public.commune', status: 'failed', reason: 'space', error: 'refusée : place insuffisante pour cette table…' },
101
+ { target: 'public.c', status: 'skipped', error: 'en attente' },
102
+ ] })],
103
+ ]);
104
+ const { lines, out } = output();
105
+ const r = await store.sendAndLoad('abcdefghijkl', 'main', dir, files, {}, out);
106
+ assert.strictEqual(r.failed, true);
107
+ assert.deepStrictEqual(r.tables.map((x) => x.state), ['refused']);
108
+ const text = lines.join('\n');
109
+ assert.match(text, /table by table \(3 tables, not enough room for all at once\): public\.a, public\.commune, public\.c/);
110
+ assert.match(text, /⚠ place restante faible/);
111
+ assert.match(text, /public\.commune: refusée : place insuffisante/);
112
+ assert.match(text, /public\.c: pending, not loaded into main; the next "poad deploy" loads it/);
113
+ });
@@ -14,10 +14,12 @@ const DEFAULT_API = 'https://poad.io/_poad/cloud';
14
14
  const EXIT = { ok: 0, error: 1, usage: 2, auth: 3, confirm: 4, failed: 5 };
15
15
 
16
16
  class CloudError extends Error {
17
- constructor(message, { status = 0, code = 'error', exit } = {}) {
17
+ constructor(message, { status = 0, code = 'error', exit, details } = {}) {
18
18
  super(message);
19
19
  this.status = status;
20
20
  this.code = code;
21
+ // Champs du refus rendus par poad.io (tailles, tables…), jamais de secret
22
+ if (details) this.details = details;
21
23
  this.exit = exit || (status === 401 || code === 'not_logged_in' ? EXIT.auth : EXIT.error);
22
24
  }
23
25
  }
@@ -104,7 +106,7 @@ function errorOf(res, what) {
104
106
  const message = typeof e.message === 'string' && e.message ? e.message : `HTTP ${res.status}`;
105
107
  if (res.status === 401) return new CloudError(`poad.io refused the session (${message}): run "poad login".`, { status: 401, code });
106
108
  if (res.status === 404) return new CloudError(`${what ? `${what}: ` : ''}not found (${message}).`, { status: 404, code });
107
- return new CloudError(`${what ? `${what}: ` : ''}${message}${code && !message.includes(code) ? ` (${code})` : ''}`, { status: res.status, code });
109
+ return new CloudError(`${what ? `${what}: ` : ''}${message}${code && !message.includes(code) ? ` (${code})` : ''}`, { status: res.status, code, details: e });
108
110
  }
109
111
 
110
112
  /** Appel authentifié : la réponse JSON, ou CloudError */
@@ -152,6 +152,13 @@ async function sendAndLoad(id, branch, poadDir, files, opts, out) {
152
152
  }
153
153
  let load = null;
154
154
  if (toLoad.length) load = await startAndWait(id, branch, toLoad, opts, out);
155
+ // État de chaque table dans cet environnement : loaded, pending (pas encore chargée), refused (place), failed
156
+ for (const t of tables) {
157
+ const st = load && (load.steps || []).find((x) => x.target === t.target);
158
+ if (t.action === 'unchanged') t.state = 'loaded';
159
+ else if (st) t.state = st.status === 'done' ? 'loaded' : st.status === 'failed' ? (st.reason === 'space' ? 'refused' : 'failed') : 'pending';
160
+ else t.state = 'pending';
161
+ }
155
162
  return { tables, load, failed: Boolean(load && load.status === 'failed') };
156
163
  }
157
164