Skip to content

fix(ai-commit-msg): clone env baseline to stop cumulative test mutations#291

Open
stephansama wants to merge 1 commit into
mainfrom
stephansama/ste-33-fix-flaky-ai-tests
Open

fix(ai-commit-msg): clone env baseline to stop cumulative test mutations#291
stephansama wants to merge 1 commit into
mainfrom
stephansama/ste-33-fix-flaky-ai-tests

Conversation

@stephansama

Copy link
Copy Markdown
Owner

Closes STE-33

core/ai-commit-msg/test/ai.test.ts captured const originalEnvironment = process.env by reference, then individual tests did delete process.env.X to set up the "missing env" cases. The deletions mutated the same underlying object as originalEnvironment, so the afterEach restoration was a no-op for any key that had been deleted. In CI environments where additional env vars are present (CI, GITHUB_ACTIONS, etc.), the cumulative deletions corrupted the baseline that later tests relied on.

Fix: shallow-clone process.env into originalEnvironment once, and re-clone on each afterEach restoration. Net diff: 6 lines.

Acceptance criteria

  • Tests still pass locally (pnpm exec vitest run --root core/ai-commit-msg → 27/27 green)
  • Lint passes
  • CI runs no longer show intermittent failures in ai.test.ts (will confirm after merge)

@vercel

vercel Bot commented May 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
packages Ready Ready Preview, Comment May 18, 2026 2:44am

@changeset-bot

changeset-bot Bot commented May 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b19f298

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@stephansama has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 41 minutes and 24 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4dfd7d57-269d-4910-9781-9bda53aa347e

📥 Commits

Reviewing files that changed from the base of the PR and between 9a84b42 and b19f298.

📒 Files selected for processing (1)
  • core/ai-commit-msg/test/ai.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch stephansama/ste-33-fix-flaky-ai-tests

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the test suite in core/ai-commit-msg/test/ai.test.ts to prevent environment variable mutations from leaking between test cases by cloning process.env. The reviewer noted that reassigning process.env to a plain object can break Node.js-specific behaviors and recommended using Vitest's built-in vi.stubEnv() and vi.unstubAllEnvs() methods for a more robust implementation.


afterEach(() => {
process.env = originalEnvironment;
process.env = { ...originalEnvironment };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Reassigning process.env to a plain object (e.g., { ...originalEnvironment }) is generally discouraged in Node.js. It replaces the special internal environment object with a standard JavaScript object, which loses the built-in behavior of process.env (such as automatically converting all assigned values to strings). This can lead to subtle bugs if the code under test or other libraries expect the standard behavior.

For Vitest, the idiomatic and safer way to manage environment variables is using vi.stubEnv() in tests and vi.unstubAllEnvs() in afterEach. This avoids manual object manipulation and ensures the environment is correctly restored without side effects on the global process object.

@codecov

codecov Bot commented May 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@pkg-pr-new

pkg-pr-new Bot commented May 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

@stephansama/ai-commit-msg

pnpm add https://pkg.pr.new/@stephansama/ai-commit-msg@291

@stephansama/alfred-kaomoji

pnpm add https://pkg.pr.new/@stephansama/alfred-kaomoji@291

@stephansama/astro-iconify-svgmap

pnpm add https://pkg.pr.new/@stephansama/astro-iconify-svgmap@291

@stephansama/auto-readme

pnpm add https://pkg.pr.new/@stephansama/auto-readme@291

@stephansama/catppuccin-jsonresume-theme

pnpm add https://pkg.pr.new/@stephansama/catppuccin-jsonresume-theme@291

@stephansama/catppuccin-opml

pnpm add https://pkg.pr.new/@stephansama/catppuccin-opml@291

@stephansama/catppuccin-rss

pnpm add https://pkg.pr.new/@stephansama/catppuccin-rss@291

@stephansama/catppuccin-typedoc

pnpm add https://pkg.pr.new/@stephansama/catppuccin-typedoc@291

@stephansama/catppuccin-xsl

pnpm add https://pkg.pr.new/@stephansama/catppuccin-xsl@291

@stephansama/eslint-config

pnpm add https://pkg.pr.new/@stephansama/eslint-config@291

create-stephansama-example

pnpm add https://pkg.pr.new/create-stephansama-example@291

@stephansama/find-makefile-targets

pnpm add https://pkg.pr.new/@stephansama/find-makefile-targets@291

@stephansama/github-env

pnpm add https://pkg.pr.new/@stephansama/github-env@291

@stephansama/multipublish

pnpm add https://pkg.pr.new/@stephansama/multipublish@291

@stephansama/pnpm-hooks

pnpm add https://pkg.pr.new/@stephansama/pnpm-hooks@291

@stephansama/prettier-plugin-handlebars

pnpm add https://pkg.pr.new/@stephansama/prettier-plugin-handlebars@291

@stephansama/remark-asciinema

pnpm add https://pkg.pr.new/@stephansama/remark-asciinema@291

@stephansama/single-file

pnpm add https://pkg.pr.new/@stephansama/single-file@291

@stephansama/svelte-social-share-links

pnpm add https://pkg.pr.new/@stephansama/svelte-social-share-links@291

@stephansama/typed-env

pnpm add https://pkg.pr.new/@stephansama/typed-env@291

@stephansama/typed-events

pnpm add https://pkg.pr.new/@stephansama/typed-events@291

@stephansama/typed-nocodb-api

pnpm add https://pkg.pr.new/@stephansama/typed-nocodb-api@291

@stephansama/typed-templates

pnpm add https://pkg.pr.new/@stephansama/typed-templates@291

@stephansama/types-github-action-env

pnpm add https://pkg.pr.new/@stephansama/types-github-action-env@291

@stephansama/types-lhci

pnpm add https://pkg.pr.new/@stephansama/types-lhci@291

commit: b19f298

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