starter:gate: a fresh tarball every run and proof of which code made the site

pnpm's dlx cache is keyed by the spec, so the gate reused the previous run's plugin when the
tarball path stayed the same. Each run now packs to a new file name and calls dlx with
--config.dlx-cache-max-age=0. build:starter records the plugin commit in the bundle; ipal-kit
create records the bundle's sha256 and that commit in .ipal/starter.json; the gate checks both,
and the installed plugin, against the packed tarball.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-29 16:30:24 +01:00
co-authored by Claude Opus 5.5
parent aa88e4ea39
commit e7e756a0d7
8 changed files with 55 additions and 11 deletions
+12
View File
@@ -3,6 +3,7 @@
// (dist/starter/template.json.gz): the kept files, the manifest and the lockfile without the plugin.
// Runs in prepublishOnly after `pnpm build`; fails when the reference site breaks a manifest rule.
import { execFileSync } from 'node:child_process'
import { mkdirSync, statSync, writeFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
@@ -11,9 +12,20 @@ const root = join(dirname(fileURLToPath(import.meta.url)), '..')
const { bundleFlags, collectBundle, packBundle } = await import(pathToFileURL(join(root, 'dist', 'exports', 'starter.js')).href)
const bundle = collectBundle(join(root, 'reference'))
// provenance: the plugin commit this bundle was built from, so a generated site can be traced back (`-dirty` = uncommitted changes)
const git = (args) => {
try {
return execFileSync('git', args, { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim()
} catch {
return ''
}
}
const head = git(['rev-parse', 'HEAD'])
bundle.source = { commit: head ? `${head}${git(['status', '--porcelain']) ? '-dirty' : ''}` : null }
const out = join(root, 'dist', 'starter', 'template.json.gz')
mkdirSync(dirname(out), { recursive: true })
writeFileSync(out, packBundle(bundle))
const raw = Object.values(bundle.files).reduce((sum, text) => sum + Buffer.byteLength(text), 0) + Buffer.byteLength(bundle.lockfile)
console.log(`starter bundle: ${Object.keys(bundle.files).length} files + lockfile, ${(raw / 1024).toFixed(0)} KB raw → ${(statSync(out).size / 1024).toFixed(0)} KB gzipped (${out.slice(root.length + 1)})`)
console.log(`flags used by the reference site: ${bundleFlags(bundle).join(', ')}`)
console.log(`source: ${bundle.source.commit ?? 'not a Git checkout'}`)
+16 -3
View File
@@ -10,6 +10,7 @@
// PATH it also builds the site with Coolify's build pack and runs the seed inside that image.
import { spawn, spawnSync } from 'node:child_process'
import { createHash } from 'node:crypto'
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
@@ -80,11 +81,16 @@ async function main() {
rmSync(work, { force: true, recursive: true })
mkdirSync(work, { recursive: true })
// 1. the tarball exactly as it would be published
// 1. the tarball exactly as it would be published — a new file name every run: pnpm's dlx cache is keyed by the
// spec, so a reused path would silently run the PREVIOUS run's plugin
sh(root, 'pnpm', ['pack', '--pack-destination', work])
const packed = readdirSync(work).find((f) => f.endsWith('.tgz'))
const tarball = join(work, 'ipal-kit.tgz')
const tarball = join(work, `ipal-kit-${Date.now().toString(36)}-${process.pid}.tgz`)
sh(work, 'mv', [packed, tarball])
const version = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')).version
const packedBundle = spawnSync('tar', ['-xOzf', tarball, 'package/dist/starter/template.json.gz'], { maxBuffer: 64 * 1024 * 1024 }).stdout
const bundleSha256 = createHash('sha256').update(packedBundle).digest('hex')
const commit = out('git', ['-C', root, 'rev-parse', 'HEAD'])
// 2. MongoDB in its own container, like the Coolify database resource
sh(root, 'docker', ['run', '-d', '--rm', '--name', mongoName, '-p', '127.0.0.1::27017', 'mongo:7'])
@@ -96,9 +102,16 @@ async function main() {
const answersFile = join(work, 'answers.json')
writeFileSync(answersFile, JSON.stringify(answers, null, 2))
const started = Date.now()
const created = sh(work, 'pnpm', ['--config.auto-install-peers=false', 'dlx', tarball, 'create', domain, '--answers', answersFile, '--plugin-spec', `file:${tarball}`], {}, { allowFail: true })
const created = sh(work, 'pnpm', ['--config.auto-install-peers=false', '--config.dlx-cache-max-age=0', 'dlx', tarball, 'create', domain, '--answers', answersFile, '--plugin-spec', `file:${tarball}`], {}, { allowFail: true })
check('ipal-kit create (install, skills, tokens, types, import map, typecheck, secret check, first commit)', created === 0, `${((Date.now() - started) / 1000).toFixed(0)} s`)
const site = join(work, 'release-checkexample-web')
// the site was made by THIS tarball: the bundle hash and commit the generator recorded, and the plugin it installed
const made = JSON.parse(readFileSync(join(site, '.ipal', 'starter.json'), 'utf8'))
check('generated by this tarball (bundle sha256, plugin version)', made.source?.bundleSha256 === bundleSha256 && made.ipalKit === version, `${bundleSha256.slice(0, 12)} · ${version}`)
check('bundle built from this commit', (made.source?.commit ?? '').replace(/-dirty$/, '') === commit, made.source?.commit ?? 'none')
const installed = join(site, 'node_modules', '@intecion', 'ipal-kit')
const installedSha = createHash('sha256').update(readFileSync(join(installed, 'dist', 'starter', 'template.json.gz'))).digest('hex')
check('the site installed this tarball', installedSha === bundleSha256 && JSON.parse(readFileSync(join(installed, 'package.json'), 'utf8')).version === version)
check('first commit, nothing left uncommitted', out('git', ['-C', site, 'status', '--porcelain']) === '' && out('git', ['-C', site, 'log', '--oneline']).split('\n').length === 1)
// 4. what Coolify runs: frozen install from the committed lockfile, then build, then start