looply-cli 0.5.39 → 0.5.48
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/dist/.src-hash +1 -1
- package/dist/account-standing.d.ts +23 -0
- package/dist/account-standing.d.ts.map +1 -0
- package/dist/account-standing.js +41 -0
- package/dist/account-standing.js.map +1 -0
- package/dist/autonomy-controller.d.ts.map +1 -1
- package/dist/autonomy-controller.js +6 -0
- package/dist/autonomy-controller.js.map +1 -1
- package/dist/autonomy-tick.d.ts.map +1 -1
- package/dist/autonomy-tick.js +20 -2
- package/dist/autonomy-tick.js.map +1 -1
- package/dist/bin.d.ts.map +1 -1
- package/dist/bin.js +5 -0
- package/dist/bin.js.map +1 -1
- package/dist/branch-delivery-wiring.d.ts +56 -1
- package/dist/branch-delivery-wiring.d.ts.map +1 -1
- package/dist/branch-delivery-wiring.js +135 -26
- package/dist/branch-delivery-wiring.js.map +1 -1
- package/dist/branch-delivery.d.ts +20 -0
- package/dist/branch-delivery.d.ts.map +1 -1
- package/dist/branch-delivery.js +78 -6
- package/dist/branch-delivery.js.map +1 -1
- package/dist/canary-cmd.d.ts +42 -0
- package/dist/canary-cmd.d.ts.map +1 -0
- package/dist/canary-cmd.js +242 -0
- package/dist/canary-cmd.js.map +1 -0
- package/dist/canary-wiring.d.ts +31 -0
- package/dist/canary-wiring.d.ts.map +1 -0
- package/dist/canary-wiring.js +139 -0
- package/dist/canary-wiring.js.map +1 -0
- package/dist/canary.d.ts +123 -0
- package/dist/canary.d.ts.map +1 -0
- package/dist/canary.js +259 -0
- package/dist/canary.js.map +1 -0
- package/dist/checkout-deps.d.ts +6 -0
- package/dist/checkout-deps.d.ts.map +1 -1
- package/dist/checkout-deps.js +11 -0
- package/dist/checkout-deps.js.map +1 -1
- package/dist/checkout-leftovers.d.ts.map +1 -1
- package/dist/checkout-leftovers.js +28 -21
- package/dist/checkout-leftovers.js.map +1 -1
- package/dist/coordinator-state.d.ts.map +1 -1
- package/dist/coordinator-state.js +6 -4
- package/dist/coordinator-state.js.map +1 -1
- package/dist/daemon-cmd.d.ts.map +1 -1
- package/dist/daemon-cmd.js +76 -1
- package/dist/daemon-cmd.js.map +1 -1
- package/dist/deliver-cmd.d.ts +11 -0
- package/dist/deliver-cmd.d.ts.map +1 -1
- package/dist/deliver-cmd.js +23 -0
- package/dist/deliver-cmd.js.map +1 -1
- package/dist/environment-hold.d.ts +32 -1
- package/dist/environment-hold.d.ts.map +1 -1
- package/dist/environment-hold.js +52 -5
- package/dist/environment-hold.js.map +1 -1
- package/dist/feature-report.d.ts +4 -2
- package/dist/feature-report.d.ts.map +1 -1
- package/dist/feature-report.js +47 -6
- package/dist/feature-report.js.map +1 -1
- package/dist/gate-health.d.ts +7 -0
- package/dist/gate-health.d.ts.map +1 -1
- package/dist/gate-health.js +11 -1
- package/dist/gate-health.js.map +1 -1
- package/dist/git-driver.d.ts +5 -0
- package/dist/git-driver.d.ts.map +1 -1
- package/dist/git-driver.js +8 -0
- package/dist/git-driver.js.map +1 -1
- package/dist/goal-adaptive.d.ts +25 -1
- package/dist/goal-adaptive.d.ts.map +1 -1
- package/dist/goal-adaptive.js +42 -1
- package/dist/goal-adaptive.js.map +1 -1
- package/dist/goal-compile.d.ts.map +1 -1
- package/dist/goal-compile.js +16 -0
- package/dist/goal-compile.js.map +1 -1
- package/dist/goal-gap.d.ts +35 -3
- package/dist/goal-gap.d.ts.map +1 -1
- package/dist/goal-gap.js +110 -11
- package/dist/goal-gap.js.map +1 -1
- package/dist/grant-waiting-wiring.d.ts +17 -1
- package/dist/grant-waiting-wiring.d.ts.map +1 -1
- package/dist/grant-waiting-wiring.js +29 -2
- package/dist/grant-waiting-wiring.js.map +1 -1
- package/dist/heroku-cli.d.ts +13 -1
- package/dist/heroku-cli.d.ts.map +1 -1
- package/dist/heroku-cli.js +15 -0
- package/dist/heroku-cli.js.map +1 -1
- package/dist/machine-settings.d.ts +11 -0
- package/dist/machine-settings.d.ts.map +1 -1
- package/dist/machine-settings.js +41 -0
- package/dist/machine-settings.js.map +1 -1
- package/dist/outcome-audit.d.ts +150 -0
- package/dist/outcome-audit.d.ts.map +1 -0
- package/dist/outcome-audit.js +310 -0
- package/dist/outcome-audit.js.map +1 -0
- package/dist/parts-attribution.d.ts +38 -0
- package/dist/parts-attribution.d.ts.map +1 -0
- package/dist/parts-attribution.js +61 -0
- package/dist/parts-attribution.js.map +1 -0
- package/dist/project-terminal.d.ts +3 -1
- package/dist/project-terminal.d.ts.map +1 -1
- package/dist/project-terminal.js +37 -5
- package/dist/project-terminal.js.map +1 -1
- package/dist/provider-accounts.d.ts +5 -1
- package/dist/provider-accounts.d.ts.map +1 -1
- package/dist/provider-accounts.js +1 -0
- package/dist/provider-accounts.js.map +1 -1
- package/dist/pursuit-delivery.d.ts +5 -20
- package/dist/pursuit-delivery.d.ts.map +1 -1
- package/dist/pursuit-delivery.js +30 -2
- package/dist/pursuit-delivery.js.map +1 -1
- package/dist/pursuit-ending.d.ts.map +1 -1
- package/dist/pursuit-ending.js +10 -0
- package/dist/pursuit-ending.js.map +1 -1
- package/dist/qa-feedback.d.ts +110 -0
- package/dist/qa-feedback.d.ts.map +1 -0
- package/dist/qa-feedback.js +353 -0
- package/dist/qa-feedback.js.map +1 -0
- package/dist/run-cmd.d.ts.map +1 -1
- package/dist/run-cmd.js +90 -7
- package/dist/run-cmd.js.map +1 -1
- package/dist/run-refusal-marks.d.ts +8 -1
- package/dist/run-refusal-marks.d.ts.map +1 -1
- package/dist/run-refusal-marks.js +14 -1
- package/dist/run-refusal-marks.js.map +1 -1
- package/dist/self-update.d.ts +440 -0
- package/dist/self-update.d.ts.map +1 -0
- package/dist/self-update.js +1006 -0
- package/dist/self-update.js.map +1 -0
- package/dist/serve-cmd.d.ts +32 -1
- package/dist/serve-cmd.d.ts.map +1 -1
- package/dist/serve-cmd.js +162 -7
- package/dist/serve-cmd.js.map +1 -1
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +3 -0
- package/dist/serve.js.map +1 -1
- package/dist/server-client.d.ts +32 -1
- package/dist/server-client.d.ts.map +1 -1
- package/dist/server-client.js +28 -0
- package/dist/server-client.js.map +1 -1
- package/dist/setup-check-wiring.d.ts +31 -0
- package/dist/setup-check-wiring.d.ts.map +1 -0
- package/dist/setup-check-wiring.js +195 -0
- package/dist/setup-check-wiring.js.map +1 -0
- package/dist/setup-check.d.ts +228 -0
- package/dist/setup-check.d.ts.map +1 -0
- package/dist/setup-check.js +632 -0
- package/dist/setup-check.js.map +1 -0
- package/dist/signals.d.ts +13 -0
- package/dist/signals.d.ts.map +1 -1
- package/dist/signals.js +26 -1
- package/dist/signals.js.map +1 -1
- package/dist/ticket-attachments.d.ts +31 -1
- package/dist/ticket-attachments.d.ts.map +1 -1
- package/dist/ticket-attachments.js +232 -9
- package/dist/ticket-attachments.js.map +1 -1
- package/dist/watchdog-wiring.d.ts +151 -0
- package/dist/watchdog-wiring.d.ts.map +1 -0
- package/dist/watchdog-wiring.js +406 -0
- package/dist/watchdog-wiring.js.map +1 -0
- package/dist/watchdog.d.ts +124 -0
- package/dist/watchdog.d.ts.map +1 -0
- package/dist/watchdog.js +444 -0
- package/dist/watchdog.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SetupDeferred = exports.SETUP_BASE_CHECKS_PER_DAY = exports.maskedLogin = exports.withoutCredentials = exports.SETUP_BASE_RECHECK_MS = exports.SETUP_DEPLOY_RECHECK_MS = exports.SETUP_DAILY_MS = exports.SETUP_OUTPUT_FILE = exports.SETUP_FILE = void 0;
|
|
4
|
+
exports.readSetupRecord = readSetupRecord;
|
|
5
|
+
exports.writeSetupRecord = writeSetupRecord;
|
|
6
|
+
exports.setupReport = setupReport;
|
|
7
|
+
exports.setupNote = setupNote;
|
|
8
|
+
exports.setupInputs = setupInputs;
|
|
9
|
+
exports.setupDue = setupDue;
|
|
10
|
+
exports.herokuAppFromUrl = herokuAppFromUrl;
|
|
11
|
+
exports.checkDeployAccess = checkDeployAccess;
|
|
12
|
+
exports.setupCheckoutPrefix = setupCheckoutPrefix;
|
|
13
|
+
exports.sweepSetupCheckouts = sweepSetupCheckouts;
|
|
14
|
+
exports.runBaseSetup = runBaseSetup;
|
|
15
|
+
exports.baseItem = baseItem;
|
|
16
|
+
exports.machineBaseCheckBudget = machineBaseCheckBudget;
|
|
17
|
+
exports.makeSetupCheck = makeSetupCheck;
|
|
18
|
+
const node_crypto_1 = require("node:crypto");
|
|
19
|
+
const node_fs_1 = require("node:fs");
|
|
20
|
+
const node_path_1 = require("node:path");
|
|
21
|
+
const checkout_carry_1 = require("./checkout-carry");
|
|
22
|
+
const checkout_deps_1 = require("./checkout-deps");
|
|
23
|
+
const gate_health_1 = require("./gate-health");
|
|
24
|
+
/**
|
|
25
|
+
* A REPOSITORY IS SET UP WHEN IT IS SERVED, NOT WHEN ITS FIRST TICKET FAILS.
|
|
26
|
+
*
|
|
27
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
28
|
+
* 🔴 WHAT THIS EXISTS FOR (AUT-B-62, vuedalesystem, 2026-10-21/22). Every problem with the
|
|
29
|
+
* repository's setup on this PC was found by a goal, hours after it was assigned, one at a time,
|
|
30
|
+
* and each took a Looply release: no `node_modules` in the checkout, tests that write tracked
|
|
31
|
+
* files, 67 test files that need a real database, a test that hangs in the full run, flaky tests.
|
|
32
|
+
* Five releases for one ticket, and the ticket's owner waited through all of them.
|
|
33
|
+
*
|
|
34
|
+
* So, when a repository is first served on a PC — and again daily, after a Looply version change,
|
|
35
|
+
* and when its base branch, its gates or its deploy environments change — this checks, before any
|
|
36
|
+
* ticket arrives:
|
|
37
|
+
*
|
|
38
|
+
* - the checks on the unchanged base (`checkBase`: the repository's own slice, quarantine, hung
|
|
39
|
+
* tests, reruns), in a THROWAWAY checkout with the dependencies installed from the lockfile, as
|
|
40
|
+
* a run's checkout gets them. The answer is written to `base-health.json` under the key a run
|
|
41
|
+
* computes, so the first goal reuses it instead of finding out;
|
|
42
|
+
* - each deploy environment's access, read-only and never deploying: the Heroku login is the one
|
|
43
|
+
* the environment names and can see the app (`heroku apps:info`, never `releases:info`), a git
|
|
44
|
+
* push remote answers `ls-remote`, a Netlify site can be read with this PC's token;
|
|
45
|
+
* - that `origin` answers, since every delivery pushes there.
|
|
46
|
+
*
|
|
47
|
+
* Reported to AutoRyn as the `setup` card of the checks report, with a plain next step for every
|
|
48
|
+
* item that is not ready. It INFORMS and never blocks: serving goes on whatever it finds, and a
|
|
49
|
+
* check that throws is an item that says so.
|
|
50
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
51
|
+
*/
|
|
52
|
+
exports.SETUP_FILE = 'setup-health.json';
|
|
53
|
+
/** The full output of a red step in a setup check (never `base-check-output.txt`, which is the run's). */
|
|
54
|
+
exports.SETUP_OUTPUT_FILE = 'setup-check-output.txt';
|
|
55
|
+
/** Everything is checked again this often, even when nothing changed: a login lapses, a test starts to flake. */
|
|
56
|
+
exports.SETUP_DAILY_MS = 24 * 60 * 60 * 1000;
|
|
57
|
+
/** A deploy item that is not ready is asked again this soon, so a person's fix shows within the hour. */
|
|
58
|
+
exports.SETUP_DEPLOY_RECHECK_MS = 60 * 60 * 1000;
|
|
59
|
+
/** A base that is not ready is asked again after this (it runs the whole suite). */
|
|
60
|
+
exports.SETUP_BASE_RECHECK_MS = 6 * 60 * 60 * 1000;
|
|
61
|
+
function readSetupRecord(stateDir) {
|
|
62
|
+
try {
|
|
63
|
+
const raw = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(stateDir, exports.SETUP_FILE), 'utf8'));
|
|
64
|
+
if (raw.version !== 1 || typeof raw.looplyVersion !== 'string')
|
|
65
|
+
return null;
|
|
66
|
+
const part = (p) => typeof p === 'object' && p !== null && Array.isArray(p.items) && typeof p.inputs === 'string' ? p : null;
|
|
67
|
+
return {
|
|
68
|
+
version: 1,
|
|
69
|
+
looplyVersion: raw.looplyVersion,
|
|
70
|
+
base: part(raw.base),
|
|
71
|
+
deploy: part(raw.deploy),
|
|
72
|
+
...(typeof raw.checking === 'string' ? { checking: raw.checking } : {}),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function writeSetupRecord(stateDir, record) {
|
|
80
|
+
(0, node_fs_1.mkdirSync)(stateDir, { recursive: true });
|
|
81
|
+
const target = (0, node_path_1.join)(stateDir, exports.SETUP_FILE);
|
|
82
|
+
const tmp = `${target}.${process.pid}.tmp`;
|
|
83
|
+
(0, node_fs_1.writeFileSync)(tmp, JSON.stringify(record, null, 2) + '\n', 'utf8');
|
|
84
|
+
(0, node_fs_1.renameSync)(tmp, target);
|
|
85
|
+
}
|
|
86
|
+
/** The card AutoRyn shows: base items first, then the repository and each environment. Null: never checked. */
|
|
87
|
+
function setupReport(record) {
|
|
88
|
+
if (record === null)
|
|
89
|
+
return null;
|
|
90
|
+
const items = [...(record.base?.items ?? []), ...(record.deploy?.items ?? [])];
|
|
91
|
+
const state = items.some((i) => i.state === 'not_ready' || i.state === 'unknown')
|
|
92
|
+
? 'not_ready'
|
|
93
|
+
: record.checking !== undefined && record.base === null
|
|
94
|
+
? 'checking'
|
|
95
|
+
: 'ready';
|
|
96
|
+
const checkedAt = [record.base?.checkedAt, record.deploy?.checkedAt].filter((t) => typeof t === 'string').sort().pop() ?? null;
|
|
97
|
+
return { state, checkedAt, looplyVersion: record.looplyVersion, items };
|
|
98
|
+
}
|
|
99
|
+
/** The one line the checks report's notes carry, so a panel that does not show the card yet still says it. */
|
|
100
|
+
function setupNote(report) {
|
|
101
|
+
if (report === null || report.state !== 'not_ready')
|
|
102
|
+
return null;
|
|
103
|
+
const bad = report.items.filter((i) => i.state === 'not_ready' || i.state === 'unknown');
|
|
104
|
+
const first = bad[0];
|
|
105
|
+
if (first === undefined)
|
|
106
|
+
return null;
|
|
107
|
+
return `setup: ${bad.length} item(s) not ready — ${first.name}: ${first.next ?? first.detail ?? 'not ready'}`.slice(0, 300);
|
|
108
|
+
}
|
|
109
|
+
const digest = (s) => (0, node_crypto_1.createHash)('sha256').update(s, 'utf8').digest('hex').slice(0, 16);
|
|
110
|
+
/** What each part is checked for. A change to any of it checks that part again. */
|
|
111
|
+
function setupInputs(input) {
|
|
112
|
+
const q = [...input.quarantine.entries()].map(([k, v]) => [k, [...v.files].sort()]).sort();
|
|
113
|
+
return {
|
|
114
|
+
base: digest(JSON.stringify([input.baseRef, (0, gate_health_1.gatesDigest)(input.steps), q, input.baseCheck, [...input.carry].sort()])),
|
|
115
|
+
deploy: digest(JSON.stringify(input.environments.map((e) => [e.name, e.deploy]))),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** Which parts are due now. */
|
|
119
|
+
function setupDue(record, now, current) {
|
|
120
|
+
/**
|
|
121
|
+
* `everyVersion`: a new Looply version checks the part again whatever it found. Not for the base —
|
|
122
|
+
* a release would then run the install and the whole suite of every repository the PC serves at
|
|
123
|
+
* once; there a new version re-checks only a base that was not ready (and the daily pass the rest).
|
|
124
|
+
*/
|
|
125
|
+
const due = (part, inputs, recheckMs, everyVersion) => {
|
|
126
|
+
if (record === null || part === null || part === undefined)
|
|
127
|
+
return true;
|
|
128
|
+
if (part.inputs !== inputs)
|
|
129
|
+
return true;
|
|
130
|
+
const age = now - Date.parse(part.checkedAt);
|
|
131
|
+
if (!Number.isFinite(age) || age >= exports.SETUP_DAILY_MS)
|
|
132
|
+
return true;
|
|
133
|
+
const bad = part.items.some((i) => i.state === 'not_ready' || i.state === 'unknown');
|
|
134
|
+
if ((part.looplyVersion ?? record.looplyVersion) !== current.version && (everyVersion || bad))
|
|
135
|
+
return true;
|
|
136
|
+
return bad && age >= recheckMs;
|
|
137
|
+
};
|
|
138
|
+
return { base: due(record?.base, current.base, exports.SETUP_BASE_RECHECK_MS, false), deploy: due(record?.deploy, current.deploy, exports.SETUP_DEPLOY_RECHECK_MS, true) };
|
|
139
|
+
}
|
|
140
|
+
/** The app a Heroku git URL pushes to (`https://git.heroku.com/<app>.git`, `git@heroku.com:<app>.git`). */
|
|
141
|
+
function herokuAppFromUrl(url) {
|
|
142
|
+
if (url === null)
|
|
143
|
+
return null;
|
|
144
|
+
const m = /heroku\.com[:/]([a-z][a-z0-9-]{1,29})\.git\/?$/.exec(url.trim());
|
|
145
|
+
return m === null ? null : m[1];
|
|
146
|
+
}
|
|
147
|
+
/** A credential never reaches a report: `https://user:token@host` is said as `https://host`, wherever it appears. */
|
|
148
|
+
const withoutCredentials = (s) => s.replace(/([A-Za-z][A-Za-z0-9+.-]*:\/\/)[^@/\s'"]*@/g, '$1');
|
|
149
|
+
exports.withoutCredentials = withoutCredentials;
|
|
150
|
+
/** One sentence for a report: credentials out, whitespace folded, bounded. Every reported text goes through this. */
|
|
151
|
+
const one = (s, max = 300) => (0, exports.withoutCredentials)(s).replace(/\s+/g, ' ').trim().slice(0, max);
|
|
152
|
+
const safeUrl = exports.withoutCredentials;
|
|
153
|
+
/**
|
|
154
|
+
* 🔴 A LOGIN IS NEVER SENT WHOLE. The setup card reaches looply-api (and anyone holding a grant on the
|
|
155
|
+
* project can read it there), so an email login is said as its first letter and its domain
|
|
156
|
+
* (`d…@vuedale.com`): enough for the PC's owner to recognise it, not enough to hand it to anyone else.
|
|
157
|
+
*/
|
|
158
|
+
const maskedLogin = (login) => {
|
|
159
|
+
const at = login.lastIndexOf('@');
|
|
160
|
+
if (at <= 0)
|
|
161
|
+
return login.length <= 2 ? '…' : `${login[0]}…`;
|
|
162
|
+
return `${login[0]}…${login.slice(at)}`;
|
|
163
|
+
};
|
|
164
|
+
exports.maskedLogin = maskedLogin;
|
|
165
|
+
/**
|
|
166
|
+
* Each configured environment's access, checked without deploying anything, plus `origin`.
|
|
167
|
+
* Never throws: a check that fails to run is an item that says so.
|
|
168
|
+
*/
|
|
169
|
+
async function checkDeployAccess(environments, deps) {
|
|
170
|
+
const items = [];
|
|
171
|
+
const guard = async (kind, name, f) => {
|
|
172
|
+
try {
|
|
173
|
+
items.push(await f());
|
|
174
|
+
}
|
|
175
|
+
catch (e) {
|
|
176
|
+
items.push({ kind, name, state: 'unknown', detail: `the check could not run: ${one(e.message, 200)}`, next: null });
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
// Every delivery pushes its branch to origin, whatever the environments are.
|
|
180
|
+
await guard('repository', 'origin', async () => {
|
|
181
|
+
const url = await deps.remoteUrl('origin');
|
|
182
|
+
if (url === null) {
|
|
183
|
+
return { kind: 'repository', name: 'origin', state: 'not_ready', detail: 'the served checkout has no remote named origin', next: 'Add the repository as origin in the served folder: git remote add origin <url>' };
|
|
184
|
+
}
|
|
185
|
+
const r = await deps.lsRemote('origin');
|
|
186
|
+
if (!r.ok) {
|
|
187
|
+
return {
|
|
188
|
+
kind: 'repository',
|
|
189
|
+
name: 'origin',
|
|
190
|
+
state: 'not_ready',
|
|
191
|
+
detail: `origin (${safeUrl(url)}) did not answer: ${one(r.because, 200)}`,
|
|
192
|
+
next: 'Sign this PC in to the repository host (for GitHub: gh auth login), as an account that can push to it',
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return { kind: 'repository', name: 'origin', state: 'ready', detail: `origin (${safeUrl(url)}) answers`, next: null };
|
|
196
|
+
});
|
|
197
|
+
let whoami = null;
|
|
198
|
+
const login = async () => (whoami ??= await deps.heroku.whoami());
|
|
199
|
+
for (const env of environments) {
|
|
200
|
+
const d = env.deploy;
|
|
201
|
+
if (d.kind === 'none')
|
|
202
|
+
continue;
|
|
203
|
+
if (d.kind === 'run') {
|
|
204
|
+
items.push({ kind: 'deploy', name: env.name, state: 'skipped', detail: 'deployed by the release step, which is checked when it runs', next: null });
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (d.kind === 'merge-deploys') {
|
|
208
|
+
if (!deps.liveCommit.can(d)) {
|
|
209
|
+
items.push({ kind: 'deploy', name: env.name, state: 'skipped', detail: 'merging into the base branch deploys it; nothing is set to read what is live', next: null });
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const label = d.netlifySite !== undefined ? `${env.name} (Netlify site ${d.netlifySite})` : `${env.name} (${d.liveCommitUrl})`;
|
|
213
|
+
await guard('deploy', label, async () => {
|
|
214
|
+
// A commit nothing serves: the read says whether the site can be read, which is the question.
|
|
215
|
+
const r = await deps.liveCommit.read(d, '0000000000000000000000000000000000000000');
|
|
216
|
+
if (!r.ok) {
|
|
217
|
+
return {
|
|
218
|
+
kind: 'deploy',
|
|
219
|
+
name: label,
|
|
220
|
+
state: 'not_ready',
|
|
221
|
+
detail: one(r.because),
|
|
222
|
+
next: d.netlifySite !== undefined
|
|
223
|
+
? `Give this PC a Netlify token that can read site ${d.netlifySite} (AutoRyn → Software execution → Machine secrets → NETLIFY_AUTH_TOKEN)`
|
|
224
|
+
: `Make ${d.liveCommitUrl} reachable from this PC, or set the Netlify site instead`,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
return { kind: 'deploy', name: label, state: 'ready', detail: `readable${r.read.serves[0] ? `; serves ${r.read.serves[0].slice(0, 7)}` : ''}`, next: null };
|
|
228
|
+
});
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
// A git push: the remote must exist and answer; on Heroku, the login must be the named one and see the app.
|
|
232
|
+
const url = await deps.remoteUrl(d.remote).catch(() => null);
|
|
233
|
+
const app = d.herokuApp ?? herokuAppFromUrl(url);
|
|
234
|
+
const label = app !== null ? `${env.name} (Heroku app ${app})` : `${env.name} (push to ${d.remote}/${d.branch})`;
|
|
235
|
+
await guard('deploy', label, async () => {
|
|
236
|
+
if (url === null) {
|
|
237
|
+
return {
|
|
238
|
+
kind: 'deploy',
|
|
239
|
+
name: label,
|
|
240
|
+
state: 'not_ready',
|
|
241
|
+
detail: `the served checkout has no git remote named ${d.remote}`,
|
|
242
|
+
next: app !== null ? `Add it in the served folder: heroku git:remote -a ${app} -r ${d.remote}` : `Add it in the served folder: git remote add ${d.remote} <url>`,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
if (app !== null || d.herokuAccount !== undefined) {
|
|
246
|
+
const who = await login();
|
|
247
|
+
if (!who.ok) {
|
|
248
|
+
return {
|
|
249
|
+
kind: 'deploy',
|
|
250
|
+
name: label,
|
|
251
|
+
state: 'not_ready',
|
|
252
|
+
detail: `the Heroku CLI on this PC is not signed in (${one(who.because, 160)})`,
|
|
253
|
+
next: `Sign this PC in to Heroku: heroku login${d.herokuAccount ? ` (as ${(0, exports.maskedLogin)(d.herokuAccount)})` : ''}`,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
if (d.herokuAccount !== undefined && who.account.toLowerCase() !== d.herokuAccount.toLowerCase()) {
|
|
257
|
+
return {
|
|
258
|
+
kind: 'deploy',
|
|
259
|
+
name: label,
|
|
260
|
+
state: 'not_ready',
|
|
261
|
+
detail: `this PC's Heroku login is ${(0, exports.maskedLogin)(who.account)}, not the account the environment deploys as (${(0, exports.maskedLogin)(d.herokuAccount)})`,
|
|
262
|
+
next: `Sign this PC in to Heroku as ${(0, exports.maskedLogin)(d.herokuAccount)} (heroku logout, then heroku login), or change the environment's Heroku account in AutoRyn`,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
if (app !== null) {
|
|
266
|
+
const seen = await deps.heroku.appInfo(app);
|
|
267
|
+
if (!seen.ok) {
|
|
268
|
+
return {
|
|
269
|
+
kind: 'deploy',
|
|
270
|
+
name: label,
|
|
271
|
+
state: 'not_ready',
|
|
272
|
+
detail: `this PC's Heroku login ${(0, exports.maskedLogin)(who.account)} cannot see app ${app} (${one(seen.because, 160)})`,
|
|
273
|
+
next: `Add this PC's Heroku login (${(0, exports.maskedLogin)(who.account)}) as a collaborator on ${app} in Heroku, or sign this PC in as the account that owns ${app}`,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const r = await deps.lsRemote(d.remote);
|
|
279
|
+
if (!r.ok) {
|
|
280
|
+
return {
|
|
281
|
+
kind: 'deploy',
|
|
282
|
+
name: label,
|
|
283
|
+
state: 'not_ready',
|
|
284
|
+
detail: `${d.remote} (${safeUrl(url)}) did not answer: ${one(r.because, 200)}`,
|
|
285
|
+
next: app !== null ? 'Sign this PC in to Heroku (heroku login), so git can push to the app' : `Give this PC credentials that can push to ${safeUrl(url)}`,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const as = app !== null && whoami?.ok ? `; Heroku login ${(0, exports.maskedLogin)(whoami.account)} can see ${app}` : '';
|
|
289
|
+
return { kind: 'deploy', name: label, state: 'ready', detail: `${d.remote} answers${as}`, next: null };
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return items;
|
|
293
|
+
}
|
|
294
|
+
const NAME = 'checks on the base';
|
|
295
|
+
/** The folder every throwaway setup checkout of this repository is made in, by name: `_setup/<repo>-<hash of its path>-…`. */
|
|
296
|
+
function setupCheckoutPrefix(repoDir) {
|
|
297
|
+
const id = (0, node_crypto_1.createHash)('sha256').update(repoDir.replace(/\\/g, '/').toLowerCase()).digest('hex').slice(0, 8);
|
|
298
|
+
return `${(0, node_path_1.basename)(repoDir).replace(/[^A-Za-z0-9_-]/g, '').slice(0, 40)}-${id}-`;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* 🔴 A THROWAWAY CHECKOUT NEVER OUTLIVES ITS CHECK, EVEN WHEN THE CHECK DID NOT END. A daemon killed
|
|
302
|
+
* mid-check, or a Windows delete that met a busy file, would otherwise leave a whole checkout with its
|
|
303
|
+
* `node_modules` behind for good — and still registered with git — under a folder the workspace
|
|
304
|
+
* reaper does not look in. So every leftover of THIS repository (its path's hash is in the name: two
|
|
305
|
+
* repositories with the same folder name never sweep each other's) is removed from git and from disk,
|
|
306
|
+
* on the daemon's first tick and before each check. Never throws.
|
|
307
|
+
*/
|
|
308
|
+
async function sweepSetupCheckouts(workRoot, repoDir, git, log) {
|
|
309
|
+
const root = (0, node_path_1.join)(workRoot, '_setup');
|
|
310
|
+
const prefix = setupCheckoutPrefix(repoDir);
|
|
311
|
+
let names;
|
|
312
|
+
try {
|
|
313
|
+
names = (0, node_fs_1.readdirSync)(root).filter((n) => n.startsWith(prefix));
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
names = [];
|
|
317
|
+
}
|
|
318
|
+
let removed = 0;
|
|
319
|
+
for (const n of names) {
|
|
320
|
+
const dir = (0, node_path_1.join)(root, n);
|
|
321
|
+
await git(['worktree', 'remove', '--force', dir]).catch(() => undefined);
|
|
322
|
+
try {
|
|
323
|
+
// Copies only, never links (`checkout-carry.ts`), so a recursive delete cannot reach outside it.
|
|
324
|
+
(0, node_fs_1.rmSync)(dir, { recursive: true, force: true, maxRetries: 3 });
|
|
325
|
+
removed++;
|
|
326
|
+
}
|
|
327
|
+
catch (e) {
|
|
328
|
+
log(`setup : could not remove the leftover throwaway checkout ${dir} (${e.message}); tried again next time`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
await git(['worktree', 'prune']).catch(() => undefined);
|
|
332
|
+
if (removed > 0)
|
|
333
|
+
log(`setup : removed ${removed} leftover throwaway checkout(s) of an earlier setup check`);
|
|
334
|
+
return removed;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* The checks on the unchanged base, as a run's first round would meet them, made in a throwaway
|
|
338
|
+
* checkout. Never throws.
|
|
339
|
+
*
|
|
340
|
+
* 🔴 ONLY A HEALTHY ANSWER IS KEPT FOR RUNS. The full suite here may run beside a real goal on the
|
|
341
|
+
* same machine; under that load a test can time out or flake, and `checkBase` would quarantine it —
|
|
342
|
+
* and a quarantined record is reused for its key for good, so every later goal would run WITHOUT
|
|
343
|
+
* that test. (A contention "red" would hold goals for an hour.) So the setup check writes
|
|
344
|
+
* `base-health.json` only when every check passed with nothing left out; anything else is reported
|
|
345
|
+
* on the card and left for the run's own base check to decide. A check that a run of this
|
|
346
|
+
* repository overlapped is not believed at all.
|
|
347
|
+
*/
|
|
348
|
+
async function runBaseSetup(deps) {
|
|
349
|
+
const now = deps.now ?? Date.now;
|
|
350
|
+
const item = (kind, name, state, detail, next) => ({ kind, name, state, detail, next });
|
|
351
|
+
if (!deps.baseCheck)
|
|
352
|
+
return [item('base', NAME, 'skipped', 'the base check is switched off (AutoRyn or run.base_check)', null)];
|
|
353
|
+
if (deps.steps.length === 0) {
|
|
354
|
+
return [item('base', NAME, 'not_ready', 'no checks are configured, so finished work cannot be judged', 'Add the checks in .looply/config.yaml (gates), or in AutoRyn → Checks')];
|
|
355
|
+
}
|
|
356
|
+
const base = await deps.baseRef().catch(() => null);
|
|
357
|
+
if (base === null) {
|
|
358
|
+
return [
|
|
359
|
+
item('base', NAME, 'not_ready', 'no base branch was found (run.base_branch, origin/HEAD, or the branch the served folder is on)', 'Set run.base_branch in .looply/config.yaml, or run git remote set-head origin --auto in the served folder'),
|
|
360
|
+
];
|
|
361
|
+
}
|
|
362
|
+
const name = `checks on ${base.ref.replace(/^refs\/(heads|remotes)\//, '')}`;
|
|
363
|
+
const rev = async (spec) => {
|
|
364
|
+
const r = await deps.git(['rev-parse', '--verify', spec]);
|
|
365
|
+
const v = r.stdout.trim();
|
|
366
|
+
return r.code === 0 && /^[0-9a-f]{40}$/.test(v) ? v : null;
|
|
367
|
+
};
|
|
368
|
+
const sha = await rev(`${base.ref}^{commit}`);
|
|
369
|
+
const tree = await rev(`${base.ref}^{tree}`);
|
|
370
|
+
if (sha === null || tree === null)
|
|
371
|
+
return [item('base', name, 'unknown', `${base.ref} could not be read`, null)];
|
|
372
|
+
const key = (0, gate_health_1.baseHealthKey)(tree, deps.steps, deps.looplyVersion);
|
|
373
|
+
const prior = (0, gate_health_1.readBaseHealth)(deps.stateDir);
|
|
374
|
+
if ((0, gate_health_1.reusable)(prior, key, now()) && prior.state === 'healthy' && prior.withDependencies === true && now() - Date.parse(prior.checkedAt) < exports.SETUP_DAILY_MS) {
|
|
375
|
+
deps.log(`setup : the checks on ${base.ref} (${sha.slice(0, 7)}) were already healthy at ${prior.checkedAt}`);
|
|
376
|
+
return [baseItem(name, prior)];
|
|
377
|
+
}
|
|
378
|
+
await sweepSetupCheckouts(deps.workRoot, deps.repoDir, deps.git, deps.log);
|
|
379
|
+
const room = deps.room?.(deps.workRoot) ?? null;
|
|
380
|
+
if (room !== null)
|
|
381
|
+
return [item('base', name, 'not_ready', `no throwaway checkout could be made: ${one(room, 200)}`, 'Free disk space, or move the checkouts folder (AutoRyn → Software execution → machine settings)')];
|
|
382
|
+
// The machine's daily room for full base checks: none left, and nothing is recorded — it waits.
|
|
383
|
+
const over = deps.budget?.() ?? null;
|
|
384
|
+
if (over !== null)
|
|
385
|
+
throw new SetupDeferred(over);
|
|
386
|
+
const dir = (0, node_path_1.join)(deps.workRoot, '_setup', `${setupCheckoutPrefix(deps.repoDir)}${sha.slice(0, 8)}-${(0, node_crypto_1.randomBytes)(3).toString('hex')}`);
|
|
387
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.join)(dir, '..'), { recursive: true });
|
|
388
|
+
const added = await deps.git(['worktree', 'add', '--detach', dir, sha]);
|
|
389
|
+
if (added.code !== 0)
|
|
390
|
+
return [item('base', name, 'unknown', `no throwaway checkout could be made: ${one(added.stderr || added.stdout, 200)}`, null)];
|
|
391
|
+
deps.log(`setup : checking ${base.ref} (${sha.slice(0, 7)}) in a throwaway checkout, before any ticket`);
|
|
392
|
+
try {
|
|
393
|
+
try {
|
|
394
|
+
// Copies, never links (`checkout-carry.ts`): this checkout is deleted recursively below.
|
|
395
|
+
(0, checkout_carry_1.carryIntoCheckout)(deps.repoDir, dir, deps.carry);
|
|
396
|
+
}
|
|
397
|
+
catch (e) {
|
|
398
|
+
return [item('base', name, 'not_ready', one(e.message), 'Fix run.carry_into_checkouts in .looply/config.yaml (or the carried folders in AutoRyn)')];
|
|
399
|
+
}
|
|
400
|
+
const { gates, install } = deps.runnersFor(dir);
|
|
401
|
+
const fs = deps.fsFor(dir);
|
|
402
|
+
/**
|
|
403
|
+
* WITHOUT THE PACKAGES' OWN INSTALL SCRIPTS: this install runs unattended, with internet, when a
|
|
404
|
+
* repository is served and daily after, so it runs no code from the packages. A run installs
|
|
405
|
+
* with them; where a check needs what they build, the card says the difference may be why.
|
|
406
|
+
*/
|
|
407
|
+
const plan = (0, checkout_deps_1.dependencyInstallPlan)(deps.steps, fs).map((p) => ({ ...p, cmd: (0, checkout_deps_1.installWithoutScripts)(p), fallback: null }));
|
|
408
|
+
const installed = await (0, checkout_deps_1.installDependencies)({ plan, runner: install, log: deps.log });
|
|
409
|
+
const depsItem = installed.kind === 'failed'
|
|
410
|
+
? item('dependencies', 'dependencies', 'not_ready', one(installed.because.replace(/ — so the environment is unavailable, not the change$/, '')), `Run the same install in a fresh clone on this PC and fix what it says (a registry login, the Node version, a lockfile out of date): ${plan.map((p) => `${p.cmd}${p.dir ? ` in ${p.dir}` : ''}`).join('; ')}`.slice(0, 400))
|
|
411
|
+
: item('dependencies', 'dependencies', 'ready', installed.kind === 'installed'
|
|
412
|
+
? `installed from the lockfile in ${installed.dirs.map((d) => d || 'the root').join(', ')} (without the packages' install scripts)`
|
|
413
|
+
: 'nothing to install (already present, or no lockfile)', null);
|
|
414
|
+
if (installed.kind === 'failed')
|
|
415
|
+
return [depsItem, item('base', name, 'unknown', 'not checked: the dependencies could not be installed', null)];
|
|
416
|
+
const checked = await (0, gate_health_1.checkBase)({
|
|
417
|
+
steps: deps.steps,
|
|
418
|
+
runner: gates,
|
|
419
|
+
fs,
|
|
420
|
+
log: deps.log,
|
|
421
|
+
...(deps.slice ? { slice: (run) => deps.slice(fs, run) } : {}),
|
|
422
|
+
// Its own file: a red answer here is never kept for runs, so it must not replace the output of the run's own red check.
|
|
423
|
+
keepOutput: (step, cmd, output) => {
|
|
424
|
+
(0, node_fs_1.mkdirSync)(deps.stateDir, { recursive: true });
|
|
425
|
+
(0, node_fs_1.writeFileSync)((0, node_path_1.join)(deps.stateDir, exports.SETUP_OUTPUT_FILE), `step: ${step}\ncommand: ${cmd}\nchecked: ${new Date(now()).toISOString()} (setup check)\n\n${output.slice(-2_000_000)}`, 'utf8');
|
|
426
|
+
deps.log(`setup : the full output of the red "${step}" run is kept at ${(0, node_path_1.join)(deps.stateDir, exports.SETUP_OUTPUT_FILE)}`);
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
if (deps.busy?.() === true) {
|
|
430
|
+
deps.log('setup : a run of this repository started during the base check, so its answer is not kept; checked again later');
|
|
431
|
+
return [depsItem, item('base', name, 'unknown', 'not judged: a run of this repository started during the check, which can change its answer', null)];
|
|
432
|
+
}
|
|
433
|
+
const record = {
|
|
434
|
+
version: 1,
|
|
435
|
+
key,
|
|
436
|
+
treeSha: tree,
|
|
437
|
+
baseSha: sha,
|
|
438
|
+
checkedAt: new Date(now()).toISOString(),
|
|
439
|
+
state: checked.state,
|
|
440
|
+
steps: checked.steps,
|
|
441
|
+
withDependencies: true,
|
|
442
|
+
by: 'setup',
|
|
443
|
+
};
|
|
444
|
+
if (record.state === 'healthy') {
|
|
445
|
+
try {
|
|
446
|
+
(0, gate_health_1.writeBaseHealth)(deps.stateDir, record);
|
|
447
|
+
}
|
|
448
|
+
catch (e) {
|
|
449
|
+
deps.log(`setup : could not keep the base check (${e.message})`);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
const said = baseItem(name, record);
|
|
453
|
+
if (record.state === 'healthy' || installed.kind !== 'installed')
|
|
454
|
+
return [depsItem, said];
|
|
455
|
+
// Not kept for runs (see above), and the install here skipped the packages' scripts: both said.
|
|
456
|
+
return [
|
|
457
|
+
depsItem,
|
|
458
|
+
{
|
|
459
|
+
...said,
|
|
460
|
+
detail: one(`${said.detail ?? ''} (not kept for runs: a goal's own base check decides; the dependencies here were installed without their install scripts, which a run's install runs)`, 400),
|
|
461
|
+
},
|
|
462
|
+
];
|
|
463
|
+
}
|
|
464
|
+
finally {
|
|
465
|
+
// `worktree remove` first (it unregisters even when a busy file stops the delete), then the folder itself.
|
|
466
|
+
await deps.git(['worktree', 'remove', '--force', dir]).catch(() => undefined);
|
|
467
|
+
try {
|
|
468
|
+
(0, node_fs_1.rmSync)(dir, { recursive: true, force: true, maxRetries: 3 });
|
|
469
|
+
}
|
|
470
|
+
catch (e) {
|
|
471
|
+
deps.log(`setup : could not remove the throwaway checkout ${dir} (${e.message}); it is removed before the next check`);
|
|
472
|
+
}
|
|
473
|
+
await deps.git(['worktree', 'prune']).catch(() => undefined);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
/** A base-health record as the setup card's base item. */
|
|
477
|
+
function baseItem(name, record) {
|
|
478
|
+
const at = record.baseSha.slice(0, 7);
|
|
479
|
+
if (record.state === 'healthy')
|
|
480
|
+
return { kind: 'base', name, state: 'ready', detail: `every check passes on ${at}`, next: null };
|
|
481
|
+
if (record.state === 'quarantined') {
|
|
482
|
+
const said = record.steps.filter((s) => s.state === 'quarantined').map((s) => `"${s.name}" ${s.because ?? 'passes with tests left out'}`);
|
|
483
|
+
return { kind: 'base', name, state: 'ready', detail: one(`passes on ${at}; ${said.join('; ')}`, 400), next: null };
|
|
484
|
+
}
|
|
485
|
+
const bad = record.steps.find((s) => s.state !== 'passed' && s.state !== 'quarantined');
|
|
486
|
+
const what = bad ? `"${bad.name}" ${bad.because ?? 'is red'}` : 'a check is red';
|
|
487
|
+
const next = bad?.state === 'could_not_run'
|
|
488
|
+
? 'A program the checks run is missing on this PC: install it, or carry the folder that has it (run.carry_into_checkouts)'
|
|
489
|
+
: bad?.state === 'timed_out'
|
|
490
|
+
? `Raise the step's time limit (timeout_s in .looply/config.yaml, or in AutoRyn → Checks), or give it a faster command`
|
|
491
|
+
: 'The checks fail on the unchanged code: fix the base branch, leave the failing tests out in AutoRyn → Checks, or change the check\'s command';
|
|
492
|
+
return { kind: 'base', name, state: 'not_ready', detail: one(`on ${at}: ${what}`, 400), next };
|
|
493
|
+
}
|
|
494
|
+
/* ───────────────────────────── when, and the record ───────────────────────────── */
|
|
495
|
+
/**
|
|
496
|
+
* Full base checks (an install and the whole suite) this PC runs in a day, across every repository
|
|
497
|
+
* it serves. One machine serves many (27 on 2026-10-22): without a cap, a release, the daily pass and
|
|
498
|
+
* the rechecks of red bases would each run the whole suite of all of them. Past the cap a check waits
|
|
499
|
+
* for the next day's room; with the single maintenance slot, they also run one at a time.
|
|
500
|
+
*/
|
|
501
|
+
exports.SETUP_BASE_CHECKS_PER_DAY = 8;
|
|
502
|
+
/** A base check that did not start (no room left today): nothing is recorded, it is due again next tick. */
|
|
503
|
+
class SetupDeferred extends Error {
|
|
504
|
+
}
|
|
505
|
+
exports.SetupDeferred = SetupDeferred;
|
|
506
|
+
/** The machine-wide daily budget of full base checks, kept in one file (`~/.looply/setup-base-checks.json`). */
|
|
507
|
+
function machineBaseCheckBudget(file, cap = exports.SETUP_BASE_CHECKS_PER_DAY, now = Date.now) {
|
|
508
|
+
return {
|
|
509
|
+
take: () => {
|
|
510
|
+
let at = [];
|
|
511
|
+
try {
|
|
512
|
+
const raw = JSON.parse((0, node_fs_1.readFileSync)(file, 'utf8'));
|
|
513
|
+
if (Array.isArray(raw.at))
|
|
514
|
+
at = raw.at.filter((t) => typeof t === 'number');
|
|
515
|
+
}
|
|
516
|
+
catch {
|
|
517
|
+
/* none yet */
|
|
518
|
+
}
|
|
519
|
+
const t = now();
|
|
520
|
+
at = at.filter((x) => t - x < exports.SETUP_DAILY_MS && x <= t);
|
|
521
|
+
if (at.length >= cap)
|
|
522
|
+
return `this PC already ran ${at.length} full base checks in the last day (at most ${cap})`;
|
|
523
|
+
at.push(t);
|
|
524
|
+
try {
|
|
525
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.join)(file, '..'), { recursive: true });
|
|
526
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
527
|
+
(0, node_fs_1.writeFileSync)(tmp, JSON.stringify({ at }) + '\n', 'utf8');
|
|
528
|
+
(0, node_fs_1.renameSync)(tmp, file);
|
|
529
|
+
}
|
|
530
|
+
catch {
|
|
531
|
+
/* a budget that cannot be kept still lets this one check run */
|
|
532
|
+
}
|
|
533
|
+
return null;
|
|
534
|
+
},
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* The cadence's handle: call `tick()` as often as the daemon likes; it checks only what is due,
|
|
539
|
+
* one check at a time, and never throws. The deploy part goes first: it takes seconds, the base
|
|
540
|
+
* part can take a quarter of an hour.
|
|
541
|
+
*/
|
|
542
|
+
function makeSetupCheck(deps) {
|
|
543
|
+
const now = deps.now ?? Date.now;
|
|
544
|
+
let inFlight = false;
|
|
545
|
+
let swept = false;
|
|
546
|
+
let waitSaid = null;
|
|
547
|
+
const save = (f) => {
|
|
548
|
+
const prior = readSetupRecord(deps.stateDir);
|
|
549
|
+
const base = prior ?? { version: 1, looplyVersion: deps.looplyVersion, base: null, deploy: null };
|
|
550
|
+
try {
|
|
551
|
+
writeSetupRecord(deps.stateDir, f({ ...base, looplyVersion: deps.looplyVersion }));
|
|
552
|
+
}
|
|
553
|
+
catch (e) {
|
|
554
|
+
deps.log(`setup : could not keep the setup check (${e.message})`);
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
const guarded = async (kind, f) => {
|
|
558
|
+
try {
|
|
559
|
+
return await f();
|
|
560
|
+
}
|
|
561
|
+
catch (e) {
|
|
562
|
+
if (e instanceof SetupDeferred)
|
|
563
|
+
throw e;
|
|
564
|
+
return [{ kind, name: kind === 'base' ? NAME : 'deploy access', state: 'unknown', detail: `the setup check could not run: ${one(e.message, 200)}`, next: null }];
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
/** Said once per reason, not every tick. */
|
|
568
|
+
const waiting = (why) => {
|
|
569
|
+
if (waitSaid !== why)
|
|
570
|
+
deps.log(`setup : the base check waits — ${why}`);
|
|
571
|
+
waitSaid = why;
|
|
572
|
+
};
|
|
573
|
+
return {
|
|
574
|
+
running: () => inFlight,
|
|
575
|
+
tick: async () => {
|
|
576
|
+
if (inFlight)
|
|
577
|
+
return;
|
|
578
|
+
inFlight = true;
|
|
579
|
+
try {
|
|
580
|
+
if (!swept) {
|
|
581
|
+
swept = true;
|
|
582
|
+
// A daemon that stopped mid-check left its marker and maybe its checkout: both go.
|
|
583
|
+
await deps.sweep?.().catch(() => undefined);
|
|
584
|
+
const prior = readSetupRecord(deps.stateDir);
|
|
585
|
+
if (prior?.checking !== undefined)
|
|
586
|
+
save(({ checking: _c, ...r }) => r);
|
|
587
|
+
}
|
|
588
|
+
const inputs = await deps.inputs();
|
|
589
|
+
const due = setupDue(readSetupRecord(deps.stateDir), now(), { version: deps.looplyVersion, ...inputs });
|
|
590
|
+
if (due.deploy) {
|
|
591
|
+
const items = await guarded('deploy', deps.runDeploy);
|
|
592
|
+
save((r) => ({ ...r, deploy: { inputs: inputs.deploy, looplyVersion: deps.looplyVersion, checkedAt: new Date(now()).toISOString(), items } }));
|
|
593
|
+
for (const i of items)
|
|
594
|
+
if (i.state === 'not_ready')
|
|
595
|
+
deps.log(`setup : ${i.name} is not ready — ${i.detail ?? ''}${i.next ? ` → ${i.next}` : ''}`);
|
|
596
|
+
}
|
|
597
|
+
if (due.base) {
|
|
598
|
+
if (deps.busy?.() === true)
|
|
599
|
+
return waiting('a run of this repository is in progress');
|
|
600
|
+
const refused = deps.claimSlot?.() ?? null;
|
|
601
|
+
if (refused !== null)
|
|
602
|
+
return waiting(`no free run slot (${refused})`);
|
|
603
|
+
try {
|
|
604
|
+
save((r) => ({ ...r, checking: new Date(now()).toISOString() }));
|
|
605
|
+
const items = await guarded('base', deps.runBase);
|
|
606
|
+
waitSaid = null;
|
|
607
|
+
save(({ checking: _c, ...r }) => ({ ...r, base: { inputs: inputs.base, looplyVersion: deps.looplyVersion, checkedAt: new Date(now()).toISOString(), items } }));
|
|
608
|
+
for (const i of items)
|
|
609
|
+
if (i.state === 'not_ready')
|
|
610
|
+
deps.log(`setup : ${i.name} is not ready — ${i.detail ?? ''}${i.next ? ` → ${i.next}` : ''}`);
|
|
611
|
+
}
|
|
612
|
+
catch (e) {
|
|
613
|
+
if (!(e instanceof SetupDeferred))
|
|
614
|
+
throw e;
|
|
615
|
+
save(({ checking: _c, ...r }) => r);
|
|
616
|
+
waiting(e.message);
|
|
617
|
+
}
|
|
618
|
+
finally {
|
|
619
|
+
deps.releaseSlot?.();
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
catch (e) {
|
|
624
|
+
deps.log(`setup : the setup check could not run (${e.message})`);
|
|
625
|
+
}
|
|
626
|
+
finally {
|
|
627
|
+
inFlight = false;
|
|
628
|
+
}
|
|
629
|
+
},
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
//# sourceMappingURL=setup-check.js.map
|