@runeditrun/rer 0.2.125 → 0.2.126
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 +3 -0
- package/cli/portability-migrations.mjs +3 -1
- package/cli/project-pnpm.mjs +5 -3
- package/global/CHANGELOG.md +22 -0
- package/global/README.md +3 -0
- package/modules/portability/README.md +9 -3
- package/modules/portability/bridge.mjs +36 -10
- package/modules/portability/checkout-history.mjs +2 -1
- package/modules/portability/owner-history.mjs +7 -0
- package/modules/portability/worker-history.mjs +5 -4
- package/modules/portability/worker-owner-history.mjs +18 -1
- package/onboarding/inspection-command.mjs +30 -0
- package/onboarding/port-probe.mjs +26 -1
- package/onboarding/process-diagnostics.mjs +2 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -434,6 +434,9 @@ Licence: MIT.
|
|
|
434
434
|
|
|
435
435
|
First-party commands acquire the exact `packageManager` pnpm pin when PATH lacks
|
|
436
436
|
it, verify its registry sha512 integrity and cache it under `$HOME/.rer/pnpm`.
|
|
437
|
+
The verified tool's version check keeps three attempts. Their 10, 20 and
|
|
438
|
+
30 second deadlines scale with one-minute load per CPU, up to four times.
|
|
439
|
+
If the check fails, rer reports what pnpm did and the final attempt's deadline.
|
|
437
440
|
No global package manager installation or sudo is needed. Independent projects
|
|
438
441
|
continue to run their declared commands with their own tools. Server and job
|
|
439
442
|
state default to `$HOME/.rer/servers` and `$HOME/.rer/jobs`; supplied
|
|
@@ -6,7 +6,7 @@ import { destinationLedger, ledgerNames, matchMigrationLedger } from '../modules
|
|
|
6
6
|
import { all, insist, PortabilityError } from '../modules/portability/storage.mjs';
|
|
7
7
|
import {migrationDirectory} from '../modules/deploy-kit/migration-directory.mjs';
|
|
8
8
|
import { collectMigrations } from '../modules/delivery-producer/migrations.mjs';
|
|
9
|
-
import { nativeMigrationHistory } from '
|
|
9
|
+
import { nativeMigrationHistory, requireAppliedOwnerFiles } from '../modules/portability/owner-history.mjs';
|
|
10
10
|
export {migrationDirectory};
|
|
11
11
|
|
|
12
12
|
// Seed-owned declarations, never archive metadata: the deploymentSpec prefix
|
|
@@ -40,6 +40,7 @@ export async function migrationInventory(root,binding,{prefix},split,sources=[])
|
|
|
40
40
|
// Preserve the runner's applied order, resolving file identities by hash.
|
|
41
41
|
export async function appliedMigrations(root,db,binding,declaration,split,sources=[]) {
|
|
42
42
|
const history=await nativeMigrationHistory(db,sources),files=await migrationInventory(root,binding,declaration,split,sources);
|
|
43
|
+
requireAppliedOwnerFiles(history,files);
|
|
43
44
|
return matchMigrationLedger(history?.entries ?? [],files,declaration).map(name=>files.find(file=>file.name===name));
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -127,6 +128,7 @@ export async function nativeMigrationPreflight({root,db,binding='DB',platformMig
|
|
|
127
128
|
if(ownerSources.length && table!=='rer_migrations') {
|
|
128
129
|
const history=await nativeMigrationHistory(db,ownerSources);
|
|
129
130
|
const allFiles=await migrationInventory(root,binding,declaration,undefined,ownerSources);
|
|
131
|
+
requireAppliedOwnerFiles(history,allFiles);
|
|
130
132
|
try { matchMigrationLedger(history.entries,allFiles,declaration); }
|
|
131
133
|
catch(error) { throw constantRefusal(error,allFiles); }
|
|
132
134
|
}
|
package/cli/project-pnpm.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// The verified cache is private to rer; the resulting PATH travels to children.
|
|
3
3
|
import { mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
4
4
|
import { delimiter, dirname, join } from 'node:path';
|
|
5
|
-
import { homedir, tmpdir } from 'node:os';
|
|
5
|
+
import { availableParallelism, homedir, loadavg, tmpdir } from 'node:os';
|
|
6
6
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
7
7
|
import { cachedPnpm, downloadPnpm } from './pnpm-runtime.mjs';
|
|
8
8
|
import { missing, RerError } from './errors.mjs';
|
|
@@ -63,14 +63,16 @@ async function ensure(root, { env = process.env, signal, report = () => {}, stor
|
|
|
63
63
|
const supplied = { ...env, RER_PNPM_ENTRY: join(directory, '..', 'bin', 'pnpm.cjs'), PATH: [env.PATH, directory, dirname(process.execPath)].filter(value => value !== undefined).join(delimiter) };
|
|
64
64
|
// A fresh pnpm's first run can stall or fail once (a cold start on a busy
|
|
65
65
|
// machine): the check settles with a bounded retry, then names what failed.
|
|
66
|
+
const loadFactor = Math.min(4, Math.max(1, loadavg()[0] / availableParallelism()));
|
|
67
|
+
const timeouts = [10000, 20000, 30000].map(ms => Math.round(ms * loadFactor));
|
|
66
68
|
let result;
|
|
67
|
-
for (const [attempt, timeoutMs] of
|
|
69
|
+
for (const [attempt, timeoutMs] of timeouts.entries()) {
|
|
68
70
|
if (attempt) await delay(1000, undefined, { signal });
|
|
69
71
|
result = await probe(root, supplied, signal, store, timeoutMs);
|
|
70
72
|
if (result.version === pin) { Object.assign(env, supplied); return env; }
|
|
71
73
|
}
|
|
72
74
|
const failed = result.version === undefined ? result.reason : `it reported ${JSON.stringify(result.version.slice(0, 64))}`;
|
|
73
|
-
const message = `The verified pnpm ${pin} did not report the project version after 3 tries (${failed}).${result.diagnostic ? `\n${result.diagnostic}\n` : ' '}Run ${shellQuote(join(directory, 'pnpm'))} --version to inspect it, then rerun rer.`;
|
|
75
|
+
const message = `The verified pnpm ${pin} did not report the project version after 3 tries (${failed}). The final attempt allowed ${timeouts.at(-1) / 1000} s.${result.diagnostic ? `\n${result.diagnostic}\n` : ' '}Run ${shellQuote(join(directory, 'pnpm'))} --version to inspect it, then rerun rer.`;
|
|
74
76
|
store.report(message);
|
|
75
77
|
throw missing(message);
|
|
76
78
|
}
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.126
|
|
4
|
+
|
|
5
|
+
Signed: Run Edit Run fleet, 2026-11-20.
|
|
6
|
+
|
|
7
|
+
### Platform archives into native destinations
|
|
8
|
+
|
|
9
|
+
- A Platform-origin archive can restore into a native destination with applied owner migrations even when Platform recorded the core and owner files in a different order. Restore matches the recorded hashes to the destination's own files, replays them in the destination's applied order, and requires the result to reproduce the archive schema before bridging later migrations. This covers the qualified Platform-to-native path that rer 0.2.124 and 0.2.125 refused with `schema_mismatch`.
|
|
10
|
+
- Changed migration bytes, a missing recorded entry, an archive-extra owner migration, an absent applied owner file, or a reorder that changes the archived schema still refuse before importing product rows or creating import jobs. The Worker returns HTTP 409 and the CLI exits 4; invalid native owner history reports `schema_mismatch:owner_migration_history`.
|
|
11
|
+
- Core-only Worker bundles grow by about 0.7 KB compared with 0.2.125 in the qualified fixture. SQLite WASM and owner replay remain excluded when there are no owner migration files.
|
|
12
|
+
|
|
13
|
+
### Bounded local inspection
|
|
14
|
+
|
|
15
|
+
- Port inspection stops waiting when its inspection deadline expires, even if an `lsof` child remains hung, and reports the port unchecked. A host-scoped probe skips process inspection only after a successful bind and explicit TCP refusal on the applicable loopback addresses; ambiguous and any-address probes still inspect.
|
|
16
|
+
- The verified pnpm version probe keeps three cached-tool attempts at 10, 20 and 30 seconds at idle. Deadlines scale with one-minute load per CPU, capped at 40, 80 and 120 seconds. A failed probe reports the final attempt's deadline.
|
|
17
|
+
- Maintained CLI and onboarding copies and inventory are regenerated.
|
|
18
|
+
|
|
19
|
+
Archives written by rer 0.2.124 or 0.2.125 import into 0.2.126, and 0.2.126 archives import into those versions for the same compatible fixtures: the archive format identity remains `runeditrun-portability` version 2, unchanged from 0.2.125. This does not give older readers the new Platform-to-native restore behavior.
|
|
20
|
+
|
|
21
|
+
HappyToHelp and any seed with Platform-origin history on rer 0.2.124 or 0.2.125 need a re-pin to 0.2.126. ChargeDesk pins rer 0.2.118 and other seeds have older pins; re-pin to receive these fixes.
|
|
22
|
+
|
|
23
|
+
These changes require adoption through the seed's pinned package or refreshed source. This preparation establishes no seed adoption, live deployment, provider delivery or production result. The source range changes portability, onboarding inspection and their maintained copies, with no import-kit or product migration change.
|
|
24
|
+
|
|
3
25
|
## 0.2.125
|
|
4
26
|
|
|
5
27
|
Signed: Run Edit Run fleet, 2026-11-19.
|
package/global/README.md
CHANGED
|
@@ -434,6 +434,9 @@ Licence: MIT.
|
|
|
434
434
|
|
|
435
435
|
First-party commands acquire the exact `packageManager` pnpm pin when PATH lacks
|
|
436
436
|
it, verify its registry sha512 integrity and cache it under `$HOME/.rer/pnpm`.
|
|
437
|
+
The verified tool's version check keeps three attempts. Their 10, 20 and
|
|
438
|
+
30 second deadlines scale with one-minute load per CPU, up to four times.
|
|
439
|
+
If the check fails, rer reports what pnpm did and the final attempt's deadline.
|
|
437
440
|
No global package manager installation or sudo is needed. Independent projects
|
|
438
441
|
continue to run their declared commands with their own tools. Server and job
|
|
439
442
|
state default to `$HOME/.rer/servers` and `$HOME/.rer/jobs`; supplied
|
|
@@ -685,12 +685,18 @@ them into a scratch database to find the archive's place in that history:
|
|
|
685
685
|
recorded. Where the exporter has no checkout files (a hosted export), the
|
|
686
686
|
ledger's own names are kept beside their hashes. Import resolves each entry
|
|
687
687
|
by hash exactly as it does an archived ledger table (next item), so a
|
|
688
|
-
Platform prefix needs no declaration and a changed file refuses.
|
|
689
|
-
|
|
688
|
+
Platform prefix needs no declaration and a changed file refuses. For archives
|
|
689
|
+
with a schema object inventory, the matched files replay in the destination's
|
|
690
|
+
order, which may differ from Platform's. That replay must still reproduce the
|
|
691
|
+
archive schema before any later migrations can be bridged. Platform's ledger
|
|
692
|
+
is never imported as product tables. Native sources with applied
|
|
690
693
|
owner migrations carry `{origin:'d1_migrations',entries:[{name,sha256}]}`
|
|
691
694
|
in the same field. The entries combine core names and prefixed owner names
|
|
692
695
|
in recorded application order. Restore checks those names and hashes against
|
|
693
|
-
the destination's applied history and keeps both ledgers in place.
|
|
696
|
+
the destination's applied history and keeps both ledgers in place. A changed,
|
|
697
|
+
reordered or incomplete native owner history that cannot reproduce the archive
|
|
698
|
+
schema, or an applied owner migration missing from the destination checkout,
|
|
699
|
+
refuses with `schema_mismatch:owner_migration_history`. Core-only
|
|
694
700
|
native archives use `manifest.migrations` as before, and v1 and earlier v2
|
|
695
701
|
archives remain importable.
|
|
696
702
|
- Older archives that still carry their source's migration ledger as a table
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { all, quote, insist } from './storage.mjs';
|
|
1
|
+
import { all, quote, insist, PortabilityError } from './storage.mjs';
|
|
2
2
|
import { canonicalJson } from './hash.mjs';
|
|
3
3
|
import { tokens, identifier, folded } from './generated.mjs';
|
|
4
4
|
import { laterData } from './backfills.mjs';
|
|
@@ -15,6 +15,34 @@ function recordedMigrations(manifest, archived, files, replay) {
|
|
|
15
15
|
'schema_mismatch:owner_migration_history',409);
|
|
16
16
|
return entries.map(entry=>entry.name);
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
function platformPlacement(manifest) {
|
|
20
|
+
return manifest.migrationLedger?.origin==='rer_migrations' && manifest.schemaObjects!==undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function recordedPlacement(manifest, recorded, applied) {
|
|
24
|
+
const selected=applied.filter(name=>recorded.includes(name));
|
|
25
|
+
// Platform and Wrangler may order the same files differently. The hashes
|
|
26
|
+
// already matched; replay their destination order and check the archive schema.
|
|
27
|
+
if(platformPlacement(manifest))return selected;
|
|
28
|
+
const mismatch=manifest.migrationLedger?.origin==='d1_migrations'?'schema_mismatch:owner_migration_history':'schema_mismatch:migration_history';
|
|
29
|
+
insist(canonicalJson(selected)===canonicalJson(recorded),mismatch,409);
|
|
30
|
+
return recorded;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function verifyRecordedSchema(manifest, earlier, schemaAfter) {
|
|
34
|
+
const owner=manifest.migrationLedger?.origin==='d1_migrations';
|
|
35
|
+
const platform=platformPlacement(manifest);
|
|
36
|
+
let schema;
|
|
37
|
+
try { schema=await schemaAfter(earlier,platform); }
|
|
38
|
+
catch(error) {
|
|
39
|
+
// The full destination replay succeeded. An incomplete native history can
|
|
40
|
+
// now fail on a missing SQL dependency or the Worker's prefix requirement.
|
|
41
|
+
if(!owner || !(error?.code==='ERR_SQLITE_ERROR' || error instanceof PortabilityError && error.code==='schema_mismatch:legacy_evidence'))throw error;
|
|
42
|
+
throw new PortabilityError('schema_mismatch:owner_migration_history',409);
|
|
43
|
+
}
|
|
44
|
+
insist(schema===manifest.schema,owner?'schema_mismatch:owner_migration_history':'schema_mismatch',owner || platform?409:400);
|
|
45
|
+
}
|
|
18
46
|
// Where an archive sits in the destination's applied migrations: those its
|
|
19
47
|
// rows passed through (earlier) and those applied after it (unapplied).
|
|
20
48
|
// migrations() is the runner's replay of the destination's applied migrations
|
|
@@ -37,14 +65,12 @@ async function placement(db,manifest,cat,replay,ledger,history,legacyRecovery,un
|
|
|
37
65
|
// archive placement. The live destination check above remains complete, and
|
|
38
66
|
// current v2 imports use their authenticated object inventory. Verified legacy
|
|
39
67
|
// v2 uses the replayed complete identity; acknowledged recovery places by tables only.
|
|
40
|
-
const schemaAfter=names=>replay.schemaAfter(names,legacyRecovery && manifest.schemaObjects===undefined?{legacyExcludedObjects:true}:unverified?{tablesOnly:true}:undefined);
|
|
68
|
+
const schemaAfter=(names,allowSubsequence)=>replay.schemaAfter(names,legacyRecovery && manifest.schemaObjects===undefined?{legacyExcludedObjects:true}:unverified?{tablesOnly:true}:undefined,allowSubsequence);
|
|
41
69
|
if(unverified && archived && manifest.migrations)insist(canonicalJson(matchMigrationLedger(archived,files,replay))===canonicalJson(recorded),'schema_mismatch:migration_history',409);
|
|
42
70
|
let earlier,unapplied;
|
|
43
71
|
if(recorded) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
earlier=recorded;
|
|
47
|
-
insist(await schemaAfter(earlier)===manifest.schema,'schema_mismatch');
|
|
72
|
+
earlier=recordedPlacement(manifest,recorded,applied);
|
|
73
|
+
await verifyRecordedSchema(manifest,earlier,schemaAfter);
|
|
48
74
|
unapplied=applied.filter(name=>!earlier.includes(name));
|
|
49
75
|
}else{
|
|
50
76
|
// Unrecorded: the latest matching prefix. Migrations that change no archived
|
|
@@ -85,12 +111,12 @@ export async function verifiedLegacySchema(ledger,manifest,cat,migrations,histor
|
|
|
85
111
|
const files=replay.names.map(name=>({name,sha256:replay.sha256?.(name),aliases:replay.aliases?.(name)}));
|
|
86
112
|
const archived=history(),recorded=recordedMigrations(manifest,archived,files,replay);
|
|
87
113
|
const applied=matchMigrationLedger(ledger,files,replay);
|
|
88
|
-
if(!recorded?.length || canonicalJson(applied)!==canonicalJson(replay.names)
|
|
89
|
-
|
|
114
|
+
if(!recorded?.length || canonicalJson(applied)!==canonicalJson(replay.names))return false;
|
|
115
|
+
const earlier=recordedPlacement(manifest,recorded,applied);
|
|
90
116
|
if(archived && manifest.migrations && canonicalJson(matchMigrationLedger(archived,files,replay))!==canonicalJson(recorded))return false;
|
|
91
117
|
if(await replay.schemaAfter(applied)!==cat.identity
|
|
92
|
-
|| await replay.schemaAfter(
|
|
93
|
-
return await replay.schemaAfter(
|
|
118
|
+
|| await replay.schemaAfter(earlier,manifest.schemaObjects===undefined?{tablesOnly:true}:{legacyExcludedObjects:true})!==manifest.schema)return false;
|
|
119
|
+
return await replay.schemaAfter(earlier);
|
|
94
120
|
}catch{return false;} // Unknown history or a failed replay is not verification.
|
|
95
121
|
}
|
|
96
122
|
// An archive with the destination's schema identity can still predate later
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { catalogue, policy } from './catalogue.mjs';
|
|
2
2
|
import { readLedger, matchMigrationLedger } from './ledgers.mjs';
|
|
3
|
-
import { nativeMigrationHistory, ownerMigrationPolicy } from './owner-history.mjs';
|
|
3
|
+
import { nativeMigrationHistory, ownerMigrationPolicy, requireAppliedOwnerFiles } from './owner-history.mjs';
|
|
4
4
|
import { insist } from './storage.mjs';
|
|
5
5
|
|
|
6
6
|
function bundledPrefix(history,files) {
|
|
@@ -13,6 +13,7 @@ function bundledPrefix(history,files) {
|
|
|
13
13
|
export async function checkoutHistory(db,input,files,replayFor,{nativeWrangler=false,ownerSources=[],nativePrefix=bundledPrefix}={}) {
|
|
14
14
|
const history=await (ownerSources.length?nativeMigrationHistory(db,ownerSources):readLedger(db)),ledger=history?.entries??[];
|
|
15
15
|
insist(ledger.length,'schema_mismatch:legacy_evidence',409);
|
|
16
|
+
requireAppliedOwnerFiles(history,files);
|
|
16
17
|
if(!ledger.every(row=>row.sha256)) {
|
|
17
18
|
insist(nativeWrangler && history.table==='d1_migrations' && nativePrefix(history,files),
|
|
18
19
|
'schema_mismatch:legacy_evidence',409);
|
|
@@ -37,6 +37,13 @@ export async function nativeMigrationHistory(db, sources) {
|
|
|
37
37
|
return { table: ledger.table, entries, owners: true };
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
export function requireAppliedOwnerFiles(history, files) {
|
|
41
|
+
if (!history?.owners) return;
|
|
42
|
+
const names = new Set(files.map(file => file.name));
|
|
43
|
+
insist(history.entries.every(row => row.table === history.table || names.has(row.name)),
|
|
44
|
+
'schema_mismatch:owner_migration_history', 409);
|
|
45
|
+
}
|
|
46
|
+
|
|
40
47
|
// The existing service callback is also used for core-only replay. Consult it
|
|
41
48
|
// early only when native owner bookkeeping may exist. The replay supplies the
|
|
42
49
|
// declared table identities; a similar product table never becomes bookkeeping.
|
|
@@ -23,11 +23,12 @@ export async function workerMigrations(db,input,evidence) {
|
|
|
23
23
|
&& typeof evidence.snapshots==='function' && typeof evidence.nativePrefix==='function','schema_mismatch:legacy_evidence',409);
|
|
24
24
|
const {files,ownerSources}=evidence;
|
|
25
25
|
return await checkoutHistory(db,input,files,async (names,config)=>{
|
|
26
|
-
const {inventory,seeds}=evidence.version===2?await evidence.snapshots(names):bundledSnapshots(evidence,names);
|
|
26
|
+
const {inventory,seeds,replayInventory}=evidence.version===2?await evidence.snapshots(names):bundledSnapshots(evidence,names);
|
|
27
27
|
return {names,statements:name=>files.find(file=>file.name===name)?.statements,sha256:name=>files.find(file=>file.name===name)?.sha256,
|
|
28
|
-
schemaAfter(selected,options){
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
async schemaAfter(selected,options,allowSubsequence){
|
|
29
|
+
if(selected.length<=names.length && selected.every((name,i)=>name===names[i]))return inventorySchemaIdentity(inventory(selected.length),config,options);
|
|
30
|
+
insist(allowSubsequence && replayInventory,'schema_mismatch:legacy_evidence',409);
|
|
31
|
+
return inventorySchemaIdentity(await replayInventory(selected),config,options);
|
|
31
32
|
},
|
|
32
33
|
async rowImages(requests){return new Map(requests.filter(r=>seeds.some(s=>s.name===r.name && !s.hashes.length)).map(r=>[r.name,[]]));},
|
|
33
34
|
async rowHashes(requests,limit){return new Map(requests.flatMap(r=>{const found=seeds.find(s=>s.name===r.name && s.hashes.length<=limit && canonicalJson(s.columns)===canonicalJson(r.columns));return found?[[r.name,found.hashes]]:[];}));},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { migrationRecorder } from './migration-evidence.mjs';
|
|
2
|
+
import { insist, PortabilityError } from './storage.mjs';
|
|
2
3
|
|
|
3
4
|
function nativePrefix(history,files) {
|
|
4
5
|
if(!history.owners)return history.entries.every((row,i)=>
|
|
@@ -24,6 +25,22 @@ export function workerOwnerEvidence(evidence,openDatabase) {
|
|
|
24
25
|
...evidence,
|
|
25
26
|
nativePrefix,
|
|
26
27
|
async snapshots(names) {
|
|
28
|
+
async function replayInventory(selected) {
|
|
29
|
+
let offset=0;
|
|
30
|
+
for(const name of selected) {
|
|
31
|
+
const index=names.indexOf(name,offset);
|
|
32
|
+
insist(index>=0,'schema_mismatch:legacy_evidence',409);
|
|
33
|
+
offset=index+1;
|
|
34
|
+
}
|
|
35
|
+
const scratch=await openDatabase();
|
|
36
|
+
try {
|
|
37
|
+
const recorder=migrationRecorder(scratch);
|
|
38
|
+
for(const name of selected)recorder.apply(files.get(name));
|
|
39
|
+
return recorder.inventory();
|
|
40
|
+
}catch{
|
|
41
|
+
throw new PortabilityError('schema_mismatch:legacy_evidence',409);
|
|
42
|
+
}finally{scratch.close();}
|
|
43
|
+
}
|
|
27
44
|
const scratch=await openDatabase();
|
|
28
45
|
try {
|
|
29
46
|
const recorder=migrationRecorder(scratch),prefixes=[recorder.inventory()];
|
|
@@ -31,7 +48,7 @@ export function workerOwnerEvidence(evidence,openDatabase) {
|
|
|
31
48
|
recorder.apply(files.get(name));
|
|
32
49
|
prefixes.push(recorder.inventory());
|
|
33
50
|
}
|
|
34
|
-
return {inventory:index=>prefixes[index],seeds:await recorder.seeds(prefixes.at(-1).objects)};
|
|
51
|
+
return {inventory:index=>prefixes[index],seeds:await recorder.seeds(prefixes.at(-1).objects),replayInventory};
|
|
35
52
|
}finally{scratch.close();}
|
|
36
53
|
},
|
|
37
54
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
export function inspectionCommand(command, args, { timeout, maxBuffer, signal, keepPartialOutput }) {
|
|
4
|
+
signal?.throwIfAborted();
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
let timer, stdout = '';
|
|
7
|
+
const finish = (error, output, stderr) => {
|
|
8
|
+
clearTimeout(timer);
|
|
9
|
+
signal?.removeEventListener('abort', abort);
|
|
10
|
+
if (error) reject(Object.assign(error, { stdout: output, stderr }));
|
|
11
|
+
else resolve(output);
|
|
12
|
+
};
|
|
13
|
+
const child = execFile(command, args, { maxBuffer, killSignal: 'SIGKILL' }, finish);
|
|
14
|
+
const abandon = error => {
|
|
15
|
+
// Even SIGKILL can leave a process in a kernel wait. Release rer's
|
|
16
|
+
// handles and settle here, independently of the child and its callback.
|
|
17
|
+
finish(error, stdout, '');
|
|
18
|
+
try { child.kill('SIGKILL'); } catch { /* the deadline still applies */ }
|
|
19
|
+
child.stdin?.destroy();
|
|
20
|
+
child.stdout?.destroy();
|
|
21
|
+
child.stderr?.destroy();
|
|
22
|
+
child.unref();
|
|
23
|
+
};
|
|
24
|
+
const abort = () => abandon(new Error('Inspection cancelled'));
|
|
25
|
+
// Only a positive observation of state-file custody can use partial output.
|
|
26
|
+
if (keepPartialOutput) child?.stdout?.on('data', data => { stdout = (stdout + data).slice(0, maxBuffer); });
|
|
27
|
+
timer = setTimeout(() => abandon(Object.assign(new Error('Inspection timed out'), { killed: true })), timeout);
|
|
28
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createServer } from 'node:net';
|
|
1
|
+
import { createServer, Socket } from 'node:net';
|
|
2
2
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
3
|
import { inspectionContext, portListener, searchContext, uncheckedInspection } from './process-diagnostics.mjs';
|
|
4
4
|
|
|
@@ -13,6 +13,25 @@ async function bind(host, port) {
|
|
|
13
13
|
} finally { if (socket.listening) await new Promise(resolve => socket.close(resolve)); }
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
async function loopbackRefuses(host, port, context) {
|
|
17
|
+
// An IPv6 wildcard may appear in an IPv4 ownership check even when it is
|
|
18
|
+
// v6-only. For IPv4 and localhost, require both loopbacks to refuse.
|
|
19
|
+
if (!['127.0.0.1', 'localhost', '::1'].includes(host)) return false;
|
|
20
|
+
const addresses = host === '::1' ? ['::1'] : ['127.0.0.1', '::1'];
|
|
21
|
+
const timeout = Math.min(250, Math.floor(context.deadline - performance.now()));
|
|
22
|
+
if (timeout <= 0) return false;
|
|
23
|
+
const refused = await Promise.all(addresses.map(address => new Promise(resolve => {
|
|
24
|
+
const socket = new Socket({ signal: context.signal });
|
|
25
|
+
const finish = refused => { clearTimeout(timer); socket.destroy(); resolve(refused); };
|
|
26
|
+
const timer = setTimeout(() => finish(false), timeout);
|
|
27
|
+
socket.once('connect', () => finish(false));
|
|
28
|
+
socket.once('error', error => finish(error.code === 'ECONNREFUSED'));
|
|
29
|
+
socket.connect({ host: address, port });
|
|
30
|
+
})));
|
|
31
|
+
context.signal?.throwIfAborted();
|
|
32
|
+
return refused.every(Boolean);
|
|
33
|
+
}
|
|
34
|
+
|
|
16
35
|
// A failed diagnostic is unknown, never evidence of a foreign owner. A real
|
|
17
36
|
// bind can still prove availability. If a bind loses a race but inspection
|
|
18
37
|
// finds no listener, retry the bind within the same inspection deadline.
|
|
@@ -25,6 +44,12 @@ export async function probePort(host, port, { context = inspectionContext({ port
|
|
|
25
44
|
};
|
|
26
45
|
let bound = await bindings(), listener, unchecked;
|
|
27
46
|
if (!bound.available && (bound.code !== 'EADDRINUSE' || searching)) return bound;
|
|
47
|
+
// An any-address search must still see listeners bound only to non-loopback
|
|
48
|
+
// addresses. A failed bind is also ambiguous, even with a refused connect.
|
|
49
|
+
if (bound.available && !anyAddress && await loopbackRefuses(host, port, context)) {
|
|
50
|
+
bound = await bindings();
|
|
51
|
+
if (bound.available || bound.code !== 'EADDRINUSE') return bound;
|
|
52
|
+
}
|
|
28
53
|
try { listener = await portListener(port, anyAddress ? undefined : host, context); }
|
|
29
54
|
catch (error) { if (!uncheckedInspection(error)) throw error; unchecked = error; }
|
|
30
55
|
if (listener) return { available: false, listener };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import {execFile} from 'node:child_process';
|
|
2
|
-
import {promisify} from 'node:util';
|
|
3
1
|
import {lstat,realpath,readFile,readdir,readlink} from 'node:fs/promises';
|
|
4
2
|
import {basename,join} from 'node:path';
|
|
5
3
|
import {availableParallelism,homedir,loadavg} from 'node:os';
|
|
@@ -7,7 +5,7 @@ import {isIP} from 'node:net';
|
|
|
7
5
|
import {setTimeout as delay} from 'node:timers/promises';
|
|
8
6
|
import {commandFailure,approvedFailure} from './failures.mjs';
|
|
9
7
|
import {stateFiles} from './local/state-files.mjs';
|
|
10
|
-
|
|
8
|
+
import {inspectionCommand} from './inspection-command.mjs';
|
|
11
9
|
// macOS supplies lsof in /usr/sbin, which a command PATH may omit.
|
|
12
10
|
// Diagnose sockets with the system utility even when that PATH is constrained.
|
|
13
11
|
const lsof=process.platform==='darwin'?'/usr/sbin/lsof':'lsof';
|
|
@@ -25,7 +23,7 @@ const run=async(command,args,context=inspectionContext(),{maxBuffer=1024*1024,no
|
|
|
25
23
|
const remaining=Math.floor(context.deadline-performance.now());
|
|
26
24
|
if(remaining<=0)break;
|
|
27
25
|
const timeout=attempt===0?Math.min(3000,remaining):remaining;
|
|
28
|
-
try{return
|
|
26
|
+
try{return await inspectionCommand(command,args,{timeout,maxBuffer,signal:context.signal,keepPartialOutput:Boolean(positiveResult)});}
|
|
29
27
|
catch(error){
|
|
30
28
|
// A cancelled caller stops inspecting: the abort is never an ownership verdict.
|
|
31
29
|
if(context.signal?.aborted)throw context.signal.reason;
|