@runeditrun/rer 0.2.75 → 0.2.76
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 +7 -2
- package/cli/listing.mjs +20 -0
- package/cli/main.mjs +1 -0
- package/cli/parse.mjs +2 -1
- package/cli/portability-migrations.mjs +46 -0
- package/cli/portability-worker.mjs +7 -20
- package/cli/portability.mjs +5 -4
- package/cli/server-registry.mjs +43 -18
- package/cli/server-resources.mjs +38 -9
- package/global/CHANGELOG.md +8 -0
- package/global/README.md +7 -2
- package/global/launch/state.mjs +5 -4
- package/global/launch/stop.mjs +30 -8
- package/global/main.mjs +2 -1
- package/modules/job-queue/command.mjs +8 -3
- package/modules/portability/README.md +40 -11
- package/modules/portability/backfills.mjs +29 -16
- package/modules/portability/bridge.mjs +24 -29
- package/modules/portability/import.mjs +1 -2
- package/modules/portability/index.d.mts +1 -1
- package/modules/portability/ledgers.mjs +22 -0
- package/modules/portability/migration-history.mjs +2 -2
- package/modules/release/README.md +135 -3
- package/modules/release/catalogue.mjs +6 -2
- package/modules/release/listing.mjs +64 -0
- package/modules/release/look.mjs +26 -0
- package/modules/release/previous-listing.mjs +44 -0
- package/modules/release/produce.mjs +3 -0
- package/modules/release/screenshots.mjs +51 -0
- package/modules/release/signature.mjs +3 -2
- package/modules/release/source.mjs +19 -6
- package/modules/release/statement.mjs +8 -4
- package/onboarding/process-cleanup.mjs +5 -5
- package/onboarding/process-scope.mjs +1 -1
- package/onboarding/process-table.mjs +6 -4
- package/onboarding/process-tree.mjs +4 -4
- package/onboarding/schema/json-schema.mjs +4 -1
- package/package.json +1 -1
- package/scripts/publish-check/README.md +14 -0
- package/scripts/publish-check/assignment.py +48 -0
- package/scripts/publish-check/credential_assignments.mjs +75 -0
- package/scripts/publish-check/credential_assignments.py +70 -0
- package/scripts/publish-check/credential_literals.mjs +66 -0
- package/scripts/publish-check/credential_syntax.mjs +29 -0
- package/scripts/publish-check/env_values.py +14 -1
- package/scripts/publish-check/history_scan.py +9 -2
package/README.md
CHANGED
|
@@ -190,8 +190,13 @@ or does not report its own (`rer describe` reports `defaults`), so a current
|
|
|
190
190
|
checkout never records a limit you did not set.
|
|
191
191
|
A start is never refused for machine load alone unless `RER_SERVERS_LOAD_THRESHOLD`
|
|
192
192
|
or `RER_JOBS_LOAD_THRESHOLD` is set; memory and disk guards stay. The disk guard
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
measures installed `node_modules` and `.wrangler` (including local D1 state). It
|
|
194
|
+
requires twice those bytes plus 256 MiB, with a 1 GiB minimum, on the checkout,
|
|
195
|
+
the selected temporary directory (`TMPDIR`, then `TMP`/`TEMP`, then the OS
|
|
196
|
+
default), and the actual `RER_SERVERS_DIR` or home registry directory. A refusal
|
|
197
|
+
names the path and exact free and required bytes.
|
|
198
|
+
`RER_SERVERS_DISK_FLOOR_GIB=N` explicitly replaces this estimate (GiB, decimals
|
|
199
|
+
allowed, 0 disables the floor).
|
|
195
200
|
|
|
196
201
|
## The front door
|
|
197
202
|
|
package/cli/listing.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { writeListing } from '../modules/release/listing.mjs';
|
|
2
|
+
import { previousListing } from '../modules/release/previous-listing.mjs';
|
|
3
|
+
|
|
4
|
+
export async function dispatchListing(args) {
|
|
5
|
+
if (args.length === 1 && args[0] === '--help') {
|
|
6
|
+
console.log('Usage: rer listing --repo DIR --ref COMMIT --output NEW_DIR\n\nRead committed listing facts and assets without gates, signing or tags.\nWrites listing.json and its relative asset paths. --ref defaults to HEAD.');
|
|
7
|
+
return 0;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const options = {};
|
|
11
|
+
for (let index = 0; index < args.length; index++) {
|
|
12
|
+
const flag = args[index];
|
|
13
|
+
if (!['--repo', '--ref', '--output'].includes(flag) || options[flag.slice(2)] !== undefined || !args[index + 1] || args[index + 1].startsWith('--')) throw Error('Invalid listing arguments');
|
|
14
|
+
options[flag.slice(2)] = args[++index];
|
|
15
|
+
}
|
|
16
|
+
if (!options.repo || !options.output) throw Error('Listing requires --repo and --output');
|
|
17
|
+
console.log(JSON.stringify(writeListing(options, previousListing), null, 2));
|
|
18
|
+
return 0;
|
|
19
|
+
} catch (error) { console.error(error.message); return 2; }
|
|
20
|
+
}
|
package/cli/main.mjs
CHANGED
|
@@ -18,6 +18,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
18
18
|
options = parse(argv,process.cwd(),{deferTail:true}); out = output(options);
|
|
19
19
|
if (options.help) return showHelp(options,out);
|
|
20
20
|
if (options.verb === 'archive') return (await import('./archive.mjs')).archiveCommand(options.archiveArgs,out);
|
|
21
|
+
if (options.verb === 'listing') return (await import('./listing.mjs')).dispatchListing(options.listingArgs);
|
|
21
22
|
if (options.verb === 'release') return (await import('./release.mjs')).dispatchRelease(options.releaseArgs);
|
|
22
23
|
const independent = await parsingProfile(options.cwd)==='independent'&&!['describe','check','doctor'].includes(options.verb);
|
|
23
24
|
options=parse(argv,process.cwd(),{independent});out=output(options);
|
package/cli/parse.mjs
CHANGED
|
@@ -17,6 +17,7 @@ export const origin = (host, port) => `http://${host === '::1' ? '[::1]' : host}
|
|
|
17
17
|
export function parse(argv, cwd = process.cwd(), { independent = false, deferTail = false } = {}) {
|
|
18
18
|
const [verb, ...args] = argv;
|
|
19
19
|
if (!verb || verb === '--help') return { help: true };
|
|
20
|
+
if (verb === 'listing') return { verb, listingArgs: args };
|
|
20
21
|
// Release validates its own flags, including its integer publication scan timeout.
|
|
21
22
|
if (verb === 'release') return { verb, releaseArgs: args };
|
|
22
23
|
if (verb === 'archive') return { verb, archiveArgs: args };
|
|
@@ -105,7 +106,7 @@ export function parse(argv, cwd = process.cwd(), { independent = false, deferTai
|
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
export function help(verb) {
|
|
108
|
-
if (!verb) return `Usage: rer VERB [FLAGS]\nCommands: ${Object.keys(verbs).join(', ')}, signin, release\nRun rer VERB --help for flags.\n`;
|
|
109
|
+
if (!verb) return `Usage: rer VERB [FLAGS]\nCommands: ${Object.keys(verbs).join(', ')}, signin, release, listing\nRun rer VERB --help for flags.\n`;
|
|
109
110
|
const known = verbs[verb] ?? (verb === 'signin' ? signinVerb : undefined);
|
|
110
111
|
const door = ['export', 'import'].includes(verb) ? 'To move records, start the app and open its signed-in owner import door:\n\n rer dev\n\nOpen /app/import, then export or upload and review supported records there.\n\nTo back up or restore this installation:\n' : '';
|
|
111
112
|
return `${door}Usage: rer ${verb} [FLAGS]\nFlags: ${(known?.flags ?? commonFlags).join(', ')}\n${known?.effects ?? 'Execute the declared OPERATIONS v2 argv with explicit arguments after --.'}\n`;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
4
|
+
import { migrationStatements } from '../modules/portability/migration-sql.mjs';
|
|
5
|
+
import { destinationLedger, matchMigrationLedger } from '../modules/portability/ledgers.mjs';
|
|
6
|
+
import { all, insist } from '../modules/portability/storage.mjs';
|
|
7
|
+
import { parseJsonc } from './jsonc.mjs';
|
|
8
|
+
|
|
9
|
+
// Seed-owned declarations, never archive metadata: the deploymentSpec prefix
|
|
10
|
+
// for this binding's directory, and data-only seeds without schema files.
|
|
11
|
+
export function platformMigrationDeclaration(input={}) {
|
|
12
|
+
insist(input && typeof input==='object' && !Array.isArray(input) && Object.keys(input).every(key=>['prefix','dataOnly'].includes(key)),'invalid_platform_migrations',409);
|
|
13
|
+
const {prefix,dataOnly=[]}=input;
|
|
14
|
+
insist(prefix===undefined || typeof prefix==='string' && /^[\w.-]*$/.test(prefix),'invalid_platform_migrations',409);
|
|
15
|
+
insist(Array.isArray(dataOnly) && dataOnly.every(name=>typeof name==='string' && /^[\w.-]+\.sql$/.test(name)) && new Set(dataOnly).size===dataOnly.length,'invalid_platform_migrations',409);
|
|
16
|
+
return {prefix,dataOnly};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Reproduce the runner's stored SQL text, then recover SQLite's statement
|
|
20
|
+
// boundaries (migration-sql.mjs).
|
|
21
|
+
async function inventory(root,binding,{prefix},split) {
|
|
22
|
+
const config=parseJsonc(await readFile(join(root,'wrangler.jsonc'),'utf8'));
|
|
23
|
+
const directory=join(root,config.d1_databases.find(entry=>entry.binding===binding).migrations_dir ?? 'migrations');
|
|
24
|
+
return Promise.all((await readdir(directory)).filter(name=>name.endsWith('.sql')).sort().map(async name=>{
|
|
25
|
+
const bytes=await readFile(join(directory,name));
|
|
26
|
+
return {name,statements:migrationStatements(bytes.toString('utf8'),split),sha256:createHash('sha256').update(bytes).digest('hex'),...(prefix===undefined?{}:{aliases:[prefix+name]})};
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Preserve the runner's applied order, resolving file identities by hash.
|
|
31
|
+
export async function appliedMigrations(root,db,binding,declaration,split) {
|
|
32
|
+
const ledger=await destinationLedger(db) ?? [],files=await inventory(root,binding,declaration,split);
|
|
33
|
+
return matchMigrationLedger(ledger,files,declaration).map(name=>files.find(file=>file.name===name));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Wrangler cannot see Platform's ledger. Keep Platform as the sole authority;
|
|
37
|
+
// pending files must be applied by that runner before a local transfer.
|
|
38
|
+
export async function platformMigrationPreflight(root,db,binding,declaration,split) {
|
|
39
|
+
const tables=(await all(db,"SELECT name FROM sqlite_master WHERE type='table' AND name IN ('rer_migrations','d1_migrations','_rer_deploy_migrations')")).map(row=>row.name);
|
|
40
|
+
if(!tables.includes('rer_migrations'))return {platformLedger:false};
|
|
41
|
+
insist(tables.length===1,'migration_ledger:multiple:rer_migrations',409);
|
|
42
|
+
const files=await inventory(root,binding,declaration,split),ledger=await destinationLedger(db);
|
|
43
|
+
const applied=matchMigrationLedger(ledger,files,declaration);
|
|
44
|
+
for(const file of files)insist(applied.includes(file.name),'migration_ledger:unapplied:'+file.name,409);
|
|
45
|
+
return {platformLedger:true};
|
|
46
|
+
}
|
|
@@ -4,10 +4,7 @@ import { readLegacyArchive } from '../modules/portability/format.mjs';
|
|
|
4
4
|
import { recoverLegacyArchive } from '../modules/portability/legacy-files.mjs';
|
|
5
5
|
import { legacyTargetState, requireLegacyEmpty } from '../modules/portability/legacy-safety.mjs';
|
|
6
6
|
import { migrationReplay } from '../modules/portability/migration-history.mjs';
|
|
7
|
-
import { migrationStatements } from '../modules/portability/migration-sql.mjs';
|
|
8
|
-
import { appliedMigrations as appliedMigrationNames } from '../modules/portability/bridge.mjs';
|
|
9
7
|
import { join } from 'node:path';
|
|
10
|
-
import { createHash } from 'node:crypto';
|
|
11
8
|
import { mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
12
9
|
import { createRequire } from 'node:module';
|
|
13
10
|
import { createPortability, PortabilityError, readArchive } from '../modules/portability/index.mjs';
|
|
@@ -15,19 +12,7 @@ import { transferProgress } from '../modules/portability/progress.mjs';
|
|
|
15
12
|
import { nativeFailure, stateBytes } from './portability-progress.mjs';
|
|
16
13
|
import { parseJsonc } from './jsonc.mjs';
|
|
17
14
|
import { loadPolicy } from './portability-policy.mjs';
|
|
18
|
-
|
|
19
|
-
// The migrations this installation applied, in its ledger's order, with each
|
|
20
|
-
// file's hash, so a restore can place an older archive within them. Reproduce
|
|
21
|
-
// the runner's stored SQL text, then recover SQLite's statement boundaries.
|
|
22
|
-
async function appliedMigrations(root, db, binding, split) {
|
|
23
|
-
const config = parseJsonc(await readFile(join(root, 'wrangler.jsonc'), 'utf8'));
|
|
24
|
-
const directory = join(root, config.d1_databases.find(entry => entry.binding === binding).migrations_dir ?? 'migrations');
|
|
25
|
-
const names = await appliedMigrationNames(db) ?? [];
|
|
26
|
-
return Promise.all(names.map(async name => {
|
|
27
|
-
const bytes = await readFile(join(directory, name));
|
|
28
|
-
return { name, statements: migrationStatements(bytes.toString('utf8'), split), sha256: createHash('sha256').update(bytes).digest('hex') };
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
15
|
+
import { appliedMigrations, platformMigrationDeclaration, platformMigrationPreflight } from './portability-migrations.mjs';
|
|
31
16
|
|
|
32
17
|
// Transfers read only the D1 database and R2 buckets. A configuration with just
|
|
33
18
|
// those keeps the app's other bindings out of the proxy: a Durable Object class
|
|
@@ -40,7 +25,7 @@ async function dataConfiguration(root) {
|
|
|
40
25
|
return path;
|
|
41
26
|
}
|
|
42
27
|
|
|
43
|
-
async function run(direction, { root, path, journal, binding, buckets, policy, policyModule, transient, legacyRecovery }) {
|
|
28
|
+
async function run(direction, { root, path, journal, binding, buckets, policy, policyModule, transient, legacyRecovery, platformMigrations }) {
|
|
44
29
|
// Lines for the person go to the CLI over IPC, which prints them as the command's progress.
|
|
45
30
|
const progress = transferProgress(line => process.send({ progress: line }));
|
|
46
31
|
if (!legacyRecovery && ['export', 'import'].includes(direction)) progress({ phase: 'start', direction, bytes: direction === 'export' ? await stateBytes(join(root, '.wrangler/state')) : (await stat(path)).size });
|
|
@@ -51,6 +36,7 @@ async function run(direction, { root, path, journal, binding, buckets, policy, p
|
|
|
51
36
|
if(journal)for await(const record of fileRecords(journal)) {}
|
|
52
37
|
}
|
|
53
38
|
policy = await loadPolicy(root, policy, policyModule);
|
|
39
|
+
const declaration=platformMigrationDeclaration(platformMigrations);
|
|
54
40
|
if (direction === 'policy-preflight') return { checkedPolicy: true };
|
|
55
41
|
const { getPlatformProxy, unstable_splitSqlQuery } = createRequire(join(root, 'package.json'))('wrangler');
|
|
56
42
|
|
|
@@ -59,7 +45,8 @@ async function run(direction, { root, path, journal, binding, buckets, policy, p
|
|
|
59
45
|
let proxy;
|
|
60
46
|
try {
|
|
61
47
|
proxy = await getPlatformProxy({ configPath, persist: { path: join(root, '.wrangler/state/v3') }, remoteBindings: false });
|
|
62
|
-
|
|
48
|
+
if(direction==='migration-preflight')return await platformMigrationPreflight(root,proxy.env[binding],binding,declaration,unstable_splitSqlQuery);
|
|
49
|
+
const migrations=async()=>migrationReplay(await appliedMigrations(root,proxy.env[binding],binding,declaration,unstable_splitSqlQuery),policy,declaration);
|
|
63
50
|
const options={ db: proxy.env[binding], buckets: Object.fromEntries(Object.entries(buckets).map(([name, binding]) => [name, proxy.env[binding]])), policy, migrations };
|
|
64
51
|
if(direction==='legacy-preflight') {
|
|
65
52
|
await requireLegacyEmpty(options,await legacyTargetState(options.db,options.migrations));
|
|
@@ -81,10 +68,10 @@ const reply = message => new Promise(resolve => process.send(message, () => { pr
|
|
|
81
68
|
try { await reply({ ok: true, ...await run(process.argv[2], JSON.parse(process.argv[3])) }); }
|
|
82
69
|
catch (error) {
|
|
83
70
|
// Erasure-fence refusals name the fence: an older archive is refused, not a failed transfer.
|
|
84
|
-
const refusal = error instanceof PortabilityError && (error.status === 409 || ['wrong_product', 'schema_mismatch', 'table_inventory', 'configuration_inventory', 'erased_row', 'erasure_epoch', 'later_journal', 'invalid_journal', 'staged_validation'].includes(error.code.split(':')[0]));
|
|
71
|
+
const refusal = error instanceof PortabilityError && (error.status === 409 || ['wrong_product', 'schema_mismatch', 'migration_ledger', 'table_inventory', 'configuration_inventory', 'erased_row', 'erasure_epoch', 'later_journal', 'invalid_journal', 'staged_validation'].includes(error.code.split(':')[0]));
|
|
85
72
|
const exitCode = error.message === 'archive_json' ? 2 : refusal || error.code === 'EEXIST' ? 4 : 1;
|
|
86
73
|
// Report only symbolic codes; native database errors can contain private data.
|
|
87
|
-
const reason = error instanceof PortabilityError ? error.code.split(':')[0] : /^[A-Z_]+$/.test(error.code ?? '') ? error.code : error.message === 'archive_json' ? 'archive_json' : 'native_error';
|
|
74
|
+
const reason = error instanceof PortabilityError ? (error.code.startsWith('migration_ledger:') ? error.code : error.code.split(':')[0]) : /^[A-Z_]+$/.test(error.code ?? '') ? error.code : error.message === 'archive_json' ? 'archive_json' : 'native_error';
|
|
88
75
|
// A later migration that changes restorable data is named: it is a file of this installation.
|
|
89
76
|
const migration = error instanceof PortabilityError && error.code.startsWith('schema_mismatch:migration_data:') ? error.code.slice('schema_mismatch:migration_data:'.length) : undefined;
|
|
90
77
|
// A populated destination names its table or bucket: schema names, never row data.
|
package/cli/portability.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { shared } from './shared.mjs';
|
|
|
10
10
|
|
|
11
11
|
// Seeds declare their real bindings and data policy. The shared module owns the
|
|
12
12
|
// archive format and atomic restore; the shared runner owns its native children.
|
|
13
|
-
export function localPortability({ database, binding = 'DB', buckets = {}, policy, policyModule, transient = [] }) {
|
|
13
|
+
export function localPortability({ database, binding = 'DB', buckets = {}, policy, policyModule, transient = [], platformMigrations }) {
|
|
14
14
|
async function run({ root, path, journal, store, signal, operationToken, platform, legacyRecovery }, direction) {
|
|
15
15
|
if (direction === 'export') {
|
|
16
16
|
if (await lstat(path).catch(error => { if (error.code === 'ENOENT') return null; throw error; })) throw refuse('Export requires a new archive path.');
|
|
@@ -46,18 +46,19 @@ export function localPortability({ database, binding = 'DB', buckets = {}, polic
|
|
|
46
46
|
throw refuse(`Local portability policy refused (${error.code}). Executable policies require a seed-owned policyModule with a valid default policy export; policyModule requires native local transport.`);
|
|
47
47
|
}
|
|
48
48
|
if(platform==='container') return (await import('./container-transfer.mjs')).containerTransfer({root,path,journal,store,signal,direction,binding,buckets,policy:declaration.policy,transient});
|
|
49
|
-
const input={ root, path, journal, binding, buckets, ...declaration, transient, legacyRecovery };
|
|
49
|
+
const input={ root, path, journal, binding, buckets, ...declaration, transient, legacyRecovery, platformMigrations };
|
|
50
50
|
// Check the executable policy before migrations; the transfer worker imports
|
|
51
51
|
// it again in its own process so module closures are retained during restore.
|
|
52
52
|
if (policyModule !== undefined) await nativeWorker(store,'policy-preflight',input,signal);
|
|
53
53
|
// Do not apply pending product migrations to a populated recovery target.
|
|
54
54
|
// Check real existing bindings first; finalize repeats this under the lock.
|
|
55
55
|
if(legacyRecovery)await nativeWorker(store,'legacy-preflight',input,signal);
|
|
56
|
+
const {platformLedger}=await nativeWorker(store,'migration-preflight',input,signal);
|
|
56
57
|
// Local migrations need no provider account: wrangler runs without credentials.
|
|
57
58
|
// Its info lines (the local location and "Use --remote if you want to access
|
|
58
59
|
// the remote instance") only confuse a local backup; warnings and errors print.
|
|
59
60
|
const { dependencyEnvironment } = await shared('dependency-environment.mjs');
|
|
60
|
-
await store.run('Applying local data migrations', 'pnpm', ['exec', 'wrangler', 'd1', 'migrations', 'apply', database, '--local', '--persist-to', '.wrangler/state', '--config', 'wrangler.jsonc'], {
|
|
61
|
+
if(!platformLedger)await store.run('Applying local data migrations', 'pnpm', ['exec', 'wrangler', 'd1', 'migrations', 'apply', database, '--local', '--persist-to', '.wrangler/state', '--config', 'wrangler.jsonc'], {
|
|
61
62
|
cwd: root, signal, env: { ...dependencyEnvironment(), RER_LOCAL_OPERATION: operationToken, WRANGLER_SEND_METRICS: 'false', WRANGLER_LOG: 'warn' },
|
|
62
63
|
});
|
|
63
64
|
const receipt=await nativeWorker(store,direction,input,signal);
|
|
@@ -70,7 +71,7 @@ export function localPortability({ database, binding = 'DB', buckets = {}, polic
|
|
|
70
71
|
async function nativeWorker(store,direction,input,signal) {
|
|
71
72
|
// The notice filter loads before the worker links its static node:sqlite import.
|
|
72
73
|
const worker = fileURLToPath(new URL('./portability-worker.mjs', import.meta.url)), notice = new URL('./sqlite-notice.mjs', import.meta.url).href;
|
|
73
|
-
const child = store.spawn(`${direction === 'policy-preflight' ? 'Checking archive policy' : direction === 'legacy-preflight' ? 'Checking empty recovery destination' : direction === 'export' ? 'Exporting' : 'Restoring'} local installation data`, process.execPath,
|
|
74
|
+
const child = store.spawn(`${direction === 'migration-preflight' ? 'Checking migration history for' : direction === 'policy-preflight' ? 'Checking archive policy' : direction === 'legacy-preflight' ? 'Checking empty recovery destination' : direction === 'export' ? 'Exporting' : 'Restoring'} local installation data`, process.execPath,
|
|
74
75
|
['--import', notice, worker, direction, JSON.stringify(input)], { cwd: input.root, signal, env: { ...process.env, WRANGLER_SEND_METRICS: 'false' }, stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });
|
|
75
76
|
let receipt;
|
|
76
77
|
// Progress lines come first, as {progress}; the last message is the receipt.
|
package/cli/server-registry.mjs
CHANGED
|
@@ -32,12 +32,13 @@ async function request(record, action) {
|
|
|
32
32
|
return new Promise((resolveRequest,reject)=>{
|
|
33
33
|
const socket=createConnection(record.control);let text='';
|
|
34
34
|
socket.setTimeout(35000,()=>socket.destroy(Error('Managed server did not complete cleanup.')));
|
|
35
|
-
socket.on('connect',()=>socket.end(JSON.stringify({token:record.token,action})));
|
|
35
|
+
socket.on('connect',()=>socket.end(JSON.stringify({token:record.token,checkout:record.checkout,generation:record.generation,action})));
|
|
36
36
|
socket.on('data',chunk=>{text+=chunk;if(text.length>16384)socket.destroy(Error('Invalid managed server reply.'));});
|
|
37
|
-
socket.on('end',()=>{try{const value=JSON.parse(text);if(value.token!==record.token)throw Error('Unverified server');resolveRequest(value);}catch(error){reject(error);}});
|
|
37
|
+
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);}});
|
|
38
38
|
socket.on('error',reject);
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
+
export const serverStatus = record => request(record,'status');
|
|
41
42
|
|
|
42
43
|
// A new server starts only while this much memory is available. An idle dev
|
|
43
44
|
// server holds 0.5-1.3 GiB (preview 0.4-0.8 GiB), so 1.5 GiB leaves room for the
|
|
@@ -107,42 +108,61 @@ export async function serverRegistry(root,{env=process.env,memory=availableMemor
|
|
|
107
108
|
}
|
|
108
109
|
const change=async action=>{await (secured??=secure());return transaction(directory,lifetime.info,action,{validateState});};
|
|
109
110
|
let owned, control, closing;
|
|
110
|
-
async function inspect(state) {
|
|
111
|
+
async function inspect(state,{recover=false}={}) {
|
|
111
112
|
const kept=[];
|
|
112
113
|
for(const record of state.running){
|
|
113
|
-
let
|
|
114
|
+
let current;
|
|
115
|
+
try{current=await processInfo(record.owner?.pid);}catch{current=undefined;}
|
|
116
|
+
let live=false;
|
|
117
|
+
// Other roots remain counted under their existing lifetime protocol; this
|
|
118
|
+
// client never acquires stop/recovery authority over those live records.
|
|
119
|
+
if(record.checkout!==checkout||record.owner?.checkout===record.checkout&¤t&¤t.title===record.owner.command){
|
|
120
|
+
try{live=await alive(record.owner);}catch{}
|
|
121
|
+
}
|
|
114
122
|
if(live) kept.push(record);
|
|
115
123
|
else {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
//
|
|
119
|
-
if(record.runtime) {
|
|
124
|
+
// Fleet inspection is passive. In particular --stop never recovers an
|
|
125
|
+
// abandoned runtime, nor grants custody to a replacement at a recycled PID.
|
|
126
|
+
// Only a new start in the owning checkout may recover its dead owner's scope.
|
|
127
|
+
if(recover&&record.checkout===checkout&&record.owner?.checkout===checkout&¤t===null&&record.runtime) {
|
|
120
128
|
const { shared }=await import('./shared.mjs');
|
|
121
129
|
const { recoverCommand }=await shared('command-recovery.mjs');
|
|
122
130
|
await recoverCommand(record.runtime);
|
|
123
131
|
}
|
|
132
|
+
process.stderr.write(`Dropped stale or unverified ${record.mode} server entry for ${record.checkout}; no stop signal was sent to its recorded PID.\n`);
|
|
124
133
|
}
|
|
125
134
|
}
|
|
126
135
|
state.running=kept;
|
|
127
136
|
}
|
|
128
|
-
async function existing(mode,options
|
|
137
|
+
async function existing(mode,options) {
|
|
129
138
|
return change(async state=>{
|
|
130
|
-
await inspect(state);const record=state.running.find(item=>item.checkout===checkout);
|
|
139
|
+
await inspect(state,{recover:true});const record=state.running.find(item=>item.checkout===checkout);
|
|
131
140
|
if(!record)return null;
|
|
132
141
|
if(record.mode!==mode)throw refuse(`This checkout already owns ${description(record)}.`);
|
|
133
|
-
if(
|
|
142
|
+
if(options.supplied.has('--host')&&record.host!==undefined&&options.host!==record.host || options.supplied.has('--port')&&record.port!==undefined&&options.port!==record.port || options.supplied.has('--idle-timeout')&&options.idleTimeout!==record.idleTimeout)throw refuse(`Options conflict with ${description(record)}.`);
|
|
134
143
|
return record;
|
|
135
144
|
});
|
|
136
145
|
}
|
|
137
|
-
async function stop(mode
|
|
146
|
+
async function stop(mode) {
|
|
138
147
|
try{await lstat(join(directory,'state.json'));}catch(error){if(error.code==='ENOENT')return;throw error;}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
await change(state=>{state
|
|
148
|
+
// Capture the generations once: a later start is a separate run, even in
|
|
149
|
+
// this root, and must not be caught by a continuing stop lookup.
|
|
150
|
+
const records=await change(async state=>{await inspect(state);return state.running.filter(item=>item.checkout===checkout);});
|
|
151
|
+
for(const record of records){
|
|
152
|
+
if(record.mode!==mode)throw refuse(`This checkout already owns ${description(record)}.`);
|
|
153
|
+
// A status reply proves this root and generation before a stop request.
|
|
154
|
+
try{await serverStatus(record);}
|
|
155
|
+
catch{
|
|
156
|
+
await change(state=>{state.running=state.running.filter(item=>item.generation!==record.generation);});
|
|
157
|
+
process.stderr.write(`Dropped foreign or unverified ${mode} server entry for ${checkout}; no stop request was sent.\n`);continue;
|
|
158
|
+
}
|
|
159
|
+
await request(record,'stop');
|
|
160
|
+
await change(state=>{state.running=state.running.filter(item=>item.generation!==record.generation);});
|
|
161
|
+
}
|
|
142
162
|
}
|
|
143
163
|
async function reserve(mode,options) {
|
|
144
164
|
return change(async state=>{
|
|
145
|
-
await inspect(state);
|
|
165
|
+
await inspect(state,{recover:true});
|
|
146
166
|
const same=state.running.find(item=>item.checkout===checkout);
|
|
147
167
|
if(same)return {existing:same};
|
|
148
168
|
// Journeys are listed but uncounted: they neither use nor lower the cap.
|
|
@@ -152,7 +172,8 @@ export async function serverRegistry(root,{env=process.env,memory=availableMemor
|
|
|
152
172
|
// Unreadable memory is not a reason to refuse; only a reading below the floor is.
|
|
153
173
|
const available=journey||floor===0?NaN:await memory();
|
|
154
174
|
if(available<floor)throw refuse(memoryMessage(counted,available,floor,mode));
|
|
155
|
-
|
|
175
|
+
const {title:command}=await processInfo(process.pid);
|
|
176
|
+
owned={checkout,mode,journey,generation:randomUUID(),token:randomUUID(),owner:{...lifetime.info,checkout,command},limit:fileLimit?fileLimit.limit:limit,explicit:explicit||Boolean(fileLimit),startedAt:Number(process.hrtime.bigint()/1000000n),idleTimeout:options.idleTimeout};
|
|
156
177
|
owned.lastActivity=owned.startedAt;owned.active=0;
|
|
157
178
|
const name=`rer-server-${createHash('sha256').update(owned.generation).digest('hex').slice(0,20)}.sock`;
|
|
158
179
|
owned.control=join(tmpdir(),name);if(Buffer.byteLength(owned.control)>=100)owned.control=join('/tmp',name);
|
|
@@ -165,7 +186,11 @@ export async function serverRegistry(root,{env=process.env,memory=availableMemor
|
|
|
165
186
|
let text='';socket.setTimeout(35000,()=>socket.destroy());
|
|
166
187
|
socket.on('data',data=>{text+=data;if(text.length>1024)socket.destroy();});
|
|
167
188
|
socket.on('end',async()=>{
|
|
168
|
-
try{
|
|
189
|
+
try{
|
|
190
|
+
const request=JSON.parse(text);
|
|
191
|
+
if(request.token!==owned.token||request.action==='stop'&&(request.checkout!==checkout||request.generation!==owned.generation))throw Error('Invalid checkout capability');
|
|
192
|
+
socket.end(JSON.stringify({...await handler(request.action),token:owned.token,checkout,generation:owned.generation}));
|
|
193
|
+
}
|
|
169
194
|
catch{socket.destroy();}
|
|
170
195
|
});
|
|
171
196
|
});
|
package/cli/server-resources.mjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {loadavg,tmpdir} from 'node:os';
|
|
2
|
-
import {statfs} from 'node:fs/promises';
|
|
2
|
+
import {statfs,lstat,readdir} from 'node:fs/promises';
|
|
3
|
+
import {dirname,join,resolve} from 'node:path';
|
|
3
4
|
import {refuse} from './errors.mjs';
|
|
5
|
+
import {serversDirectory} from './server-registry.mjs';
|
|
4
6
|
// Persistent serving is not a bounded queue job. Check its launch separately,
|
|
5
7
|
// after finite preparation, while its canonical server reservation is held.
|
|
6
8
|
// The 1-minute-load guard is a fleet's rule, set in the fleet's environment:
|
|
7
9
|
// without RER_SERVERS_LOAD_THRESHOLD a person's start is never refused for load.
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
+
// Estimate another dependency/runtime-state footprint plus room for growth.
|
|
11
|
+
// RER_SERVERS_DISK_FLOOR_GIB explicitly replaces the estimate (0 disables it).
|
|
10
12
|
export function servingLoadThreshold(env=process.env){
|
|
11
13
|
if(env.RER_SERVERS_LOAD_THRESHOLD===undefined)return Infinity;
|
|
12
14
|
const threshold=Number(env.RER_SERVERS_LOAD_THRESHOLD);
|
|
@@ -14,20 +16,47 @@ export function servingLoadThreshold(env=process.env){
|
|
|
14
16
|
return threshold;
|
|
15
17
|
}
|
|
16
18
|
const gibibyte=1024n**3n;
|
|
17
|
-
export function serversDiskFloor(env=process.env){
|
|
19
|
+
export function serversDiskFloor(env=process.env,seedBytes=0n){
|
|
18
20
|
const value=env.RER_SERVERS_DISK_FLOOR_GIB;
|
|
19
|
-
if(value===undefined)
|
|
21
|
+
if(value===undefined){
|
|
22
|
+
const estimate=2n*seedBytes+gibibyte/4n,bytes=estimate>gibibyte?estimate:gibibyte;
|
|
23
|
+
return {gib:Number(bytes)/Number(gibibyte),bytes};
|
|
24
|
+
}
|
|
20
25
|
const gib=Number(value);
|
|
21
26
|
if(!/^(\d+\.?\d*|\.\d+)$/.test(value)||!Number.isFinite(gib))throw refuse('Invalid server disk floor. RER_SERVERS_DISK_FLOOR_GIB must be a number of GiB such as 4 or 2.5, 0 for no floor.');
|
|
22
27
|
return {gib,bytes:BigInt(Math.round(gib*Number(gibibyte)))};
|
|
23
28
|
}
|
|
29
|
+
// Count logical file bytes conservatively, including pnpm's local .pnpm tree.
|
|
30
|
+
// Do not follow symlinks: linked packages are already in that tree, and links
|
|
31
|
+
// can point outside the seed or form cycles. Missing state has not been created.
|
|
32
|
+
async function seedDiskBytes(root){
|
|
33
|
+
async function bytes(path){
|
|
34
|
+
let info;try{info=await lstat(path,{bigint:true});}catch(error){if(error.code==='ENOENT')return 0n;throw error;}
|
|
35
|
+
if(info.isSymbolicLink())return 0n;
|
|
36
|
+
if(!info.isDirectory())return info.size;
|
|
37
|
+
let total=0n;
|
|
38
|
+
for(const name of await readdir(path))total+=await bytes(join(path,name));
|
|
39
|
+
return total;
|
|
40
|
+
}
|
|
41
|
+
return await bytes(join(root,'node_modules'))+await bytes(join(root,'.wrangler'));
|
|
42
|
+
}
|
|
43
|
+
// The registry or TMPDIR may not exist yet. Its nearest existing ancestor is
|
|
44
|
+
// on the filesystem that will receive it; retain the requested path in errors.
|
|
45
|
+
async function diskAt(path,disk){
|
|
46
|
+
try{return await disk(path,{bigint:true});}
|
|
47
|
+
catch(error){if(error.code!=='ENOENT'||dirname(path)===path)throw error;return diskAt(dirname(path),disk);}
|
|
48
|
+
}
|
|
24
49
|
export async function serverResources(root,{load=()=>loadavg()[0],disk=statfs,env=process.env}={}){
|
|
25
|
-
const threshold=servingLoadThreshold(env)
|
|
50
|
+
const threshold=servingLoadThreshold(env);
|
|
51
|
+
// Validate explicit values before doing any measurements.
|
|
52
|
+
let floor=serversDiskFloor(env);
|
|
26
53
|
const measured=threshold===Infinity?0:await load();
|
|
27
54
|
if(!Number.isFinite(measured)||measured>threshold)throw refuse(`Not started: this computer is busy. Its 1-minute load is ${Number.isFinite(measured)?measured.toFixed(1):'unknown'} and a server starts only at ${threshold} or below.\nTry again in a few minutes, or start it anyway with a higher threshold, for example RER_SERVERS_LOAD_THRESHOLD=${Math.ceil(Math.max(threshold,Number.isFinite(measured)?measured:0)*2)} rer dev.`);
|
|
28
|
-
|
|
29
|
-
|
|
55
|
+
if(env.RER_SERVERS_DISK_FLOOR_GIB===undefined)floor=serversDiskFloor(env,await seedDiskBytes(root));
|
|
56
|
+
const temporary=resolve(env.TMPDIR||env.TMP||env.TEMP||tmpdir());
|
|
57
|
+
for(const path of new Set([resolve(root),temporary,serversDirectory(env)])){
|
|
58
|
+
const state=await diskAt(path,disk);
|
|
30
59
|
const free=state.bavail*state.bsize;
|
|
31
|
-
if(free<floor.bytes)throw refuse(`Server startup requires ${floor.
|
|
60
|
+
if(free<floor.bytes)throw refuse(`Server startup requires ${floor.bytes} bytes free (${floor.gib.toFixed(2)} GiB) at ${path}; it has ${free} bytes free (${(Number(free)/Number(gibibyte)).toFixed(2)} GiB). Recover owned space before retrying.\nRER_SERVERS_DISK_FLOOR_GIB explicitly overrides the seed-sized floor (GiB, decimals allowed, 0 for no floor).`);
|
|
32
61
|
}
|
|
33
62
|
}
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.76
|
|
4
|
+
|
|
5
|
+
- **Patch the maintained TanStack Start security closure (#386).** The default seed and foundation carry the patched Start and server-core dependencies for GHSA-qx66-fv34-fjm8.
|
|
6
|
+
- **Restore across native and Platform migration ledgers (#368, #380, #379).** Match migration files by digest, preserve alias-aware ledger checks, and replay later inserts into carried tables after archived rows are restored.
|
|
7
|
+
- **Carry seed listing metadata through releases (#372).** Listing facts and reusable screenshots follow the release artifact.
|
|
8
|
+
- **Keep runtime custody through exec (#352) and measure actual dev write paths (#383).** Process custody stays within the installation root, and disk admission measures the seed's write paths with the WSL temporary-directory floor.
|
|
9
|
+
- **Correct publication scanning (#371, #387, #389).** Use hosted credential-assignment rules, reject comma-neighbour false assignments, and match environment values only when secret-shaped. Documentation examples use public repository references or explicit logical identifiers.
|
|
10
|
+
|
|
3
11
|
## 0.2.75
|
|
4
12
|
|
|
5
13
|
- **Custom-origin owner claims use the recorded app origin (#374).** Native deployment inspection retains the configured public origin from the deployment receipt, so owner claim and status work for custom domains while the ownership guard still refuses a claim at a different origin. Existing workers.dev deployments keep their derived origin.
|
package/global/README.md
CHANGED
|
@@ -190,8 +190,13 @@ or does not report its own (`rer describe` reports `defaults`), so a current
|
|
|
190
190
|
checkout never records a limit you did not set.
|
|
191
191
|
A start is never refused for machine load alone unless `RER_SERVERS_LOAD_THRESHOLD`
|
|
192
192
|
or `RER_JOBS_LOAD_THRESHOLD` is set; memory and disk guards stay. The disk guard
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
measures installed `node_modules` and `.wrangler` (including local D1 state). It
|
|
194
|
+
requires twice those bytes plus 256 MiB, with a 1 GiB minimum, on the checkout,
|
|
195
|
+
the selected temporary directory (`TMPDIR`, then `TMP`/`TEMP`, then the OS
|
|
196
|
+
default), and the actual `RER_SERVERS_DIR` or home registry directory. A refusal
|
|
197
|
+
names the path and exact free and required bytes.
|
|
198
|
+
`RER_SERVERS_DISK_FLOOR_GIB=N` explicitly replaces this estimate (GiB, decimals
|
|
199
|
+
allowed, 0 disables the floor).
|
|
195
200
|
|
|
196
201
|
## The front door
|
|
197
202
|
|
package/global/launch/state.mjs
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// stop.json when rer dev --stop last ran: a launch requested before it stops
|
|
11
11
|
// pin-install.json the process installing the checkout's pinned rer package
|
|
12
12
|
import { createHash } from 'node:crypto';
|
|
13
|
-
import { appendFile, link, mkdir, readFile, readdir, rm, writeFile } from 'node:fs/promises';
|
|
13
|
+
import { appendFile, link, mkdir, readFile, readdir, realpath, rm, writeFile } from 'node:fs/promises';
|
|
14
14
|
import { basename, join } from 'node:path';
|
|
15
15
|
import { processInfo } from '../../modules/job-queue/processes.mjs';
|
|
16
16
|
import { serversDirectory } from '../registry.mjs';
|
|
@@ -35,9 +35,10 @@ async function live(holder) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export async function liveWorker(directory) {
|
|
38
|
-
const holder = await
|
|
38
|
+
const holder = await readWorker(directory);
|
|
39
39
|
return await live(holder) ? holder : undefined;
|
|
40
40
|
}
|
|
41
|
+
export const readWorker = directory => readJson(join(directory, 'worker.json'));
|
|
41
42
|
|
|
42
43
|
// A claim file is written to a private file first and hard-linked into place,
|
|
43
44
|
// so it appears complete or not at all: a process finding it never reads a
|
|
@@ -101,8 +102,8 @@ export async function settledPinInstall(checkout, { env = process.env, signal, o
|
|
|
101
102
|
export async function claimLaunch(directory, token) {
|
|
102
103
|
const path = join(directory, 'worker.json');
|
|
103
104
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
104
|
-
const { start } = await processInfo(process.pid);
|
|
105
|
-
if (await linkClaim(path, { token, pid: process.pid, start, startedAt: Date.now(), events: `events-${token}.jsonl` })) {
|
|
105
|
+
const { start, title: command } = await processInfo(process.pid), checkout = await realpath(process.cwd());
|
|
106
|
+
if (await linkClaim(path, { token, pid: process.pid, start, command, checkout, startedAt: Date.now(), events: `events-${token}.jsonl` })) {
|
|
106
107
|
for (const entry of await readdir(directory)) if (/^events-.*\.jsonl$/.test(entry) && entry !== `events-${token}.jsonl`) await rm(join(directory, entry), { force: true });
|
|
107
108
|
return true;
|
|
108
109
|
}
|
package/global/launch/stop.mjs
CHANGED
|
@@ -5,22 +5,34 @@
|
|
|
5
5
|
// the registered server and everything they spawned -- has exited. It says
|
|
6
6
|
// what it stopped, or exits non-zero naming what is still running.
|
|
7
7
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
import { rm } from 'node:fs/promises';
|
|
8
11
|
import { processInfo } from '../../modules/job-queue/processes.mjs';
|
|
9
12
|
import { readProcessTable, sameBirth } from '../../onboarding/process-table.mjs';
|
|
10
13
|
import { delegate } from '../delegate.mjs';
|
|
11
14
|
import { liveServers } from '../registry.mjs';
|
|
15
|
+
import { serverStatus } from '../../cli/server-registry.mjs';
|
|
12
16
|
import { LaunchFailure } from './failure.mjs';
|
|
13
|
-
import {
|
|
17
|
+
import { readWorker, serverRecord, stopRequest } from './state.mjs';
|
|
14
18
|
|
|
15
19
|
export async function stopLaunch(target, devArgs, { checkout, directory }) {
|
|
16
20
|
// Written before looking for a worker: one that claims the launch after this
|
|
17
21
|
// look reads it and ends itself (worker.mjs).
|
|
18
22
|
await stopRequest.write(directory);
|
|
19
|
-
const holder = await
|
|
20
|
-
const
|
|
21
|
-
|
|
23
|
+
const holder = await readWorker(directory);
|
|
24
|
+
const verified = holder && await verifiedWorker(holder, checkout);
|
|
25
|
+
const launch = verified ? await tree([holder]) : [];
|
|
26
|
+
if (verified) await endWorker(holder, checkout);
|
|
27
|
+
else if (holder) {
|
|
28
|
+
await rm(join(directory, 'worker.json'), { force: true });
|
|
29
|
+
process.stderr.write(`Dropped foreign or unverified launch worker entry for ${checkout}; no signal was sent.\n`);
|
|
30
|
+
}
|
|
22
31
|
// Only now: a worker stopped while its server came up has registered it.
|
|
23
|
-
|
|
32
|
+
let record;
|
|
33
|
+
for (const candidate of (await liveServers()).filter(item => item.checkout === checkout)) {
|
|
34
|
+
try { await serverStatus(candidate); record = candidate; break; } catch {}
|
|
35
|
+
}
|
|
24
36
|
const started = await serverRecord.read(directory);
|
|
25
37
|
const server = await tree([record?.owner, record?.runtimeProcess, started, started?.spawned]);
|
|
26
38
|
await delegate(target, ['dev', ...devArgs]);
|
|
@@ -28,15 +40,25 @@ export async function stopLaunch(target, devArgs, { checkout, directory }) {
|
|
|
28
40
|
const left = await exited([...launch, ...server], 15000);
|
|
29
41
|
if (left.length) {
|
|
30
42
|
const pids = left.map(item => item.pid).join(' ');
|
|
31
|
-
process.stderr.write(`rer dev --stop: ${left.length === 1 ? 'a process' : `${left.length} processes`}
|
|
43
|
+
process.stderr.write(`rer dev --stop: ${left.length === 1 ? 'a process' : `${left.length} processes`} recorded for this checkout's dev server ${left.length === 1 ? 'is' : 'are'} still running 15 seconds after the stop (PID ${pids}). Preserve these processes and inspect their ownership before stopping them.\n`);
|
|
32
44
|
return 1;
|
|
33
45
|
}
|
|
34
|
-
if (!devArgs.includes('--json')) process.stdout.write(said({ checkout, record, started, server, holder, launch }) + '\n');
|
|
46
|
+
if (!devArgs.includes('--json')) process.stdout.write(said({ checkout, record, started, server, holder:verified?holder:undefined, launch }) + '\n');
|
|
35
47
|
return 0;
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
// SIGTERM the preparing worker and wait for it to exit.
|
|
39
|
-
async function
|
|
51
|
+
async function verifiedWorker(holder, checkout) {
|
|
52
|
+
if (!Number.isSafeInteger(holder.pid) || holder.pid < 2 || typeof holder.token !== 'string') return false;
|
|
53
|
+
const current = await processInfo(holder.pid);
|
|
54
|
+
const worker = fileURLToPath(new URL('./worker.mjs', import.meta.url));
|
|
55
|
+
return Boolean(current && !current.zombie && current.start === holder.start
|
|
56
|
+
&& holder.checkout === checkout && current.title === holder.command
|
|
57
|
+
&& current.title.includes(`${worker} ${checkout} ${holder.token} `));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function endWorker(holder, checkout) {
|
|
61
|
+
if (!await verifiedWorker(holder, checkout)) return;
|
|
40
62
|
try { process.kill(holder.pid, 'SIGTERM'); } catch (error) { if (error.code === 'ESRCH') return; throw error; }
|
|
41
63
|
for (let waited = 0; waited < 60000; waited += 250) {
|
|
42
64
|
const current = await processInfo(holder.pid);
|
package/global/main.mjs
CHANGED
|
@@ -45,7 +45,7 @@ pins (installed first by any verb when node_modules holds another), else its ven
|
|
|
45
45
|
of a checkout that pins the rer package use it).
|
|
46
46
|
|
|
47
47
|
Checkout verbs: install, setup, dev, demo, preview, build, verify, reset, deploy, signin, export,
|
|
48
|
-
import, doctor, describe, check, release. Run rer VERB --help in a checkout for its flags.
|
|
48
|
+
import, doctor, describe, check, release, listing. Run rer VERB --help in a checkout for its flags.
|
|
49
49
|
`;
|
|
50
50
|
|
|
51
51
|
// The checkout verbs that install the pinned package before they run when
|
|
@@ -64,6 +64,7 @@ export async function main(argv) {
|
|
|
64
64
|
// verb never inherits it.
|
|
65
65
|
delete process.env[localDefaults];
|
|
66
66
|
if (verb === 'update') return (await import('./update/command.mjs')).update(argv.slice(1));
|
|
67
|
+
if (verb === 'listing') return (await import('../cli/listing.mjs')).dispatchListing(argv.slice(1));
|
|
67
68
|
if (verb === 'business') return (await import('../cli/business/command.mjs')).businessCommand(argv.slice(1));
|
|
68
69
|
if (verb === 'companion') return (await import('../cli/companion/command.mjs')).companionCommand(argv.slice(1));
|
|
69
70
|
const notice = await import('./update/notice.mjs');
|
|
@@ -51,13 +51,18 @@ export async function execute(command, job, config, adopt, signal, onStarted, op
|
|
|
51
51
|
} finally {
|
|
52
52
|
signal.removeEventListener('abort', abort);
|
|
53
53
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
// Stop escaped descendants through custody first, then finish the group
|
|
55
|
+
// this run created even if custody cleanup fails. The ready owner's start
|
|
56
|
+
// time and unique marker protect against a replacement group leader.
|
|
57
|
+
try { await options.cleanup?.(child,outcome); }
|
|
58
|
+
finally {
|
|
59
|
+
if (owner) await stopGroup(owner, config.killGraceMs);
|
|
60
|
+
else child.kill('SIGKILL'); // The supervisor has not been given GO.
|
|
61
|
+
}
|
|
56
62
|
// Its group is stopped; output still arriving on a dead supervisor's pipes
|
|
57
63
|
// comes from escaped descendants, which the caller's cleanup stops.
|
|
58
64
|
if (outcome?.supervisorEnded) { child.stdout?.destroy(); child.stderr?.destroy(); }
|
|
59
65
|
await exited;
|
|
60
|
-
await options.cleanup?.(child,outcome);
|
|
61
66
|
if (owner?.socket) await unlink(owner.socket).catch(error => { if (error.code !== 'ENOENT') throw error; });
|
|
62
67
|
} catch (error) { error.keepLease = true; throw error; }
|
|
63
68
|
}
|