@runeditrun/rer 0.2.48 → 0.2.50
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/cli/dev-identity.mjs +1 -1
- package/cli/errors.mjs +1 -1
- package/cli/lifecycle.mjs +2 -0
- package/cli/managed-server.mjs +1 -1
- package/cli/release.mjs +1 -1
- package/foundation/runtime/seed-contract.mjs +16 -3
- package/global/CHANGELOG.md +12 -0
- package/modules/delivery-producer/declarations.mjs +5 -3
- package/modules/demo-host/README.md +3 -1
- package/modules/demo-host/native/prepare.mjs +2 -1
- package/modules/demo-host/native/warm.mjs +1 -1
- package/modules/demo-host/native/worker.mjs +3 -1
- package/modules/job-queue/index.mjs +3 -5
- package/modules/operator-auth/dev/index.mjs +7 -4
- package/modules/release/catalogue.mjs +5 -25
- package/onboarding/adapter.mjs +3 -3
- package/onboarding/busy.mjs +21 -0
- package/onboarding/commands.mjs +4 -2
- package/onboarding/failures.mjs +7 -0
- package/onboarding/queue.mjs +3 -2
- package/package.json +1 -1
package/cli/dev-identity.mjs
CHANGED
|
@@ -61,7 +61,7 @@ export async function resolvePersona(url, key, as, signal) {
|
|
|
61
61
|
const { appFetch } = await shared('app-fetch.mjs');
|
|
62
62
|
const response = await appFetch(url + '/__dev/personas', { headers: { [DEV_KEY_HEADER]: key }, signal: AbortSignal.any([signal, AbortSignal.timeout(10000)].filter(Boolean)) });
|
|
63
63
|
if (!response.ok) { await response.body?.cancel(); throw refuse(`The application did not serve dev identity (HTTP ${response.status}). Check its local-only entry.`); }
|
|
64
|
-
const personas = await response.json(), persona = personas.find(entry => entry.as === as);
|
|
64
|
+
const personas = await response.json(), email = as.toLowerCase(), persona = personas.find(entry => entry.as === as || (as.includes('@') && entry.email?.toLowerCase() === email));
|
|
65
65
|
if (persona) return persona;
|
|
66
66
|
// The people rer can sign in as: each persona with its email, then every
|
|
67
67
|
// invited or active person in this checkout's local database by email.
|
package/cli/errors.mjs
CHANGED
|
@@ -14,5 +14,5 @@ export async function lifecycleError(error, store) {
|
|
|
14
14
|
const {shared}=await import('./shared.mjs');
|
|
15
15
|
const {approvedFailure}=await shared('failures.mjs');
|
|
16
16
|
const approved=approvedFailure(error);
|
|
17
|
-
return new RerError(approved?.code
|
|
17
|
+
return new RerError(['owner_conflict','machine_busy'].includes(approved?.code)?'safety_refusal':'command_failed', approved?.message ?? `${store?.state?.step ?? 'Local lifecycle'} failed. Inspect the private redacted capture log.`, approved?.exitCode ?? 1, {childExitCode:approved?.childExitCode,signal:approved?.signal});
|
|
18
18
|
}
|
package/cli/lifecycle.mjs
CHANGED
|
@@ -184,6 +184,8 @@ async function hostedNeeds(project) {
|
|
|
184
184
|
// full log. A step that stopped outside a command still names the step and log.
|
|
185
185
|
async function installStepError(error, store, root) {
|
|
186
186
|
const { approvedFailure } = await shared('failures.mjs');
|
|
187
|
+
// A step the job queue never admitted is a busy machine; its message already says what to do.
|
|
188
|
+
if (approvedFailure(error)?.code === 'machine_busy') return error;
|
|
187
189
|
const { checkoutPath, stepDiagnostic, stepFailureText } = await shared('step-failure.mjs');
|
|
188
190
|
const step = approvedFailure(error)?.step ?? stepDiagnostic({ name: store.state.step, output: store.state.logs, log: store.redact(checkoutPath(root, store.logPath)) });
|
|
189
191
|
// Only a RerError's message or a symbolic error code is safe to show; a native message can hold private data.
|
package/cli/managed-server.mjs
CHANGED
|
@@ -175,5 +175,5 @@ async function devReady(url,key,options,signal){
|
|
|
175
175
|
const as=options.as??'owner',persona=await resolvePersona(url,key,as,signal);
|
|
176
176
|
// The owner persona names the owner the session will actually have (the
|
|
177
177
|
// remaining owner once the setup owner has left), or none when none is left.
|
|
178
|
-
return {identity:true,signedInAs:persona.email??null,ownerLeft:as==='owner'&&!persona.email,openUrl:openUrl(url,key,{path:'/__dev/key',as})};
|
|
178
|
+
return {identity:true,signedInAs:persona.email??null,ownerLeft:as==='owner'&&!persona.email,openUrl:openUrl(url,key,{path:'/__dev/key',as:persona.as})};
|
|
179
179
|
}
|
package/cli/release.mjs
CHANGED
|
@@ -67,7 +67,7 @@ export async function dispatchRelease(args) {
|
|
|
67
67
|
console.log(JSON.stringify(receipt, null, 2));
|
|
68
68
|
return receipt.status === 'BLOCKED' ? 1 : 0;
|
|
69
69
|
} catch (error) {
|
|
70
|
-
console.error(error?.
|
|
70
|
+
console.error(error?.message || 'Release failed during argument, source or artifact validation. No release completed.');
|
|
71
71
|
return 2;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -120,6 +120,19 @@ function areaGroup(headings, area) {
|
|
|
120
120
|
return 'published'
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
// A clause's prose, on one line: what follows its definition on that line, then
|
|
124
|
+
// the lines below it up to the next heading or definition. A bullet's body also
|
|
125
|
+
// ends at the first unindented line; a bold paragraph's or heading's runs on.
|
|
126
|
+
function bodyText(lines, line, form, rest) {
|
|
127
|
+
const body = [rest]
|
|
128
|
+
for (let next = line; next < lines.length; next++) {
|
|
129
|
+
const text = lines[next]
|
|
130
|
+
if (heading.test(text) || definitions.some(pattern => pattern.test(text)) || (form === 0 && text.trim() && !/^[\t ]/.test(text))) break
|
|
131
|
+
body.push(text)
|
|
132
|
+
}
|
|
133
|
+
return body.join(' ').replace(/\s+/gu, ' ').trim()
|
|
134
|
+
}
|
|
135
|
+
|
|
123
136
|
// Clause definitions everywhere except the Status section and retired-ID
|
|
124
137
|
// sections. The area is the nearest heading above that is not a clause.
|
|
125
138
|
// A clause's own "*Status:* partial." line, kept beside its text, is recorded
|
|
@@ -132,7 +145,7 @@ function readDefinitions(lines, headings, skipped, problems) {
|
|
|
132
145
|
const marker = /^\s*(```|~~~)/.exec(text)?.[1]
|
|
133
146
|
if (marker) { fence = fence === marker ? undefined : fence ?? marker; return }
|
|
134
147
|
if (fence || skipped.some(([start, end]) => line >= start && line <= end)) { current = undefined; return }
|
|
135
|
-
const
|
|
148
|
+
const form = definitions.findIndex(pattern => pattern.test(text)), match = form < 0 ? null : definitions[form].exec(text)
|
|
136
149
|
if (!match) {
|
|
137
150
|
if (heading.test(text)) current = undefined
|
|
138
151
|
const stated = /^\*{1,2}Status:\*{1,2}\s*(done|partial|missing)\b/.exec(text)
|
|
@@ -143,7 +156,7 @@ function readDefinitions(lines, headings, skipped, problems) {
|
|
|
143
156
|
const [, clause, title] = match
|
|
144
157
|
if (defined.has(clause)) { problems.push({ line, message: `${clause} is defined twice (first at line ${defined.get(clause).line}).` }); return }
|
|
145
158
|
if (!area) { problems.push({ line, message: `${clause} is defined above every section heading, so it has no area.` }); return }
|
|
146
|
-
current = { id: clause, title: cleanTitle(title), area: area.text, line }
|
|
159
|
+
current = { id: clause, title: cleanTitle(title), area: area.text, line, text: bodyText(lines, line, form, text.slice(match[0].length)) }
|
|
147
160
|
defined.set(clause, current)
|
|
148
161
|
const group = areaGroup(headings, area), known = areas.get(area.text)
|
|
149
162
|
if (known && known.group !== group) problems.push({ line: area.line, message: `Area "${area.text}" is a ${group} area here but a ${known.group} area at line ${known.line}; give one of them its own name.` })
|
|
@@ -256,7 +269,7 @@ export function parseContract(text, { file = 'CONTRACT.md' } = {}) {
|
|
|
256
269
|
if (state === 'done' && !evidence.length) problems.push({ line: rowLine, message: `${clause} is done, so its Evidence names the repository path that proves it, in backticks.` })
|
|
257
270
|
if (state === 'partial' && !evidence.length) problems.push({ line: rowLine, message: `${clause} is partial, so its Evidence names the repository path that backs it, in backticks.` })
|
|
258
271
|
if ((state === 'partial' || state === 'missing') && !gap) problems.push({ line: rowLine, message: `${clause} is ${state}, so its Gap says what is missing.` })
|
|
259
|
-
if (definition && kinds.includes(kind) && statuses.includes(state)) clauses.push({ id: clause, title, kind, status: state, evidence, gap, area: definition.area, line: definition.line, row: rowLine })
|
|
272
|
+
if (definition && kinds.includes(kind) && statuses.includes(state)) clauses.push({ id: clause, title, kind, status: state, evidence, gap, area: definition.area, text: definition.text, line: definition.line, row: rowLine })
|
|
260
273
|
}
|
|
261
274
|
}
|
|
262
275
|
line = end
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.50
|
|
4
|
+
|
|
5
|
+
- **Seeds can declare an owner sign-in route.** The delivery producer, in Base and in each seed's vendored copy, now accepts an optional `surfaces.app.signIn.ownerSignIn` path, such as `"/auth/owner-signin"`. This is the route that accepts the platform's owner sign-in grant. The platform binds `RER_PREVIEW_OWNER_SIGNIN` to the declared path, and only when a seed declares it. The path follows the same rules as `signIn.path`, and the producer still refuses unknown keys and values such as `//evil` or `https://x` (#234).
|
|
6
|
+
- **`rer dev` says when the computer is busy.** When the job queue or the machine's load holds a setup step until its wait runs out, `rer dev` (and setup, build, preview, deploy and verify) now prints "Not started: this computer is busy" with the measured 1-minute load, the threshold and what to do next: run the same command again, or raise `RER_JOBS_LOAD_THRESHOLD`. It exits 4, like the server load guard. Before, the hold was reported as "Local migrations failed". A real migration failure keeps its own message and captured output. The job queue's `maxWait` now bounds only a blocked wait, so a job the machine can run is admitted even when the queue's first lock, reclaim and sample pass takes longer than `maxWait` (#221).
|
|
7
|
+
|
|
8
|
+
## 0.2.49
|
|
9
|
+
|
|
10
|
+
- **Large imports no longer fail with D1's request limit.** The import kit sized each D1 batch from the data statements alone and left out the authority, progress, scope and return checks that `atomic()` adds to the same request. A large import could therefore build one request just over D1's limit and stop with 409 `IMPORT_D1_REQUEST_LIMIT`: Nook's 3,547-entry Slack import stopped at checkpoint 51, where the estimate said 524 statements and the request held 573 against 572 remaining. Each batch is now sized with `atomicCount()`, the same count `atomic()` sends. The apply, reverse and fenced-reversal planners share it, because undo had the same gap. Nook's import now applies all 3,547 entries in 78 saved batches (#230).
|
|
11
|
+
- **A native demo serves every built chunk as immutable.** The demo worker now sends `cache-control: public, max-age=31536000, immutable` for every hashed chunk the seed's build produced, taken from its Vite manifest or else its recorded `assetsDir`, as well as for the existing `/assets/` default. Before, seeds that build elsewhere, such as Lamp with `/app-assets/`, had their chunks revalidated on every use, so the start page's prefetch barely helped (#227).
|
|
12
|
+
- **`rer release` names the real validation error.** A validation failure now prints its own message, such as "CONTRACT.md must contain published clauses", in place of the generic "Release failed during argument, source or artifact validation", and still exits 2. The release catalogue reads clauses through `parseContract`, the same parser `rer check` and the run site use, so published clauses written as headings or bold paragraphs release just like the bullet form. `rer dev --as <email>` also matches a built-in persona by its address, so a person invited at a persona's address signs in as that invited person with the invited role (#231).
|
|
13
|
+
- Base's TanStack Start migration notes add one harness line for test queues: keep the producers, drop the consumers, and name a single opt-in for tests that need real consumers (#225).
|
|
14
|
+
|
|
3
15
|
## 0.2.48
|
|
4
16
|
|
|
5
17
|
- **The job queue no longer aborts or strands a waiting command under load.** Before, when another queued job's owner did not answer its 3 s identity probe, the waiting build, verify or deploy stopped with "Command failed; inspect the project operating documentation." A probe timeout now counts as "the owner may still be alive", so the waiting job samples again instead of giving up. The same holds for the queue lock and for nested-command membership, which had left a job queued behind its own parent until the queue's maximum wait. A recorded failed install is retried only when `pnpm-lock.yaml` or `package.json` changed since it failed. An error that is not one of rer's own now prints its message and a hint instead of the generic line (#219).
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {array, bindingPattern, keys, string, strings} from './bindings.mjs';
|
|
2
2
|
|
|
3
3
|
const pathPattern = /^\/[A-Za-z0-9/_.~-]*$/;
|
|
4
|
+
const signInPath = value => typeof value === 'string' && /^\/(?!\/)[a-zA-Z0-9/_-]*$/.test(value);
|
|
4
5
|
const validSignIn = value => value && typeof value === 'object' && !Array.isArray(value)
|
|
5
|
-
&& Object.keys(value).every(key => ['path','loginHint'].includes(key))
|
|
6
|
-
&&
|
|
7
|
-
&& typeof value.loginHint === 'boolean'
|
|
6
|
+
&& Object.keys(value).every(key => ['path','loginHint','ownerSignIn'].includes(key))
|
|
7
|
+
&& signInPath(value.path)
|
|
8
|
+
&& typeof value.loginHint === 'boolean'
|
|
9
|
+
&& (value.ownerSignIn === undefined || signInPath(value.ownerSignIn));
|
|
8
10
|
const status = (value, label) => {
|
|
9
11
|
if (!Number.isInteger(value) || value < 100 || value > 599) throw Error(`Invalid ${label}`);
|
|
10
12
|
};
|
|
@@ -15,7 +15,9 @@ host. See [adoption and deployment](../../export/DEMO.md#hosting-the-demo).
|
|
|
15
15
|
- `native/warm.mjs`: the start page's prefetch list, built from `dist/client`
|
|
16
16
|
(the Vite manifest if the build wrote one, else the build's `assetsDir`, else
|
|
17
17
|
`assets`) and TanStack Start's route manifest, the console's views first,
|
|
18
|
-
capped by compressed size.
|
|
18
|
+
capped by compressed size. The same built chunks (`bundle.immutable`) are
|
|
19
|
+
what `native/worker.mjs` serves with an immutable `cache-control`, besides
|
|
20
|
+
hashed files under `/assets/`.
|
|
19
21
|
- `capacity.mjs`: concurrent visitor admission and operator diagnostics. This
|
|
20
22
|
is used by the native host as well as retained during legacy upgrades.
|
|
21
23
|
- `upgrade.mjs`: verifies ownership, removes the old Container application and
|
|
@@ -4,7 +4,7 @@ import { createHash } from 'node:crypto';
|
|
|
4
4
|
import { collectBuildModules } from '../../deploy-kit/build-modules.mjs';
|
|
5
5
|
import { collectFiles, moduleType } from '../../deploy-kit/artifact.mjs';
|
|
6
6
|
import { nativeBindings, ISOLATE_FILES, objectExports } from './config.mjs';
|
|
7
|
-
import { warmList } from './warm.mjs';
|
|
7
|
+
import { warmList, builtChunks } from './warm.mjs';
|
|
8
8
|
|
|
9
9
|
// The Worker Loader module kind for each upload type deploy-kit gives a build
|
|
10
10
|
// module, so a demo carries what a normal deploy uploads. Binary kinds travel
|
|
@@ -34,6 +34,7 @@ export async function prepareNative(folder) {
|
|
|
34
34
|
const bundle = { compatibilityDate: config.compatibility_date, compatibilityFlags: [...new Set([...(config.compatibility_flags ?? []), 'nodejs_compat'])], modules,
|
|
35
35
|
bindings, migrations: manifest.migrations, vars: config.vars ?? {}, crons: config.triggers?.crons ?? [],
|
|
36
36
|
assetPaths: assets.filter(file => !file.path.split('/').some(part => part.startsWith('.'))).map(file => '/' + file.path),
|
|
37
|
+
immutable: [...builtChunks(assets, manifest.assetsDir)].sort(),
|
|
37
38
|
warm: (await warmList(assets, root, manifest.operatorPath, manifest.assetsDir)).paths };
|
|
38
39
|
bundle.digest = createHash('sha256').update(JSON.stringify(bundle)).digest('hex');
|
|
39
40
|
await cp(join(app, 'dist/client'), join(folder, 'assets'), { recursive: true });
|
|
@@ -20,7 +20,7 @@ const within = (path, root) => path === root || path.startsWith(root.endsWith('/
|
|
|
20
20
|
// names (build.manifest), else everything under the configured build.assetsDir
|
|
21
21
|
// (Vite's default is 'assets'). Never source maps or unhashed files.
|
|
22
22
|
const MANIFESTS = ['.vite/manifest.json', 'manifest.json'];
|
|
23
|
-
function builtChunks(files, assetsDir) {
|
|
23
|
+
export function builtChunks(files, assetsDir) {
|
|
24
24
|
const manifest = files.find(file => MANIFESTS.includes(file.path));
|
|
25
25
|
const paths = (manifest
|
|
26
26
|
? Object.values(JSON.parse(Buffer.from(manifest.base64, 'base64'))).flatMap(entry => [entry.file, ...(entry.css ?? [])]).map(path => '/' + path)
|
|
@@ -7,6 +7,8 @@ export { NativeDemo } from './visitor.mjs';
|
|
|
7
7
|
export { DemoCapacity } from '../capacity.mjs';
|
|
8
8
|
|
|
9
9
|
const assets = new Set(bundle.assetPaths);
|
|
10
|
+
// The seed's built chunks (its Vite manifest, else its assetsDir) are hashed wherever the build put them.
|
|
11
|
+
const chunks = new Set(bundle.immutable);
|
|
10
12
|
export default {
|
|
11
13
|
async fetch(request, env, ctx) {
|
|
12
14
|
const url = new URL(request.url);
|
|
@@ -14,7 +16,7 @@ export default {
|
|
|
14
16
|
if (['GET', 'HEAD'].includes(request.method) && assets.has(url.pathname)) {
|
|
15
17
|
const response = await env.ASSETS.fetch(request);
|
|
16
18
|
const headers = new Headers(response.headers);
|
|
17
|
-
if (HASHED_ASSET.test(url.pathname)) headers.set('cache-control', 'public, max-age=31536000, immutable');
|
|
19
|
+
if (chunks.has(url.pathname) || HASHED_ASSET.test(url.pathname)) headers.set('cache-control', 'public, max-age=31536000, immutable');
|
|
18
20
|
headers.set('x-rer-demo-assets', 'edge');
|
|
19
21
|
return new Response(response.body, { status: response.status, headers });
|
|
20
22
|
}
|
|
@@ -79,10 +79,8 @@ export async function createQueue(options = {}) {
|
|
|
79
79
|
if (blockers.length) return { reason: blockers.join('; '), blockers, reasonCodes, position, ahead,
|
|
80
80
|
queued: waiting.length, running: state.running.length, resources,
|
|
81
81
|
limits: { slots: config.slots, loadThreshold: config.loadThreshold, minFreeMemoryBytes: config.minFreeMemoryBytes } };
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
reasonCodes: ['max_wait'], position, queued: waiting.length, running: state.running.length, resources,
|
|
85
|
-
limits: { slots: config.slots, loadThreshold: config.loadThreshold, minFreeMemoryBytes: config.minFreeMemoryBytes } };
|
|
82
|
+
// maxWait bounds how long a blocked job waits. A job this pass finds admissible is admitted
|
|
83
|
+
// however long the pass itself took (lock, reclaim, sample), so a slow pass never refuses a free machine.
|
|
86
84
|
state.queued = state.queued.filter(item => item.id !== job.id);
|
|
87
85
|
job.startedAt = Date.now(); state.running.push(job);
|
|
88
86
|
return null;
|
|
@@ -90,7 +88,7 @@ export async function createQueue(options = {}) {
|
|
|
90
88
|
if (!result) break;
|
|
91
89
|
const elapsed = performance.now() - start;
|
|
92
90
|
if (opts.maxWait !== undefined && elapsed >= opts.maxWait * 1000)
|
|
93
|
-
return { code: TIMEOUT_EXIT, timedOut: true, reason: result.reason };
|
|
91
|
+
return { code: TIMEOUT_EXIT, timedOut: true, reason: result.reason, reasonCodes: result.reasonCodes, resources: result.resources, limits: result.limits };
|
|
94
92
|
const signature = `${result.position}:${result.reasonCodes.join(',')}`;
|
|
95
93
|
const now = performance.now();
|
|
96
94
|
if (!lastWaitReportAt || signature !== lastWaitSignature || now - lastWaitReportAt >= WAIT_REPORT_INTERVAL_MS) {
|
|
@@ -130,15 +130,18 @@ async function enter(request, gate, { config, store, hash, current, everyone, ow
|
|
|
130
130
|
reply.set('location', '/');
|
|
131
131
|
return new Response(null, { status: 303, headers: reply });
|
|
132
132
|
}
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
const value = await auth.oneClick.enter(request, { as, returnTo: url.searchParams.get('returnTo') ?? '/app' });
|
|
133
|
+
const oneClick = async email => {
|
|
134
|
+
const value = await auth.oneClick.enter(request, { as: email, returnTo: url.searchParams.get('returnTo') ?? '/app' });
|
|
136
135
|
reply.append('set-cookie', value.cookie);
|
|
137
136
|
reply.set('location', value.returnTo);
|
|
138
137
|
return new Response(null, { status: 303, headers: reply });
|
|
139
|
-
}
|
|
138
|
+
};
|
|
139
|
+
const persona = (await everyone()).find(p => p.as === as);
|
|
140
|
+
if (!persona) return oneClick(as);
|
|
140
141
|
if (!persona.email) return text(409, 'No active owner remains in this app. Sign in another way, or run rer reset --yes and rer setup for a new owner.');
|
|
141
142
|
let operator = await store.byEmail(persona.email);
|
|
143
|
+
// Someone invited at a persona's address is that person, with the role they were invited to; accepting the invite signs them in.
|
|
144
|
+
if (operator?.status === 'invited') return oneClick(operator.email);
|
|
142
145
|
// Personas are real operators, created only here, in local dev.
|
|
143
146
|
if (!operator && persona.role) {
|
|
144
147
|
if (persona.role === 'owner') {
|
|
@@ -1,36 +1,16 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { resolve, dirname } from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { parseContract } from '../../foundation/runtime/seed-contract.mjs';
|
|
5
5
|
|
|
6
6
|
export const sha256 = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
7
7
|
export const json = value => JSON.stringify(value, null, 2) + '\n';
|
|
8
8
|
|
|
9
|
+
// The listing's clauses are the contract's published ones, read by the parser
|
|
10
|
+
// `rer check` and the run site use: a malformed contract throws its ContractError.
|
|
9
11
|
function clauses(text) {
|
|
10
|
-
const result =
|
|
11
|
-
|
|
12
|
-
const finish = () => {
|
|
13
|
-
if (!current) return;
|
|
14
|
-
const body = current.body.join(' ').replace(/\s+/gu, ' ').trim();
|
|
15
|
-
if (body) result.push({ id: current.id, title: current.title, text: body });
|
|
16
|
-
current = null;
|
|
17
|
-
};
|
|
18
|
-
const clauseLine = new RegExp(`^- \\*\\*(${clauseIdSource})\\s+[—–-]\\s+(.+?)\\.?\\*\\*[ \\t]*(.*)$`);
|
|
19
|
-
for (const line of text.split(/\r\n|\n|\r/)) {
|
|
20
|
-
const match = clauseLine.exec(line);
|
|
21
|
-
if (match) {
|
|
22
|
-
finish();
|
|
23
|
-
current = { id: match[1], title: match[2], body: [match[3]] };
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (!current) continue;
|
|
27
|
-
if (!line.trim() || /^[\t ]/.test(line)) {
|
|
28
|
-
current.body.push(line);
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
finish();
|
|
32
|
-
}
|
|
33
|
-
finish();
|
|
12
|
+
const result = parseContract(text).clauses.filter(clause => clause.kind === 'published' && clause.text)
|
|
13
|
+
.sort((a, b) => a.line - b.line).map(({ id, title, text }) => ({ id, title, text }));
|
|
34
14
|
if (!result.length) throw Error('CONTRACT.md must contain published clauses');
|
|
35
15
|
return result;
|
|
36
16
|
}
|
package/onboarding/adapter.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { constants } from 'node:fs';
|
|
2
2
|
import { access } from 'node:fs/promises';
|
|
3
3
|
import { delimiter, join } from 'node:path';
|
|
4
|
-
import { commandFailure, approvedFailure, installationFailure, installationFailureMessage } from './failures.mjs';
|
|
4
|
+
import { commandFailure, approvedFailure, installationFailure, installationFailureMessage, isBusyFailure } from './failures.mjs';
|
|
5
5
|
import { withoutLocalVariables } from './local/build.mjs';
|
|
6
6
|
import { buildEnvironment } from './local/environment.mjs';
|
|
7
7
|
import { localOperation } from './local/operation.mjs';
|
|
@@ -72,7 +72,7 @@ export function localInstaller(hooks = {}) {
|
|
|
72
72
|
if (['installer', 'setup', 'dev'].includes(verb) && hooks.migrate) {
|
|
73
73
|
try { await phase(context, hooks, 'migrate', hooks.migrate); }
|
|
74
74
|
catch (error) {
|
|
75
|
-
if (verb !== 'dev' || signal?.aborted) throw error;
|
|
75
|
+
if (verb !== 'dev' || signal?.aborted || isBusyFailure(error)) throw error;
|
|
76
76
|
const failure = approvedFailure(error);
|
|
77
77
|
throw commandFailure(`${store.redact(failure?.message ?? error.message)}\nLocal migrations failed. Fix the error and run rer setup before trying again.`, failure ?? {});
|
|
78
78
|
}
|
|
@@ -124,7 +124,7 @@ function createContext(root, input, store, onApp, signal, guard) {
|
|
|
124
124
|
async run(label, command, args = [], { step = 'setup', ...options } = {}) {
|
|
125
125
|
if (guard) await guard(context);
|
|
126
126
|
try { return await store.run(label, command, args, { cwd: root, signal, ...options }); } catch (error) {
|
|
127
|
-
if (signal?.aborted || options.signal?.aborted) throw error;
|
|
127
|
+
if (signal?.aborted || options.signal?.aborted || isBusyFailure(error)) throw error;
|
|
128
128
|
throw installationFailure('command_failed', { step, diagnostic: error });
|
|
129
129
|
}
|
|
130
130
|
},
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { busyFailure } from './failures.mjs';
|
|
2
|
+
|
|
3
|
+
// A queued step the job queue never admitted is a busy machine, not a failed
|
|
4
|
+
// command: say what held it, the limit and the next step, in the same plain form
|
|
5
|
+
// as the server load guard (cli/server-resources.mjs).
|
|
6
|
+
const commandNames = new Set(['dev', 'setup', 'preview', 'build', 'deploy', 'verify']);
|
|
7
|
+
|
|
8
|
+
function waited(seconds) {
|
|
9
|
+
return seconds >= 60 ? `${Math.round(seconds / 60)} minutes` : `${Math.round(seconds)} seconds`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function busyMessage(result, { verb, maxWait }) {
|
|
13
|
+
const command = commandNames.has(verb) ? `rer ${verb}` : 'the same command';
|
|
14
|
+
const load = result.resources?.load, threshold = result.limits?.loadThreshold;
|
|
15
|
+
if (result.reasonCodes?.includes('load') && Number.isFinite(load) && threshold !== undefined) {
|
|
16
|
+
return `Not started: this computer is busy. Its 1-minute load is ${load.toFixed(1)} and jobs start only at ${threshold} or below; this step waited ${waited(maxWait)} for it to drop.\nTry again in a few minutes by running ${command} again, or start it anyway with a higher threshold, for example RER_JOBS_LOAD_THRESHOLD=${Math.ceil(Math.max(threshold, load) * 2)} ${command}.`;
|
|
17
|
+
}
|
|
18
|
+
return `Not started: the job queue did not admit this step within ${waited(maxWait)}: ${result.reason}.\nTry again in a few minutes by running ${command} again.`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const busyRefusal = (result, options) => busyFailure(busyMessage(result, options));
|
package/onboarding/commands.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { queuedCommand, queueLabel, commandPolicy } from './queue.mjs';
|
|
1
|
+
import { queuedCommand, queueLabel, commandPolicy, maxWaitSeconds } from './queue.mjs';
|
|
2
|
+
import { busyRefusal } from './busy.mjs';
|
|
2
3
|
import { spawn as spawnChild } from 'node:child_process';
|
|
3
4
|
import { writeSync } from 'node:fs';
|
|
4
5
|
import { join } from 'node:path';
|
|
@@ -148,8 +149,9 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
|
|
|
148
149
|
let queuedChild;
|
|
149
150
|
const commandSignal=signal&&options.signal?AbortSignal.any([signal,options.signal]):options.signal||signal;
|
|
150
151
|
const result = await queuedCommand(command,args,{...options,verb:queuePolicy.verb,signal:commandSignal,originalCI:policy.ci,
|
|
151
|
-
label:await queueLabel(options.cwd??process.cwd(),queuePolicy.verb,options.phase??'command'),report,onWaiting,
|
|
152
|
+
label:await queueLabel(options.cwd??process.cwd(),queuePolicy.verb,options.phase??'command'),report,onWaiting,maxWait:queuePolicy.maxWait,queueOptions:queuePolicy.sampler?{sampler:queuePolicy.sampler}:undefined,
|
|
152
153
|
spawn:(program,argv,native)=>(queuedChild=spawnCommand(label,program,argv,{...native,onChild:options.onChild,display:options.display})),cleanup:async(child,result)=>{await stopCommand(child);await options.afterCommand?.(result);}});
|
|
154
|
+
if(result?.timedOut)throw busyRefusal({...result,reason:redaction.redact(String(result.reason))},{verb:queuePolicy.verb,maxWait:queuePolicy.maxWait??maxWaitSeconds});
|
|
153
155
|
if(result){if(result.code!==0)throw failure(label,result,captures.get(queuedChild));return result;}
|
|
154
156
|
}
|
|
155
157
|
let child;try{child=spawnCommand(label,command,args,options);}catch{throw failure(label,options.signal?.aborted||signal?.aborted?{reason:'cancel'}:{error:true});}
|
package/onboarding/failures.mjs
CHANGED
|
@@ -37,6 +37,13 @@ export function commandFailure(message, details = {}) {
|
|
|
37
37
|
const error=new Error(message);approved.set(error,{code:'captured_command_failed',message,details:{...details}});return error;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
// The job queue held a step until its wait ran out. The message names the load, the
|
|
41
|
+
// limit and the next step; callers show it as a refusal, never as a failed command.
|
|
42
|
+
export function busyFailure(message) {
|
|
43
|
+
const error=new Error(message);approved.set(error,{code:'machine_busy',message,details:{exitCode:4}});return error;
|
|
44
|
+
}
|
|
45
|
+
export const isBusyFailure = error => approved.get(error)?.code==='machine_busy';
|
|
46
|
+
|
|
40
47
|
// Terminal callers may expose only diagnostics approved at the capture boundary.
|
|
41
48
|
// A prior diagnostic's metadata must not replace the current composed message.
|
|
42
49
|
export const approvedFailure = error => { const value=approved.get(error); return value ? {...value.details,...value} : undefined; };
|
package/onboarding/queue.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { createHash } from 'node:crypto';
|
|
|
4
4
|
import { readFile, realpath } from 'node:fs/promises';
|
|
5
5
|
const portable = basename(dirname(fileURLToPath(import.meta.url))) === 'base-onboarding';
|
|
6
6
|
const queueURL = new URL(portable ? '../base-cli/modules/job-queue/' : '../modules/job-queue/', import.meta.url);
|
|
7
|
+
export const maxWaitSeconds = 1200;
|
|
7
8
|
export const heavyVerbs = new Set(['install', 'setup', 'build', 'verify', 'dev', 'preview', 'deploy', 'release', 'export', 'import', 'installer']);
|
|
8
9
|
export const verificationBoundary = verb => verb === 'release' || verb === 'verify' || verb?.startsWith('verify:');
|
|
9
10
|
// The seed's display name (seed.json `name`, else its folder name) for terminal lines,
|
|
@@ -43,9 +44,9 @@ export async function queuedCommand(command, args, options) {
|
|
|
43
44
|
}
|
|
44
45
|
return null;
|
|
45
46
|
}
|
|
46
|
-
const queue = await createQueue();
|
|
47
|
+
const queue = await createQueue(options.queueOptions);
|
|
47
48
|
try {
|
|
48
|
-
const result = await queue.run([command, ...args], { ...options, kind: 'heavy', maxWait:
|
|
49
|
+
const result = await queue.run([command, ...args], { ...options, kind: 'heavy', maxWait: options.maxWait ?? maxWaitSeconds,
|
|
49
50
|
onWaiting: (reason, detail) => {
|
|
50
51
|
const wait = { ...(detail ?? { reason }), statusCommand, statusCommandText };
|
|
51
52
|
if (typeof options.onWaiting === 'function') return options.onWaiting(wait);
|