@runeditrun/rer 0.2.26 → 0.2.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/README.md CHANGED
@@ -126,13 +126,20 @@ rebuild preview. A build that regenerates its own files declares them as
126
126
  paths are not inputs, while any other file touched during the build is refused by name. Both use the same `.wrangler/state` and saved owner. Dev opens signed in through `RER_OPEN`, including with the legacy
127
127
  `--login` flag. Stop before changing modes.
128
128
 
129
- Local startup holds the checkout's exclusive operation lock until serving stops.
129
+ Setup, local import/restore, reset and local startup hold the checkout's exclusive
130
+ operation lock through completion (or until serving stops).
130
131
  Its state-holder inspection selects only regular files under `.wrangler/state`,
131
- including SQLite sidecars. Dev and demo give `lsof` three seconds to answer. A confirmed
132
+ including SQLite sidecars. Each local custody check gives inspection three seconds to answer. A confirmed
132
133
  holder is refused with its PID and process name. If inspection cannot answer,
133
- dev (including demo) continues under the held checkout lock; another
134
- cooperating launch cannot acquire it. This lock does not inventory unmanaged
135
- processes. Setup, reset and preview still require their state inspection to complete.
134
+ canonical-state commands probe existing SQLite databases with an immediate exclusive transaction,
135
+ then continue under the held checkout lock; another cooperating operation cannot
136
+ acquire it. A conflicting SQLite transaction is refused even when its PID could not
137
+ be inspected. The probe rolls back without changing rows. Neither proof inventories
138
+ idle unmanaged file handles or WAL readers. Keep the bounded inspection even when
139
+ the launch lock is free: skipping it would miss unmanaged state holders and saved
140
+ origin listeners that a completed inspection currently detects.
141
+ Demo uses the launch lock without opening canonical SQLite: probes can checkpoint
142
+ idle WAL or change read marks, and demo preserves every owner state byte.
136
143
  Stop dev or preview before build, verification or data transfer; use the
137
144
  documented `--stop` flag or Ctrl-C.
138
145
 
package/cli/contract.mjs CHANGED
@@ -26,5 +26,5 @@ export const demoVerb = Object.freeze({ flags: [...commonFlags, '--port', '--hos
26
26
  // sign the owner in to, so no seed declares it and check does not ask for it.
27
27
  export const signinVerb = Object.freeze({ flags: [...commonFlags, '--environment', '--env-file'], effects: 'A one-time sign-in link for the hosted owner, without mail. Uses the Cloudflare credentials that deployed --environment (default production; from the environment or --env-file) to write a single-use grant for the recorded owner into that deployment\'s auth database, then prints the link once to this terminal; it is never saved. The link works once, only for that owner, expires within 15 minutes, and its use is recorded in the owner\'s audit log. Signed in this way, the owner can correct a wrong email in settings.' });
28
28
  export const aliases = Object.fromEntries([...Object.keys(verbs).filter(v => v !== 'install'), 'release', 'deps', 'rer'].map(name => [name, name === 'deps' ? 'install' : name === 'rer' ? null : name]));
29
- export const releaseFlags = ['--repo', '--project', '--repository', '--output', '--ref', '--dry-run', '--tag', '--clean-history', '--onto', '--env-file', '--no-queue'];
29
+ export const releaseFlags = ['--repo', '--project', '--repository', '--output', '--ref', '--public-base', '--dry-run', '--tag', '--clean-history', '--onto', '--env-file', '--no-queue'];
30
30
  export const requiredHooks = ['preview', 'dependencies', 'build', 'migrate', 'start', 'health', 'owner', 'signIn', 'verify', 'deploy', 'portability', 'state', 'settings', 'input'];
package/cli/lifecycle.mjs CHANGED
@@ -49,16 +49,19 @@ async function runLifecycle(project, options, out, deployRedaction) {
49
49
  if (!project.adapter?.run) throw refuse('The first-party command adapter is unavailable. Restore the shared lifecycle adapter.');
50
50
  if (options.forwarded.length) throw refuse('First-party commands do not accept arbitrary forwarded arguments. Run rer VERB --help.');
51
51
  await stateSafety(project);
52
- if(options.verb==='setup')await refuseLegacyProcess(project,{verb:options.verb});
52
+ const { localOperation } = await shared('local/operation.mjs');
53
+ // The run site reads no local state: it builds beside a running rer dev.
54
+ if (!options.site) try { operation = await localOperation(project.root, process.env.RER_LOCAL_OPERATION); } catch (error) { throw refuse(error.message); }
55
+ if(options.verb==='setup'||options.verb==='import'&&(options.target??'local')==='local'){
56
+ const ownership=await refuseLegacyProcess(project,{verb:options.verb,operation});
57
+ if(ownership?.lockProof)out.progress('Local process inspection did not answer; continuing with the exclusive checkout launch lock.\n');
58
+ }
53
59
  if (options.verb === 'setup') {
54
60
  selected = await selectedOrigin(project, options, { setup: options.verb === 'setup' });
55
61
  if (options.verb === 'setup') {input = await setupInput(project, options, selected.vars, signal, { origin: selected.url });await dependencyInputs({project,input,origin:selected.url});}
56
62
  if (!selected.door) await availablePort(selected.host, selected.port, { root: project.root, saved: !selected.explicitPort && selected.savedOrigin !== undefined, verb:options.verb });
57
63
  if (options.verb === 'setup') announcePort(out, options, selected);
58
64
  }
59
- const { localOperation } = await shared('local/operation.mjs');
60
- // The run site reads no local state: it builds beside a running rer dev.
61
- if (!options.site) try { operation = await localOperation(project.root, process.env.RER_LOCAL_OPERATION); } catch (error) { throw refuse(error.message); }
62
65
  const { recoverInterrupted } = await shared('local/recovery.mjs');
63
66
  if (operation) await recoverInterrupted(project.root, operation);
64
67
  if (project.ownerReplacement) await replaceOwner(project, options, out);
package/cli/local.mjs CHANGED
@@ -66,7 +66,15 @@ async function safeTree(project, path) {
66
66
 
67
67
  export async function reset(project, options, out) {
68
68
  await stateSafety(project);
69
- await refuseLegacyProcess(project,{reset:true,verb:'reset'});
69
+ const { localOperation } = await shared('local/operation.mjs');
70
+ let operation;
71
+ try { operation = await localOperation(project.root); } catch (error) { throw refuse(error.message); }
72
+ try { return await resetHeld(project,options,out,operation); }
73
+ finally { await operation.release(); }
74
+ }
75
+
76
+ async function resetHeld(project,options,out,operation) {
77
+ await refuseLegacyProcess(project,{reset:true,verb:'reset',operation});
70
78
  const { strandedOriginals } = await shared('local/recovery.mjs');
71
79
  if ((await strandedOriginals(project.root)).length) throw refuse('An interrupted build holds private settings. Run rer build to recover them before reviewing reset.');
72
80
  // The seed's own safety check (legacy data it still has to recover, for
@@ -89,29 +97,32 @@ export async function reset(project, options, out) {
89
97
  }
90
98
  if (!confirmed) throw refuse('Reset requires explicit confirmation. Review the inventory, then pass --yes.');
91
99
  // The shared lock lives outside every removal path and remains held throughout.
92
- const { localOperation } = await shared('local/operation.mjs');
93
- let operation;
94
- try { operation = await localOperation(project.root); } catch (error) { throw refuse(error.message); }
95
- try {
96
- for (const path of inventory) { const absolute = await safeTree(project, path); if (absolute) await rm(absolute, { recursive: true, force: true }); }
97
- } finally { await operation.release(); }
100
+ for (const path of inventory) { const absolute = await safeTree(project, path); if (absolute) await rm(absolute, { recursive: true, force: true }); }
98
101
  return { paths: inventory };
99
102
  }
100
103
 
101
- export async function refuseLegacyProcess(project,{reset=false,verb='dev',operation}={}) {
104
+ export async function refuseLegacyProcess(project,{reset=false,verb='dev',operation,isolated=false}={}) {
105
+ // Every caller must keep this exclusive checkout proof through its operation.
106
+ const {localOperation}=await shared('local/operation.mjs');
107
+ if(!operation?.token)throw refuse('Local ownership inspection requires the checkout operation lock.');
108
+ await localOperation(project.root,operation.token);
102
109
  let selected;try{selected=await selectedOrigin(project,{});}catch(error){if(!reset)throw error;}
103
110
  // Confirmed reset can recover malformed settings; checkout/state custody is
104
111
  // still checked even when there is no usable saved origin.
105
112
  const {localProcessConflict,inspectionContext,uncheckedInspection}=await shared('process-diagnostics.mjs');
106
113
  // The front door holds a door origin's port, not this checkout.
107
114
  let conflict;
108
- try{conflict=await localProcessConflict(project.root,selected?.door?undefined:selected?.savedOrigin,inspectionContext({verb}));}
115
+ try{conflict=await localProcessConflict(project.root,selected?.door?undefined:selected?.savedOrigin,inspectionContext({verb,budgetMs:3000}));}
109
116
  catch(error){
110
- // Startup already holds the exclusive checkout operation through teardown.
111
- // An unanswered observation must not defeat that cooperating-launch proof.
112
- // Setup/reset retain their destructive-operation inspection requirement.
113
- if(operation?.token&&verb==='dev'&&uncheckedInspection(error))return {lockProof:true};
114
- throw error;
117
+ if(!uncheckedInspection(error))throw error;
118
+ // Demo serves isolated data. Even a read-only SQLite connection can update
119
+ // canonical WAL read marks, so its owner-state byte preservation forbids it.
120
+ if(!isolated){
121
+ const {sqliteCustody}=await shared('local/sqlite-custody.mjs');
122
+ const database=await sqliteCustody(project.root);
123
+ if(database)throw refuse(`Another process holds an active SQLite lock on ${database}. Process inspection did not identify its PID. Stop unmanaged local servers (including Wrangler), then retry. Use rer dev --stop or rer preview --stop for a registered server.`);
124
+ }
125
+ return {lockProof:true};
115
126
  }
116
127
  if(conflict)throw refuse(`A local process holds ${conflict.reason}: PID ${conflict.pid} (${conflict.command}). Stop it with kill -TERM ${conflict.pid}, then retry. Use rer dev --stop or rer preview --stop for a registered server.`);
117
128
  }
@@ -87,7 +87,7 @@ export async function managedServer(project,options,out,{clock={}}={}){
87
87
  await stateSafety(project);
88
88
  const {localOperation}=await shared('local/operation.mjs');
89
89
  try{operation=await localOperation(project.root);}catch(error){throw refuse(error.message);}
90
- const ownership=await refuseLegacyProcess(project,{verb:options.verb,operation});
90
+ const ownership=await refuseLegacyProcess(project,{verb:options.verb,operation,isolated:options.demo});
91
91
  if(ownership?.lockProof)out.progress('Local process inspection did not answer; continuing with the exclusive checkout launch lock.\n');
92
92
  const {recoverInterrupted}=await shared('local/recovery.mjs');await recoverInterrupted(project.root,operation);
93
93
  const {loadInstallerSeed}=await shared('setup-manifest.mjs');
package/cli/release.mjs CHANGED
@@ -11,6 +11,8 @@ Without --tag, write a preview. This command never pushes, uploads or deploys.
11
11
  Credential-free https://github.com/<owner>/<repository> destination.
12
12
  --output NEW_DIR New output directory outside the source repository.
13
13
  --ref REF Selected committed source (default: HEAD).
14
+ --public-base REF Public history as GIT_URL#BRANCH for exact-source scans;
15
+ defaults to this public repository's default branch.
14
16
  --tag [vVERSION] Prepare source artifacts and create a local annotated tag;
15
17
  an explicit tag must match the committed release version.
16
18
  --dry-run Run the real gates and suppress local tag creation.
@@ -43,8 +45,8 @@ export async function dispatchRelease(args) {
43
45
  else if (args[index] === '--tag') options.tag = args[index + 1]?.startsWith('v') ? args[++index] : true;
44
46
  else if (args[index] === '--clean-history') options.cleanHistory = true;
45
47
  else if (args[index] === '--dry-run') options.dryRun = true;
46
- else if (['--repo', '--project', '--repository', '--output', '--ref', '--env-file', '--onto'].includes(args[index]) && args[index + 1] && !args[index + 1].startsWith('--'))
47
- options[args[index] === '--env-file' ? 'envFile' : args[index].slice(2)] = args[++index];
48
+ else if (['--repo', '--project', '--repository', '--output', '--ref', '--env-file', '--onto', '--public-base'].includes(args[index]) && args[index + 1] && !args[index + 1].startsWith('--'))
49
+ options[args[index] === '--env-file' ? 'envFile' : args[index] === '--public-base' ? 'publicBase' : args[index].slice(2)] = args[++index];
48
50
  else throw Error('Invalid release arguments');
49
51
  }
50
52
  if(args.includes('--no-queue')){const {shared}=await import('./shared.mjs');const {commandPolicy}=await shared('queue.mjs');const policy=await commandPolicy();try{if(!policy.ci)throw Error('Original CI required');}finally{await policy.close();}}
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.27
4
+
5
+ - `rer release` of an exact source commit scans source history against the repository's public history. When the checkout's origin is a confirmed public GitHub repository, its default branch and published tags are the scanner's public base, so findings already public are classified pre-existing and unpublished content still blocks. `--public-base GIT_URL#BRANCH` selects public history explicitly; it cannot be combined with `--onto` or `--clean-history`.
6
+ - On a busy machine, a process-table read that outlives its ordinary bound is awaited for up to 25 more seconds with a `RER_PROCESS_INSPECTION_SLOW` warning, instead of failing a passing run's cleanup. Cleanup still fails only on owned processes observed alive.
7
+ - Setup, local import/restore, reset and local startup hold the checkout's exclusive operation lock through completion, and every local ownership check falls back to that lock proof when `lsof` does not answer within three seconds. Canonical-state commands then probe existing SQLite databases with an immediate exclusive transaction that rolls back, and refuse when another process holds a SQLite lock. Demo uses the lock proof without opening canonical SQLite.
8
+ - `modules/operator-auth/policy.d.mts` ships client-safe types for `normalizeEmail`, `emailDomain` and `safeReturnTo`.
9
+ - `DEMO.md` says that new visitors may get the previous demo version for several minutes after a deploy (about 7–9 minutes measured), so measure about 10 minutes after a demo deploy.
10
+
11
+ ### Upgrade notes
12
+
13
+ - Update the exact rer package pin, or refresh vendored operating commands, to receive these changes.
14
+
3
15
  ## 0.2.26
4
16
 
5
17
  - The `rer` mail adapter carries `List-Id`, `List-Archive`, `List-Help`, `In-Reply-To` and `References` to the Managed relay as its `listId`, `listArchive`, `listHelp`, `inReplyTo` and `references` fields, and refuses invalid values before sending. Other raw headers stay refused.
@@ -0,0 +1,3 @@
1
+ export function normalizeEmail(value: unknown): string;
2
+ export function emailDomain(email: string): string;
3
+ export function safeReturnTo(value: unknown, fallback?: string): string;
@@ -48,8 +48,12 @@ accept independent project and repository inputs, retain strict reference checks
48
48
  and cannot receive this INFO classification.
49
49
 
50
50
  It installs frozen dependencies and runs `pnpm run verify` in a disposable clone
51
- of the exact selected commit, then scans the original repository's complete
52
- local-ref history with publish-check. A verify that mutates tracked source fails.
51
+ of the exact selected commit, then scans source history with publish-check.
52
+ When the checkout's origin is a confirmed public repository, the scanner uses
53
+ that source repository's advertised default branch and published tags as its public
54
+ base. Already-public findings are classified pre-existing; unpublished content
55
+ still blocks. Other sources retain complete local-ref history inspection.
56
+ A verify that mutates tracked source fails.
53
57
  When declared in the committed package, it runs `pnpm run verify:release` after
54
58
  default verification succeeds. Keep capacity, maximum-size memory and load cases
55
59
  in that release-only script. Both dry runs and releases require it to pass;
@@ -120,6 +124,25 @@ the source tag. Release notes pass the same content rules as the public tree.
120
124
 
121
125
  ## Releasing a seed that is already public
122
126
 
127
+ Release the exact green source commit with the ordinary command:
128
+
129
+ ```sh
130
+ pnpm rer release --repo /path/to/public-seed --ref GREEN_COMMIT \
131
+ --project "$PUBLIC_PROJECT" --repository "$PUBLIC_REPOSITORY" \
132
+ --tag v1.2.3 --output /path/to/new-release-directory
133
+ ```
134
+
135
+ Both source-history and staged-annotation scans receive the repository's public
136
+ base. Public annotated tags, including the previous release, are fetched into
137
+ the scanner's isolated namespace and recognized by their exact object identity.
138
+ The selected source commit and final tag target are preserved.
139
+
140
+ Use `--public-base GIT_URL#BRANCH` to select public history explicitly, including
141
+ when the checkout has no public origin. The scanner fetches that remote branch
142
+ and its public tags; local refs and commit IDs cannot establish public history.
143
+ This option applies to exact-source releases and cannot be combined with
144
+ `--onto` or `--clean-history`.
145
+
123
146
  Use `--onto` to create one public child of the destination's current branch from
124
147
  an independently developed private source tree:
125
148
 
@@ -7,14 +7,16 @@ import { publicExport, cleanHistory, annotate, releaseMessage } from './export.m
7
7
  import { publicationScan, validatePublicationDestination } from './publication-scan.mjs';
8
8
  import { publicDestination, requirePublicDestination, remotePublicHead, publicChild, assertPublicTree } from './public-child.mjs';
9
9
  import { writePublishHandoff } from './publish-handoff.mjs';
10
+ import { releasePublicBase } from './public-base.mjs';
10
11
 
11
12
  // Failure output belongs to the private receipt, not the site preview.
12
13
  const withoutOutput = gates => JSON.parse(JSON.stringify(gates, (key, value) => key === 'output' ? undefined : value));
13
14
 
14
- export async function release({ repo, ref = 'HEAD', output, project, repository, dryRun = false, tag = false, cleanHistory: clean = false, envFile, onto }) {
15
+ export async function release({ repo, ref = 'HEAD', output, project, repository, dryRun = false, tag = false, cleanHistory: clean = false, envFile, onto, publicBase }) {
15
16
  if (!/^[\w.-]+\/[\w.-]+$/.test(project ?? '')) throw Error('--project must be publisher/name');
16
17
  if (!/^https:\/\/github\.com\/[\w.-]+\/[\w.-]+(?:\.git)?$/i.test(repository ?? '')) throw Error('--repository must be a credential-free GitHub repository URL');
17
18
  if (onto !== undefined && clean) throw Error('--onto and --clean-history are mutually exclusive');
19
+ if (publicBase !== undefined && (onto !== undefined || clean)) throw Error('--public-base selects exact-source history; cannot combine with export history modes');
18
20
  const preview = dryRun || !tag;
19
21
  const source = inspectSource(repo, ref);
20
22
  validatePublicationDestination(source, project, repository);
@@ -25,6 +27,7 @@ export async function release({ repo, ref = 'HEAD', output, project, repository,
25
27
  // Validate metadata before installs or output writes.
26
28
  catalogue(source, project, repository, { verify: { status: 'PENDING' }, publishCheck: { status: 'PENDING' } }, preview);
27
29
  const destination = onto !== undefined ? publicDestination(onto, repository, source.repo) : null;
30
+ const scanBase = destination?.spec ?? (clean ? undefined : releasePublicBase(source, publicBase));
28
31
  let publicParent = null;
29
32
  if (destination) {
30
33
  requirePublicDestination(destination);
@@ -54,12 +57,13 @@ export async function release({ repo, ref = 'HEAD', output, project, repository,
54
57
  verify.status = 'FAIL'; verify.reason = 'verify-changed-tracked-source';
55
58
  }
56
59
  // Explicit clean-history publication scans every byte and ref of the actual
57
- // parentless export. Ordinary releases retain the private full-history gate.
60
+ // parentless export. Exact-source releases classify against public history
61
+ // when available, retaining the selected source commit and tag identity.
58
62
  const exported = destination ? publicChild(source, temporary, destination, publicParent, Boolean(tag))
59
63
  : clean ? cleanHistory(source, temporary, Boolean(tag)) : null;
60
64
  const scanRepo = exported?.repo ?? source.repo;
61
65
  const scanRef = exported?.commit ?? source.commit;
62
- let report = publicationScan(scanRepo, scanRef, envFile, project, repository, destination?.spec);
66
+ let report = publicationScan(scanRepo, scanRef, envFile, project, repository, scanBase);
63
67
  if (!exported && tag && report.status === 'PASS') {
64
68
  // Stage the exact final annotation before any source tag or distributable
65
69
  // artifact exists, in a fresh clone of the selected commit: verification
@@ -70,7 +74,7 @@ export async function release({ repo, ref = 'HEAD', output, project, repository,
70
74
  git(candidate, 'checkout', '--detach', source.commit);
71
75
  const staged = git(candidate, 'tag', '--list', source.tag).toString().trim();
72
76
  annotate(candidate, source, source.commit, staged ? `${source.tag}-publication-candidate` : source.tag);
73
- const annotations = publicationScan(candidate, source.commit, envFile, project, repository);
77
+ const annotations = publicationScan(candidate, source.commit, envFile, project, repository, scanBase);
74
78
  report.annotationInspection = annotations;
75
79
  if (annotations.status !== 'PASS') {
76
80
  report.status = annotations.status;
@@ -0,0 +1,29 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { resolve } from 'node:path';
3
+ import { git } from './source.mjs';
4
+ import { publicGit } from './public-git.mjs';
5
+
6
+ const identity = url => /^(?:https:\/\/github\.com\/|ssh:\/\/git@github\.com\/|git@github\.com:)([\w.-]+\/[\w.-]+)$/i
7
+ .exec(url)?.[1].replace(/\.git$/i, '');
8
+
9
+ // Publication targets do not establish whether the source is already public.
10
+ // Infer a base from the source repository's own confirmed public origin.
11
+ export function releasePublicBase(source, explicit) {
12
+ if (explicit !== undefined) return explicit;
13
+ if (!git(source.repo, 'remote').toString().trim().split('\n').includes('origin')) return undefined;
14
+ const origin = git(source.repo, 'config', '--get', 'remote.origin.url').toString().trim();
15
+ const sourceIdentity = identity(origin);
16
+ if (!sourceIdentity) return undefined;
17
+ const repository = `https://github.com/${sourceIdentity}`;
18
+ const script = 'import sys; sys.path.insert(0, sys.argv[1]); from github_refs import GitHubResolver; print(GitHubResolver().resolve(sys.argv[2]))';
19
+ const visibility = execFileSync('python3', ['-B', '-c', script,
20
+ resolve(import.meta.dirname, '../../scripts/publish-check'), sourceIdentity],
21
+ { stdio: ['ignore', 'pipe', 'pipe'] }).toString().trim();
22
+ if (['private', 'missing'].includes(visibility)) return undefined;
23
+ if (visibility !== 'public') throw Error('Source repository visibility could not be established');
24
+ const advertised = publicGit(source.repo, ['--git-dir=/dev/null', 'ls-remote', '--symref', '--', repository, 'HEAD']).toString();
25
+ const branches = [...advertised.matchAll(/^ref: refs\/heads\/(.+)\tHEAD$/gm)].map(match => match[1]);
26
+ if (branches.length !== 1) throw Error('Public source default branch is missing or ambiguous');
27
+ publicGit(source.repo, ['check-ref-format', `refs/heads/${branches[0]}`]);
28
+ return `${repository}#${branches[0]}`;
29
+ }
@@ -0,0 +1,34 @@
1
+ import {open} from 'node:fs/promises';
2
+ import {join,relative} from 'node:path';
3
+ import {stateFiles} from './state-files.mjs';
4
+
5
+ // A launch lock excludes cooperating commands. When process inspection fails,
6
+ // SQLite can still positively identify a conflicting transaction without a
7
+ // process-table walk. This cannot detect idle file handles or WAL readers.
8
+ export async function sqliteCustody(root) {
9
+ for(const path of await stateFiles(join(root,'.wrangler/state'))){
10
+ // Sidecars are not databases; state can disappear after this snapshot.
11
+ if(/-(?:wal|shm|journal)$/.test(path))continue;
12
+ let file;
13
+ try{file=await open(path,'r');}catch(error){if(error.code==='ENOENT')continue;throw error;}
14
+ let sqlite;
15
+ try{
16
+ const header=Buffer.alloc(16),{bytesRead}=await file.read(header,0,16,0);
17
+ sqlite=bytesRead===16&&header.toString()==='SQLite format 3\0';
18
+ }finally{await file.close();}
19
+ if(!sqlite)continue;
20
+ // Lazy import keeps the database engine out of early launcher registration.
21
+ const {DatabaseSync}=await import('node:sqlite');
22
+ let db;
23
+ try{
24
+ // This must be a writable connection: read-only WAL transactions do not
25
+ // exclude writers. Closing it may checkpoint idle WAL, so never use it for
26
+ // demo, whose canonical owner-state bytes must remain unchanged.
27
+ db=new DatabaseSync(path);
28
+ db.exec('PRAGMA busy_timeout=0; BEGIN EXCLUSIVE; ROLLBACK;');
29
+ }catch(error){
30
+ if(error.errcode===5||error.errcode===6)return relative(root,path);
31
+ throw new Error('Could not check the local SQLite lock. Preserve local state and resolve the database error before retrying.');
32
+ }finally{db?.close();}
33
+ }
34
+ }
@@ -32,19 +32,19 @@ export async function stopOwnedGroup(child, signal, ownership) {
32
32
  const stopped = new Map()
33
33
  let lastGroup = []
34
34
 
35
- const snapshot = async (limit = deadline) => {
36
- const current = await inspect(Math.min(inspectionMs, limit - Date.now()))
37
- if (Date.now() >= limit) throw new Error('Process inspection deadline expired.')
35
+ // Every inspection gets its full bound (and process-table's extension): a
36
+ // slow but complete read is still a valid observation. The cleanup deadline
37
+ // ends the loop below, and only processes observed alive at it fail cleanup.
38
+ const snapshot = async () => {
39
+ const current = await inspect(inspectionMs)
38
40
  lastGroup = current
39
41
  return current
40
42
  }
41
- const send = async (member, name, requireLeaf = true, limit = deadline) => {
43
+ const send = async (member, name, requireLeaf = true) => {
42
44
  // Recheck both identity and children immediately before each numeric PID
43
45
  // signal. Never send a negative/group signal that can kill parents first.
44
- const timeout = Math.min(inspectionMs, limit - Date.now())
45
- const current = requireLeaf ? await readProcessTable(timeout) : []
46
- const target = await readProcessIdentity(member.pid, Math.min(inspectionMs, limit - Date.now()))
47
- if (Date.now() >= limit) throw new Error('Process inspection deadline expired.')
46
+ const current = requireLeaf ? await readProcessTable(inspectionMs) : []
47
+ const target = await readProcessIdentity(member.pid, inspectionMs)
48
48
  if (!sameProcess(member, target) || isZombie(target)) return false
49
49
  if (requireLeaf && !isLeaf(target, current)) return false
50
50
  if (name === 'SIGKILL' && !isStopped(target)) return false
@@ -122,9 +122,8 @@ export async function stopOwnedGroup(child, signal, ownership) {
122
122
  } finally {
123
123
  // Inspection/signalling failures must not leave a process suspended.
124
124
  const errors = []
125
- const resumeDeadline = Math.min(deadline + 1000, Date.now() + 1000)
126
125
  for (const member of stopped.values()) {
127
- try { await send(member, 'SIGCONT', false, resumeDeadline) } catch (error) { errors.push(error) }
126
+ try { await send(member, 'SIGCONT', false) } catch (error) { errors.push(error) }
128
127
  }
129
128
  // Preserve the original failure while reporting a failure to resume an owned process.
130
129
  // eslint-disable-next-line no-unsafe-finally
@@ -215,9 +215,7 @@ export async function localProcessConflict(root,savedOrigin,context=inspectionCo
215
215
  return {pid:held.pid,command:command||'process',reason:'the canonical local state'};
216
216
  }
217
217
  }
218
- let all;
219
- try{all=await listeners(undefined,context);}
220
- catch(error){if(!uncheckedInspection(error)||context.verb==='reset')throw error;return;}
218
+ const all=await listeners(undefined,context);
221
219
  const cwdRecords=process.platform!=='linux'&&all.length?records(await run(lsof,['-nP','-b','-w','-a','-p',all.map(row=>row.pid).join(','),'-d','cwd','-Fpn'],context)):[];
222
220
  let port;try{const url=new URL(savedOrigin);port=Number(url.port||80);}catch{}
223
221
  for(const row of all){
@@ -228,6 +226,9 @@ export async function localProcessConflict(root,savedOrigin,context=inspectionCo
228
226
  // A listener running somewhere else is another program's or another checkout's
229
227
  // server: it does not use this checkout's state, so it only blocks the port.
230
228
  if(onSavedPort&&places.length&&!places.some(place=>place===root||place.startsWith(root+'/')))continue;
231
- if(onSavedPort||inCheckout)return {pid:row.pid,command:await processName(row.pid,context),reason:onSavedPort?`saved local port ${port}`:'this checkout'};
229
+ if(onSavedPort||inCheckout){
230
+ let command;try{command=await processName(row.pid,context);}catch(error){if(!uncheckedInspection(error))throw error;}
231
+ return {pid:row.pid,command:command||'process',reason:onSavedPort?`saved local port ${port}`:'this checkout'};
232
+ }
232
233
  }
233
234
  }
@@ -3,7 +3,7 @@ import { readFile } from 'node:fs/promises'
3
3
  import { randomUUID } from 'node:crypto'
4
4
  import { promisify } from 'node:util'
5
5
  import { setTimeout as delay } from 'node:timers/promises'
6
- import { inspectionMs, readProcessIdentity, readProcessTable, sameBirth } from './process-table.mjs'
6
+ import { extensionMs, inspectionMs, readProcessIdentity, readProcessTable, sameBirth } from './process-table.mjs'
7
7
 
8
8
  const execute = promisify(execFile)
9
9
  const scopes = new WeakMap()
@@ -35,7 +35,9 @@ export function processScopeEnvironment(scope, environment) {
35
35
  }
36
36
  export async function scopedProcesses(scope, table, timeout = inspectionMs, previous = []) {
37
37
  if (!scopes.has(scope)) throw new Error('Unknown process scope.')
38
- const inspectionEnd = Date.now() + timeout
38
+ // Reading environments is the slowest inspection on a busy Mac; it shares
39
+ // process-table's bounded extension rather than failing at the ordinary bound.
40
+ const inspectionEnd = Date.now() + timeout + extensionMs
39
41
  // Inspect same-user candidates in one bounded call. A child can change cwd,
40
42
  // detach and lose its parent between captures; the exclusive inherited marker
41
43
  // still proves ownership. Arguments/environment never leave this function.
@@ -52,7 +54,7 @@ export async function scopedProcesses(scope, table, timeout = inspectionMs, prev
52
54
  && (member.uid === undefined || member.uid === process.getuid())
53
55
  )
54
56
  if (!candidates.length) return []
55
- const environments = process.platform === 'linux' ? new Map() : await readEnvironments(candidates.map(member => member.pid), timeout)
57
+ const environments = process.platform === 'linux' ? new Map() : await readEnvironments(candidates.map(member => member.pid), Math.max(1, inspectionEnd - Date.now()))
56
58
  const matches = []
57
59
  inspectCandidate: for (const member of candidates) {
58
60
  let environment
@@ -13,14 +13,26 @@ export const inspectionMs = 5000
13
13
  // launch whose own processes are accounted for.
14
14
  const transient = (message) => Object.assign(new Error(message), { transient: true })
15
15
  const retryMs = 10
16
- async function withinBound(timeout, attempt) {
17
- const deadline = Date.now() + timeout
18
- for (;;) {
19
- try { return await attempt(Math.max(1, deadline - Date.now())) } catch (error) {
20
- if (!error.transient || Date.now() + retryMs >= deadline) throw error
21
- await delay(retryMs)
16
+ // A busy machine can starve ps, or this process, past the ordinary bound while
17
+ // the read itself is healthy; its finished output can even be queued behind
18
+ // the deadline timer. Such a read is not a failure of the caller's work: the
19
+ // same in-flight read is awaited for a bounded extension, with a warning, and
20
+ // only an inspection that also outlives the extension fails.
21
+ export const extensionMs = 25000
22
+ async function withinBound(timeout, attempt, extension = extensionMs) {
23
+ const deadline = Date.now() + timeout + extension
24
+ const slow = setTimeout(() => process.emitWarning(
25
+ `Process inspection is taking longer than ${timeout} ms on a busy machine; waiting up to ${extension} ms more.`,
26
+ { code: 'RER_PROCESS_INSPECTION_SLOW' }), timeout)
27
+ slow.unref()
28
+ try {
29
+ for (;;) {
30
+ try { return await attempt(Math.max(1, deadline - Date.now())) } catch (error) {
31
+ if (!error.transient || Date.now() + retryMs >= deadline) throw error
32
+ await delay(retryMs)
33
+ }
22
34
  }
23
- }
35
+ } finally { clearTimeout(slow) }
24
36
  }
25
37
  export const validPid = (pid) => Number.isSafeInteger(pid) && pid > 0 && pid <= 0x7fffffff
26
38
 
@@ -103,7 +115,7 @@ async function processGroup(pgid, signal) {
103
115
  // cleanup slower than the existing bounded shutdown contract.
104
116
  export async function readProcessIdentity(pid, timeout = inspectionMs) {
105
117
  if (!validPid(pid) || !(timeout > 0)) throw new Error('Invalid process identity deadline.')
106
- if (process.platform === 'linux') return linuxProcess(pid, undefined, AbortSignal.timeout(timeout))
118
+ if (process.platform === 'linux') return withinBound(timeout, (remaining) => linuxProcess(pid, undefined, AbortSignal.timeout(remaining)))
107
119
  return withinBound(timeout, (remaining) => psIdentity(pid, remaining))
108
120
  }
109
121
 
@@ -122,7 +134,7 @@ async function psIdentity(pid, timeout) {
122
134
 
123
135
  // `read` is the process edge: it returns the table or throws; tests supply a
124
136
  // failing one.
125
- export async function readProcessTable(timeout = inspectionMs, pgid, read = processGroup) {
137
+ export async function readProcessTable(timeout = inspectionMs, pgid, read = processGroup, extension = extensionMs) {
126
138
  if (!(timeout > 0)) throw new Error('Process inspection deadline expired.')
127
139
  return withinBound(timeout, async (remaining) => {
128
140
  const controller = new AbortController()
@@ -135,7 +147,7 @@ export async function readProcessTable(timeout = inspectionMs, pgid, read = proc
135
147
  }, remaining)
136
148
  })])
137
149
  } finally { clearTimeout(timer) }
138
- })
150
+ }, extension)
139
151
  }
140
152
 
141
153
  export const sameBirth = (left, right) => validPid(left?.pid) && left.pid === right?.pid && left.birth === right?.birth
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.26",
3
+ "version": "0.2.27",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,6 +20,7 @@ class History:
20
20
  self.repo = str(Path(repo).resolve())
21
21
  self.env = git_environment()
22
22
  self.public_commit = self.public_label = None
23
+ self.public_tags = set()
23
24
  self.reader = None
24
25
  self.commit = self.run('rev-parse', '--verify', '--end-of-options', ref + '^{commit}').decode().strip()
25
26
  if self.run('rev-parse', '--is-shallow-repository').strip() != b'false':
@@ -27,15 +28,19 @@ class History:
27
28
  if public_base is not None:
28
29
  url, branch = parse(public_base, self.repo)
29
30
  try:
30
- self.run('fetch', '--quiet', '--no-tags', '--no-recurse-submodules', '--no-write-fetch-head', '--',
31
- url, 'refs/heads/' + branch + ':refs/publish-check/public/base')
31
+ self.run('fetch', '--quiet', '--prune', '--no-tags', '--no-recurse-submodules', '--no-write-fetch-head', '--',
32
+ url, 'refs/heads/' + branch + ':refs/publish-check/public/base',
33
+ 'refs/tags/*:refs/publish-check/public/tags/*')
32
34
  self.public_commit = self.run('rev-parse', 'refs/publish-check/public/base^{commit}').decode().strip()
33
35
  self.public_label = display(url) + '#' + branch
36
+ self.public_tags = set(self.run('for-each-ref', '--format=%(objectname)',
37
+ 'refs/publish-check/public/tags').decode().splitlines())
34
38
  except InspectionError:
35
39
  raise PublicBaseError('public-base.fetch-failed') from None
36
- self.revisions = [self.commit, self.public_commit] if public_base else ['--all', self.commit]
40
+ public_revisions = [self.public_commit, *sorted(self.public_tags)] if public_base else []
41
+ self.revisions = [self.commit, *public_revisions] if public_base else ['--all', self.commit]
37
42
  self.commits = self.run('rev-list', *self.revisions).decode().splitlines()
38
- self.public_commits = set(self.run('rev-list', self.public_commit).decode().splitlines()) if self.public_commit else set()
43
+ self.public_commits = set(self.run('rev-list', *public_revisions).decode().splitlines()) if public_base else set()
39
44
  self.trees = {}
40
45
  self.tree_ids = dict(line.split() for line in self.run('log', '--format=%H %T', *self.revisions).decode().splitlines())
41
46
  self.reader = subprocess.Popen(['git', '-C', self.repo, 'cat-file', '--batch'],
@@ -97,9 +102,12 @@ class History:
97
102
  for index in range(0, len(records) - 1, 2):
98
103
  if records[index]:
99
104
  yield 'commit', records[index].decode().strip(), records[index + 1]
100
- for record in self.run('for-each-ref', '--format=%(objecttype) %(objectname)', 'refs/tags').splitlines():
105
+ seen = set()
106
+ for record in self.run('for-each-ref', '--format=%(objecttype) %(objectname)', 'refs/tags',
107
+ 'refs/publish-check/public/tags').splitlines():
101
108
  kind, oid = record.decode().split()
102
- if kind == 'tag':
109
+ if kind == 'tag' and oid not in seen:
110
+ seen.add(oid)
103
111
  raw = self.run('cat-file', 'tag', oid)
104
112
  yield 'tag', oid, raw.partition(b'\n\n')[2]
105
113
 
@@ -161,7 +161,7 @@ def scan(repo, ref='HEAD', public_base=None, env_file=None, project=None, reposi
161
161
  report['history']['tagMessages' if message_type == 'tag' else 'commitMessages'] += 1
162
162
  rules, _ = text_rules(data, path, selected_context, resolver, hashes,
163
163
  commit_message=message_type == 'commit')
164
- scope = 'release-tree' if commit == history.commit else 'pre-existing' if commit in history.public_commits else 'newly-public'
164
+ scope = 'pre-existing' if commit in history.public_commits or commit in history.public_tags else 'release-tree' if commit == history.commit else 'newly-public'
165
165
  for rule in rules:
166
166
  add(rule, path, commit, scope=scope)
167
167
  messages.append(data + b'\n')