Skip to content

fix: stabilize integration test suite#8208

Open
jherr wants to merge 1 commit intomainfrom
fix/integration-test-flakes
Open

fix: stabilize integration test suite#8208
jherr wants to merge 1 commit intomainfrom
fix/integration-test-flakes

Conversation

@jherr
Copy link
Copy Markdown
Contributor

@jherr jherr commented Apr 24, 2026

Summary

  • Add a deterministic --shell option for completion:install and use it in the zsh completion integration tests so they no longer drive the upstream tabtab shell picker interactively.
  • Remove fixed dev-server target ports from flaky concurrent dev/redirects integration tests by allocating free ports per test fixture.
  • Respect dynamically-set process.env.CI in error telemetry reporting so expected CLI failures in integration tests do not spawn telemetry subprocesses that Vitest reports as unhandled rejections.
  • Update the stale netlify help completion snapshot to match the current option ordering.

Test plan

  • npm run test:init
  • npm run typecheck
  • npm run lint
  • npm exec vitest -- run --retry=3 --reporter=default tests/integration/frameworks/hugo.test.ts tests/integration/commands/dev/redirects.test.ts tests/integration/commands/build/build.test.ts tests/integration/commands/completion/completion-install.test.ts tests/integration/commands/dev/dev.test.ts tests/integration/commands/help/help.test.ts
  • npm exec vitest -- run --retry=3 --reporter=default tests/integration/commands/sites/sites.test.ts
  • npm run test:integration — 60 files passed, 554 passed / 3 skipped / 7 todo

Made with Cursor

Make flaky integration tests deterministic by avoiding interactive shell selection, using dynamic dev-server target ports, and suppressing telemetry subprocesses when tests explicitly set CI mode.

Made-with: Cursor
@jherr jherr requested a review from a team as a code owner April 24, 2026 20:09
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added --shell option to the completion:install command, allowing explicit shell selection without interactive prompts
    • Added shell validation to reject unsupported shell types with clear error messaging
  • Bug Fixes

    • Improved CI environment detection to recognize CI contexts more reliably

Walkthrough

The changes introduce an optional --shell CLI option for the completion:install command that validates shell support and passes the selected shell to the tabtab installation process. Additionally, telemetry error reporting now checks for the CI environment variable in addition to existing CI detection. Integration tests are updated to remove shell selection prompts by explicitly specifying --shell zsh for completion tests, and to use dynamic port allocation rather than fixed ports for dev server tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'fix: stabilize integration test suite' directly and clearly summarizes the main objective of the changeset, which addresses flakiness in integration tests through multiple targeted fixes.
Description check ✅ Passed The PR description comprehensively explains the changes made, provides a clear test plan with documented results, and directly relates to the changeset including shell option addition, port allocation fixes, and telemetry adjustments.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/integration-test-flakes

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 and usage tips.

@github-actions
Copy link
Copy Markdown

📊 Benchmark results

Comparing with 0415e87

  • Dependency count: 1,061 (no change)
  • Package size: 355 MB (no change)
  • Number of ts-expect-error directives: 356 (no change)

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/commands/completion/index.ts (1)

10-10: Optional: move shell validation to Commander via .choices().

The description already enumerates the supported shells. Declaring .choices(['bash','fish','pwsh','zsh']) (e.g. via addOption(new Option(...).choices([...]))) would let Commander reject invalid values before the action runs and keep the help text and accepted values in one place, instead of duplicating that list in completion.ts's isShellSupported guard.

Feel free to skip if you prefer keeping validation close to the tabtab call.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/completion/index.ts` at line 10, Replace the free-form
.option('--shell <shell>') with a Commander Option that specifies allowed values
so invalid shells are rejected before action runs: import Option from commander
and use addOption(new Option('--shell
<shell>').choices(['bash','fish','pwsh','zsh'])); then remove or bypass the
duplicate validation in isShellSupported in completion.ts so the supported-shell
list is maintained in one place.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/integration/commands/dev/redirects.test.ts`:
- Around line 50-53: The current replace call may be a silent no-op if the exact
substring 'targetPort = 6123' isn't present; update the logic around
readFile/replace/writeFile (referencing netlifyTomlPath and targetPort) to
perform a more robust regex-based replacement (e.g., allow flexible spacing) and
then assert that the replacement actually occurred by comparing the original and
replaced contents or by checking a replace count; if no replacement happened,
throw or fail the test immediately before calling writeFile so the test fails
loudly rather than silently using the unchanged fixture.

---

Nitpick comments:
In `@src/commands/completion/index.ts`:
- Line 10: Replace the free-form .option('--shell <shell>') with a Commander
Option that specifies allowed values so invalid shells are rejected before
action runs: import Option from commander and use addOption(new Option('--shell
<shell>').choices(['bash','fish','pwsh','zsh'])); then remove or bypass the
duplicate validation in isShellSupported in completion.ts so the supported-shell
list is maintained in one place.
🪄 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: CHILL

Plan: Pro

Run ID: 6e9f17c5-ffeb-429a-97c0-ec0eeb993f05

📥 Commits

Reviewing files that changed from the base of the PR and between 0415e87 and 767503b.

⛔ Files ignored due to path filters (1)
  • tests/integration/commands/help/__snapshots__/help.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • src/commands/completion/completion.ts
  • src/commands/completion/index.ts
  • src/utils/telemetry/report-error.ts
  • tests/integration/commands/completion/completion-install.test.ts
  • tests/integration/commands/dev/dev.test.ts
  • tests/integration/commands/dev/redirects.test.ts

Comment on lines +50 to +53
await writeFile(
netlifyTomlPath,
(await readFile(netlifyTomlPath, 'utf8')).replace('targetPort = 6123', `targetPort = ${targetPort.toString()}`),
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Silent no-op risk: assert the targetPort replacement actually happened.

String.prototype.replace returns the original string unchanged if 'targetPort = 6123' isn't present (e.g., the fixture's default port changes, someone reformats to targetPort=6123, or the line is moved/removed). The test would then silently fall back to whatever port is checked into the fixture, re-introducing a flaky/unexpected port binding without any signal.

Either pattern-match more robustly or assert that the replacement occurred.

🛡️ Proposed fix
-        packageJson.scripts.dev = `next dev -p ${targetPort.toString()}`
-        await writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`)
-        await writeFile(
-          netlifyTomlPath,
-          (await readFile(netlifyTomlPath, 'utf8')).replace('targetPort = 6123', `targetPort = ${targetPort.toString()}`),
-        )
+        packageJson.scripts.dev = `next dev -p ${targetPort.toString()}`
+        await writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`)
+
+        const originalToml = await readFile(netlifyTomlPath, 'utf8')
+        const updatedToml = originalToml.replace(/targetPort\s*=\s*\d+/, `targetPort = ${targetPort.toString()}`)
+        if (updatedToml === originalToml) {
+          throw new Error(`Failed to rewrite targetPort in ${netlifyTomlPath}; fixture may have changed.`)
+        }
+        await writeFile(netlifyTomlPath, updatedToml)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/integration/commands/dev/redirects.test.ts` around lines 50 - 53, The
current replace call may be a silent no-op if the exact substring 'targetPort =
6123' isn't present; update the logic around readFile/replace/writeFile
(referencing netlifyTomlPath and targetPort) to perform a more robust
regex-based replacement (e.g., allow flexible spacing) and then assert that the
replacement actually occurred by comparing the original and replaced contents or
by checking a replace count; if no replacement happened, throw or fail the test
immediately before calling writeFile so the test fails loudly rather than
silently using the unchanged fixture.

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