Skip to content

feat(cli): make the deploy target selectable end to end - #225

Merged
prisis merged 7 commits into
feat/platform-abstraction-layerfrom
feat/engine-conformance-legs
Jul 28, 2026
Merged

prisis merged 7 commits into
feat/platform-abstraction-layerfrom
feat/engine-conformance-legs

Conversation

@prisis

@prisis prisis commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

Closes the plan 114 §5.3 / §5.5 gaps. Stacked on #190 — review that first.

An audit found the target machinery complete and unreachable: resolveDeployDriver(target) and runCodegen({ target }) both accepted a target, nothing supplied one, so only the default was ever selectable. The first pass at wiring it up got 5 of ~9 places — a two-pass review caught the rest, including deploy.

The invariant

Codegen tailors the emitted ctx.* surface to a target while deploy picks the driver that ships it. If those disagree you get an app that builds cleanly and fails at runtime with nothing in the build to explain it. So there is exactly one resolution order — flag → lunora.json → default — stated once at resolveProjectTarget.

  • lunora.json gains a target key, beside remote.
  • --target on codegen, dev, prepare, deploy, logs, build, and verify, with help text generated from the driver registry.
  • The Vite plugin resolves and validates identically, so vite build and lunora deploy agree without configuring each.

runCodegen resolves the target itself when the caller passes none. This is the part that makes it hold: a call site that forgets emitted the default surface with no diagnostic, so nothing could catch it — not review, not CI. Defaulting from the project file makes every caller correct without remembering. The reader lives in @lunora/codegen because @lunora/config depends on it and not the reverse; config delegates there so one parser serves both, with JSONC support that a second copy would have silently lost.

What review caught

deploy was broken four ways — the command whose disagreement with codegen this feature exists to prevent. It read only the --target flag, so lunora.json's target was invisible to it: a typo'd config failed codegen/prepare/dev and shipped fine from deploy. It passed no target to codegen or provisioning, and resolved so late that _generated/* was rewritten and wrangler.jsonc possibly mutated before the error surfaced. It now resolves once, before anything writes.

dev dropped --target when backgrounding — the automatic path when an AI agent runs it — so the flag looked accepted and did nothing. It also gated resolution on codegenEnabled, false for the vite and framework-worker flavors, and pre-generated its sidecar with no target.

Error-level diagnostics exited 0. platform_unknown_target and platform_unsupported_feature both carry level: "error" because each "drops or misdirects an emitted surface" — and both were printed as warnings. That was the root cause the target validation had been patching around. They now fail the command, reporting is shared rather than copied across the paths, and the Vite plugin surfaces them at all — it had never read platformDiagnostics, so vite build against a mis-declared target emitted the default surface, printed nothing, and exited 0.

Two id spaces for one concept. resolveTargetOrThrow validates against the driver registry; codegen gates against the matrix registry. A target with a driver but no matrix passes validation and then emits an un-gated surface — the silent fallback back again, with the guard fully in place. They are now asserted equal, so the next target's omission is a failing test.

@lunora/codegen pinned @lunora/platform to 1.0.0-alpha.1 — a version that does not exist on the registry. Inherited from #190 and masked by the workspace overrides, it would have frozen the published dependency permanently. Now workspace:* like its six siblings.

Two more I introduced and caught only by running the built binary: deploy's early return set error but never logged it, so it exited 1 in silence; and verify accepted --target without validating it. Neither was visible in the diff.

Verification

Every fix above was verified by hand and by nothing else — which is how they broke in the first place. They are now pinned, with eight mutations each caught by its own test: dropping the lunora.json fallback, swapping JSONC for JSON.parse, removing the daemon forwarding, reverting deploy to the raw flag, moving deploy's resolution after codegen, degrading error diagnostics to warnings, registering a matrix with no driver, and breaking the codegen exit code.

With {"target":"clouflare"} in lunora.json, all five of codegen/prepare/build/verify/deploy exit 1 with the same message. Default path unchanged.

@lunora/cli 876
@lunora/config 495
@lunora/codegen 930 (goldens byte-identical)
@lunora/vite 186
repo lint:types, lint:eslint, lint:prettier, lint:package-json, api:check

(Unrelated: examples/blog/lunora/_generated/server.ts is stale — last regenerated in #202, one commit before vector emission landed in #203. Left alone rather than folded in.)

🤖 Generated with Claude Code

https://claude.ai/code/session_0137KKKmGRyB69XgLzMaFgSh

@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (2)
  • main
  • alpha

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b929b547-41ea-4f1f-976a-f986e8ccc40f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/engine-conformance-legs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for confirming the Contributor License Agreement! 🙏

@prisis prisis changed the title feat(cli): make the deploy target selectable feat(cli): make the deploy target selectable end to end Jul 28, 2026
prisis added 7 commits July 28, 2026 22:27
Closes the gap the plan-114 audit found in §5.3 and §5.5: the target machinery
was complete and unreachable. `resolveDeployDriver(target)` and
`runCodegen({ target })` both accepted one; nothing supplied it, so
`options.target` was always `undefined` and only the default was selectable.

- `lunora.json` gains a `target` key, beside `remote`.
- `--target` is declared on `codegen`, `dev`, `prepare`, `deploy`, and `logs`,
  with help text generated from the driver registry rather than a hand-kept
  string.
- `resolveProjectTarget(projectRoot, explicit)` is the single resolution point:
  flag, then config, then default. One point on purpose — codegen tailors the
  emitted `ctx.*` surface to a target while deploy picks the driver that ships
  it, and resolving those separately lets them disagree, producing an app that
  builds cleanly and fails at runtime.
- The Vite plugin takes `target` too, resolved the same way, so `vite build`
  and `lunora deploy` agree without configuring each.

Wiring it up surfaced two things that would have made the flag decorative:

- The flag parsed and appeared in `--help`, but no `CreateOptions` map declared
  it and no `execute` wrapper forwarded it — the same declared-but-unreachable
  shape as the original finding, one layer down.
- `codegen --target aws` emitted the full Cloudflare surface un-gated, reported
  `platform_unknown_target` as a *warning*, and exited 0. That is the silent
  fallback the driver registry was built to prevent, arriving through the back
  door: codegen resolves no driver of its own, so nothing rejected the name.
  All five commands now resolve through `resolveTargetOrThrow`, so a typo fails
  identically everywhere — including one committed to `lunora.json`, which is
  where it would otherwise go unnoticed longest.

An unregistered target is rejected rather than defaulted, deliberately: quietly
deploying to Cloudflare because `--target aws` was not recognized would ship an
app to the wrong provider.

Default behaviour is unchanged — goldens byte-identical, 921 codegen tests
green.
Regenerated after rebasing onto the alpha merge — alpha's own additions
shifted the surrounding fields, so the `target` entries land in new
positions rather than changing shape.
Review found the target selector wired into 5 of ~9 places, and the biggest
miss was `deploy` — the one command whose disagreement with codegen the
feature's own comments describe as the failure being prevented. The plan note
claiming "every `runCodegen` call site now passes a resolved target" was false.

**The class fix.** `runCodegen` now resolves the target itself, falling back to
`lunora.json` when the caller passes none. A call site that omits it emitted the
DEFAULT surface with no diagnostic, so the mismatch stayed invisible until the
deployed app failed; defaulting from the project file makes every caller correct
without having to remember. The reader lives in `@lunora/codegen` because
`@lunora/config` depends on it and not the reverse, and config now delegates
there so one parser serves both — with JSONC support, which a second copy would
have lost.

**`deploy`** resolved its driver from the raw `--target` flag at two sites and
never passed a target to codegen or provisioning. So `lunora.json`'s `target`
was invisible to it: a typo'd config failed `codegen`/`prepare`/`dev` and
shipped fine from `deploy`. It now resolves once, before anything writes —
previously the unknown-target error surfaced only at the wrangler step, after
`_generated/*` was rewritten and `wrangler.jsonc` possibly mutated.

**`dev`** dropped `--target` for `--background`, which is the automatic path
when an AI agent runs it, so the flag looked accepted and did nothing. It also
gated resolution on `codegenEnabled`, which is false for the `vite` and
`framework-worker` flavors, and pre-generated its sidecar with no target.

**`build` and `verify`** had no `--target` at all. `build` is the artifact half
of the `build` → `deploy --prebuilt` split, so that split could only ever
produce a default-target artifact.

**Error-level diagnostics now fail the command.** `platform_unknown_target` and
`platform_unsupported_feature` both carry `level: "error"` because each "drops
or misdirects an emitted surface", but both were printed as warnings with exit
0 — the root cause the earlier `resolveTargetOrThrow` guard was patching
around. Reporting is shared across `codegen`, `prepare`, and the dev watcher
rather than copied, and the Vite plugin now surfaces them too; it had never read
`platformDiagnostics` at all, so `vite build` against a mis-declared target
emitted the default surface, printed nothing, and exited 0.

**`resolveTargetOrThrow` moved to `@lunora/config`**, beside the registry it
validates against — the Vite plugin needing it was the proof it was never
CLI-shaped. The CLI keeps the cerebro option descriptor and adds a
non-throwing wrapper matching the `validateOutputFormat` idiom the handlers
already use.

Also: `@lunora/codegen` pinned `@lunora/platform` to `1.0.0-alpha.1`, a version
that does not exist on the registry — inherited from #190 and masked by the
workspace overrides, it would have frozen the published dependency forever.
Now `workspace:*` like its six siblings.

Plus the smaller review points: `readProjectConfig` carried the docblock of the
function it was extracted from; the resolution rationale was copy-pasted at six
sites and is now stated once at `resolveProjectTarget`; five field docs claimed
a `"cloudflare"` default that is really `lunora.json`-then-cloudflare; `runOnce`
took six positionals to feed `setTimeout` and now takes an options object; and
the "default surface unchanged" test asserted only that a file existed rather
than that it was byte-identical.

Verified end to end: with `{"target":"clouflare"}` in `lunora.json`, all five of
codegen/prepare/build/verify/deploy exit 1 with the same message. Default path
unchanged — goldens byte-identical, 926 codegen tests green.
Every blocker fixed in the previous commit was verified by hand against the
built binary and by nothing else — which is exactly how they broke in the first
place. These are the regression tests:

- `runCodegen` gates against the project's declared target when the caller
  passes none, reads it as JSONC (a plain-`JSON.parse` copy would reject a
  config the CLI accepts), lets an explicit target win, and degrades to the
  default on an unusable one.
- `deploy` rejects an unregistered target from `lunora.json` — it previously
  read only the `--target` flag, so a typo in the committed config failed
  `codegen`/`prepare`/`dev` and shipped fine from here — and aborts *before*
  spawning wrangler, since resolution now happens ahead of any write.
- `startBackground` forwards `--target` to the daemon, and omits it when
  absent rather than passing an empty string over a project setting.
- `reportPlatformDiagnostics` fails on error-level diagnostics and stays quiet
  when there are none.

Also closes the two-id-space gap the review flagged and the last commit did
not address: `deployTargetIds()` and codegen's `platformMatrixIds()` are now
asserted equal. A target with a driver but no matrix passes validation and
then emits an un-gated surface — reintroducing the silent fallback with the
guard fully in place — and one with a matrix but no driver gates a surface
nothing can deploy. They agree today only because both hold `cloudflare`, so
this makes the next target's omission a failing test rather than a production
surprise.

Eight mutations verified, each caught by its own leg: dropping the
`lunora.json` fallback, swapping JSONC for `JSON.parse`, removing the daemon
forwarding, reverting deploy to the raw flag, moving deploy's resolution after
codegen, degrading error diagnostics to warnings, and registering a matrix
with no driver.
Three call sites looked the driver up with no argument, so they always got the
default one regardless of what the project declared:

- `wrangler-secrets.ts` (`secret list`)
- `env` (`secret put`)
- `dev`'s framework-worker sidecar (`dev`)

Each picks a *toolchain* — which CLI to shell out to — so a project on a
non-default target would have run wrangler against a deployment that is not
Cloudflare's. The review rated these lower stakes than the deploy path and did
not report them; they are the same class, and now that the resolution exists
there is no reason to leave them reading a constant.

Every `resolveDeployDriver` call in the CLI now resolves from the project.
@prisis
prisis force-pushed the feat/engine-conformance-legs branch from 62050dc to b57b1fd Compare July 28, 2026 20:27
@prisis
prisis merged commit 7616878 into feat/platform-abstraction-layer Jul 28, 2026
3 of 4 checks passed
@prisis
prisis deleted the feat/engine-conformance-legs branch July 28, 2026 20:28
prisis added a commit that referenced this pull request Jul 28, 2026
Three leftovers from the target-selector review, none behavioural:

- `--target` was spread into each command's `options` array right after
  `api-spec`/`env`, breaking the alphabetical run those arrays otherwise keep
  and landing the flag in an odd spot in `--help`. Moved to its alphabetical
  slot in `codegen`, `deploy`, `logs`, `build`, and `verify` (`prepare` was
  already correct, and `dev`'s array is not alphabetical to begin with, so the
  flag is simply placed alphabetically there).
- Dropped a stray blank line #225 introduced before `projectRoot` in
  `LunoraPluginOptions`. This file separates members with a blank line only
  ahead of a multi-line docblock; `projectRoot`'s is one line.
- Regenerated `examples/blog`'s `_generated/server.ts`, stale since #202 — one
  commit before vector emission landed in #203, so it was missing the `vectors`
  ctx surface and left a dirty tree for anyone running codegen there. This PR
  changes codegen emission, which is what makes the regen its chore.
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using our GitHub Discussions tab for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant