create-pmos 0.270.0 → 0.272.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-insights-test.js +1 -1
- package/workspace/guide/briefing-premium.md +4 -1
- 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/premium-studio-report-test.js +203 -0
- package/workspace/public/pm/premium-insights.js +84 -13
- package/workspace/public/pm/premium-studio-report.js +264 -0
- package/workspace/public/pm/premium-studio.js +259 -47
- package/workspace/public/pm/premium.css +38 -0
- package/workspace/test-lists/premium-studio-chart.json +13 -0
- package/workspace/test-lists/premium-studio-report.json +9 -0
|
@@ -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); });
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* premium-studio-report-test.js — the Insight Studio's Report mode on the premium Insights page (initiative premium-studio-report;
|
|
4
|
+
* planning/prd/premium-studio-report-prd.md R1 to R13). A real server on a scratch git repository with KR metric records, and a stub `claude` on the PATH that
|
|
5
|
+
* plays the report-structure job (as c3-report-structure-real-test.js does). The real page presses the real routes:
|
|
6
|
+
* O opening · K the checks · C the conversation · U Undo · B the brief · S set it up · H shaping a set-up report · L the library · P the POST allow-list · F floors
|
|
7
|
+
* Set STUDIO_SHOTS=<dir> to save screenshots of a new report and a set-up report, at 1280 and 390 wide. */
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const os = require('os');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const { spawn, execFileSync } = require('child_process');
|
|
12
|
+
const { findBrowser } = require('./lib/find-browser');
|
|
13
|
+
const T = require('./test-run').configure({ name: 'premium-studio-report' });
|
|
14
|
+
const RS = require('./lib/report-setups.js');
|
|
15
|
+
const S = require('./lib/report-structure.js');
|
|
16
|
+
|
|
17
|
+
const BASE = T.BASE;
|
|
18
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
19
|
+
const until = async (fn, ms = 20000, step = 150) => { const t0 = Date.now(); for (;;) { let v; try { v = await fn(); } catch { v = null; } if (v) return v; if (Date.now() - t0 > ms) return v; await sleep(step); } };
|
|
20
|
+
const results = [];
|
|
21
|
+
const ok = (name, cond, extra = '') => { results.push({ name, cond: !!cond }); console.log(`${cond ? '✓' : '✗'} ${name}${!cond && extra !== '' ? ' — ' + String(extra).slice(0, 500) : ''}`); };
|
|
22
|
+
let srv = null, browser = null;
|
|
23
|
+
const base = fs.mkdtempSync(path.join(os.tmpdir(), 'studio-report-'));
|
|
24
|
+
const finish = async (code) => {
|
|
25
|
+
if (browser) await browser.close().catch(() => {});
|
|
26
|
+
if (srv) { try { srv.kill('SIGKILL'); } catch { /* gone */ } }
|
|
27
|
+
T.killTmux();
|
|
28
|
+
try { fs.rmSync(base, { recursive: true, force: true }); } catch { /* left for the OS */ }
|
|
29
|
+
const bad = results.filter((x) => !x.cond).length;
|
|
30
|
+
console.log(`\n${results.length - bad}/${results.length} premium-studio-report assertions passed`);
|
|
31
|
+
process.exit(code !== undefined ? code : (bad ? 1 : 0));
|
|
32
|
+
};
|
|
33
|
+
process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
|
|
34
|
+
|
|
35
|
+
/* the scratch repository: one measure with a series, so the page draws; a git repository, so a report draft can be written */
|
|
36
|
+
const dir = path.join(base, 'repo'), stateDir = path.join(base, 'state'), fakeBin = path.join(base, 'bin'), fakeHome = path.join(base, 'home');
|
|
37
|
+
for (const d of [path.join(dir, 'planning', 'records'), stateDir, fakeBin, path.join(fakeHome, '.claude')]) fs.mkdirSync(d, { recursive: true });
|
|
38
|
+
const rd = (id, rid, at, value) => ({ id, kind: 'reading', rid, fields: { at, value } });
|
|
39
|
+
fs.writeFileSync(path.join(dir, 'planning', 'records', 'kr-metrics.jsonl'), [
|
|
40
|
+
{ id: '1', kind: 'add', rid: 'krm-a', fields: { metric: 'Partner activation', baseline: 20, target: 50, by: '2026-12-31', pillar: 'Growth', unit: '%' } },
|
|
41
|
+
rd('2', 'krm-a', '2026-08-01', 24), rd('3', 'krm-a', '2026-09-01', 30), rd('4', 'krm-a', '2026-10-01', 33),
|
|
42
|
+
].map((x) => JSON.stringify(x)).join('\n') + '\n');
|
|
43
|
+
fs.mkdirSync(path.join(dir, 'planning', 'initiatives'), { recursive: true });
|
|
44
|
+
fs.writeFileSync(path.join(dir, 'planning', 'initiatives', 'partner-activation.md'), '---\ntype: Initiative\ntitle: "Partner activation"\nid: partner-activation\nlane: feature\nparent_kr: q4:o1:kr1\n---\n\n# Partner activation\n');
|
|
45
|
+
const git = (...a) => execFileSync('git', a, { cwd: dir, stdio: 'ignore' });
|
|
46
|
+
git('init', '-q'); git('-c', 'user.name=t', '-c', 'user.email=t@t', 'add', '-A'); git('-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-q', '-m', 'records');
|
|
47
|
+
/* The stub plays the structure job: the first turn builds a plan with five sections; a later turn builds on the previous version. Any other run is a no-op. */
|
|
48
|
+
fs.writeFileSync(path.join(fakeBin, 'claude'), `#!/usr/bin/env node
|
|
49
|
+
const fs = require('fs');
|
|
50
|
+
let input = ''; process.stdin.on('data', (d) => { input += d; }); process.stdin.on('end', () => {
|
|
51
|
+
const line = (k) => { const m = new RegExp('^- ' + k + ': (.*)$', 'm').exec(input); return m ? m[1].trim() : null; };
|
|
52
|
+
const mode = line('Mode'); const out = line('Output path');
|
|
53
|
+
const done = (o) => { process.stdout.write(JSON.stringify({ type: 'result', subtype: 'success', is_error: false, result: typeof o === 'string' ? o : JSON.stringify(o), num_turns: 2, duration_ms: 500, permission_denials: [] })); process.exit(0); };
|
|
54
|
+
if (!mode || !out || mode === 'dry') return done('Done.');
|
|
55
|
+
const prev = line('Previous version');
|
|
56
|
+
const plan = prev && prev.startsWith('/') ? JSON.parse(fs.readFileSync(prev, 'utf8')) : {
|
|
57
|
+
purpose: { readers: 'Leadership', decision: 'Whether partners activate fast enough', scope: 'Partners', cadence: 'monthly', questions: ['Are partners activating?'] },
|
|
58
|
+
sources: [{ id: 'board', kind: 'pmos-level', name: 'Board', ref: 'board', use: 'The KR metric records', state: 'reached' }],
|
|
59
|
+
charts: [{ id: 'act', chart: null, name: 'Partner activation', source: 'board', from: 'KR metric record', how: 'Latest reading', compare: 'Previous reading', flag: 'Below the line', question: 'Are partners activating?', query: '', why: 'The KR' }],
|
|
60
|
+
outline: [{ id: 'headline', title: 'Headline', fixed: true, charts: [], notes: '', show: 'Text' }, { id: 'funnel', title: 'Activation', charts: ['act'], notes: 'The KR against its line', show: 'Chart' },
|
|
61
|
+
{ id: 'changes', title: 'What changed', charts: [], notes: '', show: 'List' }, { id: 'needs', title: 'Needs your call', fixed: true, charts: [], notes: '', show: 'List' }, { id: 'sources', title: 'Sources', fixed: true, charts: [], notes: '', show: 'List' }],
|
|
62
|
+
options: [],
|
|
63
|
+
};
|
|
64
|
+
fs.writeFileSync(out, JSON.stringify(plan));
|
|
65
|
+
setTimeout(() => done({ answer: prev && prev.startsWith('/') ? 'Kept the sections as they are.' : 'Built the first version: the headline, activation, what changed, needs your call and sources.' }), 600);
|
|
66
|
+
});
|
|
67
|
+
`, { mode: 0o755 });
|
|
68
|
+
const model = async () => (await (await fetch(BASE + '/api/insights-premium')).json()).model;
|
|
69
|
+
|
|
70
|
+
(async () => {
|
|
71
|
+
const exe = findBrowser();
|
|
72
|
+
if (!exe) { console.log('✗ no Chrome/Chromium on this machine — the suite cannot run'); return finish(1); }
|
|
73
|
+
let chromium;
|
|
74
|
+
try { ({ chromium } = require('playwright-core')); } catch { console.log('✗ playwright-core is not installed'); return finish(1); }
|
|
75
|
+
srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore',
|
|
76
|
+
env: T.env({ PMOS_WS_PORT: String(T.PORT), PMOS_SELF_ROOT: dir, PMOS_STATE_DIR: stateDir, PMOS_NO_OPEN: '1', PMOS_REPORT_FIND: 'off', PMOS_CORE_DOCS: 'off', HOME: fakeHome, PATH: fakeBin + path.delimiter + process.env.PATH }) });
|
|
77
|
+
await T.waitForServer(BASE);
|
|
78
|
+
browser = await chromium.launch({ executablePath: exe, headless: true, args: ['--no-sandbox'] });
|
|
79
|
+
|
|
80
|
+
const ctx = await browser.newContext({ viewport: { width: 1280, height: 900 } }), p = await ctx.newPage(), errs = [], posts = [];
|
|
81
|
+
p.on('pageerror', (e) => errs.push(String(e)));
|
|
82
|
+
p.on('request', (r) => { if (r.method() === 'POST') posts.push(new URL(r.url()).pathname); });
|
|
83
|
+
await p.goto(BASE + '/premium-insights.html');
|
|
84
|
+
await until(() => p.evaluate(() => !!document.querySelector('#repNew')));
|
|
85
|
+
const M0 = await model(), bname = M0.board.name;
|
|
86
|
+
const say = async (t, ms = 150) => { await p.fill('#stIn', t); await p.press('#stIn', 'Enter'); await sleep(ms); return p.evaluate(() => { const a = [...document.querySelectorAll('#dBody .stream .turn.a .tt')]; return a.length ? a[a.length - 1].textContent : ''; }); };
|
|
87
|
+
const lastA = () => p.evaluate(() => { const a = [...document.querySelectorAll('#dBody .stream .turn.a .tt')]; return a.length ? a[a.length - 1].textContent : ''; });
|
|
88
|
+
const chipv = (k) => p.evaluate((x) => (document.querySelector(`#oMain [data-st="chip|${x}"] b`) || {}).textContent || '', k);
|
|
89
|
+
const checksTxt = () => p.evaluate(() => (document.querySelector('#stCk .suckb b') || {}).textContent || '');
|
|
90
|
+
const secs = () => p.evaluate(() => [...document.querySelectorAll('#stPv .stsec h4')].map((h) => h.firstChild.textContent));
|
|
91
|
+
const tap = (sel) => p.$eval(sel, (b) => b.click());
|
|
92
|
+
const mode = () => p.evaluate(() => (document.querySelector('#oMain .stmd [aria-pressed="true"]') || {}).textContent || '');
|
|
93
|
+
const shot = async (n) => { if (process.env.STUDIO_SHOTS) await p.screenshot({ path: path.join(process.env.STUDIO_SHOTS, n + '.png') }); };
|
|
94
|
+
const cta = () => p.evaluate(() => { const b = document.querySelector('#stFt [data-st="save"]'); return b ? b.textContent + (b.disabled ? ':off' : ':on') : ''; });
|
|
95
|
+
|
|
96
|
+
/* O: New report opens the Studio in Report mode */
|
|
97
|
+
await p.click('#repNew');
|
|
98
|
+
await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#oMain .stu')));
|
|
99
|
+
ok('O1 New report opens the Studio in Report mode, with the brief of the mockup', await mode() === 'Report' && await chipv('title') === bname + ' weekly report' && await chipv('purpose') === 'Not set'
|
|
100
|
+
&& await chipv('aud') === 'The team' && await chipv('out') === 'Google Doc' && await chipv('sched') === 'Weekly, Mondays at 09:00' && await chipv('from') === 'Your work' && await chipv('secs') === '7', [await mode(), await chipv('title'), await chipv('sched')].join());
|
|
101
|
+
ok('O2 the preview lists the frozen frame, headline first and sources last', (await secs()).join() === 'Headline,Timeline,Initiatives,New since last report,Decided this cycle,Needs your call,Sources', (await secs()).join());
|
|
102
|
+
|
|
103
|
+
/* K and C: the checks and the conversation */
|
|
104
|
+
ok('K1 without what it answers, 4 of 5 checks pass', await checksTxt() === '4 of 5 checks pass', await checksTxt());
|
|
105
|
+
let a = await say('It answers: Are partners activating fast enough?');
|
|
106
|
+
ok('C1 "it answers" sets What it answers, and 5 of 5 checks pass', await chipv('purpose') === 'Are partners activating fast enough?' && await checksTxt() === '5 of 5 checks pass', a);
|
|
107
|
+
a = await say('for leadership, monthly');
|
|
108
|
+
ok('C2 one turn sets the audience and the schedule', await chipv('aud') === 'Leadership' && await chipv('sched') === 'Monthly on the 1st at 09:00', a);
|
|
109
|
+
ok('K2 leadership with a document fails "The format fits the audience"', await checksTxt() === '4 of 5 checks pass', await checksTxt());
|
|
110
|
+
await tap('#oMain [data-st="ck"]'); await sleep(100);
|
|
111
|
+
const fix = await p.evaluate(() => [...document.querySelectorAll('#stCk .sucl li.bad button')].map((b) => b.textContent));
|
|
112
|
+
ok('K3 the failing check offers its fix', fix.join() === 'Make it slides', fix.join());
|
|
113
|
+
await tap('#stCk .sucl li.bad button'); await sleep(150);
|
|
114
|
+
ok('K4 the fix makes it slides, and the checks pass', await chipv('out') === 'Google Slides' && await checksTxt() === '5 of 5 checks pass');
|
|
115
|
+
a = await say('leave out the timeline');
|
|
116
|
+
ok('C3 a request to change a section of a new report changes nothing and says why', /^I changed nothing: a new report always has the same sections/.test(a) && (await secs()).length === 7, a);
|
|
117
|
+
a = await say('call it Partner review, every two weeks on Thursday');
|
|
118
|
+
ok('C4 one turn names it and sets every other Thursday', await chipv('title') === 'Partner review' && await chipv('sched') === 'Every other Thursday at 09:00', a);
|
|
119
|
+
await tap('#oMain [data-st="undo"]'); await sleep(150);
|
|
120
|
+
ok('U1 Undo steps back one turn', await chipv('title') === bname + ' weekly report' && await chipv('sched') === 'Monthly on the 1st at 09:00', await chipv('title'));
|
|
121
|
+
await say('call it Partner review');
|
|
122
|
+
await shot('report-new-1280');
|
|
123
|
+
ok('C5 no turn on a new report posted anything', posts.length === 0, posts.join());
|
|
124
|
+
|
|
125
|
+
/* B: the brief and its tray */
|
|
126
|
+
await tap('#oMain [data-st="chip|from"]'); await sleep(100);
|
|
127
|
+
const from = await p.evaluate(() => [...document.querySelectorAll('#stTr .sto b')].map((b) => b.textContent));
|
|
128
|
+
ok('B1 Draw from offers your work and the board\'s dashboard', from.join() === 'Your work,The board\'s dashboard', from.join());
|
|
129
|
+
await tap('#stTr [data-st="set|from|dash"]'); await sleep(100);
|
|
130
|
+
ok('B2 the board\'s dashboard has no fixed frame to list, and says what it draws', await chipv('from') === 'The board\'s dashboard' && (await secs()).length === 0 && /dashboard: each of its charts/.test(await p.evaluate(() => document.querySelector('#stPv').textContent)));
|
|
131
|
+
await tap('#oMain [data-st="chip|from"]'); await sleep(100); await tap('#stTr [data-st="set|from|work"]'); await sleep(100);
|
|
132
|
+
await tap('#oMain [data-st="chip|sched"]'); await sleep(100);
|
|
133
|
+
await tap('#stTr [data-st="set|cadence|weekly"]'); await sleep(100);
|
|
134
|
+
await tap('#oMain [data-st="chip|sched"]'); await sleep(100);
|
|
135
|
+
await tap('#stTr [data-st="set|day|Tue"]'); await sleep(100);
|
|
136
|
+
ok('B3 the Schedule tray sets weekly on a Tuesday', await chipv('sched') === 'Weekly, Tuesdays at 09:00', await chipv('sched'));
|
|
137
|
+
await tap('#oMain [data-st="chip|aud"]'); await sleep(100);
|
|
138
|
+
await p.fill('#stI', 'Leadership team'); await sleep(150);
|
|
139
|
+
ok('B4 the Audience field sets the audience as it is typed', await chipv('aud') === 'Leadership team');
|
|
140
|
+
await p.press('#stI', 'Enter'); await sleep(100);
|
|
141
|
+
|
|
142
|
+
/* S: set it up */
|
|
143
|
+
await tap('#oMain [data-st="save"]');
|
|
144
|
+
await until(() => p.evaluate(() => !document.querySelector('#dlg').classList.contains('on')));
|
|
145
|
+
const st0 = [...RS.fold(RS.readLines(RS.ledgerFile(dir))).setups.values()];
|
|
146
|
+
const su = st0[0] || {};
|
|
147
|
+
ok('S1 Set it up writes one setup with what the brief shows', st0.length === 1 && su.name === 'Partner review' && su.audience === 'Leadership team' && su.output === 'google-slides' && su.source === 'work'
|
|
148
|
+
&& su.schedule.cadence === 'weekly' && su.schedule.day === 'Tue' && su.purpose === 'Are partners activating fast enough?', JSON.stringify(su));
|
|
149
|
+
const toastT = await p.evaluate(() => (document.querySelector('#toast') || {}).textContent || '');
|
|
150
|
+
const draftRel = (/first draft is (\S+\.md)/.exec(toastT) || [])[1];
|
|
151
|
+
ok('S2 the answer says where the first draft is, and the file is there', !!draftRel && fs.existsSync(path.join(dir, draftRel)), toastT);
|
|
152
|
+
ok('S3 Set it up posted the setup route only', posts.join() === '/api/report-setups/setup', posts.join());
|
|
153
|
+
|
|
154
|
+
/* H: shape the set-up report */
|
|
155
|
+
await until(() => p.evaluate((id) => !!document.querySelector(`#repBody [data-setup="${id}"]`), su.id));
|
|
156
|
+
await p.click(`#repBody [data-setup="${su.id}"]`);
|
|
157
|
+
await until(() => p.evaluate(() => !!document.querySelector('#oMain [data-rx="studio"]')));
|
|
158
|
+
await tap('#oMain [data-rx="studio"]');
|
|
159
|
+
await until(() => p.evaluate(() => !!document.querySelector('#oMain .stu')) && chipv('ver').then((v) => v === 'None yet'));
|
|
160
|
+
ok('H1 Shape it in the Studio opens Report mode on the report, with no structure yet', await mode() === 'Report' && await chipv('facts') === 'Partner review' && await chipv('ver') === 'None yet' && (await secs()).length === 7, [await mode(), await chipv('facts'), (await secs()).join()].join(' | '));
|
|
161
|
+
await tap('#oMain [data-st="chip|secs"]'); await sleep(100);
|
|
162
|
+
ok('H2 with no structure, the sections cannot be left out by press, and the fixed ones say Always in', await p.evaluate(() => document.querySelectorAll('#stTr [data-st^="rsec|"]').length === 0 && [...document.querySelectorAll('#stTr .stlc small')].length === 3));
|
|
163
|
+
ok('K5 with no structure, "The version shown is saved" fails, and seven sections are long for a leadership audience', await checksTxt() === '3 of 5 checks pass' && await cta() === 'Use this structure:off', await checksTxt() + ' ' + await cta());
|
|
164
|
+
await p.fill('#stIn', 'Shape it for the partner review'); await p.press('#stIn', 'Enter');
|
|
165
|
+
ok('H3 a turn shows PMOS working', await until(() => lastA().then((x) => x === 'PMOS is working on it.'), 3000));
|
|
166
|
+
await until(() => chipv('ver').then((v) => v === 'S1, not saved'), 30000);
|
|
167
|
+
a = await lastA();
|
|
168
|
+
ok('H4 the job\'s answer replaces the working line, and S1 is shown', /^Built the first version/.test(a) && /Shown: S1, not saved yet\./.test(a) && (await secs()).join() === 'Headline,Activation,What changed,Needs your call,Sources', a + ' ' + (await secs()).join());
|
|
169
|
+
ok('H5 the turn posted report-structure/turn', posts.includes('/api/report-structure/turn'), posts.join());
|
|
170
|
+
await until(() => p.evaluate(() => !!document.querySelector('#stTr [data-st="rsec|changes"]')), 3000);
|
|
171
|
+
await tap('#stTr [data-st="rsec|changes"]');
|
|
172
|
+
await until(() => chipv('ver').then((v) => v === 'S2, not saved'));
|
|
173
|
+
ok('H6 Leave out makes the next version without the section', (await secs()).join() === 'Headline,Activation,Needs your call,Sources' && posts.includes('/api/report-structure/remove'), (await secs()).join());
|
|
174
|
+
await tap('#oMain [data-st="undo"]');
|
|
175
|
+
await until(() => chipv('ver').then((v) => v === 'S1, not saved'));
|
|
176
|
+
ok('U2 Undo on a set-up report goes back one version', (await secs()).length === 5 && posts.includes('/api/report-structure/revert'));
|
|
177
|
+
ok('K6 Leadership with five sections passes the length check; the unsaved version fails', await checksTxt() === '4 of 5 checks pass', await checksTxt());
|
|
178
|
+
await tap('#oMain [data-st="save"]');
|
|
179
|
+
await until(() => chipv('ver').then((v) => v === 'S1, saved'));
|
|
180
|
+
const sv = S.stateOf(dir, su.id).saved;
|
|
181
|
+
ok('H7 Use this structure saves the version shown, and is then not offered', sv && sv.n === 1 && await cta() === 'Use this structure:off' && await checksTxt() === '5 of 5 checks pass', JSON.stringify(sv) + ' ' + await cta());
|
|
182
|
+
|
|
183
|
+
await tap('#oMain [data-st="chip|secs"]'); await sleep(150); await shot('report-shape-1280'); await tap('#oMain [data-st="chip|secs"]');
|
|
184
|
+
/* L: the library */
|
|
185
|
+
await tap('#oMain [data-st="lib"]'); await sleep(100);
|
|
186
|
+
const lib = await p.evaluate(() => [...document.querySelectorAll('#stLb .stli')].map((b) => b.querySelector('b').textContent + ':' + b.querySelector('em').textContent));
|
|
187
|
+
ok('L1 the library lists the set-up reports', lib.join() === 'Partner review:Open', lib.join());
|
|
188
|
+
await tap('#oMain [data-st="lib"]');
|
|
189
|
+
|
|
190
|
+
/* P: the writes */
|
|
191
|
+
const allowed = new Set(['/api/report-setups/setup', '/api/report-setups/from-dashboard', '/api/report-structure/turn', '/api/report-structure/remove', '/api/report-structure/revert', '/api/report-structure/accept']);
|
|
192
|
+
ok('P1 every POST is one of the existing report routes', posts.length > 0 && posts.every((x) => allowed.has(x)), posts.join());
|
|
193
|
+
|
|
194
|
+
/* F: floors */
|
|
195
|
+
await p.setViewportSize({ width: 390, height: 844 }); await sleep(300);
|
|
196
|
+
const wide = await p.evaluate(() => { const d = document.querySelector('#oMain'); return [document.documentElement.scrollWidth - innerWidth, d ? d.scrollWidth - d.clientWidth : 0]; });
|
|
197
|
+
await shot('report-shape-390');
|
|
198
|
+
ok('F1 at 390 wide, Report mode does not scroll sideways', wide[0] <= 0 && wide[1] <= 1, wide.join());
|
|
199
|
+
const small = await p.evaluate(() => [...document.querySelectorAll('#oMain .stmd button, #oMain .suc, #stFt button')].filter((b) => b.offsetParent && b.getBoundingClientRect().height < 44).map((b) => b.textContent));
|
|
200
|
+
ok('F2 the mode switch, the chips and the footer are 44 px tall', small.length === 0, small.join());
|
|
201
|
+
ok('F3 no script error', errs.length === 0, errs.join(' | '));
|
|
202
|
+
return finish();
|
|
203
|
+
})().catch((e) => { console.error(e); finish(1); });
|