diff --git a/.claude/settings.json b/.claude/settings.json index 72723a1..3556fdf 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -4,7 +4,7 @@ "source": { "source": "github", "repo": "LasVegasForTransit/repository-tooling", - "ref": "v0.7.6" + "ref": "v0.7.8" } } }, diff --git a/.lvbt/web-platform.json b/.lvbt/web-platform.json index 8b6f2b3..249a102 100644 --- a/.lvbt/web-platform.json +++ b/.lvbt/web-platform.json @@ -1,9 +1,9 @@ { "formatVersion": 1, "preset": "lvbt-web", - "release": "v0.7.6", - "commit": "71bd6ea8a314417be4d85829480444bb61bba232", - "contentHash": "8533976f630e4836a9fa2cda0bc43616b646f577ef896118b50f1fe349ca245c", + "release": "v0.7.8", + "commit": "3690a066080a394bb3af97dc5717844d3011a467", + "contentHash": "4221255e2e275d9630e40922f45132c25fc5787903eedb5d43b4c6a59b120103", "executables": [ "examples/with-astro/.githooks/commit-msg", "examples/with-astro/.githooks/pre-commit", diff --git a/.lvbt/web-platform/examples/with-astro/.claude/settings.json b/.lvbt/web-platform/examples/with-astro/.claude/settings.json index 72723a1..3556fdf 100644 --- a/.lvbt/web-platform/examples/with-astro/.claude/settings.json +++ b/.lvbt/web-platform/examples/with-astro/.claude/settings.json @@ -4,7 +4,7 @@ "source": { "source": "github", "repo": "LasVegasForTransit/repository-tooling", - "ref": "v0.7.6" + "ref": "v0.7.8" } } }, diff --git a/.lvbt/web-platform/examples/with-astro/apps/deploy/package.json b/.lvbt/web-platform/examples/with-astro/apps/deploy/package.json index 0a37fca..d7c6c38 100644 --- a/.lvbt/web-platform/examples/with-astro/apps/deploy/package.json +++ b/.lvbt/web-platform/examples/with-astro/apps/deploy/package.json @@ -10,9 +10,9 @@ "validate": "cf deploy --dry-run" }, "devDependencies": { - "@lasvegasfortransit/eslint-config": "0.7.6", + "@lasvegasfortransit/eslint-config": "0.7.8", "@lasvegasfortransit/site": "workspace:*", - "@lasvegasfortransit/typescript-config": "0.7.6", + "@lasvegasfortransit/typescript-config": "0.7.8", "cf": "catalog:", "eslint": "catalog:", "typescript": "catalog:", diff --git a/.lvbt/web-platform/examples/with-astro/apps/site/package.json b/.lvbt/web-platform/examples/with-astro/apps/site/package.json index 11018d2..c551ffb 100644 --- a/.lvbt/web-platform/examples/with-astro/apps/site/package.json +++ b/.lvbt/web-platform/examples/with-astro/apps/site/package.json @@ -23,10 +23,10 @@ }, "devDependencies": { "@astrojs/check": "catalog:", - "@lasvegasfortransit/eslint-config": "0.7.6", - "@lasvegasfortransit/playwright-config": "0.7.6", - "@lasvegasfortransit/typescript-config": "0.7.6", - "@lasvegasfortransit/vitest-config": "0.7.6", + "@lasvegasfortransit/eslint-config": "0.7.8", + "@lasvegasfortransit/playwright-config": "0.7.8", + "@lasvegasfortransit/typescript-config": "0.7.8", + "@lasvegasfortransit/vitest-config": "0.7.8", "@playwright/test": "catalog:", "@types/node": "catalog:", "eslint": "catalog:", diff --git a/.lvbt/web-platform/examples/with-astro/package.json b/.lvbt/web-platform/examples/with-astro/package.json index 09460d5..856c12f 100644 --- a/.lvbt/web-platform/examples/with-astro/package.json +++ b/.lvbt/web-platform/examples/with-astro/package.json @@ -28,8 +28,8 @@ "*": "prettier --write --ignore-unknown" }, "devDependencies": { - "@lasvegasfortransit/cli": "0.7.6", - "@lasvegasfortransit/prettier-config": "0.7.6", + "@lasvegasfortransit/cli": "0.7.8", + "@lasvegasfortransit/prettier-config": "0.7.8", "lint-staged": "catalog:", "markdownlint-cli2": "catalog:", "markdownlint-rule-relative-links": "catalog:", @@ -39,7 +39,7 @@ "typescript": "catalog:", "wrangler": "catalog:", "tsx": "catalog:", - "@lasvegasfortransit/web-platform": "0.7.6" + "@lasvegasfortransit/web-platform": "0.7.8" }, "packageManager": "pnpm@11.25.0", "engines": { diff --git a/.lvbt/web-platform/examples/with-astro/pnpm-workspace.yaml b/.lvbt/web-platform/examples/with-astro/pnpm-workspace.yaml index f931807..8042f82 100644 --- a/.lvbt/web-platform/examples/with-astro/pnpm-workspace.yaml +++ b/.lvbt/web-platform/examples/with-astro/pnpm-workspace.yaml @@ -24,7 +24,7 @@ overrides: sharp: 0.35.5 'undici@^7.0.0': 7.29.1 'undici@^8.0.0': 8.10.2 - smol-toml: 1.8.0 + smol-toml: 1.9.0 source-map-js: 1.2.2 svgo: 4.1.0 diff --git a/.lvbt/web-platform/examples/with-vite-react/.claude/settings.json b/.lvbt/web-platform/examples/with-vite-react/.claude/settings.json index 72723a1..3556fdf 100644 --- a/.lvbt/web-platform/examples/with-vite-react/.claude/settings.json +++ b/.lvbt/web-platform/examples/with-vite-react/.claude/settings.json @@ -4,7 +4,7 @@ "source": { "source": "github", "repo": "LasVegasForTransit/repository-tooling", - "ref": "v0.7.6" + "ref": "v0.7.8" } } }, diff --git a/.lvbt/web-platform/examples/with-vite-react/apps/app/package.json b/.lvbt/web-platform/examples/with-vite-react/apps/app/package.json index a1d9fea..c4560f5 100644 --- a/.lvbt/web-platform/examples/with-vite-react/apps/app/package.json +++ b/.lvbt/web-platform/examples/with-vite-react/apps/app/package.json @@ -19,10 +19,10 @@ "react-dom": "catalog:" }, "devDependencies": { - "@lasvegasfortransit/eslint-config": "0.7.6", - "@lasvegasfortransit/playwright-config": "0.7.6", - "@lasvegasfortransit/typescript-config": "0.7.6", - "@lasvegasfortransit/vitest-config": "0.7.6", + "@lasvegasfortransit/eslint-config": "0.7.8", + "@lasvegasfortransit/playwright-config": "0.7.8", + "@lasvegasfortransit/typescript-config": "0.7.8", + "@lasvegasfortransit/vitest-config": "0.7.8", "@playwright/test": "catalog:", "@tailwindcss/vite": "catalog:", "@types/node": "catalog:", diff --git a/.lvbt/web-platform/examples/with-vite-react/apps/deploy/package.json b/.lvbt/web-platform/examples/with-vite-react/apps/deploy/package.json index 2c4c666..4894137 100644 --- a/.lvbt/web-platform/examples/with-vite-react/apps/deploy/package.json +++ b/.lvbt/web-platform/examples/with-vite-react/apps/deploy/package.json @@ -10,9 +10,9 @@ "validate": "cf deploy --dry-run" }, "devDependencies": { - "@lasvegasfortransit/eslint-config": "0.7.6", + "@lasvegasfortransit/eslint-config": "0.7.8", "@lasvegasfortransit/app": "workspace:*", - "@lasvegasfortransit/typescript-config": "0.7.6", + "@lasvegasfortransit/typescript-config": "0.7.8", "cf": "catalog:", "eslint": "catalog:", "typescript": "catalog:", diff --git a/.lvbt/web-platform/examples/with-vite-react/package.json b/.lvbt/web-platform/examples/with-vite-react/package.json index d4420f2..40a160a 100644 --- a/.lvbt/web-platform/examples/with-vite-react/package.json +++ b/.lvbt/web-platform/examples/with-vite-react/package.json @@ -28,8 +28,8 @@ "*": "prettier --write --ignore-unknown" }, "devDependencies": { - "@lasvegasfortransit/cli": "0.7.6", - "@lasvegasfortransit/prettier-config": "0.7.6", + "@lasvegasfortransit/cli": "0.7.8", + "@lasvegasfortransit/prettier-config": "0.7.8", "lint-staged": "catalog:", "markdownlint-cli2": "catalog:", "markdownlint-rule-relative-links": "catalog:", @@ -38,7 +38,7 @@ "typescript": "catalog:", "wrangler": "catalog:", "tsx": "catalog:", - "@lasvegasfortransit/web-platform": "0.7.6" + "@lasvegasfortransit/web-platform": "0.7.8" }, "packageManager": "pnpm@11.25.0", "engines": { diff --git a/.lvbt/web-platform/examples/with-vite-react/pnpm-workspace.yaml b/.lvbt/web-platform/examples/with-vite-react/pnpm-workspace.yaml index f931807..8042f82 100644 --- a/.lvbt/web-platform/examples/with-vite-react/pnpm-workspace.yaml +++ b/.lvbt/web-platform/examples/with-vite-react/pnpm-workspace.yaml @@ -24,7 +24,7 @@ overrides: sharp: 0.35.5 'undici@^7.0.0': 7.29.1 'undici@^8.0.0': 8.10.2 - smol-toml: 1.8.0 + smol-toml: 1.9.0 source-map-js: 1.2.2 svgo: 4.1.0 diff --git a/.lvbt/web-platform/packages/cli/catalog.json b/.lvbt/web-platform/packages/cli/catalog.json index 65e6cfc..6aff308 100644 --- a/.lvbt/web-platform/packages/cli/catalog.json +++ b/.lvbt/web-platform/packages/cli/catalog.json @@ -10,7 +10,7 @@ "sharp": "0.35.5", "undici@^7.0.0": "7.29.1", "undici@^8.0.0": "8.10.2", - "smol-toml": "1.8.0", + "smol-toml": "1.9.0", "source-map-js": "1.2.2", "svgo": "4.1.0" }, diff --git a/.lvbt/web-platform/packages/cli/package.json b/.lvbt/web-platform/packages/cli/package.json index 76a644b..f23cf5a 100644 --- a/.lvbt/web-platform/packages/cli/package.json +++ b/.lvbt/web-platform/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@lasvegasfortransit/cli", - "version": "0.7.6", + "version": "0.7.8", "description": "The lvbt command every LVBT repository runs for bootstrap, preflight, and deploy, plus the production platform setup, the shared git hooks, and the lvbt-contributions agent plugin.", "license": "MIT", "type": "module", diff --git a/.lvbt/web-platform/packages/cli/plugins/lvbt-contributions/.claude-plugin/plugin.json b/.lvbt/web-platform/packages/cli/plugins/lvbt-contributions/.claude-plugin/plugin.json index 98a9441..3468a7a 100644 --- a/.lvbt/web-platform/packages/cli/plugins/lvbt-contributions/.claude-plugin/plugin.json +++ b/.lvbt/web-platform/packages/cli/plugins/lvbt-contributions/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "lvbt-contributions", - "version": "0.7.6", + "version": "0.7.8", "description": "Create readable LVBT contributions and reconcile trusted audit and recurring issues through the organization workflow.", "author": { "name": "Las Vegans for Better Transit", diff --git a/.lvbt/web-platform/packages/cli/plugins/lvbt-contributions/.codex-plugin/plugin.json b/.lvbt/web-platform/packages/cli/plugins/lvbt-contributions/.codex-plugin/plugin.json index 317f2a2..616b707 100644 --- a/.lvbt/web-platform/packages/cli/plugins/lvbt-contributions/.codex-plugin/plugin.json +++ b/.lvbt/web-platform/packages/cli/plugins/lvbt-contributions/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "lvbt-contributions", - "version": "0.7.6", + "version": "0.7.8", "description": "Create readable LVBT contributions and reconcile trusted audit and recurring issues through the organization workflow.", "author": { "name": "Las Vegans for Better Transit", diff --git a/.lvbt/web-platform/packages/cli/src/lib/git-hooks.mjs b/.lvbt/web-platform/packages/cli/src/lib/git-hooks.mjs new file mode 100644 index 0000000..cad3d14 --- /dev/null +++ b/.lvbt/web-platform/packages/cli/src/lib/git-hooks.mjs @@ -0,0 +1,21 @@ +import { spawnSync } from 'node:child_process'; +import { CliError } from './arguments.mjs'; + +/** Protect a fresh checkout even when dependency installation never finishes. */ +export function installGitHooks(cwd) { + const installed = spawnSync('git', ['config', '--local', 'core.hooksPath', '.githooks'], { + cwd, + encoding: 'utf8', + }); + if (installed.status !== 0) + throw new CliError('bootstrap: cannot install Git hooks; run inside a Git checkout.', 1); + const effective = spawnSync('git', ['config', '--get', 'core.hooksPath'], { + cwd, + encoding: 'utf8', + }); + if (effective.status !== 0 || effective.stdout.trim() !== '.githooks') + throw new CliError( + 'bootstrap: another Git configuration overrides .githooks. Remove the override shown by git config --show-origin --get core.hooksPath, then rerun pnpm bootstrap.', + 1, + ); +} diff --git a/.lvbt/web-platform/packages/cli/src/lib/operate.mjs b/.lvbt/web-platform/packages/cli/src/lib/operate.mjs index 0c094e7..092c8de 100644 --- a/.lvbt/web-platform/packages/cli/src/lib/operate.mjs +++ b/.lvbt/web-platform/packages/cli/src/lib/operate.mjs @@ -9,6 +9,7 @@ import { findManifests } from './platform/manifest.mjs'; import { platformBootstrap, platformPreflight } from './platform/index.mjs'; import { readTooling } from './tooling.mjs'; import { secretScannerFinding } from './check/secrets.mjs'; +import { installGitHooks } from './git-hooks.mjs'; function output(command, args, cwd) { const result = spawnSync(command, args, { @@ -170,13 +171,13 @@ async function toolchainFindings(cwd, packageJson, report, { includeDependencies } async function repositoryFindings(cwd, report, { production = false } = {}) { - const hooksPath = output('git', ['config', '--local', 'core.hooksPath'], cwd); + const hooksPath = output('git', ['config', '--get', 'core.hooksPath'], cwd); if (hooksPath === '.githooks') report.pass('git hooks', 'core.hooksPath is .githooks'); else report.fail( 'git hooks', `core.hooksPath is ${hooksPath ?? 'unset'}`, - 'pnpm install # the prepare script sets it', + 'pnpm bootstrap; remove any overriding hooks path shown by git config --show-origin --get core.hooksPath', ); const scopes = await readFile(path.join(cwd, '.lvbt/commit-scopes.txt'), 'utf8').catch( @@ -330,6 +331,7 @@ export async function preflight({ cwd, options = {} }) { export async function bootstrap({ cwd, options = {} }) { if (options.rotate !== undefined && !options.production) throw new CliError('--rotate replaces production secrets, so it needs --production.', 2); + installGitHooks(cwd); const tools = await machineFindings(cwd, { toolsOnly: true, includeDependencies: false }); if (tools) throw new CliError(tools, 1); process.stdout.write('pnpm install\n'); diff --git a/.lvbt/web-platform/packages/eslint-config/package.json b/.lvbt/web-platform/packages/eslint-config/package.json index 7f41dd6..d37dbdb 100644 --- a/.lvbt/web-platform/packages/eslint-config/package.json +++ b/.lvbt/web-platform/packages/eslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@lasvegasfortransit/eslint-config", - "version": "0.7.6", + "version": "0.7.8", "description": "The ESLint configurations every LVBT repository uses.", "license": "MIT", "type": "module", diff --git a/.lvbt/web-platform/packages/playwright-config/package.json b/.lvbt/web-platform/packages/playwright-config/package.json index e287660..f0b212b 100644 --- a/.lvbt/web-platform/packages/playwright-config/package.json +++ b/.lvbt/web-platform/packages/playwright-config/package.json @@ -1,6 +1,6 @@ { "name": "@lasvegasfortransit/playwright-config", - "version": "0.7.6", + "version": "0.7.8", "description": "The Playwright configuration every LVBT repository spreads into its own: end-to-end tests under tests/e2e, desktop and mobile projects, traces on failure.", "license": "MIT", "type": "module", diff --git a/.lvbt/web-platform/packages/prettier-config/package.json b/.lvbt/web-platform/packages/prettier-config/package.json index b14a2d7..422765c 100644 --- a/.lvbt/web-platform/packages/prettier-config/package.json +++ b/.lvbt/web-platform/packages/prettier-config/package.json @@ -1,6 +1,6 @@ { "name": "@lasvegasfortransit/prettier-config", - "version": "0.7.6", + "version": "0.7.8", "description": "The Prettier configuration every LVBT repository uses.", "license": "MIT", "type": "module", diff --git a/.lvbt/web-platform/packages/typescript-config/package.json b/.lvbt/web-platform/packages/typescript-config/package.json index c9b814b..a94cfe9 100644 --- a/.lvbt/web-platform/packages/typescript-config/package.json +++ b/.lvbt/web-platform/packages/typescript-config/package.json @@ -1,6 +1,6 @@ { "name": "@lasvegasfortransit/typescript-config", - "version": "0.7.6", + "version": "0.7.8", "description": "TypeScript configurations every LVBT repository extends.", "license": "MIT", "repository": { diff --git a/.lvbt/web-platform/packages/vitest-config/package.json b/.lvbt/web-platform/packages/vitest-config/package.json index 2b68dd0..6e28cfc 100644 --- a/.lvbt/web-platform/packages/vitest-config/package.json +++ b/.lvbt/web-platform/packages/vitest-config/package.json @@ -1,6 +1,6 @@ { "name": "@lasvegasfortransit/vitest-config", - "version": "0.7.6", + "version": "0.7.8", "description": "The Vitest configuration every LVBT repository spreads into its own.", "license": "MIT", "type": "module", diff --git a/.lvbt/web-platform/packages/web-platform/package.json b/.lvbt/web-platform/packages/web-platform/package.json index e14c464..1908796 100644 --- a/.lvbt/web-platform/packages/web-platform/package.json +++ b/.lvbt/web-platform/packages/web-platform/package.json @@ -1,6 +1,6 @@ { "name": "@lasvegasfortransit/web-platform", - "version": "0.7.6", + "version": "0.7.8", "description": "Provider-neutral deployment, provisioning, and validation primitives for LVBT web repositories.", "license": "MIT", "type": "module", diff --git a/.lvbt/web-platform/packages/web-platform/src/cf-worker-release-artifact.ts b/.lvbt/web-platform/packages/web-platform/src/cf-worker-release-artifact.ts index d2af769..82f4c99 100644 --- a/.lvbt/web-platform/packages/web-platform/src/cf-worker-release-artifact.ts +++ b/.lvbt/web-platform/packages/web-platform/src/cf-worker-release-artifact.ts @@ -4,6 +4,7 @@ import { z } from 'zod'; import type { ReleaseConfiguration } from './release-config.js'; import { configuredReleaseIdentity, workerReleaseEntry } from './worker-release-entry.js'; import { sealSavedRelease, type WebsiteRelease } from './saved-release-artifact.js'; +import { assertServiceWorkerIsolation, serviceWorkerBindingSchema } from './worker-bindings.js'; const dataset = z.strictObject({ type: z.literal('analytics-engine-dataset'), @@ -18,7 +19,12 @@ const rateLimit = z.strictObject({ }), }); const secret = z.strictObject({ type: z.literal('secret') }); -const binding = z.discriminatedUnion('type', [dataset, rateLimit, secret]); +const binding = z.discriminatedUnion('type', [ + dataset, + rateLimit, + secret, + serviceWorkerBindingSchema, +]); const bindings = z.record(z.string().regex(/^[A-Z][A-Z0-9_]*$/), binding); type Bindings = z.infer; const modulePath = z @@ -56,6 +62,12 @@ function assertBindingIsolation( ): void { if (candidate?.type !== value.type) throw new Error(`Preview binding ${name} must retain its declared type.`); + if (value.type === 'worker' && candidate.type === 'worker') { + if (candidate.worker === value.worker) + throw new Error(`Preview binding ${name} must use an isolated Worker service.`); + if (candidate.exportName !== value.exportName) + throw new Error(`Preview binding ${name} must retain its Worker service entrypoint.`); + } if ( value.type === 'analytics-engine-dataset' && candidate.type === 'analytics-engine-dataset' && @@ -83,6 +95,7 @@ function previewBindings(production: Bindings, config: WorkerReleaseConfiguratio throw new Error('Preview Worker and origin must be isolated from production.'); if (Object.keys(preview).sort().join(',') !== Object.keys(production).sort().join(',')) throw new Error('Preview bindings must explicitly match every production binding.'); + assertServiceWorkerIsolation(production, preview, config.productionWorker); for (const [name, value] of Object.entries(production)) assertBindingIsolation(name, value, preview[name]); return preview; @@ -90,14 +103,21 @@ function previewBindings(production: Bindings, config: WorkerReleaseConfiguratio function wranglerBindings(values: Bindings): Record { const analytics_engine_datasets = []; const ratelimits = []; + const services = []; for (const [name, value] of Object.entries(values)) { if (value.type === 'analytics-engine-dataset') analytics_engine_datasets.push({ binding: name, dataset: value.name }); if (value.type === 'rate-limit') ratelimits.push({ name, namespace_id: value.namespace, simple: value.simple }); + if (value.type === 'worker') + services.push({ + binding: name, + service: value.worker, + ...(value.exportName ? { entrypoint: value.exportName } : {}), + }); // Secrets belong to the target Worker; names declare requirements but never copy values. } - return { analytics_engine_datasets, ratelimits }; + return { analytics_engine_datasets, ratelimits, services }; } async function copyModules( source: string, diff --git a/.lvbt/web-platform/packages/web-platform/src/typed-worker-config.ts b/.lvbt/web-platform/packages/web-platform/src/typed-worker-config.ts index 2b4b7e7..b5c14df 100644 --- a/.lvbt/web-platform/packages/web-platform/src/typed-worker-config.ts +++ b/.lvbt/web-platform/packages/web-platform/src/typed-worker-config.ts @@ -137,6 +137,7 @@ export function typedWorkerConfiguration( built.env, config.previewBindings, config.previewReadOnlyBindings, + config.productionWorker, ); durableNamespaces(built, preview, config); const assetNames = Object.entries(built.env) diff --git a/.lvbt/web-platform/packages/web-platform/src/worker-bindings.ts b/.lvbt/web-platform/packages/web-platform/src/worker-bindings.ts index 5b6525d..d049c5b 100644 --- a/.lvbt/web-platform/packages/web-platform/src/worker-bindings.ts +++ b/.lvbt/web-platform/packages/web-platform/src/worker-bindings.ts @@ -1,9 +1,15 @@ import { z } from 'zod'; +export const serviceWorkerBindingSchema = z.strictObject({ + type: z.literal('worker'), + worker: z.string().min(1), + exportName: z.string().min(1).optional(), +}); const simple = z.strictObject({ limit: z.number().int().positive(), period: z.union([z.literal(10), z.literal(60)]), }); const binding = z.discriminatedUnion('type', [ + serviceWorkerBindingSchema, z.strictObject({ type: z.literal('d1'), name: z.string().min(1), @@ -34,7 +40,7 @@ function isolated(value: WorkerBindings[string], candidate: WorkerBindings[strin if (value.type === 'd1' && candidate.type === 'd1') return value.id !== candidate.id && value.name !== candidate.name; if (value.type === 'r2' && candidate.type === 'r2') return value.name !== candidate.name; - if (value.type === 'durable-object' && candidate.type === 'durable-object') + if ('worker' in value && 'worker' in candidate) return value.worker !== candidate.worker && value.exportName === candidate.exportName; if (value.type === 'analytics-engine-dataset' && candidate.type === 'analytics-engine-dataset') return value.name !== candidate.name; @@ -49,6 +55,7 @@ export function isolatedPreviewBindings( production: WorkerBindings, input: unknown, readonlyBindings: string[] = [], + productionWorker?: string, ): WorkerBindings { const preview = workerBindingsSchema.parse(input); if (Object.keys(preview).sort().join(',') !== Object.keys(production).sort().join(',')) @@ -61,6 +68,7 @@ export function isolatedPreviewBindings( if (value?.type !== 'r2' || candidate?.type !== 'r2' || value.name !== candidate.name) throw new Error('Preview read-only capabilities require an explicitly shared R2 binding.'); } + assertServiceWorkerIsolation(production, preview, productionWorker); for (const [name, value] of Object.entries(production)) { const candidate = preview[name]; if (!candidate || (!readonlyBindings.includes(name) && !isolated(value, candidate))) @@ -68,8 +76,37 @@ export function isolatedPreviewBindings( } return preview; } +export function assertServiceWorkerIsolation( + production: Record, + preview: Record, + productionWorker?: string, +): void { + const productionTargets = new Set( + Object.values(production).flatMap((value) => + value.type === 'worker' || value.type === 'durable-object' ? [value.worker] : [], + ), + ); + if (productionWorker) productionTargets.add(productionWorker); + for (const [name, value] of Object.entries(preview)) { + if (value.type === 'worker' && productionTargets.has(value.worker)) + throw new Error( + `Preview binding ${name} must use an isolated Worker service target from production.`, + ); + } +} export function wranglerBindings(values: WorkerBindings): Record { return { + services: Object.entries(values).flatMap(([binding, value]) => + value.type === 'worker' + ? [ + { + binding, + service: value.worker, + ...(value.exportName ? { entrypoint: value.exportName } : {}), + }, + ] + : [], + ), durable_objects: { bindings: Object.entries(values).flatMap(([name, value]) => value.type === 'durable-object' diff --git a/.lvbt/web-platform/packages/web-platform/tests/cf-worker-release-artifact.test.ts b/.lvbt/web-platform/packages/web-platform/tests/cf-worker-release-artifact.test.ts index b495d3e..2674d1b 100644 --- a/.lvbt/web-platform/packages/web-platform/tests/cf-worker-release-artifact.test.ts +++ b/.lvbt/web-platform/packages/web-platform/tests/cf-worker-release-artifact.test.ts @@ -7,6 +7,7 @@ import type { ReleaseConfiguration } from '../src/release-config'; import { verifyRelease } from '../src/saved-release-artifact'; import { packageWorkerCfRelease } from '../src/cf-worker-release-artifact'; interface WranglerTarget { + services: { binding: string; service: string; entrypoint?: string }[]; analytics_engine_datasets: unknown[]; ratelimits: { namespace_id: string }[]; vars: Record; @@ -141,6 +142,109 @@ it('saved marker describes the packaged identity while the original runtime keep expect(calls).toEqual(['preview']); expect(runtime.named).toBe('preserved'); }); +it('compiled Worker artifacts retain default and named service bindings through sealing', async () => { + const setup = await fixture(); + await writeFile( + path.join(setup.output, 'worker.config.json'), + JSON.stringify({ + ...descriptor, + env: { + ...descriptor.env, + JOBS: { type: 'worker', worker: 'jobs' }, + HISTORY: { type: 'worker', worker: 'history', exportName: 'History' }, + }, + }), + ); + const release = await packageWorkerCfRelease(setup.source, setup.destination, identity, { + ...configuration, + previewBindings: { + ...configuration.previewBindings, + JOBS: { type: 'worker', worker: 'jobs-preview' }, + HISTORY: { type: 'worker', worker: 'history-preview', exportName: 'History' }, + }, + }); + expect(await verifyRelease(setup.destination)).toEqual(release); + const saved = JSON.parse( + await readFile(path.join(setup.destination, 'wrangler.jsonc'), 'utf8'), + ) as WranglerConfig; + expect(saved.services).toEqual([ + { binding: 'JOBS', service: 'jobs' }, + { binding: 'HISTORY', service: 'history', entrypoint: 'History' }, + ]); + expect(saved.env.preview.services).toEqual([ + { binding: 'JOBS', service: 'jobs-preview' }, + { binding: 'HISTORY', service: 'history-preview', entrypoint: 'History' }, + ]); + expect( + JSON.parse(await readFile(path.join(setup.destination, 'worker-bindings.json'), 'utf8')), + ).toMatchObject({ + production: { JOBS: { type: 'worker', worker: 'jobs' } }, + preview: { JOBS: { type: 'worker', worker: 'jobs-preview' } }, + }); +}); +it('compiled Worker services reject missing, reused, mistyped or changed preview entrypoints before saving', async () => { + for (const JOBS of [ + undefined, + { type: 'worker', worker: 'jobs' }, + { type: 'worker', worker: '' }, + { type: 'secret' }, + { type: 'worker', worker: 'jobs-preview', exportName: 'DifferentCapability' }, + ]) { + const setup = await fixture(); + await writeFile( + path.join(setup.output, 'worker.config.json'), + JSON.stringify({ + ...descriptor, + env: { ...descriptor.env, JOBS: { type: 'worker', worker: 'jobs' } }, + }), + ); + const previewBindings: Record = { ...configuration.previewBindings, JOBS }; + if (JOBS === undefined) delete previewBindings.JOBS; + await expect( + packageWorkerCfRelease(setup.source, setup.destination, identity, { + ...configuration, + previewBindings, + }), + ).rejects.toThrow(); + await expect(readFile(path.join(setup.destination, 'wrangler.jsonc'))).rejects.toMatchObject({ + code: 'ENOENT', + }); + } +}); +it.each([ + ['swapped', { JOBS: 'history', HISTORY: 'jobs' }], + ['aliased', { JOBS: 'history', HISTORY: 'history-preview' }], + ['selected production Worker', { JOBS: 'lvbt-analytics-events', HISTORY: 'history-preview' }], +])( + 'compiled preview rejects %s production service targets before saving', + async (_label, targets) => { + const setup = await fixture(); + await writeFile( + path.join(setup.output, 'worker.config.json'), + JSON.stringify({ + ...descriptor, + env: { + ...descriptor.env, + JOBS: { type: 'worker', worker: 'jobs' }, + HISTORY: { type: 'worker', worker: 'history', exportName: 'History' }, + }, + }), + ); + await expect( + packageWorkerCfRelease(setup.source, setup.destination, identity, { + ...configuration, + previewBindings: { + ...configuration.previewBindings, + JOBS: { type: 'worker', worker: targets.JOBS }, + HISTORY: { type: 'worker', worker: targets.HISTORY, exportName: 'History' }, + }, + }), + ).rejects.toThrow(/isolat|production/i); + await expect(readFile(path.join(setup.destination, 'wrangler.jsonc'))).rejects.toMatchObject({ + code: 'ENOENT', + }); + }, +); it('tampered compiled code or saved marker cannot verify', async () => { const setup = await fixture(); await packageWorkerCfRelease(setup.source, setup.destination, identity, configuration); diff --git a/.lvbt/web-platform/packages/web-platform/tests/release-publish-workflow.test.ts b/.lvbt/web-platform/packages/web-platform/tests/release-publish-workflow.test.ts index 77e52a5..458fdb3 100644 --- a/.lvbt/web-platform/packages/web-platform/tests/release-publish-workflow.test.ts +++ b/.lvbt/web-platform/packages/web-platform/tests/release-publish-workflow.test.ts @@ -21,3 +21,16 @@ test('preview schema applies before candidate acceptance, production applies aft expect(workflow).toContain('secrets.CLOUDFLARE_PREVIEW_API_TOKEN'); expect(workflow).toContain("steps.upload.outputs.protected == 'true'"); }); + +test('named production installs Chromium before its browser-backed public smoke', async () => { + const workflow = await readFile( + new URL('../../../.github/workflows/release-publish.yml', import.meta.url), + 'utf8', + ); + const namedProduction = workflow.slice(workflow.indexOf(' named-production:')); + + expect(namedProduction).toContain('name: Install Chromium'); + expect(namedProduction.indexOf('name: Install Chromium')).toBeLessThan( + namedProduction.indexOf('name: Verify activated origin'), + ); +}); diff --git a/.lvbt/web-platform/packages/web-platform/tests/typed-worker-config.test.ts b/.lvbt/web-platform/packages/web-platform/tests/typed-worker-config.test.ts index f198807..6effb53 100644 --- a/.lvbt/web-platform/packages/web-platform/tests/typed-worker-config.test.ts +++ b/.lvbt/web-platform/packages/web-platform/tests/typed-worker-config.test.ts @@ -1,5 +1,7 @@ import { expect, test } from 'vitest'; import { typedWorkerConfiguration, resolveTypedConfiguration } from '../src/typed-worker-config.js'; +import { bindings } from 'cf/config'; +import { isolatedPreviewBindings, workerBindingsSchema } from '../src/worker-bindings.js'; const worker = { name: 'participant', entrypoint: '../site/worker/index.ts', @@ -93,6 +95,102 @@ test('typed generation rejects missing or reused preview resources and undeclare typedWorkerConfiguration({ worker: { ...worker, name: 'another-worker' } }, config), ).toThrow('configured'); }); +test('canonical Worker service bindings serialize default and named entrypoints with isolated preview targets', () => { + const canonical = { + worker: { + ...worker, + env: { + ...worker.env, + JOBS: bindings.worker({ worker: 'jobs' }), + HISTORY: bindings.worker({ worker: 'history', exportName: 'History' }), + }, + }, + }; + const selected = { + ...config, + previewBindings: { + ...config.previewBindings, + JOBS: { type: 'worker', worker: 'jobs-preview' }, + HISTORY: { type: 'worker', worker: 'history-preview', exportName: 'History' }, + }, + }; + expect(typedWorkerConfiguration(canonical, selected)).toMatchObject({ + services: [ + { binding: 'JOBS', service: 'jobs' }, + { binding: 'HISTORY', service: 'history', entrypoint: 'History' }, + ], + env: { + preview: { + services: [ + { binding: 'JOBS', service: 'jobs-preview' }, + { binding: 'HISTORY', service: 'history-preview', entrypoint: 'History' }, + ], + }, + }, + }); + for (const JOBS of [ + undefined, + { type: 'worker', worker: 'jobs' }, + { type: 'worker', worker: '' }, + { type: 'text', value: 'jobs-preview' }, + { type: 'worker', worker: 'jobs-preview', exportName: 'DifferentCapability' }, + ]) { + const previewBindings: Record = { ...selected.previewBindings, JOBS }; + if (JOBS === undefined) delete previewBindings.JOBS; + expect(() => typedWorkerConfiguration(canonical, { ...selected, previewBindings })).toThrow(); + } +}); +test.each([ + ['swapped', { JOBS: 'history', HISTORY: 'jobs' }], + ['aliased', { JOBS: 'history', HISTORY: 'history-preview' }], +])('typed preview rejects %s production service targets', (_label, targets) => { + const canonical = { + worker: { + ...worker, + env: { + ...worker.env, + JOBS: bindings.worker({ worker: 'jobs' }), + HISTORY: bindings.worker({ worker: 'history', exportName: 'History' }), + }, + }, + }; + expect(() => + typedWorkerConfiguration(canonical, { + ...config, + previewBindings: { + ...config.previewBindings, + JOBS: { type: 'worker', worker: targets.JOBS }, + HISTORY: { type: 'worker', worker: targets.HISTORY, exportName: 'History' }, + }, + }), + ).toThrow(/isolat|production/i); +}); +test('typed preview services cannot invoke the selected production Worker', () => { + expect(() => + typedWorkerConfiguration( + { worker: { ...worker, env: { ...worker.env, JOBS: bindings.worker({ worker: 'jobs' }) } } }, + { + ...config, + previewBindings: { + ...config.previewBindings, + JOBS: { type: 'worker', worker: 'participant' }, + }, + }, + ), + ).toThrow(/isolat|production/i); +}); +test('typed preview services cannot alias a declared production Durable Object Worker', () => { + const production = workerBindingsSchema.parse({ + JOBS: bindings.worker({ worker: 'jobs' }), + GATE: { type: 'durable-object', worker: 'production-gate', exportName: 'Gate' }, + }); + expect(() => + isolatedPreviewBindings(production, { + JOBS: { type: 'worker', worker: 'production-gate' }, + GATE: { type: 'durable-object', worker: 'preview-gate', exportName: 'Gate' }, + }), + ).toThrow(/isolat|production/i); +}); test('canonical upload metadata retains text and key credentials and preview mode retains its routing policy', () => { const unsafe = { metadata: { keep_bindings: ['secret_text', 'secret_key'] } }; const production = { diff --git a/.lvbt/web-platform/packages/web-platform/tests/typed-worker-release.test.ts b/.lvbt/web-platform/packages/web-platform/tests/typed-worker-release.test.ts index 5179ee5..bf023fc 100644 --- a/.lvbt/web-platform/packages/web-platform/tests/typed-worker-release.test.ts +++ b/.lvbt/web-platform/packages/web-platform/tests/typed-worker-release.test.ts @@ -21,7 +21,12 @@ test.each([true, false])( path.join(source, 'worker.mjs'), 'export default {fetch(){return new Response("ok")}}', ); - const bindings = { ASSETS: { type: 'assets' }, TOKEN: { type: 'secret' } }; + const bindings = { + ASSETS: { type: 'assets' }, + TOKEN: { type: 'secret' }, + JOBS: { type: 'worker', worker: 'jobs' }, + }; + const previewBindings = { ...bindings, JOBS: { type: 'worker', worker: 'jobs-preview' } }; const content = `export default ${JSON.stringify({ worker: { name: 'app', entrypoint: 'worker.mjs', compatibilityDate: '2026-08-31', domains: ['example.org'], observability: { enabled: true }, assets: { runWorkerFirst: true }, env: bindings } })}`; await writeFile(path.join(source, 'cloudflare.config.mjs'), content); await mkdir(path.join(root, 'bin')); @@ -48,7 +53,7 @@ fs.writeFileSync(path.join(args[args.indexOf('--outdir')+1],'index.js'),'export artifactPrefix: 'app-release', typedConfig: 'cloudflare.config.mjs', assetsDirectory: '../site/dist', - previewBindings: bindings, + previewBindings, stagingWorkflow: { name: 'Deploy staging', path: '.github/workflows/deploy.yml', @@ -90,7 +95,13 @@ fs.writeFileSync(path.join(args[args.indexOf('--outdir')+1],'index.js'),'export }); expect( JSON.parse(await readFile(path.join(directory, '.wrangler/worker/bindings.json'), 'utf8')), - ).toEqual({ production: bindings, preview: bindings }); + ).toEqual({ production: bindings, preview: previewBindings }); + expect( + JSON.parse(await readFile(path.join(directory, 'wrangler.jsonc'), 'utf8')), + ).toMatchObject({ + services: [{ binding: 'JOBS', service: 'jobs' }], + env: { preview: { services: [{ binding: 'JOBS', service: 'jobs-preview' }] } }, + }); await expect( packageTypedWorkerRelease( source, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 19eac7a..60dcc33 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -46,7 +46,7 @@ overrides: sharp: 0.35.5 undici@^7.0.0: 7.29.1 undici@^8.0.0: 8.10.2 - smol-toml: 1.8.0 + smol-toml: 1.9.0 source-map-js: 1.2.2 svgo: 4.1.0 @@ -1424,8 +1424,8 @@ packages: resolution: {integrity: sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==} engines: {node: '>=14.16'} - smol-toml@1.8.0: - resolution: {integrity: sha512-kCZr2V3ch9i00x8zXRhjUNVcjG9ijES5dDudkXvUVCT5QlJNQWElSJdZqyPemffHoLNUYwOcou0Fy+ojN0uHSQ==} + smol-toml@1.9.0: + resolution: {integrity: sha512-hpd+HLON7HdZXqYchMM/+LaTTbdK0AU3NngIJ4KVyWbY9bfQqdL9cD+4yf6dUoU2Ap4VsU0JkQi6FxAI1B2mXQ==} engines: {node: '>= 18'} source-map-js@1.2.2: @@ -2633,7 +2633,7 @@ snapshots: markdownlint: 0.41.1 markdownlint-cli2-formatter-default: 0.0.6(markdownlint-cli2@0.23.2) micromatch: 4.0.8 - smol-toml: 1.8.0 + smol-toml: 1.9.0 transitivePeerDependencies: - supports-color @@ -2964,7 +2964,7 @@ snapshots: slash@5.1.0: {} - smol-toml@1.8.0: {} + smol-toml@1.9.0: {} source-map-js@1.2.2: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index f931807..8042f82 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -24,7 +24,7 @@ overrides: sharp: 0.35.5 'undici@^7.0.0': 7.29.1 'undici@^8.0.0': 8.10.2 - smol-toml: 1.8.0 + smol-toml: 1.9.0 source-map-js: 1.2.2 svgo: 4.1.0