Skip to content

Commit f5aad16

Browse files
binoy14claude
andcommitted
fix(cli): fix E2E test failures, broken sharding, and --no-git/--bare bugs
- Remove broken E2E sharding (fileParallelism: false defeats --shard) - Fix --bare in unattended mode: skip --output-path check since bare produces no files and the flags are mutually exclusive - Fix --no-git: the hidden no-git boolean flag was defined but never checked in the useGit logic, so git init always ran - Fix template import idempotency: pass --missing to dataset import so re-importing into an existing dataset skips duplicate documents - Fix interactive test expectations to match actual CLI prompt order: dataset selection default, Next.js TypeScript-before-studio flow, and moviedb import prompt text Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2dee8fc commit f5aad16

5 files changed

Lines changed: 34 additions & 16 deletions

File tree

.github/workflows/e2e.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ jobs:
5555
matrix:
5656
os: [ubuntu-latest]
5757
node-version: [20, 22, 24]
58-
shard: [1, 2, 3]
5958
fail-fast: false
6059

6160
steps:
@@ -84,7 +83,7 @@ jobs:
8483
SANITY_E2E_TOKEN: ${{ secrets.SANITY_E2E_TOKEN }}
8584
SANITY_E2E_PROJECT_ID: ${{ secrets.SANITY_E2E_PROJECT_ID }}
8685
SANITY_E2E_DATASET: ${{ secrets.SANITY_E2E_DATASET }}
87-
run: pnpm --filter @sanity/cli-e2e test -- --shard=${{ matrix.shard }}/3
86+
run: pnpm --filter @sanity/cli-e2e test
8887

8988
notify-failure:
9089
if: ${{ failure() && inputs.cli_version }}

packages/@sanity/cli-e2e/__tests__/init/init-interactive.test.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ describe('sanity init - interactive', () => {
120120
interactive: true,
121121
})
122122

123-
await session.waitForText(/Select dataset|dataset/i)
123+
await session.waitForText(/Select dataset/i)
124+
// "Create new dataset" is selected by default; navigate down to "production"
125+
session.sendKey('ArrowDown')
124126
session.sendKey('Enter')
125127

126128
await session.waitForText(/output path|template/i)
@@ -134,11 +136,11 @@ describe('sanity init - interactive', () => {
134136
interactive: true,
135137
})
136138

137-
await session.waitForText(/Select dataset|dataset/i)
138-
session.sendKey('ArrowUp')
139+
await session.waitForText(/Select dataset/i)
140+
// "Create new dataset" is the default first item; press Enter to select it
139141
session.sendKey('Enter')
140142

141-
await session.waitForText(/name.*dataset|dataset.*name/i)
143+
await session.waitForText(/Dataset name/i)
142144

143145
session.kill()
144146
}, 60_000)
@@ -236,17 +238,20 @@ describe('sanity init - interactive', () => {
236238
tmp.path,
237239
'--template',
238240
'moviedb',
241+
'--no-mcp',
242+
'--package-manager',
243+
'pnpm',
239244
],
240245
interactive: true,
241246
})
242247

243248
await session.waitForText(/TypeScript/i)
244249
session.sendKey('Enter')
245250

246-
await session.waitForText(/sample dataset|import/i)
251+
await session.waitForText(/sampling.*movies|dataset on the hosted backend/i)
247252
session.write('y\n')
248253

249-
await session.waitForText(/import/i)
254+
await session.waitForText(/import/i, {timeout: 90_000})
250255

251256
session.kill()
252257
} finally {
@@ -268,17 +273,20 @@ describe('sanity init - interactive', () => {
268273
tmp.path,
269274
'--template',
270275
'moviedb',
276+
'--no-mcp',
277+
'--package-manager',
278+
'pnpm',
271279
],
272280
interactive: true,
273281
})
274282

275283
await session.waitForText(/TypeScript/i)
276284
session.sendKey('Enter')
277285

278-
await session.waitForText(/sample dataset|import/i)
286+
await session.waitForText(/sampling.*movies|dataset on the hosted backend/i)
279287
session.write('n\n')
280288

281-
await session.waitForText(/package manager|Success/i)
289+
await session.waitForText(/installing|Success/i, {timeout: 90_000})
282290

283291
session.kill()
284292
} finally {

packages/@sanity/cli-e2e/__tests__/init/init-nextjs.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ describe.skipIf(!hasToken)('sanity init - Next.js integration', () => {
152152
await session.waitForText(/add configuration files|Would you like to add/i)
153153
session.sendKey('Enter')
154154

155-
await session.waitForText(/embed.*studio|studio.*route/i)
155+
// TypeScript prompt comes before embedded studio prompt
156+
await session.waitForText(/TypeScript/i)
157+
session.sendKey('Enter')
158+
159+
await session.waitForText(/embed.*studio|Would you like an embedded/i)
156160
session.sendKey('Enter')
157161

158162
await session.waitForText(/route.*studio|What route/i)
@@ -174,7 +178,11 @@ describe.skipIf(!hasToken)('sanity init - Next.js integration', () => {
174178
await session.waitForText(/add configuration files|Would you like to add/i)
175179
session.sendKey('Enter')
176180

177-
await session.waitForText(/embed.*studio|studio.*route/i)
181+
// TypeScript prompt comes before embedded studio prompt
182+
await session.waitForText(/TypeScript/i)
183+
session.sendKey('Enter')
184+
185+
await session.waitForText(/embed.*studio|Would you like an embedded/i)
178186
session.sendKey('Enter')
179187

180188
await session.waitForText(/route.*studio|What route/i)

packages/@sanity/cli-e2e/__tests__/init/init-noninteractive.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ describe.skipIf(!hasToken)('sanity init --yes (non-interactive)', () => {
275275
}, 120_000)
276276

277277
test('2.25 --import-dataset with moviedb template imports sample data', async () => {
278-
const {exitCode, stdout} = await runCli({
278+
const {error, exitCode, stdout} = await runCli({
279279
args: baseInitArgs({
280280
extraArgs: [
281281
'--template',
@@ -290,6 +290,7 @@ describe.skipIf(!hasToken)('sanity init --yes (non-interactive)', () => {
290290
}),
291291
})
292292

293+
if (error) throw error
293294
expect(exitCode).toBe(0)
294295
expect(stdout).toMatch(/import/i)
295296
}, 120_000)

packages/@sanity/cli/src/commands/init.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ export class InitCommand extends SanityCommand<typeof InitCommand> {
611611
workDir,
612612
})
613613

614-
const useGit = this.flags.git === undefined || Boolean(this.flags.git)
614+
const useGit =
615+
!this.flags['no-git'] && (this.flags.git === undefined || Boolean(this.flags.git))
615616
const commitMessage = this.flags.git
616617
await this.writeStagingEnvIfNeeded(outputPath)
617618

@@ -635,6 +636,7 @@ export class InitCommand extends SanityCommand<typeof InitCommand> {
635636
datasetName,
636637
'--token',
637638
token,
639+
'--missing',
638640
],
639641
{
640642
root: outputPath,
@@ -756,8 +758,8 @@ export class InitCommand extends SanityCommand<typeof InitCommand> {
756758
})
757759
}
758760

759-
// output-path is required in unattended mode when not using nextjs
760-
if (!isNextJs && !this.flags['output-path']) {
761+
// output-path is required in unattended mode when not using nextjs or bare
762+
if (!isNextJs && !this.flags.bare && !this.flags['output-path']) {
761763
this.error(`\`--output-path\` must be specified in unattended mode`, {
762764
exit: 1,
763765
})

0 commit comments

Comments
 (0)