@runeditrun/rer 0.2.75 → 0.2.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/cli/README.md +55 -0
- package/cli/contract.mjs +1 -1
- package/cli/deploy-command.mjs +4 -2
- package/cli/deploy-inputs.mjs +15 -3
- package/cli/deploy-installation-key.mjs +71 -0
- package/cli/deploy-secrets.mjs +2 -0
- package/cli/deploy.mjs +13 -2
- package/cli/deployment-record.mjs +2 -0
- package/cli/listing.mjs +20 -0
- package/cli/main.mjs +2 -1
- package/cli/parse.mjs +5 -3
- package/cli/portability-migrations.mjs +46 -0
- package/cli/portability-worker.mjs +7 -20
- package/cli/portability.mjs +5 -4
- package/cli/runtime-front-door.mjs +1 -1
- package/cli/server-registry.mjs +43 -18
- package/cli/server-resources.mjs +38 -9
- package/global/CHANGELOG.md +14 -0
- package/global/README.md +7 -2
- package/global/launch/state.mjs +5 -4
- package/global/launch/stop.mjs +30 -8
- package/global/main.mjs +2 -1
- package/modules/dependencies/README.md +71 -1
- package/modules/dependencies/auth.mjs +4 -4
- package/modules/dependencies/crypto.mjs +6 -1
- package/modules/dependencies/custody.mjs +16 -0
- package/modules/dependencies/index.d.mts +1 -1
- package/modules/dependencies/index.mjs +6 -5
- package/modules/dependencies/schema/keys-sealed.sql +4 -0
- package/modules/dependencies/sealing.mjs +55 -0
- package/modules/dependencies/store.mjs +62 -9
- package/modules/deploy-kit/README.md +1 -0
- package/modules/deploy-kit/owner-cli.mjs +4 -2
- package/modules/deploy-kit/owner-rekey.mjs +69 -0
- package/modules/job-queue/command.mjs +8 -3
- package/modules/operator-auth/docs/native-accounts.md +4 -1
- package/modules/operator-auth/identity/oidc/aes-gcm.mjs +21 -0
- package/modules/operator-auth/identity/oidc/crypto.mjs +5 -12
- package/modules/operator-auth/index.d.mts +1 -1
- package/modules/portability/README.md +40 -11
- package/modules/portability/backfills.mjs +29 -16
- package/modules/portability/bridge.mjs +24 -29
- package/modules/portability/import.mjs +1 -2
- package/modules/portability/index.d.mts +1 -1
- package/modules/portability/ledgers.mjs +22 -0
- package/modules/portability/migration-history.mjs +2 -2
- package/modules/release/README.md +135 -3
- package/modules/release/catalogue.mjs +6 -2
- package/modules/release/listing.mjs +64 -0
- package/modules/release/look.mjs +26 -0
- package/modules/release/previous-listing.mjs +44 -0
- package/modules/release/produce.mjs +3 -0
- package/modules/release/screenshots.mjs +51 -0
- package/modules/release/signature.mjs +3 -2
- package/modules/release/source.mjs +19 -6
- package/modules/release/statement.mjs +8 -4
- package/onboarding/local/environment.mjs +2 -2
- package/onboarding/process-cleanup.mjs +5 -5
- package/onboarding/process-scope.mjs +1 -1
- package/onboarding/process-table.mjs +6 -4
- package/onboarding/process-tree.mjs +4 -4
- package/onboarding/schema/json-schema.mjs +4 -1
- package/package.json +1 -1
- package/scripts/publish-check/README.md +14 -0
- package/scripts/publish-check/assignment.py +48 -0
- package/scripts/publish-check/credential_assignments.mjs +75 -0
- package/scripts/publish-check/credential_assignments.py +70 -0
- package/scripts/publish-check/credential_literals.mjs +66 -0
- package/scripts/publish-check/credential_syntax.mjs +29 -0
- package/scripts/publish-check/env_values.py +14 -1
- package/scripts/publish-check/history_scan.py +9 -2
|
@@ -38,7 +38,7 @@ export interface Status {id:string;kind:'export'|'import';phase:'building'|'stag
|
|
|
38
38
|
/** Later additive migrations an older archive was restored across. */
|
|
39
39
|
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
40
|
/** A runner's replay of the destination's applied migrations: the archive schema identity after a chosen set, and each migration's statements. */
|
|
41
|
-
export interface MigrationReplay {names:string[];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>}
|
|
41
|
+
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
42
|
export interface PortabilityOptions {db:D1Database;buckets?:Record<string,R2Bucket>;policy:ArchivePolicy;migrations?:()=>Promise<MigrationReplay>}
|
|
43
43
|
export interface Portability {
|
|
44
44
|
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>};
|
|
@@ -39,6 +39,28 @@ export async function destinationLedger(db) {
|
|
|
39
39
|
}
|
|
40
40
|
const entry=row=>({name:row.name,...(typeof row.sha256==='string'?{sha256:row.sha256}:{})});
|
|
41
41
|
|
|
42
|
+
// Resolve ledger identities against the destination's own migration files.
|
|
43
|
+
// Hash-bearing entries must identify exactly one file; a coinciding name may
|
|
44
|
+
// confirm that file, but cannot point at another one. Hashless rows use exact
|
|
45
|
+
// names or seed-declared aliases. The caller keeps the destination replay order.
|
|
46
|
+
export function matchMigrationLedger(entries,files,{dataOnly=[]}={}) {
|
|
47
|
+
return entries.flatMap(m=>{
|
|
48
|
+
const named=files.filter(file=>file.name===m.name || file.aliases?.includes(m.name));
|
|
49
|
+
insist(named.length<=1,'migration_ledger:ambiguous:'+m.name,409);
|
|
50
|
+
if(m.sha256===undefined) {
|
|
51
|
+
if(!named.length && dataOnly.includes(m.name))return [];
|
|
52
|
+
insist(named.length,'migration_ledger:unknown:'+m.name,409);
|
|
53
|
+
return [named[0].name];
|
|
54
|
+
}
|
|
55
|
+
const matches=files.filter(file=>file.sha256===m.sha256);
|
|
56
|
+
if(!matches.length && !named.length && dataOnly.includes(m.name))return [];
|
|
57
|
+
insist(matches.length,'migration_ledger:unknown:'+m.name,409);
|
|
58
|
+
insist(matches.length===1,'migration_ledger:ambiguous:'+m.name,409);
|
|
59
|
+
insist(!named.length || named[0]===matches[0],'migration_ledger:conflict:'+m.name,409);
|
|
60
|
+
return [matches[0].name];
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
42
64
|
/** The ledger tables an archive carries (old archives carried rer_migrations before it became bookkeeping). */
|
|
43
65
|
export const archivedLedgerTables=manifest=>manifest.tables.filter(t=>ledgerNames.includes(identifier(t.name)));
|
|
44
66
|
|
|
@@ -6,9 +6,9 @@ import { policy, schemaIdentity } from './catalogue.mjs';
|
|
|
6
6
|
// Node runners only: restore uses it to place an older archive within the
|
|
7
7
|
// destination's history (see bridge.mjs). plan: [{name,statements,sha256?}],
|
|
8
8
|
// sha256 being the migration file's hash where the runner read the file.
|
|
9
|
-
export function migrationReplay(plan,input) {
|
|
9
|
+
export function migrationReplay(plan,input,{dataOnly=[]}={}) {
|
|
10
10
|
const config=policy(input);
|
|
11
|
-
return {names:plan.map(migration=>migration.name),statements:name=>plan.find(m=>m.name===name).statements,sha256:name=>plan.find(m=>m.name===name).sha256,async schemaAfter(names) {
|
|
11
|
+
return {names:plan.map(migration=>migration.name),dataOnly,aliases:name=>plan.find(m=>m.name===name).aliases,statements:name=>plan.find(m=>m.name===name).statements,sha256:name=>plan.find(m=>m.name===name).sha256,async schemaAfter(names) {
|
|
12
12
|
const scratch=new DatabaseSync(':memory:');
|
|
13
13
|
const db={prepare:sql=>{const query=scratch.prepare(sql);let values=[];return {bind(...args){values=args;return this;},async all(){return {results:query.all(...values)};}};}};
|
|
14
14
|
try {
|
|
@@ -123,7 +123,8 @@ metadata and Git blobs are never loaded as producer code.
|
|
|
123
123
|
|
|
124
124
|
With `--tag`, passing gates produce `public-source.tar`, containing the checked tree's
|
|
125
125
|
exact ordinary files without Git history, and a hash-pinned site bundle:
|
|
126
|
-
`site/<id>/<version>/release.json`, published documents and
|
|
126
|
+
`site/<id>/<version>/release.json`, published documents, listing assets and
|
|
127
|
+
`site/registry.json`.
|
|
127
128
|
Export attributes cannot silently omit or substitute bytes. The site metadata
|
|
128
129
|
comes from committed seed and contract data; no screenshots, install guarantees
|
|
129
130
|
or verified maturity claims are invented. Copy the reviewed bundle into the site
|
|
@@ -338,6 +339,135 @@ Generated source commits and annotated tags identify Run Edit Run with the
|
|
|
338
339
|
non-contact address `releases@runeditrun.invalid`. Provenance remains bound to
|
|
339
340
|
the source commit and tree; the Git author address is not a delivery destination.
|
|
340
341
|
|
|
342
|
+
## Listing metadata and assets
|
|
343
|
+
|
|
344
|
+
`rer release` adds `slug`, `homepage`, `headline`, `brand`, structured `shots`
|
|
345
|
+
and `look` to the existing `release.json` listing. All inputs come from the
|
|
346
|
+
selected committed tree. Asset paths are relative to the bundle directory:
|
|
347
|
+
`assets/seeds/<id>/mark.svg`, optional `mark-light.svg`, and screenshot filenames.
|
|
348
|
+
The slug is the repository name without its `run-` prefix; the asset directory
|
|
349
|
+
uses `seed.json.id`, which can differ from the slug.
|
|
350
|
+
|
|
351
|
+
To produce the same listing fields and asset bytes between releases:
|
|
352
|
+
|
|
353
|
+
```sh
|
|
354
|
+
rer listing --repo /path/to/seed --ref COMMIT_SHA --output /path/to/new-directory
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
This writes `listing.json` containing `slug`, `homepage`, `headline`, `brand`,
|
|
358
|
+
`shots` and `look`, plus the referenced files under `assets/seeds/<id>/`.
|
|
359
|
+
It reads the selected ref even with a dirty working tree. The output must be a
|
|
360
|
+
new directory outside the source. This command runs no release gates, creates
|
|
361
|
+
no tags and performs no signing. It needs a committed
|
|
362
|
+
`rer-project.json.sourceRepository` or a credential-free GitHub `origin` to
|
|
363
|
+
identify the repository. Previous-shot selection can read advertised remote tags.
|
|
364
|
+
|
|
365
|
+
### Seed author fields
|
|
366
|
+
|
|
367
|
+
| Committed input | Listing value and default |
|
|
368
|
+
| --- | --- |
|
|
369
|
+
| `seed.json.homepage` | `homepage`; optional, defaults to `https://run-<slug>.com`; credential-free HTTP(S) URL |
|
|
370
|
+
| `seed.json.headline` | `headline`; optional nonempty text, otherwise `null` |
|
|
371
|
+
| `seed.json.brand.mark` | SVG source path; defaults to `public/brand/mark.svg` |
|
|
372
|
+
| `seed.json.brand.markLight` | Optional SVG variant; defaults to `public/brand/mark-light.svg` when present |
|
|
373
|
+
| `src/branding.json` → `primaryColor` | `brand.colours.accent` |
|
|
374
|
+
| `public/rer-theme.css` → `--rer-text`, `--rer-page` | `brand.colours.ink`, `brand.colours.paper` |
|
|
375
|
+
|
|
376
|
+
Brand paths are repository-relative. An explicitly declared mark must exist and
|
|
377
|
+
contain SVG. Legacy seeds without a default mark emit `brand.mark: null`;
|
|
378
|
+
an absent default light variant emits `brand.markLight: null`. Missing branding
|
|
379
|
+
colours emit `null`. The producer copies the committed SVG bytes to the bundle's
|
|
380
|
+
standard mark filenames.
|
|
381
|
+
|
|
382
|
+
### Look fingerprints
|
|
383
|
+
|
|
384
|
+
`look.home` and `look.app` fingerprint these default glob arrays:
|
|
385
|
+
|
|
386
|
+
```json
|
|
387
|
+
{
|
|
388
|
+
"home": ["public/brand/**", "src/branding.json", "public/rer-theme.css", "public/fonts/**", "src/site/**", "!src/site/docs/**"],
|
|
389
|
+
"app": ["public/brand/**", "src/branding.json", "public/**/*.{css,js,mjs,html}", "src/ui/**", "src/**/*.css", "src/client/**"]
|
|
390
|
+
}
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
Declare `look.home` and/or `look.app` in committed `rer-project.json` to replace
|
|
394
|
+
the respective default array. An omitted array keeps its default. Patterns are
|
|
395
|
+
repository-relative; `!` patterns exclude any matching path regardless of array
|
|
396
|
+
order. Mark declarations do not implicitly add files to either glob set:
|
|
397
|
+
include nonstandard mark paths in the appropriate overrides.
|
|
398
|
+
|
|
399
|
+
For each set, the producer sorts matching committed blob paths in JavaScript
|
|
400
|
+
string order and hashes UTF-8 records of `path`, NUL, Git blob object ID, LF.
|
|
401
|
+
The result is `sha256:<hex>`. No browser or capture runs. With the defaults,
|
|
402
|
+
backend-only changes outside these sets leave both fingerprints unchanged;
|
|
403
|
+
homepage and app changes affect the sets covering their files.
|
|
404
|
+
|
|
405
|
+
### Release screenshots and reuse
|
|
406
|
+
|
|
407
|
+
Authors declare committed screenshots in `RELEASE.json`:
|
|
408
|
+
|
|
409
|
+
```json
|
|
410
|
+
{
|
|
411
|
+
"screenshots": [
|
|
412
|
+
{
|
|
413
|
+
"path": ".github/assets/release/01-issues.webp",
|
|
414
|
+
"alt": "Issue list with grouped errors",
|
|
415
|
+
"caption": "Group related errors and open an issue to investigate.",
|
|
416
|
+
"width": 1600,
|
|
417
|
+
"height": 1000
|
|
418
|
+
}
|
|
419
|
+
]
|
|
420
|
+
}
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
When supplied, the array must contain 1–5 still WebP files, each with nonempty
|
|
424
|
+
alt text and caption, encoded dimensions exactly 1600×1000 and size at most
|
|
425
|
+
300 KiB. Dimensions are checked in the image bytes as well as the declaration.
|
|
426
|
+
Source paths must be repository-relative, and filenames must be unique across
|
|
427
|
+
the set because the bundle keeps only each basename. The listing preserves
|
|
428
|
+
`path`, `alt`, `caption`, `width` and `height`, rewriting paths to
|
|
429
|
+
`assets/seeds/<id>/<filename>.webp`.
|
|
430
|
+
|
|
431
|
+
Screenshots remain optional for legacy releases. Without screenshots or reused
|
|
432
|
+
history, `shots` is `[]` and `look.shotsAt` is `null`. Missing screenshots and
|
|
433
|
+
stale screenshots are not release gates; malformed declared screenshots fail
|
|
434
|
+
input validation. A free-text screenshot note does not populate this array.
|
|
435
|
+
|
|
436
|
+
For reuse, the producer reads publicly advertised version tags (`vX.Y.Z`, including prereleases) from the
|
|
437
|
+
origin/destination remote, limited to versions at or below the selected version
|
|
438
|
+
and excluding tags targeting the selected commit. Local-only tags cannot supply
|
|
439
|
+
history. It processes prior tags in SemVer order, reading each tag's committed
|
|
440
|
+
`RELEASE.json` and shot bytes to preserve historical `shotsAt`:
|
|
441
|
+
|
|
442
|
+
- Unchanged `look.app` reuses the previous shots and their `shotsAt`.
|
|
443
|
+
- Changed `look.app` with the same source screenshot paths and bytes keeps the
|
|
444
|
+
previous shots and `shotsAt`, making stale shots visible as `shotsAt != app`.
|
|
445
|
+
Editing only alt text or captions cannot claim a fresh capture.
|
|
446
|
+
- A changed screenshot set with a changed app records `shotsAt = app` when
|
|
447
|
+
screenshots are present.
|
|
448
|
+
|
|
449
|
+
The producer does not capture images. The live homepage still is a separate sync
|
|
450
|
+
artifact and is not included in the signed release bundle.
|
|
451
|
+
|
|
452
|
+
### Adopting this in seed release work
|
|
453
|
+
|
|
454
|
+
Commit the seed fields, look overrides and structured screenshots before
|
|
455
|
+
selecting the release SHA. Release authors capture fresh demo-data app shots
|
|
456
|
+
when `look.app` changes; an unchanged app reuses its gallery. Use the listing
|
|
457
|
+
command to inspect fingerprints and packaged assets before release.
|
|
458
|
+
|
|
459
|
+
For Spool, set `seed.json.brand.mark` to `public/theme/spool-mark.svg` and extend
|
|
460
|
+
the `look.home` override to cover `public/theme/landing*`, `src/ui/landing/**`
|
|
461
|
+
and `public/theme/spool-mark.svg` alongside the relevant default patterns.
|
|
462
|
+
Because an override replaces its array, retain every default pattern still
|
|
463
|
+
needed. Include the theme mark in `look.app` too if it appears in the app.
|
|
464
|
+
|
|
465
|
+
The B6 release-template follow-up carries the completed bundle to
|
|
466
|
+
`~/.orchestrator/listings/bundles/<slug>/<version>/` and posts the `RELEASED`
|
|
467
|
+
line to the sync lane as well as the import lane. Look landings post `LOOK`
|
|
468
|
+
with the seed and commit. Those template/sync actions are separate from
|
|
469
|
+
`rer release` and `rer listing`; neither command edits or deploys a site.
|
|
470
|
+
|
|
341
471
|
## Signing and checking release receipts
|
|
342
472
|
|
|
343
473
|
`rer release keygen` creates a publisher key and its proof-of-possession anchor
|
|
@@ -366,8 +496,10 @@ as `rer-release.dsse.json` beside the receipt. The statement binds the public
|
|
|
366
496
|
repository, tag, commit, tree and tag object, and hashes `public-source.tar`,
|
|
367
497
|
`release-receipt.json`, `publish-check.json`, the bundle's single
|
|
368
498
|
`site/<id>/<version>/release.json`, and every document under that bundle's
|
|
369
|
-
`documents/` directory
|
|
370
|
-
|
|
499
|
+
`documents/` directory, plus the listing's referenced mark, light mark and
|
|
500
|
+
screenshot files under `assets/seeds/<id>/`. Signing and receipt verification
|
|
501
|
+
check those asset hashes against the actual bytes. The envelope is an artifact
|
|
502
|
+
file; signing does not change the existing release or registry pins.
|
|
371
503
|
|
|
372
504
|
After writing the signature, `sign` prints (but never runs) a shell-quoted
|
|
373
505
|
`gh release upload` command for attaching `rer-release.dsse.json` to the
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { resolve, dirname } from 'node:path';
|
|
4
|
+
import { listingContent } from './listing.mjs';
|
|
4
5
|
import { parseContract } from '../../foundation/runtime/seed-contract.mjs';
|
|
5
6
|
|
|
6
7
|
export const sha256 = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
@@ -30,13 +31,15 @@ export function catalogue(source, project, repository, gates, dryRun) {
|
|
|
30
31
|
const docs = ['seed.json', 'CONTRACT.md', 'AGENTS.md', 'LICENSE', 'RELEASE.json',
|
|
31
32
|
...['README.md', 'BASELINE.md', 'OPERATIONS.md', 'ACCEPTANCE.md'].filter(path => source.entries.has(path))];
|
|
32
33
|
const artifacts = docs.map(path => ({ path: `documents/${path}`, target: `agents/seeds/${s.id}/${path}`, sha256: sha256(source.bytes(path)) }));
|
|
34
|
+
const content = source.listingContent ?? listingContent(source, repository);
|
|
35
|
+
artifacts.push(...content.assets.map(asset => ({ path: asset.path, target: asset.path, sha256: sha256(asset.bytes) })));
|
|
33
36
|
const listing = { id: s.id, name: s.name, licence: 'MIT', repository, category: s.category,
|
|
34
37
|
categoryLabel: s.categoryLabel ?? s.category, version: s.version, oneLiner: s.description,
|
|
35
38
|
summary: s.description, maturity: s.maturity, replaces: s.replaces ?? [], clauses: contract,
|
|
36
39
|
clauseCount: contract.length, nonGoals: s.nonGoals ?? [], externals: (s.externals ?? []).map(e => ({
|
|
37
40
|
name: e.name ?? e.id, reason: e.reason ?? e.why, required: e.required, data: e.data ?? [], adapters: e.adapters ?? [],
|
|
38
41
|
})), extensionPoints: Array.isArray(s.extensionPoints) ? s.extensionPoints : Object.values(s.extensionPoints ?? {}).flat(),
|
|
39
|
-
|
|
42
|
+
...content.listing, landing: null, hasReadme: docs.includes('README.md'), hasBaseline: docs.includes('BASELINE.md'), manifestFile: 'seed.json' };
|
|
40
43
|
for (const key of ['scope', 'spine', 'composition', 'operatingCost', 'limits', 'accessibility']) if (s[key] !== undefined) listing[key] = s[key];
|
|
41
44
|
return { schemaVersion: 1, project, release: s.version, provenance: {
|
|
42
45
|
kind: dryRun ? 'release-preview' : 'publisher-release', repository, revision: source.commit, tree: source.tree,
|
|
@@ -50,10 +53,11 @@ export function catalogue(source, project, repository, gates, dryRun) {
|
|
|
50
53
|
|
|
51
54
|
export function writeCatalogue(source, output, manifest) {
|
|
52
55
|
const directory = resolve(output, 'site', source.seed.id, source.seed.version);
|
|
56
|
+
const assets = new Map((source.listingContent ?? listingContent(source, manifest.listing.repository)).assets.map(asset => [asset.path, asset.bytes]));
|
|
53
57
|
for (const artifact of manifest.artifacts) {
|
|
54
58
|
const path = resolve(directory, artifact.path);
|
|
55
59
|
mkdirSync(dirname(path), { recursive: true });
|
|
56
|
-
writeFileSync(path, source.bytes(artifact.path.slice('documents/'.length)), { flag: 'wx' });
|
|
60
|
+
writeFileSync(path, artifact.path.startsWith('documents/') ? source.bytes(artifact.path.slice('documents/'.length)) : assets.get(artifact.path), { flag: 'wx' });
|
|
57
61
|
}
|
|
58
62
|
const bytes = json(manifest);
|
|
59
63
|
const releasePath = `${source.seed.id}/${source.seed.version}/release.json`;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync, rmSync } from 'node:fs';
|
|
2
|
+
import { resolve, dirname } from 'node:path';
|
|
3
|
+
import { lookFingerprints } from './look.mjs';
|
|
4
|
+
import { screenshotSet } from './screenshots.mjs';
|
|
5
|
+
import { validRelativePath } from './signature.mjs';
|
|
6
|
+
import { committedSource, git, newOutput } from './source.mjs';
|
|
7
|
+
|
|
8
|
+
function projectFile(source) {
|
|
9
|
+
return source.entries.has('rer-project.json') ? JSON.parse(source.bytes('rer-project.json')) : {};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function listingRepository(source) {
|
|
13
|
+
const declared = projectFile(source).sourceRepository;
|
|
14
|
+
if (declared) return declared;
|
|
15
|
+
const remote = git(source.repo, 'remote').toString().split('\n').includes('origin') ? git(source.repo, 'remote', 'get-url', 'origin').toString().trim() : '';
|
|
16
|
+
const match = /^(?:https:\/\/github\.com\/|git@github\.com:)([\w.-]+\/[\w.-]+?)(?:\.git)?$/.exec(remote);
|
|
17
|
+
if (!match) throw Error('Listing needs rer-project.json sourceRepository or a credential-free GitHub origin');
|
|
18
|
+
return `https://github.com/${match[1]}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function listingContent(source, repository, previous = null) {
|
|
22
|
+
const seed = source.seed, slug = repository.replace(/\.git$/, '').split('/').at(-1).toLowerCase().replace(/^run-/, '');
|
|
23
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug) || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(seed.id)) throw Error('Invalid listing slug or ID');
|
|
24
|
+
const homepage = seed.homepage ?? `https://run-${slug}.com`;
|
|
25
|
+
const url = new URL(homepage);
|
|
26
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password) throw Error('Listing homepage must be a credential-free HTTP URL');
|
|
27
|
+
if (seed.headline !== undefined && (typeof seed.headline !== 'string' || !seed.headline.trim())) throw Error('Listing headline must be nonempty text');
|
|
28
|
+
const assets = [];
|
|
29
|
+
const mark = (key, fallback, name) => {
|
|
30
|
+
const path = seed.brand?.[key] ?? fallback;
|
|
31
|
+
if (!validRelativePath(path)) throw Error('Brand mark must be a repository-relative path');
|
|
32
|
+
if (!source.entries.has(path) && seed.brand?.[key] === undefined) return null;
|
|
33
|
+
const bytes = source.bytes(path);
|
|
34
|
+
if (!path.endsWith('.svg') || !/<svg[\s/>]/.test(bytes.toString())) throw Error('Brand mark must be SVG');
|
|
35
|
+
const target = `assets/seeds/${seed.id}/${name}`;
|
|
36
|
+
assets.push({ path: target, bytes });
|
|
37
|
+
return target;
|
|
38
|
+
};
|
|
39
|
+
const css = source.entries.has('public/rer-theme.css') ? source.bytes('public/rer-theme.css').toString().replace(/\/\*[\s\S]*?\*\//g, '') : '';
|
|
40
|
+
const token = name => new RegExp(`--rer-${name}\\s*:\\s*([^;}]+)`).exec(css)?.[1].trim() ?? null;
|
|
41
|
+
const branding = source.entries.has('src/branding.json') ? JSON.parse(source.bytes('src/branding.json')) : {};
|
|
42
|
+
const brand = { mark: mark('mark', 'public/brand/mark.svg', 'mark.svg'), markLight: mark('markLight', 'public/brand/mark-light.svg', 'mark-light.svg'),
|
|
43
|
+
colours: { accent: branding.primaryColor ?? null, ink: token('text'), paper: token('page') } };
|
|
44
|
+
const look = lookFingerprints(source), current = screenshotSet(source, seed.id);
|
|
45
|
+
const selected = previous?.listing.shots.length && (previous.listing.look.app === look.app || (current.identity && current.identity === previous.shotIdentity)) ? previous : null;
|
|
46
|
+
const shots = selected ? selected.listing.shots : current.shots;
|
|
47
|
+
assets.push(...(selected ? selected.shotAssets : current.assets));
|
|
48
|
+
return { listing: { slug, homepage, headline: seed.headline ?? null, brand, shots, look: { ...look, shotsAt: selected ? selected.listing.look.shotsAt : shots.length ? look.app : null } },
|
|
49
|
+
assets, shotAssets: selected ? selected.shotAssets : current.assets, shotIdentity: selected ? selected.shotIdentity : current.identity };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function writeListing({ repo, ref = 'HEAD', output }, previousReader) {
|
|
53
|
+
const hydrateFrom = git(repo, 'remote').toString().split('\n').includes('origin') ? git(repo, 'remote', 'get-url', 'origin').toString().trim() : undefined;
|
|
54
|
+
const source = committedSource(repo, ref, { hydrateFrom }), repository = listingRepository(source);
|
|
55
|
+
const content = listingContent(source, repository, previousReader(source, repository));
|
|
56
|
+
output = newOutput(source.repo, output);
|
|
57
|
+
try {
|
|
58
|
+
for (const asset of content.assets) {
|
|
59
|
+
const target = resolve(output, asset.path); mkdirSync(dirname(target), { recursive: true }); writeFileSync(target, asset.bytes, { flag: 'wx' });
|
|
60
|
+
}
|
|
61
|
+
writeFileSync(resolve(output, 'listing.json'), JSON.stringify(content.listing, null, 2) + '\n', { flag: 'wx' });
|
|
62
|
+
} catch (error) { rmSync(output, { recursive: true, force: true }); throw error; }
|
|
63
|
+
return { path: resolve(output, 'listing.json'), revision: source.commit, listing: content.listing };
|
|
64
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { matchesGlob } from 'node:path';
|
|
3
|
+
|
|
4
|
+
export const defaultLook = Object.freeze({
|
|
5
|
+
home: ['public/brand/**', 'src/branding.json', 'public/rer-theme.css', 'public/fonts/**', 'src/site/**', '!src/site/docs/**'],
|
|
6
|
+
app: ['public/brand/**', 'src/branding.json', 'public/**/*.{css,js,mjs,html}', 'src/ui/**', 'src/**/*.css', 'src/client/**'],
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export function lookFingerprints(source) {
|
|
10
|
+
const declared = source.entries.has('rer-project.json') ? JSON.parse(source.bytes('rer-project.json')).look : undefined;
|
|
11
|
+
if (declared !== undefined && (!declared || typeof declared !== 'object' || Array.isArray(declared) || Object.keys(declared).some(key => !['home', 'app'].includes(key))))
|
|
12
|
+
throw Error('rer-project.json look must declare home and/or app glob arrays');
|
|
13
|
+
return Object.fromEntries(['home', 'app'].map(kind => {
|
|
14
|
+
const globs = declared?.[kind] ?? defaultLook[kind];
|
|
15
|
+
if (!Array.isArray(globs) || !globs.every(glob => typeof glob === 'string' && glob.replace(/^!/, '') && !/[\\\0\r\n]/.test(glob) && !glob.replace(/^!/, '').startsWith('/') && !glob.split('/').includes('..')))
|
|
16
|
+
throw Error('Look globs must be repository-relative patterns');
|
|
17
|
+
const includes = globs.filter(glob => !glob.startsWith('!')), excludes = globs.filter(glob => glob.startsWith('!')).map(glob => glob.slice(1));
|
|
18
|
+
const hash = createHash('sha256');
|
|
19
|
+
for (const path of [...source.entries.keys()].sort()) {
|
|
20
|
+
const entry = source.entries.get(path);
|
|
21
|
+
if (entry.type === 'blob' && includes.some(glob => matchesGlob(path, glob)) && !excludes.some(glob => matchesGlob(path, glob)))
|
|
22
|
+
hash.update(`${path}\0${entry.oid}\n`);
|
|
23
|
+
}
|
|
24
|
+
return [kind, `sha256:${hash.digest('hex')}`];
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { committedSource, git } from './source.mjs';
|
|
2
|
+
import { listingContent } from './listing.mjs';
|
|
3
|
+
|
|
4
|
+
const order = (a, b) => a === b ? 0 : a < b ? -1 : 1;
|
|
5
|
+
function version(value) {
|
|
6
|
+
const match = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?$/.exec(value);
|
|
7
|
+
return match ? { core: match.slice(1, 4).map(BigInt), pre: match[4]?.split('.') ?? [] } : null;
|
|
8
|
+
}
|
|
9
|
+
function compare(a, b) {
|
|
10
|
+
for (let i = 0; i < 3; i++) if (a.core[i] !== b.core[i]) return order(a.core[i], b.core[i]);
|
|
11
|
+
if (!a.pre.length || !b.pre.length) return order(Boolean(b.pre.length), Boolean(a.pre.length));
|
|
12
|
+
for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
|
|
13
|
+
const x = a.pre[i], y = b.pre[i];
|
|
14
|
+
if (x === undefined || y === undefined) return order(a.pre.length, b.pre.length);
|
|
15
|
+
if (x === y) continue;
|
|
16
|
+
const nx = /^\d+$/.test(x), ny = /^\d+$/.test(y);
|
|
17
|
+
return nx && ny ? order(BigInt(x), BigInt(y)) : nx !== ny ? (nx ? -1 : 1) : order(x, y);
|
|
18
|
+
}
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Only advertised tags count. A scratch/local tag can never claim that stale
|
|
23
|
+
// pictures were public. The selected ref's own release tag is excluded.
|
|
24
|
+
export function previousListing(source, repository) {
|
|
25
|
+
if (!source.repo || !git(source.repo, 'remote').toString().split('\n').includes('origin')) return null;
|
|
26
|
+
const origin = git(source.repo, 'remote', 'get-url', 'origin').toString().trim();
|
|
27
|
+
const remote = /^(?:https:\/\/github\.com\/|git@github\.com:)/.test(origin) ? repository : origin;
|
|
28
|
+
const current = version(source.seed.version);
|
|
29
|
+
if (!current) return null;
|
|
30
|
+
const records = git(source.repo, 'ls-remote', '--tags', remote, 'refs/tags/v*').toString().trim().split('\n').filter(Boolean);
|
|
31
|
+
const refs = new Map(records.map(record => record.split('\t').reverse()));
|
|
32
|
+
const tags = [...refs].filter(([ref]) => !ref.endsWith('^{}')).map(([ref, oid]) => ({ ref, oid, commit: refs.get(ref + '^{}') ?? oid, version: version(ref.slice('refs/tags/'.length)) }))
|
|
33
|
+
.filter(tag => tag.version && compare(tag.version, current) <= 0 && tag.commit !== source.commit)
|
|
34
|
+
.sort((a, b) => compare(a.version, b.version));
|
|
35
|
+
let previous = null;
|
|
36
|
+
for (const tag of tags) {
|
|
37
|
+
// Fetch the advertised object by ID, without changing local tag refs.
|
|
38
|
+
try { git(source.repo, 'cat-file', '-e', `${tag.commit}^{commit}`); }
|
|
39
|
+
catch { git(source.repo, 'fetch', '--no-tags', '--filter=blob:none', remote, tag.oid); }
|
|
40
|
+
const prior = committedSource(source.repo, tag.commit, { hydrateFrom: remote });
|
|
41
|
+
previous = listingContent(prior, repository, previous);
|
|
42
|
+
}
|
|
43
|
+
return previous;
|
|
44
|
+
}
|
|
@@ -11,6 +11,8 @@ import { writePublishHandoff } from './publish-handoff.mjs';
|
|
|
11
11
|
import { releasePublicBase } from './public-base.mjs';
|
|
12
12
|
import { prepareTagAdoption, confirmTagAdoption, assertTagAdoption } from './tag-adoption.mjs';
|
|
13
13
|
import { placeholderMarks, placeholderMessage } from '../../cli/placeholder-mark.mjs';
|
|
14
|
+
import { listingContent } from './listing.mjs';
|
|
15
|
+
import { previousListing } from './previous-listing.mjs';
|
|
14
16
|
import { cleanupTemporary } from './cleanup.mjs';
|
|
15
17
|
import { parseTimeoutSeconds } from '../../scripts/publish-check/timeout.mjs';
|
|
16
18
|
|
|
@@ -37,6 +39,7 @@ export async function release({ repo, ref = 'HEAD', output, project, repository,
|
|
|
37
39
|
if (typeof tag === 'string' && tag !== source.tag) throw Error('Requested tag must match the committed release version');
|
|
38
40
|
const existing = git(source.repo, 'tag', '--list', source.tag).toString().trim();
|
|
39
41
|
if (existing && tag && !dryRun && (onto !== undefined || clean)) throw Error('Release tag already exists; choose a new committed version');
|
|
42
|
+
source.listingContent = listingContent(source, repository, previousListing(source, repository));
|
|
40
43
|
// Validate metadata before installs or output writes.
|
|
41
44
|
catalogue(source, project, repository, { verify: { status: 'PENDING' }, publishCheck: { status: 'PENDING' } }, preview);
|
|
42
45
|
const destination = onto !== undefined ? publicDestination(onto, repository, source.repo) : null;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { validRelativePath } from './signature.mjs';
|
|
4
|
+
|
|
5
|
+
// Inspect the WebP container and encoded image dimensions, not its extension or
|
|
6
|
+
// the author's width/height claim. No image decoder or browser is required.
|
|
7
|
+
function webpSize(bytes) {
|
|
8
|
+
if (bytes.length < 20 || bytes.toString('ascii', 0, 4) !== 'RIFF' || bytes.toString('ascii', 8, 12) !== 'WEBP' || bytes.readUInt32LE(4) + 8 !== bytes.length)
|
|
9
|
+
throw Error('Screenshot must be a complete WebP image');
|
|
10
|
+
let canvas, image;
|
|
11
|
+
for (let offset = 12; offset < bytes.length;) {
|
|
12
|
+
if (offset + 8 > bytes.length) throw Error('Invalid WebP chunk');
|
|
13
|
+
const type = bytes.toString('ascii', offset, offset + 4), size = bytes.readUInt32LE(offset + 4), start = offset + 8;
|
|
14
|
+
if (start + size + (size & 1) > bytes.length) throw Error('Invalid WebP chunk length');
|
|
15
|
+
if (type === 'VP8X' && size === 10) {
|
|
16
|
+
if (bytes[start] & 2) throw Error('Screenshot WebP must be a still image');
|
|
17
|
+
canvas = [1 + bytes.readUIntLE(start + 4, 3), 1 + bytes.readUIntLE(start + 7, 3)];
|
|
18
|
+
} else if (type === 'VP8 ' && size >= 10 && bytes.subarray(start + 3, start + 6).equals(Buffer.from([0x9d, 0x01, 0x2a]))) {
|
|
19
|
+
image = [bytes.readUInt16LE(start + 6) & 0x3fff, bytes.readUInt16LE(start + 8) & 0x3fff];
|
|
20
|
+
} else if (type === 'VP8L' && size >= 5 && bytes[start] === 0x2f) {
|
|
21
|
+
const bits = bytes.readUInt32LE(start + 1);
|
|
22
|
+
image = [(bits & 0x3fff) + 1, ((bits >>> 14) & 0x3fff) + 1];
|
|
23
|
+
}
|
|
24
|
+
offset = start + size + (size & 1);
|
|
25
|
+
}
|
|
26
|
+
if (!image || (canvas && (canvas[0] !== image[0] || canvas[1] !== image[1]))) throw Error('Invalid WebP image dimensions');
|
|
27
|
+
return image;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function screenshotSet(source, id) {
|
|
31
|
+
const screenshots = source.release?.screenshots;
|
|
32
|
+
if (screenshots === undefined) return { shots: [], assets: [], identity: null };
|
|
33
|
+
if (!Array.isArray(screenshots) || screenshots.length < 1 || screenshots.length > 5) throw Error('RELEASE.json screenshots requires 1–5 images');
|
|
34
|
+
const paths = new Set(), assets = [];
|
|
35
|
+
const shots = screenshots.map(shot => {
|
|
36
|
+
if (!validRelativePath(shot?.path) || !shot.path.endsWith('.webp') || !['alt', 'caption'].every(key => typeof shot[key] === 'string' && shot[key].trim()) || shot.width !== 1600 || shot.height !== 1000)
|
|
37
|
+
throw Error('Each screenshot needs a WebP path, alt, caption, width 1600 and height 1000');
|
|
38
|
+
const bytes = source.bytes(shot.path), [width, height] = webpSize(bytes);
|
|
39
|
+
if (width !== 1600 || height !== 1000 || bytes.length > 300 * 1024) throw Error('Screenshot WebP must be 1600x1000 and at most 300 KiB');
|
|
40
|
+
const path = `assets/seeds/${id}/${basename(shot.path)}`;
|
|
41
|
+
if (paths.has(path) || ['mark.svg', 'mark-light.svg'].includes(basename(shot.path))) throw Error('Screenshot bundle paths must be unique');
|
|
42
|
+
paths.add(path); assets.push({ path, bytes });
|
|
43
|
+
return { path, alt: shot.alt, caption: shot.caption, width, height };
|
|
44
|
+
});
|
|
45
|
+
// Byte identity plus source names distinguish a recapture at the same path
|
|
46
|
+
// from unchanged pictures; copy edits alone cannot claim a fresh capture.
|
|
47
|
+
const identities = screenshots.map((shot, index) => [shot.path, createHash('sha256').update(assets[index].bytes).digest('hex')])
|
|
48
|
+
.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
49
|
+
const identity = createHash('sha256').update(JSON.stringify(identities)).digest('hex');
|
|
50
|
+
return { shots, assets, identity };
|
|
51
|
+
}
|
|
@@ -106,7 +106,7 @@ export function compareVersion(a, b) {
|
|
|
106
106
|
return 0;
|
|
107
107
|
}
|
|
108
108
|
const requiredFiles = ['public-source.tar', 'release-receipt.json', 'publish-check.json'];
|
|
109
|
-
const filePattern = /^(public-source\.tar|release-receipt\.json|publish-check\.json|site\/[a-z0-9]+(?:-[a-z0-9]+)*\/[^/]+\/(?:release\.json|documents
|
|
109
|
+
const filePattern = /^(public-source\.tar|release-receipt\.json|publish-check\.json|site\/[a-z0-9]+(?:-[a-z0-9]+)*\/[^/]+\/(?:release\.json|documents\/.+|assets\/seeds\/[a-z0-9]+(?:-[a-z0-9]+)*\/.+))$/;
|
|
110
110
|
function safePath(path) {
|
|
111
111
|
return validRelativePath(path) && matches(path, filePattern);
|
|
112
112
|
}
|
|
@@ -131,7 +131,8 @@ export function validateStatement(s) {
|
|
|
131
131
|
if (releases.length !== 1 || releases[0].path.split('/')[2] !== s.version) refuse('STATEMENT_INVALID');
|
|
132
132
|
const prefix = releases[0].path.slice(0, -'release.json'.length);
|
|
133
133
|
if (requiredFiles.some(path => !s.files.some(f => f.path === path))
|
|
134
|
-
|| s.files.some(f => f.path.startsWith('site/') && !f.path.startsWith(prefix)
|
|
134
|
+
|| s.files.some(f => f.path.startsWith('site/') && (!f.path.startsWith(prefix)
|
|
135
|
+
|| (f.path.startsWith(prefix + 'assets/') && !f.path.startsWith(prefix + `assets/seeds/${releases[0].path.split('/')[1]}/`))))) refuse('STATEMENT_INVALID');
|
|
135
136
|
} catch (error) { sanitized(error, 'STATEMENT_INVALID'); }
|
|
136
137
|
}
|
|
137
138
|
function parseJSON(value, code) {
|
|
@@ -17,9 +17,8 @@ export function git(repo, ...args) {
|
|
|
17
17
|
} catch { throw Error('Git source operation failed'); }
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export function
|
|
20
|
+
export function committedSource(repo, ref, { hydrateFrom } = {}) {
|
|
21
21
|
repo = realpathSync(repo);
|
|
22
|
-
if (git(repo, 'status', '--porcelain', '--untracked-files=all').length) throw Error('Release requires a clean source checkout');
|
|
23
22
|
const commit = git(repo, 'rev-parse', '--verify', '--end-of-options', `${ref}^{commit}`).toString().trim();
|
|
24
23
|
const tree = git(repo, 'rev-parse', `${commit}^{tree}`).toString().trim();
|
|
25
24
|
const records = git(repo, 'ls-tree', '-r', '-z', commit).toString().split('\0').filter(Boolean);
|
|
@@ -33,15 +32,29 @@ export function inspectSource(repo, ref) {
|
|
|
33
32
|
const bytes = path => {
|
|
34
33
|
const entry = entries.get(path);
|
|
35
34
|
if (!entry || entry.type !== 'blob' || !['100644', '100755'].includes(entry.mode)) throw Error('Release input must be a committed ordinary file');
|
|
35
|
+
if (hydrateFrom) {
|
|
36
|
+
try { git(repo, 'cat-file', '-e', entry.oid); }
|
|
37
|
+
catch { git(repo, 'fetch', '--no-tags', hydrateFrom, entry.oid); }
|
|
38
|
+
}
|
|
36
39
|
return git(repo, 'cat-file', 'blob', entry.oid);
|
|
37
40
|
};
|
|
38
41
|
const seed = JSON.parse(bytes('seed.json'));
|
|
39
|
-
const
|
|
40
|
-
|
|
42
|
+
const release = entries.has('RELEASE.json') ? JSON.parse(bytes('RELEASE.json')) : {};
|
|
43
|
+
// Read this object alone: show/log may inspect unavailable parents in a
|
|
44
|
+
// shallow partial clone, even when only the timestamp was requested.
|
|
45
|
+
const committedAt = /^committer .* (\d+) [+-]\d{4}$/m.exec(git(repo, 'cat-file', 'commit', commit).toString())?.[1];
|
|
46
|
+
if (!committedAt) throw Error('Invalid Git commit timestamp');
|
|
47
|
+
const timestamp = new Date(Number(committedAt) * 1000).toISOString();
|
|
48
|
+
return { repo, commit, tree, entries, bytes, seed, release, timestamp, tag: `v${seed.version}` };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function inspectSource(repo, ref) {
|
|
52
|
+
if (git(repo, 'status', '--porcelain', '--untracked-files=all').length) throw Error('Release requires a clean source checkout');
|
|
53
|
+
const source = committedSource(repo, ref), { seed, release } = source;
|
|
54
|
+
const pkg = JSON.parse(source.bytes('package.json'));
|
|
41
55
|
if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?$/.test(seed.version) ||
|
|
42
56
|
pkg.version !== seed.version || release.version !== seed.version || !pkg.scripts?.verify) throw Error('Seed, package and release versions must agree, and verify must exist');
|
|
43
|
-
|
|
44
|
-
return { repo, commit, tree, entries, bytes, seed, release, timestamp, tag: `v${seed.version}` };
|
|
57
|
+
return source;
|
|
45
58
|
}
|
|
46
59
|
|
|
47
60
|
export function newOutput(repo, output) {
|
|
@@ -18,6 +18,7 @@ export async function readArtifact(directory) {
|
|
|
18
18
|
if (!pathOK(manifestPath) || !/^site\/[a-z0-9]+(?:-[a-z0-9]+)*\/(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\/release\.json$/.test(manifestPath)) refuse('PATH_UNSAFE');
|
|
19
19
|
const base = posix.dirname(manifestPath);
|
|
20
20
|
const selected = new Map();
|
|
21
|
+
const isAsset = path => path.startsWith(`${base}/assets/`);
|
|
21
22
|
const walk = (relative = '') => {
|
|
22
23
|
for (const name of readdirSync(resolve(root, relative)).sort()) {
|
|
23
24
|
const path = relative ? `${relative}/${name}` : name;
|
|
@@ -32,9 +33,9 @@ export async function readArtifact(directory) {
|
|
|
32
33
|
if (stat.isSymbolicLink() || (!stat.isDirectory() && !stat.isFile())) refuse('PATH_UNSAFE');
|
|
33
34
|
if (stat.isFile() && stat.size > FILE_LIMIT) refuse('INPUT_TOO_LARGE');
|
|
34
35
|
if (stat.isDirectory()) {
|
|
35
|
-
if (!ancillary && path !== 'site' && path !== posix.dirname(base) && path !== base && path !== `${base}/documents` && !path.startsWith(`${base}/documents/`)) refuse('FILE_UNDECLARED');
|
|
36
|
+
if (!ancillary && path !== 'site' && path !== posix.dirname(base) && path !== base && path !== `${base}/documents` && !path.startsWith(`${base}/documents/`) && path !== `${base}/assets` && !isAsset(path)) refuse('FILE_UNDECLARED');
|
|
36
37
|
walk(path);
|
|
37
|
-
} else if (required.includes(path) || path === manifestPath || path.startsWith(`${base}/documents/`)) {
|
|
38
|
+
} else if (required.includes(path) || path === manifestPath || path.startsWith(`${base}/documents/`) || isAsset(path)) {
|
|
38
39
|
selected.set(path, stat.size);
|
|
39
40
|
if (selected.size > 256) refuse('INPUT_TOO_LARGE');
|
|
40
41
|
} else if (!ancillary && !['PUBLISH.md', 'site/registry.json', SIGNATURE_FILE].includes(path)) refuse('FILE_UNDECLARED');
|
|
@@ -62,14 +63,17 @@ export async function readArtifact(directory) {
|
|
|
62
63
|
if (!Array.isArray(manifest.artifacts)) refuse('STATEMENT_INVALID');
|
|
63
64
|
const declared = new Set();
|
|
64
65
|
for (const artifact of manifest.artifacts) {
|
|
65
|
-
if (!pathOK(artifact?.path) || !artifact.path.startsWith('documents/')) refuse('PATH_UNSAFE');
|
|
66
|
+
if (!pathOK(artifact?.path) || !(artifact.path.startsWith('documents/') || artifact.path.startsWith(`assets/seeds/${manifest.listing.id}/`))) refuse('PATH_UNSAFE');
|
|
66
67
|
const path = `${base}/${artifact.path}`;
|
|
67
68
|
if (declared.has(path)) refuse('STATEMENT_INVALID');
|
|
68
69
|
declared.add(path);
|
|
69
70
|
if (!files.has(path)) refuse('FILE_MISSING');
|
|
70
71
|
match(path, artifact.sha256);
|
|
71
72
|
}
|
|
72
|
-
for (const path of files.keys()) if (path.startsWith(`${base}/documents/`) && !declared.has(path)) refuse('FILE_UNDECLARED');
|
|
73
|
+
for (const path of files.keys()) if ((path.startsWith(`${base}/documents/`) || isAsset(path)) && !declared.has(path)) refuse('FILE_UNDECLARED');
|
|
74
|
+
for (const path of [manifest.listing.brand?.mark, manifest.listing.brand?.markLight, ...(manifest.listing.shots ?? []).map(shot => typeof shot === 'string' ? shot : shot.path)].filter(Boolean)) {
|
|
75
|
+
if (!pathOK(path) || !declared.has(`${base}/${path}`)) refuse('FILE_MISSING');
|
|
76
|
+
}
|
|
73
77
|
return { root, receipt, subject, files, entries };
|
|
74
78
|
}
|
|
75
79
|
|
|
@@ -13,7 +13,7 @@ export function localVariables(text) {
|
|
|
13
13
|
|
|
14
14
|
// Inherited application bindings never reach a build or migration command.
|
|
15
15
|
// The default names are the Base operator-auth and mail bindings.
|
|
16
|
-
export const applicationBindings = /^(SESSION_SECRET|SETUP_TOKEN|OWNER_EMAIL|AUTH_|MAIL_|OIDC_|AI_|MODELS_|RER_MODELS_)/
|
|
16
|
+
export const applicationBindings = /^(SESSION_SECRET|INSTALLATION_KEY(?:_PREVIOUS)?$|SETUP_TOKEN|OWNER_EMAIL|AUTH_|MAIL_|OIDC_|AI_|MODELS_|RER_MODELS_)/
|
|
17
17
|
|
|
18
18
|
export function buildEnvironment(bindings = applicationBindings, inherited = process.env) {
|
|
19
19
|
const env = { ...inherited, CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV: 'false', CLOUDFLARE_INCLUDE_PROCESS_ENV: 'false', WRANGLER_SEND_METRICS: 'false' }
|
|
@@ -23,7 +23,7 @@ export function buildEnvironment(bindings = applicationBindings, inherited = pro
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// Values printed by a child are redacted when their name marks a credential.
|
|
26
|
-
export const secretValues = (vars) => Object.entries(vars).filter(([key]) => /SECRET|TOKEN|API_KEY
|
|
26
|
+
export const secretValues = (vars) => Object.entries(vars).filter(([key]) => /SECRET|TOKEN|API_KEY|^INSTALLATION_KEY(?:_PREVIOUS)?$/.test(key)).map(([, value]) => value).filter(Boolean)
|
|
27
27
|
|
|
28
28
|
export function localOrigin(vars) {
|
|
29
29
|
let url
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setTimeout as delay } from 'node:timers/promises'
|
|
2
|
-
import { inspectionMs, readProcessIdentity, readProcessTable, sameBirth,
|
|
2
|
+
import { inspectionMs, readProcessIdentity, readProcessTable, sameBirth, validPid } from './process-table.mjs'
|
|
3
3
|
import { readOwnedTree } from './process-tree.mjs'
|
|
4
4
|
|
|
5
5
|
const graceMs = 1000
|
|
@@ -8,7 +8,7 @@ const cleanupMs = 30000
|
|
|
8
8
|
const pollMs = process.platform === 'darwin' ? 5 : 25
|
|
9
9
|
const isZombie = (member) => member.state.startsWith('Z')
|
|
10
10
|
const isStopped = (member) => /^[Tt]/.test(member.state)
|
|
11
|
-
const key = (member) => `${member.pid}:${member.birth}
|
|
11
|
+
const key = (member) => `${member.pid}:${member.birth}`
|
|
12
12
|
const isLeaf = (member, group) => !group.some((other) => other.ppid === member.pid)
|
|
13
13
|
|
|
14
14
|
// Ask every owned process to shut down gracefully, including supervisors that
|
|
@@ -24,7 +24,7 @@ export async function stopOwnedGroup(child, signal, ownership) {
|
|
|
24
24
|
const inspect = async (timeout) => {
|
|
25
25
|
const current = await readOwnedTree(child, ownership, timeout)
|
|
26
26
|
// Retain departed group leaders as provenance, not as signal targets.
|
|
27
|
-
for (const member of current) if (!ownership.some(saved =>
|
|
27
|
+
for (const member of current) if (!ownership.some(saved => sameBirth(saved, member))) ownership.push(member)
|
|
28
28
|
return current
|
|
29
29
|
}
|
|
30
30
|
let group
|
|
@@ -45,7 +45,7 @@ export async function stopOwnedGroup(child, signal, ownership) {
|
|
|
45
45
|
// signal. Never send a negative/group signal that can kill parents first.
|
|
46
46
|
const current = requireLeaf ? await readProcessTable(inspectionMs) : []
|
|
47
47
|
const target = await readProcessIdentity(member.pid, inspectionMs)
|
|
48
|
-
if (!
|
|
48
|
+
if (!sameBirth(member, target) || isZombie(target)) return false
|
|
49
49
|
if (requireLeaf && !isLeaf(target, current)) return false
|
|
50
50
|
if (name === 'SIGKILL' && !isStopped(target)) return false
|
|
51
51
|
if (requireLeaf && target.pid === pgid && current.some(other => other.pid !== pgid
|
|
@@ -66,7 +66,7 @@ export async function stopOwnedGroup(child, signal, ownership) {
|
|
|
66
66
|
const leader = ownership.find(member => member.pid === pgid)
|
|
67
67
|
if (leader && child.exitCode == null && child.signalCode == null) {
|
|
68
68
|
const live = await readProcessIdentity(pgid, inspectionMs)
|
|
69
|
-
if (
|
|
69
|
+
if (sameBirth(leader, live) && live.ppid === process.pid && !isZombie(live)) {
|
|
70
70
|
try { process.kill(pgid, signal); signalled.set(key(live), Date.now()) }
|
|
71
71
|
catch (error) { if (error.code !== 'ESRCH') throw new Error(`Could not send ${signal} to owned process ${pgid}.`) }
|
|
72
72
|
}
|