Skip to content

feat(init): select project / dataset during app init#612

Draft
cngonzalez wants to merge 1 commit intomainfrom
feat/select-projects-during-init
Draft

feat(init): select project / dataset during app init#612
cngonzalez wants to merge 1 commit intomainfrom
feat/select-projects-during-init

Conversation

@cngonzalez
Copy link
Member

Description

What to review

Testing

@claude
Copy link

claude bot commented Mar 11, 2026

Claude finished @cngonzalez's task in 2m 1s —— View job


Code Review

  • Gather context
  • Read changed files
  • Analyze and post review

3 issues found:

1. getProjectDetails calls confirm() in unattended mode (init.ts:1116)

When running sanity init --yes --template=app-quickstart --project=test --dataset=test, the code reaches getProjectDetails where confirm() is called unconditionally for app templates. In unattended mode (--yes), this interactive prompt will hang waiting for user input. The call should check isUnattended() first and skip or default to true.

// init.ts:1114-1119
if (isAppTemplate) {
  // This will hang in unattended mode
  const selectProjectForAppTemplate = await confirm({
    default: true,
    message: 'Do you want to select a default project for your app to initialize with?',
  })

Fix this →


2. organizationId: '' written to config when project has no org (createAppCliConfig.ts:6-18)

processTemplate replaces undefined values with '' (line 36 of processTemplate.ts). Both app config templates always include organizationId: '%organizationId%'. When a user selects a personal project (no org), organizationId is undefined, resulting in organizationId: '' being written to sanity.cli.ts. This is likely invalid config.

The hasResources helper already handles conditional template selection — a similar pattern should be used for organizationId, or the templates should be refactored to only include organizationId when it's non-empty.

Fix this →


3. No test coverage for app template in unattended mode (init.bootstrap-app.test.ts)

The unattended mode test at line 455 uses the default (studio) template, not --template=app-quickstart. There's no test verifying that sanity init --yes --template=app-quickstart --project=test --dataset=test works correctly — which would catch the confirm() bug in issue #1 above.

Fix this →

@cngonzalez cngonzalez force-pushed the feat/select-projects-during-init branch from e3b7ef0 to 1f15426 Compare March 12, 2026 20:54
@github-actions
Copy link

Coverage Delta

File Statements
packages/@sanity/cli/src/actions/init/bootstrapLocalTemplate.ts 1.9% (±0%)
packages/@sanity/cli/src/actions/init/createAppCliConfig.ts 40.0% (- 10.0%)
packages/@sanity/cli/src/commands/init.ts 91.0% (+ 0.2%)

Comparing 3 changed files against main @ 2f44698e5e319fc69d5266b00ac7f50026011c13

Overall Coverage

Metric Coverage
Statements 81.5% (±0%)
Branches 70.1% (+ 0.0%)
Functions 79.6% (- 0.0%)
Lines 81.9% (+ 0.0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant