create-pmos 0.388.0 → 0.389.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.
Files changed (35) hide show
  1. package/package.json +13 -13
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/briefing-premium-insights-test.js +16 -21
  7. package/workspace/changelog.json +12 -0
  8. package/workspace/guide/briefing-premium.md +19 -9
  9. package/workspace/lib/briefing-premium-agent.js +3 -0
  10. package/workspace/lib/report-chat.js +37 -0
  11. package/workspace/package-lock.json +2 -2
  12. package/workspace/package.json +1 -1
  13. package/workspace/premium-chat-chart-tab-test.js +150 -0
  14. package/workspace/premium-chat-report-tab-test.js +127 -0
  15. package/workspace/public/pm/goal-chat.js +2 -1
  16. package/workspace/public/pm/premium-chart-draw.js +58 -0
  17. package/workspace/public/pm/premium-chart-tab.js +157 -0
  18. package/workspace/public/pm/premium-chat.js +8 -2
  19. package/workspace/public/pm/premium-insights.js +17 -79
  20. package/workspace/public/pm/premium-report-tab.js +233 -0
  21. package/workspace/public/pm/premium-shell.js +35 -3
  22. package/workspace/public/pm/premium-vw-report.css +60 -0
  23. package/workspace/public/pm/premium.css +1 -120
  24. package/workspace/public/pm/report-chat.js +89 -0
  25. package/workspace/test-lists/premium-chat-chart-tab.json +12 -0
  26. package/workspace/test-lists/premium-chat-report-tab.json +12 -0
  27. package/workspace/premium-studio-chart-test.js +0 -193
  28. package/workspace/premium-studio-report-test.js +0 -277
  29. package/workspace/premium-studio-test.js +0 -185
  30. package/workspace/public/pm/premium-studio-design.js +0 -298
  31. package/workspace/public/pm/premium-studio-report.js +0 -291
  32. package/workspace/public/pm/premium-studio.js +0 -453
  33. package/workspace/test-lists/premium-studio-chart.json +0 -13
  34. package/workspace/test-lists/premium-studio-report.json +0 -9
  35. package/workspace/test-lists/premium-studio.json +0 -9
@@ -0,0 +1,89 @@
1
+ /* report-chat — the page's half of reports, charts and dashboards from chat (initiative premium-reports-from-chat, slices B and C; PRD R1–R4, C1–C3).
2
+ * Pure: no DOM, so Node tests it. Claude ends an answer about a report, a chart or a dashboard with a fenced `pmos-report` JSON block
3
+ * (lib/report-chat.js writes the rule into the message). This module splits the block off the words, checks its shape, and draws the chip under the
4
+ * answer that opens the Report or Chart tab. */
5
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
6
+ const ID_RE = /^[a-z0-9][a-z0-9-]{0,62}$/;
7
+ const REF_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,119}$/; // a KR metric id, a saved chart id (pc-…) or a dashboard id (lib/premium-charts.js ID_RE)
8
+ const FORMS = ['line', 'bars', 'number', 'meter'];
9
+ const OUTPUTS = ['google-doc', 'google-slides', 'google-sheets', 'confluence', 'pdf'];
10
+ const CADENCES = ['daily', 'weekly', 'bi-weekly', 'monthly'];
11
+ const DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
12
+ const clip = (s, n) => { const t = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1) + '…' : t; };
13
+
14
+ /** A schedule as the routes take it, 'off', or null (none said, or not a schedule). */
15
+ export function cleanSchedule(x) {
16
+ if (x === 'off' || (x && x.cadence === 'off')) return 'off';
17
+ if (!x || typeof x !== 'object' || !CADENCES.includes(x.cadence)) return null;
18
+ const out = { cadence: x.cadence, time: /^\d{1,2}:\d{2}$/.test(String(x.time || '')) ? String(x.time) : '09:00' };
19
+ if (x.cadence === 'weekly' || x.cadence === 'bi-weekly') out.day = DAYS.includes(x.day) ? x.day : 'Mon';
20
+ if (x.cadence === 'monthly') out.dayOfMonth = Number.isInteger(+x.dayOfMonth) && +x.dayOfMonth >= 1 && +x.dayOfMonth <= 28 ? +x.dayOfMonth : 1;
21
+ return out;
22
+ }
23
+
24
+ /** A chart as the premium-charts route takes it, or null without a measure. */
25
+ function cleanChart(p) {
26
+ if (!p || typeof p !== 'object' || !REF_RE.test(String(p.measure || ''))) return null;
27
+ const tg = p.target === null || p.target === undefined || p.target === '' || !Number.isFinite(+p.target) ? null : +p.target;
28
+ const rg = Number.isInteger(+p.range) && +p.range >= 2 && +p.range <= 500 ? +p.range : null;
29
+ return { measure: p.measure, title: clip(p.title, 60), question: clip(p.question, 100), form: FORMS.includes(p.form) ? p.form : 'line', range: rg, target: tg,
30
+ better: p.better === 'lower' ? 'lower' : 'higher', note: clip(p.note, 200) };
31
+ }
32
+ /** A chart or a dashboard: { kind, id?, proposal? }. id names a saved one; proposal is what Claude proposes (new, or the change to that one). */
33
+ function cleanChartBlock(b) {
34
+ const id = typeof b.id === 'string' && REF_RE.test(b.id) ? b.id : null;
35
+ let proposal = null;
36
+ if (b.kind === 'chart') proposal = cleanChart(b.proposal);
37
+ else if (b.proposal && typeof b.proposal === 'object') {
38
+ const charts = (Array.isArray(b.proposal.charts) ? b.proposal.charts : []).map(String).filter((x) => REF_RE.test(x)).filter((x, i, a) => a.indexOf(x) === i).slice(0, 12);
39
+ if (clip(b.proposal.name, 60) && charts.length) proposal = { name: clip(b.proposal.name, 60), purpose: clip(b.proposal.purpose, 200), charts };
40
+ }
41
+ if (!id && !proposal) return null;
42
+ const out = { kind: b.kind }; if (id) out.id = id; if (proposal) out.proposal = proposal;
43
+ return out;
44
+ }
45
+
46
+ /** The block as the tab uses it, or null when it is not a block. Unknown keys are dropped; text is clipped. */
47
+ export function cleanBlock(b) {
48
+ if (b && typeof b === 'object' && (b.kind === 'chart' || b.kind === 'dashboard')) return cleanChartBlock(b);
49
+ if (!b || typeof b !== 'object' || b.kind !== 'report') return null;
50
+ if (typeof b.id === 'string' && ID_RE.test(b.id)) {
51
+ const out = { kind: 'report', id: b.id };
52
+ if (b.schedule !== undefined) { const s = cleanSchedule(b.schedule); if (s) out.schedule = s; }
53
+ for (const k of ['structure', 'design']) { const v = clip(b[k], 600); if (v) out[k] = v; }
54
+ return out;
55
+ }
56
+ const p = b.proposal && typeof b.proposal === 'object' ? b.proposal : null;
57
+ if (!p || !clip(p.name, 80)) return null;
58
+ return { kind: 'report', proposal: {
59
+ name: clip(p.name, 80), purpose: clip(p.purpose, 400), audience: clip(p.audience, 120) || 'The team',
60
+ output: OUTPUTS.includes(p.output) ? p.output : 'google-doc', schedule: cleanSchedule(p.schedule) === 'off' ? null : cleanSchedule(p.schedule),
61
+ sources: (Array.isArray(p.sources) ? p.sources : []).map((x) => clip(x, 160)).filter(Boolean).slice(0, 8),
62
+ } };
63
+ }
64
+
65
+ /** { text, block }: the words with the last `pmos-report` block taken out, and that block checked (null when there is none or it does not parse). */
66
+ export function splitReport(text) {
67
+ const t = String(text == null ? '' : text);
68
+ const re = /```pmos-report[^\n]*\n([\s\S]*?)```/g;
69
+ let m, last = null;
70
+ while ((m = re.exec(t))) last = m;
71
+ if (!last) return { text: t, block: null };
72
+ let block = null; try { block = cleanBlock(JSON.parse(last[1])); } catch { block = null; }
73
+ return { text: (t.slice(0, last.index) + t.slice(last.index + last[0].length)).trim(), block };
74
+ }
75
+
76
+ /** A stable key for a block, so the same answer opens the tab once. */
77
+ export const blockSig = (b) => (b ? JSON.stringify(b) : '');
78
+
79
+ /** The chip under Claude's answer: it opens the Report tab with this block. `i` is the message's index in the conversation. */
80
+ export function reportChipHtml(block, i) {
81
+ if (!block) return '';
82
+ const k = block.kind, P = block.proposal;
83
+ const name = k === 'report' ? (P ? P.name : block.id) : P ? (k === 'chart' ? P.title || P.measure : P.name) : block.id;
84
+ const noun = k === 'report' ? 'report' : k;
85
+ const what = k === 'report' && !P ? (block.schedule ? 'Schedule change' : block.structure || block.design ? 'Report change' : 'Report')
86
+ : P && !block.id ? 'New ' + noun : P ? noun[0].toUpperCase() + noun.slice(1) + ' change' : noun[0].toUpperCase() + noun.slice(1);
87
+ const tab = k === 'report' ? 'Report' : k === 'chart' ? 'Chart' : 'Dashboard';
88
+ return `<div class="ctxc"><button type="button" class="ctxchip lead" data-report-open="${i}"><span><b>${esc(name)}</b><em>${esc(what)} · View in the ${tab} tab</em></span></button></div>`;
89
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "_comment": "Initiative premium-reports-from-chat, slice C: charts and dashboards from any chat (the Chart and Dashboard tabs) and the Insight Studio removed, against the real server on a scratch repository's KR metric records.",
3
+ "modules": [
4
+ "premium-charts.test.js"
5
+ ],
6
+ "seconds": {
7
+ "premium-chat-chart-tab-test.js": 60
8
+ },
9
+ "panels": [
10
+ "premium-chat-chart-tab-test.js"
11
+ ]
12
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "_comment": "Initiative premium-reports-from-chat, slice B: reports from any chat. The block helpers (unit) and the Report tab beside a chat, against the real server on a scratch repository.",
3
+ "modules": [
4
+ "report-chat.test.js"
5
+ ],
6
+ "seconds": {
7
+ "premium-chat-report-tab-test.js": 60
8
+ },
9
+ "panels": [
10
+ "premium-chat-report-tab-test.js"
11
+ ]
12
+ }
@@ -1,193 +0,0 @@
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) => { if (sel === '#pdNew' || sel === '#repNew') await p.click('#listNew'); if (['#pdEdit', '#pcNew', '#pdPin', '#pdBack'].includes(sel) && await p.locator('#dashBar').isHidden()) await p.click('#dashMore'); 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('#hDash').textContent === 'Weekly' && !!document.querySelector('#repBody [data-d="all"]')));
140
- await p.$eval('#repBody [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 (async (pg, sel) => { if (await pg.locator('#dashBar').isHidden()) await pg.click('#dashMore'); await pg.click(sel); })(q, '#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); });