Repository navigation
fix: let zitadel doctor --fix make the app URL setup 0.1.0 registered deployable - #2401
Conversation
… deployable zitadel setup 0.1.0 registered the app's URL (ZITADEL_ISSUER) as a preview origin; deploy lands only on primary origins, and origin add --kind primary refuses the stored pattern as a kind conflict. A new doctor check (issuer-origin) warns about such a project, and doctor --fix removes the pattern and adds it back as primary, then records it so in .zitadel/secret. deploy's no-primary-origin error now suggests the step that works for the project: doctor --fix, origin rm then add, or origin add with the issuer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🦋 Changeset detectedLatest commit: 415f5d9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 26 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
🔵 Needs a closer look
doctor --fix performs a non-atomic remove-then-add mutation of project origins on the server that can briefly leave a project with no origins (admitting all), a migration-sensitive behavior that warrants final human sign-off.
1 open issue
What changed in this PR
This PR closes an upgrade gap for CLI users: a project set up with zitadel 0.1.0 registered its app URL (ZITADEL_ISSUER) as a preview origin, but 0.2.0's deploy only lands on primary origins, so the first deploy fails and the obvious origin add --kind primary hint is rejected as a kind conflict. The change teaches doctor to detect and repair this state and deploy to suggest the step that actually works, plus shared origin helpers and updated agent docs.
Changes:
- New
doctorcheckissuer-origin(+--fix) that warns when the project holds its issuer as a preview origin with no primary, and repairs it by remove-then-add as primary on the server and in.zitadel/secret(with rollback if the add fails). - Restructured
deploy's "no primary origin" error (noPrimaryOriginError) to route each project to the correct remedy (doctor --fix,origin rm+origin add, ororigin add <issuer>), backed by new shared helpers insrc/lib/origins.tsand an extractedconfiguredIssuer. - Unit + integration tests, a
@zitadel/clipatch changeset, and a SKILL.md Origins note.
| File | Description |
|---|---|
apps/cli/src/lib/origins.ts |
New shared helpers (issuerHeldAsPreview, recordedOrigins, originOf) used by the check and deploy. |
apps/cli/src/commands/doctor/checks/issuer-origin.ts |
New check+fix that detects and repairs a preview-held issuer. |
apps/cli/src/commands/doctor/checks/index.ts |
Registers IssuerOriginCheck in the sanity-check battery. |
apps/cli/src/commands/doctor/index.ts |
Adds the warning advisory suggesting doctor --fix. |
apps/cli/src/commands/doctor/patch-context.ts |
Extracts configuredIssuer so the check reads the issuer like the repairs do. |
apps/cli/src/commands/deploy.ts |
Replaces the inline error with noPrimaryOriginError routing to the right remedy. |
apps/cli/skills/zitadel-cli/SKILL.md |
Documents the issuer-origin warning and repair. |
.changeset/cli-doctor-preview-issuer-origin.md |
Customer-facing @zitadel/cli patch note. |
apps/cli/tests/helpers/project.ts |
Adds hasItsIssuerAsAPreviewOrigin() test fixture. |
apps/cli/tests/unit/lib/origins.test.ts |
Unit coverage for the shared helpers. |
apps/cli/tests/unit/commands/doctor/checks/issuer-origin.test.ts |
Unit coverage for the check and fix (including rollback). |
apps/cli/tests/unit/commands/doctor.test.ts |
Covers the new advisory. |
apps/cli/tests/unit/commands/deploy.test.ts |
Covers every branch of noPrimaryOriginError. |
apps/cli/tests/integration/doctor.spec.ts |
Integration: doctor --fix makes the issuer primary. |
apps/cli/tests/integration/deploy.spec.ts |
Integration: deploy suggests doctor --fix. |
Review effort: Balanced
| @@ -0,0 +1,44 @@ | |||
| /** One of a project's origins, as the API returns it and `.zitadel/secret` records it. */ | |||
| export type ProjectOrigin = Readonly<{ pattern: string; kind: string }>; | |||

Summary
The upgrade gap.
zitadel setup0.1.0 registered the app's URL (ZITADEL_ISSUER, e.g.http://localhost:3000) as aprevieworigin; 0.2.0'ssetupregisters it asprimary.deploylands only on primary origins, so a project set up with 0.1.0 fails its first 0.2.0 deploy withE_VALIDATION"The project has no primary origin to deploy to". The hint,origin add <url> --kind primary, then fails withE_CONFLICT("the pattern is already stored with a different kind"). Today the only way out isorigin rm <url>thenorigin add <url> --kind primary, which #2399 documents in the 0.2.0 release note. This PR removes the need for those manual steps.doctorcheckissuer-origin(apps/cli/src/commands/doctor/checks/issuer-origin.ts): warns when the project has no primary origin but holds its configured issuer as a preview origin. It asks the server only when.zitadel/secretrecords the issuer as preview-only, which 0.1.0 wrote alongside the origin. Every other project gets no request, sodoctorstays offline for them. A server it cannot reach skips the check:doctorcarries on past a failed probe. The warning's advisory suggestsdoctor --fix.doctor --fixmakes the issuer primary. The API has no kind change (onlyaddOrigin/removeOrigininapi/openapi/endpoints/projects/by_id/origins/), so the fix removes the pattern and adds it back as primary. If the add fails, it puts the preview pattern back, because an empty origin list admits every origin. It then moves the pattern frompreview_originstoprimary_originsin.zitadel/secret.deploy's error (noPrimaryOriginError) now suggests the step that works for the project:doctor --fixwhen the project holds its issuer as a preview origin and is the project.zitadel/secretrecords, which is the one doctor repairs.origin rmthenorigin add --kind primaryfor any other project that holds its issuer as a preview origin.origin add <issuer> --kind primarywith the resolvedZITADEL_ISSUERotherwise.<url>placeholder hint andorigin listwhen no issuer resolves.All of them are built with the
SuggestedCommandbuilders and carry the run's selector.issuerHeldAsPreview/recordedOrigins/originOflive insrc/lib/origins.ts, shared by the check anddeploy.configuredIssueris pulled out ofpatch-context.ts'sresolveIssuer, so the check reads the issuer the same way the repairs do.@zitadel/api-mockalready answersorigin.kind_conflictfor an existing pattern with another kind, so it needed no change.Validation
moon run cli:typecheck cli:lint cli:testpasses.tests/unit/commands/doctor/checks/issuer-origin.test.tscovers the check and the fix against the platform mock: warn, no request when the secret records a primary origin, a project made primary by hand, an issuer with a trailing slash, an unreachable server, a missing issuer or secret, the fix on the server and in the secret, dry run, and the rollback when the server refuses the primary add.tests/unit/lib/origins.test.ts.tests/unit/commands/deploy.test.tscovers every branch ofnoPrimaryOriginError.tests/unit/commands/doctor.test.tscovers the advisory.doctor.spec.ts:doctor --fixmakes the issuer setup 0.1.0 registered as a preview origin primary.deploy.spec.ts: such a project's deploy suggestsdoctor --fix.node scripts/check-pr-title.mjsaccepts the title.Release notes / changeset
.changeset/cli-doctor-preview-issuer-origin.md(@zitadel/cli: patch). It tells 0.1.0 users to runzitadel doctor --fixonce before their firstzitadel deploy, and says whatdoctoranddeploynow report.Notes
origin rm/origin addsteps can become "runzitadel doctor --fix"..zitadel/secretrecord. A project whose secret records a primary origin while the server holds the issuer as preview-only is not detected. 0.1.0 never wrote that combination.deploy's error still routes such a project to the right step, because it reads the server.SKILL.md's Origins rule now names theissuer-originwarning and the repair.🤖 Generated with Claude Code