@qameleon-ai/qameleon 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +6 -2
- package/docs/QUICKSTART.md +2 -2
- package/docs/errors.md +16 -0
- package/docs/setup.md +13 -1
- package/package.json +1 -1
- package/src/board/file/index.js +3 -2
- package/src/board/retry.js +2 -1
- package/src/board/throttle.js +7 -1
- package/src/cli/commands/console.js +4 -1
- package/src/cli/commands/setup.js +2 -1
- package/src/cli/commands/shortcut.js +54 -0
- package/src/config/load.js +2 -1
- package/src/config/validate.js +12 -1
- package/src/console/actions.js +12 -2
- package/src/console/connections.js +7 -3
- package/src/console/jobs.js +81 -0
- package/src/console/page.js +200 -34
- package/src/console/view.js +7 -2
- package/src/import/breaker.js +2 -1
- package/src/import/cases.js +2 -1
- package/src/json-text.js +5 -0
- package/src/licence/email-draft.js +3 -3
- package/src/review/sessions.js +112 -23
- package/src/review/steps.js +2 -2
- package/src/run/checks.js +1 -1
- package/src/setup/answers.js +4 -1
- package/src/setup/page.js +1 -1
- package/src/setup/run.js +2 -2
- package/src/setup/steps/build.js +2 -2
- package/src/setup/steps/loop.js +2 -2
- package/src/setup/workflows.js +17 -2
- package/src/shortcut.js +109 -0
- package/templates/github-actions/qameleon-morning.yml +1 -1
- package/templates/github-actions/qameleon-post-deploy.yml +1 -1
- package/templates/github-actions/qameleon-publish.yml +1 -1
package/src/console/page.js
CHANGED
|
@@ -24,7 +24,9 @@ table{border-collapse:collapse;width:100%;margin:.5rem 0}
|
|
|
24
24
|
th,td{border:1px solid var(--line);padding:.35rem .6rem;text-align:left;vertical-align:top}
|
|
25
25
|
th{background:var(--panel)}
|
|
26
26
|
.muted{color:var(--muted)}
|
|
27
|
-
.pill{display:inline-block;padding
|
|
27
|
+
.pill{display:inline-block;padding:.05rem .6rem;border-radius:1rem;border:1px solid currentColor;font-size:.95rem;font-weight:700;white-space:nowrap}
|
|
28
|
+
td.key{white-space:nowrap}
|
|
29
|
+
main a{color:var(--accent)}
|
|
28
30
|
.green,.PASS{color:var(--green)}.amber,.NOT-VERIFIED{color:var(--amber)}.red,.FAIL,.HELD{color:var(--red)}
|
|
29
31
|
.banner{padding:.6rem .9rem;border:1px solid var(--red);border-radius:.4rem;color:var(--red);margin:.5rem 0}
|
|
30
32
|
.stats{display:flex;gap:.75rem;flex-wrap:wrap;margin:.5rem 0}
|
|
@@ -40,7 +42,17 @@ input[type=text]{font:inherit;padding:.25rem .5rem;border:1px solid var(--line);
|
|
|
40
42
|
.note div{padding:.5rem .8rem;border:1px solid var(--green);color:var(--green);border-radius:.4rem}
|
|
41
43
|
.note div.bad{border-color:var(--red);color:var(--red)}
|
|
42
44
|
.row{display:flex;gap:.5rem;align-items:center;flex-wrap:wrap;margin:.5rem 0}
|
|
45
|
+
.draft{border:1px solid var(--line);border-radius:.4rem;padding:.4rem .9rem;margin:.4rem 0;overflow-wrap:anywhere}
|
|
46
|
+
.draft h3{font-size:1.1rem;margin:.9rem 0 .4rem}.draft h4{font-size:1rem;margin:.8rem 0 .3rem}
|
|
47
|
+
.draft .lead{font-size:1.05rem}
|
|
48
|
+
.draft blockquote{margin:.4rem 0;padding:.3rem .7rem;border-left:3px solid var(--line);color:var(--muted);white-space:pre-wrap}
|
|
49
|
+
.draft td .pill{white-space:nowrap}
|
|
50
|
+
details{margin:.4rem 0}
|
|
43
51
|
.draft-text{white-space:pre-wrap;overflow-wrap:anywhere;max-height:24rem;overflow:auto;padding:.5rem .7rem;border:1px solid var(--line);border-radius:.4rem}
|
|
52
|
+
.needs{font-size:1.2rem;font-weight:600;margin:.5rem 0;display:flex;gap:.75rem;align-items:center;flex-wrap:wrap}
|
|
53
|
+
.needs a{font-size:1rem;font-weight:600;padding:.4rem .9rem;border:1px solid var(--accent);border-radius:.4rem;color:var(--accent);text-decoration:none}
|
|
54
|
+
.runs{border:1px solid var(--line);background:var(--panel);border-radius:.4rem;padding:.6rem .8rem;margin:.75rem 0}
|
|
55
|
+
.runs button{font-size:1.05rem;padding:.45rem .9rem}
|
|
44
56
|
.preview{margin-top:.4rem;padding:.4rem .6rem;border:1px dashed var(--line);border-radius:.4rem}
|
|
45
57
|
code{background:var(--panel);padding:.1rem .35rem;border-radius:.3rem}
|
|
46
58
|
</style></head>
|
|
@@ -63,12 +75,40 @@ function el(tag, props) {
|
|
|
63
75
|
return node;
|
|
64
76
|
}
|
|
65
77
|
function pill(text) { return el('span', { 'class': 'pill ' + String(text).replace(/ /g, '-') }, text); }
|
|
66
|
-
// The server sends every time already in the configured zone
|
|
67
|
-
|
|
78
|
+
// The server sends every time already in the configured zone (2026-11-24 13:58 GMT); the browser's own zone is never used.
|
|
79
|
+
// Shown the way a person says it (bug 106): Tue 24 Nov, 13:58. The year only when it is not this year.
|
|
80
|
+
var DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
81
|
+
var LONG_DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
82
|
+
var MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
83
|
+
var LONG_MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
84
|
+
function dateParts(shown) {
|
|
85
|
+
var m = /^(\\d{4})-(\\d{2})-(\\d{2})(?: (\\d{2}):(\\d{2})(?::\\d{2})?(?: \\S+)?)?$/.exec(String(shown || ''));
|
|
86
|
+
if (!m) return null;
|
|
87
|
+
var y = Number(m[1]), mo = Number(m[2]) - 1, d = Number(m[3]);
|
|
88
|
+
return { y: y, mo: mo, d: d, wd: new Date(Date.UTC(y, mo, d)).getUTCDay(), time: m[4] ? m[4] + ':' + m[5] : '', thisYear: y === new Date().getFullYear() };
|
|
89
|
+
}
|
|
90
|
+
function when(shown) {
|
|
91
|
+
var p = dateParts(shown);
|
|
92
|
+
if (!p) return shown || '';
|
|
93
|
+
return DAYS[p.wd] + ' ' + p.d + ' ' + MONTHS[p.mo] + (p.thisYear ? '' : ' ' + p.y) + (p.time ? ', ' + p.time : '');
|
|
94
|
+
}
|
|
95
|
+
function longDate(shown) { var p = dateParts(shown); return p ? LONG_DAYS[p.wd] + ' ' + p.d + ' ' + LONG_MONTHS[p.mo] + ' ' + p.y : String(shown || ''); }
|
|
68
96
|
function table(head, rows) {
|
|
69
97
|
if (rows.length === 0) return null;
|
|
70
|
-
|
|
98
|
+
var keyed = /^(Ticket|Draft)$/.test(head[0]);
|
|
99
|
+
return el('table', {}, el('thead', {}, el('tr', {}, head.map(function (h) { return el('th', {}, h); }))), el('tbody', {}, rows.map(function (r) { return el('tr', {}, r.map(function (c, i) { return el('td', keyed && i === 0 ? { 'class': 'key' } : {}, c); })); })));
|
|
71
100
|
}
|
|
101
|
+
// What a review's state means, in words (bug 105): the bare word 'pending' told nobody what to do.
|
|
102
|
+
var REVIEW_STATE = { pending: 'waiting for your approval', changed: 'changed since it was approved: read it again', approved: 'approved, not posted yet' };
|
|
103
|
+
// A ticket link from the server is only used when it is a plain https address.
|
|
104
|
+
function isTicketLink(v) { return typeof v === 'string' && /^https:\\/\\/[^\\s"<>]+$/.test(v); }
|
|
105
|
+
function plural(n, one, many) { return n + ' ' + (n === 1 ? one : many); }
|
|
106
|
+
// Plain words for a check that is not set up (bug 103): the config path goes in small print, not in the sentence.
|
|
107
|
+
function plainHeadline(text) {
|
|
108
|
+
var m = /^not configured \\(([^)]*)\\)$/.exec(String(text));
|
|
109
|
+
return m ? ['Not set up yet. Ask whoever set up QAmeleon to turn this check on.', el('div', { 'class': 'muted' }, 'Setting: ' + m[1])] : text;
|
|
110
|
+
}
|
|
111
|
+
var STATUS_MEANING = 'GREEN: every check that ran passed. AMBER: something could not be checked, so look at the morning report. RED: something failed.';
|
|
72
112
|
function empty(text) { return el('p', { 'class': 'muted' }, text); }
|
|
73
113
|
function stat(label, value) { return el('div', { 'class': 'stat' }, el('b', {}, value), label); }
|
|
74
114
|
function actionsFor(page, item) { return ACTIONS[page] ? ACTIONS[page](item) : null; }
|
|
@@ -94,31 +134,145 @@ function button(label, go, cls) {
|
|
|
94
134
|
return b;
|
|
95
135
|
}
|
|
96
136
|
function done(r, message) { if (!r.ok) { note(r.body.error || 'That did not work.', true); return false; } note(message(r.body), false); show(); return true; }
|
|
137
|
+
// The Run buttons (T-0321): start a dry-run review or morning run from the page, then show how it is going and how it ended.
|
|
138
|
+
// They post nothing, so they need no approver's name. One run at a time; the page asks for the status every two seconds.
|
|
139
|
+
var polling = null;
|
|
140
|
+
var panelPaint = function () {};
|
|
141
|
+
var lastStatus = null;
|
|
142
|
+
function poll() {
|
|
143
|
+
act('job').then(function (r) {
|
|
144
|
+
if (!r.ok) return;
|
|
145
|
+
lastStatus = r.body;
|
|
146
|
+
panelPaint(r.body);
|
|
147
|
+
if (r.body.running) { polling = setTimeout(poll, 2000); }
|
|
148
|
+
else if (polling !== null) { polling = null; show(); }
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function runPanel() {
|
|
152
|
+
var line = el('p', { role: 'status' });
|
|
153
|
+
var review = el('button', { type: 'button' }, 'Check my tickets now');
|
|
154
|
+
var morning = el('button', { type: 'button' }, 'Run the morning checks');
|
|
155
|
+
function paint(s) {
|
|
156
|
+
var busy = Boolean(s && s.running);
|
|
157
|
+
review.disabled = busy; morning.disabled = busy;
|
|
158
|
+
if (busy) { line.replaceChildren(s.running.label + '. Started ' + s.running.seconds + ' seconds ago. You can leave this page open.'); return; }
|
|
159
|
+
if (s && s.last) {
|
|
160
|
+
var l = s.last;
|
|
161
|
+
var what = l.kind === 'review' ? 'The ticket check' : 'The morning checks';
|
|
162
|
+
var more = l.page === 'waiting' ? el('a', { href: '#waiting' }, 'See what is waiting for you') : el('a', { href: '#morning' }, 'See the morning report');
|
|
163
|
+
line.replaceChildren(el('b', {}, l.ok ? what + ' finished.' : what + ' stopped with a problem.'), (l.ok ? l.summary : l.problems.concat(l.summary)).map(function (t) { return el('div', {}, t); }), more);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
line.replaceChildren('Nothing is running. Each button runs a dry run: QAmeleon reads and checks, and nothing goes on your board until you approve it.');
|
|
167
|
+
}
|
|
168
|
+
panelPaint = paint;
|
|
169
|
+
function start(name) {
|
|
170
|
+
note('');
|
|
171
|
+
review.disabled = true; morning.disabled = true;
|
|
172
|
+
act(name).then(function (r) {
|
|
173
|
+
if (!r.ok) { note(r.body.error || 'That did not start.', true); review.disabled = false; morning.disabled = false; return; }
|
|
174
|
+
line.replaceChildren(r.body.label + '. Starting...');
|
|
175
|
+
clearTimeout(polling); polling = setTimeout(poll, 1000);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
review.addEventListener('click', function () { start('check-tickets'); });
|
|
179
|
+
morning.addEventListener('click', function () { start('run-morning'); });
|
|
180
|
+
paint(lastStatus);
|
|
181
|
+
act('job').then(function (r) { if (r.ok) { lastStatus = r.body; paint(r.body); if (r.body.running && polling === null) polling = setTimeout(poll, 2000); } });
|
|
182
|
+
return el('section', { 'class': 'runs', 'aria-label': 'Run QAmeleon' }, el('div', { 'class': 'row' }, review, morning), line);
|
|
183
|
+
}
|
|
184
|
+
// A draft as a person reads it (bug 98): the text the server sends is Markdown, so its headings, step table, lists,
|
|
185
|
+
// quotes, bold and code are drawn as such. Every piece goes in with textContent, so draft text can never become markup.
|
|
186
|
+
var VERDICT_WORDS = /^(PASS|FAIL|NOT VERIFIED|BLOCKED|NEEDS A PERSON|HELD|SKIPPED)$/;
|
|
187
|
+
function inline(text) {
|
|
188
|
+
return String(text).split(/(\\*\\*[^*]+\\*\\*|\`[^\`]+\`)/).filter(function (p) { return p !== ''; }).map(function (p) {
|
|
189
|
+
if (/^\\*\\*[^*]+\\*\\*$/.test(p)) return el('b', {}, p.slice(2, -2));
|
|
190
|
+
if (/^\`[^\`]+\`$/.test(p)) return el('code', {}, p.slice(1, -1));
|
|
191
|
+
return p;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function cells(line) { return line.trim().replace(/^\\|/, '').replace(/\\|$/, '').split('|').map(function (c) { return c.trim(); }); }
|
|
195
|
+
function draftView(text) {
|
|
196
|
+
var lines = String(text).split('\\n');
|
|
197
|
+
var out = [];
|
|
198
|
+
var i = 0;
|
|
199
|
+
while (i < lines.length) {
|
|
200
|
+
var line = lines[i];
|
|
201
|
+
var m;
|
|
202
|
+
if (line.trim() === '') { i += 1; continue; }
|
|
203
|
+
if ((m = /^Verdict: (.+)$/.exec(line))) { out.push(el('p', { 'class': 'lead' }, 'Verdict: ', pill(m[1]))); i += 1; continue; }
|
|
204
|
+
if ((m = /^(#{2,4}) (.+)$/.exec(line))) { out.push(el(m[1].length === 2 ? 'h3' : 'h4', {}, inline(m[2]))); i += 1; continue; }
|
|
205
|
+
if (/^(Would (comment on|create in|move)|Would not)/.test(line)) { out.push(el('h3', {}, inline(line))); i += 1; continue; }
|
|
206
|
+
if (/^\\s*\\|/.test(line)) {
|
|
207
|
+
var rows = [];
|
|
208
|
+
while (i < lines.length && /^\\s*\\|/.test(lines[i])) { if (!/^\\s*\\|[\\s:|-]+\\|\\s*$/.test(lines[i])) rows.push(cells(lines[i])); i += 1; }
|
|
209
|
+
var head = rows.shift() || [];
|
|
210
|
+
out.push(el('table', {}, el('thead', {}, el('tr', {}, head.map(function (h) { return el('th', {}, inline(h)); }))),
|
|
211
|
+
el('tbody', {}, rows.map(function (r) { return el('tr', {}, r.map(function (c) { return el('td', {}, VERDICT_WORDS.test(c) ? pill(c) : inline(c)); })); }))));
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (/^\\s*[-*] /.test(line)) {
|
|
215
|
+
var bullets = [];
|
|
216
|
+
while (i < lines.length && /^\\s*[-*] /.test(lines[i])) { bullets.push(el('li', {}, inline(lines[i].replace(/^\\s*[-*] /, '')))); i += 1; }
|
|
217
|
+
out.push(el('ul', {}, bullets));
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (/^\\s*\\d+\\. /.test(line)) {
|
|
221
|
+
var steps = [];
|
|
222
|
+
while (i < lines.length && /^\\s*\\d+\\. /.test(lines[i])) { steps.push(el('li', {}, inline(lines[i].replace(/^\\s*\\d+\\. /, '')))); i += 1; }
|
|
223
|
+
out.push(el('ol', {}, steps));
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (/^>\\s?/.test(line)) {
|
|
227
|
+
var quote = [];
|
|
228
|
+
while (i < lines.length && /^>\\s?/.test(lines[i])) { quote.push(lines[i].replace(/^>\\s?/, '')); i += 1; }
|
|
229
|
+
out.push(el('blockquote', {}, quote.join('\\n')));
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
var para = [];
|
|
233
|
+
while (i < lines.length && lines[i].trim() !== '' && !/^(\\s*\\||#{2,4} |\\s*[-*] |\\s*\\d+\\. |>|Verdict: |Would )/.test(lines[i])) { para.push(lines[i]); i += 1; }
|
|
234
|
+
if (para.length === 0) { para.push(line); i += 1; }
|
|
235
|
+
out.push(el('p', {}, inline(para.join(' '))));
|
|
236
|
+
}
|
|
237
|
+
return el('div', { 'class': 'draft', tabindex: '0', 'aria-label': 'The draft as it would be posted' }, out);
|
|
238
|
+
}
|
|
97
239
|
function items(list) { return el('ul', {}, list.map(function (i) { return el('li', {}, i.describe + (i.key ? ' -> ' + i.key : '') + (i.existing ? ' (already on the board)' : '')); })); }
|
|
98
240
|
|
|
99
241
|
var RENDER = {
|
|
100
242
|
today: function (d) {
|
|
101
243
|
var c = d.counts;
|
|
244
|
+
var n = d.needsYou || { toApprove: 0, toPublish: 0 };
|
|
245
|
+
var needs = n.toApprove > 0
|
|
246
|
+
? el('p', { 'class': 'needs' }, plural(n.toApprove, 'result is', 'results are') + ' waiting for you to read and approve.', el('a', { href: '#waiting' }, 'Go to Waiting for you'))
|
|
247
|
+
: n.toPublish > 0
|
|
248
|
+
? el('p', { 'class': 'needs' }, plural(n.toPublish, 'approved result is', 'approved results are') + ' ready to post to the board.', el('a', { href: '#waiting' }, 'Go to Waiting for you'))
|
|
249
|
+
: el('p', { 'class': 'needs' }, 'Nothing is waiting for you.');
|
|
102
250
|
return [
|
|
103
|
-
el('h2', {}, 'Today, ' + d.date
|
|
104
|
-
|
|
105
|
-
el('div', { 'class': '
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
el('
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
251
|
+
el('h2', {}, 'Today, ' + longDate(d.date)),
|
|
252
|
+
el('p', { 'class': 'muted' }, 'Times on these pages are ' + d.timeZone + ' time.'),
|
|
253
|
+
d.paused ? el('div', { 'class': 'banner', role: 'alert' }, 'QAmeleon is paused: nothing runs until a person presses Resume on the Controls page.') : null,
|
|
254
|
+
needs,
|
|
255
|
+
runPanel(),
|
|
256
|
+
el('div', { 'class': 'stats' }, stat('checks run', c.runs), stat('tickets checked', c.reviewed), stat('approved', c.approvals), stat('posted to the board', c.posted), stat('stopped by the safety guard', c.blocked), stat('safety stops', c.incidents)),
|
|
257
|
+
el('h2', {}, 'Checks run today'),
|
|
258
|
+
table(['Time', 'Run', 'Result', 'Held back for a person'], d.runs.map(function (r) { return [when(r.generatedAt), r.mode, pill(r.status.toUpperCase()), r.held]; })) || empty('No checks have run today.'),
|
|
259
|
+
d.runs.length ? el('p', { 'class': 'muted' }, STATUS_MEANING) : null,
|
|
260
|
+
el('h2', {}, 'Tickets checked today'),
|
|
261
|
+
d.reviewed ? el('p', {}, plural(d.reviewed.tickets, 'ticket', 'tickets') + ' checked at ' + when(d.reviewed.at) + ': ' + (Object.keys(d.reviewed.verdicts).map(function (k) { return d.reviewed.verdicts[k] + ' ' + k; }).join(', ') || 'no results') + '.') : empty('No tickets have been checked today.'),
|
|
262
|
+
el('h2', {}, 'What people did today'),
|
|
263
|
+
table(['Time', 'What happened', 'Ticket', 'By', 'Detail'], d.events.map(function (e) { return [when(e.at), e.event, e.draft || '', e.by || '', e.detail]; })) || empty('Nobody has approved, posted or paused anything today.')
|
|
112
264
|
];
|
|
113
265
|
},
|
|
114
266
|
morning: function (d) {
|
|
115
|
-
if (!d.latest) return [el('h2', {}, 'Morning report'), empty('No
|
|
267
|
+
if (!d.latest) return [el('h2', {}, 'Morning report'), runPanel(), empty('No morning report yet. Press Run the morning checks.')];
|
|
116
268
|
var l = d.latest;
|
|
117
269
|
return [
|
|
118
270
|
el('h2', {}, 'Latest run: ', pill(l.status.toUpperCase())),
|
|
271
|
+
runPanel(),
|
|
119
272
|
el('p', { 'class': 'muted' }, l.mode + ' at ' + when(l.generatedAt) + (l.product ? ' on ' + l.product : '') + ' (' + l.baseUrl + ')'),
|
|
120
273
|
l.paused ? el('div', { 'class': 'banner', role: 'alert' }, 'Everything was paused during this run.') : null,
|
|
121
|
-
table(['Check', '
|
|
274
|
+
table(['Check', 'Result', 'What it found'], l.checks.map(function (c) { return [c.title, pill(c.status.toUpperCase()), plainHeadline(c.headline)]; })),
|
|
275
|
+
el('p', { 'class': 'muted' }, STATUS_MEANING),
|
|
122
276
|
el('h2', {}, 'Findings'),
|
|
123
277
|
el('ul', {}, l.checks.reduce(function (all, c) { return all.concat(c.findings.map(function (f) { return el('li', {}, el('b', {}, f.severity), ': ', f.title, f.held ? [' ', pill('HELD')] : null, f.detail ? el('div', { 'class': 'muted' }, f.detail) : null); })); }, [])),
|
|
124
278
|
el('h2', {}, 'Last runs'),
|
|
@@ -128,17 +282,22 @@ var RENDER = {
|
|
|
128
282
|
queue: function (d) {
|
|
129
283
|
return [
|
|
130
284
|
el('h2', {}, 'Queue: ' + d.column),
|
|
131
|
-
|
|
132
|
-
var
|
|
133
|
-
return [
|
|
134
|
-
|
|
285
|
+
(function () {
|
|
286
|
+
var labels = d.tickets.some(function (t) { return t.labels.length > 0; });
|
|
287
|
+
return table(['Ticket', 'Title'].concat(labels ? ['Labels'] : [], ['Review']), d.tickets.map(function (t) {
|
|
288
|
+
var draft = t.draft ? [pill(t.draft.verdict || 'NO VERDICT'), ' ', t.draft.posted ? 'posted to the board' : (REVIEW_STATE[t.draft.state] || t.draft.state)] : el('span', { 'class': 'muted' }, 'not reviewed yet');
|
|
289
|
+
var key = isTicketLink(t.link) ? el('a', { href: t.link, target: '_blank', rel: 'noopener noreferrer', title: 'Open ' + t.key + ' on the board (new tab)' }, t.key) : t.key;
|
|
290
|
+
return [key, t.title].concat(labels ? [t.labels.join(', ')] : [], [[draft, t.held ? [' ', pill('HELD')] : null, actionsFor('queue', t)]]);
|
|
291
|
+
}));
|
|
292
|
+
})() || empty('No tickets in the ' + d.column + ' column.')
|
|
135
293
|
];
|
|
136
294
|
},
|
|
137
295
|
waiting: function (d) {
|
|
138
296
|
var g = d.guard;
|
|
139
297
|
return [
|
|
140
|
-
|
|
141
|
-
|
|
298
|
+
runPanel(),
|
|
299
|
+
el('h2', {}, 'Stopped by the safety guard'),
|
|
300
|
+
g.paused ? el('div', { 'class': 'banner', role: 'alert' }, 'Paused since ' + when(g.since) + (g.reason ? ': ' + g.reason : '') + '. When it is safe, press Resume on the Controls page.') : el('p', {}, 'Nothing is stopped.'),
|
|
142
301
|
table(['Time', 'Kind', 'Rule', 'Reason'], g.incidents.map(function (i) { return [when(i.at), i.kind, i.rule, i.reason]; })),
|
|
143
302
|
el('h2', {}, 'Drafts waiting for approval'),
|
|
144
303
|
table(['Draft', 'Title', 'Verdict', 'Why it waits'], d.drafts.map(function (x) {
|
|
@@ -155,18 +314,18 @@ var RENDER = {
|
|
|
155
314
|
controls: function (d) {
|
|
156
315
|
var why = el('input', { type: 'text', size: '40', 'aria-label': 'Reason for pausing', placeholder: 'Why are you pausing?' });
|
|
157
316
|
return [
|
|
158
|
-
el('h2', {}, '
|
|
159
|
-
d.paused ? el('div', { 'class': 'banner', role: 'alert' }, 'PAUSED since ' + when(d.since) + (d.reason ? ': ' + d.reason : '') + '. Nothing runs, is approved or is published until a person resumes.') : el('p', {}, 'Running. Nothing is
|
|
317
|
+
el('h2', {}, 'Stop everything'),
|
|
318
|
+
d.paused ? el('div', { 'class': 'banner', role: 'alert' }, 'PAUSED since ' + when(d.since) + (d.reason ? ': ' + d.reason : '') + '. Nothing runs, is approved or is published until a person resumes.') : el('p', {}, 'Running. Nothing is stopped.'),
|
|
160
319
|
d.paused
|
|
161
320
|
? el('div', { 'class': 'row' }, button('Resume', function () { return act('resume').then(function (r) { return done(r, function () { return 'Resumed.'; }); }); }))
|
|
162
321
|
: el('div', { 'class': 'row' }, why, button('Pause everything', function () {
|
|
163
322
|
if (why.value.trim() === '') { note('Say why you are pausing.', true); return Promise.resolve(); }
|
|
164
323
|
return act('pause', { reason: why.value }).then(function (r) { return done(r, function () { return 'Paused. Nothing will act until a person resumes.'; }); });
|
|
165
324
|
}, 'danger')),
|
|
166
|
-
el('p', { 'class': 'muted' }, '
|
|
167
|
-
el('h2', {}, '
|
|
168
|
-
table(['Time', 'Kind', 'Rule', 'Reason'], d.incidents.map(function (i) { return [when(i.at), i.kind, i.rule, i.reason]; })) || empty('No
|
|
169
|
-
el('h2', {}, '
|
|
325
|
+
el('p', { 'class': 'muted' }, 'Pausing stops QAmeleon from checking, approving or posting anything until a person presses Resume. Your name is recorded each time.'),
|
|
326
|
+
el('h2', {}, 'Safety stops'),
|
|
327
|
+
table(['Time', 'Kind', 'Rule', 'Reason'], d.incidents.map(function (i) { return [when(i.at), i.kind, i.rule, i.reason]; })) || empty('No safety stops.'),
|
|
328
|
+
el('h2', {}, 'Times it was resumed'),
|
|
170
329
|
table(['Time', 'By', 'Paused since', 'Reason'], d.resumes.map(function (r) { return [when(r.at), r.by, when(r.since), r.reason || '']; })) || empty('Never resumed.')
|
|
171
330
|
];
|
|
172
331
|
},
|
|
@@ -182,8 +341,8 @@ var RENDER = {
|
|
|
182
341
|
el('h2', {}, 'Report destinations'),
|
|
183
342
|
table(['Type', 'Secret', 'State'], d.destinations.reduce(function (all, x) { return all.concat(x.secrets.map(function (s) { return [x.type, s.name, pill(s.set ? 'SET' : 'NOT SET')]; })); }, [])) || empty('No report destination is set up.'),
|
|
184
343
|
d.nudge ? [el('h2', {}, 'Slack nudges'), secrets(d.nudge.secrets) || empty('No token secret named.')] : null,
|
|
185
|
-
el('h2', {}, 'Model
|
|
186
|
-
secrets(d.model.secrets),
|
|
344
|
+
el('h2', {}, 'Model'),
|
|
345
|
+
secrets(d.model.secrets) || empty(d.model.note || 'No model key is named.'),
|
|
187
346
|
el('h2', {}, 'Accounts'),
|
|
188
347
|
table(['Account', 'Role', 'Credential', 'Secret', 'State'], d.accounts.reduce(function (all, a) { return all.concat(a.secrets.map(function (s) { return [a.name, a.role, s.purpose, s.name, pill(s.set ? 'SET' : 'NOT SET')]; })); }, [])) || empty('No account is set up.')
|
|
189
348
|
];
|
|
@@ -219,12 +378,19 @@ ACTIONS.waiting = function (x) {
|
|
|
219
378
|
var read = button('Read the draft', function () {
|
|
220
379
|
return act('read', { id: x.id, hash: x.hash }).then(function (r) {
|
|
221
380
|
if (!r.ok) { note(r.body.error || 'That did not work.', true); return; }
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
381
|
+
// The Approve button sits above the draft and again below it (bug 98), both for the text shown here.
|
|
382
|
+
function approveButton() {
|
|
383
|
+
return button(label, function () {
|
|
384
|
+
return act('approve', { id: x.id, hash: x.hash, held: held }).then(function (a) {
|
|
385
|
+
return done(a, function (b) { return x.id + ': ' + (b.held ? 'held part' : 'approved') + ' by ' + b.by + ' (hash ' + b.hash + ')' + (b.needsHeldApproval ? '. It holds a critical or security finding and needs its own approval too.' : '.'); });
|
|
386
|
+
});
|
|
225
387
|
});
|
|
226
|
-
}
|
|
227
|
-
box.replaceChildren(
|
|
388
|
+
}
|
|
389
|
+
box.replaceChildren(
|
|
390
|
+
el('div', { 'class': 'row' }, approveButton(), el('span', { 'class': 'muted' }, 'Approving means this exact text may be posted. Read it first.')),
|
|
391
|
+
draftView(r.body.text),
|
|
392
|
+
el('details', {}, el('summary', {}, 'Show the plain text'), el('pre', { 'class': 'draft-text', tabindex: '0' }, r.body.text)),
|
|
393
|
+
el('div', { 'class': 'row' }, approveButton()));
|
|
228
394
|
});
|
|
229
395
|
});
|
|
230
396
|
return el('div', {}, el('div', { 'class': 'row' }, read), box);
|
package/src/console/view.js
CHANGED
|
@@ -18,6 +18,7 @@ import { REPORT_SCHEMA } from '../run/report.js';
|
|
|
18
18
|
import { assertReadable } from '../upgrade/version.js';
|
|
19
19
|
import { fit } from '../limits.js';
|
|
20
20
|
import { formatDate, instantOf, localiseDeep, partsOf, zoneOf } from '../time/zone.js';
|
|
21
|
+
import { ticketUrlPattern } from '../board/ticket-url.js';
|
|
21
22
|
|
|
22
23
|
export const PAGES = Object.freeze(['today', 'morning', 'queue', 'waiting', 'history', 'controls', 'connections', 'settings']);
|
|
23
24
|
|
|
@@ -157,7 +158,8 @@ export function createConsoleView({ board, config, root, now = () => new Date(),
|
|
|
157
158
|
|
|
158
159
|
async function today() {
|
|
159
160
|
const day = dayBounds(now(), zone);
|
|
160
|
-
const [reports, audit, index] = await Promise.all([readReports(reportsDir, SCANNED_REPORTS), store.readAudit(), readJson(path.join(store.dir, 'index.json'))]);
|
|
161
|
+
const [reports, audit, index, infos] = await Promise.all([readReports(reportsDir, SCANNED_REPORTS), store.readAudit(), readJson(path.join(store.dir, 'index.json')), inspectAll(store)]);
|
|
162
|
+
const open = infos.filter((i) => !i.posted);
|
|
161
163
|
const events = audit.filter((e) => within(e.at, day));
|
|
162
164
|
const runs = reports.filter((r) => within(r.report.generatedAt, day)).map(runSummary);
|
|
163
165
|
const reviewed = index && within(index.createdAt, day) ? { at: index.createdAt, model: index.model, tickets: index.tickets.length, verdicts: index.verdicts ?? {} } : null;
|
|
@@ -173,6 +175,8 @@ export function createConsoleView({ board, config, root, now = () => new Date(),
|
|
|
173
175
|
blocked: events.filter((e) => e.event === 'blocked').length,
|
|
174
176
|
incidents: guard.incidents.filter((i) => within(i.at, day)).length,
|
|
175
177
|
},
|
|
178
|
+
// What waits for a person (bug 102): drafts to read and approve, and approved drafts not yet posted.
|
|
179
|
+
needsYou: { toApprove: open.filter((i) => i.state !== 'approved').length, toPublish: open.filter((i) => i.state === 'approved').length },
|
|
176
180
|
runs, reviewed, events: events.map(eventRow).reverse(),
|
|
177
181
|
};
|
|
178
182
|
}
|
|
@@ -190,11 +194,12 @@ export function createConsoleView({ board, config, root, now = () => new Date(),
|
|
|
190
194
|
const column = config.board.qaColumn;
|
|
191
195
|
const tickets = await board.listColumn(column);
|
|
192
196
|
const infos = new Map((await inspectAll(store)).map((i) => [i.id, i]));
|
|
197
|
+
const ticketLink = ticketUrlPattern(config.board, env);
|
|
193
198
|
return {
|
|
194
199
|
column, holdLabel,
|
|
195
200
|
tickets: tickets.map((t) => {
|
|
196
201
|
const info = infos.get(t.key);
|
|
197
|
-
return { key: t.key, title: fit(t.title, TITLE_COLUMN), labels: t.labels, held: isHeldTicket(t), comments: t.comments.length, draft: info ? { verdict: verdictOf(info), state: info.state, posted: Boolean(info.posted) } : null };
|
|
202
|
+
return { key: t.key, link: ticketLink ? ticketLink.replace('{key}', encodeURIComponent(t.key)) : null, title: fit(t.title, TITLE_COLUMN), labels: t.labels, held: isHeldTicket(t), comments: t.comments.length, draft: info ? { verdict: verdictOf(info), state: info.state, posted: Boolean(info.posted) } : null };
|
|
198
203
|
}),
|
|
199
204
|
};
|
|
200
205
|
}
|
package/src/import/breaker.js
CHANGED
|
@@ -3,6 +3,7 @@ import { readFile, stat } from 'node:fs/promises';
|
|
|
3
3
|
import { locateJsonError } from '../config/json-position.js';
|
|
4
4
|
import { EXTRA_USERS, LENSES } from '../review/lenses.js';
|
|
5
5
|
import { SEVERITIES, casesOf, evidenceProblems, probeProblems, tagProblems } from './cases.js';
|
|
6
|
+
import { stripBom } from '../json-text.js';
|
|
6
7
|
|
|
7
8
|
// Reads a Breaker playbook bundle and maps each of its checks to a QAmeleon lens (docs/breaker-import.md).
|
|
8
9
|
// PROVISIONAL: qameleon-ai/fractal-breaker has not published its export yet, so the bundle below is this
|
|
@@ -233,7 +234,7 @@ export async function readBundle(file) {
|
|
|
233
234
|
}
|
|
234
235
|
let bundle;
|
|
235
236
|
try {
|
|
236
|
-
bundle = JSON.parse(text);
|
|
237
|
+
bundle = JSON.parse(stripBom(text));
|
|
237
238
|
} catch {
|
|
238
239
|
const at = locateJsonError(text) ?? { line: 1, column: 1, reason: 'the file could not be parsed', excerpt: { line: '', caret: '^' } };
|
|
239
240
|
throw new BundleError(`${file} is not valid JSON (a plain data file) at line ${at.line}, column ${at.column}: ${at.reason}`, { fix: `fix line ${at.line}, column ${at.column} of ${file}, or export the bundle from Breaker again`, excerpt: at.excerpt });
|
package/src/import/cases.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFile, stat } from 'node:fs/promises';
|
|
2
2
|
import { visibleText } from '../display-text.js';
|
|
3
|
+
import { stripBom } from '../json-text.js';
|
|
3
4
|
|
|
4
5
|
// The test cases an import makes, and how a saved import is read back (docs/breaker-import.md, "Test cases").
|
|
5
6
|
// PROVISIONAL like the bundle they come from. Pure data: nothing here reads the network or reaches a model.
|
|
@@ -147,7 +148,7 @@ export async function loadCases(file) {
|
|
|
147
148
|
}
|
|
148
149
|
let doc;
|
|
149
150
|
try {
|
|
150
|
-
doc = JSON.parse(raw);
|
|
151
|
+
doc = JSON.parse(stripBom(raw));
|
|
151
152
|
} catch {
|
|
152
153
|
throw new CasesError(`${file} is not valid JSON: run qameleon import <bundle> --out ${file} again`);
|
|
153
154
|
}
|
package/src/json-text.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Bug 95: a JSON file saved on Windows often starts with a byte-order mark (U+FEFF): Notepad and
|
|
2
|
+
// Windows PowerShell 5.1's Set-Content -Encoding utf8 both add one. JSON.parse refuses it, so every
|
|
3
|
+
// file a person writes by hand (the config, setup answers, file-board tickets, import bundles) is
|
|
4
|
+
// read through this first.
|
|
5
|
+
export const stripBom = (text) => (typeof text === 'string' && text.charCodeAt(0) === 0xfeff ? text.slice(1) : text);
|
|
@@ -14,9 +14,9 @@ import { SUPPORT_ADDRESS, BILLING_PORTAL_URL, withSupportAddress } from '../supp
|
|
|
14
14
|
* docs/renewal-runbook.md and docs/pilot/setup-checklist.md).
|
|
15
15
|
*/
|
|
16
16
|
export const INSTALL_STEP = [
|
|
17
|
-
'1. The code comes as a packed file, attached to this email. It is a single file with a name like qameleon-ai-qameleon-0.1.
|
|
18
|
-
'2. Open a terminal in that folder and install it. On Mac or Linux: npm install -g ./qameleon-ai-qameleon-0.1.
|
|
19
|
-
' On Windows PowerShell: npm install -g .\\qameleon-ai-qameleon-0.1.
|
|
17
|
+
'1. The code comes as a packed file, attached to this email. It is a single file with a name like qameleon-ai-qameleon-0.1.1.tgz. Save it in a folder you can find.',
|
|
18
|
+
'2. Open a terminal in that folder and install it. On Mac or Linux: npm install -g ./qameleon-ai-qameleon-0.1.1.tgz',
|
|
19
|
+
' On Windows PowerShell: npm install -g .\\qameleon-ai-qameleon-0.1.1.tgz',
|
|
20
20
|
' If your file has another name, use that name.',
|
|
21
21
|
'3. Run `qameleon --version`. It should print the version number.',
|
|
22
22
|
'4. You need Node 22 or newer.',
|
package/src/review/sessions.js
CHANGED
|
@@ -2,40 +2,129 @@
|
|
|
2
2
|
// guard, and only ever against the configured dev base URL. Credentials come from the
|
|
3
3
|
// environment variables the config's credentialRefs name; the config never holds a value.
|
|
4
4
|
import { withinBaseUrls } from '../guard/classify.js';
|
|
5
|
+
import { findSignInForm } from '../setup/look.js';
|
|
5
6
|
|
|
6
7
|
export const DEFAULT_SESSION_PATH = '/api/session';
|
|
7
8
|
|
|
9
|
+
const MAX_PAGE = 300_000;
|
|
10
|
+
const TIMEOUT_MS = 15_000;
|
|
11
|
+
|
|
12
|
+
// The name=value part of each Set-Cookie header, skipping cookies that are being cleared.
|
|
13
|
+
function cookiesOf(res) {
|
|
14
|
+
const out = [];
|
|
15
|
+
for (const raw of res.headers.getSetCookie?.() ?? []) {
|
|
16
|
+
const [pair, ...attrs] = raw.split(';').map((s) => s.trim());
|
|
17
|
+
if (!/^[^=\s;]+=[^;\s]+/.test(pair)) continue;
|
|
18
|
+
const cleared = attrs.some((a) => /^max-age=\s*(0|-\d+)$/i.test(a) || (/^expires=/i.test(a) && Date.parse(a.slice(8)) < Date.now()));
|
|
19
|
+
if (!cleared) out.push(pair);
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// A cookie jar for one sign-in: later cookies with the same name replace earlier ones.
|
|
25
|
+
function jar() {
|
|
26
|
+
const all = new Map();
|
|
27
|
+
return {
|
|
28
|
+
add(pairs) { for (const p of pairs) all.set(p.slice(0, p.indexOf('=')), p); },
|
|
29
|
+
header() { return [...all.values()].join('; '); },
|
|
30
|
+
values() { return [...all.values()].map((p) => p.slice(p.indexOf('=') + 1)).filter((v) => v.length >= 8); },
|
|
31
|
+
size() { return all.size; },
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const readText = async (res) => {
|
|
36
|
+
const text = await res.text().catch(() => '');
|
|
37
|
+
return text.length > MAX_PAGE ? text.slice(0, MAX_PAGE) : text;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* How the dev app signs in, from the config: `product.signIn.apiPath` (a sign-in that takes JSON,
|
|
42
|
+
* default /api/session) and `product.signIn.loginPath` (a sign-in page with a form, tried when the
|
|
43
|
+
* API path is not there). An explicit `path` (the review's --session-path) wins over the config.
|
|
44
|
+
*/
|
|
45
|
+
export function signInOf(config, path) {
|
|
46
|
+
const signIn = config?.product?.signIn ?? {};
|
|
47
|
+
return { apiPath: path ?? signIn.apiPath ?? DEFAULT_SESSION_PATH, loginPath: signIn.loginPath ?? null, apiConfigured: Boolean(path ?? signIn.apiPath) };
|
|
48
|
+
}
|
|
49
|
+
|
|
8
50
|
/**
|
|
9
|
-
* A session provider: `await provider(accountName)` -> { headers } or null
|
|
10
|
-
*
|
|
11
|
-
* (
|
|
12
|
-
*
|
|
13
|
-
*
|
|
51
|
+
* A session provider: `await provider(accountName)` -> { headers } or null. A sign-in that takes JSON
|
|
52
|
+
* (POST { email, password }) gives a bearer token when it answers { token }, or else the cookies it
|
|
53
|
+
* sets; when that path does not exist (404 or 405) and the config names a sign-in page, the page's form
|
|
54
|
+
* is posted and its cookies kept. provider.why(name) says in one sentence why an account has no session.
|
|
55
|
+
* Tokens and cookie values are listed in provider.secrets() so they can be removed from anything that is
|
|
56
|
+
* written, and handed to `onSecret` as they arrive (the debug log learns them there).
|
|
14
57
|
*/
|
|
15
|
-
export function createBearerSessions({ config, baseUrl, env = {}, path
|
|
16
|
-
|
|
17
|
-
const
|
|
58
|
+
export function createBearerSessions({ config, baseUrl, env = {}, path, fetch: doFetch = globalThis.fetch, onSecret }) {
|
|
59
|
+
const how = signInOf(config, path);
|
|
60
|
+
const inside = (p) => withinBaseUrls(new URL(p, baseUrl).href, config.product.baseUrls);
|
|
61
|
+
if (!inside(how.apiPath)) throw new Error('the sign-in address is outside the configured dev base URLs: add its address to product.baseUrls in the config');
|
|
62
|
+
if (how.loginPath && !inside(how.loginPath)) throw new Error('the sign-in page is outside the configured dev base URLs: product.signIn.loginPath must be a path on the dev app');
|
|
63
|
+
const origin = new URL(baseUrl).origin;
|
|
64
|
+
const secrets = [];
|
|
65
|
+
const reasons = new Map();
|
|
66
|
+
const learn = (values) => { for (const v of values) { secrets.push(v); onSecret?.(v); } };
|
|
67
|
+
const request = (url, init) => doFetch(url, { redirect: 'manual', signal: AbortSignal.timeout(TIMEOUT_MS), ...init });
|
|
68
|
+
|
|
69
|
+
async function viaApi(email, password) {
|
|
70
|
+
const res = await request(new URL(how.apiPath, baseUrl), { method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json' }, body: JSON.stringify({ email, password }) });
|
|
71
|
+
if (res.status === 404 || res.status === 405) { await res.body?.cancel?.(); return { missing: true }; }
|
|
72
|
+
if (res.status < 200 || res.status >= 300) {
|
|
73
|
+
await res.body?.cancel?.();
|
|
74
|
+
return { why: [400, 401, 403, 422].includes(res.status) ? `the app refused the email and password at ${how.apiPath} (${res.status})` : `the sign-in at ${how.apiPath} answered ${res.status}` };
|
|
75
|
+
}
|
|
76
|
+
const cookies = jar();
|
|
77
|
+
cookies.add(cookiesOf(res));
|
|
78
|
+
let token = null;
|
|
79
|
+
try { const body = JSON.parse(await readText(res)); if (typeof body?.token === 'string' && body.token !== '') token = body.token; } catch { /* a sign-in may answer with no JSON body: the cookies carry the session */ }
|
|
80
|
+
if (token) { learn([token]); return { headers: { authorization: `Bearer ${token}` } }; }
|
|
81
|
+
if (cookies.size() > 0) { learn(cookies.values()); return { headers: { cookie: cookies.header() } }; }
|
|
82
|
+
return { why: `the sign-in at ${how.apiPath} answered ${res.status} but gave no token and set no cookie` };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function viaForm(email, password) {
|
|
86
|
+
const cookies = jar();
|
|
87
|
+
const pageUrl = new URL(how.loginPath, baseUrl);
|
|
88
|
+
const page = await request(pageUrl, { method: 'GET' });
|
|
89
|
+
cookies.add(cookiesOf(page));
|
|
90
|
+
const form = page.status === 200 ? findSignInForm(await readText(page)) : (await page.body?.cancel?.(), null);
|
|
91
|
+
if (!form) return { why: `no sign-in form with an email and a password field was found at ${how.loginPath}` };
|
|
92
|
+
if (form.method !== 'post') return { why: `the sign-in form at ${how.loginPath} is sent by the page's script, not posted; set product.signIn.apiPath to the address that script calls` };
|
|
93
|
+
const target = new URL(form.action || how.loginPath, pageUrl);
|
|
94
|
+
if (target.origin !== origin || !inside(target.href)) return { why: 'the sign-in form posts to another site, so nothing was sent' };
|
|
95
|
+
const res = await request(target, { method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded', ...(cookies.size() ? { cookie: cookies.header() } : {}) }, body: new URLSearchParams({ ...Object.fromEntries(form.hidden), [form.userField]: email, [form.passwordField]: password }).toString() });
|
|
96
|
+
await res.body?.cancel?.();
|
|
97
|
+
cookies.add(cookiesOf(res));
|
|
98
|
+
const back = res.status >= 300 && res.status < 400 && new URL(res.headers.get('location') ?? '/', origin).pathname === pageUrl.pathname;
|
|
99
|
+
if (res.status >= 400 || back) return { why: `the app refused the email and password on the sign-in page ${how.loginPath}` };
|
|
100
|
+
if (cookies.size() === 0) return { why: `the sign-in page ${how.loginPath} set no cookie, so there is no session to keep` };
|
|
101
|
+
learn(cookies.values());
|
|
102
|
+
return { headers: { cookie: cookies.header() } };
|
|
103
|
+
}
|
|
104
|
+
|
|
18
105
|
const provider = async (name) => {
|
|
19
106
|
const account = config.accounts.find((a) => a.name === name);
|
|
107
|
+
if (!account) { reasons.set(name, `there is no account named "${name}" in qa.config.json`); return null; }
|
|
20
108
|
const email = env[account?.credentialRefs?.usernameRef];
|
|
21
109
|
const password = env[account?.credentialRefs?.passwordRef];
|
|
22
|
-
if (!email || !password)
|
|
23
|
-
|
|
24
|
-
method: 'POST',
|
|
25
|
-
headers: { 'content-type': 'application/json' },
|
|
26
|
-
body: JSON.stringify({ email, password }),
|
|
27
|
-
redirect: 'manual',
|
|
28
|
-
});
|
|
29
|
-
if (res.status !== 200) {
|
|
30
|
-
await res.body?.cancel?.();
|
|
110
|
+
if (!email || !password) {
|
|
111
|
+
reasons.set(name, `its email or password is not set in this terminal (${account.credentialRefs?.usernameRef}, ${account.credentialRefs?.passwordRef})`);
|
|
31
112
|
return null;
|
|
32
113
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
114
|
+
let out;
|
|
115
|
+
try {
|
|
116
|
+
out = await viaApi(email, password);
|
|
117
|
+
if (out.missing) {
|
|
118
|
+
out = how.loginPath ? await viaForm(email, password) : { why: `there is no sign-in at ${how.apiPath} on the dev app (404)${how.apiConfigured ? '' : '; set product.signIn.apiPath (a sign-in that takes JSON) or product.signIn.loginPath (the sign-in page) in the config'}` };
|
|
119
|
+
}
|
|
120
|
+
} catch (e) {
|
|
121
|
+
out = { why: `could not reach the dev app to sign in (${e?.cause?.code ?? e?.name ?? 'error'}): is it running?` };
|
|
122
|
+
}
|
|
123
|
+
if (out.headers) { reasons.delete(name); return { headers: out.headers }; }
|
|
124
|
+
reasons.set(name, out.why);
|
|
125
|
+
return null;
|
|
38
126
|
};
|
|
39
|
-
provider.secrets = () => [...
|
|
127
|
+
provider.secrets = () => [...secrets];
|
|
128
|
+
provider.why = (name) => reasons.get(name) ?? null;
|
|
40
129
|
return provider;
|
|
41
130
|
}
|
package/src/review/steps.js
CHANGED
|
@@ -530,7 +530,7 @@ async function guessedFor(action, run, headers) {
|
|
|
530
530
|
async function runStep(step, action, run) {
|
|
531
531
|
const { guard, baseUrl, test, signal, sessionFor } = run;
|
|
532
532
|
const session = action.as ? await sessionFor(action.as) : { headers: {} }; // the signed-out account has no session to make
|
|
533
|
-
if (!session) return { status: 'blocked', reasonKind: 'no-session', needs: needsFor('no-session', action), actual: `not run:
|
|
533
|
+
if (!session) return { status: 'blocked', reasonKind: 'no-session', needs: needsFor('no-session', action), actual: `not run: could not sign in as "${action.as}"${run.whyNoSession?.(action.as) ? `: ${run.whyNoSession(action.as)}` : ''}`, remedy: `fix the sign-in for account "${action.as}" (${run.whyNoSession?.(action.as) ?? 'the sign-in failed or the account has none'}), then run the review again` };
|
|
534
534
|
try {
|
|
535
535
|
const guessed = await guessedFor(action, run, session.headers);
|
|
536
536
|
const out = outcomeOf(step, action, await send({ guard, baseUrl, action, headers: session.headers, test, signal }), run);
|
|
@@ -619,7 +619,7 @@ export async function executeSteps({ steps, guard, config, baseUrl, session, red
|
|
|
619
619
|
if (!cache.has(name)) cache.set(name, await session(name).catch(() => null));
|
|
620
620
|
return cache.get(name);
|
|
621
621
|
};
|
|
622
|
-
const run = { guard, config, baseUrl, redact, test, signal, vars: new Map(), pages: new Map(), sessionFor };
|
|
622
|
+
const run = { guard, config, baseUrl, redact, test, signal, vars: new Map(), pages: new Map(), sessionFor, whyNoSession: (name) => session?.why?.(name) ?? null };
|
|
623
623
|
const results = [];
|
|
624
624
|
const signals = [];
|
|
625
625
|
const pending = [];
|
package/src/run/checks.js
CHANGED
|
@@ -144,7 +144,7 @@ export async function runChecks({ config, guard, baseUrl, sessions: provider, st
|
|
|
144
144
|
onStep?.({ id: step.id, title: step.title, phase: 'start' });
|
|
145
145
|
if (missing) checks.push(skipped(step.id, step.title, missing));
|
|
146
146
|
else if (guard.isPaused()) checks.push(skipped(step.id, step.title, 'not run: everything is paused'));
|
|
147
|
-
else if (step.signedIn && !sessions[probeAccount]) checks.push(errored(step.id, step.title, `
|
|
147
|
+
else if (step.signedIn && !sessions[probeAccount]) checks.push(errored(step.id, step.title, `could not sign in as "${probeAccount}": ${provider.why?.(probeAccount) ?? 'are its credential secrets set?'}`));
|
|
148
148
|
else {
|
|
149
149
|
try {
|
|
150
150
|
checks.push(await step.run(ctx));
|