@runeditrun/rer 0.2.85 → 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/README.md +138 -29
- package/cli/README.md +61 -1
- package/cli/agent-bindings.mjs +25 -0
- package/cli/agent-door.mjs +145 -0
- package/cli/agent-fixtures.mjs +16 -0
- package/cli/agent-journey-fixtures.mjs +17 -0
- package/cli/agent-mail.mjs +54 -0
- package/cli/agent-network.mjs +64 -0
- package/cli/agent-reviewers.mjs +110 -0
- package/cli/agent-rpc.mjs +23 -0
- package/cli/agent-secrets.mjs +23 -0
- package/cli/agent-sponsors.mjs +43 -0
- package/cli/agent-surface.mjs +34 -0
- package/cli/agent-verifier.mjs +31 -0
- package/cli/agent-webhooks.mjs +19 -0
- package/cli/authoring.mjs +2 -1
- package/cli/business/archive-task.mjs +32 -0
- package/cli/business/carry.mjs +3 -1
- package/cli/business/catchup-task.mjs +42 -0
- package/cli/business/choices.mjs +97 -0
- package/cli/business/command.mjs +23 -5
- package/cli/business/connect.mjs +19 -7
- package/cli/business/detector.mjs +4 -1
- package/cli/business/device.mjs +13 -0
- package/cli/business/export-inputs.mjs +69 -0
- package/cli/business/export-task.mjs +17 -0
- package/cli/business/invocation.mjs +8 -1
- package/cli/business/keychain.mjs +8 -1
- package/cli/business/lease.mjs +11 -1
- package/cli/business/local-commands.mjs +79 -31
- package/cli/business/outbound.mjs +9 -4
- package/cli/business/parsers-config.mjs +8 -7
- package/cli/business/parsers-syntax.mjs +7 -3
- package/cli/business/permissions.mjs +2 -0
- package/cli/business/questions.mjs +89 -9
- package/cli/business/setup-command.mjs +49 -0
- package/cli/business/setup-company.json +15 -0
- package/cli/business/setup-demo.mjs +95 -0
- package/cli/business/state.mjs +44 -10
- package/cli/business/supervisor.mjs +94 -35
- package/cli/business/vendor-door.mjs +230 -0
- package/cli/business/vendors/README.md +29 -3
- package/cli/business/vendors/common.mjs +8 -6
- package/cli/business/vendors/index.mjs +22 -11
- package/cli/business/vendors/sorry.mjs +106 -0
- package/cli/contract.mjs +2 -2
- package/cli/demo-deploy-error.mjs +14 -0
- package/cli/demo-native.mjs +4 -1
- package/cli/deploy-config.mjs +1 -1
- package/cli/deploy-owner-input.mjs +3 -1
- package/cli/deploy-variables.mjs +89 -0
- package/cli/door-clauses.mjs +157 -0
- package/cli/export.mjs +17 -4
- package/cli/hosted-output.mjs +31 -8
- package/cli/inspect.mjs +4 -0
- package/cli/jsonc.mjs +8 -4
- package/cli/lifecycle.mjs +3 -1
- package/cli/main.mjs +1 -0
- package/cli/managed-data-schema.mjs +14 -1
- package/cli/managed-data.mjs +8 -4
- package/cli/portability-empty.mjs +6 -0
- package/cli/portability-migrations.mjs +26 -4
- package/cli/portability-worker.mjs +2 -1
- package/cli/portability.mjs +1 -0
- package/cli/production-auth.mjs +2 -2
- package/cli/production-mail.mjs +19 -3
- package/cli/server-registry.mjs +2 -0
- package/edition-authoring/archive-source.mjs +65 -0
- package/edition-authoring/base-copies.mjs +108 -21
- package/edition-authoring/cli.mjs +1 -1
- package/edition-authoring/copy-namespaces.mjs +28 -0
- package/edition-authoring/edition-migrations.mjs +7 -3
- package/edition-authoring/files.mjs +2 -1
- package/edition-authoring/module-closure.mjs +58 -27
- package/edition-authoring/module-edges.mjs +13 -2
- package/edition-authoring/workflow-copies.mjs +1 -1
- package/edition-authoring/workflow-scripts.mjs +12 -3
- package/foundation/runtime/contract-docs.mjs +220 -32
- package/foundation/runtime/contract-prose-patterns.mjs +14 -0
- package/foundation/runtime/contract-prose.mjs +88 -0
- package/global/CHANGELOG.md +151 -0
- package/global/README.md +138 -29
- package/global/door/command.mjs +3 -1
- package/global/main.mjs +1 -1
- package/modules/agent-door/CLAUSES.md +215 -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 +63 -0
- package/modules/agent-door/conformance/authority.d.mts +2 -0
- package/modules/agent-door/conformance/authority.mjs +17 -0
- package/modules/agent-door/conformance/crypto.mjs +36 -0
- package/modules/agent-door/conformance/discovery.mjs +61 -0
- package/modules/agent-door/conformance/fixtures.mjs +41 -0
- package/modules/agent-door/conformance/index.mjs +41 -0
- package/modules/agent-door/conformance/injection.mjs +24 -0
- package/modules/agent-door/conformance/invocation.mjs +33 -0
- package/modules/agent-door/conformance/journey.mjs +117 -0
- package/modules/agent-door/conformance/narrowing.d.mts +2 -0
- package/modules/agent-door/conformance/narrowing.mjs +29 -0
- package/modules/agent-door/conformance/negative.mjs +48 -0
- package/modules/agent-door/conformance/network-modules.mjs +86 -0
- package/modules/agent-door/conformance/network-runtime.mjs +46 -0
- package/modules/agent-door/conformance/policy-phases.mjs +83 -0
- package/modules/agent-door/conformance/protocol.mjs +153 -0
- package/modules/agent-door/conformance/replay.mjs +39 -0
- package/modules/agent-door/conformance/schema.mjs +71 -0
- package/modules/agent-door/conformance/security.mjs +34 -0
- package/modules/agent-door/conformance/sponsors.mjs +68 -0
- package/modules/agent-door/conformance/step-hooks.mjs +4 -0
- package/modules/agent-door/conformance/surface.mjs +92 -0
- package/modules/agent-door/conformance/target.mjs +19 -0
- package/modules/agent-door/conformance/tool-name.d.mts +1 -0
- package/modules/agent-door/conformance/tool-name.mjs +7 -0
- package/modules/agent-door/conformance/webhooks.mjs +31 -0
- package/modules/container/image-variables.mjs +8 -2
- package/modules/delivery-producer/mail.mjs +20 -0
- package/modules/demo-host/README.md +6 -0
- package/modules/demo-host/ownership.mjs +39 -0
- package/modules/demo-host/plan.mjs +2 -1
- package/modules/demo-host/remove.mjs +6 -1
- package/modules/import-kit/schema/importer-verification-receipt.schema.json +171 -0
- package/modules/import-kit/schema/importers.schema.json +107 -0
- package/modules/import-kit/src/door/ADOPTING.md +20 -0
- package/modules/import-kit/src/door/README.md +2 -1
- package/modules/import-kit/src/door/admission.ts +5 -3
- package/modules/import-kit/src/door/archive.ts +5 -2
- package/modules/import-kit/src/door/authority.ts +1 -0
- package/modules/import-kit/src/door/grants.ts +1 -1
- package/modules/import-kit/src/door/handler.ts +14 -8
- package/modules/import-kit/src/door/index.ts +1 -1
- package/modules/import-kit/src/door/jobs.ts +40 -0
- package/modules/import-kit/src/door/operator.ts +3 -3
- package/modules/import-kit/src/door/planning.ts +10 -6
- package/modules/import-kit/src/door/protocol.ts +2 -2
- package/modules/import-kit/src/door/raw.ts +25 -0
- package/modules/import-kit/src/door/refusals.ts +1 -0
- package/modules/import-kit/src/door/types.ts +26 -6
- package/modules/import-kit/src/receipt/encoding.ts +37 -0
- package/modules/import-kit/src/receipt/index.ts +69 -0
- package/modules/import-kit/src/receipt/policy.ts +24 -0
- package/modules/import-kit/src/receipt/types.ts +64 -0
- package/modules/import-kit/src/receipt/uri.ts +45 -0
- package/modules/import-kit/src/receipt/validation.ts +87 -0
- package/modules/import-kit/src/status/encoding.ts +13 -0
- package/modules/import-kit/src/status/evidence.ts +218 -0
- package/modules/import-kit/src/status/index.ts +56 -0
- package/modules/import-kit/src/status/schema.ts +208 -0
- package/modules/import-kit/src/status/types.ts +86 -0
- package/modules/operator-auth/accounts/delegated.mjs +48 -0
- package/modules/operator-auth/index.d.mts +7 -0
- package/modules/operator-auth/service.mjs +2 -0
- package/modules/portability/README.md +37 -13
- package/modules/portability/bridge.mjs +22 -2
- package/modules/portability/catalogue.mjs +12 -2
- package/modules/portability/copies.mjs +8 -1
- package/modules/portability/derived.mjs +33 -0
- package/modules/portability/http-errors.mjs +1 -1
- package/modules/portability/import.mjs +14 -7
- package/package.json +4 -2
- package/scripts/publish-check/copy_identities.py +3 -1
- package/scripts/publish-check/github_refs.py +32 -13
- package/cli/business/opt-ins.mjs +0 -37
|
@@ -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,9 +10,9 @@ 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
|
-
if (mail.senderIssue && options.verb === 'deploy') throw refuse(`${mail.senderIssue} Nothing was built or uploaded.`);
|
|
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;
|
|
17
17
|
if (mail.canInspect && !options.dryRun && declarationPath) {
|
|
18
18
|
try {
|
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' };
|
|
@@ -11,11 +13,16 @@ const present = value => typeof value === 'string' && Boolean(value.trim());
|
|
|
11
13
|
// The sender forms the mail runtime sends from: a bare address or "Display Name <address>".
|
|
12
14
|
const sender = value => { try { parseAddress(value); return true; } catch { return false; } };
|
|
13
15
|
const SENDER = "MAIL_FROM (a real sender on your provider's verified domain; bare address or Display Name <address>)";
|
|
16
|
+
const fixtureSender = value => {
|
|
17
|
+
if (!sender(value)) return false;
|
|
18
|
+
const domain = parseAddress(value).email.toLowerCase().split('@')[1];
|
|
19
|
+
return /(?:^|\.)(?:invalid|example|test|localhost)$/.test(domain)
|
|
20
|
+
|| /(?:^|\.)example\.(?:com|net|org)$/.test(domain);
|
|
21
|
+
};
|
|
14
22
|
const placeholderSender = value => {
|
|
15
23
|
if (!sender(value)) return false;
|
|
16
24
|
const { email } = parseAddress(value), [local, domain] = email.toLowerCase().split('@');
|
|
17
|
-
return
|
|
18
|
-
|| /(?:^|\.)example\.(?:com|net|org)$/.test(domain)
|
|
25
|
+
return fixtureSender(value)
|
|
19
26
|
|| /^(?:your-?domain|your-?business|fake|placeholder|changeme)\./.test(domain)
|
|
20
27
|
|| /^(?:fake|placeholder|change-?me|replace-?me|your-?email|your-?name|you)(?:[+._-]|$)/.test(local);
|
|
21
28
|
};
|
|
@@ -23,13 +30,16 @@ const placeholderSender = value => {
|
|
|
23
30
|
// Packaging can declare inputs that a product's deploy adapter adds to the
|
|
24
31
|
// root declaration later. Read that source contract, never arbitrary ambient
|
|
25
32
|
// keys or the adapter's executable source, before any build or provider write.
|
|
26
|
-
export async function productionMail(root, declaration, env, declarationPath = 'deploy.json') {
|
|
33
|
+
export async function productionMail(root, declaration, env, declarationPath = 'deploy.json', adapter) {
|
|
27
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));
|
|
28
37
|
let senderFix = `Edit vars.MAIL_FROM in ${declarationPath}`;
|
|
29
38
|
const environmentFix = name => `Set ${name} in your environment or owned 0600 --env-file`;
|
|
30
39
|
for (const secret of declaration.secrets ?? []) {
|
|
31
40
|
secrets.add(secret.binding);
|
|
32
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] });
|
|
33
43
|
bindings[secret.binding] = env[secret.environment];
|
|
34
44
|
if (secret.binding === 'MAIL_FROM') senderFix = environmentFix(secret.environment);
|
|
35
45
|
}
|
|
@@ -42,6 +52,7 @@ export async function productionMail(root, declaration, env, declarationPath = '
|
|
|
42
52
|
try { spec = select(JSON.parse(text)); }
|
|
43
53
|
catch { throw refuse(`Restore a valid mail deployment declaration at ${path}. Nothing was built or uploaded.`); }
|
|
44
54
|
if (!spec) continue;
|
|
55
|
+
senders.push({ source: `${path} publicVariables.MAIL_FROM`, value: spec.publicVariables?.MAIL_FROM });
|
|
45
56
|
for (const name of spec.publicVariableNames ?? []) publicInputs.add(name);
|
|
46
57
|
for (const [name, value] of Object.entries(spec.publicVariables ?? {})) {
|
|
47
58
|
if (!(name in bindings) || name === 'MAIL_PROVIDER' && bindings[name] === 'later') {
|
|
@@ -54,15 +65,19 @@ export async function productionMail(root, declaration, env, declarationPath = '
|
|
|
54
65
|
// A root secret's explicit environment-to-binding mapping wins.
|
|
55
66
|
if (!declaration.secrets?.some(secret => secret.binding === name) && present(env[name])) {
|
|
56
67
|
bindings[name] = env[name];
|
|
68
|
+
if (name === 'MAIL_FROM') senders.push({ source: `${path} secret MAIL_FROM (environment or --env-file)`, value: env[name] });
|
|
57
69
|
if (name === 'MAIL_FROM') senderFix = environmentFix(name);
|
|
58
70
|
}
|
|
59
71
|
}
|
|
60
72
|
for (const provider of spec.mail?.providers ?? []) if (providers.includes(provider)) declaredProviders.add(provider);
|
|
61
73
|
}
|
|
62
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] });
|
|
63
76
|
bindings[name] = env[name];
|
|
64
77
|
if (name === 'MAIL_FROM') senderFix = environmentFix(name);
|
|
65
78
|
}
|
|
79
|
+
try { validateMailSenders(senders); }
|
|
80
|
+
catch (error) { throw refuse(`${error.message} Nothing was built or uploaded.`); }
|
|
66
81
|
let senderIssue;
|
|
67
82
|
if (present(bindings.MAIL_FROM) && (!sender(bindings.MAIL_FROM) || placeholderSender(bindings.MAIL_FROM))) {
|
|
68
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.`;
|
|
@@ -99,6 +114,7 @@ export async function productionMail(root, declaration, env, declarationPath = '
|
|
|
99
114
|
return {
|
|
100
115
|
declared: 'MAIL_PROVIDER' in bindings || publicInputs.has('MAIL_PROVIDER') || secrets.has('MAIL_API_KEY') || selected.length > 0,
|
|
101
116
|
senderIssue,
|
|
117
|
+
fixtureSender: fixtureSender(bindings.MAIL_FROM),
|
|
102
118
|
configured: (live = []) => routes.some(missing => missing(live).length === 0),
|
|
103
119
|
canInspect: sender(bindings.MAIL_FROM) && !senderIssue && routes.length > 0,
|
|
104
120
|
missing: routes.length ? routes.map(missing => missing([]).join(', ')).join(' or ') : [
|
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{
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// A source archive supplies one caller-identified revision, never Git history.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import crypto from 'node:crypto';
|
|
5
|
+
import {hash, safe} from './files.mjs';
|
|
6
|
+
|
|
7
|
+
const limit = 64 * 1024 * 1024;
|
|
8
|
+
const objectId = bytes => crypto.createHash('sha1').update(`blob ${bytes.length}\0`).update(bytes).digest('hex');
|
|
9
|
+
|
|
10
|
+
export function archiveReader(directory, revision) {
|
|
11
|
+
if (!/^[a-f0-9]{40}$/.test(revision)) throw Error('A Base archive requires its immutable full 40-character Base commit in --ref');
|
|
12
|
+
if (!fs.lstatSync(directory).isDirectory()) throw Error('Base archive must be a plain directory without .git');
|
|
13
|
+
const root = fs.realpathSync(directory), tree = new Map(), objects = new Map();
|
|
14
|
+
function bytes(name) {
|
|
15
|
+
const filename = path.join(root, name), stat = fs.lstatSync(filename);
|
|
16
|
+
if (!stat.isFile()) throw Error(`Base archive source is not a regular file: ${name}`);
|
|
17
|
+
if (stat.size > limit) throw Error('Base archive source output exceeds the 64 MiB acquisition limit');
|
|
18
|
+
return fs.readFileSync(filename);
|
|
19
|
+
}
|
|
20
|
+
function walk(prefix = '') {
|
|
21
|
+
for (const name of fs.readdirSync(path.join(root, prefix)).sort((a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b)))) {
|
|
22
|
+
if (name.toLowerCase() === '.git') throw Error('Base archive must be a plain directory without .git');
|
|
23
|
+
const relative = safe(prefix ? `${prefix}/${name}` : name), stat = fs.lstatSync(path.join(root, relative));
|
|
24
|
+
if (stat.isDirectory()) walk(relative);
|
|
25
|
+
else if (stat.isFile()) {
|
|
26
|
+
const object = objectId(bytes(relative)), mode = stat.mode & 0o100 ? '100755' : '100644';
|
|
27
|
+
tree.set(relative, {object, mode});
|
|
28
|
+
if (!objects.has(object)) objects.set(object, relative);
|
|
29
|
+
} else throw Error(`Unsupported Base archive entry: ${relative}; supply regular files and directories only`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
walk();
|
|
33
|
+
const orderedTree = new Map([...tree].sort(([a], [b]) => Buffer.compare(Buffer.from(a), Buffer.from(b))));
|
|
34
|
+
const history = () => { throw Error('Base archive has no Git history. Repeat with --base <checkout> containing the recorded and target commits; no files were refreshed.'); };
|
|
35
|
+
return {
|
|
36
|
+
historyAvailable: false,
|
|
37
|
+
objectId,
|
|
38
|
+
tree(pin) { return pin === revision ? orderedTree : history(); },
|
|
39
|
+
blobs(ids) {
|
|
40
|
+
const result = new Map(), unique = [...new Set(ids)];
|
|
41
|
+
for (let offset = 0; offset < unique.length; offset += 100) {
|
|
42
|
+
let size = 0;
|
|
43
|
+
for (const object of unique.slice(offset, offset + 100)) {
|
|
44
|
+
const name = objects.get(object);
|
|
45
|
+
if (!name) throw Error(`Base archive object ${object} is not available`);
|
|
46
|
+
const data = bytes(name);
|
|
47
|
+
size += data.length;
|
|
48
|
+
if (size > limit) throw Error('Base archive source output exceeds the 64 MiB acquisition limit');
|
|
49
|
+
if (objectId(data) !== object) throw Error(`Base archive changed while reading ${name}; retry with an unchanged archive`);
|
|
50
|
+
result.set(object, data);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
},
|
|
55
|
+
digests(ids) { return new Map([...this.blobs(ids)].map(([object, data]) => [object, hash(data)])); },
|
|
56
|
+
contains: history,
|
|
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
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -17,6 +17,7 @@ import {requireMaterializedCopies, preflightRefresh} from './copy-checkout.mjs';
|
|
|
17
17
|
import {completeModuleCopies} from './module-closure.mjs';
|
|
18
18
|
import {editionMigrations} from './edition-migrations.mjs';
|
|
19
19
|
import {adoptWorkflowTemplates, completeWorkflowHelpers} from './workflow-copies.mjs';
|
|
20
|
+
import {archiveReader} from './archive-source.mjs';
|
|
20
21
|
|
|
21
22
|
export const RECORD = 'base-copies.json';
|
|
22
23
|
const commit = /^[a-f0-9]{40}$/, sha256 = /^[a-f0-9]{64}$/;
|
|
@@ -44,7 +45,11 @@ function declaredRemote(record, root) {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
// An explicit checkout, else the record's legacy repository, else the seed's declaration.
|
|
47
|
-
function open(record, base, root, offline = false) {
|
|
48
|
+
function open(record, base, root, offline = false, baseArchive = null, revision = null) {
|
|
49
|
+
if (baseArchive) {
|
|
50
|
+
if (base) throw Error('Choose either --base or --base-archive');
|
|
51
|
+
return {repository: path.resolve(baseArchive), read: archiveReader(baseArchive, revision), head: revision, offline: true, close() {}};
|
|
52
|
+
}
|
|
48
53
|
if (base) {
|
|
49
54
|
const repository = fs.realpathSync(base);
|
|
50
55
|
const source = gitReader(repository, offline);
|
|
@@ -67,25 +72,74 @@ function open(record, base, root, offline = false) {
|
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
export function options(args, count) {
|
|
70
|
-
const result = {positional: [], record: RECORD, base: null, offline: false, editionMigration: []};
|
|
75
|
+
const result = {positional: [], record: RECORD, base: null, baseArchive: null, offline: false, editionMigration: []};
|
|
71
76
|
for (let i = 0; i < args.length; i++) {
|
|
72
77
|
const arg = args[i];
|
|
73
78
|
if (arg === '--offline') result.offline = true;
|
|
79
|
+
else if (arg === '--from-api') result.fromApi = true;
|
|
74
80
|
else if (arg === '--edition-migration') {
|
|
75
81
|
if (!args[i + 1] || args[i + 1].startsWith('--')) throw Error(`${arg} requires a value`);
|
|
76
82
|
result.editionMigration.push(args[++i]);
|
|
77
83
|
}
|
|
78
|
-
else if (
|
|
79
|
-
if (!args[i + 1]) throw Error(`${arg} requires a value`);
|
|
80
|
-
|
|
84
|
+
else if (['--record', '--base', '--base-archive', '--ref'].includes(arg)) {
|
|
85
|
+
if (!args[i + 1] || args[i + 1].startsWith('--')) throw Error(`${arg} requires a value`);
|
|
86
|
+
const key = arg === '--base-archive' ? 'baseArchive' : arg.slice(2);
|
|
87
|
+
if (key === 'ref' && result.ref) throw Error('Provide --ref only once');
|
|
88
|
+
result[key] = args[++i];
|
|
81
89
|
} else if (arg.startsWith('--')) throw Error(`Unknown option: ${arg}`);
|
|
82
90
|
else result.positional.push(arg);
|
|
83
91
|
}
|
|
84
|
-
if (result.
|
|
92
|
+
if (result.ref) {
|
|
93
|
+
if (![1, 3].includes(count) || result.positional.length !== count - 1) throw Error('Use --ref instead of the positional Base revision');
|
|
94
|
+
result.positional.push(result.ref);
|
|
95
|
+
}
|
|
96
|
+
if (result.base && result.baseArchive) throw Error('Choose either --base or --base-archive');
|
|
97
|
+
if (result.positional.length !== count) throw Error('Usage: verify-base [--record <file>] [--base <checkout>] [--offline] | record-base <path> <origin-path> <revision>|--ref <revision> [--record <file>] [--base <checkout>|--base-archive <directory>|--from-api|--offline --base <checkout>] | adapt-base <file> [--record <file>] | refresh-base <revision>|--ref <revision> [--record <file>] [--base <checkout>|--base-archive <directory>]');
|
|
98
|
+
if (result.fromApi && count !== 3) throw Error('--from-api is only supported by record-base');
|
|
85
99
|
safe(result.record);
|
|
86
100
|
return result;
|
|
87
101
|
}
|
|
88
102
|
|
|
103
|
+
// Read immutable Git objects through GitHub, without cloning Base or trusting
|
|
104
|
+
// an archive's filesystem modes. Refuse incomplete trees and verify blob IDs.
|
|
105
|
+
function apiReader(record, root, revision) {
|
|
106
|
+
const declared = record.repository ?? baseRepository(root);
|
|
107
|
+
const repository = /^(?:https:\/\/github\.com\/)?([\w.-]+\/[\w.-]+?)(?:\.git)?$/.exec(declared)?.[1];
|
|
108
|
+
if (!repository) throw Error('--from-api requires a GitHub Base repository');
|
|
109
|
+
const request = endpoint => {
|
|
110
|
+
try {
|
|
111
|
+
return JSON.parse(execFileSync('gh', ['api', `repos/${repository}/git/${endpoint}`], {
|
|
112
|
+
encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 60_000, maxBuffer: 64 * 1024 * 1024,
|
|
113
|
+
}));
|
|
114
|
+
} catch { throw Error(`Cannot read immutable Base ${revision} from the GitHub API; no copy record was changed.`); }
|
|
115
|
+
};
|
|
116
|
+
const pinned = request(`commits/${revision}`);
|
|
117
|
+
if (pinned.sha !== revision || !commit.test(pinned.tree?.sha)) throw Error('Base API did not resolve the immutable commit; no copy record was changed.');
|
|
118
|
+
const tree = request(`trees/${pinned.tree.sha}?recursive=1`);
|
|
119
|
+
if (tree.sha !== pinned.tree.sha || tree.truncated !== false || !Array.isArray(tree.tree)) throw Error('Incomplete Base API tree; no copy record was changed.');
|
|
120
|
+
const entries = new Map();
|
|
121
|
+
for (const entry of tree.tree) {
|
|
122
|
+
safe(entry.path);
|
|
123
|
+
if (entry.type === 'blob' && FILE_MODES.includes(entry.mode)) {
|
|
124
|
+
if (!commit.test(entry.sha)) throw Error('Invalid Base API blob identity');
|
|
125
|
+
entries.set(entry.path, {object: entry.sha, mode: entry.mode});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
tree: () => entries,
|
|
130
|
+
digests(objects) {
|
|
131
|
+
return new Map([...new Set(objects)].map(object => {
|
|
132
|
+
const blob = request(`blobs/${object}`);
|
|
133
|
+
if (blob.sha !== object || blob.encoding !== 'base64' || typeof blob.content !== 'string') throw Error('Invalid Base API blob');
|
|
134
|
+
const bytes = Buffer.from(blob.content, 'base64');
|
|
135
|
+
const actual = crypto.createHash('sha1').update(`blob ${bytes.length}\0`).update(bytes).digest('hex');
|
|
136
|
+
if (blob.size !== bytes.length || actual !== object) throw Error('Base API blob integrity mismatch; no copy record was changed.');
|
|
137
|
+
return [object, hash(bytes)];
|
|
138
|
+
}));
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
89
143
|
export function validate(record) {
|
|
90
144
|
const legacy = record?.repository;
|
|
91
145
|
if (record?.schemaVersion !== 1 || (legacy !== undefined && (typeof legacy !== 'string' || !legacy || legacy.startsWith('-'))) || !Array.isArray(record.copies)) {
|
|
@@ -101,6 +155,14 @@ export function validate(record) {
|
|
|
101
155
|
safe(name);
|
|
102
156
|
if (!within(name, copy.path) || !sha256.test(digest)) throw Error(`Invalid recorded copy file: ${name}`);
|
|
103
157
|
}
|
|
158
|
+
if (copy.originFiles !== undefined) {
|
|
159
|
+
if (!Array.isArray(copy.originFiles) || new Set(copy.originFiles).size !== copy.originFiles.length) throw Error(`Invalid Base source membership: ${copy.path}`);
|
|
160
|
+
for (const name of copy.originFiles) {
|
|
161
|
+
safe(name);
|
|
162
|
+
if (!within(name, copy.originPath)) throw Error(`Invalid Base source membership: ${name}`);
|
|
163
|
+
}
|
|
164
|
+
for (const name of Object.keys(copy.files)) if (!copy.adapted?.[name] && !copy.originFiles.includes(mapped(name, copy.path, copy.originPath))) throw Error(`Missing Base source membership: ${name}`);
|
|
165
|
+
}
|
|
104
166
|
if (copy.adapted !== undefined) {
|
|
105
167
|
if (!copy.adapted || typeof copy.adapted !== 'object' || Array.isArray(copy.adapted)) throw Error(`Invalid adaptations: ${copy.path}`);
|
|
106
168
|
for (const [name, revision] of Object.entries(copy.adapted)) {
|
|
@@ -186,6 +248,7 @@ function containsHistory(origin, source, revision, introduced) {
|
|
|
186
248
|
}
|
|
187
249
|
|
|
188
250
|
function reader(origin) {
|
|
251
|
+
if (origin.read) return origin.read;
|
|
189
252
|
const source = origin.source ?? gitReader(origin.repository);
|
|
190
253
|
const format = source.git('rev-parse', '--show-object-format');
|
|
191
254
|
const trees = new Map(), ancestry = new Map();
|
|
@@ -253,7 +316,8 @@ function recordFile(root, recordPath) {
|
|
|
253
316
|
return filename;
|
|
254
317
|
}
|
|
255
318
|
|
|
256
|
-
export function verifyCopies(root, {record: recordPath, base, offline}) {
|
|
319
|
+
export function verifyCopies(root, {record: recordPath, base, baseArchive, offline}) {
|
|
320
|
+
if (baseArchive) throw Error('--base-archive is supported by record-base and refresh-base; use verify-base --offline to check recorded local bytes');
|
|
257
321
|
const filename = recordFile(root, recordPath);
|
|
258
322
|
if (!filename) throw Error(`No ${recordPath} found; run record-base <path> <origin-path> <commit> first`);
|
|
259
323
|
const record = validate(JSON.parse(fs.readFileSync(filename, 'utf8')));
|
|
@@ -326,16 +390,18 @@ export function verifyCopies(root, {record: recordPath, base, offline}) {
|
|
|
326
390
|
};
|
|
327
391
|
}
|
|
328
392
|
|
|
329
|
-
export function recordCopy(root, {positional: [localPath, originPath, revision], record: recordPath, base}) {
|
|
393
|
+
export function recordCopy(root, {positional: [localPath, originPath, revision], record: recordPath, base, baseArchive, offline, fromApi}) {
|
|
330
394
|
safe(localPath); safe(originPath);
|
|
331
395
|
if (!commit.test(revision)) throw Error('Record an immutable full Base commit');
|
|
332
396
|
const filename = recordFile(root, recordPath) || path.join(root, recordPath);
|
|
333
397
|
const record = validate(fs.existsSync(filename) ? JSON.parse(fs.readFileSync(filename, 'utf8')) : {schemaVersion: 1, copies: []});
|
|
334
398
|
const files = seedFiles(root);
|
|
335
|
-
|
|
336
|
-
|
|
399
|
+
if (fromApi && (base || baseArchive || offline)) throw Error('--from-api cannot be combined with --base, --base-archive or --offline');
|
|
400
|
+
if (offline && !base && !baseArchive) throw Error('record-base --offline requires --base <checkout> or --base-archive <directory>; use --from-api while online');
|
|
401
|
+
const origin = fromApi ? {close() {}} : open(record, base, root, offline, baseArchive, revision);
|
|
337
402
|
try {
|
|
338
|
-
const read = reader(origin);
|
|
403
|
+
const read = fromApi ? apiReader(record, root, revision) : reader(origin);
|
|
404
|
+
delete record.repository;
|
|
339
405
|
const sources = [...read.tree(revision)].filter(([name]) => within(name, originPath));
|
|
340
406
|
if (!sources.length) throw Error(`No Base source at ${originPath} in ${revision}`);
|
|
341
407
|
const present = sources.filter(([name]) => files.get(mapped(name, originPath, localPath))?.regular);
|
|
@@ -345,7 +411,8 @@ export function recordCopy(root, {positional: [localPath, originPath, revision],
|
|
|
345
411
|
const ordered = present.map(([name, {object, mode}]) => [mapped(name, originPath, localPath), digests.get(object), mode]).sort(([a], [b]) => a.localeCompare(b));
|
|
346
412
|
const recorded = Object.fromEntries(ordered.map(([name, digest]) => [name, digest]));
|
|
347
413
|
const modes = Object.fromEntries(ordered.map(([name, , mode]) => [name, mode]));
|
|
348
|
-
|
|
414
|
+
const originFiles = sources.map(([name]) => name).sort();
|
|
415
|
+
record.copies = [...record.copies.filter(copy => copy.path !== localPath), {path: localPath, originPath, revision, files: recorded, modes, originFiles}].sort((a, b) => a.path.localeCompare(b.path));
|
|
349
416
|
validate(record);
|
|
350
417
|
fs.writeFileSync(filename, json(record));
|
|
351
418
|
return {
|
|
@@ -360,7 +427,8 @@ export function recordCopy(root, {positional: [localPath, originPath, revision],
|
|
|
360
427
|
|
|
361
428
|
// Explicitly transfer one recorded file to seed ownership without changing its bytes
|
|
362
429
|
// or its Base digest/mode. The per-file revision survives later whole-copy refreshes.
|
|
363
|
-
export function adaptCopy(root, {positional: [name], record: recordPath}) {
|
|
430
|
+
export function adaptCopy(root, {positional: [name], record: recordPath, baseArchive, ref}) {
|
|
431
|
+
if (baseArchive || ref) throw Error('--base-archive and --ref are supported by record-base and refresh-base');
|
|
364
432
|
safe(name);
|
|
365
433
|
const filename = recordFile(root, recordPath);
|
|
366
434
|
if (!filename) throw Error(`No ${recordPath} found; run record-base first`);
|
|
@@ -387,15 +455,15 @@ export function adaptCopy(root, {positional: [name], record: recordPath}) {
|
|
|
387
455
|
// entirely, just as absent files are dropped from directory copies. Local edits
|
|
388
456
|
// are refused, never overwritten, as is any change to an existing file under a
|
|
389
457
|
// migrations folder.
|
|
390
|
-
export function refreshCopies(root, {positional: [revision], record: recordPath, base, offline, editionMigration = []}) {
|
|
458
|
+
export function refreshCopies(root, {positional: [revision], record: recordPath, base, baseArchive, offline, editionMigration = []}) {
|
|
391
459
|
if (!commit.test(revision)) throw Error('Refresh requires an immutable full 40-character Base commit. Resolve the release tag with git -C <base-checkout> rev-parse <tag>^{commit}, then repeat with --ref <commit> --base <base-checkout>.');
|
|
392
|
-
if (offline && !base) throw Error('Offline refresh needs a Base checkout. Repeat rer refresh-base --ref <commit> --offline --base <checkout> containing that commit
|
|
460
|
+
if (offline && !base && !baseArchive) throw Error('Offline refresh needs a Base checkout or archive. Repeat rer refresh-base --ref <commit> --offline --base <checkout> containing that commit, or use --base-archive <directory>.');
|
|
393
461
|
const filename = recordFile(root, recordPath);
|
|
394
462
|
if (!filename) throw Error(`No ${recordPath} found; run record-base <path> <origin-path> <commit> first`);
|
|
395
463
|
const record = validate(JSON.parse(fs.readFileSync(filename, 'utf8')));
|
|
396
464
|
const files = seedFiles(root);
|
|
397
465
|
requireMaterializedCopies(root, record, files);
|
|
398
|
-
const origin = open(record, base, root, offline);
|
|
466
|
+
const origin = open(record, base, root, offline, baseArchive, revision);
|
|
399
467
|
origin.refresh = {revision, recordPath, editionMigration};
|
|
400
468
|
let writing = false, notices = [];
|
|
401
469
|
try {
|
|
@@ -437,8 +505,14 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
437
505
|
// removals, and a still-present singleton must retain a Base source.
|
|
438
506
|
const retired = Object.keys(copy.files).length === 1 && Object.hasOwn(copy.files, copy.path) &&
|
|
439
507
|
!files.has(copy.path) && !fs.existsSync(path.join(root, copy.path)) && !Object.hasOwn(copy.adapted || {}, copy.path);
|
|
440
|
-
const pinned = read.tree(copy.revision);
|
|
441
508
|
if (retired) return {copy, sources: [], retired, removed: [copy.path]};
|
|
509
|
+
// An archive has only the target tree. Complete prior source membership
|
|
510
|
+
// retains the distinction between omitted old files and new additions.
|
|
511
|
+
let pinned;
|
|
512
|
+
if (baseArchive && copy.revision !== revision) {
|
|
513
|
+
if (!copy.originFiles) throw Error(`Base copy ${copy.path} lacks prior source membership (originFiles). Repeat this refresh with --base <checkout> containing the recorded and target commits; future archive refreshes can then preserve omitted files. No files were refreshed.`);
|
|
514
|
+
pinned = new Set(copy.originFiles);
|
|
515
|
+
} else pinned = read.tree(copy.revision);
|
|
442
516
|
const tests = Object.keys(copy.files).some(name => testSource(mapped(name, copy.path, copy.originPath)));
|
|
443
517
|
const sources = [...next].filter(([name]) => {
|
|
444
518
|
if (!within(name, copy.originPath)) return false;
|
|
@@ -459,7 +533,8 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
459
533
|
const templates = adoptWorkflowTemplates(root, plans, {tree: next, read, revision, files});
|
|
460
534
|
notices = templates.notices;
|
|
461
535
|
completeWorkflowHelpers(root, plans, {tree: next, read, revision});
|
|
462
|
-
const
|
|
536
|
+
const relocations = new Map();
|
|
537
|
+
const withheld = completeModuleCopies(root, plans, {tree: next, read, revision, base: origin.repository, ownerSources, relocations,
|
|
463
538
|
deliveries: migrations.flatMap(step => step.deliver.map(source => ({source, origin: step.origin, importers: step.copies})))});
|
|
464
539
|
// Closure may add individually recorded siblings when the seed originally
|
|
465
540
|
// selected runtime files one at a time instead of copying the directory.
|
|
@@ -493,9 +568,21 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
493
568
|
const {object, mode} = byName.get(name);
|
|
494
569
|
if (!Object.hasOwn(copy.files, name)) added.push(name);
|
|
495
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
|
+
}
|
|
496
578
|
}
|
|
497
579
|
changes.push({path: copy.path, from: copy.revision, files: sources.length, added, removed});
|
|
498
|
-
|
|
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()});
|
|
499
586
|
}
|
|
500
587
|
record.copies = plans.filter(plan => !plan.retired).map(plan => plan.copy);
|
|
501
588
|
delete record.repository;
|
|
@@ -510,12 +597,12 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
510
597
|
noLinks(root, name);
|
|
511
598
|
const target = path.join(root, name);
|
|
512
599
|
fs.mkdirSync(path.dirname(target), {recursive: true});
|
|
513
|
-
fs.writeFileSync(target, bytes.get(object));
|
|
600
|
+
fs.writeFileSync(target, relocations.get(name) ?? bytes.get(object));
|
|
514
601
|
fs.chmodSync(target, mode === '100755' ? 0o755 : 0o644);
|
|
515
602
|
}
|
|
516
603
|
}
|
|
517
604
|
fs.writeFileSync(filename, json(record));
|
|
518
|
-
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.'};
|
|
519
606
|
} catch (error) {
|
|
520
607
|
if (!writing && !/no files were refreshed/i.test(error.message)) error.message += ' No files were refreshed.';
|
|
521
608
|
if (!writing && notices.length) error.message += '\n' + notices.join('\n');
|
|
@@ -77,7 +77,7 @@ try {
|
|
|
77
77
|
} else if (command === 'record-base') result = recordCopy(root, options(args.slice(1), 3));
|
|
78
78
|
else if (command === 'adapt-base') result = adaptCopy(root, options(args.slice(1), 1));
|
|
79
79
|
else if (command === 'refresh-base') result = refreshCopies(root, options(args.slice(1), 1));
|
|
80
|
-
else throw Error('Usage: cli.mjs adopt|inspect|lock|check|receipt <sidecar-json>|changes|extract <id|parent> <new-output>|compare <id|parent> <candidate-checkout> [current-parent-checkout]|materialize <new-output>|promote <id>|release <new-local-git-repository>|verify-base [--record <file>] [--base <checkout>] [--offline]|record-base <path> <origin-path> <revision> [--record <file>] [--base <checkout>]|adapt-base <file> [--record <file>]|refresh-base <revision> [--record <file>] [--base <checkout>]');
|
|
80
|
+
else throw Error('Usage: cli.mjs adopt|inspect|lock|check|receipt <sidecar-json>|changes|extract <id|parent> <new-output>|compare <id|parent> <candidate-checkout> [current-parent-checkout]|materialize <new-output>|promote <id>|release <new-local-git-repository>|verify-base [--record <file>] [--base <checkout>] [--offline]|record-base <path> <origin-path> <revision>|--ref <revision> [--record <file>] [--base <checkout>|--base-archive <directory>|--from-api|--offline --base <checkout>]|adapt-base <file> [--record <file>]|refresh-base <revision>|--ref <revision> [--record <file>] [--base <checkout>|--base-archive <directory>]');
|
|
81
81
|
console.log(json(result));
|
|
82
82
|
} catch (error) {
|
|
83
83
|
console.error(error.message);
|
|
@@ -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
|
+
}
|
|
@@ -16,7 +16,7 @@ export function editionMigrations(record, {tree, read, revision, base, recordPat
|
|
|
16
16
|
typeof step.guide !== 'string' || !step.guide || typeof step.edit !== 'string' || !step.edit ||
|
|
17
17
|
!Array.isArray(step.deliver) || step.deliver.some(name => typeof name !== 'string')) fail('invalid entry');
|
|
18
18
|
safe(step.origin); safe(step.guide); step.deliver.forEach(safe);
|
|
19
|
-
read.tree(step.introduced);
|
|
19
|
+
if (read.historyAvailable !== false) read.tree(step.introduced);
|
|
20
20
|
for (const name of step.deliver) if (!tree.has(name)) fail(`missing delivery ${name}`);
|
|
21
21
|
ids.add(step.id);
|
|
22
22
|
}
|
|
@@ -25,9 +25,13 @@ export function editionMigrations(record, {tree, read, revision, base, recordPat
|
|
|
25
25
|
}
|
|
26
26
|
for (const id of consent) if (!migrations.some(step => step.id === id)) throw Error(`Unknown edition migration ${id} at Base ${revision}. Use only ids declared in ${dataPath} at that commit; no files were refreshed.`);
|
|
27
27
|
const applicable = migrations.flatMap(step => {
|
|
28
|
+
// No introduction can be crossed by an unrelated copy or a same-pin
|
|
29
|
+
// refresh. Archives can decide those cases without claiming Git ancestry.
|
|
30
|
+
const candidates = record.copies.flatMap(copy => copy.revision === revision ? [] : Object.keys(copy.files).filter(name =>
|
|
31
|
+
!copy.adapted?.[name] && copy.originPath + name.slice(copy.path.length) === step.origin).map(name => ({name, revision: copy.revision})));
|
|
32
|
+
if (!candidates.length) return [];
|
|
28
33
|
if (!read.contains(revision, step.introduced)) return [];
|
|
29
|
-
const copies =
|
|
30
|
-
!copy.adapted?.[name] && copy.originPath + name.slice(copy.path.length) === step.origin && !read.contains(copy.revision, step.introduced)));
|
|
34
|
+
const copies = candidates.filter(copy => !read.contains(copy.revision, step.introduced)).map(copy => copy.name);
|
|
31
35
|
return copies.length ? [{...step, copies}] : [];
|
|
32
36
|
});
|
|
33
37
|
const missing = applicable.filter(step => !consent.includes(step.id));
|
|
@@ -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();
|