@runeditrun/rer 0.2.15 → 0.2.17
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/demo-host.mjs +4 -4
- package/cli/deploy-claim-request.mjs +32 -0
- package/cli/deploy-command.mjs +22 -8
- package/cli/deploy-hook.mjs +11 -3
- package/cli/deploy-observation.mjs +7 -4
- package/cli/deploy-owner.mjs +5 -4
- package/cli/deploy.mjs +4 -4
- package/cli/door.mjs +4 -3
- package/cli/local.mjs +5 -3
- package/cli/pnpm-probe.mjs +19 -10
- package/cli/port.mjs +17 -10
- package/cli/project-pnpm.mjs +4 -2
- package/cli/site-diagnostics.mjs +35 -0
- package/cli/site-render.mjs +4 -1
- package/cli/site.mjs +5 -0
- package/global/CHANGELOG.md +21 -0
- package/modules/container/boundary.mjs +70 -34
- package/modules/container/build.mjs +20 -3
- package/modules/container/import-graph.mjs +233 -0
- package/modules/demo-host/README.md +8 -1
- package/modules/demo-host/container.mjs +25 -6
- package/modules/demo-host/plan.mjs +12 -7
- package/modules/deploy-kit/deploy.mjs +8 -3
- package/modules/deploy-kit/health-request.mjs +14 -11
- package/modules/deploy-kit/health.mjs +16 -6
- package/modules/deploy-kit/owner-cli.mjs +24 -4
- package/modules/deploy-kit/owner.mjs +6 -3
- package/modules/deploy-kit/provider.mjs +6 -2
- package/modules/deploy-kit/readiness-window.mjs +32 -0
- package/modules/deploy-kit/uploaded-worker.mjs +22 -0
- package/modules/deploy-kit/worker.mjs +1 -1
- package/onboarding/adapter.mjs +13 -4
- package/onboarding/process-diagnostics.mjs +142 -36
- package/package.json +1 -1
package/cli/demo-host.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { dirname, join } from 'node:path';
|
|
|
4
4
|
import { contained } from './project.mjs';
|
|
5
5
|
import { invalid, missing, refuse, RerError } from './errors.mjs';
|
|
6
6
|
import { imageFolder } from './container.mjs';
|
|
7
|
-
import { DEMO_FILES, demoPlan } from '../modules/demo-host/plan.mjs';
|
|
7
|
+
import { DEMO_FILES, INSTANCE_TYPES, demoPlan } from '../modules/demo-host/plan.mjs';
|
|
8
8
|
|
|
9
9
|
// `rer deploy --demo [--dry-run]`: the seed's hosted demo at demo.<domain>
|
|
10
10
|
// (modules/demo-host), from deploy-demo.json. It writes .rer/demo-host/: the
|
|
@@ -19,7 +19,7 @@ export async function demoHostCommand(project, options, store, signal, out, oper
|
|
|
19
19
|
if (!(app.platforms ?? ['workers']).includes('container')) throw refuse('A hosted demo runs the seed\'s container image: declare "container" in deploy.json platforms first.');
|
|
20
20
|
let plan;
|
|
21
21
|
try { plan = demoPlan({ project: app.project, environment: options.environment ?? 'production', compatibilityDate: app.compatibilityDate, originVar: app.originVar, declaration, turnstileSiteKey: process.env.TURNSTILE_SITE_KEY?.trim() }); }
|
|
22
|
-
catch (error) { throw invalid(`The demo deploy declaration is invalid (${error.message}). deploy-demo.json holds {"version": 1, "domain": "<run site apex>", "name": "<product name>"}, optionally "maxInstances" and plain "settings".`); }
|
|
22
|
+
catch (error) { throw invalid(`The demo deploy declaration is invalid (${error.message}). deploy-demo.json holds {"version": 1, "domain": "<run site apex>", "name": "<product name>"}, optionally "maxInstances", "instanceType" (${INSTANCE_TYPES.join(', ')}; default basic) and plain "settings".`); }
|
|
23
23
|
if (options.remove) return removeDemo(plan, store);
|
|
24
24
|
if (process.env.RER_DEMO_OPERATOR_TOKEN && (process.env.RER_DEMO_OPERATOR_TOKEN.length < 32 || process.env.RER_DEMO_OPERATOR_TOKEN.length > 512)) throw invalid('RER_DEMO_OPERATOR_TOKEN must contain 32 to 512 characters.');
|
|
25
25
|
const folder = join(project.root, '.rer', 'demo-host');
|
|
@@ -29,9 +29,9 @@ export async function demoHostCommand(project, options, store, signal, out, oper
|
|
|
29
29
|
await imageFolder(project, operation, { ...app, secrets: [...(app.secrets ?? []), { binding: 'RER_DEMO_OPERATOR_TOKEN' }, { binding: 'TURNSTILE_SECRET_KEY' }] }, { output: join(folder, 'image'), engine: 'workerd' });
|
|
30
30
|
for (const file of DEMO_FILES) await cp(new URL(`../modules/demo-host/${file}`, import.meta.url), join(folder, file));
|
|
31
31
|
await writeFile(join(folder, 'wrangler.json'), JSON.stringify(plan.wrangler, null, 2) + '\n');
|
|
32
|
-
const summary = { worker: plan.worker, origin: plan.origin, hostname: plan.hostname, folder: '.rer/demo-host', maxInstances: plan.maxInstances, settings: plan.settings, instanceType:
|
|
32
|
+
const summary = { worker: plan.worker, origin: plan.origin, hostname: plan.hostname, folder: '.rer/demo-host', maxInstances: plan.maxInstances, settings: plan.settings, instanceType: plan.instanceType, startsPerIpPerMinute: 3, minutes: 60, idleMinutes: 15, enableInternet: false };
|
|
33
33
|
const human = [`Demo plan: Worker ${summary.worker} on ${summary.hostname} (custom domain; workers.dev off), written to ${summary.folder}`,
|
|
34
|
-
` one container per visitor (
|
|
34
|
+
` one container per visitor (${summary.instanceType}, at most ${summary.maxInstances} at once, no internet, RER_DEMO=1), 3 starts per IP per minute behind Turnstile`,
|
|
35
35
|
` each demo ends after 60 minutes or 15 idle minutes; its container is destroyed and its state deleted`];
|
|
36
36
|
if (options.dryRun) {
|
|
37
37
|
if (options.json) out.event('demo', summary); else for (const line of human) out.human(line);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { observedReadiness } from '../modules/deploy-kit/readiness-window.mjs';
|
|
2
|
+
// Retry only the bootstrap HTTP exchange, never the hook's other effects. The
|
|
3
|
+
// current invocation must prove it uploaded this token to a newly created Worker.
|
|
4
|
+
export async function ownerClaimRequest(fetch, input, init, { deployed, tokenKey = 'SETUP_TOKEN', signal } = {}) {
|
|
5
|
+
const url = new URL(input instanceof Request ? input.url : input);
|
|
6
|
+
if (deployed?.origin && url.origin !== deployed.origin) throw new Error('owner-claim-origin-mismatch');
|
|
7
|
+
const known = deployed?.propagation ? deployed : observedReadiness(url.origin);
|
|
8
|
+
const propagation = known?.propagation;
|
|
9
|
+
let token;
|
|
10
|
+
try { token = JSON.parse(typeof init.body === 'string' ? init.body : input instanceof Request ? await input.clone().text() : 'null')?.token; } catch {}
|
|
11
|
+
const fresh = propagation?.freshUpload && propagation.versionId === (deployed?.versionId ?? known.versionId) && propagation.matchesToken(tokenKey, token);
|
|
12
|
+
const window = fresh ? propagation.window : undefined;
|
|
13
|
+
for (;;) {
|
|
14
|
+
const remaining = window?.remaining() ?? 30000;
|
|
15
|
+
if (remaining <= 0) throw new Error('owner-claim-readiness-timeout');
|
|
16
|
+
const timeout = AbortSignal.timeout(Math.max(1, Math.ceil(Math.min(30000, remaining))));
|
|
17
|
+
const signals = [signal, init.signal, input instanceof Request ? input.signal : undefined, timeout].filter(Boolean);
|
|
18
|
+
const response = await fetch(input instanceof Request ? input.clone() : input, { ...init, redirect: 'manual', signal: AbortSignal.any(signals) });
|
|
19
|
+
if (response.redirected) throw new Error('owner-claim-redirected');
|
|
20
|
+
if (response.status === 303) {
|
|
21
|
+
const destination = response.headers.get('location');
|
|
22
|
+
if (destination && new URL(destination, url).origin !== url.origin) throw new Error('owner-claim-origin-mismatch');
|
|
23
|
+
}
|
|
24
|
+
let invalid = false;
|
|
25
|
+
if (fresh && response.status === 403) {
|
|
26
|
+
try { invalid = (await response.clone().json())?.error === 'invalid_setup_token'; } catch {}
|
|
27
|
+
}
|
|
28
|
+
if (!invalid || window.remaining() <= 0) return response;
|
|
29
|
+
await response.body?.cancel();
|
|
30
|
+
await window.pause();
|
|
31
|
+
}
|
|
32
|
+
}
|
package/cli/deploy-command.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { observedReadiness } from '../modules/deploy-kit/readiness-window.mjs';
|
|
1
2
|
import { readFile, readdir } from 'node:fs/promises';
|
|
2
3
|
import { contained } from './project.mjs';
|
|
3
4
|
import { invalid, refuse, RerError } from './errors.mjs';
|
|
@@ -43,7 +44,18 @@ export async function deployCommand(context) {
|
|
|
43
44
|
validateDeployOptions(options);
|
|
44
45
|
try { await refuseLocalModels(root); } catch { throw refuse('Deploy refuses the local-only key file .rer/local/models.json. Remove live-dev credentials before deployment.'); }
|
|
45
46
|
const { path, value: declaration } = await declarationFor(root, adapter);
|
|
46
|
-
ownerWorkerName(declaration.project, options.environment ?? 'production');
|
|
47
|
+
try { ownerWorkerName(declaration.project, options.environment ?? 'production'); }
|
|
48
|
+
catch (error) {
|
|
49
|
+
const message = {
|
|
50
|
+
'invalid-owner-environment': 'Invalid deployment environment: use at most 32 characters, starting with a lowercase letter, with lowercase letters or digits separated by single hyphens.',
|
|
51
|
+
'invalid-owner-project': 'Invalid deployment project in the deploy declaration: use a lowercase project name, optionally preceded by its owner and a slash.',
|
|
52
|
+
'owner-name-too-long': 'The project and environment produce a Worker name longer than 63 characters.',
|
|
53
|
+
}[error.message];
|
|
54
|
+
if (!message) throw error;
|
|
55
|
+
const failure = invalid(`${message} Nothing was uploaded.`);
|
|
56
|
+
store.report(failure.message);
|
|
57
|
+
throw failure;
|
|
58
|
+
}
|
|
47
59
|
const local = localOnlyBinding(declaration, localOnlyKeys);
|
|
48
60
|
if (local) throw refuse(`${path} names the local-only key ${local} as a deploy binding or secret. Remove it; local dev keys never reach a deployment.`);
|
|
49
61
|
// Custom hooks historically ignored these flags. Only the ownership controller
|
|
@@ -60,19 +72,19 @@ export async function deployCommand(context) {
|
|
|
60
72
|
// A hook keeping the kit's record in its own state file named it; every kit
|
|
61
73
|
// step after the hook (inspect, secret, record-owner) reads that record.
|
|
62
74
|
let hookRecord = await hookState(root, environment);
|
|
63
|
-
const command = (verb, extra = [], values = env) => owner([verb, '--declaration', path, '--environment', environment, ...(hookRecord ? ['--state', hookRecord] : []), ...extra], values, { cwd: root, localOnlyKeys });
|
|
75
|
+
const command = (verb, extra = [], values = env, more = {}) => owner([verb, '--declaration', path, '--environment', environment, ...(hookRecord ? ['--state', hookRecord] : []), ...extra], values, { cwd: root, localOnlyKeys, ...more });
|
|
64
76
|
// A hook that deployed through the kit's standard record lets rer issue and
|
|
65
77
|
// retire the setup token; a hook keeping an unnamed record of its own keeps its token.
|
|
66
78
|
let recorded;
|
|
67
|
-
const inspect = async () => {
|
|
68
|
-
try { return recorded = await command('inspect'); }
|
|
79
|
+
const inspect = async (origin = deployed?.origin) => {
|
|
80
|
+
try { return recorded = await command('inspect', [], env, {propagation:observedReadiness(origin)?.propagation}); }
|
|
69
81
|
catch (error) { if (error.message !== 'missing-owner-receipt') throw error; }
|
|
70
82
|
};
|
|
71
83
|
let observedClaims = [];
|
|
72
84
|
let deployed, claimed, linked = false, linkResult, step = 'custom deploy';
|
|
73
|
-
const link = async (token, origin) => { if (!linked) { const state = await inspect(); linkResult = await linkDependencies?.(state?.origin ?? origin, token); linked = true; } return linkResult; };
|
|
85
|
+
const link = async (token, origin) => { if (!linked) { const state = await inspect(origin); linkResult = await linkDependencies?.(state?.origin ?? origin, token); linked = true; } return linkResult; };
|
|
74
86
|
try {
|
|
75
|
-
return await observeOwner({ paths: ['/auth/bootstrap', adapter.hooks?.owner?.path, setupManifest?.steps?.find(item => item.type === 'owner-claim')?.path].filter(Boolean), inspect, beforeClaim: link, addSecret }, async claims => {
|
|
87
|
+
return await observeOwner({ paths: ['/auth/bootstrap', adapter.hooks?.owner?.path, setupManifest?.steps?.find(item => item.type === 'owner-claim')?.path].filter(Boolean), inspect, beforeClaim: link, addSecret, deployed: () => deployed, tokenKey: setupManifest?.steps?.find(item => item.type === 'owner-claim')?.tokenField }, async claims => {
|
|
76
88
|
observedClaims = claims;
|
|
77
89
|
const saved = { ...process.env };
|
|
78
90
|
try {
|
|
@@ -86,8 +98,9 @@ export async function deployCommand(context) {
|
|
|
86
98
|
await rememberHookState(root, environment, deployed?.state);
|
|
87
99
|
hookRecord = await hookState(root, environment);
|
|
88
100
|
const origin = hookOrigin(deployed, deployAgain(options));
|
|
101
|
+
const uploaded = observedReadiness(origin);
|
|
89
102
|
step = 'wait for the deployed source';
|
|
90
|
-
await waitForSource({ origin, sourceSha, again: deployAgain(options) });
|
|
103
|
+
await waitForSource({ origin, sourceSha, uploaded, again: deployAgain(options) });
|
|
91
104
|
step = 'verify recorded deployment';
|
|
92
105
|
const state = await inspect();
|
|
93
106
|
if ((state?.origin ?? origin) !== origin || claims.some(item => item.origin !== origin)) throw new Error('owner-claim-origin-mismatch');
|
|
@@ -95,8 +108,9 @@ export async function deployCommand(context) {
|
|
|
95
108
|
claimed = claims.at(-1)?.outcome;
|
|
96
109
|
step = 'claim owner';
|
|
97
110
|
if (typeof deployed.setupToken === 'string' && deployed.setupToken) addSecret(deployed.setupToken);
|
|
111
|
+
const sentSecrets = (uploaded?.sentSecrets ?? []).filter(binding => uploaded.propagation.matchesToken(binding, env[declaration.secrets.find(item => item.binding === binding)?.environment]));
|
|
98
112
|
const kit = state ? { secret: (extra, values) => command('secret', extra, values), recordClaim: outcome => command('record-owner', ['--outcome', outcome]) } : { token: deployed.setupToken || undefined };
|
|
99
|
-
claimed = await claimHostedOwner({ hook: adapter.hooks?.owner, setupManifest, declaration, deployed: { ...state, origin, owner: claimed, observedOwner: () => claims.at(-1)?.outcome }, env, supplied, ...kit, addSecret, beforeClaim: token => link(token, origin), store, signal: context.signal });
|
|
113
|
+
claimed = await claimHostedOwner({ hook: adapter.hooks?.owner, setupManifest, declaration, deployed: { ...state, sentSecrets, propagation:deployed.propagation ?? uploaded?.propagation, origin, owner: claimed, observedOwner: () => claims.at(-1)?.outcome }, env, supplied, ...kit, addSecret, beforeClaim: token => link(token, origin), store, signal: context.signal });
|
|
100
114
|
if (!linked) await linkDependencies?.(origin);
|
|
101
115
|
step = 'verify hosted setup';
|
|
102
116
|
await checkHostedSetup({ origin, claimed: claimed ?? state?.ownerClaim?.outcome ?? claims.at(-1)?.outcome, signal: context.signal });
|
package/cli/deploy-hook.mjs
CHANGED
|
@@ -12,8 +12,15 @@ export function hookOrigin(deployed, again) {
|
|
|
12
12
|
throw hookFailure(`The deploy hook finished without reporting a live deployment, so rer claimed no owner. A deploy hook returns { deployed: true, origin } once its upload is live. Check the hook's output above, fix the hook, then run ${again} again.`);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export async function waitForSource({ origin, sourceSha, again }) {
|
|
16
|
-
|
|
15
|
+
export async function waitForSource({ origin, sourceSha, uploaded, again }) {
|
|
16
|
+
// Only a kit upload observed in this hook invocation supplies a deadline and
|
|
17
|
+
// version. An external hook without that proof keeps its independent wait.
|
|
18
|
+
const propagation = uploaded?.propagation;
|
|
19
|
+
const fresh = propagation?.freshUpload && propagation.versionId === uploaded.versionId;
|
|
20
|
+
const window = fresh ? propagation.window : undefined;
|
|
21
|
+
try { await waitHealth({ origin, expected: { sourceSha, ...(uploaded?.versionId ? { versionId: uploaded.versionId } : {}) },
|
|
22
|
+
request: (url, init) => globalThis.fetch(url, init),
|
|
23
|
+
...(window ? { window, clock: window.clock, sleep: window.sleep, freshUpload: true } : {}) }); }
|
|
17
24
|
catch (error) {
|
|
18
25
|
const last = error.attempts?.at(-1);
|
|
19
26
|
let named;
|
|
@@ -22,7 +29,8 @@ export async function waitForSource({ origin, sourceSha, again }) {
|
|
|
22
29
|
: last.status !== 200 ? `its last answer was HTTP ${last.status}`
|
|
23
30
|
: typeof named === 'string' && /^[0-9a-f]{7,64}$/.test(named) ? `it still answers for commit ${named.slice(0, 12)}`
|
|
24
31
|
: 'it answers without a deploy identity';
|
|
25
|
-
|
|
32
|
+
const deadline = window?.remaining() <= 0 ? ' before the upload readiness deadline' : '';
|
|
33
|
+
throw hookFailure(`The deploy hook reported a deployment at ${origin}, but its /health never named this checkout's commit ${sourceSha.slice(0, 12)}${uploaded?.versionId ? ' and the uploaded Worker version' : ''}${deadline} (${seen}), so rer stopped before owner finalization. Check that the hook uploaded this build and that /health answers deploymentHealth(env), then run ${again} again.`);
|
|
26
34
|
}
|
|
27
35
|
}
|
|
28
36
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { observeReadiness, observedReadiness } from '../modules/deploy-kit/readiness-window.mjs';
|
|
2
|
+
import { ownerClaimRequest } from './deploy-claim-request.mjs';
|
|
1
3
|
// Observe the actual bootstrap exchange of a custom hook, including hooks that
|
|
2
4
|
// call the shared owner helper themselves. Never issue a second claim after it.
|
|
3
5
|
// The kit's deployment record, when the hook keeps one there, is checked before
|
|
4
6
|
// linking with its live setup token; rer checks the origin the hook returns too.
|
|
5
|
-
export async function observeOwner({ paths, inspect, beforeClaim, addSecret }, run) {
|
|
7
|
+
export async function observeOwner({ paths, inspect, beforeClaim, addSecret, deployed: knownDeployment, tokenKey }, run) {
|
|
6
8
|
const fetch = globalThis.fetch, claims = [];
|
|
7
9
|
globalThis.fetch = async (input, init = {}) => {
|
|
8
10
|
const url = new URL(input instanceof Request ? input.url : input);
|
|
@@ -12,10 +14,11 @@ export async function observeOwner({ paths, inspect, beforeClaim, addSecret }, r
|
|
|
12
14
|
}
|
|
13
15
|
if (typeof body?.token !== 'string' || !body.token) return fetch(input, init);
|
|
14
16
|
addSecret(body.token);
|
|
15
|
-
const deployed = await inspect();
|
|
17
|
+
const deployed = await inspect(url.origin);
|
|
16
18
|
if (deployed && url.origin !== deployed.origin) throw new Error('owner-claim-origin-mismatch');
|
|
17
19
|
await beforeClaim?.(body.token, url.origin);
|
|
18
|
-
const
|
|
20
|
+
const known = knownDeployment?.() ?? observedReadiness(url.origin);
|
|
21
|
+
const response = await ownerClaimRequest(fetch, input, init, {deployed:known ?? deployed, tokenKey});
|
|
19
22
|
let code;
|
|
20
23
|
if (response.status !== 303) {
|
|
21
24
|
try { code = (await response.clone().json()).error; } catch {}
|
|
@@ -24,6 +27,6 @@ export async function observeOwner({ paths, inspect, beforeClaim, addSecret }, r
|
|
|
24
27
|
claims.push({ origin: url.origin, outcome, status: response.status });
|
|
25
28
|
return response;
|
|
26
29
|
};
|
|
27
|
-
try { return await run(claims); }
|
|
30
|
+
try { return await observeReadiness(() => run(claims)); }
|
|
28
31
|
finally { globalThis.fetch = fetch; }
|
|
29
32
|
}
|
package/cli/deploy-owner.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ownerClaimRequest } from './deploy-claim-request.mjs';
|
|
1
2
|
import { observeOwner } from './deploy-observation.mjs';
|
|
2
3
|
import { randomBytes } from 'node:crypto';
|
|
3
4
|
|
|
@@ -55,7 +56,7 @@ export async function claimHostedOwner({ hook, setupManifest, declaration, deplo
|
|
|
55
56
|
let observed;
|
|
56
57
|
try {
|
|
57
58
|
if (deployed.observedOwner) await hook(context);
|
|
58
|
-
else await observeOwner({ paths: ['/auth/bootstrap', claim?.path].filter(Boolean), inspect, addSecret }, async claims => { await hook(context); observed = claims.at(-1)?.outcome; });
|
|
59
|
+
else await observeOwner({ paths: ['/auth/bootstrap', claim?.path].filter(Boolean), inspect, addSecret, deployed: () => deployed, tokenKey }, async claims => { await hook(context); observed = claims.at(-1)?.outcome; });
|
|
59
60
|
} catch (cause) { if (cause.message === 'owner-claim-failed') throw cause; throw ownerFailure(cause.message); }
|
|
60
61
|
// Function hooks can keep existing owners without returning a value. Observe
|
|
61
62
|
// their actual response, instead of assuming that a resolved promise claimed.
|
|
@@ -66,9 +67,9 @@ export async function claimHostedOwner({ hook, setupManifest, declaration, deplo
|
|
|
66
67
|
const displayName = (typeof hook.displayName === 'function' ? hook.displayName({}) : undefined) || 'Owner';
|
|
67
68
|
let response, code = 'no code';
|
|
68
69
|
try {
|
|
69
|
-
response = await fetch
|
|
70
|
-
headers: { Origin: deployed.origin, 'Content-Type': 'application/json' }, body: JSON.stringify({ token, displayName, returnTo: hook.returnTo ?? '/' }) });
|
|
71
|
-
} catch { throw ownerFailure('the hosted application did not answer'); }
|
|
70
|
+
response = await ownerClaimRequest(fetch, new URL(hook.path ?? '/auth/bootstrap', deployed.origin), { method: 'POST',
|
|
71
|
+
headers: { Origin: deployed.origin, 'Content-Type': 'application/json' }, body: JSON.stringify({ token, displayName, returnTo: hook.returnTo ?? '/' }) }, {deployed, tokenKey, signal});
|
|
72
|
+
} catch (error) { throw ownerFailure(['owner-claim-origin-mismatch','owner-claim-redirected','owner-claim-readiness-timeout'].includes(error.message) ? error.message : 'the hosted application did not answer'); }
|
|
72
73
|
if (response.status !== 303) { try { const body = await response.json(); if (typeof body?.error === 'string' && /^[a-z_]{1,64}$/.test(body.error)) code = body.error; } catch {} }
|
|
73
74
|
else await response.body?.cancel();
|
|
74
75
|
const outcome = response.status === 303 ? 'claimed' : response.status === 409 && code === 'already_initialized' ? 'kept' : undefined;
|
package/cli/deploy.mjs
CHANGED
|
@@ -79,12 +79,12 @@ export function ownerDeploy(declarationPath, lifecycle) {
|
|
|
79
79
|
const sent = supplied.filter(name => deployed.sentSecrets.includes(name));
|
|
80
80
|
if (sent.length) store.report(`rer supplied ${sent.join(', ')} from the local setup owner and fresh generated values.`);
|
|
81
81
|
step = 'health';
|
|
82
|
-
await owner('health');
|
|
82
|
+
await owner('health', [], env, {propagation:deployed.propagation});
|
|
83
83
|
step = 'claim owner';
|
|
84
|
-
const { liveSecrets, retiredSecrets, ownerClaim } = await owner('inspect');
|
|
84
|
+
const { liveSecrets, retiredSecrets, ownerClaim } = await owner('inspect', [], env, {propagation:deployed.propagation});
|
|
85
85
|
const linked = token => linkDependencies?.(deployed.origin, token);
|
|
86
|
-
const claimed = await claimHostedOwner({ hook: lifecycle.hooks?.owner, setupManifest, declaration, deployed: { ...deployed, liveSecrets, retiredSecrets, ownerClaim }, env, supplied, addSecret: value => { redaction.addSecrets([value]); store.addSecrets?.([value]); },
|
|
87
|
-
secret: (extra, values) => owner('secret', extra, values), beforeClaim: linked, recordClaim: outcome => owner('record-owner', ['--outcome', outcome]), inspect: () => owner('inspect'), store, signal });
|
|
86
|
+
const claimed = await claimHostedOwner({ hook: lifecycle.hooks?.owner, setupManifest, declaration, deployed: { ...deployed, propagation:deployed.propagation, liveSecrets, retiredSecrets, ownerClaim }, env, supplied, addSecret: value => { redaction.addSecrets([value]); store.addSecrets?.([value]); },
|
|
87
|
+
secret: (extra, values) => owner('secret', extra, values), beforeClaim: linked, recordClaim: outcome => owner('record-owner', ['--outcome', outcome]), inspect: () => owner('inspect', [], env, {propagation:deployed.propagation}), store, signal });
|
|
88
88
|
// A seed that claims its owner its own way links with the token it was given.
|
|
89
89
|
if (claimed === undefined) await linked(env[declared(claim?.tokenField ?? 'SETUP_TOKEN')?.environment]);
|
|
90
90
|
step = 'verify hosted setup';
|
package/cli/door.mjs
CHANGED
|
@@ -241,11 +241,12 @@ export async function verifyDoor(env, port) {
|
|
|
241
241
|
|
|
242
242
|
async function verifyOnce(env, port) {
|
|
243
243
|
const directory = doorDirectory(env), record = await runningDoor(env);
|
|
244
|
-
const { listeners, processName } = await shared('process-diagnostics.mjs');
|
|
245
|
-
const
|
|
244
|
+
const { listeners, processName, inspectionContext } = await shared('process-diagnostics.mjs');
|
|
245
|
+
const context = inspectionContext();
|
|
246
|
+
const holders = (await listeners(undefined,context,port)).filter(row => row.names.some(name => portOf(name) === port));
|
|
246
247
|
const foreign = holders.find(row => row.pid !== record?.pid);
|
|
247
248
|
const withheld = 'No sign-in link was printed.';
|
|
248
|
-
if (foreign) throw refuse(`Port ${port} is held by PID ${foreign.pid} (${await processName(foreign.pid)}), which is not this account's front door${record ? ` (PID ${record.pid})` : ''}. ${withheld} Stop PID ${foreign.pid}, then run rer door restart.`);
|
|
249
|
+
if (foreign) throw refuse(`Port ${port} is held by PID ${foreign.pid} (${await processName(foreign.pid,context)}), which is not this account's front door${record ? ` (PID ${record.pid})` : ''}. ${withheld} Stop PID ${foreign.pid}, then run rer door restart.`);
|
|
249
250
|
if (!record || record.port !== port) throw refuse(`The front door is not running on port ${port}. ${withheld} Start it with rer door start, then run this again.`);
|
|
250
251
|
const token = (await readPrivate(join(directory, 'token')))?.trim();
|
|
251
252
|
if (!token) throw refuse(`The front door's token is missing from ${directory}. ${withheld} Run rer door restart.`);
|
package/cli/local.mjs
CHANGED
|
@@ -40,16 +40,18 @@ export async function selectedOrigin(project, options, { setup = false } = {}) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export async function availablePort(host, port, { root, saved = false } = {}) {
|
|
43
|
+
const { portListener, inspectionContext } = await shared('process-diagnostics.mjs');
|
|
44
|
+
const context = inspectionContext();
|
|
43
45
|
const socket = createServer();
|
|
44
46
|
try { await new Promise((resolve, reject) => { socket.once('error', reject); socket.listen(port, host, resolve); }); }
|
|
45
47
|
catch (error) {
|
|
46
48
|
if (error.code !== 'EADDRINUSE') throw refuse(`Port ${port} cannot be used on ${host}: ${error.code ?? error.message}.`);
|
|
47
|
-
throw refuse(await busyPortMessage({ port, host, root, saved }));
|
|
49
|
+
throw refuse(await busyPortMessage({ port, host, root, saved, context }));
|
|
48
50
|
}
|
|
49
51
|
finally { if (socket.listening) await new Promise(resolve => socket.close(resolve)); }
|
|
50
52
|
// A server on every address (*:port) lets a bind to 127.0.0.1 succeed.
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
53
|
+
const listener = await portListener(port, host, context);
|
|
54
|
+
if (listener) throw refuse(await busyPortMessage({ port, host, root, saved, context, listener }));
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
export {setupInput} from './setup-input.mjs';
|
package/cli/pnpm-probe.mjs
CHANGED
|
@@ -8,17 +8,26 @@ import { shared } from './shared.mjs';
|
|
|
8
8
|
export async function probePnpm(root, store, signal, env = process.env, timeoutMs = 10000) {
|
|
9
9
|
const { dependencyEnvironment } = await shared('dependency-environment.mjs');
|
|
10
10
|
const timeout = AbortSignal.timeout(timeoutMs), probeSignal = AbortSignal.any([signal, timeout].filter(Boolean));
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
let child, result, cleanup, version = '', errors = '';
|
|
12
|
+
// Redact before bounding the text: a limit must not cut through a secret.
|
|
13
|
+
const filter = store.redactionStream(text => { errors = (errors + text).slice(-4096); });
|
|
14
|
+
try {
|
|
15
|
+
child = store.spawn('Checking pinned pnpm', 'pnpm', ['--version'], { cwd: root, env: dependencyEnvironment(env), signal: probeSignal });
|
|
16
|
+
child.stdout.on('data', chunk => { version = (version + chunk).slice(-1024); });
|
|
17
|
+
child.stderr.on('data', chunk => filter.write(chunk));
|
|
18
|
+
result = await new Promise(resolve => { child.once('error', error => resolve({ code: null, error })); child.once('exit', (code, exitSignal) => resolve({ code, exitSignal })); });
|
|
19
|
+
} catch (error) { result = { code: null, error }; }
|
|
20
|
+
if (child) try { await store.stop(child); } catch (error) { cleanup = store.redact(String(error.message)); }
|
|
21
|
+
filter.end();
|
|
22
|
+
const { code, exitSignal, error } = result;
|
|
23
|
+
if (code === 0 && !probeSignal.aborted && !cleanup) return version.trim();
|
|
24
|
+
const line = errors.split('\n').map(text => text.trim()).find(Boolean)?.slice(0, 200);
|
|
19
25
|
const reason = timeout.aborted ? `pnpm --version gave no answer within ${timeoutMs / 1000} s`
|
|
20
|
-
: error ? `pnpm could not start (${error.code ?? error.message})`
|
|
26
|
+
: error ? `pnpm could not start (${store.redact(error.code ?? error.message)})`
|
|
27
|
+
: cleanup ? `pnpm --version exited ${code}; process cleanup failed: ${cleanup}`
|
|
21
28
|
: code === null ? `pnpm --version was stopped by ${exitSignal}`
|
|
22
29
|
: `pnpm --version exited ${code}${line ? `: ${line}` : ''}`;
|
|
23
|
-
|
|
30
|
+
const diagnostic = `Command: pnpm --version\nExit code: ${code ?? 'none'}; signal: ${exitSignal ?? 'none'}\nStderr (redacted):\n${errors.trim() || '(no stderr)'}`;
|
|
31
|
+
const message = `The pinned pnpm version probe failed (${reason}).\n${diagnostic}\nSelect the documented tool.`;
|
|
32
|
+
throw Object.assign(missing(message), { reason, diagnostic });
|
|
24
33
|
}
|
package/cli/port.mjs
CHANGED
|
@@ -17,18 +17,22 @@ async function bindable(host, port) {
|
|
|
17
17
|
// The first port from `from` that nothing listens on, on any address, and that
|
|
18
18
|
// this host can bind. Another checkout's server may listen on every address,
|
|
19
19
|
// which a bind to 127.0.0.1 alone does not notice.
|
|
20
|
-
export async function firstFreePort(host, from = defaultPort) {
|
|
21
|
-
const { listeningPorts } = await shared('process-diagnostics.mjs');
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
export async function firstFreePort(host, from = defaultPort, context) {
|
|
21
|
+
const { listeningPorts, inspectionContext } = await shared('process-diagnostics.mjs');
|
|
22
|
+
context ??= inspectionContext();
|
|
23
|
+
const busy = await listeningPorts(context);
|
|
24
|
+
for (let port = from; port <= 65535; port++) {
|
|
25
|
+
if (performance.now() >= context.deadline) throw Error('Free-port search stopped at the shared inspection deadline.');
|
|
26
|
+
if (!busy.has(port) && await bindable(host, port)) return port;
|
|
27
|
+
}
|
|
24
28
|
throw Error(`No free port from ${from} upward.`);
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
// Who holds a port: a server another checkout registered (its path and the
|
|
28
32
|
// command that stops it), else the process and its working directory.
|
|
29
|
-
export async function portHolder(port, host, root, env = process.env) {
|
|
33
|
+
export async function portHolder(port, host, root, env = process.env, context, observed) {
|
|
30
34
|
const { portListener } = await shared('process-diagnostics.mjs');
|
|
31
|
-
const listener = await portListener(port, host);
|
|
35
|
+
const listener = observed ?? await portListener(port, host, context);
|
|
32
36
|
if (!listener) return undefined;
|
|
33
37
|
const state = await readJson(join(serversDirectory(env), 'state.json'), { running: [] }).catch(() => ({ running: [] }));
|
|
34
38
|
const record = (state.running ?? []).find(item => item.owner?.pid === listener.pid && item.port === port);
|
|
@@ -37,12 +41,15 @@ export async function portHolder(port, host, root, env = process.env) {
|
|
|
37
41
|
|
|
38
42
|
// The refusal for a busy port. For a checkout that wants to move, it names the
|
|
39
43
|
// holder and gives the exact command that moves this checkout to a free port.
|
|
40
|
-
export async function busyPortMessage({ port, host, root, saved, env = process.env }) {
|
|
41
|
-
const
|
|
42
|
-
|
|
44
|
+
export async function busyPortMessage({ port, host, root, saved, env = process.env, context, listener }) {
|
|
45
|
+
const { inspectionContext } = await shared('process-diagnostics.mjs');
|
|
46
|
+
context ??= inspectionContext();
|
|
47
|
+
const holder = await portHolder(port, host, root, env, context, listener);
|
|
48
|
+
|
|
43
49
|
const kind = saved ? `Port ${port} is saved for this checkout but is` : `Port ${port} is`;
|
|
44
|
-
if (!holder) return `${kind}
|
|
50
|
+
if (!holder) return `${kind} unavailable for binding; completed inspection found no listener on ${host}. Pick a free port or retry after checking local socket availability.`;
|
|
45
51
|
if (holder.own) return `${kind} held by this checkout's own ${holder.server.mode} server (PID ${holder.pid}). Stop it with: ${stopInstruction(holder.server)}`;
|
|
52
|
+
const next = await firstFreePort(host, port + 1, context).catch(() => undefined);
|
|
46
53
|
const who = holder.server
|
|
47
54
|
? `the ${holder.server.mode} server for ${holder.checkout} (PID ${holder.pid})`
|
|
48
55
|
: `PID ${holder.pid} (${holder.command})${holder.cwd ? ` running in ${holder.cwd}` : ''}`;
|
package/cli/project-pnpm.mjs
CHANGED
|
@@ -19,7 +19,7 @@ export async function projectPnpmPin(root) {
|
|
|
19
19
|
}
|
|
20
20
|
async function probe(root, env, signal, store, timeoutMs) {
|
|
21
21
|
try { return { version: await probePnpm(root, store, signal, env, timeoutMs) }; }
|
|
22
|
-
catch (error) { if (signal?.aborted) throw error; return { reason: error.reason ?? error.message }; }
|
|
22
|
+
catch (error) { if (signal?.aborted) throw error; return { reason: error.reason ?? error.message, diagnostic: error.diagnostic }; }
|
|
23
23
|
}
|
|
24
24
|
export async function ensureProjectPnpm(root, options = {}) {
|
|
25
25
|
if (options.store) return ensure(root, options);
|
|
@@ -71,5 +71,7 @@ async function ensure(root, { env = process.env, signal, report = () => {}, stor
|
|
|
71
71
|
if (result.version === pin) { Object.assign(env, supplied); return env; }
|
|
72
72
|
}
|
|
73
73
|
const failed = result.version === undefined ? result.reason : `it reported ${JSON.stringify(result.version.slice(0, 64))}`;
|
|
74
|
-
|
|
74
|
+
const message = `The verified pnpm ${pin} did not report the project version after 3 tries (${failed}).${result.diagnostic ? `\n${result.diagnostic}\n` : ' '}Run ${shellQuote(join(directory, 'pnpm'))} --version to inspect it, then rerun rer.`;
|
|
75
|
+
store.report(message);
|
|
76
|
+
throw missing(message);
|
|
75
77
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
3
|
+
|
|
4
|
+
// Vite and config plugins can write directly, before a build rejects. Redact
|
|
5
|
+
// at this child process's output boundary, including paths split across writes.
|
|
6
|
+
export function redactSiteText(text) {
|
|
7
|
+
return text.replaceAll(homedir(), '~')
|
|
8
|
+
.replace(/\/(?:Users|home)\/[^/\s:)'"<>]+/g, '~')
|
|
9
|
+
.replace(/[A-Za-z]:[\\/]+(?:Users|Documents and Settings)[\\/]+[^\\/\r\n:)'"<>]+/gi, '~');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function redactSiteOutput() {
|
|
13
|
+
for (const stream of [process.stdout, process.stderr]) {
|
|
14
|
+
const write = stream.write.bind(stream), decoder = new StringDecoder('utf8');
|
|
15
|
+
let pending = '';
|
|
16
|
+
stream.write = (chunk, encoding, callback) => {
|
|
17
|
+
if (typeof encoding === 'function') { callback = encoding; encoding = undefined; }
|
|
18
|
+
pending += typeof chunk === 'string' ? chunk : decoder.write(chunk);
|
|
19
|
+
const end = pending.lastIndexOf('\n') + 1;
|
|
20
|
+
const ready = pending.slice(0, end); pending = pending.slice(end);
|
|
21
|
+
if (ready) return write(redactSiteText(ready), encoding, callback);
|
|
22
|
+
callback?.(); return true;
|
|
23
|
+
};
|
|
24
|
+
process.on('exit', () => { pending += decoder.end(); if (pending) write(redactSiteText(pending)); });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function siteBuildDiagnostic(error) {
|
|
29
|
+
const message = String(error?.message ?? error);
|
|
30
|
+
const plugin = error?.plugin && !message.includes(error.plugin) ? `[plugin ${error.plugin}]\n` : '';
|
|
31
|
+
const file = error?.loc?.file ?? error?.id;
|
|
32
|
+
const location = file ? `${file}${error.loc?.line ? `:${error.loc.line}${error.loc.column !== undefined ? `:${error.loc.column}` : ''}` : ''}` : '';
|
|
33
|
+
const frame = error?.frame && !message.includes(error.frame) ? error.frame : '';
|
|
34
|
+
return [plugin + message, location && !message.includes(location) ? location : '', frame].filter(Boolean).join('\n');
|
|
35
|
+
}
|
package/cli/site-render.mjs
CHANGED
|
@@ -14,6 +14,9 @@ import { createRequire } from 'node:module';
|
|
|
14
14
|
import { dirname, join, resolve, sep } from 'node:path';
|
|
15
15
|
import { pathToFileURL } from 'node:url';
|
|
16
16
|
import { buildClients, writeSiteAsset } from './site-client.mjs';
|
|
17
|
+
import { redactSiteOutput, siteBuildDiagnostic } from './site-diagnostics.mjs';
|
|
18
|
+
|
|
19
|
+
redactSiteOutput();
|
|
17
20
|
|
|
18
21
|
const [root, entry, output, config, clientJSON] = process.argv.slice(2);
|
|
19
22
|
const fail = message => { process.stderr.write(`${message}\n`); process.exit(2); };
|
|
@@ -38,7 +41,7 @@ try {
|
|
|
38
41
|
ssr: resolve(root, entry), outDir: server, emptyOutDir: true, copyPublicDir: false, ssrEmitAssets: true,
|
|
39
42
|
cssCodeSplit: false, assetsDir: ASSETS, sourcemap: false, minify: false, reportCompressedSize: false, watch: null,
|
|
40
43
|
},
|
|
41
|
-
}).catch(error => fail(`The run site entry ${entry} did not build: ${error
|
|
44
|
+
}).catch(error => fail(`The run site entry ${entry} did not build: ${siteBuildDiagnostic(error)}${config ? '' : '\nIf its pages need Vite plugins (a docs virtual module, a CSS toolchain), name a site Vite config: site: { config } in the command adapter.'}`));
|
|
42
45
|
const outputs = (Array.isArray(built) ? built : [built]).flatMap(result => result.output ?? []);
|
|
43
46
|
const chunk = outputs.find(item => item.type === 'chunk' && item.isEntry);
|
|
44
47
|
if (!chunk) fail(`The run site entry ${entry} produced no module.`);
|
package/cli/site.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { readDevKey } from './dev-identity.mjs';
|
|
|
8
8
|
import { shared } from './shared.mjs';
|
|
9
9
|
import { unpublishedIdentities } from './site-private.mjs';
|
|
10
10
|
import { privateSitePaths } from './site-inputs.mjs';
|
|
11
|
+
import { redactSiteText } from './site-diagnostics.mjs';
|
|
11
12
|
|
|
12
13
|
// The run site: a seed's static marketing pages, /run and docs, built from
|
|
13
14
|
// edition identity with no installation data. A seed opts in with
|
|
@@ -62,6 +63,10 @@ export async function buildSite(project, store, signal) {
|
|
|
62
63
|
const code = await readFile(`${staging}.refusal`, 'utf8').catch(() => '');
|
|
63
64
|
if (code === 'site_private_input') throw new RerError(code, 'Run site client imports a private installation file or a file outside the seed and its declared dependencies.', 4);
|
|
64
65
|
if (code === 'site_client_server_import') throw new RerError(code, 'Run site client imports a server-only module. Use browser dependencies in every reachable island module.', 4);
|
|
66
|
+
// Command capture appends its absolute log path after the child output.
|
|
67
|
+
const { approvedFailure, commandFailure } = await shared('failures.mjs');
|
|
68
|
+
const diagnostic = approvedFailure(error);
|
|
69
|
+
if (diagnostic) throw commandFailure(redactSiteText(diagnostic.message), diagnostic);
|
|
65
70
|
throw error;
|
|
66
71
|
}
|
|
67
72
|
const checked = await checkSite(staging, {root:project.root, ...await privateValues(project)});
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.17
|
|
4
|
+
|
|
5
|
+
- Container builds check the app's reachable runtime imports from Wrangler main and fresh server output. Dormant source files and ordinary calls containing cloudflare-looking strings no longer fail the boundary; reachable Node-engine restrictions remain.
|
|
6
|
+
- Site builds preserve complete plugin diagnostics and source locations while redacting absolute home paths.
|
|
7
|
+
- Fresh Worker deploys wait for the uploaded version and secrets before the owner claim. A matching fresh setup token that has not propagated and a fresh workers.dev 1042/404 readback retry inside the existing upload deadline; wrong tokens and unrelated 404s still fail.
|
|
8
|
+
- Demo removal accepts empty successful DELETE responses, so removing a recorded demo with its Custom Domain completes in one command.
|
|
9
|
+
- Local dev, setup and demo inspect the started process tree with nonblocking macOS socket queries. Slow or failed diagnostics retry within one 15-second bound; unresolved ownership refuses with the command and bound instead of falsely naming another owner.
|
|
10
|
+
|
|
11
|
+
### Upgrade notes
|
|
12
|
+
|
|
13
|
+
- Update the exact rer package pin, or refresh vendored operating commands, to receive these changes. Rebuild container images for the import-graph boundary. Existing local data and seed-owned application source are unchanged.
|
|
14
|
+
|
|
15
|
+
## 0.2.16
|
|
16
|
+
|
|
17
|
+
- A hosted demo's container stays up until the visitor's 15 idle minutes or the demo's hour, however long the visitor goes without a request. Before, the platform stopped it about three minutes after the last request, the next request got a Cloudflare 500, and its place stayed held. A container that is gone anyway (stopped by the platform, or failing once stopped) now ends its demo, frees its place at once and answers the ended page (410, with "Start a new demo").
|
|
18
|
+
- `deploy-demo.json` takes an optional `instanceType`, one of Cloudflare Containers' predefined types (`lite`, `basic`, `standard-1` to `standard-4`); `basic` unless set, so existing demos are unchanged. `rer deploy --demo --dry-run` prints the planned type and refuses any other value. DEMO.md notes what a larger type costs.
|
|
19
|
+
|
|
20
|
+
### Upgrade notes
|
|
21
|
+
|
|
22
|
+
- Update the exact rer package pin and redeploy hosted demos (`rer deploy --demo`, or run-demo) to receive the keepalive. Demos already running end as before. Set `instanceType` (for example `standard-1`) only where a faster start is worth the cost.
|
|
23
|
+
|
|
3
24
|
## 0.2.15
|
|
4
25
|
|
|
5
26
|
- Demo pages show a slim strip pinned to the top, collapsed by default. Captured mail and blocked-send details open in a popover without moving the page.
|