cornfield 0.65.0 → 0.65.2
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/explorer/decision-model.js +15 -3
- package/explorer/work-view.css +2 -2
- package/package.json +1 -1
- package/server/decision.js +7 -2
- package/server/lander.js +73 -12
- package/server/server.js +2 -0
- package/server/submit-review.js +3 -1
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* review.js is the half that touches the page; the words and the choices are here so each row of the spec's two tables is a test.
|
|
7
7
|
*
|
|
8
8
|
* The facts come from `GET /proposals/<slug>/decision` (server/decision.js): `{ pull: { number, draft, head }, checks: { total, passed, running,
|
|
9
|
-
* failed: [names] } | null, lands, landing, run: null | { kind, transport, runner, lastSeen, open, fired } }`. Everything in them from the forge (names) is text,
|
|
9
|
+
* failed: [names] } | null, lands, landing, waiting: null | { others: [slugs] }, run: null | { kind, transport, runner, lastSeen, open, fired } }`. Everything in them from the forge (names) is text,
|
|
10
10
|
* and it only ever becomes text: this module builds strings, never markup. The server decides; these words are a courtesy before the click.
|
|
11
11
|
*
|
|
12
12
|
* decide(input) { line, approve: 'allowed' | 'asks' | 'done' | 'refused' | 'reading', reasons, ask, askButton }
|
|
@@ -97,9 +97,21 @@ function pullWords(facts) {
|
|
|
97
97
|
return lands ? `Approve posts an approval on PR #${n} and lands it.` : `${head} It does not land it.`;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* "This PR also holds 0041-planner, which is not approved: landing waits for it." An approval that started no landing because the PR holds other
|
|
102
|
+
* proposals not approved as they are now (#301). The slugs are the PR's file names, as text.
|
|
103
|
+
*/
|
|
104
|
+
export function waitingWords(facts) {
|
|
105
|
+
const others = facts && facts.waiting && Array.isArray(facts.waiting.others) ? facts.waiting.others.map(oneLine).filter(Boolean) : [];
|
|
106
|
+
if (!others.length) return '';
|
|
107
|
+
const one = others.length === 1;
|
|
108
|
+
return `This PR also holds ${nameList(others)}, which ${one ? 'is' : 'are'} not approved: landing waits for ${one ? 'it' : 'them'}.`;
|
|
109
|
+
}
|
|
110
|
+
|
|
100
111
|
/** The line while Approve reads Approved: what stands, and what makes it live again */
|
|
101
112
|
function doneWords(n, facts) {
|
|
102
|
-
const
|
|
113
|
+
const waits = waitingWords(facts);
|
|
114
|
+
const landing = waits ? ` ${waits}` : facts && facts.landing ? ' Its landing waits for the checks.' : '';
|
|
103
115
|
return `An approval of this version of PR #${n} stands.${landing} A push makes Approve live again.`;
|
|
104
116
|
}
|
|
105
117
|
|
|
@@ -168,7 +180,7 @@ export function decide({ source, facts, factsState, review = null, edits = 0, fo
|
|
|
168
180
|
}
|
|
169
181
|
const reasons = askReasons({ facts, edits, form });
|
|
170
182
|
const run = facts.run ? runWords(facts.run, now) : '';
|
|
171
|
-
const line = tail(pullWords(facts), run, editsWords(edits), played);
|
|
183
|
+
const line = tail(pullWords(facts), facts.lands ? waitingWords(facts) : '', run, editsWords(edits), played);
|
|
172
184
|
// Approve does nothing now (an approval of this version stands): the line says that, not what a press would post
|
|
173
185
|
if (done) return { line: tail(doneWords(n, facts), played), approve: 'done', reasons, ask: '' };
|
|
174
186
|
return { line, approve: reasons.length ? 'asks' : 'allowed', reasons, ask: askWords(reasons) };
|
package/explorer/work-view.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* The Work view (explorer/work-view.js, spec 0012): the line of what could not be read, and the node panel's work detail. Its controls (Waiting on you, List) are the header's (css/header.css, spec 0015 D5). */
|
|
2
|
-
.hx-work-note { position: absolute; z-index: 3; left: var(--corn-space-4); bottom: var(--corn-space-4); max-width: min(32rem, calc(100% - var(--corn-space-
|
|
2
|
+
.hx-work-note { position: absolute; z-index: 3; left: var(--corn-space-4); bottom: var(--corn-space-4); max-width: min(32rem, calc(100% - 2 * var(--corn-space-4))); margin: 0; padding: var(--corn-space-2) var(--corn-space-3); border-radius: var(--corn-radius); background: var(--corn-surface-1); color: var(--corn-text-2); font-size: var(--corn-text-xs); }
|
|
3
3
|
.hx-work-note[hidden] { display: none; }
|
|
4
4
|
.hx-view-badge { margin-left: var(--corn-space-2); }
|
|
5
5
|
.hx-work-links { list-style: none; margin: 0; padding: 0; }
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
.hx-stage.is-work .hx-hint { display: none; }
|
|
35
35
|
@keyframes hx-work-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.8; } }
|
|
36
36
|
@media (prefers-reduced-motion: reduce) { .hx-work-skel-lane i { animation: none; opacity: 0.6; } }
|
|
37
|
-
.hx-work-loading-text { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(26rem, calc(100% - var(--corn-space-
|
|
37
|
+
.hx-work-loading-text { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(26rem, calc(100% - 2 * var(--corn-space-4))); margin: 0; padding: var(--corn-space-3) var(--corn-space-4); border-radius: var(--corn-radius); border: var(--corn-border) solid var(--corn-line); background: var(--corn-surface-1); color: var(--corn-text); font-size: var(--corn-text-sm); text-align: center; box-shadow: var(--corn-shadow); }
|
|
38
38
|
@container corn-box (max-width: 767px) {
|
|
39
39
|
/* The Layers chip, the view's controls and Fit sit on the map's top row (layers.css, header.css); the lanes run top to bottom under it */
|
|
40
40
|
.hx-work-note { bottom: var(--corn-space-4); }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornfield",
|
|
3
|
-
"version": "0.65.
|
|
3
|
+
"version": "0.65.2",
|
|
4
4
|
"description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "popcorn245 (https://github.com/popcorn245)",
|
package/server/decision.js
CHANGED
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
* the server's own checks (server/submit-review.js) are the rule whatever the page does with it.
|
|
7
7
|
*
|
|
8
8
|
* { pull: { number, draft, head }, checks: { total, passed, running, failed: [names] } | null,
|
|
9
|
-
* lands: boolean, landing: { by, since } | null, run: null | { kind, transport, runner, lastSeen, quietAfterMs, open, fired } }
|
|
9
|
+
* lands: boolean, landing: { by, since } | null, waiting: { others: [slugs] } | null, run: null | { kind, transport, runner, lastSeen, quietAfterMs, open, fired } }
|
|
10
10
|
*
|
|
11
11
|
* - `pull`: the PR, read from the forge. A PR that is not open, or that does not hold the proposal, is 404.
|
|
12
12
|
* - `checks`: the checks on the PR's head, counted: `passed` is the ones that finished green (`success`), `running` the queued and running,
|
|
13
13
|
* `failed` the names of the ones that failed or were cancelled (text from the forge: the page sets it as text). `null` when the forge
|
|
14
14
|
* could not list them (the pull is still answered; the line then says it could not read them).
|
|
15
15
|
* - `lands`: `proposals.approveLands` is on; `landing`: a landing is waiting on this PR now (Cancel landing, spec 0007 D3).
|
|
16
|
+
* - `waiting`: the last approval at this head started no landing, because the PR also holds other proposals not approved as they are now
|
|
17
|
+
* (`others`, their slugs, text from the PR's file names): the line above Approve names them (#301). What the lander kept; the forge is not asked.
|
|
16
18
|
* - `run`: what an approval would ask for, from `agents.on['spec.approved']`, or null. `runner` is `online`, `quiet` (it polled once, not within
|
|
17
19
|
* the window) or `never` on the pull transport (the only one with runners that ask), and null on the forge and push transports. `open` is the
|
|
18
20
|
* id of a run already open on the PR or the proposal, and `fired` says the trigger already asked for a run at this head: either way an approval
|
|
@@ -82,11 +84,12 @@ export function countChecks(checks) {
|
|
|
82
84
|
* @param {{ proposals: string }} where
|
|
83
85
|
* @param {{ slug: string, n: number, fresh?: boolean, now?: () => number,
|
|
84
86
|
* lands?: boolean, landing?: (n: number) => ({ by: string, since: string } | null) | null,
|
|
87
|
+
* waiting?: (n: number, sha: string) => ({ others: string[] } | null) | null,
|
|
85
88
|
* run?: null | { kind: string, transport: string, presence: () => Promise<null | { online: boolean, lastSeen: string | null, quietAfterMs: number }>,
|
|
86
89
|
* already?: (n: number, slug: string, headSha: string) => Promise<{ open: string | null, fired: boolean }> } }} opts
|
|
87
90
|
* @returns {Promise<object>} the answer; throws a ForgeError (`not-found` when the PR is not open or does not hold the proposal)
|
|
88
91
|
*/
|
|
89
|
-
export async function readDecision(forge, where, { slug, n, fresh = false, now = Date.now, lands = false, landing = null, run = null }) {
|
|
92
|
+
export async function readDecision(forge, where, { slug, n, fresh = false, now = Date.now, lands = false, landing = null, waiting = null, run = null }) {
|
|
90
93
|
const { pull, checks } = await readPull(forge, where, n, { fresh, now });
|
|
91
94
|
if (pull.state !== 'open') throw new ForgeError(`Pull request #${n} is not open.`, { code: 'not-found' });
|
|
92
95
|
const folder = folderOf(where);
|
|
@@ -107,11 +110,13 @@ export async function readDecision(forge, where, { slug, n, fresh = false, now =
|
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
const landingNow = landing ? landing(n) : null;
|
|
113
|
+
const waitingNow = !landingNow && waiting ? waiting(n, pull.head.sha) : null;
|
|
110
114
|
return {
|
|
111
115
|
pull: { number: n, draft: !!pull.draft, head: pull.head.sha },
|
|
112
116
|
checks: countChecks(checks),
|
|
113
117
|
lands: !!lands,
|
|
114
118
|
landing: landingNow ? { by: landingNow.by, since: landingNow.since } : null,
|
|
119
|
+
waiting: waitingNow && waitingNow.others.length ? { others: waitingNow.others.map((o) => String(o).slice(0, 80)).slice(0, NAMES_MAX) } : null,
|
|
115
120
|
run: runOut,
|
|
116
121
|
};
|
|
117
122
|
}
|
package/server/lander.js
CHANGED
|
@@ -22,8 +22,10 @@
|
|
|
22
22
|
* the PR is closed or merged done (landed elsewhere, or closed: nothing to say)
|
|
23
23
|
* its head is not the approved sha cancelled, "a push after approval" (the approval covered another version)
|
|
24
24
|
* a check is red left open: <check> failed
|
|
25
|
-
* another proposal not approved waits
|
|
26
|
-
*
|
|
25
|
+
* another proposal not approved waits (a PR with several proposals lands only once every one of them is approved by a
|
|
26
|
+
* maintainer at its current SHA-256, `allApproved`). Found at `start`, no landing begins
|
|
27
|
+
* and it says so: a `waiting` audit row, a log line, one comment naming them, and the
|
|
28
|
+
* line above Approve (`waiting`, #301); found at a later look, it waits saying nothing
|
|
27
29
|
* green, not a draft, mergeable lands, pinned to the approved sha
|
|
28
30
|
* the time is up left open: timed out
|
|
29
31
|
*
|
|
@@ -61,6 +63,11 @@ const NAME_MAX = 80;
|
|
|
61
63
|
|
|
62
64
|
const iso = (ms) => new Date(ms).toISOString();
|
|
63
65
|
const oneLine = (v, max) => String(v).replace(/\s+/g, ' ').trim().slice(0, max);
|
|
66
|
+
/** "proposal 0041-planner in this PR is not approved as it is now": the why of a landing that waits on others (#301) */
|
|
67
|
+
export function othersWords(others) {
|
|
68
|
+
if (others.length === 1) return `proposal ${others[0]} in this PR is not approved as it is now`;
|
|
69
|
+
return `proposals ${others.slice(0, -1).join(', ')} and ${others[others.length - 1]} in this PR are not approved as they are now`;
|
|
70
|
+
}
|
|
64
71
|
|
|
65
72
|
/**
|
|
66
73
|
* @param {{
|
|
@@ -80,6 +87,8 @@ export function createLander({ config, where, auth, hooks = null, now = Date.now
|
|
|
80
87
|
const targetOf = (pull) => `${repo}#${pull}`;
|
|
81
88
|
/** The landings being waited for in this process, by pull request */
|
|
82
89
|
const jobs = new Map();
|
|
90
|
+
/** The approvals that started no landing, waiting on other proposals of their PR, by pull request (#301) */
|
|
91
|
+
const waits = new Map();
|
|
83
92
|
/** The looks in flight, so a test (and a shutdown) can wait for them */
|
|
84
93
|
const looking = new Set();
|
|
85
94
|
let closed = false;
|
|
@@ -124,21 +133,52 @@ export function createLander({ config, where, auth, hooks = null, now = Date.now
|
|
|
124
133
|
});
|
|
125
134
|
|
|
126
135
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
136
|
+
* The proposals the PR holds at its head whose latest review by a maintainer is not an approval of the file as it is now (its
|
|
137
|
+
* SHA-256), by slug; null when it holds none. Approving one proposal of a PR that holds several does not land the others.
|
|
129
138
|
* @param {import('./forge.js').Forge} forge
|
|
130
139
|
* @param {import('./forge.js').Pull} pull read fresh from the forge
|
|
140
|
+
* @returns {Promise<string[] | null>}
|
|
131
141
|
*/
|
|
132
|
-
async function
|
|
142
|
+
async function notApproved(forge, pull) {
|
|
133
143
|
const entries = await pullProposals(forge, folder, pull);
|
|
134
|
-
if (!entries.length) return
|
|
144
|
+
if (!entries.length) return null;
|
|
135
145
|
const comments = await forge.comments(pull.number);
|
|
146
|
+
const out = [];
|
|
136
147
|
for (const e of entries) {
|
|
137
148
|
const review = await latestReview(forge, pull.number, e.slug, comments);
|
|
138
|
-
|
|
139
|
-
if (
|
|
149
|
+
const ok = !!review && review.verdict === 'approved' && typeof review.proposal === 'string' && review.proposal === proposalHash(await readPullProposal(forge, folder, e));
|
|
150
|
+
if (!ok) out.push(e.slug);
|
|
151
|
+
}
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Whether every proposal the PR holds at its head is approved as it is now (see `notApproved`) */
|
|
156
|
+
async function allApproved(forge, pull) {
|
|
157
|
+
const left = await notApproved(forge, pull);
|
|
158
|
+
return left !== null && left.length === 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* An approval that started no landing because other proposals of the PR are not approved as they are now (#301): a row in
|
|
163
|
+
* `actions` (`landing`, state `waiting`), a line in the log and one comment on the PR naming them, and what the line above
|
|
164
|
+
* Approve shows (`waiting`). The same approval at the same head, waiting on the same proposals, says it once.
|
|
165
|
+
*/
|
|
166
|
+
async function hold(forge, { pull, slug, sha, who }, others) {
|
|
167
|
+
const had = waits.get(pull);
|
|
168
|
+
const same = had && had.sha === sha && had.others.join('\n') === others.join('\n');
|
|
169
|
+
waits.set(pull, { pull, slug, sha, others, by: who.login, since: iso(now()) });
|
|
170
|
+
if (same) return;
|
|
171
|
+
const job = { pull, slug, sha, login: who.login };
|
|
172
|
+
const why = othersWords(others);
|
|
173
|
+
log(`#${pull} waits`, why);
|
|
174
|
+
await audit(job, { state: 'waiting', others }, null, { state: 'waiting', why });
|
|
175
|
+
const names = others.map((o) => `\`${o}\``);
|
|
176
|
+
const list = names.length === 1 ? names[0] : `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;
|
|
177
|
+
try {
|
|
178
|
+
await postNote(forge, pull, `Landing on approval waits: this pull request also holds ${list}, which ${others.length === 1 ? 'is' : 'are'} not approved as ${others.length === 1 ? 'it is' : 'they are'} now. \`${slug}\` lands once every proposal in it is approved.`);
|
|
179
|
+
} catch (err) {
|
|
180
|
+
log(`the comment on #${pull} could not be posted`, err);
|
|
140
181
|
}
|
|
141
|
-
return true;
|
|
142
182
|
}
|
|
143
183
|
|
|
144
184
|
/** One look at the PR. Resolves when it has ended the landing or decided to wait. */
|
|
@@ -264,12 +304,22 @@ export function createLander({ config, where, auth, hooks = null, now = Date.now
|
|
|
264
304
|
async function start({ pull, slug, sha, who }) {
|
|
265
305
|
if (closed) return;
|
|
266
306
|
// A PR that holds other proposals not approved as they are now: this approval does not start a landing (the last
|
|
267
|
-
// approval does). Asked fresh of the forge; a forge that cannot say now is asked again at every look before the merge.
|
|
307
|
+
// approval does), and says so. Asked fresh of the forge; a forge that cannot say now is asked again at every look before the merge.
|
|
308
|
+
let held = null;
|
|
268
309
|
try {
|
|
269
310
|
const forge = await auth.forgeForUser(String(who.userId));
|
|
270
311
|
const now_ = await forge.pull(pull);
|
|
271
|
-
if (now_.state === 'open' && now_.head.sha.toLowerCase() === sha.toLowerCase()
|
|
312
|
+
if (now_.state === 'open' && now_.head.sha.toLowerCase() === sha.toLowerCase()) {
|
|
313
|
+
const left = await notApproved(forge, now_);
|
|
314
|
+
if (left === null) return;
|
|
315
|
+
const others = left.filter((s) => s !== slug);
|
|
316
|
+
// The approved one itself not approved as it is now (a review posted since): nothing to name, nothing started
|
|
317
|
+
if (left.includes(slug)) return;
|
|
318
|
+
if (others.length) held = { forge, others };
|
|
319
|
+
}
|
|
272
320
|
} catch { /* the looks decide */ }
|
|
321
|
+
if (held) return hold(held.forge, { pull, slug, sha: sha.toLowerCase(), who }, held.others);
|
|
322
|
+
waits.delete(pull);
|
|
273
323
|
const row = { repo, pull, slug, sha: sha.toLowerCase(), user_id: String(who.userId), login: who.login, started: iso(now()), state: /** @type {LandingState} */ ('pending') };
|
|
274
324
|
(await auth.store()).prepare("INSERT INTO landings (repo, pull, slug, sha, user_id, login, started, state) VALUES (?, ?, ?, ?, ?, ?, ?, 'pending') ON CONFLICT(repo, pull) DO UPDATE SET slug = excluded.slug, sha = excluded.sha, user_id = excluded.user_id, login = excluded.login, started = excluded.started, state = 'pending'")
|
|
275
325
|
.run(repo, pull, row.slug, row.sha, row.user_id, row.login, row.started);
|
|
@@ -311,6 +361,16 @@ export function createLander({ config, where, auth, hooks = null, now = Date.now
|
|
|
311
361
|
return job && !job.over ? { pull, slug: job.slug, sha: job.sha, by: job.login, since: job.started } : null;
|
|
312
362
|
}
|
|
313
363
|
|
|
364
|
+
/**
|
|
365
|
+
* What an approval of PR `pull` is waiting on, at head `sha`, or null: the other proposals of the PR not approved as they are
|
|
366
|
+
* now, when the last approval there started no landing (#301).
|
|
367
|
+
* @returns {{ pull: number, slug: string, sha: string, others: string[], by: string, since: string } | null}
|
|
368
|
+
*/
|
|
369
|
+
function waiting(pull, sha) {
|
|
370
|
+
const w = waits.get(pull);
|
|
371
|
+
return w && (sha === undefined || w.sha === String(sha).toLowerCase()) ? { ...w, others: [...w.others] } : null;
|
|
372
|
+
}
|
|
373
|
+
|
|
314
374
|
/**
|
|
315
375
|
* A maintainer stops a landing. Posts the one comment, as them. False when nothing was waiting.
|
|
316
376
|
* @param {number} pull
|
|
@@ -335,9 +395,10 @@ export function createLander({ config, where, auth, hooks = null, now = Date.now
|
|
|
335
395
|
closed = true;
|
|
336
396
|
for (const job of jobs.values()) if (job.timer !== null) timer.clearTimeout(job.timer);
|
|
337
397
|
jobs.clear();
|
|
398
|
+
waits.clear();
|
|
338
399
|
}
|
|
339
400
|
|
|
340
|
-
return { start, resume, pending, cancel, idle, close };
|
|
401
|
+
return { start, resume, pending, waiting, cancel, idle, close };
|
|
341
402
|
}
|
|
342
403
|
|
|
343
404
|
/** @typedef {ReturnType<typeof createLander>} Lander */
|
package/server/server.js
CHANGED
|
@@ -331,11 +331,13 @@ export function createCornfieldServer(config, opts = {}) {
|
|
|
331
331
|
const decisionFacts = {
|
|
332
332
|
lands: !!config.approveLands,
|
|
333
333
|
landing: null,
|
|
334
|
+
waiting: null,
|
|
334
335
|
run: approvalRun ? { kind: approvalRun[1].kind, transport: config.agents?.transport ?? 'forge', presence: async () => runnerPresence(await auth.store(), (opts.now ?? Date.now)(), runnerQuietAfterMs(config)) } : null,
|
|
335
336
|
};
|
|
336
337
|
const lander = config.approveLands ? createLander({ config, where, auth, hooks, now: opts.now, timer: opts.landTimer }) : null;
|
|
337
338
|
if (lander) {
|
|
338
339
|
decisionFacts.landing = (n) => lander.pending(n);
|
|
340
|
+
decisionFacts.waiting = (n, sha) => lander.waiting(n, sha);
|
|
339
341
|
// What a restart left waiting: looked at again, in the background
|
|
340
342
|
lander.resume().catch((err) => console.error(`[cornfield] pending landings could not be picked up: ${err instanceof Error ? err.message : err}`));
|
|
341
343
|
}
|
package/server/submit-review.js
CHANGED
|
@@ -206,7 +206,9 @@ export function isRepeat(standing, review, login) {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
/** Whether a landing on approval already waits on PR `n` at this head (so an approval again would begin nothing new) */
|
|
209
|
-
export const stillLanding = (lander, n, sha) => String(lander.pending(n)?.sha ?? '').toLowerCase() === String(sha).toLowerCase()
|
|
209
|
+
export const stillLanding = (lander, n, sha) => String(lander.pending(n)?.sha ?? '').toLowerCase() === String(sha).toLowerCase()
|
|
210
|
+
// or, with other proposals of the PR not approved, this approval waits for them at this head (#301): approving again would start nothing new
|
|
211
|
+
|| !!lander.waiting?.(n, sha);
|
|
210
212
|
|
|
211
213
|
/**
|
|
212
214
|
* Whether a review that stands is an approval of exactly this: the proposal file as the head holds it and its mockups (what an approval covers).
|