@runeditrun/rer 0.2.83 → 0.2.85
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 +21 -24
- package/cli/README.md +17 -1
- package/cli/authoring.mjs +1 -0
- package/cli/bounded.mjs +1 -1
- package/cli/business/carry.mjs +149 -0
- package/cli/business/command.mjs +6 -1
- package/cli/business/connect.mjs +1 -1
- package/cli/business/local-commands.mjs +2 -0
- package/cli/business/opt-ins.mjs +8 -4
- package/cli/business/questions.mjs +4 -1
- package/cli/business/state.mjs +1 -1
- package/cli/business/supervisor.mjs +7 -1
- package/cli/container-transfer.mjs +2 -2
- package/cli/contract.mjs +7 -7
- package/cli/demo-host.mjs +5 -1
- package/cli/demo-native.mjs +2 -1
- package/cli/demo.mjs +6 -1
- package/cli/deploy-command.mjs +6 -4
- package/cli/deploy.mjs +9 -7
- package/cli/errors.mjs +1 -1
- package/cli/export.mjs +1 -1
- package/cli/human-error.mjs +20 -0
- package/cli/lifecycle.mjs +23 -5
- package/cli/main.mjs +1 -1
- package/cli/managed-data-schema.mjs +114 -0
- package/cli/managed-data-zip.mjs +116 -0
- package/cli/managed-data.mjs +110 -0
- package/cli/managed-server.mjs +25 -14
- package/cli/native-owner-entry.mjs +86 -0
- package/cli/output.mjs +3 -2
- package/cli/parse.mjs +3 -3
- package/cli/portability-empty.mjs +59 -0
- package/cli/portability-migrations.mjs +7 -5
- package/cli/portability-policy.mjs +5 -2
- package/cli/portability-worker.mjs +15 -6
- package/cli/portability.mjs +30 -8
- package/cli/ready-summary.mjs +9 -0
- package/cli/run-transfers.mjs +37 -0
- package/cli/runtime-front-door.mjs +4 -4
- package/cli/server-proxy.mjs +4 -3
- package/cli/server-registry.mjs +13 -8
- package/cli/site.mjs +6 -1
- package/cli/transfers.mjs +17 -4
- package/edition-authoring/base-copies.mjs +125 -30
- package/edition-authoring/copy-checkout.mjs +7 -120
- package/edition-authoring/edition-migrations.mjs +41 -0
- package/edition-authoring/files.mjs +67 -0
- package/edition-authoring/lock.mjs +2 -2
- package/edition-authoring/module-closure.mjs +232 -0
- package/edition-authoring/module-edges.mjs +100 -0
- package/edition-authoring/module-resolution.mjs +66 -0
- package/edition-authoring/module-syntax.mjs +57 -0
- package/edition-authoring/package-target.mjs +92 -0
- package/edition-authoring/runtime-dependencies.mjs +74 -97
- package/edition-authoring/vendor/babel-parser/LICENSE +22 -0
- package/edition-authoring/vendor/babel-parser/README.md +21 -0
- package/edition-authoring/vendor/babel-parser/babel-helper-string-parser/index.mjs +292 -0
- package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/identifier.mjs +66 -0
- package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/index.mjs +13 -0
- package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/keyword.mjs +31 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/index.mjs +99 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/options.mjs +81 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/bind-operator-errors.mjs +8 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/module-errors.mjs +15 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/parse-expression-errors.mjs +10 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/pipeline-operator-errors.mjs +29 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/standard-errors.mjs +224 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/strict-mode-errors.mjs +17 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/to-node-description.mjs +31 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error.mjs +114 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/base.mjs +34 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/comments.mjs +199 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/expression.mjs +1794 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/index.mjs +76 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/lval.mjs +439 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/node.mjs +111 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/statement.mjs +1962 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/util.mjs +244 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugin-utils.mjs +116 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/estree.mjs +417 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/flow/index.mjs +2412 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/flow/scope.mjs +37 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/jsx/index.mjs +420 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/jsx/xhtml.mjs +261 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/placeholders.mjs +205 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/typescript/index.mjs +2889 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/typescript/scope.mjs +115 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/v8intrinsic.mjs +26 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/context.mjs +22 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/index.mjs +1037 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/state.mjs +178 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/types.mjs +583 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/types.mjs +1 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/class-scope.mjs +82 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/expression-scope.mjs +121 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/identifier.mjs +23 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/location.mjs +34 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/production-parameter.mjs +40 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/scope.mjs +173 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/scopeflags.mjs +66 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/whitespace.mjs +61 -0
- package/edition-authoring/vendor/yaml/LICENSE +13 -0
- package/edition-authoring/vendor/yaml/README.md +11 -0
- package/edition-authoring/vendor/yaml/compose/compose-collection.mjs +88 -0
- package/edition-authoring/vendor/yaml/compose/compose-doc.mjs +43 -0
- package/edition-authoring/vendor/yaml/compose/compose-node.mjs +110 -0
- package/edition-authoring/vendor/yaml/compose/compose-scalar.mjs +86 -0
- package/edition-authoring/vendor/yaml/compose/composer.mjs +218 -0
- package/edition-authoring/vendor/yaml/compose/resolve-block-map.mjs +115 -0
- package/edition-authoring/vendor/yaml/compose/resolve-block-scalar.mjs +198 -0
- package/edition-authoring/vendor/yaml/compose/resolve-block-seq.mjs +49 -0
- package/edition-authoring/vendor/yaml/compose/resolve-end.mjs +37 -0
- package/edition-authoring/vendor/yaml/compose/resolve-flow-collection.mjs +207 -0
- package/edition-authoring/vendor/yaml/compose/resolve-flow-scalar.mjs +228 -0
- package/edition-authoring/vendor/yaml/compose/resolve-props.mjs +148 -0
- package/edition-authoring/vendor/yaml/compose/util-contains-newline.mjs +34 -0
- package/edition-authoring/vendor/yaml/compose/util-empty-scalar-position.mjs +27 -0
- package/edition-authoring/vendor/yaml/compose/util-flow-indent-check.mjs +15 -0
- package/edition-authoring/vendor/yaml/compose/util-map-includes.mjs +13 -0
- package/edition-authoring/vendor/yaml/doc/Document.mjs +333 -0
- package/edition-authoring/vendor/yaml/doc/anchors.mjs +74 -0
- package/edition-authoring/vendor/yaml/doc/applyReviver.mjs +54 -0
- package/edition-authoring/vendor/yaml/doc/createNode.mjs +88 -0
- package/edition-authoring/vendor/yaml/doc/directives.mjs +176 -0
- package/edition-authoring/vendor/yaml/errors.mjs +57 -0
- package/edition-authoring/vendor/yaml/index.mjs +17 -0
- package/edition-authoring/vendor/yaml/log.mjs +11 -0
- package/edition-authoring/vendor/yaml/nodes/Alias.mjs +119 -0
- package/edition-authoring/vendor/yaml/nodes/Collection.mjs +147 -0
- package/edition-authoring/vendor/yaml/nodes/Node.mjs +38 -0
- package/edition-authoring/vendor/yaml/nodes/Pair.mjs +36 -0
- package/edition-authoring/vendor/yaml/nodes/Scalar.mjs +24 -0
- package/edition-authoring/vendor/yaml/nodes/YAMLMap.mjs +144 -0
- package/edition-authoring/vendor/yaml/nodes/YAMLSeq.mjs +113 -0
- package/edition-authoring/vendor/yaml/nodes/addPairToJSMap.mjs +62 -0
- package/edition-authoring/vendor/yaml/nodes/identity.mjs +36 -0
- package/edition-authoring/vendor/yaml/nodes/toJS.mjs +35 -0
- package/edition-authoring/vendor/yaml/parse/cst-scalar.mjs +214 -0
- package/edition-authoring/vendor/yaml/parse/cst-stringify.mjs +61 -0
- package/edition-authoring/vendor/yaml/parse/cst-visit.mjs +97 -0
- package/edition-authoring/vendor/yaml/parse/cst.mjs +98 -0
- package/edition-authoring/vendor/yaml/parse/lexer.mjs +722 -0
- package/edition-authoring/vendor/yaml/parse/line-counter.mjs +39 -0
- package/edition-authoring/vendor/yaml/parse/parser.mjs +975 -0
- package/edition-authoring/vendor/yaml/public-api.mjs +102 -0
- package/edition-authoring/vendor/yaml/schema/Schema.mjs +37 -0
- package/edition-authoring/vendor/yaml/schema/common/map.mjs +17 -0
- package/edition-authoring/vendor/yaml/schema/common/null.mjs +15 -0
- package/edition-authoring/vendor/yaml/schema/common/seq.mjs +17 -0
- package/edition-authoring/vendor/yaml/schema/common/string.mjs +14 -0
- package/edition-authoring/vendor/yaml/schema/core/bool.mjs +19 -0
- package/edition-authoring/vendor/yaml/schema/core/float.mjs +43 -0
- package/edition-authoring/vendor/yaml/schema/core/int.mjs +38 -0
- package/edition-authoring/vendor/yaml/schema/core/schema.mjs +23 -0
- package/edition-authoring/vendor/yaml/schema/json/schema.mjs +62 -0
- package/edition-authoring/vendor/yaml/schema/tags.mjs +96 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/binary.mjs +59 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/bool.mjs +26 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/float.mjs +46 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/int.mjs +71 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/merge.mjs +67 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/omap.mjs +74 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/pairs.mjs +78 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/schema.mjs +39 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/set.mjs +93 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/timestamp.mjs +101 -0
- package/edition-authoring/vendor/yaml/stringify/foldFlowLines.mjs +146 -0
- package/edition-authoring/vendor/yaml/stringify/stringify.mjs +130 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyCollection.mjs +155 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyComment.mjs +20 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyDocument.mjs +85 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyNumber.mjs +25 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyPair.mjs +150 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyString.mjs +338 -0
- package/edition-authoring/vendor/yaml/util.mjs +11 -0
- package/edition-authoring/vendor/yaml/visit.mjs +233 -0
- package/edition-authoring/workflow-copies.mjs +125 -0
- package/edition-authoring/workflow-scripts.mjs +112 -0
- package/foundation/runtime/contract-docs.mjs +754 -0
- package/foundation/runtime/run-data.d.mts +1 -0
- package/foundation/runtime/run-data.mjs +2 -0
- package/global/CHANGELOG.md +55 -3
- package/global/README.md +21 -24
- package/global/cli/command.mjs +8 -2
- package/global/cli/install.mjs +4 -5
- package/global/cli/path-link.mjs +3 -2
- package/global/cli/repo-command.mjs +3 -7
- package/global/launch/dev.mjs +12 -2
- package/global/launch/facts.mjs +2 -2
- package/global/launch/render.mjs +16 -9
- package/global/launch/state.mjs +4 -4
- package/global/main.mjs +12 -7
- package/install.sh +17 -6
- package/modules/container/README.md +6 -1
- package/modules/container/adapters/d1-limits.mjs +286 -0
- package/modules/container/adapters/d1-sqlite.mjs +95 -0
- package/modules/container/adapters/d1-workerd-preload.mjs +19 -0
- package/modules/container/adapters/d1-workerd-setup.mjs +26 -0
- package/modules/container/adapters/d1-workerd.mjs +5 -0
- package/modules/container/adapters/sqlite-worker.mjs +5 -3
- package/modules/container/build.mjs +1 -0
- package/modules/container/image-variables.mjs +8 -3
- package/modules/container/transfer.mjs +14 -4
- package/modules/container/worker-engine.mjs +3 -3
- package/modules/demo/declaration.mjs +1 -4
- package/modules/demo/vite.mjs +1 -1
- package/modules/demo-host/build.mjs +1 -0
- package/modules/demo-host/native/prepare.mjs +2 -1
- package/modules/demo-host/native/sql.mjs +7 -2
- package/modules/deploy-kit/README.md +23 -3
- package/modules/deploy-kit/d1-import-diagnostics.mjs +56 -0
- package/modules/deploy-kit/d1-import.mjs +17 -5
- package/modules/deploy-kit/diagnostics.mjs +29 -3
- package/modules/deploy-kit/owner-cli.mjs +20 -7
- package/modules/deploy-kit/provider-transport.mjs +19 -4
- package/modules/deploy-kit/provider.mjs +57 -22
- package/modules/deploy-kit/readiness-window.mjs +1 -1
- package/modules/deploy-kit/site.mjs +8 -3
- package/modules/deploy-kit/templates.mjs +3 -3
- package/modules/deploy-kit/worker.mjs +4 -4
- package/modules/import-kit/src/d1/README.md +23 -4
- package/modules/import-kit/src/d1/atomic-prefix.ts +2 -2
- package/modules/import-kit/src/d1/budget.ts +15 -7
- package/modules/import-kit/src/d1/column-layout.ts +5 -0
- package/modules/import-kit/src/d1/creation.ts +15 -8
- package/modules/import-kit/src/d1/database.ts +3 -3
- package/modules/import-kit/src/d1/erasure-pages.ts +2 -1
- package/modules/import-kit/src/d1/erasure.ts +2 -2
- package/modules/import-kit/src/d1/jobs.ts +10 -6
- package/modules/import-kit/src/d1/plans.ts +14 -8
- package/modules/import-kit/src/d1/retirement.ts +2 -2
- package/modules/import-kit/src/d1/sets.ts +1 -3
- package/modules/import-kit/src/d1/staged-creation.ts +3 -3
- package/modules/import-kit/src/door/limits.ts +1 -1
- package/modules/import-kit/src/door/refusals.ts +1 -1
- package/modules/portability/README.md +112 -4
- package/modules/portability/backfills.mjs +9 -8
- package/modules/portability/bridge.mjs +12 -5
- package/modules/portability/catalogue.mjs +12 -5
- package/modules/portability/files.mjs +4 -3
- package/modules/portability/http.mjs +3 -3
- package/modules/portability/import.mjs +18 -9
- package/modules/portability/index.d.mts +4 -3
- package/modules/portability/index.mjs +1 -1
- package/modules/portability/ledgers.mjs +3 -2
- package/modules/portability/legacy-safety.mjs +11 -2
- package/modules/portability/migration-history.mjs +2 -2
- package/modules/portability/progress.mjs +1 -0
- package/modules/portability/restore-empty.mjs +12 -0
- package/modules/release/github-verify.mjs +11 -2
- package/onboarding/adapter.mjs +35 -6
- package/onboarding/app-fetch.mjs +6 -4
- package/onboarding/development-runtime.mjs +19 -0
- package/onboarding/local/operation.mjs +45 -27
- package/onboarding/loopback-fetch.mjs +16 -0
- package/onboarding/operator-installer.mjs +4 -6
- package/onboarding/process-diagnostics.mjs +6 -2
- package/onboarding/production-runtime.mjs +4 -2
- package/onboarding/readiness.mjs +1 -0
- package/package.json +1 -1
- package/scripts/publish-check/README.md +6 -0
- package/scripts/publish-check/history_scan.py +5 -3
- package/scripts/publish-check/hygiene_config.py +2 -1
- package/scripts/publish-check/public_hygiene.py +1 -1
- package/scripts/publish-check/report.py +9 -3
- package/scripts/publish-check/third-party-notices.json +13 -0
- package/scripts/publish-check/third_party_notices.py +38 -0
- package/scripts/publish-check/tree_scan.py +6 -0
- package/scripts/publish-check.mjs +1 -1
package/cli/server-proxy.mjs
CHANGED
|
@@ -23,12 +23,13 @@ import { UpstreamAgent } from './upstream-agent.mjs';
|
|
|
23
23
|
// A Host that is neither loopback, a `*.localhost` name nor the configured
|
|
24
24
|
// origin's (origin) gets a plain 421 here: the application would refuse it
|
|
25
25
|
// anyway, and an auth check that throws on it must not answer with a crash page.
|
|
26
|
-
export async function trafficProxy({host,port,target,activity,door,devKey,origin}) {
|
|
26
|
+
export async function trafficProxy({host,port,target,activity,door,devKey,origin,ownerEntry}) {
|
|
27
27
|
const probe=randomUUID(),sockets=new Set(),keyed=keyHolder(devKey),configured=origin?new URL(origin).host:null;
|
|
28
28
|
const agent=new UpstreamAgent();let closing=false;
|
|
29
|
-
const server=http.createServer((req,res)=>{
|
|
29
|
+
const server=http.createServer(async (req,res)=>{
|
|
30
30
|
if(door&&!doorAdmits(req,door)){req.resume();res.writeHead(403,{'content-type':'text/plain; charset=utf-8'});res.end('This checkout answers only through its front door.');return;}
|
|
31
31
|
if(!hostAdmits(req,configured)){req.resume();res.writeHead(421,{'content-type':'text/plain; charset=utf-8'});res.end('This local server answers only its own host.');return;}
|
|
32
|
+
try { if(await ownerEntry?.(req,res))return; } catch {req.resume();notFound(res);return;}
|
|
32
33
|
if(!publicPath(req.url)||fsPath(req.url)&&!keyed(req)){req.resume();notFound(res);return;}
|
|
33
34
|
const internal=req.headers['x-rer-probe']===probe;delete req.headers['x-rer-probe'];
|
|
34
35
|
const endActivity=internal?()=>{}:activity.begin();let finished=false;
|
|
@@ -102,7 +103,7 @@ export async function trafficProxy({host,port,target,activity,door,devKey,origin
|
|
|
102
103
|
upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>upstream.destroy());upstream.on('close',()=>socket.destroy());
|
|
103
104
|
});
|
|
104
105
|
try{await listen(server,host,port);}catch(error){agent.destroy();throw error;}
|
|
105
|
-
return {probe,port:server.address().port,async close(){closing=true;agent.destroy();for(const socket of sockets)socket.destroy();await new Promise(resolve=>server.close(resolve));}};
|
|
106
|
+
return {probe,port:server.address().port,setTarget(port){target=port;},async close(){closing=true;agent.destroy();for(const socket of sockets)socket.destroy();await new Promise(resolve=>server.close(resolve));}};
|
|
106
107
|
}
|
|
107
108
|
function doorAdmits(req,door){
|
|
108
109
|
const host=String(req.headers.host??'').toLowerCase(),given=Buffer.from(String(req.headers[door.header]??'')),secret=Buffer.from(door.secret);
|
package/cli/server-registry.mjs
CHANGED
|
@@ -28,10 +28,11 @@ export const declaresJourney = env => {
|
|
|
28
28
|
if(env.RER_SERVER_JOURNEY==='1')return true;
|
|
29
29
|
throw invalid('RER_SERVER_JOURNEY must be 1 to declare a test or CI journey.');
|
|
30
30
|
};
|
|
31
|
-
async function request(record, action) {
|
|
31
|
+
async function request(record, action, {timeoutMs=35000,signal}={}) {
|
|
32
32
|
return new Promise((resolveRequest,reject)=>{
|
|
33
|
-
const socket=createConnection(record.control);let text='';
|
|
34
|
-
|
|
33
|
+
const socket=createConnection({path:record.control,signal});let text='';
|
|
34
|
+
const timer=setTimeout(()=>socket.destroy(Error('Managed server did not complete cleanup.')),timeoutMs);
|
|
35
|
+
socket.once('close',()=>clearTimeout(timer));
|
|
35
36
|
socket.on('connect',()=>socket.end(JSON.stringify({token:record.token,checkout:record.checkout,generation:record.generation,action})));
|
|
36
37
|
socket.on('data',chunk=>{text+=chunk;if(text.length>16384)socket.destroy(Error('Invalid managed server reply.'));});
|
|
37
38
|
socket.on('end',()=>{try{const value=JSON.parse(text);if(value.token!==record.token||value.checkout!==record.checkout||value.generation!==record.generation)throw Error('Unverified checkout server');resolveRequest(value);}catch(error){reject(error);}});
|
|
@@ -198,15 +199,19 @@ export async function serverRegistry(root,{env=process.env,memory=availableMemor
|
|
|
198
199
|
}
|
|
199
200
|
async function update(fields){Object.assign(owned,fields);await change(state=>{const item=state.running.find(item=>item.generation===owned.generation);if(!item)throw Error('Server reservation disappeared');Object.assign(item,fields);});}
|
|
200
201
|
async function updateActivity(fields){await change(state=>{const item=state.running.find(item=>item.generation===owned.generation);if(item)Object.assign(item,fields);});}
|
|
201
|
-
async function waitReady(record,signal){
|
|
202
|
-
|
|
202
|
+
async function waitReady(record,signal,{timeoutMs=300000,now=()=>performance.now()}={}){
|
|
203
|
+
const deadline=now()+timeoutMs;
|
|
204
|
+
while(now()<deadline){
|
|
203
205
|
signal?.throwIfAborted();if(!await alive(record.owner))throw refuse('Concurrent server startup failed. Retry after recovery.');
|
|
204
|
-
|
|
205
|
-
await
|
|
206
|
+
const remaining=deadline-now();if(remaining<=0)break;
|
|
207
|
+
try{const status=await request(record,'status',{timeoutMs:Math.min(35000,remaining),signal});if(now()<deadline&&status.ready)return {...record,...status};}
|
|
208
|
+
catch(error){if(signal?.aborted)throw error;}
|
|
209
|
+
if(now()<deadline)await delay(Math.min(250,deadline-now()),undefined,{signal});
|
|
206
210
|
}
|
|
207
211
|
throw refuse('The existing server is still starting. Wait for its ready output.');
|
|
208
212
|
}
|
|
209
|
-
|
|
213
|
+
|
|
214
|
+
return {checkout,existing,stop,reserve,serve,update,updateActivity,waitReady,ownerEntry:record=>request(record,'owner-entry'),custodyToken:()=>owned?.token,
|
|
210
215
|
// The sockets close even when the record cannot be removed (its registry
|
|
211
216
|
// deleted under it, say): an open listener would keep this process alive.
|
|
212
217
|
close(){return closing??=(async()=>{
|
package/cli/site.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { unpublishedIdentities } from './site-private.mjs';
|
|
|
10
10
|
import { privateSitePaths } from './site-inputs.mjs';
|
|
11
11
|
import { redactSiteText } from './site-diagnostics.mjs';
|
|
12
12
|
import { siteRuntime, buildSiteRuntime, runtimeSummary } from './site-runtime.mjs';
|
|
13
|
+
import { deployDiagnostic, providerFailure } from '../modules/deploy-kit/diagnostics.mjs';
|
|
13
14
|
import { siteHosting } from './site-hosting.mjs';
|
|
14
15
|
|
|
15
16
|
// The run site: a seed's static marketing pages, /run and docs, built from
|
|
@@ -154,7 +155,11 @@ export async function siteCommand(project, options, store, signal, out) {
|
|
|
154
155
|
return { dryRun: false, deployed: true, origin: result.origin, site: summary };
|
|
155
156
|
} catch (error) {
|
|
156
157
|
if (error instanceof RerError) throw error;
|
|
157
|
-
|
|
158
|
+
const { createRedaction } = await shared('redaction.mjs');
|
|
159
|
+
const redaction = createRedaction();
|
|
160
|
+
redaction.addSecrets(names.map(name => process.env[name]));
|
|
161
|
+
const diagnostic = deployDiagnostic(error,redaction.redact), provider = providerFailure(error,redaction.redact);
|
|
162
|
+
throw new RerError('deploy_refused', redaction.redact(`Run site deploy stopped: ${/^[a-z0-9-]{1,80}$/.test(error.message) ? error.message : 'site-deploy-failed'}${error.resource ? ` (${error.resource})` : ''}.${provider ? ` ${provider}.` : ''}${siteReadbackSummary(error)}`), 1, {step:diagnostic?.step, ...(diagnostic ? {siteDeploy:diagnostic} : {})});
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
165
|
|
package/cli/transfers.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { isManagedDataZip } from './managed-data-zip.mjs';
|
|
1
2
|
import { stat } from 'node:fs/promises';
|
|
2
|
-
import { relative } from 'node:path';
|
|
3
|
+
import { basename, relative } from 'node:path';
|
|
3
4
|
import {localDependencyLinks} from './dependency-doctor.mjs';
|
|
4
5
|
import { contained } from './project.mjs';
|
|
5
6
|
import { missing, refuse } from './errors.mjs';
|
|
@@ -18,19 +19,31 @@ export async function transfer(project, options, signal, custody) {
|
|
|
18
19
|
if(target!=='local'||options.platform==='container'||api?.legacyRecovery!==true)throw refuse('Legacy v1 recovery is supported only by the local Workers portability adapter in an empty isolated installation.');
|
|
19
20
|
}else if(direction==='import' && (options.acknowledgeUnverifiedMetadata||options.output))throw refuse('--acknowledge-unverified-metadata and import --output require --legacy-v1.');
|
|
20
21
|
if (!api || typeof api[direction] !== 'function' || (target === 'remote' && api.remote !== true)) throw refuse(`Complete ${target} ${direction} is unsupported: the reviewed portability API and binding policy must be adopted first.`);
|
|
21
|
-
const
|
|
22
|
+
const pathArgument = async (flag, action) => {
|
|
23
|
+
try { return await action(); } catch (error) {
|
|
24
|
+
if (error.code === 'safety_refusal' && error.message === 'Path must be a contained checkout path without traversal.') {
|
|
25
|
+
const quote = value => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
26
|
+
const staged = value => `.rer/recovery/${basename(value.replaceAll('\\', '/'))}`;
|
|
27
|
+
const args = ['rer import', '--input', quote(flag === '--input' ? staged(options.input) : options.input), ...(options.journal ? ['--journal', quote(staged(options.journal))] : []), '--yes', '--cwd', quote(project.root)];
|
|
28
|
+
error.humanMessage = `${flag} ${JSON.stringify(options[flag.slice(2)])} must stay inside this checkout, without .. or an absolute path, for example .rer/recovery/<name>.rer. Stage the archives there as owned private files (0600), then run: ${args.join(' ')}`;
|
|
29
|
+
}
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const located = direction === 'export' ? await locateExport(project.root, file) : await pathArgument('--input', () => locateImport(project.root, file)), path = located.path;
|
|
22
34
|
const legacyOutput = options.legacyV1 ? await locateExport(project.root, options.output) : undefined;
|
|
23
35
|
const legacyRecovery=legacyOutput?{output:legacyOutput.path,acknowledged:options.acknowledgeUnverifiedMetadata}:undefined;
|
|
24
36
|
const sessionFile = options.sessionFile ? await contained(project.root, options.sessionFile, { privateFile: true }) : undefined;
|
|
25
37
|
if(options.journal && legacyRecovery)throw refuse('--journal requires normal v2 import; legacy v1 metadata cannot authenticate a later-journal recovery.');
|
|
26
38
|
if (options.journal && (direction !== 'import' || target !== 'local')) throw refuse('--journal applies to a local import only.');
|
|
27
39
|
// A later archive of the same installation carries its latest erasure journal.
|
|
28
|
-
const journal = options.journal ? await contained(project.root, options.journal, { privateFile: true }) : undefined;
|
|
40
|
+
const journal = options.journal ? await pathArgument('--journal', () => contained(project.root, options.journal, { privateFile: true })) : undefined;
|
|
29
41
|
await project.adapter.prepareData?.(project.root, custody.store, signal);
|
|
30
42
|
await custody.store.step(`${target === 'remote' ? 'Hosted' : 'Local'} ${direction}`);
|
|
31
43
|
// Only now can the seed's Vite configuration load in a checkout that never built.
|
|
32
44
|
await located.unserved(); await legacyOutput?.unserved();
|
|
33
|
-
const
|
|
45
|
+
const operation = direction === 'import' && typeof api.managedDataImport === 'function' && await isManagedDataZip(path) ? api.managedDataImport : api[direction];
|
|
46
|
+
const result=await operation.call(api, { root: project.root, target, path, journal, origin: options.origin, sessionFile, signal, platform:options.platform, legacyRecovery, acknowledgeUnverifiedSchemaObjects:options.acknowledgeUnverifiedSchemaObjects, ...custody });
|
|
34
47
|
// The archive's size, for the line a finished export ends with.
|
|
35
48
|
if(direction==='export')return {...result,target,...(target==='remote'&&options.origin?{origin:new URL(options.origin).origin}:{}),output:result.output??relative(project.root,path),bytes:(await stat(path)).size};
|
|
36
49
|
if(direction==='import' && target==='local' && (await localDependencyLinks(project.root)).some(link=>link.needs_relink)) {
|
|
@@ -10,10 +10,13 @@ import os from 'node:os';
|
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import crypto from 'node:crypto';
|
|
12
12
|
import {execFileSync} from 'node:child_process';
|
|
13
|
-
import {
|
|
13
|
+
import {fileURLToPath} from 'node:url';
|
|
14
|
+
import {hash, json, git, raw, gitReader, safe, noLinks, requirePhysical, testSource} from './files.mjs';
|
|
14
15
|
import {snapshot, acknowledgementDrift} from './base-acknowledgements.mjs';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
16
|
+
import {requireMaterializedCopies, preflightRefresh} from './copy-checkout.mjs';
|
|
17
|
+
import {completeModuleCopies} from './module-closure.mjs';
|
|
18
|
+
import {editionMigrations} from './edition-migrations.mjs';
|
|
19
|
+
import {adoptWorkflowTemplates, completeWorkflowHelpers} from './workflow-copies.mjs';
|
|
17
20
|
|
|
18
21
|
export const RECORD = 'base-copies.json';
|
|
19
22
|
const commit = /^[a-f0-9]{40}$/, sha256 = /^[a-f0-9]{64}$/;
|
|
@@ -35,16 +38,24 @@ function baseRepository(root) {
|
|
|
35
38
|
return (source?.kind === 'git' ? source.repository : source?.origin?.repository) || 'runeditrun/base';
|
|
36
39
|
}
|
|
37
40
|
|
|
41
|
+
function declaredRemote(record, root) {
|
|
42
|
+
const declared = record.repository ?? baseRepository(root);
|
|
43
|
+
return declared === 'runeditrun/base' ? 'https://github.com/runeditrun/base.git' : declared;
|
|
44
|
+
}
|
|
45
|
+
|
|
38
46
|
// An explicit checkout, else the record's legacy repository, else the seed's declaration.
|
|
39
47
|
function open(record, base, root, offline = false) {
|
|
40
48
|
if (base) {
|
|
41
49
|
const repository = fs.realpathSync(base);
|
|
42
50
|
const source = gitReader(repository, offline);
|
|
43
|
-
try { return {repository, source, head: source.git('rev-parse', 'HEAD'), offline, close: source.close
|
|
51
|
+
try { return {repository, source, head: source.git('rev-parse', 'HEAD'), offline, close: source.close,
|
|
52
|
+
remote: () => {
|
|
53
|
+
try { return git(repository, 'remote', 'get-url', 'origin'); }
|
|
54
|
+
catch { return declaredRemote(record, root); }
|
|
55
|
+
}}; }
|
|
44
56
|
catch (error) { source.close(); throw error; }
|
|
45
57
|
}
|
|
46
|
-
const
|
|
47
|
-
const source = declared === 'runeditrun/base' ? 'https://github.com/runeditrun/base.git' : declared;
|
|
58
|
+
const source = declaredRemote(record, root);
|
|
48
59
|
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), 'base-copies-'));
|
|
49
60
|
try {
|
|
50
61
|
execFileSync('git', ['clone', '--bare', '--quiet', '--', source, temporary], {env: {...process.env, GIT_NO_REPLACE_OBJECTS: '1'}, stdio: 'pipe'});
|
|
@@ -52,14 +63,18 @@ function open(record, base, root, offline = false) {
|
|
|
52
63
|
fs.rmSync(temporary, {recursive: true, force: true});
|
|
53
64
|
throw Error('Cannot acquire Base source. Clone https://github.com/runeditrun/base.git when online, then repeat with --base <checkout>.');
|
|
54
65
|
}
|
|
55
|
-
return {repository: temporary, head: null, close: () => fs.rmSync(temporary, {recursive: true, force: true})};
|
|
66
|
+
return {repository: temporary, head: null, remote: () => source, close: () => fs.rmSync(temporary, {recursive: true, force: true})};
|
|
56
67
|
}
|
|
57
68
|
|
|
58
69
|
export function options(args, count) {
|
|
59
|
-
const result = {positional: [], record: RECORD, base: null, offline: false};
|
|
70
|
+
const result = {positional: [], record: RECORD, base: null, offline: false, editionMigration: []};
|
|
60
71
|
for (let i = 0; i < args.length; i++) {
|
|
61
72
|
const arg = args[i];
|
|
62
73
|
if (arg === '--offline') result.offline = true;
|
|
74
|
+
else if (arg === '--edition-migration') {
|
|
75
|
+
if (!args[i + 1] || args[i + 1].startsWith('--')) throw Error(`${arg} requires a value`);
|
|
76
|
+
result.editionMigration.push(args[++i]);
|
|
77
|
+
}
|
|
63
78
|
else if (arg === '--record' || arg === '--base') {
|
|
64
79
|
if (!args[i + 1]) throw Error(`${arg} requires a value`);
|
|
65
80
|
result[arg.slice(2)] = args[++i];
|
|
@@ -133,10 +148,47 @@ function seedFiles(root) {
|
|
|
133
148
|
return files;
|
|
134
149
|
}
|
|
135
150
|
|
|
151
|
+
const quote = value => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
152
|
+
|
|
153
|
+
// A fresh object store avoids inheriting shallow boundaries from the supplied
|
|
154
|
+
// checkout. Fetch only the two immutable tips, with no tags or other branches.
|
|
155
|
+
function containsHistory(origin, source, revision, introduced) {
|
|
156
|
+
try {
|
|
157
|
+
const ancestor = source.git('merge-base', revision, introduced);
|
|
158
|
+
if (ancestor === introduced) return true;
|
|
159
|
+
if (git(origin.repository, 'rev-parse', '--is-shallow-repository') === 'false') return false;
|
|
160
|
+
} catch { /* Missing ancestry must be acquired before deciding applicability. */ }
|
|
161
|
+
const remote = origin.remote();
|
|
162
|
+
const format = source.git('rev-parse', '--show-object-format');
|
|
163
|
+
const fetch = ['fetch', '--no-tags', '--no-recurse-submodules', '--', remote, revision, introduced];
|
|
164
|
+
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), 'base-history-'));
|
|
165
|
+
try {
|
|
166
|
+
if (origin.offline) throw Error('offline');
|
|
167
|
+
execFileSync('git', ['init', '--bare', '--quiet', '--template=', '--object-format=' + format, temporary], {stdio: 'pipe'});
|
|
168
|
+
execFileSync('git', ['-C', temporary, ...fetch], {
|
|
169
|
+
env: {...process.env, GIT_NO_REPLACE_OBJECTS: '1', GIT_TERMINAL_PROMPT: '0'}, stdio: 'pipe', timeout: 60_000,
|
|
170
|
+
});
|
|
171
|
+
return git(temporary, 'merge-base', revision, introduced) === introduced;
|
|
172
|
+
} catch {
|
|
173
|
+
const {revision: target, recordPath, editionMigration} = origin.refresh;
|
|
174
|
+
const refs = [...new Set([revision, introduced, target])];
|
|
175
|
+
const cli = fileURLToPath(new URL('../bin/rer.mjs', import.meta.url));
|
|
176
|
+
const repair = 'history=$(mktemp -d) && git init --bare --quiet --template= --object-format=' + format +
|
|
177
|
+
' "$history" && git -C "$history" fetch --no-tags --no-recurse-submodules -- ' +
|
|
178
|
+
[remote, ...refs].map(quote).join(' ') + ' && ' +
|
|
179
|
+
[process.execPath, cli, 'refresh-base', '--ref', target, '--base'].map(quote).join(' ') +
|
|
180
|
+
' "$history" --record ' + quote(recordPath) +
|
|
181
|
+
editionMigration.map(id => ' --edition-migration ' + quote(id)).join('');
|
|
182
|
+
throw Error(`Cannot compare Base history for ${revision} and ${introduced} from remote ${remote}${origin.offline ? ' while offline' : '; fetching the required revisions failed or their ancestry is unavailable'}. No files were refreshed. When online, run exactly:\n${repair}`);
|
|
183
|
+
} finally {
|
|
184
|
+
fs.rmSync(temporary, {recursive: true, force: true});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
136
188
|
function reader(origin) {
|
|
137
189
|
const source = origin.source ?? gitReader(origin.repository);
|
|
138
190
|
const format = source.git('rev-parse', '--show-object-format');
|
|
139
|
-
const trees = new Map();
|
|
191
|
+
const trees = new Map(), ancestry = new Map();
|
|
140
192
|
return {
|
|
141
193
|
// Git object identity of local bytes, to find copies by content without reading Base blobs.
|
|
142
194
|
objectId: bytes => crypto.createHash(format).update(`blob ${bytes.length}\0`).update(bytes).digest('hex'),
|
|
@@ -177,12 +229,22 @@ function reader(origin) {
|
|
|
177
229
|
digests(objects) {
|
|
178
230
|
return new Map([...this.blobs(objects)].map(([object, bytes]) => [object, hash(bytes)]));
|
|
179
231
|
},
|
|
232
|
+
contains(revision, introduced) {
|
|
233
|
+
this.tree(revision); this.tree(introduced);
|
|
234
|
+
const key = revision + ':' + introduced;
|
|
235
|
+
if (!ancestry.has(key)) ancestry.set(key, containsHistory(origin, source, revision, introduced));
|
|
236
|
+
return ancestry.get(key);
|
|
237
|
+
},
|
|
238
|
+
history(revision, name) {
|
|
239
|
+
return source.git('log', '--format=%H', revision, '--', name).split('\n').filter(Boolean)
|
|
240
|
+
.flatMap(pin => { const entry = this.tree(pin).get(name); return entry ? [{revision: pin, ...entry}] : []; });
|
|
241
|
+
},
|
|
180
242
|
};
|
|
181
243
|
}
|
|
182
244
|
|
|
183
245
|
// The record is edition input: never read or write it through a link, and only as a regular file.
|
|
184
246
|
function recordFile(root, recordPath) {
|
|
185
|
-
|
|
247
|
+
requirePhysical(root, recordPath);
|
|
186
248
|
const filename = path.join(root, recordPath);
|
|
187
249
|
let stat;
|
|
188
250
|
try { stat = fs.lstatSync(filename); }
|
|
@@ -202,7 +264,9 @@ export function verifyCopies(root, {record: recordPath, base, offline}) {
|
|
|
202
264
|
for (const [name, file] of files) {
|
|
203
265
|
if (!within(name, copy.path)) continue;
|
|
204
266
|
if (!file.regular) drift.push({kind: 'not-a-file', path: name, copy: copy.path});
|
|
205
|
-
else if (!Object.hasOwn(copy.files, name))
|
|
267
|
+
else if (!Object.hasOwn(copy.files, name)) {
|
|
268
|
+
if (!(record.ignore || []).some(p => within(name, p))) drift.push({kind: 'unrecorded', path: name, copy: copy.path});
|
|
269
|
+
}
|
|
206
270
|
else if (Object.hasOwn(copy.adapted || {}, name)) {
|
|
207
271
|
noLinks(root, name);
|
|
208
272
|
drift.push(...acknowledgementDrift(root, copy, name, file, recordPath));
|
|
@@ -323,7 +387,7 @@ export function adaptCopy(root, {positional: [name], record: recordPath}) {
|
|
|
323
387
|
// entirely, just as absent files are dropped from directory copies. Local edits
|
|
324
388
|
// are refused, never overwritten, as is any change to an existing file under a
|
|
325
389
|
// migrations folder.
|
|
326
|
-
export function refreshCopies(root, {positional: [revision], record: recordPath, base, offline}) {
|
|
390
|
+
export function refreshCopies(root, {positional: [revision], record: recordPath, base, offline, editionMigration = []}) {
|
|
327
391
|
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>.');
|
|
328
392
|
if (offline && !base) throw Error('Offline refresh needs a Base checkout. Repeat rer refresh-base --ref <commit> --offline --base <checkout> containing that commit.');
|
|
329
393
|
const filename = recordFile(root, recordPath);
|
|
@@ -332,9 +396,14 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
332
396
|
const files = seedFiles(root);
|
|
333
397
|
requireMaterializedCopies(root, record, files);
|
|
334
398
|
const origin = open(record, base, root, offline);
|
|
399
|
+
origin.refresh = {revision, recordPath, editionMigration};
|
|
400
|
+
let writing = false, notices = [];
|
|
335
401
|
try {
|
|
336
402
|
const read = reader(origin);
|
|
337
403
|
const next = read.tree(revision);
|
|
404
|
+
const migrations = editionMigrations(record, {tree: next, read, revision, base: base ? origin.repository : null, recordPath, offline, consent: editionMigration});
|
|
405
|
+
const index = new Set(raw(root, 'ls-files', '-z').toString('utf8').split('\0').filter(Boolean));
|
|
406
|
+
for (const name of record.copies.flatMap(copy => Object.keys(copy.files))) requirePhysical(root, name);
|
|
338
407
|
const upstream = read.digests([...next.values()].map(({object}) => object));
|
|
339
408
|
const local = name => files.get(name)?.regular ? hash(files.get(name).read()) : null;
|
|
340
409
|
const edited = [], unacknowledged = [];
|
|
@@ -360,6 +429,7 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
360
429
|
...(conflict ? {note: 'Upstream changed or removed this seed-owned adaptation; review and reconcile explicitly.',
|
|
361
430
|
diffHint: `git -C <base> diff ${baseline} ${revision} -- ${JSON.stringify(originPath)}`} : {})};
|
|
362
431
|
}));
|
|
432
|
+
const ownerSources = new Map();
|
|
363
433
|
const plans = record.copies.map(copy => {
|
|
364
434
|
// Absence is the existing directory-copy removal signal; there is no
|
|
365
435
|
// separate deletion-intent marker. Only an absent, unadapted singleton
|
|
@@ -370,51 +440,58 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
370
440
|
const pinned = read.tree(copy.revision);
|
|
371
441
|
if (retired) return {copy, sources: [], retired, removed: [copy.path]};
|
|
372
442
|
const tests = Object.keys(copy.files).some(name => testSource(mapped(name, copy.path, copy.originPath)));
|
|
373
|
-
const sources = [...next].filter(([name
|
|
443
|
+
const sources = [...next].filter(([name]) => {
|
|
374
444
|
if (!within(name, copy.originPath)) return false;
|
|
375
445
|
const target = mapped(name, copy.originPath, copy.path), actual = local(target);
|
|
376
446
|
if (Object.hasOwn(copy.adapted || {}, target)) return false;
|
|
377
447
|
if (Object.hasOwn(copy.files, target)) {
|
|
378
448
|
return Boolean(actual);
|
|
379
449
|
}
|
|
380
|
-
if (actual)
|
|
450
|
+
if (actual) {
|
|
451
|
+
if (index.has(target)) ownerSources.set(target, name);
|
|
452
|
+
return false; // Existing unrecorded source is edition-owned.
|
|
453
|
+
}
|
|
381
454
|
return !pinned.has(name) && (tests || !testSource(name));
|
|
382
455
|
});
|
|
383
456
|
if (!sources.length && !Object.keys(copy.adapted || {}).length) throw Error(`No Base source at ${copy.originPath} in ${revision}`);
|
|
384
457
|
return {copy, sources, retired, removed: Object.keys(copy.files).filter(name => !Object.hasOwn(copy.adapted || {}, name) && !sources.some(([source]) => mapped(source, copy.originPath, copy.path) === name))};
|
|
385
458
|
});
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}});
|
|
459
|
+
const templates = adoptWorkflowTemplates(root, plans, {tree: next, read, revision, files});
|
|
460
|
+
notices = templates.notices;
|
|
461
|
+
completeWorkflowHelpers(root, plans, {tree: next, read, revision});
|
|
462
|
+
const withheld = completeModuleCopies(root, plans, {tree: next, read, revision, base: origin.repository, ownerSources,
|
|
463
|
+
deliveries: migrations.flatMap(step => step.deliver.map(source => ({source, origin: step.origin, importers: step.copies})))});
|
|
392
464
|
// Closure may add individually recorded siblings when the seed originally
|
|
393
465
|
// selected runtime files one at a time instead of copying the directory.
|
|
394
|
-
record.copies = plans.map(plan => plan.copy).sort((a, b) => a.path.localeCompare(b.path));
|
|
395
466
|
// A migration a database may already have applied is never rewritten in place:
|
|
396
467
|
// the schema change it brings belongs in a new migration of the seed's own.
|
|
397
468
|
const applied = plans.flatMap(({copy, sources}) => sources.map(([source, {object}]) => [mapped(source, copy.originPath, copy.path), object])
|
|
398
469
|
.filter(([name, object]) => name.split('/').slice(0, -1).includes('migrations') && local(name) && local(name) !== upstream.get(object)).map(([name]) => name));
|
|
399
470
|
if (applied.length) throw Error(`Refusing to rewrite migrations that may already be applied: ${applied.join(', ')}. Base changed these files after they were copied; keep them as they are, drop them from ${recordPath}, and add a new migration for the change instead.`);
|
|
471
|
+
// A file already owned by the edition can become byte-equal when Base adds
|
|
472
|
+
// its own implementation. Preserve ownership explicitly for discovery; it
|
|
473
|
+
// must never enter the copy write plan merely because the bytes now match.
|
|
474
|
+
const ownedMatches = [...ownerSources].filter(([target, source]) => {
|
|
475
|
+
const entry = next.get(source);
|
|
476
|
+
return entry && local(target) === upstream.get(entry.object);
|
|
477
|
+
}).map(([target]) => target);
|
|
478
|
+
if (ownedMatches.length) record.ignore = [...new Set([...(record.ignore || []), ...ownedMatches])].sort();
|
|
400
479
|
const bytes = read.blobs(plans.flatMap(plan => plan.sources.map(([, {object}]) => object)));
|
|
401
|
-
|
|
480
|
+
const writes = plans.flatMap(({copy, sources}) => sources.map(([source, entry]) => ({
|
|
481
|
+
name: safe(mapped(source, copy.originPath, copy.path)), ...entry,
|
|
482
|
+
})));
|
|
483
|
+
const byName = new Map(writes.map(entry => [entry.name, entry]));
|
|
402
484
|
const changes = [];
|
|
403
485
|
for (const {copy, sources, removed} of plans) {
|
|
404
|
-
for (const name of removed) { noLinks(root, name); fs.rmSync(path.join(root, name), {force: true}); }
|
|
405
486
|
const recorded = {}, modes = {}, added = [];
|
|
406
487
|
for (const name of Object.keys(copy.adapted || {})) {
|
|
407
488
|
recorded[name] = copy.files[name];
|
|
408
489
|
if (copy.modes?.[name]) modes[name] = copy.modes[name];
|
|
409
490
|
}
|
|
410
|
-
for (const [source
|
|
491
|
+
for (const [source] of sources.sort(([a], [b]) => a.localeCompare(b))) {
|
|
411
492
|
const name = safe(mapped(source, copy.originPath, copy.path));
|
|
412
|
-
|
|
493
|
+
const {object, mode} = byName.get(name);
|
|
413
494
|
if (!Object.hasOwn(copy.files, name)) added.push(name);
|
|
414
|
-
const target = path.join(root, name);
|
|
415
|
-
fs.mkdirSync(path.dirname(target), {recursive: true});
|
|
416
|
-
fs.writeFileSync(target, bytes.get(object));
|
|
417
|
-
fs.chmodSync(target, mode === '100755' ? 0o755 : 0o644);
|
|
418
495
|
recorded[name] = upstream.get(object); modes[name] = mode;
|
|
419
496
|
}
|
|
420
497
|
changes.push({path: copy.path, from: copy.revision, files: sources.length, added, removed});
|
|
@@ -423,7 +500,25 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
423
500
|
record.copies = plans.filter(plan => !plan.retired).map(plan => plan.copy);
|
|
424
501
|
delete record.repository;
|
|
425
502
|
validate(record);
|
|
503
|
+
preflightRefresh(root, plans, recordPath, files);
|
|
504
|
+
writing = true;
|
|
505
|
+
for (const {copy, sources, removed} of plans) {
|
|
506
|
+
for (const name of removed) { noLinks(root, name); fs.rmSync(path.join(root, name), {force: true}); }
|
|
507
|
+
for (const [source] of sources) {
|
|
508
|
+
const name = safe(mapped(source, copy.originPath, copy.path));
|
|
509
|
+
const {object, mode} = byName.get(name);
|
|
510
|
+
noLinks(root, name);
|
|
511
|
+
const target = path.join(root, name);
|
|
512
|
+
fs.mkdirSync(path.dirname(target), {recursive: true});
|
|
513
|
+
fs.writeFileSync(target, bytes.get(object));
|
|
514
|
+
fs.chmodSync(target, mode === '100755' ? 0o755 : 0o644);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
426
517
|
fs.writeFileSync(filename, json(record));
|
|
427
|
-
return {refreshed: revision, record: recordPath, copies: changes, retired: plans.filter(plan => plan.retired).map(plan => plan.copy.path), adapted, next: 'Run verify-base, then the edition tests, and commit the copied files with the 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.'};
|
|
519
|
+
} catch (error) {
|
|
520
|
+
if (!writing && !/no files were refreshed/i.test(error.message)) error.message += ' No files were refreshed.';
|
|
521
|
+
if (!writing && notices.length) error.message += '\n' + notices.join('\n');
|
|
522
|
+
throw error;
|
|
428
523
|
} finally { origin.close(); }
|
|
429
524
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import {git, raw, safe, noLinks,
|
|
4
|
-
import {specifiers} from './runtime-dependencies.mjs';
|
|
3
|
+
import {git, raw, safe, noLinks, requirePhysical, freedEntries} from './files.mjs';
|
|
5
4
|
const quote = value => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
6
5
|
|
|
7
6
|
// -v marks assume-unchanged; -f marks fsmonitor-valid. Read them separately
|
|
@@ -45,7 +44,7 @@ export function requireMaterializedCopies(root, record, files) {
|
|
|
45
44
|
const prefix = path.relative(root, path.join(directory, link[0])).split(path.sep).join('/');
|
|
46
45
|
const child = path.join(root, prefix);
|
|
47
46
|
let initialized = false;
|
|
48
|
-
try { initialized = fs.realpathSync(git(child, 'rev-parse', '--show-toplevel')) === fs.realpathSync(child); } catch {}
|
|
47
|
+
try { initialized = fs.realpathSync(git(child, 'rev-parse', '--show-toplevel')) === fs.realpathSync(child); } catch { initialized = false; }
|
|
49
48
|
if (!initialized) throw Error(`Base copy ${name} is beneath the uninitialized Git submodule ${prefix}. Run git -C ${quote(directory)} submodule update --init -- ${quote(link[0])}, then repeat refresh-base. No copy record was changed.`);
|
|
50
49
|
relative = relative.slice(link[0].length + 1);
|
|
51
50
|
directory = child;
|
|
@@ -69,131 +68,19 @@ export function requireMaterializedCopies(root, record, files) {
|
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
// Every recorded authoring module is a root, including exported mirrors and
|
|
73
|
-
// local adaptations. Edition-owned tracked siblings end traversal at that edge.
|
|
74
|
-
export function completeAuthoringImports(root, plans, {tree, read, revision, base}) {
|
|
75
|
-
const mapped = (name, copy) => copy.path + name.slice(copy.originPath.length);
|
|
76
|
-
const authoring = name => path.posix.basename(path.posix.dirname(name)) === 'edition-authoring' && name.endsWith('.mjs') && !testSource(name);
|
|
77
|
-
const tracked = index(root), planned = new Map(), recorded = new Map(), queue = [];
|
|
78
|
-
for (const plan of plans) {
|
|
79
|
-
for (const name of Object.keys(plan.copy.files)) recorded.set(name, plan);
|
|
80
|
-
for (const [source, entry] of plan.sources) {
|
|
81
|
-
const target = mapped(source, plan.copy);
|
|
82
|
-
planned.set(target, plan);
|
|
83
|
-
if (authoring(source)) queue.push({source, target, entry});
|
|
84
|
-
}
|
|
85
|
-
for (const target of Object.keys(plan.copy.adapted || {})) {
|
|
86
|
-
const source = plan.copy.originPath + target.slice(plan.copy.path.length);
|
|
87
|
-
if (authoring(source)) queue.push({source, target, adapted: true});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const refuse = (target, reason, command) => {
|
|
91
|
-
throw Error(`Cannot refresh authoring import ${target}: ${reason}. Run ${command}, then repeat refresh-base; no files were refreshed.`);
|
|
92
|
-
};
|
|
93
|
-
const move = target => `mv -i -- ${quote(target)} ${quote(target + '.refresh-backup')}`;
|
|
94
|
-
// Unlike the write preflight, closure must also validate files it only relies
|
|
95
|
-
// on. Read actual directory entries to reject aliases, never infer volume case.
|
|
96
|
-
function inspect(target) {
|
|
97
|
-
const parts = safe(target).split('/');
|
|
98
|
-
let parent = root;
|
|
99
|
-
for (const [i, part] of parts.entries()) {
|
|
100
|
-
const absolute = path.join(parent, part), name = parts.slice(0, i + 1).join('/');
|
|
101
|
-
let stat;
|
|
102
|
-
try { stat = fs.lstatSync(absolute); }
|
|
103
|
-
catch (error) {
|
|
104
|
-
if (error.code === 'ENOENT') return null;
|
|
105
|
-
refuse(name, error.message, move(name));
|
|
106
|
-
}
|
|
107
|
-
if (!fs.readdirSync(parent).includes(part)) refuse(name, 'the volume resolves a differently spelled entry', move(name));
|
|
108
|
-
if (stat.isSymbolicLink()) refuse(name, 'symlink in import path', move(name));
|
|
109
|
-
if (i < parts.length - 1 && !stat.isDirectory()) refuse(name, 'import parent is not a directory', move(name));
|
|
110
|
-
if (i === parts.length - 1) {
|
|
111
|
-
if (!stat.isFile()) refuse(name, 'import is not a regular file', move(name));
|
|
112
|
-
return stat;
|
|
113
|
-
}
|
|
114
|
-
parent = absolute;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
const blobs = new Map(), seen = new Set();
|
|
118
|
-
for (let i = 0; i < queue.length; i++) {
|
|
119
|
-
const {source, target, entry, adapted} = queue[i];
|
|
120
|
-
if (seen.has(target)) continue;
|
|
121
|
-
seen.add(target);
|
|
122
|
-
inspect(target);
|
|
123
|
-
let bytes;
|
|
124
|
-
if (adapted) bytes = fs.readFileSync(path.join(root, target), 'utf8');
|
|
125
|
-
else {
|
|
126
|
-
if (!blobs.has(entry.object)) blobs.set(entry.object, read.blobs([entry.object]).get(entry.object).toString('utf8'));
|
|
127
|
-
bytes = blobs.get(entry.object);
|
|
128
|
-
}
|
|
129
|
-
for (const specifier of specifiers(bytes)) {
|
|
130
|
-
const directory = path.posix.dirname(source);
|
|
131
|
-
const dependency = path.posix.normalize(path.posix.join(directory, specifier));
|
|
132
|
-
const destination = path.posix.normalize(path.posix.join(path.posix.dirname(target), specifier));
|
|
133
|
-
if (path.posix.dirname(dependency) !== directory) {
|
|
134
|
-
refuse(target, `import ${specifier} leaves its directory`, `\${EDITOR:-vi} ${quote(target)}`);
|
|
135
|
-
}
|
|
136
|
-
const exists = inspect(destination), owner = recorded.get(destination);
|
|
137
|
-
if (owner?.removed.includes(destination)) {
|
|
138
|
-
const original = owner.copy.originPath + destination.slice(owner.copy.path.length);
|
|
139
|
-
const restore = tracked.has(destination) ? `git restore -- ${quote(destination)}` :
|
|
140
|
-
`git -C ${quote(base)} show ${quote(owner.copy.revision + ':' + original)} > ${quote(destination)}`;
|
|
141
|
-
refuse(destination, 'recorded file was removed but is still imported', restore);
|
|
142
|
-
}
|
|
143
|
-
if (planned.has(destination) || owner) continue;
|
|
144
|
-
if (tracked.has(destination)) {
|
|
145
|
-
if (!exists) refuse(destination, 'tracked edition source is missing', `git restore -- ${quote(destination)}`);
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
if (exists) refuse(destination, 'existing file has no Base copy record or Git index entry', `git add -f -- ${quote(destination)}`);
|
|
149
|
-
const value = tree.get(dependency);
|
|
150
|
-
if (!value) refuse(destination, `no source at ${dependency} in ${revision}`, `\${EDITOR:-vi} ${quote(target)}`);
|
|
151
|
-
// A directory copy can already own this destination's namespace. Extend
|
|
152
|
-
// that record; otherwise the dependency is a new singleton copy.
|
|
153
|
-
let plan = plans.find(plan => destination.startsWith(plan.copy.path + '/'));
|
|
154
|
-
if (plan && mapped(dependency, plan.copy) !== destination) {
|
|
155
|
-
refuse(destination, 'source cannot fit its enclosing copy record', `\${EDITOR:-vi} base-copies.json`);
|
|
156
|
-
}
|
|
157
|
-
if (!plan) {
|
|
158
|
-
if (plans.some(plan => plan.copy.path.startsWith(destination + '/'))) refuse(destination, 'overlaps a copy directory', `\${EDITOR:-vi} base-copies.json`);
|
|
159
|
-
plan = {copy: {path: destination, originPath: dependency, revision, files: {}, modes: {}}, sources: [], removed: []};
|
|
160
|
-
plans.push(plan);
|
|
161
|
-
}
|
|
162
|
-
plan.sources.push([dependency, value]);
|
|
163
|
-
planned.set(destination, plan);
|
|
164
|
-
queue.push({source: dependency, target: destination, entry: value});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
71
|
// Inspect real filesystem facts in apply order without opening or changing any
|
|
170
72
|
// file. This cannot see later races, disk-space or I/O failures, umask on newly
|
|
171
73
|
// created directories, or two new names differing only in case on an insensitive
|
|
172
74
|
// volume. Only earlier removals are remembered; no future directory is modelled.
|
|
173
75
|
export function preflightRefresh(root, plans, recordPath, seedFiles) {
|
|
174
|
-
const uid = process.geteuid?.(), freed =
|
|
175
|
-
const identity = (name, stat) => stat.nlink > 1 ? name : `${stat.dev}:${stat.ino}`;
|
|
76
|
+
const uid = process.geteuid?.(), freed = freedEntries(root);
|
|
176
77
|
const writable = (target, stat, directory = false) => {
|
|
177
78
|
if (uid === 0 && !(stat.mode & 0o222)) throw Error('no write permission bits');
|
|
178
79
|
fs.accessSync(target, fs.constants.W_OK | (directory ? fs.constants.X_OK : 0));
|
|
179
80
|
};
|
|
81
|
+
const cache = new Map();
|
|
180
82
|
function inspect(name) {
|
|
181
|
-
|
|
182
|
-
if (!parentStat.isDirectory()) throw Error('checkout root is not a directory');
|
|
183
|
-
const parts = safe(name).split('/');
|
|
184
|
-
for (const [i, part] of parts.entries()) {
|
|
185
|
-
const target = path.join(parent, part), relative = parts.slice(0, i + 1).join('/');
|
|
186
|
-
let stat;
|
|
187
|
-
try { stat = fs.lstatSync(target); }
|
|
188
|
-
catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
189
|
-
if (!stat || (stat.isFile() && freed.has(identity(relative, stat)))) return {parent, parentStat};
|
|
190
|
-
if (i === parts.length - 1) {
|
|
191
|
-
if (!stat.isFile()) throw Error('destination is not a regular file');
|
|
192
|
-
return {parent, parentStat, target, stat};
|
|
193
|
-
}
|
|
194
|
-
if (!stat.isDirectory()) throw Error(`directory required at ${relative}`);
|
|
195
|
-
parent = target; parentStat = stat;
|
|
196
|
-
}
|
|
83
|
+
return requirePhysical(root, name, {cache, freed: freed.has});
|
|
197
84
|
}
|
|
198
85
|
function check(name, operation) {
|
|
199
86
|
try {
|
|
@@ -202,9 +89,9 @@ export function preflightRefresh(root, plans, recordPath, seedFiles) {
|
|
|
202
89
|
if (!stat) return;
|
|
203
90
|
writable(parent, parentStat, true);
|
|
204
91
|
if (uid !== undefined && uid !== 0 && (parentStat.mode & 0o1000) && uid !== parentStat.uid && uid !== stat.uid) throw Error('sticky parent and file are owned by another user');
|
|
205
|
-
freed.add(
|
|
92
|
+
freed.add(name, stat);
|
|
206
93
|
} else if (stat) {
|
|
207
|
-
if (operation !== 'record' && !seedFiles.has(name)) throw Error('existing destination is ignored
|
|
94
|
+
if (operation !== 'record' && !seedFiles.has(name)) throw Error('existing destination is ignored');
|
|
208
95
|
writable(target, stat);
|
|
209
96
|
if (operation !== 'record' && uid !== undefined && uid !== 0 && uid !== stat.uid) throw Error('file is owned by another user; cannot set its mode');
|
|
210
97
|
} else writable(parent, parentStat, true);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Base declares edition edits; consent permits refresh, never edits seed data.
|
|
2
|
+
import {safe} from './files.mjs';
|
|
3
|
+
import {fileURLToPath} from 'node:url';
|
|
4
|
+
const dataPath = 'foundation/edition-migrations.json';
|
|
5
|
+
const quote = value => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
6
|
+
export function editionMigrations(record, {tree, read, revision, base, recordPath, offline, consent = []}) {
|
|
7
|
+
let migrations = [];
|
|
8
|
+
const fail = reason => { throw Error(`Base edition migration data error: ${reason}. Repair ${dataPath} in Base and commit it, then refresh to that commit; no files were refreshed.`); };
|
|
9
|
+
if (tree.has(dataPath)) {
|
|
10
|
+
try {
|
|
11
|
+
const data = JSON.parse(read.blobs([tree.get(dataPath).object]).get(tree.get(dataPath).object));
|
|
12
|
+
if (data.schemaVersion !== 1 || !Array.isArray(data.migrations)) fail('invalid schema');
|
|
13
|
+
const ids = new Set();
|
|
14
|
+
for (const step of data.migrations) {
|
|
15
|
+
if (!step || !/^[a-z][a-z0-9-]+$/.test(step.id) || ids.has(step.id) || !/^[a-f0-9]{40}$/.test(step.introduced) ||
|
|
16
|
+
typeof step.guide !== 'string' || !step.guide || typeof step.edit !== 'string' || !step.edit ||
|
|
17
|
+
!Array.isArray(step.deliver) || step.deliver.some(name => typeof name !== 'string')) fail('invalid entry');
|
|
18
|
+
safe(step.origin); safe(step.guide); step.deliver.forEach(safe);
|
|
19
|
+
read.tree(step.introduced);
|
|
20
|
+
for (const name of step.deliver) if (!tree.has(name)) fail(`missing delivery ${name}`);
|
|
21
|
+
ids.add(step.id);
|
|
22
|
+
}
|
|
23
|
+
migrations = data.migrations;
|
|
24
|
+
} catch (error) { fail(error.message); }
|
|
25
|
+
}
|
|
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
|
+
const applicable = migrations.flatMap(step => {
|
|
28
|
+
if (!read.contains(revision, step.introduced)) return [];
|
|
29
|
+
const copies = record.copies.flatMap(copy => Object.keys(copy.files).filter(name =>
|
|
30
|
+
!copy.adapted?.[name] && copy.originPath + name.slice(copy.path.length) === step.origin && !read.contains(copy.revision, step.introduced)));
|
|
31
|
+
return copies.length ? [{...step, copies}] : [];
|
|
32
|
+
});
|
|
33
|
+
const missing = applicable.filter(step => !consent.includes(step.id));
|
|
34
|
+
if (missing.length) {
|
|
35
|
+
const cli = fileURLToPath(new URL('./cli.mjs', import.meta.url));
|
|
36
|
+
// Keep automatic acquisition automatic: its temporary checkout closes on refusal.
|
|
37
|
+
const command = `${quote(process.execPath)} ${quote(cli)} refresh-base ${revision}${base ? ' --base ' + quote(base) : ''} --record ${quote(recordPath)}${offline ? ' --offline' : ''}${applicable.map(step => ' --edition-migration ' + step.id).join('')}`;
|
|
38
|
+
throw Error(`Edition migrations require consent before planning:\n${missing.map(step => `${step.id}: ${step.copies.join(', ')}; ${step.guide}: ${step.edit}`).join('\n')}\nReview the guides and repeat exactly: ${command}\nRefresh will leave these edition-owned edits owed; no files were refreshed.`);
|
|
39
|
+
}
|
|
40
|
+
return applicable;
|
|
41
|
+
}
|