@runeditrun/rer 0.2.67 → 0.2.68

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.
@@ -3,18 +3,92 @@ import { tokens, identifier, folded } from './generated.mjs';
3
3
  // Whether one migration statement can change rows a restore carries. Only
4
4
  // CREATE TABLE (not AS SELECT), CREATE INDEX and ALTER TABLE ... ADD COLUMN
5
5
  // are additive: SQLite refuses ADD COLUMN with a non-constant default, so a
6
- // restored row takes the same value the migration gave existing rows. Any
7
- // other statement (INSERT, UPDATE, DELETE, triggers, table rebuilds) changes
8
- // data unless it names none of the restorable tables, as when it only touches
9
- // operator-auth or other excluded tables.
10
- export function changesData(sql,restorable) {
11
- const list=tokens(sql),words=list.map(t=>t.quoted?undefined:folded(t.text));
12
- const kind=words.slice(0,4).filter(w=>!['temp','temporary','unique'].includes(w)).slice(0,2).join(' ');
6
+ // restored row takes the same value the migration gave existing rows.
7
+ // CREATE TRIGGER and DROP TRIGGER are schema-only whatever the body does:
8
+ // neither runs the body, so no row changes when the migration runs, and a
9
+ // restore inserts rows with the destination's triggers dropped and recreates
10
+ // them afterwards (import.mjs finalizeImport), exactly as the live upgrade left
11
+ // the rows that predate the trigger. That holds only for a statement bounded
12
+ // as exactly one trigger statement; any other (INSERT, UPDATE, DELETE, table
13
+ // rebuilds, a trigger glued to a further statement) changes data unless it
14
+ // names none of `reached` (reachingTables), as when it only touches
15
+ // operator-auth or other excluded tables that no trigger links to restorable ones.
16
+ // `empty` lists the restorable tables the archive holds no rows of: restore
17
+ // leaves them empty, and an UPDATE or DELETE of an empty table changes nothing
18
+ // (no row fires a trigger either), so such a statement changes data only if it
19
+ // names another reached table (one it could write, or read into its writes).
20
+ // Any other statement naming an empty table still does: an INSERT would leave
21
+ // rows the restore lacks.
22
+ export function changesData(sql,reached,empty=[]) {
23
+ const list=tokens(sql),words=list.map(t=>t.quoted?undefined:folded(t.text)),kind=kindOf(words);
13
24
  if(kind==='create table')return topLevelWords(list,words).includes('as');
14
25
  if(kind==='create index')return false;
15
26
  if(kind==='alter table' && words.find((w,i)=>i>2 && ['add','rename','drop'].includes(w))==='add')return false;
16
- const names=new Set(restorable.map(folded));
17
- return list.some(t=>t.quoted ? !t.text.startsWith("'") && names.has(folded(identifier(t))) : t.text.split('.').some(part=>names.has(folded(part))));
27
+ if(kind==='create trigger' && createdTrigger(list))return false;
28
+ if(kind==='drop trigger' && droppedTrigger(list))return false;
29
+ const skipped=new Set(['update','delete'].includes(words[0])?empty.map(folded):[]);
30
+ return names(list,new Set(reached.map(folded).filter(name=>!skipped.has(name))));
31
+ }
32
+ // The restorable tables and every table whose writes reach one through a
33
+ // trigger any of `statements` creates: a write to such a table during a later
34
+ // migration changes restorable rows the archive lacks. A trigger counts when
35
+ // its statement names a reached table anywhere; one this parser cannot bound
36
+ // adds every name it holds.
37
+ export function reachingTables(statements,restorable) {
38
+ const reached=new Set(restorable.map(folded));
39
+ const triggers=statements.map(sql=>tokens(sql)).filter(list=>kindOf(list.map(t=>t.quoted?undefined:folded(t.text)))==='create trigger')
40
+ .map(list=>({list,on:createdTrigger(list)?.on}));
41
+ for(let grew=true;grew;) {
42
+ grew=false;
43
+ for(const {list,on} of triggers)if(names(list,reached))for(const name of on===undefined?identifiers(list):[on])if(!reached.has(name)){reached.add(name);grew=true;}
44
+ }
45
+ return [...reached];
46
+ }
47
+ const kindOf=words=>words.slice(0,4).filter(w=>!['temp','temporary','unique'].includes(w)).slice(0,2).join(' ');
48
+ const identifiers=list=>list.flatMap(t=>t.quoted?(t.text.startsWith("'")?[]:[folded(identifier(t))]):folded(t.text).split(/[^a-z0-9_$\u0080-\uffff]+/).filter(Boolean));
49
+ const names=(list,reached)=>identifiers(list).some(name=>reached.has(name));
50
+ // Tokens with each unquoted ';' split out, and trailing ones dropped.
51
+ function atoms(list) {
52
+ const result=list.flatMap(t=>t.quoted?[t]:t.text.split(/(;)/).filter(Boolean).map(text=>({text})));
53
+ while(result.length && semicolon(result.at(-1)))result.pop();
54
+ return result;
55
+ }
56
+ const semicolon=a=>!a.quoted && a.text===';';
57
+ const word=(a,value)=>a && !a.quoted && folded(a.text)===value;
58
+ // {on} for CREATE [TEMP] TRIGGER ... ON table ... BEGIN statement; ... END and
59
+ // nothing after it. The body ends at the first END that starts a statement;
60
+ // CASE ... END inside a statement does not. Anything else is unbounded.
61
+ function createdTrigger(list) {
62
+ const parts=atoms(list);let depth=0,begin=-1,on;
63
+ for(let i=0;i<parts.length && begin<0;i++) {
64
+ const a=parts[i];
65
+ if(a.quoted)continue;
66
+ if(a.text===';')return;
67
+ if(a.text==='(')depth++;
68
+ else if(a.text===')'){if(--depth<0)return;}
69
+ else if(!depth && on===undefined && word(a,'on')) {
70
+ const name=[];
71
+ for(let j=i+1;j<parts.length && !['for','when','begin'].some(w=>word(parts[j],w));j++)name.push(parts[j]);
72
+ const last=name.at(-1);
73
+ if(!last || name.length>3)return;
74
+ on=folded(last.quoted?identifier(last):last.text.split('.').at(-1));
75
+ if(!on)return;
76
+ }else if(!depth && word(a,'begin'))begin=i;
77
+ }
78
+ if(begin<0 || on===undefined)return;
79
+ let start=true,statements=0;
80
+ for(let i=begin+1;i<parts.length;i++) {
81
+ const a=parts[i];
82
+ if(start && word(a,'end'))return i===parts.length-1 && statements && !depth?{on}:undefined;
83
+ if(semicolon(a)){if(start || depth)return;start=true;statements++;continue;}
84
+ if(!a.quoted){if(a.text==='(')depth++;else if(a.text===')' && --depth<0)return;}
85
+ start=false;
86
+ }
87
+ }
88
+ // DROP TRIGGER [IF EXISTS] [schema.]name, and nothing after it.
89
+ function droppedTrigger(list) {
90
+ const parts=atoms(list),from=word(parts[2],'if') && word(parts[3],'exists')?4:2,name=parts.slice(from);
91
+ return name.length>=1 && name.length<=3 && name.every(a=>a.quoted?!a.text.startsWith("'"):!/[;(),]/.test(a.text));
18
92
  }
19
93
  function topLevelWords(list,words) {
20
94
  let depth=0;const result=[];
@@ -17,6 +17,8 @@ The `rer` bin and `node bin/rer.mjs` expose the same command. Node 22+, Python 3
17
17
  Git, pnpm and tar are required, along with authenticated `gh` for GitHub sources.
18
18
  Use a full-history, clean seed clone with its declared package-manager version;
19
19
  `--filter=blob:none` is supported, while shallow history is refused. Before
20
+ release work begins, tracked changes and untracked files in the source checkout
21
+ are refused; ignored local files do not become release inputs. Before
20
22
  reading source files, destination validation uses the publication scanner's
21
23
  single batched hydration fetch. An unavailable blob reports its object ID and
22
24
  committed path with `fetch the full history` guidance, separately from identity
@@ -97,9 +99,14 @@ path needs the seed's browser prerequisites and any resources its verification
97
99
  requires. Routine CI and default verification do not invoke the release-only
98
100
  script.
99
101
 
100
- Both paths then scan source history with publish-check. When the checkout's
101
- origin is a confirmed public repository, the scanner uses that source
102
- repository's advertised default branch and published tags as its public base.
102
+ Both paths then run publish-check in a fresh disposable clone checked out at
103
+ the selected source commit. Its working tree contains exactly that commit's
104
+ committed files, isolated from the caller's ignored or untracked files and from
105
+ installation, build and verification outputs. The clone retains all source refs
106
+ and full history: committed secrets and historical findings remain subject to
107
+ the publication checks. When the source checkout's origin is a confirmed public
108
+ repository, the scanner uses that source repository's advertised default branch
109
+ and published tags as its public base.
103
110
  Already-public findings are classified pre-existing; unpublished content still
104
111
  blocks. Other sources retain complete local-ref history inspection.
105
112
  A passing step's receipt retains exit status and numeric final summaries from
@@ -212,9 +219,10 @@ Public export commit and annotated-tag messages contain the version and optional
212
219
  `RELEASE.json.publicReleaseNotes` only. Private source commit identities stay in
213
220
  the private release receipt. The clean export's final annotated tag exists
214
221
  before publication inspection, and the checked repository is copied unchanged
215
- into `public-git/`. Ordinary releases inspect their source history and stage the
216
- exact final annotation in a disposable checkout for inspection before creating
217
- the source tag. Release notes pass the same content rules as the public tree.
222
+ into `public-git/`. Ordinary releases stage the exact final annotation in the
223
+ fresh selected-commit checkout and inspect it with the source history before
224
+ creating the source tag. Release notes pass the same content rules as the
225
+ public tree.
218
226
 
219
227
  ## Releasing a seed that is already public
220
228
 
@@ -2,7 +2,7 @@ import { execFileSync } from 'node:child_process';
2
2
  import { resolve } from 'node:path';
3
3
  import { writeFileSync } from 'node:fs';
4
4
  import { git } from './source.mjs';
5
- import { annotate } from './export.mjs';
5
+ import { annotate, sourceTree } from './export.mjs';
6
6
  import { runningVersion } from '../../cli/version.mjs';
7
7
 
8
8
  export function validatePublicationDestination(source, project, repository) {
@@ -36,26 +36,32 @@ export function publicationScan(repo, ref, envFile, project, repository, publicB
36
36
  }
37
37
 
38
38
  // This is the ordinary release gate, also usable without installing/building a
39
- // seed. The scanner sees the original checkout and every source ref; only the
40
- // new annotation is read from the clean candidate, never verification output.
39
+ // seed. Materialize raw committed bytes, without checkout filters or export
40
+ // attributes, and mirror every source ref for the existing history policy.
41
+ // Neither the caller's local files nor verification output enters this tree.
41
42
  export function sourcePublicationScan(source, temporary, envFile, project, repository, publicBase, tagged, adopted) {
42
43
  const started = performance.now();
44
+ const candidate = sourceTree(source, resolve(temporary, 'publication'));
45
+ git(source.repo, 'clone', '--mirror', '--no-hardlinks', '--', source.repo, resolve(candidate, '.git'));
46
+ git(candidate, 'config', 'core.bare', 'false');
47
+ git(candidate, 'update-ref', '--no-deref', 'HEAD', source.commit);
48
+ git(candidate, 'read-tree', source.commit);
43
49
  let annotationFile;
44
50
  if (adopted) {
45
51
  annotationFile = resolve(temporary, 'annotation.tag');
46
52
  writeFileSync(annotationFile, git(adopted.repo, 'cat-file', 'tag', adopted.object), { mode: 0o600 });
47
53
  } else if (tagged) {
48
- const candidate = resolve(temporary, 'annotation');
49
- git(source.repo, 'clone', '--no-hardlinks', '--no-checkout', '--', source.repo, candidate);
50
- git(candidate, 'checkout', '--detach', source.commit);
51
54
  const staged = git(candidate, 'tag', '--list', source.tag).toString().trim();
52
55
  const name = staged ? `${source.tag}-publication-candidate` : source.tag;
53
56
  annotate(candidate, source, source.commit, name);
54
57
  annotationFile = resolve(temporary, 'annotation.tag');
55
58
  writeFileSync(annotationFile, git(candidate, 'cat-file', 'tag', `refs/tags/${name}`), { mode: 0o600 });
59
+ // Inspect the new tag once via annotationFile, leaving the mirrored source
60
+ // refs unchanged for the full-history scan.
61
+ git(candidate, 'tag', '-d', name);
56
62
  }
57
63
  const stagingSeconds = (performance.now() - started) / 1000;
58
- const report = publicationScan(source.repo, source.commit, envFile, project, repository, publicBase, annotationFile);
64
+ const report = publicationScan(candidate, source.commit, envFile, project, repository, publicBase, annotationFile);
59
65
  Object.assign(report.invocation, { stagingSeconds, totalSeconds: (performance.now() - started) / 1000 });
60
66
  return report;
61
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.67",
3
+ "version": "0.2.68",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",