@runeditrun/rer 0.2.79 → 0.2.81

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.
Files changed (147) hide show
  1. package/README.md +17 -3
  2. package/cli/README.md +25 -13
  3. package/cli/authoring.mjs +14 -0
  4. package/cli/contract.mjs +25 -5
  5. package/cli/demo-host.mjs +4 -2
  6. package/cli/deploy-needs.mjs +4 -2
  7. package/cli/dev-identity.mjs +2 -2
  8. package/cli/export.mjs +1 -1
  9. package/cli/inspect.mjs +38 -2
  10. package/cli/ledger-refusal.mjs +18 -0
  11. package/cli/main.mjs +8 -2
  12. package/cli/managed-server.mjs +1 -1
  13. package/cli/parse.mjs +7 -6
  14. package/cli/portability-migrations.mjs +30 -11
  15. package/cli/portability-worker.mjs +4 -1
  16. package/cli/portability.mjs +8 -2
  17. package/cli/production-auth.mjs +2 -1
  18. package/cli/production-mail.mjs +36 -9
  19. package/cli/project.mjs +5 -14
  20. package/cli/release.mjs +6 -5
  21. package/cli/site-hosting.mjs +90 -0
  22. package/cli/site-preview.mjs +4 -1
  23. package/cli/site-render.mjs +3 -2
  24. package/cli/site.mjs +8 -4
  25. package/edition-authoring/adopt.mjs +39 -0
  26. package/edition-authoring/base-acknowledgements.mjs +24 -0
  27. package/edition-authoring/base-copies.mjs +427 -0
  28. package/edition-authoring/cli.mjs +85 -0
  29. package/edition-authoring/copy-checkout.mjs +69 -0
  30. package/edition-authoring/files.mjs +15 -2
  31. package/edition-authoring/lock.mjs +48 -0
  32. package/edition-authoring/offline-git.mjs +28 -0
  33. package/edition-authoring/parent-comparison.mjs +77 -0
  34. package/edition-authoring/projection-lock.mjs +38 -0
  35. package/edition-authoring/release.mjs +48 -0
  36. package/edition-authoring/runtime-dependencies.mjs +108 -0
  37. package/edition-authoring/sources.mjs +114 -0
  38. package/edition-authoring/updates.mjs +105 -0
  39. package/global/CHANGELOG.md +24 -0
  40. package/global/README.md +17 -3
  41. package/global/cli/install.mjs +3 -1
  42. package/global/main.mjs +9 -12
  43. package/modules/container/build.mjs +1 -1
  44. package/modules/d1-transport/index.mjs +68 -21
  45. package/modules/demo/README.md +16 -2
  46. package/modules/demo/declaration.mjs +21 -0
  47. package/modules/demo/input-path.mjs +18 -0
  48. package/modules/demo/label.d.mts +1 -1
  49. package/modules/demo/label.mjs +10 -5
  50. package/modules/demo/navigation.mjs +148 -0
  51. package/modules/demo/run-url.mjs +9 -0
  52. package/modules/demo/vite.d.mts +7 -2
  53. package/modules/demo/vite.mjs +17 -2
  54. package/modules/demo-host/README.md +5 -3
  55. package/modules/demo-host/page-style.mjs +2 -2
  56. package/modules/demo-host/pages.mjs +3 -3
  57. package/modules/demo-host/plan.mjs +6 -4
  58. package/modules/demo-host/theme.mjs +5 -2
  59. package/modules/dependencies/auth.mjs +2 -2
  60. package/modules/deploy-kit/README.md +19 -15
  61. package/modules/deploy-kit/owner-cli.mjs +1 -1
  62. package/modules/deploy-kit/owner.mjs +8 -1
  63. package/modules/deploy-kit/readiness-window.mjs +3 -3
  64. package/modules/erasure/README.md +10 -5
  65. package/modules/import-kit/src/d1/README.md +15 -9
  66. package/modules/import-kit/src/d1/apply-effects.ts +33 -0
  67. package/modules/import-kit/src/d1/apply.ts +46 -14
  68. package/modules/import-kit/src/d1/atomic-prefix.ts +64 -0
  69. package/modules/import-kit/src/d1/budget.ts +48 -26
  70. package/modules/import-kit/src/d1/compressed-plan.ts +9 -2
  71. package/modules/import-kit/src/d1/database.ts +2 -1
  72. package/modules/import-kit/src/d1/jobs.ts +2 -1
  73. package/modules/import-kit/src/d1/plans.ts +4 -2
  74. package/modules/import-kit/src/d1/verified-plan.ts +63 -0
  75. package/modules/import-kit/src/types.ts +3 -1
  76. package/modules/integrations/core/README.md +2 -2
  77. package/modules/mail/README.md +4 -3
  78. package/modules/mail/pnpm-lock.yaml +16 -0
  79. package/modules/operator-auth/README.md +92 -3
  80. package/modules/operator-auth/accounts/admin.mjs +52 -20
  81. package/modules/operator-auth/accounts/audit.mjs +24 -0
  82. package/modules/operator-auth/accounts/business-team.mjs +91 -0
  83. package/modules/operator-auth/accounts/domain-audit.mjs +24 -0
  84. package/modules/operator-auth/accounts/native.mjs +6 -2
  85. package/modules/operator-auth/accounts/provider-control.mjs +7 -4
  86. package/modules/operator-auth/accounts/provider-setup.mjs +34 -0
  87. package/modules/operator-auth/accounts/settings-page.mjs +26 -4
  88. package/modules/operator-auth/accounts/status.mjs +7 -2
  89. package/modules/operator-auth/accounts/store.mjs +32 -6
  90. package/modules/operator-auth/business-settings.mjs +40 -0
  91. package/modules/operator-auth/conformance/README.md +1 -1
  92. package/modules/operator-auth/dev/index.mjs +22 -4
  93. package/modules/operator-auth/dev/refusal.mjs +19 -0
  94. package/modules/operator-auth/docs/README.md +6 -5
  95. package/modules/operator-auth/docs/tanstack-start.md +1 -1
  96. package/modules/operator-auth/docs/vite-spa.md +5 -6
  97. package/modules/operator-auth/identity/email-link/index.mjs +1 -1
  98. package/modules/operator-auth/identity/oidc/admin-audit.mjs +31 -0
  99. package/modules/operator-auth/identity/oidc/index.mjs +12 -5
  100. package/modules/operator-auth/identity/oidc/store.mjs +2 -0
  101. package/modules/operator-auth/index.d.mts +41 -2
  102. package/modules/operator-auth/page.mjs +14 -0
  103. package/modules/operator-auth/representation.mjs +83 -0
  104. package/modules/operator-auth/routes.mjs +31 -3
  105. package/modules/operator-auth/service.mjs +8 -3
  106. package/modules/operator-auth/signin/index.mjs +1 -1
  107. package/modules/portability/README.md +173 -15
  108. package/modules/portability/bookkeeping.mjs +3 -3
  109. package/modules/portability/bridge.mjs +5 -4
  110. package/modules/portability/catalogue.mjs +12 -8
  111. package/modules/portability/cli.mjs +5 -1
  112. package/modules/portability/export.mjs +10 -14
  113. package/modules/portability/format.mjs +12 -1
  114. package/modules/portability/http-errors.mjs +51 -0
  115. package/modules/portability/http.mjs +4 -1
  116. package/modules/portability/import-lease.mjs +13 -2
  117. package/modules/portability/import.mjs +10 -0
  118. package/modules/portability/index.d.mts +13 -2
  119. package/modules/portability/index.mjs +3 -2
  120. package/modules/portability/ledgers.mjs +27 -4
  121. package/modules/portability/references.mjs +20 -0
  122. package/modules/portability/schema-identity.mjs +13 -0
  123. package/modules/portability/schema-legacy.mjs +21 -0
  124. package/modules/portability/sqlite-tokens.mjs +121 -0
  125. package/modules/release/README.md +94 -11
  126. package/modules/release/github-verify.mjs +30 -9
  127. package/modules/release/sign.mjs +4 -2
  128. package/modules/release/signature.mjs +14 -7
  129. package/modules/release/signing-cli.mjs +2 -1
  130. package/modules/release/statement.mjs +2 -2
  131. package/modules/release/vectors/generate.mjs +1 -0
  132. package/modules/release/vectors/publisher-projects.mjs +133 -0
  133. package/modules/release/vectors/release-signature-vectors.json +5195 -0
  134. package/modules/release/verify.mjs +5 -1
  135. package/modules/site/docs-search/search.css +1 -1
  136. package/onboarding/README.md +16 -4
  137. package/onboarding/adapter.mjs +5 -1
  138. package/onboarding/schema/SETUP.schema.json +68 -1
  139. package/onboarding/schema/business-field-inputs.mjs +36 -0
  140. package/onboarding/schema/json-schema.mjs +6 -2
  141. package/onboarding/schema/setup-validation.mjs +23 -3
  142. package/onboarding/server.mjs +1 -1
  143. package/onboarding/setup-manifest.mjs +2 -0
  144. package/onboarding/start-origin-diagnostic.mjs +24 -0
  145. package/onboarding/ui/style.css +9 -9
  146. package/package.json +1 -1
  147. package/scripts/publish-check/README.md +1 -1
@@ -6,6 +6,13 @@ import { statement, guard, job, PortabilityError } from './storage.mjs';
6
6
  export const IMPORT_LEASE_MS=5*60*1000;
7
7
  const RENEW_MS=30*1000;
8
8
  const active=row=>['staging','applying'].includes(row.phase);
9
+ const runningMetadata=new WeakMap();
10
+ // Only the lease constructor can approve these details. Mutable Error fields,
11
+ // prototypes and diagnostic code suffixes cannot establish that provenance.
12
+ export const importRunningMetadata=(error,actor)=>{
13
+ const running=runningMetadata.get(error);
14
+ return typeof actor==='string' && actor===running?.actor?running.details:undefined;
15
+ };
9
16
 
10
17
  // Private transfer bookkeeping can be added to already-installed destinations
11
18
  // without changing product migrations or the archive's schema identity. Keep
@@ -27,8 +34,12 @@ export async function importLeaseStatus(db,row) {
27
34
  return {abortableAt:active(row)&&lease?new Date(lease.expires_at).toISOString():null,stale:active(row)&&!!lease&&lease.expires_at<=Date.now()};
28
35
  }
29
36
  export async function importRunning(db,id) {
30
- const error=new PortabilityError('import_running',409);
31
- error.jobId=id;error.abortableAt=(await importLeaseStatus(db,await job(db,id,'import'))).abortableAt;
37
+ const error=new PortabilityError('import_running',409),row=await job(db,id,'import');
38
+ error.jobId=id;error.abortableAt=(await importLeaseStatus(db,row)).abortableAt;
39
+ if(typeof id==='string' && id.length>0 && id.length<=100 && !/[^a-zA-Z0-9-]/.test(id)
40
+ && (error.abortableAt===null || typeof error.abortableAt==='string' && Number.isFinite(Date.parse(error.abortableAt))
41
+ && new Date(error.abortableAt).toISOString()===error.abortableAt))
42
+ runningMetadata.set(error,Object.freeze({actor:row.actor,details:Object.freeze({jobId:id,abortableAt:error.abortableAt})}));
32
43
  return error;
33
44
  }
34
45
 
@@ -17,6 +17,7 @@ import { additiveBridge, sameSchemaMigrations, appliedMigrations } from './bridg
17
17
  import { replayStatements } from './backfills.mjs';
18
18
  import { checkArchivedLedgers, archivedHistory } from './ledgers.mjs';
19
19
  import { legacyEmptyGuards, legacyAuditStatements, requireLegacyEmpty } from './legacy-safety.mjs';
20
+ import { checkReferences } from './references.mjs';
20
21
  // ledgers: the rows of each migration ledger table the archive carries, as the
21
22
  // caller read them from it ({table:rows}); uploadPart binds them to its parts.
22
23
  export async function createImport(context,manifest,actor='direct',legacyRecovery,ledgers) {
@@ -27,8 +28,15 @@ export async function createImport(context,manifest,actor='direct',legacyRecover
27
28
  const original=manifest;manifest=await restorableManifest(original);
28
29
  const skippedTables=original.tables.filter(table=>platformTable(table.name)).map(table=>table.name);
29
30
  const cat=await catalogue(db,config),upgrade=config.acceptedSchemas[original.schema];
31
+ // Table SQL and migration names cannot establish missing trigger/view/index
32
+ // definitions. Never infer that an old archive's absent inventory is empty.
33
+ insist(manifest.schemaObjects!==undefined || legacyRecovery,'schema_mismatch:legacy_schema',409);
30
34
  const same=manifest.schema===cat.identity,history=()=>archivedHistory(original,ledgers);
31
35
  const {replays,...bridge}=upgrade?{}:same?(await sameSchemaMigrations(db,manifest,cat,context.migrations,history)??{}):await additiveBridge(db,manifest,cat,context.migrations,history);
36
+ // Finalize checks object references on the staged rows; a later migration
37
+ // replayed into a reference table would publish rows that check never saw.
38
+ const referenced=replays?.find(r=>Object.values(config.buckets).some(spec=>spec.objectReferences?.table===r.table));
39
+ insist(!referenced,'schema_mismatch:migration_data:'+referenced?.migration);
32
40
  if(!bridge.fromSchema)insist(canonicalJson(manifest.tables.map(x=>x.name))===canonicalJson(cat.tables.map(x=>x.name)),'table_inventory');
33
41
  if(!upgrade && !bridge.fromSchema)for(const table of manifest.tables) {
34
42
  const target=cat.tables.find(t=>t.name===table.name);
@@ -181,6 +189,8 @@ async function finalizeLeasedImport(context,id,{contentHash,archiveHash,laterJou
181
189
  await refusePolicyApprovals(db,row.metadata.copies);
182
190
  await normalizeStaged(context,row);
183
191
  await refusePolicyApprovals(db,row.metadata.copies);
192
+ // The rows publication restores may name only this archive's objects, in their namespace.
193
+ await checkReferences(context,row.metadata.copies,manifest.objects);
184
194
  if(config.validateStaged) {
185
195
  const read=async table=>{insist(row.metadata.copies[table],'staged_table:'+table);const target=row.metadata.targets.find(t=>t.name===table);return (await readCopy(db,target,row.metadata.copies[table],0,row.metadata.manifest.tables.find(t=>t.name===table)?.count??0)).map(x=>x.row);};
186
196
  insist(await config.validateStaged({db,tables:{...row.metadata.copies},read,manifest})!==false,'staged_validation');
@@ -2,14 +2,19 @@ export type Cell = null | string | number | { blob: string };
2
2
  export type Row = Record<string, Cell>;
3
3
  export interface Column { name: string; type: string; notnull: number; pk: number; generated?: 'virtual'|'stored' }
4
4
  export interface Table { name: string; sql: string; columns: Column[]; dependencies: string[]; count: number; rowidAlias: string|null }
5
+ export interface SchemaObject { name: string; type: 'index'|'view'|'trigger'; table: string; sql: string }
5
6
  export interface ObjectDescriptor { bucket: string; key: string; size: number; sha256: string; httpMetadata: Omit<R2HTTPMetadata,'cacheExpiry'> & {cacheExpiry?:string}; customMetadata: Record<string,string> }
6
7
  export interface PayloadDescriptor { name: string; size: number; sha256: string }
7
8
  export interface Manifest {
8
9
  kind: 'manifest'; format: 'runeditrun-portability'; version: 2; product: string; exportedAt: string; sourceIdentity: string;
9
10
  schema: string; tables: Table[]; objects: ObjectDescriptor[]; payloads: PayloadDescriptor[];
11
+ /** Complete behavioral object definitions; absent from older table-only archives. */
12
+ schemaObjects?: SchemaObject[];
10
13
  excludedTables: string[]; excludedColumns: Record<string,string[]>; requiredConfiguration: string[]; partCount: number; epoch: number; journal: string[];
11
14
  /** Applied product migrations; absent from archives made before additive restore. */
12
15
  migrations?: string[];
16
+ /** Present when RER Platform's runner migrated the source: each applied migration by native file name and SHA-256, in application order. */
17
+ migrationLedger?: {origin:'rer_migrations';entries:{name:string;sha256:string}[]};
13
18
  }
14
19
  export type Item = {kind:'row';table:string;index:number;row:Row;rowid?:number} | {kind:'object';bucket:string;key:string;offset:number;data:string} | {kind:'payload';name:string;offset:number;data:string};
15
20
  export interface Part {kind:'part';index:number;items:Item[];sha256:string}
@@ -39,7 +44,13 @@ export interface Status {id:string;kind:'export'|'import';phase:'building'|'stag
39
44
  export interface Bridge {fromSchema:string;toSchema:string;migrations:string[];tables:string[];columns:Record<string,string[]>;/** Later backfills of tables the archive lacks, replayed at finalize in this order; rows is null until the apply commits. */replayed?:{migration:string;statement:number;table:string;rows:number|null}[]}
40
45
  /** A runner's replay of the destination's applied migrations: the archive schema identity after a chosen set, and each migration's statements. */
41
46
  export interface MigrationReplay {names:string[];/** Seed-declared data-only Platform entries without migration files. */dataOnly?:string[];/** Names generated by the seed's deployment specification for this file. */aliases?(name:string):string[]|undefined;statements(name:string):string[];/** The migration file's SHA-256 hex, where the runner read the file. */sha256?(name:string):string|undefined;schemaAfter(names:string[]):Promise<string>}
42
- export interface PortabilityOptions {db:D1Database;buckets?:Record<string,R2Bucket>;policy:ArchivePolicy;migrations?:()=>Promise<MigrationReplay>}
47
+ /** Export job creation only; no record data, object keys or file paths. */
48
+ export interface ExportEvent {id:string;/** Opaque caller id; the direct/CLI sentinel is normalized to null. */actor:string|null;scope:'installation'}
49
+ export interface PortabilityOptions {
50
+ db:D1Database;buckets?:Record<string,R2Bucket>;policy:ArchivePolicy;migrations?:()=>Promise<MigrationReplay>;
51
+ /** Seed-owned audit SQL, appended to the snapshot/job batch. Throwing or SQL failure refuses creation. */
52
+ onExport?:(event:ExportEvent)=>[sql:string,args:unknown[]][];
53
+ }
43
54
  export interface Portability {
44
55
  exports: {create(actor?:string):Promise<string>;advance(id:string,options?:{expectedPart?:number;maxParts?:number}):Promise<Status>;status(id:string):Promise<Status>;download(id:string):Promise<ReadableStream<Uint8Array>>;abort(id:string):Promise<Status>};
45
56
  imports: {active(actor?:string):Promise<Status|null>;/** ledgers: the rows of each migration ledger table an old archive carries, as read from it; they place it in the destination's history and must equal its parts. */create(manifest:Manifest,actor?:string,options?:{ledgers?:Record<string,Row[]>}):Promise<string>;uploadPart(id:string,index:number,part:Part):Promise<Status>;finalize(id:string,options:{archiveHash:string;contentHash?:string;laterJournal?:LaterJournal}):Promise<Status>;status(id:string):Promise<Status>;abort(id:string):Promise<Status>;/** Aborts the import left staged by a crashed restore and returns its id; call only as the destination's sole operator. */abortAbandoned():Promise<string|null>};
@@ -49,7 +60,7 @@ export interface Portability {
49
60
  invalidateTransfersStatements():Promise<D1PreparedStatement[]>;
50
61
  }
51
62
  export function createPortability(options:PortabilityOptions):Promise<Portability>;
52
- export interface HandlerOptions extends PortabilityOptions {
63
+ export interface HandlerOptions extends Omit<PortabilityOptions,'onExport'> {
53
64
  appOrigin:string;basePath?:string;maxBodyBytes?:number;
54
65
  authorize:(request:Request,context:{operation:'export'|'import'|'unknown';jobId:string|null})=>string|null|Promise<string|null>;
55
66
  }
@@ -11,12 +11,13 @@ export { readArchive, makePart, MAX_LINE_BYTES, MAX_PART_BYTES } from './format.
11
11
  export { canonicalJson, sha256 } from './hash.mjs';
12
12
  export { PortabilityError } from './storage.mjs';
13
13
  export { createPortabilityHandler } from './http.mjs';
14
- export async function createPortability({db,buckets={},policy:input,migrations}) {
14
+ export async function createPortability({db,buckets={},policy:input,migrations,onExport}) {
15
+ insist(onExport===undefined || typeof onExport==='function','invalid_on_export');
15
16
  db=wireDatabase(db);
16
17
  const config=policy(input);await catalogue(db,config);
17
18
  for(const name of Object.keys(config.buckets))insist(buckets[name] && typeof buckets[name].get==='function','missing_bucket:'+name);
18
19
  await ensureImportLeases(db);
19
- const context={db,buckets,config,migrations};
20
+ const context={db,buckets,config,migrations,onExport};
20
21
  return {
21
22
  exports:{create:actor=>createExport(context,actor),advance:(id,options)=>advanceExport(context,id,options),status:id=>exportStatus(context,id),download:id=>downloadExport(context,id),abort:id=>abortExport(context,id)},
22
23
  imports:{active:actor=>activeImport(context,actor),create:(manifest,actor,options={})=>createImport(context,manifest,actor,undefined,options.ledgers),uploadPart:(id,index,part)=>uploadPart(context,id,index,part),finalize:(id,options)=>finalizeImport(context,id,options),status:id=>importStatus(context,id),abort:id=>abortImport(context,id),abortAbandoned:()=>abortAbandonedImport(context)},
@@ -18,8 +18,12 @@ const partial=name=>name.includes('#');
18
18
 
19
19
  /** The destination's applied product migrations, [{name,sha256?}] in the ledger's own order, or undefined without a ledger. */
20
20
  export async function destinationLedger(db) {
21
+ return (await readLedger(db))?.entries;
22
+ }
23
+ /** The ledger table in use and its applied migrations, {table,entries}, or undefined without a ledger. */
24
+ export async function readLedger(db) {
21
25
  const found=(await all(db,`SELECT name FROM sqlite_master WHERE type='table' AND name IN (${ledgerNames.map(n=>`'${n}'`).join(',')})`)).map(x=>x.name);
22
- if(found.includes('_rer_deploy_migrations'))return (await all(db,"SELECT * FROM _rer_deploy_migrations WHERE state='applied' ORDER BY name")).map(entry);
26
+ if(found.includes('_rer_deploy_migrations'))return {table:'_rer_deploy_migrations',entries:(await all(db,"SELECT * FROM _rer_deploy_migrations WHERE state='applied' ORDER BY name")).map(entry)};
23
27
  if(found.includes('d1_migrations')) {
24
28
  const columns=(await all(db,'PRAGMA table_info(d1_migrations)')).map(x=>x.name);
25
29
  insist(['id','name','applied_at'].every(name=>columns.includes(name)),'schema_mismatch:migration_history',409);
@@ -29,7 +33,7 @@ export async function destinationLedger(db) {
29
33
  insist(rows.every(row=>typeof row.name==='string') && new Set(rows.map(row=>row.name)).size===rows.length,'schema_mismatch:migration_history',409);
30
34
  if(tracked)insist(rows.every(row=>row.state==='applied'),'schema_mismatch:uncertain_migrations',409);
31
35
  if(tracked)insist(rows.every(row=>typeof row.sha256==='string' && /^[a-f0-9]{64}$/.test(row.sha256)),'schema_mismatch:migration_history',409);
32
- return rows.map(entry);
36
+ return {table:'d1_migrations',entries:rows.map(entry)};
33
37
  }
34
38
  if(!found.includes('rer_migrations'))return;
35
39
  // Platform applies pending files in its plan's order and inserts each ledger
@@ -39,7 +43,7 @@ export async function destinationLedger(db) {
39
43
  const rows=await all(db,'SELECT name,sha256 FROM rer_migrations ORDER BY rowid');
40
44
  insist(rows.every(row=>typeof row.name==='string' && typeof row.sha256==='string' && /^[a-f0-9]{64}$/.test(row.sha256)) && new Set(rows.map(row=>row.name)).size===rows.length,'schema_mismatch:migration_history',409);
41
45
  insist(!rows.some(row=>partial(row.name)),'schema_mismatch:uncertain_migrations',409);
42
- return rows.map(entry);
46
+ return {table:'rer_migrations',entries:rows.map(entry)};
43
47
  }
44
48
  const entry=row=>({name:row.name,...(typeof row.sha256==='string'?{sha256:row.sha256}:{})});
45
49
 
@@ -67,6 +71,23 @@ export function matchMigrationLedger(entries,files,{dataOnly=[]}={}) {
67
71
  return matched;
68
72
  }
69
73
 
74
+ /**
75
+ * What an export records when its source was migrated by RER Platform:
76
+ * {origin:'rer_migrations',entries:[{name,sha256}]} in application order, each
77
+ * entry named by the checkout file with that hash (the native identity) where
78
+ * the exporter can read the checkout's files. Declared data-only entries and
79
+ * hosted exporters, which have no files, keep the ledger's own names. Native
80
+ * sources record nothing here, so their archives are unchanged.
81
+ */
82
+ export async function platformOrigin(ledger,migrations) {
83
+ if(ledger?.table!=='rer_migrations')return;
84
+ const replay=await migrations?.();
85
+ const files=replay?.names.map(name=>({name,sha256:replay.sha256?.(name),aliases:replay.aliases?.(name)}));
86
+ const entries=ledger.entries.map(({name,sha256})=>({name:files?(matchMigrationLedger([{name,sha256}],files,replay)[0]??name):name,sha256}));
87
+ insist(new Set(entries.map(entry=>entry.name)).size===entries.length,'migration_ledger:ambiguous',409);
88
+ return {origin:'rer_migrations',entries};
89
+ }
90
+
70
91
  /** The ledger tables an archive carries (old archives carried rer_migrations before it became bookkeeping). */
71
92
  export const archivedLedgerTables=manifest=>manifest.tables.filter(t=>ledgerNames.includes(identifier(t.name)));
72
93
 
@@ -96,7 +117,9 @@ export function checkArchivedLedgers(manifest,ledgers) {
96
117
  /** The applied migrations an archive's own ledger records, [{name,sha256?}]; undefined when it carries no ledger. */
97
118
  export function archivedHistory(manifest,ledgers) {
98
119
  const tables=archivedLedgerTables(manifest);
99
- if(!tables.length)return;
120
+ // A Platform-origin export records its ledger in the manifest, never as a table.
121
+ if(manifest.migrationLedger)insist(!tables.length,'schema_mismatch:migration_history');
122
+ if(!tables.length)return manifest.migrationLedger?.entries.map(entry);
100
123
  insist(tables.length===1 && ledgers?.[tables[0].name],'schema_mismatch:migration_history');
101
124
  const [table]=tables,rows=ledgers[table.name],columns=table.columns.map(c=>c.name);
102
125
  if(identifier(table.name)==='rer_migrations') {
@@ -0,0 +1,20 @@
1
+ import { all, quote, insist } from './storage.mjs';
2
+ // A referenced key stays in its bucket's namespace however a reader joins or
3
+ // resolves it: nonempty, under the declared prefix, not absolute and with no
4
+ // '.' or '..' segment.
5
+ const namespaced=(prefix,key)=>typeof key==='string' && key!=='' && key.startsWith(prefix) && !/^[\\/]/.test(key) && !key.split(/[\\/]/).some(part=>part==='.' || part==='..');
6
+ // Export checks its snapshot and restore its staged rows, before any object
7
+ // write: for every bucket that declares references, the distinct referenced keys
8
+ // lie in its namespace and are exactly its archived objects, none missing and
9
+ // none extra. A table restored across a later ADD COLUMN stages only archived
10
+ // columns; publication gives its rows the destination's default there.
11
+ export async function checkReferences({db,config},copies,objects) {
12
+ for(const [binding,spec] of Object.entries(config.buckets)) if(spec.objectReferences) {
13
+ const {table,keyColumn}=spec.objectReferences,copy=copies[table];
14
+ const column=async name=>(await all(db,`PRAGMA table_xinfo(${quote(name)})`)).find(c=>c.name===keyColumn);
15
+ const value=await column(copy)?quote(keyColumn):'('+((await column(table))?.dflt_value??'NULL')+')';
16
+ const keys=new Set((await all(db,`SELECT DISTINCT ${value} COLLATE BINARY AS key FROM ${quote(copy)} WHERE ${value} IS NOT NULL`)).map(x=>x.key));
17
+ const listed=objects.filter(x=>x.bucket===binding);
18
+ insist([...keys].every(key=>namespaced(spec.prefix??'',key)) && listed.length===keys.size && listed.every(x=>keys.has(x.key)),'object_references:'+binding);
19
+ }
20
+ }
@@ -0,0 +1,13 @@
1
+ import { canonicalTokens } from './sqlite-tokens.mjs';
2
+ import { canonicalJson, sha256 } from './hash.mjs';
3
+ export { rawSchemaIdentityOf } from './schema-legacy.mjs';
4
+
5
+ // Typed, lossless lexical identity. Only trivia and proven-safe keyword case
6
+ // are normalized; the same lexer proves every removed separator is harmless.
7
+ export const schemaSQL = sql => canonicalJson(canonicalTokens(sql));
8
+ const tableDefinitions = tables => tables.map(({ name, sql }) => ({ name, sql: schemaSQL(sql) }));
9
+ export const schemaIdentityOf = (tables, objects = []) => sha256(canonicalJson({
10
+ tables: tableDefinitions(tables),
11
+ objects: objects.map(({ name, type, table, sql }) => ({ name, type, table, sql: schemaSQL(sql) })),
12
+ }));
13
+ export const tableSchemaIdentityOf = tables => sha256(canonicalJson(tableDefinitions(tables)));
@@ -0,0 +1,21 @@
1
+ import { sqliteTokens } from './sqlite-tokens.mjs';
2
+ import { canonicalJson, sha256 } from './hash.mjs';
3
+
4
+ // Read-only wire codecs for 4280971d/537b088b/9352a46d checksums. These
5
+ // lossy representations authenticate historical manifests ONLY; they never
6
+ // decide whether two schemas match. All compatibility uses schemaIdentityOf.
7
+ function legacySQL(sql) {
8
+ return canonicalJson(sqliteTokens(sql).flatMap(token => {
9
+ if (token.type === 'blob') return [token.text[0], token.text.slice(1)];
10
+ if (token.type === 'quoted-identifier' || token.type === 'string') return [token.text];
11
+ return token.text.match(/[\p{L}\p{N}_$]+|->>|->|==|!=|<>|<=|>=|<<|>>|\|\||./gu);
12
+ }));
13
+ }
14
+ export const rawSchemaIdentityOf = tables => sha256(canonicalJson(tables.map(({name,sql}) => ({name,sql}))));
15
+ export async function legacySchemaIdentities(tables, objects = []) {
16
+ const definitions = tables.map(({name,sql}) => ({name,sql:legacySQL(sql)}));
17
+ return Promise.all([
18
+ sha256(canonicalJson(definitions)),
19
+ sha256(canonicalJson({tables:definitions,objects:objects.map(({name,type,table,sql}) => ({name,type,table,sql:legacySQL(sql)}))})),
20
+ ]);
21
+ }
@@ -0,0 +1,121 @@
1
+ import { insist } from './storage.mjs';
2
+
3
+ // SQLite's public-domain sqlite3GetToken (src/tokenize.c). Scan original
4
+ // characters once: never strip trivia before deciding where a token ends.
5
+ // Unknown or deliberately unsupported syntax is a schema refusal, not a token.
6
+ const digit = c => c !== undefined && c >= '0' && c <= '9';
7
+ const hex = c => digit(c) || (c !== undefined && ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')));
8
+ const letter = c => c !== undefined && ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
9
+ const id = c => letter(c) || digit(c) || c === '_' || c === '$' || (c !== undefined && c.charCodeAt(0) >= 128);
10
+ const space = c => c !== undefined && ' \t\n\f\r'.includes(c);
11
+ const refuse = () => insist(false, 'schema_mismatch:unsupported_sql', 409);
12
+ export const asciiFold = text => text.replace(/[A-Z]/g, c => c.toLowerCase());
13
+
14
+ // Only grammar-reserved keywords can be folded without parsing. SQLite's
15
+ // fallback/JOIN/window keywords can instead be identifiers or DEFAULT strings.
16
+ // Keep their original spelling, as well as every ordinary identifier.
17
+ const reserved = new Set(`add all alter and as autoincrement between case check collate commit constraint create default deferrable delete distinct drop else escape exists foreign from group having in index insert intersect into is isnull join limit not notnull null on or order primary references returning select set table then to transaction union unique update using values when where`.split(' '));
18
+ const keywords = new Set(`abort action add after all alter always analyze and as asc attach autoincrement before begin between by cascade case cast check collate column commit conflict constraint create cross current current_date current_time current_timestamp database default deferrable deferred delete desc detach distinct do drop each else end escape except exclude exclusive exists explain fail filter first following for foreign from full generated glob group groups having if ignore immediate in index indexed initially inner insert instead intersect into is isnull join key last left like limit match materialized natural no not nothing notnull null nulls of offset on or order others outer over partition plan pragma preceding primary query raise range recursive references regexp reindex release rename replace restrict returning right rollback row rows savepoint select set table temp temporary then ties to transaction trigger unbounded union unique update using vacuum values view virtual when where window with without`.split(' '));
19
+ const operators = new Set(['||','->','->>','<=','>=','<>','!=','<<','>>','==']);
20
+
21
+ function digits(sql, at, accepts) {
22
+ let i = at;
23
+ while (accepts(sql[i]) || sql[i] === '_') {
24
+ if (sql[i] === '_' && (!accepts(sql[i-1]) || !accepts(sql[i+1]))) refuse();
25
+ i++;
26
+ }
27
+ return i;
28
+ }
29
+ function number(sql, start) {
30
+ let i = start, type = 'integer';
31
+ if (sql[i] === '0' && ['x','X'].includes(sql[i+1]) && hex(sql[i+2])) {
32
+ i = digits(sql, i+2, hex); type = 'hex';
33
+ } else {
34
+ i = digits(sql, i, digit);
35
+ if (sql[i] === '.') { type = 'float'; i = digits(sql, i+1, digit); }
36
+ if (['e','E'].includes(sql[i])) {
37
+ type = 'float'; i++;
38
+ if (['+','-'].includes(sql[i])) i++;
39
+ if (!digit(sql[i])) refuse();
40
+ i = digits(sql, i, digit);
41
+ }
42
+ }
43
+ if (id(sql[i])) refuse();
44
+ return { end: i, type };
45
+ }
46
+ function variable(sql, start) {
47
+ let i = start+1, count = 0;
48
+ if (sql[start] === '?') { while (digit(sql[i])) i++; return i; }
49
+ while (i < sql.length) {
50
+ if (id(sql[i])) { count++; i++; }
51
+ else if (sql.startsWith('::', i)) i += 2;
52
+ else if (sql[i] === '(' && count) {
53
+ i++;
54
+ while (i < sql.length && !space(sql[i]) && sql[i] !== '\v' && sql[i] !== ')') i++;
55
+ if (sql[i] !== ')') refuse();
56
+ i++; break;
57
+ } else break;
58
+ }
59
+ if (!count) refuse();
60
+ return i;
61
+ }
62
+ export function sqliteTokens(sql, { trivia = false } = {}) {
63
+ if (typeof sql !== 'string' || sql.includes('\0') || !sql.isWellFormed()) refuse();
64
+ const result = [];
65
+ for (let i = 0; i < sql.length;) {
66
+ const start = i, c = sql[i]; let type;
67
+ if (space(c)) { while (space(sql[i])) i++; type = 'space'; }
68
+ else if (c === '\v' || c === '\ufeff') refuse();
69
+ else if (sql.startsWith('--', i)) { i = sql.indexOf('\n', i+2); if (i < 0) i = sql.length; type = 'comment'; }
70
+ else if (sql.startsWith('/*', i)) {
71
+ const end = sql.indexOf('*/', i+2); if (end < 0) refuse();
72
+ i = end+2; type = 'comment';
73
+ } else if ((c === 'x' || c === 'X') && sql[i+1] === "'") {
74
+ i += 2; const first = i;
75
+ while (hex(sql[i])) i++;
76
+ if (sql[i] !== "'" || (i-first)%2) refuse();
77
+ i++; type = 'blob';
78
+ } else if ('\'"`['.includes(c)) {
79
+ const close = c === '[' ? ']' : c; i++; let closed = false;
80
+ while (i < sql.length) {
81
+ if (sql[i++] !== close) continue;
82
+ if (c !== '[' && sql[i] === close) { i++; continue; }
83
+ closed = true; break;
84
+ }
85
+ if (!closed) refuse();
86
+ type = c === "'" ? 'string' : 'quoted-identifier';
87
+ } else if (digit(c) || (c === '.' && digit(sql[i+1]))) {
88
+ const numeric = number(sql, i); i = numeric.end; type = numeric.type;
89
+ } else if ('?@:$#'.includes(c)) { i = variable(sql, i); type = 'variable'; }
90
+ else if (letter(c) || c === '_' || c.charCodeAt(0) >= 128) {
91
+ while (id(sql[++i])) { /* longest identifier */ }
92
+ type = keywords.has(asciiFold(sql.slice(start,i))) ? 'keyword' : 'identifier';
93
+ } else {
94
+ const three = sql.slice(i,i+3), two = sql.slice(i,i+2);
95
+ if (operators.has(three)) i += 3;
96
+ else if (operators.has(two)) i += 2;
97
+ else if ('+-*/%<>=&|~();,.'.includes(c)) i++;
98
+ else refuse();
99
+ type = 'operator';
100
+ }
101
+ const text = sql.slice(start,i);
102
+ if (trivia || (type !== 'space' && type !== 'comment')) result.push({type,text,start,end:i,
103
+ value:type === 'keyword' && reserved.has(asciiFold(text)) ? asciiFold(text) : text});
104
+ }
105
+ return result;
106
+ }
107
+ const spelling = list => JSON.stringify(list.map(({type,text}) => [type,text]));
108
+ // One lexer defines the boundary rule, including comment creation, doubled
109
+ // quotes, numeric prefixes, variables and longest-match operators.
110
+ export function significantBoundary(left, right) {
111
+ try { return spelling(sqliteTokens(left.text+right.text)) !== spelling([left,right]); }
112
+ catch { return true; }
113
+ }
114
+ export function canonicalTokens(sql) {
115
+ const tokens = sqliteTokens(sql), canonical = tokens.map(t => ({...t,text:t.value}));
116
+ const joined = canonical.map((t,i) => (i && significantBoundary(canonical[i-1],t) ? ' ' : '')+t.text).join('');
117
+ // Check the entire stream too: a lookahead spanning more than one boundary
118
+ // must never silently collapse. Unsupported cases refuse at the public door.
119
+ if (spelling(sqliteTokens(joined)) !== spelling(canonical)) refuse();
120
+ return {tokens:tokens.map(({type,value}) => [type,value]),sql:joined};
121
+ }
@@ -63,11 +63,19 @@ For a GitHub source, the producer uses the operator's existing `gh` authenticati
63
63
  to resolve the source repository's **Verify** workflow for the exact selected
64
64
  commit. The source identity comes from its GitHub `origin` (HTTPS or SSH), or the
65
65
  committed `rer-project.json.sourceRepository` when no GitHub origin is present;
66
- it is independent of the publication destination. Only a completed successful
67
- `push` or `workflow_dispatch` run on the default branch or the version's release
68
- tag qualifies. The run and head repository must both match the source repository,
69
- and a release tag must resolve remotely to the exact source commit. PR merge runs,
70
- other SHAs, repositories, branches and unsuccessful runs cannot authorize release.
66
+ it is independent of the publication destination. A completed successful run of
67
+ the selected workflow qualifies when its `head_sha` equals the source commit
68
+ exactly, both `repository.full_name` and `head_repository.full_name` match the
69
+ source repository, and its event is `push` or `workflow_dispatch`. Any branch
70
+ of that repository can qualify. These events run that commit's own workflow
71
+ file on that commit's tree. Pull-request runs test a merge ref and cannot serve
72
+ as exact-SHA evidence, even for a same-repository PR. Fork runs and other events
73
+ cannot authorize release. A run on the version's release tag still requires
74
+ that tag to resolve remotely to the source commit. A failed tag lookup
75
+ disqualifies that tag run; a separate qualifying run can still authorize release.
76
+ When several runs qualify, the highest run ID is selected. Failed or unfinished
77
+ duplicates do not invalidate a qualifying success; the receipt records them as
78
+ informational entries, including their run identities and outcomes.
71
79
  `gates.verify` records the source repository and commit, `workflowId`,
72
80
  `workflowFile`, `workflowName`, `runId`,
73
81
  `runUrl`, event, branch and conclusion in both receipt and site provenance.
@@ -87,15 +95,18 @@ script, when declared, in a disposable clone. `gates.verify.install` and
87
95
  `gates.verify.build` record those local results; failure or a tracked-source
88
96
  mutation blocks release. Publication/history/annotation scans, exact-source
89
97
  packaging, package integrity checks and the separate signing commands still run
90
- locally. A missing green Verify blocks with the exact SHA and instructions to
91
- push or re-run it. API/authentication failures also block, without substituting
92
- local verification.
98
+ locally. A missing green Verify blocks with the exact SHA and the rejected run
99
+ details; an unfinished run is named. Push the exact commit to any branch of the
100
+ source repository and wait for its selected Verify workflow to complete
101
+ successfully. If the required GitHub evidence cannot be resolved, release
102
+ blocks without substituting local verification.
93
103
 
94
104
  Pass **`--local-verify`** to explicitly retain the previous behavior: frozen
95
105
  installation, `pnpm run verify`, then the committed `pnpm run verify:release`
96
106
  when declared, with its result in `gates.verify.release`. Sources without a
97
107
  GitHub origin or committed source identity also retain this behavior. This local
98
- path needs the seed's browser prerequisites and any resources its verification
108
+ path is appropriate only when the repository's verification policy permits it
109
+ and needs the seed's browser prerequisites and any resources its verification
99
110
  requires. Routine CI and default verification do not invoke the release-only
100
111
  script.
101
112
 
@@ -486,7 +497,10 @@ not a complete anchor set. On success the PKCS#8 private key goes to stdout
486
497
  only when stdout is not a terminal. Pipe it directly to the owner's vault;
487
498
  never send private key bytes to a terminal, repository, log or evidence. The
488
499
  signer accepts `--artifact DIR` and exactly one of `--key-file FILE` or
489
- `--key-stdin`, with `--scope test|rer` (default `rer`). Read production
500
+ `--key-stdin`, with `--scope test|rer` (default `rer`) and optional
501
+ `--publisher NAMESPACE`. Without `--publisher`, the signing publisher remains
502
+ the project ID prefix before `/`. Supply the flag when the authenticating
503
+ publisher differs from that prefix. Read production
490
504
  signing material from the vault through `--key-stdin`; `sign` never echoes it.
491
505
  `--key-stdin` refuses terminal input; pipe the key from a vault or file instead.
492
506
 
@@ -522,6 +536,69 @@ Base receipt check always requires a signature and refuses a missing envelope
522
536
  with `SIGNATURE_MISSING`, even where site or service consumers accept a legacy
523
537
  unsigned listing.
524
538
 
539
+ ### Anchor manifest versions and project authorization
540
+
541
+ An anchor manifest has exactly the top-level fields `schemaVersion`,
542
+ `environment`, `serial`, `legacyUnsigned` and `keys`. Schema version 2 requires
543
+ `schemaVersion: 2` and a `projects` array on **every** entry in `keys`. Each array
544
+ must contain 1–1024 unique, well-formed project IDs. There is no top-level
545
+ `projects` field. All other anchor fields retain their existing meanings:
546
+
547
+ - Each key requires `keyId`, `publicKey`, `publisher`, `githubOwner`, `notBefore`,
548
+ `notAfter`, `status`, `enrolment` and `review`, plus `projects` in version 2.
549
+ The existing optional fields are `retiredAt`, `compromisedAt` and
550
+ `keepStatements`, subject to the existing key-status rules.
551
+ - `githubOwner` contains exactly `login` and `id`. The enrolment envelope retains
552
+ exactly `payloadType`, `payload` and `signatures`, with exactly `keyid` and
553
+ `sig` on its single signature. Its signed claim retains exactly
554
+ `schemaVersion`, `keyId`, `publicKey`, `publisher`, `githubOwner`, `notBefore`,
555
+ `notAfter`, `issuedAt` and `unsignedThrough`.
556
+ - Unknown fields are refused at every level. Malformed manifests, including a
557
+ version 2 key without `projects`, are refused with `ANCHORS_INVALID`.
558
+
559
+ Project IDs use the verifier's existing `validProject` grammar: exactly
560
+ `OWNER`, a slash, and `NAME`, where `OWNER` matches `[a-z0-9][a-z0-9-]{0,38}` and `NAME` is a
561
+ nonempty printable ASCII component (U+0020–U+007E), excluding `/`, `\` and the
562
+ whole components `.` and `..`. Names remain literal and case-sensitive; this
563
+ change introduces no name-length limit. Arrays containing duplicates or invalid
564
+ IDs are invalid manifests.
565
+
566
+ For version 2, only the signing key's own `projects` array authorizes the
567
+ statement's project. Membership is exact and case-sensitive, with no prefix,
568
+ namespace, repository-name or other-key inference. A well-formed project absent
569
+ from that array is refused with `PUBLISHER_MISMATCH`; a statement with malformed
570
+ project grammar is refused with `STATEMENT_INVALID`. The statement's publisher
571
+ must still match the signing key's authenticated publisher.
572
+
573
+ Version 1 requires the explicit numeric `schemaVersion: 1` and preserves the
574
+ existing namespace checks and refusal behavior: the statement's project must
575
+ start with its publisher followed by `/`, and that publisher must match the
576
+ signing key. `projects` is invalid both at the top level and on a key in a
577
+ version 1 manifest. Omitting a version or adding `projects` never opts a version
578
+ 1 manifest into version 2.
579
+
580
+ This version change applies only to the anchor manifest. Release statements and
581
+ key-enrolment claims remain at `schemaVersion: 1`, with the same DSSE payload
582
+ types. Revocation and compromise handling, retirement, expiry and validity,
583
+ serial freshness, unsigned-version floors and environment/scope checks remain
584
+ unchanged. In particular, `projects` does not change the enrolment's
585
+ `unsignedThrough` or the manifest's `legacyUnsigned` policy.
586
+
587
+ For example, to sign project `octocat/hello-world` using a key whose publisher is
588
+ `just-every`, use:
589
+
590
+ ```sh
591
+ rer release sign --artifact /path/to/release --key-stdin --publisher just-every
592
+ ```
593
+
594
+ Pipe the signing key from the vault into that command as described above. Its
595
+ version 2 anchor must list `octocat/hello-world` in that key's `projects`. Verify with
596
+ `rer release receipt --artifact /path/to/release --anchors /path/to/anchors-v2.json`.
597
+ The receipt check matches the signed project, repository and files against the
598
+ artifact while authenticating the publisher through the anchor; it does not
599
+ infer the publisher from the project owner component. The signer's temporary self-proof anchor
600
+ manifest uses version 2 and lists exactly the one project being signed.
601
+
525
602
  The dependency-free verifier source is `modules/release/signature.mjs`; it has
526
603
  no `node:` imports and is exported as
527
604
  `@runeditrun/rer/modules/release/signature`. Its default-seed portable copy is
@@ -530,5 +607,11 @@ generated byte-for-byte at
530
607
  test vectors live in `modules/release/vectors/release-signature-vectors.json`
531
608
  and are generated byte-for-byte at
532
609
  `default-seed/scripts/base-cli/modules/release/vectors/release-signature-vectors.json`.
533
- The vectors use the existing public Octocat example repository context with synthetic bundle bytes and throwaway test keys; they do not represent an actual release.
610
+ The vectors use public Octocat and just-every repository contexts with synthetic
611
+ bundle bytes and throwaway test keys; they do not represent actual releases.
612
+ `vectors/publisher-projects.mjs` regenerates only the appended publisher-project
613
+ cases while preserving the historical v1 vector bytes.
534
614
  Consumers vendor and pin the verifier source by Base commit and SHA-256.
615
+ Site and Platform adoption must copy `signature.mjs` and the shared vectors
616
+ byte-for-byte and repin them to the landed Base commit. Migration of their
617
+ anchor manifests to version 2 is separate from that source adoption.
@@ -43,7 +43,7 @@ function tagCommit(repository, tag) {
43
43
  export function githubVerify(source, repository, selector) {
44
44
  const result = { status: 'FAIL', provider: 'github', repository, commit: source.commit,
45
45
  reason: 'github-verify-not-successful',
46
- message: `No successful Verify run exists for ${repository} at exact source commit ${source.commit}. Push this commit to the default branch or release tag, or re-run Verify for this SHA with workflow_dispatch. Use --local-verify to run verification locally.` };
46
+ message: `No successful Verify run exists for ${repository} at exact source commit ${source.commit}. To obtain qualifying evidence, push the exact commit to any branch of ${repository} and wait for its Verify run to complete successfully. Check the run details below. --local-verify runs local verification instead, only when the repository's verification policy permits it.` };
47
47
  try {
48
48
  const metadata = api(`repos/${repository}`);
49
49
  if (!same(metadata.full_name, repository) || typeof metadata.default_branch !== 'string' || !metadata.default_branch) throw Error('repository');
@@ -53,8 +53,8 @@ export function githubVerify(source, repository, selector) {
53
53
  if (selected.error) return { ...result, details: selected.error };
54
54
  const workflow = selected.workflow;
55
55
  Object.assign(result, { workflowId: workflow.id, workflowFile: workflow.path, workflowName: workflow.name });
56
- const rejected = new Set();
57
- let checkedTag = false, tagSHA;
56
+ const rejected = new Set(), successful = [], information = [];
57
+ let checkedTag = false, tagSHA, tagUnavailable = false;
58
58
  const runs = api(`repos/${repository}/actions/workflows/${workflow.id}/runs?head_sha=${source.commit}&per_page=100`, true)
59
59
  .flatMap(page => page.workflow_runs);
60
60
  for (const run of runs) {
@@ -64,21 +64,42 @@ export function githubVerify(source, repository, selector) {
64
64
  }
65
65
  if (run.workflow_id !== workflow.id) { rejected.add('different workflow'); continue; }
66
66
  if (!['push', 'workflow_dispatch'].includes(run.event)) { rejected.add('event must be push or workflow_dispatch'); continue; }
67
+ const evidence = { runId: run.id, runUrl: `https://github.com/${metadata.full_name}/actions/runs/${run.id}`,
68
+ event: run.event, branch: run.head_branch, conclusion: run.conclusion };
67
69
  if (run.status !== 'completed' || run.conclusion !== 'success') {
68
- rejected.add(run.status === 'completed' ? `conclusion ${['failure', 'cancelled', 'skipped', 'timed_out', 'neutral', 'action_required', 'stale'].includes(run.conclusion) ? run.conclusion : 'not success'}` : 'run not completed');
70
+ const reason = run.status === 'completed'
71
+ ? `conclusion ${['failure', 'cancelled', 'skipped', 'timed_out', 'neutral', 'action_required', 'stale'].includes(run.conclusion) ? run.conclusion : 'not success'}`
72
+ : `run not completed (${run.status})`;
73
+ rejected.add(`Run ${run.id} on ${run.head_branch} (${run.event}): ${reason}; ${evidence.runUrl}`);
74
+ information.push({ ...evidence, status: run.status,
75
+ message: `${reason}; does not invalidate a separate successful Verify run for this exact SHA.` });
69
76
  continue;
70
77
  }
71
- if (run.head_branch !== metadata.default_branch) {
72
- if (run.head_branch !== source.tag) { rejected.add('neither default branch nor release tag'); continue; }
73
- if (!checkedTag) { tagSHA = tagCommit(repository, source.tag); checkedTag = true; }
78
+ // A push or workflow_dispatch run for this exact SHA ran this commit's
79
+ // own workflow file on this commit's tree, regardless of branch. A
80
+ // pull_request run tests its merge ref and cannot provide that evidence.
81
+ if (run.head_branch === source.tag && run.head_branch !== metadata.default_branch) {
82
+ if (!checkedTag) {
83
+ checkedTag = true;
84
+ try { tagSHA = tagCommit(repository, source.tag); }
85
+ catch { tagUnavailable = true; }
86
+ }
87
+ // A tag lookup failure rejects this run, not independent branch evidence.
88
+ if (tagUnavailable) { rejected.add('release tag could not be resolved'); continue; }
74
89
  if (tagSHA !== source.commit) { rejected.add('release tag points at a different commit'); continue; }
75
90
  }
76
91
  if (!Number.isSafeInteger(run.id) || run.id <= 0) throw Error('run');
92
+ successful.push(evidence);
93
+ }
94
+ // API page order is not an authority: select the highest qualifying run ID.
95
+ successful.sort((left, right) => right.runId - left.runId);
96
+ information.sort((left, right) => right.runId - left.runId);
97
+ if (successful.length) {
77
98
  return { status: 'PASS', provider: 'github', repository: metadata.full_name, commit: source.commit,
78
99
  workflowId: workflow.id, workflowFile: workflow.path, workflowName: workflow.name,
79
- runId: run.id, runUrl: `https://github.com/${metadata.full_name}/actions/runs/${run.id}`,
80
- event: run.event, branch: run.head_branch, conclusion: run.conclusion };
100
+ ...successful[0], ...(information.length ? { information } : {}) };
81
101
  }
102
+ if (tagUnavailable) throw Error('tag');
82
103
  result.details = rejected.size ? [...rejected].join('; ') : 'No runs found for this SHA.';
83
104
  } catch {
84
105
  result.reason = 'github-verify-unavailable';
@@ -26,6 +26,7 @@ export async function signArtifact(options) {
26
26
  if (privateKey.asymmetricKeyType !== 'ed25519') throw new Error();
27
27
  } catch { refuse('SIGNATURE_INVALID'); }
28
28
  const artifact = await readArtifact(options.artifact);
29
+ if (options.publisher !== undefined) artifact.subject.publisher = options.publisher;
29
30
  const tag = artifact.receipt.tag;
30
31
  if (artifact.receipt.status !== 'RELEASED' || !(tag?.created === true ||
31
32
  (tag?.adopted === true && tag.object === artifact.subject.tagObject))) refuse('SUBJECT_MISMATCH');
@@ -34,9 +35,10 @@ export async function signArtifact(options) {
34
35
  // consumer still needs a separately reviewed anchor with the real owner ID.
35
36
  const entry = await publicEntry(privateKey, { scope, publisher: artifact.subject.publisher,
36
37
  githubOwner: { login: artifact.subject.repository.split('/')[3], id: 1 }, ...validity(new Date(issuedAt)), issuedAt });
37
- const anchors = anchorSet(entry, scope);
38
+ const anchors = { ...anchorSet(entry, scope), schemaVersion: 2,
39
+ keys: [{ ...entry, projects: [artifact.subject.project] }] };
38
40
  const loaded = await loadAnchors(anchors, anchors.environment);
39
- const statement = statementFor(artifact, entry.keyId, issuedAt);
41
+ const statement = statementFor(artifact, entry.keyId, issuedAt, anchors.schemaVersion);
40
42
  const bytes = Buffer.from(JSON.stringify(envelope(privateKey, entry.keyId, PAYLOAD_TYPE, statement)) + '\n');
41
43
  await verifyArtifact(artifact, loaded, anchors.environment, bytes);
42
44
  const target = resolve(artifact.root, SIGNATURE_FILE);