fix(project): resolution hierarchy#15
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (11)
WalkthroughThis PR refactors the Prisma CLI's project context model from a "linked project" approach (persisting project references in ChangesDocumentation and Public API Contracts
Local State and Project Resolution Foundation
Type Contracts and Gateway Interfaces
Authentication and Use-Case Refactoring
Command Wiring for Project Selection
Controller Refactoring for Resolved Project Context
Output Rendering and Serialization
Comprehensive Test Migration
🎯 4 (Complex) | ⏱️ ~60 minutes ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
|
There was a problem hiding this comment.
Actionable comments posted: 6
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/product/command-principles.md`:
- Around line 86-88: Remove the duplicated sentence "use changes local active
context only": keep a single occurrence and delete the repeated bullet point so
the phrase appears only once (locate the duplicate instances of the exact string
"`use` changes local active context only" in the surrounding text and remove the
redundant bullet entry).
In `@packages/cli/src/controllers/app.ts`:
- Around line 180-184: The block in runAppDeploy duplicates
requireProviderAndProjectContext; replace the manual fetch-and-resolve
(requirePreviewAppProviderWithClient + resolveProjectContext) with a single call
to requireProviderAndProjectContext(context, options?.projectRef, { allowCreate:
true }) to obtain { client, provider, target } (or destructure the returned
target) and then set projectId = target.project.id; ensure you still have client
and provider available from that helper for the rest of runAppDeploy.
- Around line 1430-1433: The guard for missing workspace on the result of
requireAuthenticatedAuthState is correct but the thrown error is wrong; replace
the authRequiredError([...]) call with a workspace-specific usage error that
instructs the user to run the workspace selection/creation flow (e.g., call
usageError(...) with a message and next steps like "run prisma-cli workspaces
select or create" or whatever the project's workspace selection command is).
Update this pattern in the current function in
packages/cli/src/controllers/app.ts (the block using
requireAuthenticatedAuthState and throwing authRequiredError) and mirror the
same change in the other occurrences noted (project.ts and app-env.ts) to
consistently guide authenticated-but-no-workspace users to the workspace
selection flow instead of asking them to log in again.
- Around line 559-562: The call to readLastResolvedProject() can return a
project from a different workspace and its id is passed unchecked into
readKnownLiveDeployment(), which leaks cross-workspace state; update the logic
around rememberedProject (from readLastResolvedProject()) to validate that
rememberedProject.workspaceId === context.auth.workspaceId before using it — if
it doesn’t match, treat rememberedProject as null (or re-call a workspace-scoped
variant of readLastResolvedProject that accepts the current workspace id) so
that readKnownLiveDeployment(rememberedProject.id, deployment.app.id) is only
invoked for projects in the authenticated workspace.
In `@packages/cli/src/lib/project/resolution.ts`:
- Around line 156-170: readPackageName currently assumes JSON.parse returns an
object and accesses parsed.name, which throws when package.json parses to a
primitive (e.g., null); update readPackageName to guard that parsed is a
non-null object (e.g., typeof parsed === "object" && parsed !== null) before
accessing parsed.name and treat any non-object root as a missing name (return
null) so it no longer throws a TypeError for primitive JSON roots.
In `@packages/cli/src/use-cases/create-cli-gateways.ts`:
- Around line 66-76: readRememberedProjectId and rememberProjectId are using
different state APIs (readLastResolvedProject vs setRememberedProject) causing
inconsistent reads after writes; update one to use the other's state accessor so
both read and write target the same source. Specifically, in projectStateGateway
adjust either readRememberedProjectId to call the remembered-project read method
(e.g., context.stateStore.readRememberedProject or equivalent) or change
rememberProjectId to persist via the last-resolved API (e.g.,
context.stateStore.setLastResolvedProject) so both use the same state methods
(reference projectStateGateway, readRememberedProjectId, rememberProjectId,
context.stateStore.readLastResolvedProject,
context.stateStore.setRememberedProject).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: fa3690d8-cea7-463c-a85e-6a84ea40e7a5
📒 Files selected for processing (48)
docs/product/cli-style-guide.mddocs/product/command-principles.mddocs/product/command-spec.mddocs/product/error-conventions.mddocs/product/output-conventions.mddocs/product/resource-model.mdpackages/cli/src/adapters/config.tspackages/cli/src/adapters/local-state.tspackages/cli/src/commands/app/index.tspackages/cli/src/commands/env.tspackages/cli/src/commands/project/index.tspackages/cli/src/controllers/app-env.tspackages/cli/src/controllers/app.tspackages/cli/src/controllers/project.tspackages/cli/src/lib/app/env-config.tspackages/cli/src/lib/auth/auth-ops.tspackages/cli/src/lib/project/resolution.tspackages/cli/src/output/patterns.tspackages/cli/src/presenters/app.tspackages/cli/src/presenters/branch.tspackages/cli/src/presenters/project.tspackages/cli/src/shell/command-meta.tspackages/cli/src/types/app.tspackages/cli/src/types/auth.tspackages/cli/src/types/branch.tspackages/cli/src/types/project.tspackages/cli/src/use-cases/auth.tspackages/cli/src/use-cases/branch.tspackages/cli/src/use-cases/contracts.tspackages/cli/src/use-cases/create-cli-gateways.tspackages/cli/src/use-cases/project.tspackages/cli/tests/app-controller.test.tspackages/cli/tests/app-env-vars.test.tspackages/cli/tests/app-env.test.tspackages/cli/tests/auth-ops.test.tspackages/cli/tests/auth-real-mode.test.tspackages/cli/tests/auth-usecases.test.tspackages/cli/tests/auth.test.tspackages/cli/tests/branch-usecases.test.tspackages/cli/tests/branch.test.tspackages/cli/tests/config-adapter.test.tspackages/cli/tests/helpers.tspackages/cli/tests/project-controller.test.tspackages/cli/tests/project-real-mode.test.tspackages/cli/tests/project-usecases.test.tspackages/cli/tests/project.test.tspackages/cli/tests/shell.test.tspackages/cli/tests/use-case-helpers.ts
💤 Files with no reviewable changes (6)
- packages/cli/tests/config-adapter.test.ts
- packages/cli/tests/auth-real-mode.test.ts
- packages/cli/tests/auth-ops.test.ts
- packages/cli/src/adapters/config.ts
- packages/cli/src/types/auth.ts
- packages/cli/src/lib/auth/auth-ops.ts
This PR removes outdated project link commands, and replaces it with the current resolution hierarchy through inference, with flags to fallback on
Summary
project linkfrom the Public Beta command surface and replace repo config linking with automatic project resolution.--project, revalidated remembered local context, package-name inference, deploy-only creation, and stable structured errors.Testing
pnpm --filter @prisma/cli buildpnpm --filter @prisma/cli exec vitest run tests/project.test.ts tests/project-controller.test.ts tests/project-real-mode.test.ts tests/app-controller.test.ts tests/app-env.test.ts tests/app-env-vars.test.ts tests/shell.test.ts