create-pmos 0.269.0 → 0.271.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/package.json +1 -1
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/briefing-premium-calendar-2-test.js +2 -2
- package/workspace/briefing-premium-calendar-3-test.js +360 -0
- package/workspace/briefing-premium-calendar-test.js +2 -2
- package/workspace/guide/briefing-premium.md +13 -2
- package/workspace/lib/insights-premium.js +26 -5
- package/workspace/lib/premium-charts.js +129 -0
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-insights-premium.js +4 -2
- package/workspace/lib/routes-premium-charts.js +46 -0
- package/workspace/lib/routes-premium-dashboards.js +3 -2
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-studio-chart-test.js +193 -0
- package/workspace/public/pm/premium-insights.js +71 -12
- package/workspace/public/pm/premium-meeting.js +375 -16
- package/workspace/public/pm/premium-shell.js +36 -0
- package/workspace/public/pm/premium-studio.js +224 -45
- package/workspace/public/pm/premium.css +66 -0
- package/workspace/public/pm/premium.js +1 -0
- package/workspace/test-files.json +2 -0
- package/workspace/test-lists/briefing-premium.json +2 -0
- package/workspace/test-lists/premium-studio-chart.json +13 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* premium-charts.js — the charts the PM makes in the Insight Studio on the premium Insights page (initiative premium-studio-chart, PRD C1).
|
|
3
|
+
* THE ONE WRITER and THE ONE FOLD of <state>/premium-charts.jsonl.
|
|
4
|
+
*
|
|
5
|
+
* FORMS · TITLE_MAX · QUESTION_MAX · NOTE_MAX
|
|
6
|
+
* ledgerFile(root) · readLines(file)
|
|
7
|
+
* check(input) → { ok: true, value } | { ok: false, status, error } PURE: the shape only
|
|
8
|
+
* fold(lines) → { [board]: [{ id, board, measure, title, question, form, range, target, better, note, at }] } PURE
|
|
9
|
+
* list(root, board) → the charts of one board, in the order they were made
|
|
10
|
+
* save(root, input, actor, { now, known }) → { ok: true, chart, charts } | { ok: false, status, error }
|
|
11
|
+
*
|
|
12
|
+
* THE LEDGER. Lines { v: 1, ev: save | remove, id, board, measure, title, question, form, range, target, better, note, actor, at }. `measure` is a KR metric
|
|
13
|
+
* id of the workspace. `range` is how many of the latest readings to draw (2 or more), or null for all of them. `target` is a number, or null for none.
|
|
14
|
+
* The fold keeps the last save of each id and drops an id once it is removed. The file is never rewritten. A torn line, or one without an id and a board,
|
|
15
|
+
* is skipped. Chart ids start with `pc-`, so a dashboard can hold them beside KR metric ids (lib/premium-dashboards.js). */
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
const LEDGER = 'premium-charts.jsonl';
|
|
20
|
+
const FORMS = ['line', 'bars', 'number', 'meter'];
|
|
21
|
+
const TITLE_MAX = 60;
|
|
22
|
+
const QUESTION_MAX = 100;
|
|
23
|
+
const NOTE_MAX = 200;
|
|
24
|
+
const RANGE_MAX = 500;
|
|
25
|
+
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,119}$/;
|
|
26
|
+
|
|
27
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
28
|
+
const refuse = (status, error) => ({ ok: false, status, error });
|
|
29
|
+
const tidy = (v) => (typeof v === 'string' ? v.trim().replace(/\s+/g, ' ') : '');
|
|
30
|
+
const norm = (t) => tidy(t).toLowerCase();
|
|
31
|
+
|
|
32
|
+
function ledgerFile(root) {
|
|
33
|
+
const abs = path.resolve(String(root));
|
|
34
|
+
return path.join(abs, require('./report-draft.js').stateRel(abs), LEDGER);
|
|
35
|
+
}
|
|
36
|
+
function readLines(file) {
|
|
37
|
+
let text = '';
|
|
38
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
39
|
+
const out = [];
|
|
40
|
+
for (const raw of text.split('\n')) {
|
|
41
|
+
if (!raw.trim()) continue;
|
|
42
|
+
try { const l = JSON.parse(raw); if (isObj(l) && (l.ev === 'save' || l.ev === 'remove') && typeof l.id === 'string' && typeof l.board === 'string') out.push(l); } catch { /* a torn line is skipped */ }
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Check the fields of a save or a remove. Whether the board and the measure exist is the route's check (it passes `known`). */
|
|
48
|
+
function check(input) {
|
|
49
|
+
const i = isObj(input) ? input : {};
|
|
50
|
+
const board = typeof i.board === 'string' ? i.board : '';
|
|
51
|
+
if (!ID_RE.test(board)) return refuse(400, 'Name the board the chart belongs to.');
|
|
52
|
+
const id = i.id == null || i.id === '' ? null : i.id;
|
|
53
|
+
if (id !== null && (typeof id !== 'string' || !/^pc-/.test(id) || !ID_RE.test(id))) return refuse(400, 'That chart id is not valid.');
|
|
54
|
+
if (i.remove === true) {
|
|
55
|
+
if (id === null) return refuse(400, 'Say which chart to remove.');
|
|
56
|
+
return { ok: true, value: { remove: true, id, board } };
|
|
57
|
+
}
|
|
58
|
+
const measure = typeof i.measure === 'string' ? i.measure : '';
|
|
59
|
+
if (!ID_RE.test(measure)) return refuse(400, 'Pick the measure the chart draws.');
|
|
60
|
+
const title = tidy(i.title);
|
|
61
|
+
if (!title) return refuse(400, 'Give the chart a name.');
|
|
62
|
+
if (title.length > TITLE_MAX) return refuse(400, `The name can be at most ${TITLE_MAX} characters.`);
|
|
63
|
+
const question = tidy(i.question);
|
|
64
|
+
if (question.length > QUESTION_MAX) return refuse(400, `The question can be at most ${QUESTION_MAX} characters.`);
|
|
65
|
+
const form = i.form == null || i.form === '' ? 'line' : i.form;
|
|
66
|
+
if (!FORMS.includes(form)) return refuse(400, 'The form must be a line, bars, a number or a meter.');
|
|
67
|
+
const range = i.range == null || i.range === '' ? null : i.range;
|
|
68
|
+
if (range !== null && (!Number.isInteger(range) || range < 2 || range > RANGE_MAX)) return refuse(400, 'The range must be two or more readings, or all of them.');
|
|
69
|
+
const target = i.target == null || i.target === '' ? null : i.target;
|
|
70
|
+
if (target !== null && (typeof target !== 'number' || !Number.isFinite(target))) return refuse(400, 'The target must be a number, or none.');
|
|
71
|
+
if (form === 'meter' && target === null) return refuse(400, 'A meter needs a target.');
|
|
72
|
+
const better = i.better == null || i.better === '' ? 'higher' : i.better;
|
|
73
|
+
if (better !== 'higher' && better !== 'lower') return refuse(400, 'Better when must be higher or lower.');
|
|
74
|
+
const note = tidy(i.note);
|
|
75
|
+
if (note.length > NOTE_MAX) return refuse(400, `The note can be at most ${NOTE_MAX} characters.`);
|
|
76
|
+
return { ok: true, value: { remove: false, id, board, measure, title, question, form, range, target, better, note } };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Every board's charts after the ledger's lines, in order. PURE. */
|
|
80
|
+
function fold(lines) {
|
|
81
|
+
const byId = new Map();
|
|
82
|
+
let made = 0;
|
|
83
|
+
for (const l of lines || []) {
|
|
84
|
+
const prev = byId.get(l.id);
|
|
85
|
+
if (prev && prev.board !== l.board) continue; // an id never moves between boards
|
|
86
|
+
if (l.ev === 'remove') { byId.delete(l.id); continue; }
|
|
87
|
+
byId.set(l.id, {
|
|
88
|
+
id: l.id, board: l.board, measure: typeof l.measure === 'string' ? l.measure : '', title: tidy(l.title), question: tidy(l.question),
|
|
89
|
+
form: FORMS.includes(l.form) ? l.form : 'line', range: Number.isInteger(l.range) && l.range >= 2 ? l.range : null,
|
|
90
|
+
target: typeof l.target === 'number' && Number.isFinite(l.target) ? l.target : null, better: l.better === 'lower' ? 'lower' : 'higher', note: tidy(l.note),
|
|
91
|
+
at: l.at || null, first: prev ? prev.first : made++,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const out = {};
|
|
95
|
+
for (const c of byId.values()) (out[c.board] = out[c.board] || []).push(c);
|
|
96
|
+
for (const b of Object.keys(out)) out[b] = out[b].sort((a, z) => a.first - z.first).map(({ first, ...c }) => c);
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const list = (root, board) => fold(readLines(ledgerFile(root)))[board] || [];
|
|
101
|
+
|
|
102
|
+
/** THE SINGLE WRITER of premium-charts.jsonl. `v`, `id` (for a new one) and `at` are set here.
|
|
103
|
+
* known = { measures: Set of KR metric ids of the workspace } — a measure outside it is refused. */
|
|
104
|
+
function save(root, input, actor, { now, known } = {}) {
|
|
105
|
+
const c = check(input);
|
|
106
|
+
if (!c.ok) return c;
|
|
107
|
+
const v = c.value;
|
|
108
|
+
const file = ledgerFile(root);
|
|
109
|
+
const have = list(root, v.board);
|
|
110
|
+
const t = now == null ? Date.now() : now;
|
|
111
|
+
let line;
|
|
112
|
+
if (v.remove) {
|
|
113
|
+
if (!have.some((d) => d.id === v.id)) return refuse(404, 'That chart is not on this board.');
|
|
114
|
+
line = { v: 1, ev: 'remove', id: v.id, board: v.board, actor: actor || null, at: new Date(t).toISOString() };
|
|
115
|
+
} else {
|
|
116
|
+
if (v.id !== null && !have.some((d) => d.id === v.id)) return refuse(404, 'That chart is not on this board.');
|
|
117
|
+
if (have.some((d) => d.id !== v.id && norm(d.title) === norm(v.title))) return refuse(409, `“${v.title}” is already a chart on this board.`);
|
|
118
|
+
const ms = known && known.measures;
|
|
119
|
+
if (ms && !ms.has(v.measure)) return refuse(400, `No KR metric record is called “${v.measure}” in this workspace.`);
|
|
120
|
+
const id = v.id || 'pc-' + t.toString(36) + '-' + (readLines(file).length + 1);
|
|
121
|
+
line = { v: 1, ev: 'save', id, board: v.board, measure: v.measure, title: v.title, question: v.question, form: v.form, range: v.range, target: v.target, better: v.better, note: v.note, actor: actor || null, at: new Date(t).toISOString() };
|
|
122
|
+
}
|
|
123
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
124
|
+
fs.appendFileSync(file, JSON.stringify(line) + '\n');
|
|
125
|
+
const after = list(root, v.board);
|
|
126
|
+
return { ok: true, chart: v.remove ? null : after.find((d) => d.id === line.id) || null, charts: after };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
module.exports = { FORMS, TITLE_MAX, QUESTION_MAX, NOTE_MAX, ledgerFile, readLines, check, fold, list, save };
|
|
@@ -83,6 +83,7 @@ const MODULES = Object.freeze([
|
|
|
83
83
|
'routes-core-docs', // core-documents: the core documents of each level, Draft it (a core-doc run), Issue it and Drop (core-docs.jsonl)
|
|
84
84
|
'routes-custom-docs', // briefing-premium-adddoc: the documents the PM adds beyond the core set, Add a document (custom-docs.jsonl)
|
|
85
85
|
'routes-premium-dashboards', // briefing-premium-reports: the dashboards the PM makes on premium Insights (premium-dashboards.jsonl; page-press POST save)
|
|
86
|
+
'routes-premium-charts', // premium-studio-chart: the charts the PM makes in the Insight Studio (premium-charts.jsonl; page-press POST save)
|
|
86
87
|
'routes-report-design', // report-design-studio: the design studio (describe, samples, turns, versions, This is it), cycle renders and decisions, speaker notes and pins
|
|
87
88
|
'routes-report-structure', // report-structure: the structure step (turns, versions, Use this structure, sources and their checks, dry run) and the chart store (GET /api/charts)
|
|
88
89
|
'routes-refresh', // data-refresh-settings: Settings › Data refresh: what refreshes, when, the refresh log, Refresh now
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* model is lib/insights-premium.js build(), made from what the console's Reports tab reads: /api/boards (the board list), the KR metric records of the
|
|
6
6
|
* workspace with the line status the Calendar's Quarter pane computes from them (routes-c3-strategy.js outcomeOf; /api/c3-strategy itself drops the dated
|
|
7
7
|
* readings, so the records are read here), and /api/report (the report files). None starts a cold repository read, so this route does not answer 202.
|
|
8
|
+
* premium-studio-chart adds the board's saved charts (lib/premium-charts.js list).
|
|
8
9
|
* briefing-premium-reports adds the board's saved dashboards (lib/premium-dashboards.js list) and the workspace's GET /api/report-setups answer
|
|
9
10
|
* (setups, findings, asks). That GET is the console's own read: like the console, it may move old dashboard schedules into recurring reports once
|
|
10
11
|
* per repository. This route itself writes nothing. The page's presses post to /api/report-setups/* and /api/premium-dashboards/save. */
|
|
@@ -48,14 +49,15 @@ module.exports = {
|
|
|
48
49
|
} catch (e) { return fail('the KR metric records could not be read: ' + ((e && e.message) || e)); }
|
|
49
50
|
const reportsOk = !!(rp.body && rp.body.ok !== false);
|
|
50
51
|
const missing = reportsOk ? [] : ['reports'];
|
|
51
|
-
let saved = [];
|
|
52
|
+
let saved = [], mine = [];
|
|
52
53
|
if (pick && pick.id) { try { saved = PD.list(require('path').resolve(ctx.getWs(pick.ws).root), pick.id); } catch { missing.push('dashboards'); } }
|
|
54
|
+
if (pick && pick.id) { try { mine = require('./premium-charts.js').list(require('path').resolve(ctx.getWs(pick.ws).root), pick.id); } catch { missing.push('saved charts'); } }
|
|
53
55
|
const su = await via(setups, '/api/report-setups' + q, req, ctx).catch(() => ({ status: 500, body: null }));
|
|
54
56
|
const setupsOk = su.status === 200 && !!su.body && Array.isArray(su.body.setups);
|
|
55
57
|
if (!setupsOk) missing.push('report setups');
|
|
56
58
|
const model = Insights.build({
|
|
57
59
|
now: Date.now(), board: pick ? { ws: pick.ws, id: pick.id, name: pick.name } : { ws, id: null, name: 'Insights' }, boards: all.map((x) => ({ ws: x.ws, id: x.id, name: x.name })),
|
|
58
|
-
outcomes, reports: reportsOk ? rp.body.reports || [] : [], reportsOk, missing, saved,
|
|
60
|
+
outcomes, reports: reportsOk ? rp.body.reports || [] : [], reportsOk, missing, saved, mine,
|
|
59
61
|
setups: setupsOk ? su.body : null,
|
|
60
62
|
});
|
|
61
63
|
ctx.json(res, { ok: true, state: 'ready', model, as_of: Date.now() });
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-premium-charts.js — the charts the PM makes in the Insight Studio on the premium Insights page (initiative premium-studio-chart, PRD C1).
|
|
3
|
+
*
|
|
4
|
+
* POST /api/premium-charts/save { ws, board, id?, measure, title, question, form, range, target, better, note, remove? } → { ok, chart, charts }
|
|
5
|
+
* one `save` or `remove` line in <state>/premium-charts.jsonl (lib/premium-charts.js, the one writer)
|
|
6
|
+
*
|
|
7
|
+
* The page reads the charts through GET /api/insights-premium, so this module has no GET.
|
|
8
|
+
*
|
|
9
|
+
* WHO WRITES. As routes-premium-dashboards.js: the POST refuses a request that carries an agent session header (403) and passes pm-guard
|
|
10
|
+
* requirePagePress, the launch nonce and the page's origin. The board must be one of the workspace's boards, and the measure a KR metric record of that
|
|
11
|
+
* workspace. The route stores what the PM chose and nothing else. */
|
|
12
|
+
const guard = require('./pm-guard.js');
|
|
13
|
+
const PC = require('./premium-charts.js');
|
|
14
|
+
const { wsOf, boardIds, krIds } = require('./routes-premium-dashboards.js');
|
|
15
|
+
|
|
16
|
+
const bad = (status, error) => ({ status, body: { ok: false, error } });
|
|
17
|
+
|
|
18
|
+
async function handle(req, res, url, ctx) {
|
|
19
|
+
const send = (r) => { ctx.json(res, r.body, r.status); return true; };
|
|
20
|
+
if (url.pathname !== '/api/premium-charts/save') return send(bad(404, 'no such premium-charts route'));
|
|
21
|
+
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
22
|
+
const read = await ctx.readJson(req);
|
|
23
|
+
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
24
|
+
const body = read.body || {};
|
|
25
|
+
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot change a chart. Only a press on the page does'));
|
|
26
|
+
const g = guard.requirePagePress(req, body);
|
|
27
|
+
if (!g.ok) return send(bad(g.status, g.error));
|
|
28
|
+
const w = wsOf(ctx, typeof body.ws === 'string' ? body.ws : '');
|
|
29
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
30
|
+
const c = PC.check(body);
|
|
31
|
+
if (!c.ok) return send(bad(c.status, c.error));
|
|
32
|
+
const ids = boardIds(ctx, w);
|
|
33
|
+
if (!ids) return send(bad(503, 'The boards could not be read. Try again in a moment.'));
|
|
34
|
+
if (!ids.has(c.value.board)) return send(bad(404, 'no such board in this workspace'));
|
|
35
|
+
let known = null;
|
|
36
|
+
if (!c.value.remove) {
|
|
37
|
+
const ms = krIds(ctx, w.id);
|
|
38
|
+
if (!ms) return send(bad(503, 'The KR metric records could not be read, so the measure cannot be checked.'));
|
|
39
|
+
known = { measures: ms };
|
|
40
|
+
}
|
|
41
|
+
const r = PC.save(w.root, body, g.actor, { now: Date.now(), known });
|
|
42
|
+
if (!r.ok) return send(bad(r.status, r.error));
|
|
43
|
+
return send({ status: 200, body: { ok: true, chart: r.chart, charts: r.charts } });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = { prefixes: ['/api/premium-charts'], handle };
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* WHO WRITES. The POST refuses a request that carries an agent session header (403), as routes-custom-docs.js does, and passes pm-guard
|
|
10
10
|
* requirePagePress: the launch nonce and the page's origin. The board must be one of the workspace's boards (routes-boards.js frameFor), and every chart
|
|
11
|
-
* must be a KR metric record of that workspace (its `rid`, the id the Insights model gives a chart). The route stores what the PM chose and nothing else: no chart, report or console layout changes. */
|
|
11
|
+
* must be a KR metric record of that workspace (its `rid`, the id the Insights model gives a chart) or a saved chart of the board (premium-studio-chart C2). The route stores what the PM chose and nothing else: no chart, report or console layout changes. */
|
|
12
12
|
const guard = require('./pm-guard.js');
|
|
13
13
|
const PD = require('./premium-dashboards.js');
|
|
14
14
|
const boards = require('./routes-boards.js');
|
|
@@ -52,6 +52,7 @@ async function handle(req, res, url, ctx) {
|
|
|
52
52
|
if (!c.value.remove) {
|
|
53
53
|
const ks = krIds(ctx, w.id);
|
|
54
54
|
if (!ks) return send(bad(503, 'The KR metric records could not be read, so the charts cannot be checked.'));
|
|
55
|
+
for (const pc of require('./premium-charts.js').list(w.root, c.value.board)) ks.add(pc.id); // premium-studio-chart C2: a saved chart of the board
|
|
55
56
|
known = { charts: ks };
|
|
56
57
|
}
|
|
57
58
|
const r = PD.save(w.root, body, g.actor, { now: Date.now(), known });
|
|
@@ -59,4 +60,4 @@ async function handle(req, res, url, ctx) {
|
|
|
59
60
|
return send({ status: 200, body: { ok: true, dashboard: r.dashboard, dashboards: r.dashboards } });
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
module.exports = { prefixes: ['/api/premium-dashboards'], handle };
|
|
63
|
+
module.exports = { prefixes: ['/api/premium-dashboards'], handle, wsOf, boardIds, krIds };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.271.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.271.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/workspace/package.json
CHANGED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* premium-studio-chart-test.js — the Insight Studio's Chart mode on the premium Insights page (initiative premium-studio-chart;
|
|
4
|
+
* planning/prd/premium-studio-chart-prd.md C1 to C12). A real server on a scratch repository whose KR metric records hold two measures with a series and
|
|
5
|
+
* one without. The real page presses the real save routes:
|
|
6
|
+
* O opening · C the conversation · D the four forms · K the checks · U Undo · B the brief · S save, add to a dashboard, edit and remove · P the POST allow-list · F floors */
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const os = require('os');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const { spawn } = require('child_process');
|
|
11
|
+
const { findBrowser } = require('./lib/find-browser');
|
|
12
|
+
const T = require('./test-run').configure({ name: 'premium-studio-chart' });
|
|
13
|
+
const PC = require('./lib/premium-charts.js');
|
|
14
|
+
|
|
15
|
+
const BASE = T.BASE;
|
|
16
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
17
|
+
const until = async (fn, ms = 20000, step = 150) => { const t0 = Date.now(); for (;;) { const v = await fn(); if (v) return v; if (Date.now() - t0 > ms) return v; await sleep(step); } };
|
|
18
|
+
const results = [];
|
|
19
|
+
const ok = (name, cond, extra = '') => { results.push({ name, cond: !!cond }); console.log(`${cond ? '✓' : '✗'} ${name}${!cond && extra !== '' ? ' — ' + String(extra).slice(0, 500) : ''}`); };
|
|
20
|
+
let srv = null, browser = null;
|
|
21
|
+
const finish = async (code) => {
|
|
22
|
+
if (browser) await browser.close().catch(() => {});
|
|
23
|
+
if (srv) { try { srv.kill('SIGKILL'); } catch { /* gone */ } }
|
|
24
|
+
T.killTmux();
|
|
25
|
+
const bad = results.filter((x) => !x.cond).length;
|
|
26
|
+
console.log(`\n${results.length - bad}/${results.length} premium-studio-chart assertions passed`);
|
|
27
|
+
process.exit(code !== undefined ? code : (bad ? 1 : 0));
|
|
28
|
+
};
|
|
29
|
+
process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
|
|
30
|
+
|
|
31
|
+
/* the scratch repository: Partner activation (5 readings), Time to first call (2 readings), Lonely (1 reading, no series) */
|
|
32
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'studio-chart-repo-'));
|
|
33
|
+
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), 'studio-chart-state-'));
|
|
34
|
+
fs.mkdirSync(path.join(dir, 'planning', 'records'), { recursive: true });
|
|
35
|
+
const rd = (id, rid, at, value) => ({ id, kind: 'reading', rid, fields: { at, value } });
|
|
36
|
+
const L = [
|
|
37
|
+
{ id: '1', kind: 'add', rid: 'krm-a', fields: { metric: 'Partner activation', baseline: 20, target: 50, by: '2026-12-31', pillar: 'Growth', unit: '%' } },
|
|
38
|
+
rd('2', 'krm-a', '2026-06-01', 20), rd('3', 'krm-a', '2026-07-01', 24), rd('4', 'krm-a', '2026-08-01', 30), rd('5', 'krm-a', '2026-09-01', 28), rd('6', 'krm-a', '2026-10-01', 33),
|
|
39
|
+
{ id: '7', kind: 'add', rid: 'krm-t', fields: { metric: 'Time to first call', baseline: 10, target: 4, by: '2026-12-31', pillar: 'Growth', unit: ' days' } },
|
|
40
|
+
rd('8', 'krm-t', '2026-08-01', 9), rd('9', 'krm-t', '2026-10-01', 7),
|
|
41
|
+
{ id: '10', kind: 'add', rid: 'krm-l', fields: { metric: 'Lonely', baseline: 1, target: 2, by: '2026-12-31' } }, rd('11', 'krm-l', '2026-10-01', 1),
|
|
42
|
+
];
|
|
43
|
+
fs.writeFileSync(path.join(dir, 'planning', 'records', 'kr-metrics.jsonl'), L.map((x) => JSON.stringify(x)).join('\n') + '\n');
|
|
44
|
+
const model = async () => (await (await fetch(BASE + '/api/insights-premium')).json()).model;
|
|
45
|
+
|
|
46
|
+
(async () => {
|
|
47
|
+
const exe = findBrowser();
|
|
48
|
+
if (!exe) { console.log('✗ no Chrome/Chromium on this machine — the suite cannot run'); return finish(1); }
|
|
49
|
+
let chromium;
|
|
50
|
+
try { ({ chromium } = require('playwright-core')); } catch { console.log('✗ playwright-core is not installed'); return finish(1); }
|
|
51
|
+
srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore', env: T.env({ PMOS_WS_PORT: String(T.PORT), PMOS_SELF_ROOT: dir, PMOS_STATE_DIR: stateDir }) });
|
|
52
|
+
await T.waitForServer(BASE);
|
|
53
|
+
browser = await chromium.launch({ executablePath: exe, headless: true, args: ['--no-sandbox'] });
|
|
54
|
+
|
|
55
|
+
const ctx = await browser.newContext({ viewport: { width: 1280, height: 900 } }), p = await ctx.newPage(), errs = [], posts = [];
|
|
56
|
+
p.on('pageerror', (e) => errs.push(String(e)));
|
|
57
|
+
p.on('request', (r) => { if (r.method() === 'POST') posts.push(new URL(r.url()).pathname); });
|
|
58
|
+
await p.goto(BASE + '/premium-insights.html');
|
|
59
|
+
await until(() => p.evaluate(() => !!document.querySelector('#dashBody .mch') && !!document.querySelector('#pcNew')));
|
|
60
|
+
const M0 = await model(), board = M0.board.id;
|
|
61
|
+
const ledger = () => PC.list(dir, board);
|
|
62
|
+
const say = async (t) => { await p.fill('#stIn', t); await p.press('#stIn', 'Enter'); await sleep(150); return p.evaluate(() => { const a = [...document.querySelectorAll('#dBody .stream .turn.a .tt')]; return a.length ? a[a.length - 1].textContent : ''; }); };
|
|
63
|
+
const chipv = (k) => p.evaluate((x) => (document.querySelector(`#oMain [data-st="chip|${x}"] b`) || {}).textContent || '', k);
|
|
64
|
+
const pv = () => p.evaluate(() => { const t = document.querySelector('#stPv .mt1'); return t ? { cls: t.className, title: t.querySelector('.mlab').firstChild.textContent, val: (t.querySelector('.mval') || {}).textContent, bars: [...t.querySelectorAll('.bw i')].map((i) => parseFloat(i.style.height)), foot: (t.querySelector('.mfoot') || {}).textContent || '' } : null; });
|
|
65
|
+
const checksTxt = () => p.evaluate(() => (document.querySelector('#stCk .suckb b') || {}).textContent || '');
|
|
66
|
+
const tap = (sel) => p.$eval(sel, (b) => b.click());
|
|
67
|
+
const open = async (sel) => { await p.click(sel); await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#oMain .stu'))); await sleep(300); };
|
|
68
|
+
const mode = () => p.evaluate(() => (document.querySelector('#oMain .stmd [aria-pressed="true"]') || {}).textContent || '');
|
|
69
|
+
|
|
70
|
+
/* O: New chart opens the Studio in Chart mode */
|
|
71
|
+
await open('#pcNew');
|
|
72
|
+
ok('O1 New chart opens the Studio in Chart mode, with the brief of the mockup', await mode() === 'Chart' && await chipv('q') === 'Not set' && ['Partner activation', 'Time to first call'].includes(await chipv('measure')) && await chipv('form') === 'Line', await mode() + ' ' + await chipv('measure'));
|
|
73
|
+
await tap('#oMain [data-st="lib"]'); await sleep(100);
|
|
74
|
+
const lib = await p.evaluate(() => [...document.querySelectorAll('#stLb .stli')].map((b) => b.querySelector('b').textContent + ':' + (b.disabled ? 'off' : 'on')));
|
|
75
|
+
ok('O2 the library lists the measures of the records, and one with no series cannot start a chart', lib.join() === 'Partner activation:on,Time to first call:on,Lonely:off', lib.join());
|
|
76
|
+
await tap('#stLb [data-st="libm|krm-a"]'); await sleep(100);
|
|
77
|
+
ok('O3 a measure from the library starts the draft, with the record\'s own target', await chipv('measure') === 'Partner activation' && await chipv('target') === '50' && await chipv('range') === 'All 5 readings', await chipv('target'));
|
|
78
|
+
await tap('#oMain [data-st="lib"]');
|
|
79
|
+
|
|
80
|
+
/* C and D: the conversation and the forms */
|
|
81
|
+
let a = await say('Is partner activation on track to reach its target?');
|
|
82
|
+
ok('C1 a question sets the Question chip and suggests a meter, and says why', await chipv('q') === 'Is partner activation on track to reach its target?' && await chipv('form') === 'Meter' && /a meter, because/i.test(a), a);
|
|
83
|
+
let t = await pv();
|
|
84
|
+
ok('D1 the meter draws the latest reading against the target, in words', /\bprg\b/.test(t.cls) && t.val === '33%' && /target 50%/.test(t.foot), JSON.stringify(t));
|
|
85
|
+
a = await say('show it as bars, last 4 readings, target 35');
|
|
86
|
+
t = await pv();
|
|
87
|
+
ok('C2 one turn sets the form, the range and the target', await chipv('form') === 'Bars' && await chipv('range') === 'Last 4 readings' && await chipv('target') === '35', a);
|
|
88
|
+
ok('D2 bars start at zero: four bars, each as tall as its reading against the highest of the readings and the target', t && t.bars.length === 4 && Math.abs(t.bars[3] - 33 / 35 * 84) < 0.2 && Math.abs(t.bars[0] - 24 / 35 * 84) < 0.2, JSON.stringify(t));
|
|
89
|
+
a = await say('make it a pie chart');
|
|
90
|
+
ok('C3 a pie is declined with the reason, and nothing changes', /^I changed nothing: no pie/.test(a) && await chipv('form') === 'Bars', a);
|
|
91
|
+
a = await say('call it Activation check');
|
|
92
|
+
ok('C4 "call it" names the chart on the preview', (await pv()).title === 'Activation check', a);
|
|
93
|
+
a = await say('show the number');
|
|
94
|
+
t = await pv();
|
|
95
|
+
ok('D3 the number form draws the latest value and its change', /\bnum\b/.test(t.cls) && t.val === '33%', JSON.stringify(t));
|
|
96
|
+
await say('show it as a line');
|
|
97
|
+
ok('D4 the line form is the page\'s own line chart', /\bmch\b/.test((await pv()).cls));
|
|
98
|
+
ok('C5 no turn posted anything', posts.length === 0, posts.join());
|
|
99
|
+
|
|
100
|
+
/* K and U: the checks, a fix, and Undo */
|
|
101
|
+
await say('bars');
|
|
102
|
+
ok('K1 with a question, a target, four readings and a form that fits, 5 of 5 checks pass', await checksTxt() === '5 of 5 checks pass', await checksTxt());
|
|
103
|
+
a = await say('question: How has activation moved over time?');
|
|
104
|
+
ok('K2 a question about movement with bars fails "The form fits the question"', await checksTxt() === '4 of 5 checks pass', a + ' ' + await checksTxt());
|
|
105
|
+
await tap('#oMain [data-st="ck"]'); await sleep(100);
|
|
106
|
+
const fix = await p.evaluate(() => [...document.querySelectorAll('#stCk .sucl li.bad button')].map((b) => b.textContent));
|
|
107
|
+
ok('K3 the failing check offers its fix', fix.join() === 'Use a line', fix.join());
|
|
108
|
+
await tap('#stCk .sucl li.bad button'); await sleep(150);
|
|
109
|
+
ok('K4 the fix sets the line, and the checks pass', await chipv('form') === 'Line' && await checksTxt() === '5 of 5 checks pass');
|
|
110
|
+
await tap('#oMain [data-st="undo"]'); await sleep(150);
|
|
111
|
+
ok('U1 Undo steps back one change (the form)', await chipv('form') === 'Bars');
|
|
112
|
+
await say('line');
|
|
113
|
+
|
|
114
|
+
/* B: the brief and its tray */
|
|
115
|
+
await tap('#oMain [data-st="chip|range"]'); await sleep(100);
|
|
116
|
+
await tap('#stTr [data-st="set|range|"]'); await sleep(100);
|
|
117
|
+
ok('B1 the Range tray sets every reading', await chipv('range') === 'All 5 readings');
|
|
118
|
+
await tap('#oMain [data-st="chip|target"]'); await sleep(100);
|
|
119
|
+
await p.fill('#stI', '40'); await sleep(150);
|
|
120
|
+
ok('B2 the Target field sets the target as it is typed', await chipv('target') === '40' && /target 40%/.test((await p.evaluate(() => document.querySelector('#stPv .mwk').textContent))));
|
|
121
|
+
await p.press('#stI', 'Enter'); await sleep(100);
|
|
122
|
+
await tap('#oMain [data-st="more"]'); await sleep(100);
|
|
123
|
+
ok('B3 More shows Title, Better when, Note and Add to', await chipv('title') === 'Activation check' && await chipv('better') === 'Higher' && await chipv('note') === 'None' && await chipv('addTo') === 'No dashboard');
|
|
124
|
+
await say('note: From the partner records');
|
|
125
|
+
ok('B4 a note is set in words and drawn under the chart', await p.evaluate(() => (document.querySelector('#stPv .mnote') || {}).textContent) === 'From the partner records');
|
|
126
|
+
|
|
127
|
+
/* S: save, see it on the page, add it to a dashboard, edit, remove */
|
|
128
|
+
await tap('#oMain [data-st="save"]');
|
|
129
|
+
await until(() => p.evaluate(() => !document.querySelector('#dlg').classList.contains('on')));
|
|
130
|
+
let Y = ledger();
|
|
131
|
+
ok('S1 Save writes one chart line with what the brief shows', Y.length === 1 && Y[0].title === 'Activation check' && Y[0].form === 'line' && Y[0].range === null && Y[0].target === 40 && Y[0].measure === 'krm-a' && Y[0].note === 'From the partner records' && Y[0].question === 'How has activation moved over time?', JSON.stringify(Y));
|
|
132
|
+
const cid = Y[0] && Y[0].id;
|
|
133
|
+
ok('S2 the page lists it under Your charts, drawn, with Edit', await until(() => p.evaluate((id) => [...document.querySelectorAll('#dashBody .ntw')].some((w) => /Activation check/.test(w.textContent) && !!w.querySelector(`[data-ced="${id}"]`)), cid)));
|
|
134
|
+
await open('#pdNew');
|
|
135
|
+
await say('add Time to first call'); await say('call it Weekly'); await say('it is for the Monday review');
|
|
136
|
+
await tap('#oMain [data-st="save"]');
|
|
137
|
+
await until(async () => (await model()).dashboards.some((d) => d.saved && d.name === 'Weekly'));
|
|
138
|
+
// the Studio has closed and the page has drawn the new dashboard; Your charts is under All measures
|
|
139
|
+
await until(() => p.evaluate(() => !document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#dashTabs [data-d="all"]')));
|
|
140
|
+
await p.$eval('#dashTabs [data-d="all"]', (b) => b.click());
|
|
141
|
+
await until(() => p.evaluate((id) => !!document.querySelector(`#dashBody [data-ced="${id}"]`), cid));
|
|
142
|
+
await p.$eval(`#dashBody [data-ced="${cid}"]`, (b) => b.click());
|
|
143
|
+
await until(async () => await mode() === 'Chart');
|
|
144
|
+
await sleep(200);
|
|
145
|
+
ok('S3 Edit opens the saved chart in Chart mode', await mode() === 'Chart' && await chipv('q') === 'How has activation moved over time?' && await chipv('target') === '40');
|
|
146
|
+
a = await say('last 3 readings and add it to Weekly');
|
|
147
|
+
ok('S4 "add it to" names the dashboard for Save', /it will be added to Weekly on Save/.test(a) && await chipv('range') === 'Last 3 readings', a);
|
|
148
|
+
await tap('#oMain [data-st="save"]');
|
|
149
|
+
await until(async () => { const d = (await model()).dashboards.find((x) => x.name === 'Weekly'); return d && d.charts.includes(cid); });
|
|
150
|
+
const W = (await model()).dashboards.find((x) => x.name === 'Weekly');
|
|
151
|
+
ok('S5 the chart is saved and appended to the dashboard, which draws it', ledger()[0].range === 3 && W.charts.join() === 'krm-t,' + cid && W.keys.join() === 'ins:krm-t,mine:' + cid, JSON.stringify(W));
|
|
152
|
+
const onPage = await until(() => p.evaluate(() => [...document.querySelectorAll('#dashBody .mt1 .mlab')].map((e) => e.firstChild.textContent).join()));
|
|
153
|
+
ok('S6 the page shows Weekly with the saved chart after the measure', onPage === 'Time to first call,Activation check', onPage);
|
|
154
|
+
await until(() => p.evaluate((id) => !document.querySelector('#dlg').classList.contains('on') && !!document.querySelector(`#dashBody [data-ced="${id}"]`), cid));
|
|
155
|
+
await p.$eval(`#dashBody [data-ced="${cid}"]`, (b) => b.click());
|
|
156
|
+
await until(async () => await mode() === 'Chart'); await sleep(200);
|
|
157
|
+
await tap('#oMain [data-st="del"]'); await sleep(100);
|
|
158
|
+
const armed = await p.evaluate(() => ({ b: document.querySelector('#oMain [data-st="del"]').textContent, m: document.querySelector('#stMsg').textContent }));
|
|
159
|
+
ok('S7 Remove asks for a second press and says what stays', armed.b === 'Press again to remove it' && /measure and its record stay/.test(armed.m), JSON.stringify(armed));
|
|
160
|
+
await tap('#oMain [data-st="del"]');
|
|
161
|
+
await until(() => ledger().length === 0);
|
|
162
|
+
const W2 = await until(async () => { const d = (await model()).dashboards.find((x) => x.name === 'Weekly'); return d && d.gone.length ? d : null; });
|
|
163
|
+
ok('S8 the second press removes the chart, and the dashboard says it was removed', ledger().length === 0 && W2 && /was removed/.test(W2.gone[0].why), JSON.stringify(W2 && W2.gone));
|
|
164
|
+
|
|
165
|
+
/* P: the POST allow-list and the guard */
|
|
166
|
+
const allowed = new Set(['/api/premium-charts/save', '/api/premium-dashboards/save']);
|
|
167
|
+
ok('P1 the page posted only to the two save routes', posts.length === 5 && posts.every((x) => allowed.has(x)), posts.join());
|
|
168
|
+
const H = await T.pressHeaders(BASE), body = JSON.stringify({ ws: M0.board.ws, board, measure: 'krm-a', title: 'From an agent' });
|
|
169
|
+
const asAgent = await fetch(BASE + '/api/premium-charts/save', { method: 'POST', headers: { ...H, 'x-pmos-session': 's1' }, body }).then((x) => x.status);
|
|
170
|
+
const noNonce = await fetch(BASE + '/api/premium-charts/save', { method: 'POST', headers: { 'content-type': 'application/json' }, body }).then((x) => x.status);
|
|
171
|
+
ok('P2 an agent session and a request without the page press are refused, and nothing is written', asAgent === 403 && noNonce >= 400 && ledger().length === 0, asAgent + ' ' + noNonce);
|
|
172
|
+
ok('P3 no script error', errs.length === 0, errs.join(' | '));
|
|
173
|
+
await ctx.close();
|
|
174
|
+
|
|
175
|
+
/* F: floors at 390 px, both themes */
|
|
176
|
+
for (const theme of ['light', 'dark']) {
|
|
177
|
+
const c2 = await browser.newContext({ viewport: { width: 390, height: 844 }, colorScheme: theme }), q = await c2.newPage();
|
|
178
|
+
await q.goto(BASE + '/premium-insights.html');
|
|
179
|
+
await until(() => q.evaluate(() => !!document.querySelector('#pcNew')));
|
|
180
|
+
await q.click('#pcNew'); await until(() => q.evaluate(() => !!document.querySelector('#oMain .stu'))); await sleep(400);
|
|
181
|
+
await q.$eval('#oMain [data-st="more"]', (b) => b.click()); await sleep(100);
|
|
182
|
+
await q.$eval('#oMain [data-st="chip|form"]', (b) => b.click()); await sleep(100);
|
|
183
|
+
const measure = () => q.evaluate(() => {
|
|
184
|
+
const sm = [...document.querySelectorAll('#oMain .stu button')].filter((b) => b.offsetParent).filter((b) => { const r = b.getBoundingClientRect(); return r.height < 44 || r.width < 44; }).map((b) => (b.dataset.st || b.textContent) + ':' + Math.round(b.getBoundingClientRect().width) + 'x' + Math.round(b.getBoundingClientRect().height));
|
|
185
|
+
const pane = document.querySelector('#dOut'); return { small: sm.length, which: sm, side: pane.scrollWidth - pane.clientWidth, doc: document.documentElement.scrollWidth - innerWidth };
|
|
186
|
+
});
|
|
187
|
+
await until(async () => (await measure()).small === 0, 4000);
|
|
188
|
+
const f = await measure();
|
|
189
|
+
ok(`F1 at 390 px (${theme}) every Chart mode target is 44 px or more and nothing scrolls sideways`, f.small === 0 && f.side <= 1 && f.doc <= 1, JSON.stringify(f));
|
|
190
|
+
await c2.close();
|
|
191
|
+
}
|
|
192
|
+
finish();
|
|
193
|
+
})().catch((e) => { console.error(e); finish(1); });
|