@runeditrun/rer 0.2.86 → 0.2.87
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/agent-bindings.mjs +25 -0
- package/cli/agent-door.mjs +9 -13
- package/cli/agent-journey-fixtures.mjs +17 -0
- package/cli/agent-reviewers.mjs +1 -1
- package/cli/agent-rpc.mjs +23 -0
- package/cli/agent-sponsors.mjs +2 -2
- package/cli/agent-verifier.mjs +31 -0
- package/cli/deploy-variables.mjs +48 -17
- package/cli/export.mjs +1 -0
- package/cli/hosted-output.mjs +15 -2
- package/cli/managed-data.mjs +8 -4
- package/cli/portability-worker.mjs +2 -1
- package/cli/portability.mjs +1 -0
- package/cli/production-auth.mjs +1 -1
- package/cli/production-mail.mjs +11 -1
- package/cli/server-registry.mjs +2 -0
- package/edition-authoring/archive-source.mjs +7 -1
- package/edition-authoring/base-copies.mjs +17 -4
- package/edition-authoring/copy-namespaces.mjs +28 -0
- package/edition-authoring/files.mjs +2 -1
- package/edition-authoring/module-closure.mjs +56 -11
- package/edition-authoring/module-edges.mjs +13 -2
- package/foundation/runtime/contract-docs.mjs +5 -0
- package/global/CHANGELOG.md +58 -0
- package/modules/agent-door/conformance/audit-pages.mjs +11 -0
- package/modules/agent-door/conformance/audit-rows.mjs +20 -0
- package/modules/agent-door/conformance/audit.mjs +10 -13
- package/modules/agent-door/conformance/fixtures.mjs +41 -0
- package/modules/agent-door/conformance/index.mjs +4 -4
- package/modules/agent-door/conformance/injection.mjs +24 -0
- package/modules/agent-door/conformance/invocation.mjs +1 -0
- package/modules/agent-door/conformance/journey.mjs +19 -14
- package/modules/agent-door/conformance/narrowing.d.mts +1 -0
- package/modules/agent-door/conformance/narrowing.mjs +15 -7
- package/modules/agent-door/conformance/negative.mjs +1 -0
- package/modules/agent-door/conformance/network-modules.mjs +4 -4
- package/modules/agent-door/conformance/policy-phases.mjs +12 -4
- package/modules/agent-door/conformance/protocol.mjs +22 -14
- package/modules/agent-door/conformance/replay.mjs +7 -6
- package/modules/agent-door/conformance/security.mjs +3 -2
- package/modules/agent-door/conformance/step-hooks.mjs +4 -0
- package/modules/agent-door/conformance/surface.mjs +7 -4
- package/modules/agent-door/conformance/target.mjs +2 -1
- package/modules/agent-door/conformance/webhooks.mjs +2 -1
- package/modules/delivery-producer/mail.mjs +20 -0
- package/modules/portability/README.md +5 -2
- package/modules/portability/catalogue.mjs +12 -2
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { contained } from './project.mjs';
|
|
4
|
+
import { RerError } from './errors.mjs';
|
|
5
|
+
|
|
6
|
+
export const ownerBindingValues = ['issuer', 'installationId', 'appOrigin', 'publicKeys', 'email', 'sub', 'token', 'sessionSecret'];
|
|
7
|
+
export const bindingGenerator = value => value && typeof value === 'object' && Object.keys(value).join(',') === 'module' && typeof value.module === 'string';
|
|
8
|
+
|
|
9
|
+
// Factories are trusted test tooling. Their output exists only in the fresh
|
|
10
|
+
// installation; never persist it or include a thrown value in diagnostics.
|
|
11
|
+
export async function verificationBindings(root, bindings = {}, values) {
|
|
12
|
+
const result = {};
|
|
13
|
+
for (const [name, source] of Object.entries(bindings)) {
|
|
14
|
+
if (typeof source === 'string') { result[name] = values[source]; continue; }
|
|
15
|
+
try {
|
|
16
|
+
await contained(root, source.module);
|
|
17
|
+
const generate = (await import(pathToFileURL(resolve(root, source.module)))).default;
|
|
18
|
+
if (typeof generate !== 'function') throw new Error();
|
|
19
|
+
const value = await generate(Object.freeze({ ...values }));
|
|
20
|
+
if (typeof value !== 'string' || !value.length || Buffer.byteLength(value) > 64 * 1024) throw new Error();
|
|
21
|
+
result[name] = value;
|
|
22
|
+
} catch { throw new RerError('agent_owner_invalid', 'Native verification binding generation failed. The contained module must default-export a generator returning a nonempty string of at most 64 KiB; private values are not logged.', 1); }
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
package/cli/agent-door.mjs
CHANGED
|
@@ -13,6 +13,9 @@ import { RerError } from './errors.mjs';
|
|
|
13
13
|
import { verificationReviewers } from './agent-reviewers.mjs';
|
|
14
14
|
import { verificationSponsors } from './agent-sponsors.mjs';
|
|
15
15
|
import { verificationWebhooks } from './agent-webhooks.mjs';
|
|
16
|
+
import { verificationInvoke, verificationJourney } from './agent-verifier.mjs';
|
|
17
|
+
import { verificationBindings } from './agent-bindings.mjs';
|
|
18
|
+
import { journeyFixtures } from './agent-journey-fixtures.mjs';
|
|
16
19
|
|
|
17
20
|
function finish(result, report) {
|
|
18
21
|
for (const point of result.points) report(`${point.ok ? 'PASS' : 'FAIL'} ${point.id}${point.ok || !point.detail ? '' : `: ${point.detail}`}`);
|
|
@@ -31,6 +34,7 @@ export async function checkAgentDoor(root, { declaration, setupManifest, owner,
|
|
|
31
34
|
const manifest = setupManifest ?? JSON.parse(await readFile(join(root, 'rer-setup.json'), 'utf8'));
|
|
32
35
|
const claim = manifest.steps?.find(step => step.type === 'owner-claim');
|
|
33
36
|
const verification = declared.surface.verification ?? {};
|
|
37
|
+
const workerDriver = await verificationInvoke(root, verification.invoke);
|
|
34
38
|
let prove;
|
|
35
39
|
if (verification.proof !== undefined) {
|
|
36
40
|
if (typeof verification.proof?.module !== 'string' || Object.keys(verification.proof).join(',') !== 'module') throw new RerError('agent_proof_invalid', 'verification.proof must name a contained test module.', 1);
|
|
@@ -49,11 +53,11 @@ export async function checkAgentDoor(root, { declaration, setupManifest, owner,
|
|
|
49
53
|
const { kty, crv, x, y } = await webcrypto.subtle.exportKey('jwk', pair.publicKey);
|
|
50
54
|
const publicKeys = { [kid]: { kty, crv, x, y, kid, alg: 'ES256', use: 'sig' } };
|
|
51
55
|
const values = { issuer, installationId, appOrigin: HOSTED_ORIGIN, publicKeys: JSON.stringify(publicKeys), email, sub, token, sessionSecret: randomBytes(32).toString('hex') };
|
|
52
|
-
const nativeBindings =
|
|
56
|
+
const nativeBindings = await verificationBindings(root, native.bindings, values);
|
|
53
57
|
const network = await createAgentConformanceNetwork(root, verification.network, { email });
|
|
54
58
|
let hosted;
|
|
55
59
|
try {
|
|
56
|
-
hosted = await serveHosted(root, { declaration, outboundService: async request => {
|
|
60
|
+
hosted = await serveHosted(root, { declaration, rpc: verification.rpc, workerEntrypoints: workerDriver ? [workerDriver.entrypoint] : [], outboundService: async request => {
|
|
57
61
|
const copy = reviewers.observes(request) ? request.clone() : null, response = await network.fetch(request);
|
|
58
62
|
if (copy) await reviewers.capture(copy, response.clone());
|
|
59
63
|
return response;
|
|
@@ -125,18 +129,10 @@ export async function checkAgentDoor(root, { declaration, setupManifest, owner,
|
|
|
125
129
|
}
|
|
126
130
|
const secrets = await network.provision(hosted);
|
|
127
131
|
const webhooks = await verificationWebhooks(root, verification.webhooks, secrets);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
await contained(root, verification.journey);
|
|
131
|
-
const journey = (await import(pathToFileURL(resolve(root, verification.journey)))).default;
|
|
132
|
-
if (typeof journey !== 'function') throw new RerError('agent_journey_invalid', 'verification.journey must default-export an async native journey.', 1);
|
|
133
|
-
nativeJourney = async ({ tool }) => {
|
|
134
|
-
try { await journey({ request, origin: hosted.origin, email, cookie, mail: network.mail, fixtures: network.fixtures, tool }); }
|
|
135
|
-
catch { throw new Error('Native verification journey failed; no captured mail or fixture values are logged.'); }
|
|
136
|
-
};
|
|
137
|
-
}
|
|
132
|
+
const journey = await verificationJourney(root, verification.journey, { request, origin: hosted.origin, email, cookie, mail: network.mail, fixtures: network.fixtures });
|
|
133
|
+
const prepare = await journeyFixtures(root, verification.fixtures, { request, origin: hosted.origin, email, cookie, mail: network.mail, fixtures: network.fixtures });
|
|
138
134
|
const result = await runAgentDoorConformance({ fetch: request, origin: hosted.origin, surface: declared.surface,
|
|
139
|
-
signer: { issuer, installationId, kid, privateKey: pair.privateKey }, person: sponsors[0], sponsors, webhooks, business, prove,
|
|
135
|
+
signer: { issuer, installationId, kid, privateKey: pair.privateKey }, person: sponsors[0], sponsors, webhooks, business, prove, ...journey, prepare, invoke: workerDriver?.run(hosted),
|
|
140
136
|
});
|
|
141
137
|
const points = [...result.points, ...reviewers.points()];
|
|
142
138
|
return finish({ ...result, points, ok: points.every(point => point.ok) }, report);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { contained } from './project.mjs';
|
|
4
|
+
import { RerError } from './errors.mjs';
|
|
5
|
+
|
|
6
|
+
/** Test tooling receives only the disposable installation's existing doors. */
|
|
7
|
+
export async function journeyFixtures(root, declaration, context) {
|
|
8
|
+
if (declaration === undefined) return undefined;
|
|
9
|
+
if (!declaration || Object.keys(declaration).join(',') !== 'module' || typeof declaration.module !== 'string') throw new RerError('agent_fixtures_invalid', 'verification.fixtures must name a contained test module.', 1);
|
|
10
|
+
await contained(root, declaration.module);
|
|
11
|
+
const prepare = (await import(pathToFileURL(resolve(root, declaration.module)))).default;
|
|
12
|
+
if (typeof prepare !== 'function') throw new RerError('agent_fixtures_invalid', 'verification.fixtures module must default-export a phase preparation function.', 1);
|
|
13
|
+
return async ({ phase, tool }) => {
|
|
14
|
+
try { return await prepare({ ...context, phase, tool }); }
|
|
15
|
+
catch { throw new Error('Native phase preparation failed; no captured mail, credentials or fixture values are logged.'); }
|
|
16
|
+
};
|
|
17
|
+
}
|
package/cli/agent-reviewers.mjs
CHANGED
|
@@ -95,7 +95,7 @@ export async function verificationReviewers(root, declaration, ownerEmail) {
|
|
|
95
95
|
try {
|
|
96
96
|
const response = await entry.initialize({ request, origin, label, email: entry.email, owner: { email: ownerEmail, cookie: owner.cookie },
|
|
97
97
|
returnTo, mail: Object.freeze({ read: options => read(entry.email, options) }) });
|
|
98
|
-
if (closed || !(response instanceof Response) || response.status
|
|
98
|
+
if (closed || !(response instanceof Response) || ![200, 303].includes(response.status) || response.redirected) throw failed();
|
|
99
99
|
const cookie = response.headers.getSetCookie().map(value => value.split(';', 1)[0]).join('; ');
|
|
100
100
|
await response.body?.cancel();
|
|
101
101
|
if (!cookie || cookie === owner.cookie) throw failed();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { networkAdapterModules } from '../modules/agent-door/conformance/network-modules.mjs';
|
|
2
|
+
import { RerError } from './errors.mjs';
|
|
3
|
+
|
|
4
|
+
const denied = () => new Response('Conformance RPC services cannot reach the network.', { status: 502 });
|
|
5
|
+
const invalid = () => new RerError('agent_rpc_invalid', 'verification.rpc must map declared native service bindings to contained Worker modules and named RPC entrypoints. Services run without application bindings, Node APIs or network access.', 1);
|
|
6
|
+
|
|
7
|
+
export async function verificationRpc(root, config, services = []) {
|
|
8
|
+
const workers = [], serviceBindings = {};
|
|
9
|
+
if (config === undefined) return { workers, serviceBindings };
|
|
10
|
+
if (!config || typeof config !== 'object' || Array.isArray(config) || !Object.keys(config).length) throw invalid();
|
|
11
|
+
for (const [binding, value] of Object.entries(config)) {
|
|
12
|
+
if (!services.some(service => service.binding === binding) || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(binding)
|
|
13
|
+
|| !value || typeof value !== 'object' || Object.keys(value).sort().join(',') !== 'entrypoint,module'
|
|
14
|
+
|| typeof value.module !== 'string' || typeof value.entrypoint !== 'string' || !/^[A-Za-z_$][\w$]*$/.test(value.entrypoint)) throw invalid();
|
|
15
|
+
let source;
|
|
16
|
+
try { source = await networkAdapterModules(root, value.module, { builtins: ['cloudflare:workers'] }); }
|
|
17
|
+
catch { throw invalid(); }
|
|
18
|
+
const name = `rer-conformance-rpc-${workers.length}`;
|
|
19
|
+
workers.push({ name, modules: source.modules, modulesRoot: source.root, compatibilityDate: '2026-09-01', compatibilityFlags: [], bindings: {}, outboundService: denied });
|
|
20
|
+
serviceBindings[binding] = { name, entrypoint: value.entrypoint };
|
|
21
|
+
}
|
|
22
|
+
return { workers, serviceBindings };
|
|
23
|
+
}
|
package/cli/agent-sponsors.mjs
CHANGED
|
@@ -3,9 +3,9 @@ import { resolve } from 'node:path';
|
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import { contained } from './project.mjs';
|
|
5
5
|
import { RerError } from './errors.mjs';
|
|
6
|
+
import { ownerBindingValues, bindingGenerator } from './agent-bindings.mjs';
|
|
6
7
|
|
|
7
8
|
const defaultEmail = 'synthetic-base-1@example.com';
|
|
8
|
-
const ownerBindingValues = ['issuer', 'installationId', 'appOrigin', 'publicKeys', 'email', 'sub', 'token', 'sessionSecret'];
|
|
9
9
|
|
|
10
10
|
export async function verificationOwner(root, value = {}) {
|
|
11
11
|
if (!value || typeof value !== 'object' || Array.isArray(value)
|
|
@@ -14,7 +14,7 @@ export async function verificationOwner(root, value = {}) {
|
|
|
14
14
|
if (typeof email !== 'string' || email !== email.trim().toLowerCase() || !/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(email)) throw new RerError('agent_owner_invalid', 'verification.owner.email must be a canonical owner email.', 1);
|
|
15
15
|
for (const key of ['emailField', 'tokenField']) if (value[key] !== undefined && !/^[A-Z][A-Z0-9_]{0,63}$/.test(value[key])) throw new RerError('agent_owner_invalid', `verification.owner.${key} must name a production binding.`, 1);
|
|
16
16
|
if (value.bindings !== undefined && (!value.bindings || typeof value.bindings !== 'object' || Array.isArray(value.bindings)
|
|
17
|
-
|| Object.entries(value.bindings).some(([name, source]) => !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name) || !ownerBindingValues.includes(source)))) throw new RerError('agent_owner_invalid', `verification.owner.bindings must map native binding names to ${ownerBindingValues.join(', ')}.`, 1);
|
|
17
|
+
|| Object.entries(value.bindings).some(([name, source]) => !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name) || !(ownerBindingValues.includes(source) || bindingGenerator(source))))) throw new RerError('agent_owner_invalid', `verification.owner.bindings must map native binding names to ${ownerBindingValues.join(', ')} or a contained generator {module}.`, 1);
|
|
18
18
|
let initialize;
|
|
19
19
|
if (value.initializer !== undefined) {
|
|
20
20
|
await contained(root, value.initializer);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { contained } from './project.mjs';
|
|
4
|
+
import { RerError } from './errors.mjs';
|
|
5
|
+
|
|
6
|
+
export async function verificationInvoke(root, config) {
|
|
7
|
+
if (config === undefined) return;
|
|
8
|
+
if (!config || typeof config !== 'object' || Object.keys(config).sort().join(',') !== 'entrypoint,module'
|
|
9
|
+
|| typeof config.module !== 'string' || typeof config.entrypoint !== 'string' || !/^[A-Za-z_$][\w$]*$/.test(config.entrypoint)) throw new RerError('agent_invoke_invalid', 'verification.invoke must name a contained module and the native Worker entrypoint.', 1);
|
|
10
|
+
await contained(root, config.module);
|
|
11
|
+
const driver = (await import(pathToFileURL(resolve(root, config.module)))).default;
|
|
12
|
+
if (typeof driver !== 'function') throw new RerError('agent_invoke_invalid', 'verification.invoke module must default-export a native worker driver.', 1);
|
|
13
|
+
return { entrypoint: config.entrypoint, run: hosted => async (name, args, who) => {
|
|
14
|
+
try { return await driver({ name, args, who, worker: entrypoint => hosted.worker(entrypoint) }); }
|
|
15
|
+
catch { throw new Error('Native verification worker invocation failed; private driver values are not logged.'); }
|
|
16
|
+
} };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function verificationJourney(root, path, context) {
|
|
20
|
+
if (path === undefined) return {};
|
|
21
|
+
await contained(root, path);
|
|
22
|
+
const module = await import(pathToFileURL(resolve(root, path)));
|
|
23
|
+
if (typeof module.default !== 'function' || ['beforeStep', 'afterStep'].some(key => module[key] !== undefined && typeof module[key] !== 'function')) throw new RerError('agent_journey_invalid', 'verification.journey must default-export a native journey; optional beforeStep and afterStep exports must be functions.', 1);
|
|
24
|
+
const call = async (fn, value) => {
|
|
25
|
+
try { await fn({ ...context, ...value }); }
|
|
26
|
+
catch { throw new Error('Native verification journey failed; no captured mail or fixture values are logged.'); }
|
|
27
|
+
};
|
|
28
|
+
return { nativeJourney: value => call(module.default, value),
|
|
29
|
+
nativeStep: async ({ stage, ...value }) => { if (module[stage]) await call(module[stage], value); },
|
|
30
|
+
};
|
|
31
|
+
}
|
package/cli/deploy-variables.mjs
CHANGED
|
@@ -5,6 +5,8 @@ import { parseJsonc } from './jsonc.mjs';
|
|
|
5
5
|
import { comments } from './business/parsers-syntax.mjs';
|
|
6
6
|
import { tomlEntries } from './business/parsers-config.mjs';
|
|
7
7
|
import { imageVariableSecrets } from '../modules/container/image-variables.mjs';
|
|
8
|
+
import { publicMailSender, validateMailSenders } from '../modules/delivery-producer/mail.mjs';
|
|
9
|
+
import { deliveryDeclarationSources } from './delivery-declarations.mjs';
|
|
8
10
|
|
|
9
11
|
const id = 'deploy.vars-secrets';
|
|
10
12
|
const lineAt = (source, offset) => source.slice(0, offset).split('\n').length;
|
|
@@ -16,9 +18,35 @@ async function sourceFile(root, path) {
|
|
|
16
18
|
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
17
19
|
}
|
|
18
20
|
|
|
21
|
+
async function variableEntries(root, path) {
|
|
22
|
+
const source = await sourceFile(root, path);
|
|
23
|
+
if (source === null) return [];
|
|
24
|
+
const entries = [];
|
|
25
|
+
let config;
|
|
26
|
+
try {
|
|
27
|
+
if (path.endsWith('.toml')) entries.push(...tomlEntries(comments(source).clean, { locations: true }));
|
|
28
|
+
else config = parseJsonc(source, (path, offset) => entries.push({ path, offset }));
|
|
29
|
+
} catch (error) { throw Error(`${path}: ${error.message}`); }
|
|
30
|
+
return entries.filter(entry => variablePath(entry.path)).map(entry => ({
|
|
31
|
+
binding: entry.path.at(-1),
|
|
32
|
+
value: config ? entry.path.reduce((value, key) => value?.[key], config) : entry.value,
|
|
33
|
+
source: `${path}:${lineAt(source, entry.offset)} (${entry.path.join('.')})`,
|
|
34
|
+
location: `${path}:${lineAt(source, entry.offset)} (${entry.path.slice(0, -1).join('.')})`,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Source defaults participate in the same sender check as deploy inputs. */
|
|
39
|
+
export async function sourceMailSenders(root, adapter) {
|
|
40
|
+
const senders = [];
|
|
41
|
+
for (const path of deployConfigPaths(adapter)) {
|
|
42
|
+
for (const entry of await variableEntries(root, path)) if (entry.binding === 'MAIL_FROM') senders.push(entry);
|
|
43
|
+
}
|
|
44
|
+
return senders;
|
|
45
|
+
}
|
|
46
|
+
|
|
19
47
|
// Reuse the image builder's JSONC reader and binding comparison. Source checks
|
|
20
|
-
//
|
|
21
|
-
// a
|
|
48
|
+
// reject secret placeholders before a build normalizes them. Managed MAIL_FROM
|
|
49
|
+
// is a public input even when the deploy adapter supplies it through secrets.
|
|
22
50
|
export async function deployVariableClause(root, adapter) {
|
|
23
51
|
try {
|
|
24
52
|
const declarationPath = adapter?.deploy?.declaration ?? 'deploy.json';
|
|
@@ -32,27 +60,30 @@ export async function deployVariableClause(root, adapter) {
|
|
|
32
60
|
try { JSON.parse(declarationSource); } catch { throw Error(`${declarationPath}: invalid JSON declaration.`); }
|
|
33
61
|
const secrets = declaration.secrets ?? [];
|
|
34
62
|
if (!Array.isArray(secrets) || secrets.some(secret => typeof secret?.binding !== 'string')) throw Error(`${declarationPath}: secrets must be an array of binding declarations.`);
|
|
35
|
-
const
|
|
36
|
-
|
|
63
|
+
const senders = [{ source: `${declarationPath} vars.MAIL_FROM`, value: declaration.vars?.MAIL_FROM }];
|
|
64
|
+
let publicSender = false, privateSender = false;
|
|
65
|
+
for (const [path, select] of deliveryDeclarationSources) {
|
|
37
66
|
const source = await sourceFile(root, path);
|
|
38
67
|
if (source === null) continue;
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const matched = new Set(imageVariableSecrets(
|
|
68
|
+
const spec = select(JSON.parse(source));
|
|
69
|
+
if (!spec) continue;
|
|
70
|
+
publicSender ||= publicMailSender(spec);
|
|
71
|
+
privateSender ||= [...(spec.secretNames ?? []), ...(spec.optionalSecretNames ?? [])].includes('MAIL_FROM');
|
|
72
|
+
senders.push({ source: `${path} publicVariables.MAIL_FROM`, value: spec.publicVariables?.MAIL_FROM });
|
|
73
|
+
}
|
|
74
|
+
const overlaps = [];
|
|
75
|
+
for (const path of deployConfigPaths(adapter)) {
|
|
76
|
+
for (const entry of await variableEntries(root, path)) {
|
|
77
|
+
const { binding, value } = entry;
|
|
78
|
+
if (binding === 'MAIL_FROM') senders.push(entry);
|
|
79
|
+
const matched = new Set(imageVariableSecrets({ [binding]: value }, secrets).map(secret => secret.binding));
|
|
51
80
|
if (!matched.has(binding)) continue;
|
|
81
|
+
if (binding === 'MAIL_FROM' && publicSender && !privateSender) continue;
|
|
52
82
|
for (const [index, secret] of secrets.entries()) if (secret.binding === binding) overlaps.push(
|
|
53
|
-
`${binding}: ${
|
|
83
|
+
`${binding}: ${entry.location} and ${declarationPath}:${secretLocations.get(index)} (secrets)`);
|
|
54
84
|
}
|
|
55
85
|
}
|
|
86
|
+
validateMailSenders(senders);
|
|
56
87
|
return overlaps.length ? { id, ok: false, message: overlaps.join('\n') + '\nremove it from wrangler vars; the deploy sets it as a secret' } : { id, ok: true };
|
|
57
88
|
} catch (error) { return { id, ok: false, message: error.message }; }
|
|
58
89
|
}
|
package/cli/export.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { execFileSync } from 'node:child_process';
|
|
|
10
10
|
export const sourceRoots = ['default-seed/public/rer-theme.css', 'default-seed/public/brand/mark.svg', 'default-seed/public/fonts/outfit', 'bin/rer.mjs', 'cli', 'modules/delivery-producer/declarations.mjs', 'modules/delivery-producer/bindings.mjs', 'modules/delivery-producer/migrations.mjs', 'modules/delivery-producer/mail.mjs', 'modules/job-queue', 'modules/release', 'modules/deploy-kit', 'modules/site', 'modules/container', 'modules/demo-host', 'modules/demo', 'modules/integrations/core', 'modules/mail', 'modules/ai', 'modules/portability', 'modules/d1-transport', 'modules/import-kit/src/receipt', 'modules/import-kit/src/status', 'modules/import-kit/schema', 'modules/import-kit/src/d1', 'modules/import-kit/src/door', 'modules/import-kit/src/readers', 'modules/import-kit/src/provenance/numeric-credentials.ts', 'modules/import-kit/src/types.ts', 'modules/import-kit/src/plan', 'modules/import-kit/src/provenance/canonical-hash.ts', 'modules/import-kit/src/provenance/canonical-stream.ts', 'modules/import-kit/src/provenance/credential-names.ts', 'modules/import-kit/src/provenance/credentials.ts', 'modules/import-kit/src/provenance/identity.ts', 'modules/import-kit/src/provenance/json-snapshot.ts', 'modules/import-kit/src/provenance/resumable-sha256.ts', 'modules/import-kit/src/provenance/validate-json.ts', 'modules/import-kit/src/journal/authority.ts', 'modules/import-kit/src/storage/originals.ts', 'modules/import-kit/src/storage/provenance.ts', 'modules/import-kit/src/storage/schema.ts', 'modules/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/adopt.mjs', 'edition-authoring/base-acknowledgements.mjs', 'edition-authoring/base-copies.mjs', 'edition-authoring/module-closure.mjs', 'edition-authoring/edition-migrations.mjs', 'edition-authoring/cli.mjs', 'edition-authoring/copy-checkout.mjs', 'edition-authoring/files.mjs', 'edition-authoring/lock.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/offline-git.mjs', 'edition-authoring/parent-comparison.mjs', 'edition-authoring/projection-lock.mjs', 'edition-authoring/release.mjs', 'edition-authoring/runtime-dependencies.mjs', 'edition-authoring/module-resolution.mjs', 'edition-authoring/package-target.mjs', 'edition-authoring/module-syntax.mjs', 'edition-authoring/module-edges.mjs', 'edition-authoring/vendor/babel-parser', 'edition-authoring/workflow-copies.mjs', 'edition-authoring/workflow-scripts.mjs', 'edition-authoring/vendor/yaml', 'edition-authoring/sources.mjs', 'edition-authoring/updates.mjs', 'foundation/runtime/seed-contract.mjs', 'foundation/runtime/run-data.mjs', 'foundation/runtime/run-data.d.mts', 'foundation/runtime/contract-docs.mjs'];
|
|
11
11
|
sourceRoots.push('modules/agent-door/conformance', 'modules/agent-door/CLAUSES.md');
|
|
12
12
|
sourceRoots.push('edition-authoring/archive-source.mjs');
|
|
13
|
+
sourceRoots.push('edition-authoring/copy-namespaces.mjs');
|
|
13
14
|
sourceRoots.push('foundation/runtime/contract-prose.mjs', 'foundation/runtime/contract-prose-patterns.mjs');
|
|
14
15
|
export async function inventory(base, roots = sourceRoots) {
|
|
15
16
|
const files = [];
|
package/cli/hosted-output.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { readMigrationRewrites, withRewrites } from '../modules/deploy-kit/migra
|
|
|
10
10
|
import { RerError } from './errors.mjs';
|
|
11
11
|
import { hostedMailCredentials } from './hosted-mail.mjs';
|
|
12
12
|
import { shared } from './shared.mjs';
|
|
13
|
+
import { verificationRpc } from './agent-rpc.mjs';
|
|
13
14
|
|
|
14
15
|
// Serve the production build the way rer deploy hosts it (assets behind the
|
|
15
16
|
// Worker, deploy identity bound, a public https origin) on loopback, with no
|
|
@@ -44,7 +45,7 @@ const links = html => [...html.matchAll(/(?:src|href)=["'](\/[^"'#?\s]+)/g)].map
|
|
|
44
45
|
|
|
45
46
|
/** The build served as rer deploy hosts it, with declared vars, origin and
|
|
46
47
|
* stand-in deploy/Managed mail secrets. `fetch(path, init)` uses the deployed origin. */
|
|
47
|
-
export async function serveHosted(root, { declaration: declarationPath = 'deploy.json', bindings = {}, outboundService } = {}) {
|
|
48
|
+
export async function serveHosted(root, { declaration: declarationPath = 'deploy.json', bindings = {}, outboundService, rpc, workerEntrypoints = [] } = {}) {
|
|
48
49
|
const { loopbackFetch } = await shared('loopback-fetch.mjs');
|
|
49
50
|
const build = join(root, 'dist/server'), client = join(root, 'dist/client');
|
|
50
51
|
let config;
|
|
@@ -56,13 +57,16 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
|
|
|
56
57
|
const manifest = await optional(join(root, 'rer-setup.json'));
|
|
57
58
|
const { Miniflare, convertV4MiniflareOptions = options => options } = await miniflareFor(root);
|
|
58
59
|
const entry = join(build, config.main);
|
|
60
|
+
const rpcServices = await verificationRpc(root, rpc, config.services);
|
|
61
|
+
const nativeWorkers = Object.fromEntries(workerEntrypoints.map((entrypoint, index) => [entrypoint, `RER_NATIVE_${index}`]));
|
|
62
|
+
const nativeBindings = Object.fromEntries(Object.entries(nativeWorkers).map(([entrypoint, binding]) => [binding, { name: 'app', entrypoint }]));
|
|
59
63
|
const modules = [entry, ...(await files(build)).map(path => join(build, path)).filter(path => path !== entry && moduleTypes[extname(path)])].map(path => ({ type: moduleTypes[extname(path)], path }));
|
|
60
64
|
const identity = { sourceSha: createHash('sha1').update(randomBytes(16)).digest('hex'), fingerprint: createHash('sha256').update(randomBytes(16)).digest('hex'), versionId: crypto.randomUUID() };
|
|
61
65
|
const secrets = Object.fromEntries((declaration.secrets ?? []).map(item => [item.binding, standIn(item, manifest.fields?.find(field => field.name === item.binding))]));
|
|
62
66
|
for (const binding of await hostedMailCredentials(root)) {
|
|
63
67
|
if (!Object.hasOwn(secrets, binding)) secrets[binding] = standIn({}, manifest.fields?.find(field => field.name === binding));
|
|
64
68
|
}
|
|
65
|
-
const mf = new Miniflare(convertV4MiniflareOptions({ host: '127.0.0.1', port: 0, cf: false, workers: [{ name: 'ingress', modules: true, script: ingress, serviceBindings: { APP: 'app' } }, {
|
|
69
|
+
const mf = new Miniflare(convertV4MiniflareOptions({ host: '127.0.0.1', port: 0, cf: false, workers: [{ name: 'ingress', modules: true, script: ingress, serviceBindings: { APP: 'app', ...nativeBindings } }, ...rpcServices.workers, {
|
|
66
70
|
name: 'app', ...(outboundService ? { outboundService } : {}), modules, modulesRoot: build, compatibilityDate: config.compatibility_date, compatibilityFlags: config.compatibility_flags,
|
|
67
71
|
bindings: { ...config.vars, ...declaration.vars, ...secrets, ...(declaration.originVar ? { [declaration.originVar]: HOSTED_ORIGIN } : {}),
|
|
68
72
|
RER_DEPLOY_SOURCE: identity.sourceSha, RER_DEPLOY_FINGERPRINT: identity.fingerprint, RER_VERSION: { id: identity.versionId, tag: '', timestamp: new Date().toISOString() }, ...bindings },
|
|
@@ -70,6 +74,11 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
|
|
|
70
74
|
r2Buckets: Object.fromEntries((config.r2_buckets ?? []).map(item => [item.binding, item.bucket_name])),
|
|
71
75
|
kvNamespaces: Object.fromEntries((config.kv_namespaces ?? []).map(item => [item.binding, item.id ?? item.binding])),
|
|
72
76
|
queueProducers: Object.fromEntries((config.queues?.producers ?? []).map(item => [item.binding, item.queue])),
|
|
77
|
+
queueConsumers: Object.fromEntries((config.queues?.consumers ?? []).map(item => [item.queue, {
|
|
78
|
+
...(item.max_batch_size !== undefined ? { maxBatchSize: item.max_batch_size } : {}), ...(item.max_batch_timeout !== undefined ? { maxBatchTimeout: item.max_batch_timeout } : {}),
|
|
79
|
+
...(item.max_retries !== undefined ? { maxRetries: item.max_retries } : {}), ...(item.dead_letter_queue ? { deadLetterQueue: item.dead_letter_queue } : {}), ...(item.retry_delay !== undefined ? { retryDelay: item.retry_delay } : {}),
|
|
80
|
+
}])),
|
|
81
|
+
serviceBindings: rpcServices.serviceBindings,
|
|
73
82
|
durableObjects: Object.fromEntries((config.durable_objects?.bindings ?? []).filter(item => !item.script_name).map(item => [item.name, { className: item.class_name, useSQLite: true }])),
|
|
74
83
|
...(config.assets ? { assets: { directory: client, binding: config.assets.binding ?? 'ASSETS', routerConfig: { has_user_worker: true, invoke_user_worker_ahead_of_assets: RUN_WORKER_FIRST } } } : {}),
|
|
75
84
|
}] }));
|
|
@@ -87,6 +96,10 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
|
|
|
87
96
|
}
|
|
88
97
|
} catch (error) { await mf.dispose(); throw error; }
|
|
89
98
|
return { client, identity, origin: HOSTED_ORIGIN,
|
|
99
|
+
worker: async entrypoint => {
|
|
100
|
+
if (!Object.hasOwn(nativeWorkers, entrypoint)) throw new RerError('agent_invoke_invalid', 'Verification can invoke only its declared native Worker entrypoint.', 1);
|
|
101
|
+
return (await mf.getBindings('ingress'))[nativeWorkers[entrypoint]];
|
|
102
|
+
},
|
|
90
103
|
database: async binding => {
|
|
91
104
|
if (!(config.d1_databases ?? []).some(item => item.binding === binding)) throw new RerError('hosted_database_invalid', 'Verification can read only a declared disposable database binding.', 1);
|
|
92
105
|
const db = await mf.getD1Database(binding, 'app');
|
package/cli/managed-data.mjs
CHANGED
|
@@ -26,7 +26,7 @@ export async function withManagedDataImport(context, declaration, restore) {
|
|
|
26
26
|
catch (error) {
|
|
27
27
|
if (!(error instanceof PortabilityError)) throw error;
|
|
28
28
|
const reason = error.code.startsWith('managed_data_') ? error.code : error.code.split(':').slice(0, 2).join(':');
|
|
29
|
-
throw new RerError(reason, `Managed data restore refused (${reason}). The destination has not accepted this archive
|
|
29
|
+
throw new RerError(reason, `Managed data restore refused (${reason}). The destination has not accepted this archive.${reason.startsWith('identity_table_undeclared:') ? ' Declare this table in includeTables to transfer its rows or excludeTables to omit them.' : ''}`, 4);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
async function intake(context, declaration, restore) {
|
|
@@ -55,7 +55,7 @@ async function intake(context, declaration, restore) {
|
|
|
55
55
|
check(Buffer.byteLength(sql) <= 16 * 1024 * 1024, 'oversized');
|
|
56
56
|
const statements = splitStatements(sql);
|
|
57
57
|
check(statements.length <= 10000, 'oversized');
|
|
58
|
-
const prepared = [];
|
|
58
|
+
const prepared = [[], [], []];
|
|
59
59
|
for (const statement of statements) {
|
|
60
60
|
context.signal?.throwIfAborted();
|
|
61
61
|
const tokens = sqliteTokens(statement), head = tokens.slice(0, 3).map(token => token.text.toLowerCase());
|
|
@@ -75,9 +75,13 @@ async function intake(context, declaration, restore) {
|
|
|
75
75
|
}
|
|
76
76
|
sql += statement.slice(offset);
|
|
77
77
|
check(Buffer.byteLength(sql) <= 100000, 'oversized');
|
|
78
|
-
|
|
78
|
+
// A child INSERT may precede its parent's definition in the producer's
|
|
79
|
+
// dump. Validate everything first, then create all tables in the same
|
|
80
|
+
// deferred-FK batch. Keep the remaining order, especially trigger creation.
|
|
81
|
+
const phase = head[0] === 'pragma' ? 0 : head[0] === 'create' && head[1] === 'table' ? 1 : 2;
|
|
82
|
+
prepared[phase].push(params.length ? db.prepare(sql).bind(...params) : db.prepare(sql));
|
|
79
83
|
}
|
|
80
|
-
await db.batch(prepared);
|
|
84
|
+
await db.batch(prepared.flat());
|
|
81
85
|
} catch (error) {
|
|
82
86
|
if (error instanceof PortabilityError || context.signal?.aborted) throw error;
|
|
83
87
|
check(false, 'sql_refused');
|
|
@@ -89,9 +89,10 @@ catch (error) {
|
|
|
89
89
|
// A populated destination names its table or bucket: schema names, never row data.
|
|
90
90
|
const occupied = error instanceof PortabilityError && /^(target|bucket)_not_empty:/.test(error.code) ? error.code.slice(error.code.indexOf(':') + 1) : undefined;
|
|
91
91
|
// Safety diagnostics contain only policy schema names, never source values.
|
|
92
|
+
const identityTable = error instanceof PortabilityError && error.code.startsWith('identity_table_undeclared:') ? error.code.slice('identity_table_undeclared:'.length) : undefined;
|
|
92
93
|
const safety = error instanceof PortabilityError && error.code.startsWith('import_row_') ? error.code.slice(error.code.indexOf(':')+1) : undefined;
|
|
93
94
|
// Anything that is not a portability refusal names its class and code, never its message: that can hold row data.
|
|
94
95
|
const native = error instanceof PortabilityError || error.message === 'archive_json' ? undefined : nativeFailure(error);
|
|
95
96
|
process.exitCode = exitCode;
|
|
96
|
-
await reply({ ok: false, code: exitCode === 2 ? 'invalid_archive' : exitCode === 4 ? 'restore_refused' : 'transfer_failed', reason, ...(reExport ? { reExport: true } : {}), ...(migration ? { migration } : {}), ...(unapplied ? { unapplied } : {}), ...(occupied ? { occupied } : {}), ...(safety ? { safety } : {}), ...(native ? { native } : {}), exitCode });
|
|
97
|
+
await reply({ ok: false, code: exitCode === 2 ? 'invalid_archive' : exitCode === 4 ? 'restore_refused' : 'transfer_failed', reason, ...(reExport ? { reExport: true } : {}), ...(migration ? { migration } : {}), ...(unapplied ? { unapplied } : {}), ...(occupied ? { occupied } : {}), ...(identityTable ? { identityTable } : {}), ...(safety ? { safety } : {}), ...(native ? { native } : {}), exitCode });
|
|
97
98
|
}
|
package/cli/portability.mjs
CHANGED
|
@@ -106,6 +106,7 @@ async function nativeWorker(store,direction,input,signal) {
|
|
|
106
106
|
? 'Legacy data was restored and audited, but its v2 export failed. Preserve this installation, resolve the output problem, then run rer export --output FILE. Do not reset it to retry recovery.'
|
|
107
107
|
: receipt.reason === 'archive_json' ? `Restore refused: the archive is damaged or incomplete. ${reExport}`
|
|
108
108
|
: receipt.reExport ? `Restore refused (schema_mismatch): the schema definitions cannot be safely verified by this version. ${reExport}`
|
|
109
|
+
: receipt.identityTable ? `Transfer refused (identity_table_undeclared:${receipt.identityTable}): declare this table in includeTables to transfer its rows or excludeTables to omit them.`
|
|
109
110
|
: receipt.safety ? `Restore refused (${receipt.reason}): safety normalization for ${receipt.safety} violates the declared import policy.`
|
|
110
111
|
: receipt.reason?.startsWith('migration_ledger:') ? ledgerRefusal(receipt)
|
|
111
112
|
: receipt.migration ? `Restore refused (schema_mismatch:migration_data): migration ${receipt.migration} changed data after this archive was made, so its rows would skip that change. Restore an archive made after it.`
|
package/cli/production-auth.mjs
CHANGED
|
@@ -10,7 +10,7 @@ export async function requireProductionAuth({ root, declaration, env, setupManif
|
|
|
10
10
|
const dependencies = setupManifest?.dependencies?.filter(item => item.interface === 'oidc-provider@1') ?? [];
|
|
11
11
|
const bindings = { ...declaration.vars };
|
|
12
12
|
for (const secret of declaration.secrets ?? []) if (env[secret.environment]?.trim()) bindings[secret.binding] = env[secret.environment];
|
|
13
|
-
const mail = await productionMail(root, declaration, env, declarationPath);
|
|
13
|
+
const mail = await productionMail(root, declaration, env, declarationPath, adapter);
|
|
14
14
|
if (!setupManifest?.steps?.some(step => step.type === 'owner-claim') && !dependencies.length && !mail.declared) return;
|
|
15
15
|
if (mail.senderIssue && options.verb === 'deploy' && !(options.dryRun && mail.fixtureSender)) throw refuse(`${mail.senderIssue} Nothing was built or uploaded.`);
|
|
16
16
|
if (mail.configured()) return;
|
package/cli/production-mail.mjs
CHANGED
|
@@ -4,6 +4,8 @@ import { refuse } from './errors.mjs';
|
|
|
4
4
|
import { parseAddress } from '../modules/mail/src/core/validation.mjs';
|
|
5
5
|
import { deliveryDeclarationSources } from './delivery-declarations.mjs';
|
|
6
6
|
import { validateRerConfig } from '../modules/mail/src/adapters/rer/contract.mjs';
|
|
7
|
+
import { validateMailSenders } from '../modules/delivery-producer/mail.mjs';
|
|
8
|
+
import { sourceMailSenders } from './deploy-variables.mjs';
|
|
7
9
|
|
|
8
10
|
const providers = ['resend', 'sendgrid', 'cloudflare', 'rer'];
|
|
9
11
|
const nativeCredential = { sendgrid: 'SENDGRID_API_KEY', resend: 'RESEND_API_KEY' };
|
|
@@ -28,13 +30,16 @@ const placeholderSender = value => {
|
|
|
28
30
|
// Packaging can declare inputs that a product's deploy adapter adds to the
|
|
29
31
|
// root declaration later. Read that source contract, never arbitrary ambient
|
|
30
32
|
// keys or the adapter's executable source, before any build or provider write.
|
|
31
|
-
export async function productionMail(root, declaration, env, declarationPath = 'deploy.json') {
|
|
33
|
+
export async function productionMail(root, declaration, env, declarationPath = 'deploy.json', adapter) {
|
|
32
34
|
const bindings = { ...declaration.vars }, secrets = new Set(), publicInputs = new Set(), declaredProviders = new Set();
|
|
35
|
+
const senders = [{ source: `${declarationPath} vars.MAIL_FROM`, value: declaration.vars?.MAIL_FROM }];
|
|
36
|
+
senders.push(...await sourceMailSenders(root, adapter));
|
|
33
37
|
let senderFix = `Edit vars.MAIL_FROM in ${declarationPath}`;
|
|
34
38
|
const environmentFix = name => `Set ${name} in your environment or owned 0600 --env-file`;
|
|
35
39
|
for (const secret of declaration.secrets ?? []) {
|
|
36
40
|
secrets.add(secret.binding);
|
|
37
41
|
if (present(env[secret.environment])) {
|
|
42
|
+
if (secret.binding === 'MAIL_FROM') senders.push({ source: `${declarationPath} secrets.MAIL_FROM from ${secret.environment} (environment or --env-file)`, value: env[secret.environment] });
|
|
38
43
|
bindings[secret.binding] = env[secret.environment];
|
|
39
44
|
if (secret.binding === 'MAIL_FROM') senderFix = environmentFix(secret.environment);
|
|
40
45
|
}
|
|
@@ -47,6 +52,7 @@ export async function productionMail(root, declaration, env, declarationPath = '
|
|
|
47
52
|
try { spec = select(JSON.parse(text)); }
|
|
48
53
|
catch { throw refuse(`Restore a valid mail deployment declaration at ${path}. Nothing was built or uploaded.`); }
|
|
49
54
|
if (!spec) continue;
|
|
55
|
+
senders.push({ source: `${path} publicVariables.MAIL_FROM`, value: spec.publicVariables?.MAIL_FROM });
|
|
50
56
|
for (const name of spec.publicVariableNames ?? []) publicInputs.add(name);
|
|
51
57
|
for (const [name, value] of Object.entries(spec.publicVariables ?? {})) {
|
|
52
58
|
if (!(name in bindings) || name === 'MAIL_PROVIDER' && bindings[name] === 'later') {
|
|
@@ -59,15 +65,19 @@ export async function productionMail(root, declaration, env, declarationPath = '
|
|
|
59
65
|
// A root secret's explicit environment-to-binding mapping wins.
|
|
60
66
|
if (!declaration.secrets?.some(secret => secret.binding === name) && present(env[name])) {
|
|
61
67
|
bindings[name] = env[name];
|
|
68
|
+
if (name === 'MAIL_FROM') senders.push({ source: `${path} secret MAIL_FROM (environment or --env-file)`, value: env[name] });
|
|
62
69
|
if (name === 'MAIL_FROM') senderFix = environmentFix(name);
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
72
|
for (const provider of spec.mail?.providers ?? []) if (providers.includes(provider)) declaredProviders.add(provider);
|
|
66
73
|
}
|
|
67
74
|
for (const name of publicInputs) if (present(env[name])) {
|
|
75
|
+
if (name === 'MAIL_FROM') senders.push({ source: 'public MAIL_FROM (environment or --env-file)', value: env[name] });
|
|
68
76
|
bindings[name] = env[name];
|
|
69
77
|
if (name === 'MAIL_FROM') senderFix = environmentFix(name);
|
|
70
78
|
}
|
|
79
|
+
try { validateMailSenders(senders); }
|
|
80
|
+
catch (error) { throw refuse(`${error.message} Nothing was built or uploaded.`); }
|
|
71
81
|
let senderIssue;
|
|
72
82
|
if (present(bindings.MAIL_FROM) && (!sender(bindings.MAIL_FROM) || placeholderSender(bindings.MAIL_FROM))) {
|
|
73
83
|
senderIssue = `MAIL_FROM is invalid or a placeholder sender. Replace it with a real sender address on your mail provider's verified domain (a bare address or Display Name <address>). ${senderFix}, then run rer deploy --dry-run again.`;
|
package/cli/server-registry.mjs
CHANGED
|
@@ -185,6 +185,8 @@ export async function serverRegistry(root,{env=process.env,memory=availableMemor
|
|
|
185
185
|
async function serve(handler) {
|
|
186
186
|
control=createServer({allowHalfOpen:true},socket=>{
|
|
187
187
|
let text='';socket.setTimeout(35000,()=>socket.destroy());
|
|
188
|
+
// A timed-out status caller can disconnect while its reply is in flight.
|
|
189
|
+
socket.on('error',()=>socket.destroy());
|
|
188
190
|
socket.on('data',data=>{text+=data;if(text.length>1024)socket.destroy();});
|
|
189
191
|
socket.on('end',async()=>{
|
|
190
192
|
try{
|
|
@@ -54,6 +54,12 @@ export function archiveReader(directory, revision) {
|
|
|
54
54
|
},
|
|
55
55
|
digests(ids) { return new Map([...this.blobs(ids)].map(([object, data]) => [object, hash(data)])); },
|
|
56
56
|
contains: history,
|
|
57
|
-
|
|
57
|
+
// A single observed snapshot can match current template bytes; it cannot
|
|
58
|
+
// establish older revisions or ancestry.
|
|
59
|
+
history(pin, name) {
|
|
60
|
+
if (pin !== revision) return history();
|
|
61
|
+
const entry = orderedTree.get(safe(name));
|
|
62
|
+
return entry ? [{revision, object: entry.object}] : [];
|
|
63
|
+
},
|
|
58
64
|
};
|
|
59
65
|
}
|
|
@@ -533,7 +533,8 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
533
533
|
const templates = adoptWorkflowTemplates(root, plans, {tree: next, read, revision, files});
|
|
534
534
|
notices = templates.notices;
|
|
535
535
|
completeWorkflowHelpers(root, plans, {tree: next, read, revision});
|
|
536
|
-
const
|
|
536
|
+
const relocations = new Map();
|
|
537
|
+
const withheld = completeModuleCopies(root, plans, {tree: next, read, revision, base: origin.repository, ownerSources, relocations,
|
|
537
538
|
deliveries: migrations.flatMap(step => step.deliver.map(source => ({source, origin: step.origin, importers: step.copies})))});
|
|
538
539
|
// Closure may add individually recorded siblings when the seed originally
|
|
539
540
|
// selected runtime files one at a time instead of copying the directory.
|
|
@@ -567,9 +568,21 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
567
568
|
const {object, mode} = byName.get(name);
|
|
568
569
|
if (!Object.hasOwn(copy.files, name)) added.push(name);
|
|
569
570
|
recorded[name] = upstream.get(object); modes[name] = mode;
|
|
571
|
+
if (relocations.has(name)) {
|
|
572
|
+
// The upstream digest remains the comparison baseline. Mechanical
|
|
573
|
+
// namespace edits are honest, acknowledged seed-owned adaptations.
|
|
574
|
+
(copy.adapted ||= {})[name] = revision;
|
|
575
|
+
(copy.acknowledged ||= {})[name] = {sha256: hash(relocations.get(name)), mode};
|
|
576
|
+
adapted.push({path: name, originPath: source, revision, conflict: false});
|
|
577
|
+
}
|
|
570
578
|
}
|
|
571
579
|
changes.push({path: copy.path, from: copy.revision, files: sources.length, added, removed});
|
|
572
|
-
|
|
580
|
+
// Relocations become adaptations during this pass. Keep their map order
|
|
581
|
+
// identical when the next refresh visits adaptations before sources.
|
|
582
|
+
Object.assign(copy, {revision,
|
|
583
|
+
files: Object.fromEntries(Object.entries(recorded).sort(([a], [b]) => a.localeCompare(b))),
|
|
584
|
+
modes: Object.fromEntries(Object.entries(modes).sort(([a], [b]) => a.localeCompare(b))),
|
|
585
|
+
originFiles: [...next.keys()].filter(name => within(name, copy.originPath)).sort()});
|
|
573
586
|
}
|
|
574
587
|
record.copies = plans.filter(plan => !plan.retired).map(plan => plan.copy);
|
|
575
588
|
delete record.repository;
|
|
@@ -584,12 +597,12 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
584
597
|
noLinks(root, name);
|
|
585
598
|
const target = path.join(root, name);
|
|
586
599
|
fs.mkdirSync(path.dirname(target), {recursive: true});
|
|
587
|
-
fs.writeFileSync(target, bytes.get(object));
|
|
600
|
+
fs.writeFileSync(target, relocations.get(name) ?? bytes.get(object));
|
|
588
601
|
fs.chmodSync(target, mode === '100755' ? 0o755 : 0o644);
|
|
589
602
|
}
|
|
590
603
|
}
|
|
591
604
|
fs.writeFileSync(filename, json(record));
|
|
592
|
-
return {refreshed: revision, record: recordPath, copies: changes, retired: plans.filter(plan => plan.retired).map(plan => plan.copy.path), adapted, withheld, editionMigrations: migrations.map(({id, guide, edit, copies}) => ({id, guide, edit, copies})), ...templates, next: 'Run verify-base, then the edition tests, and commit the copied files with the record.'};
|
|
605
|
+
return {refreshed: revision, record: recordPath, copies: changes, retired: plans.filter(plan => plan.retired).map(plan => plan.copy.path), adapted, relocated: [...relocations.keys()], withheld, editionMigrations: migrations.map(({id, guide, edit, copies}) => ({id, guide, edit, copies})), ...templates, next: 'Run verify-base, then the edition tests, and commit the copied files with the record.'};
|
|
593
606
|
} catch (error) {
|
|
594
607
|
if (!writing && !/no files were refreshed/i.test(error.message)) error.message += ' No files were refreshed.';
|
|
595
608
|
if (!writing && notices.length) error.message += '\n' + notices.join('\n');
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
const inside = (name, prefix) => name === prefix || name.startsWith(prefix + '/');
|
|
4
|
+
const common = (left, right) => {
|
|
5
|
+
const a = left.split('/'), b = right.split('/');
|
|
6
|
+
let length = 0;
|
|
7
|
+
while (length < a.length && a[length] === b[length]) length++;
|
|
8
|
+
return a.slice(0, length).join('/');
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// Two disjoint recorded subtrees with the same relative placement establish
|
|
12
|
+
// their shared namespace. One copy alone cannot authorize unrelated siblings,
|
|
13
|
+
// and agreement never extends to the repository root or outside the edition.
|
|
14
|
+
export function sharedNamespaces(mappings) {
|
|
15
|
+
// File selections witness their own siblings, not a parent above that
|
|
16
|
+
// directory. Only directory copies establish a shared subtree selection.
|
|
17
|
+
mappings = mappings.filter(({directory}) => directory);
|
|
18
|
+
const result = new Map();
|
|
19
|
+
for (let i = 0; i < mappings.length; i++) for (const b of mappings.slice(i + 1)) {
|
|
20
|
+
const a = mappings[i];
|
|
21
|
+
if (inside(a.from, b.from) || inside(b.from, a.from)) continue;
|
|
22
|
+
if (path.posix.relative(a.from, b.from) !== path.posix.relative(a.to, b.to)) continue;
|
|
23
|
+
const from = common(a.from, b.from), to = common(a.to, b.to);
|
|
24
|
+
if (!from || from === '.' || !to || to === '.' || to.startsWith('../')) continue;
|
|
25
|
+
result.set(JSON.stringify([from, to]), {from, to});
|
|
26
|
+
}
|
|
27
|
+
return [...result.values()];
|
|
28
|
+
}
|
|
@@ -121,8 +121,9 @@ export function tracked(root, allowMissing = false) {
|
|
|
121
121
|
export const digest = files => hash(json(files));
|
|
122
122
|
// The complete tool in `dir`, as sorted relative paths: its non-test modules and
|
|
123
123
|
// every vendored parser file with its licence. Copies and the lock identity use it.
|
|
124
|
+
export const toolFile = name => name.startsWith('vendor/') || !name.includes('/') && name.endsWith('.mjs') && !name.endsWith('.test.mjs');
|
|
124
125
|
export function toolFiles(dir) {
|
|
125
|
-
const modules = fs.readdirSync(dir).filter(
|
|
126
|
+
const modules = fs.readdirSync(dir).filter(toolFile);
|
|
126
127
|
const vendored = fs.readdirSync(path.join(dir, 'vendor'), {recursive: true, withFileTypes: true}).filter(entry => {
|
|
127
128
|
if (!entry.isFile() && !entry.isDirectory()) throw Error(`Unsupported vendored tool entry: ${entry.name}`);
|
|
128
129
|
return entry.isFile();
|