create-pmos 0.270.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/guide/briefing-premium.md +2 -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/public/pm/premium-insights.js +71 -12
- package/workspace/public/pm/premium-studio.js +224 -45
- package/workspace/public/pm/premium.css +31 -0
- package/workspace/test-lists/premium-studio-chart.json +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.271.0",
|
|
4
4
|
"description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
package/payload/KIT-VERSION
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Eval calibration log"
|
|
4
4
|
description: "Append-only record of every PM override of an evaluator verdict."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-10-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-18T13:12:06Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Health budgets"
|
|
4
4
|
description: "Closed registry of health-budget anchors (D59), edited only by the PM."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-10-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-18T13:12:06Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Discoveries and friction log"
|
|
4
4
|
description: "Append-only record of what runs discovered and where the process rubbed."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-10-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-18T13:12:06Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -203,6 +203,7 @@ Insights is the fourth place on the rail, at `/premium-insights.html`. It reads
|
|
|
203
203
|
- **Charts.** One chart for each KR metric that holds at least two readings. The line runs through the readings at their dates, so a month with no reading is a gap and not a zero. The dashed line is the metric's target. The chip is the record's own line status: on its line, behind it, or well behind it. Pressing a chart, or its Details link, opens the metric's record in the dialog with the read-only agent beside it.
|
|
204
204
|
- **Dashboards.** The switch lists All measures first, then your saved dashboards (the main one first, marked Main), then the pillars the metrics name. A saved dashboard draws its charts in the order you saved them. A chart whose record is gone, or that has fewer than two readings, is listed in its place with the reason and is not drawn.
|
|
205
205
|
- **Make or edit a dashboard.** **New dashboard**, or **Edit** on a saved one, opens the **Insight Studio**, a wide dialog. On the right, the brief shows the Name, Purpose, Charts and Main dashboard; press a chip to change it. **Library** lists the board's measures and saved dashboards to add. The preview draws the dashboard as the page will, and lists a measure with no series as not drawn. The checks (a name, a purpose, a chart, six or fewer, no repeat, a main dashboard on the board) say what fails, with a one-press fix. On the left you can say it instead: "add Partner activation", "remove …", "move … first", "call it …", "it is for …", "make it the main dashboard", "undo" or "start a new one". A turn changes the draft only. **Undo** steps back one change. **Save the dashboard** records it; **Remove the dashboard** asks once more and then removes it. In a chart's dialog, **On your dashboards** has a switch for each saved dashboard, which adds the chart to it or takes it off.
|
|
206
|
+
- **Make your own chart.** **New chart**, or **Edit** on one of your charts, opens the Insight Studio in **Chart** mode; the switch at the top moves between Chart and Dashboard, and each keeps its own draft. The brief shows the Question, Measure, Form (line, bars, number or meter), Range (all readings or the last few) and Target; **More** adds the Title, Better when, Note and Add to (a dashboard). The Studio suggests a form from the question and says why. The checks (a question, a target, enough readings, a form that fits the question, one scale) say what fails, with a one-press fix. You can say it instead: "show it as bars", "last 4 readings", "target 35", "lower is better", "call it …", "note: …", "add it to Weekly", or a question. A pie is declined, with the reason. **Save the chart** records it in the workspace's state folder, and adds it to the dashboard you named. Your charts are listed under **All measures**, and a dashboard can hold them beside the measures. **Remove the chart** asks once more; a dashboard that held it then says it was removed.
|
|
206
207
|
- **What stands out.** Up to three plain sentences taken from the series: behind its line for three readings in a row, behind and still moving away from the target, closing in, slipped, reached its target, or a large one-step move. There is no forecast and no cause.
|
|
207
208
|
- **No series recorded.** A KR metric with one reading or none is listed with the reason and is not drawn.
|
|
208
209
|
- **Ask PMOS to set up a report.** Type what the report is for and press **Ask**. A background run proposes a report and does nothing else. The request is listed as Working, then Ready to review. A ready request opens with its proposal: **Set it up**, **Change it** (say what to change; the run revises it), or **Cancel**.
|
|
@@ -210,4 +211,4 @@ Insights is the fourth place on the rail, at `/premium-insights.html`. It reads
|
|
|
210
211
|
- **Set up.** Your recurring reports, with their schedule and next draft. A report opens with **Draft it now** (for a report drawn from your work) and **Pause** or **Resume**.
|
|
211
212
|
- **Documents.** The report files of the workspace, with cadence, slot and whether each is a draft or issued. Pressing one opens the console's Reports tab, where it is read, edited or issued. Nothing is sent from this page.
|
|
212
213
|
|
|
213
|
-
Not built: the Insight Studio's
|
|
214
|
+
Not built: the Insight Studio's Report mode, a second measure next to a chart, bar highlights, the report deck, present and print, tile sizes and free layout, the finder's settings, run-based charts such as corrections per 100 runs (they belong to the Board's Metrics card), and any measure no record holds. The console's own dashboards are separate and unchanged. KR metric records belong to a workspace, so every board of a workspace shows the same charts.
|
|
@@ -69,6 +69,22 @@ function chartOf(o) {
|
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/** A chart the PM saved in the Insight Studio (premium-studio-chart C2): its measure's readings, the latest `range` of them, against the saved target.
|
|
73
|
+
* null when the measure is gone or has fewer than two readings in range. Every value is still a reading of the record. */
|
|
74
|
+
function mineOf(m, outcomes) {
|
|
75
|
+
const o = outcomes.find((x) => x.id === m.measure);
|
|
76
|
+
if (!o) return null;
|
|
77
|
+
const rs = (o.readings || []).filter((x) => x && fin(x.v) && isoDay(x.at) !== null);
|
|
78
|
+
const c = chartOf(Object.assign({}, o, { readings: m.range ? rs.slice(-m.range) : rs, target: m.target }));
|
|
79
|
+
if (!c) return null;
|
|
80
|
+
const dir = m.better === 'lower' ? -1 : 1, good = c.step ? c.step * dir > 0 : null;
|
|
81
|
+
return Object.assign(c, {
|
|
82
|
+
key: 'mine:' + m.id, id: m.id, measure: o.id, measureTitle: clip(o.name, 120), title: clip(m.title, 60), question: m.question || '', form: m.form, range: m.range,
|
|
83
|
+
better: m.better, note: m.note || '', mine: true, dir, good, all: rs.length,
|
|
84
|
+
sub: [clip(o.name, 120), (m.range ? 'last ' + c.pts.length : c.pts.length) + ' readings'].join(' · '),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
72
88
|
/** Up to three plain sentences about what stands out, from the series alone. No forecast and no cause. */
|
|
73
89
|
function findingsOf(charts) {
|
|
74
90
|
const out = [];
|
|
@@ -103,12 +119,14 @@ function reportRows(reports) {
|
|
|
103
119
|
|
|
104
120
|
/** The board's saved dashboards (briefing-premium-reports D3/D5), main first as the ledger folds them. A chart id that has no record, or no series, stays
|
|
105
121
|
* in `charts` and is listed in `gone` with the reason, so the page can say so in its place. `checks` are the two advisory checks, never a refusal. */
|
|
106
|
-
function savedOf(saved, outcomes, charts) {
|
|
122
|
+
function savedOf(saved, outcomes, charts, mine) {
|
|
107
123
|
return (saved || []).map((d) => {
|
|
108
124
|
const ids = Array.isArray(d.charts) ? d.charts : [];
|
|
109
125
|
const L = ids.map((id) => charts.find((c) => c.id === id)).filter(Boolean);
|
|
110
126
|
const gone = ids.filter((id) => !charts.some((c) => c.id === id)).map((id) => {
|
|
111
|
-
const o = outcomes.find((x) => x.id === id);
|
|
127
|
+
const o = outcomes.find((x) => x.id === id), m = (mine || []).find((x) => x.id === id);
|
|
128
|
+
if (m) return { id, title: clip(m.title, 60), why: 'Its measure has fewer than two readings in its range, so it has no chart.' };
|
|
129
|
+
if (/^pc-/.test(id)) return { id, title: id, why: 'This saved chart was removed.' };
|
|
112
130
|
return { id, title: o ? clip(o.name, 120) : id, why: o ? 'This measure has fewer than two readings, so it has no chart.' : 'No KR metric record is called ' + id + ' any more.' };
|
|
113
131
|
});
|
|
114
132
|
const checks = [];
|
|
@@ -155,6 +173,9 @@ function build(facts) {
|
|
|
155
173
|
const f = facts || {};
|
|
156
174
|
const outcomes = f.outcomes || [], missing = (f.missing || []).slice();
|
|
157
175
|
const charts = outcomes.map(chartOf).filter(Boolean);
|
|
176
|
+
const mineAll = f.mine || [], mine = mineAll.map((m) => mineOf(m, outcomes)).filter(Boolean);
|
|
177
|
+
const mineGone = mineAll.filter((m) => !mine.some((c) => c.id === m.id)).map((m) => ({ id: m.id, title: clip(m.title, 60), measure: m.measure,
|
|
178
|
+
why: outcomes.some((o) => o.id === m.measure) ? 'Its measure has fewer than two readings in its range, so it has no chart.' : 'No KR metric record is called ' + m.measure + ' any more.' }));
|
|
158
179
|
const noSeries = outcomes.filter((o) => !chartOf(o)).map((o) => ({
|
|
159
180
|
key: 'nos:' + o.id, title: clip(o.name, 120), pillar: o.pillar || '',
|
|
160
181
|
why: (o.readings || []).length === 1 ? 'Only one reading is recorded.' : (o.readings || []).length === 0 ? (o.reason && /reading/i.test(o.reason) ? o.reason : 'No reading is recorded yet.') : 'Its readings do not form a series.',
|
|
@@ -162,7 +183,7 @@ function build(facts) {
|
|
|
162
183
|
const pillars = [...new Set(charts.map((c) => c.pillar).filter(Boolean))];
|
|
163
184
|
const offOf = (L) => L.filter((c) => c.off).length;
|
|
164
185
|
const dash = (id, name, L) => ({ id, name, keys: L.map((c) => c.key), total: L.length, off: offOf(L), chip: !L.length ? '' : offOf(L) ? offOf(L) + ' off its line' : 'On their lines' });
|
|
165
|
-
const dashboards = [dash('all', 'All measures', charts)].concat(savedOf(f.saved, outcomes, charts), pillars.length > 1 ? pillars.map((p) => dash('p:' + p, p, charts.filter((c) => c.pillar === p))) : []);
|
|
186
|
+
const dashboards = [dash('all', 'All measures', charts)].concat(savedOf(f.saved, outcomes, charts.concat(mine), mineAll), pillars.length > 1 ? pillars.map((p) => dash('p:' + p, p, charts.filter((c) => c.pillar === p))) : []);
|
|
166
187
|
const findings = findingsOf(charts);
|
|
167
188
|
const rep = reportRows(f.reports);
|
|
168
189
|
const off = offOf(charts);
|
|
@@ -170,7 +191,7 @@ function build(facts) {
|
|
|
170
191
|
const model = {
|
|
171
192
|
header: { text: (f.pending ? 'Reading the records · ' : '') + 'Real data' + (missing.length ? ' · not read: ' + missing.join(', ') : '') },
|
|
172
193
|
board: { ws: board.ws || null, id: board.id || null, name: board.name || 'Insights', switcher: (f.boards || []).map((b) => ({ ws: b.ws, id: b.id, name: b.name })) },
|
|
173
|
-
charts, noSeries, dashboards, rows: charts,
|
|
194
|
+
charts, mine, mineGone, mineSaved: mineAll, noSeries, dashboards, rows: charts,
|
|
174
195
|
findings: findings.length ? findings : [{ kind: 'calm', key: null, text: charts.length ? (charts.some((c) => c.target !== null) ? 'Nothing stands out. No measure moved much, and none is far behind its line.' : 'Nothing stands out. No measure here has a target, so the series can only be described.') : '' }],
|
|
175
196
|
calm: !findings.length && charts.length > 0,
|
|
176
197
|
reports: Object.assign({ rows: rep, ok: f.reportsOk !== false, counts: { draft: rep.filter((r) => r.state === 'draft').length, issued: rep.filter((r) => r.state === 'issued').length }, missing: f.reportsOk === false }, setupsOf(f.setups, f.now)),
|
|
@@ -183,4 +204,4 @@ function build(facts) {
|
|
|
183
204
|
return model;
|
|
184
205
|
}
|
|
185
206
|
|
|
186
|
-
module.exports = { build, peekModel, chartOf, findingsOf, shortDate, num };
|
|
207
|
+
module.exports = { build, peekModel, chartOf, mineOf, findingsOf, shortDate, num };
|
|
@@ -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); });
|