Skip to content

test: add unit tests for buildProfile style analysis - #262

Open
Krshs90 wants to merge 1 commit into
404-PF:mainfrom
Krshs90:feature/236-history-profile-tests
Open

test: add unit tests for buildProfile style analysis#262
Krshs90 wants to merge 1 commit into
404-PF:mainfrom
Krshs90:feature/236-history-profile-tests

Conversation

@Krshs90

@Krshs90 Krshs90 commented Aug 6, 2026

Copy link
Copy Markdown

Closes #236. This adds unit tests covering the profile-building logic including scope-usage ratio, body-usage ratio, and the empty history edge case.

Review in cubic

Summary by CodeRabbit

  • Tests
    • Expanded automated coverage for profile metrics derived from history data.
    • Added validation for scope-usage and body-usage ratios.
    • Added checks ensuring empty histories produce zero-valued profile metrics.
    • Improved test isolation by using temporary histories and restoring the test environment after execution.

@Krshs90
Krshs90 requested a review from 404-Page-Found as a code owner August 6, 2026 04:38
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7af90e1c-a75a-4542-adf4-5a0bab3ba435

📥 Commits

Reviewing files that changed from the base of the PR and between 3270f09 and 0d46af7.

📒 Files selected for processing (1)
  • tests/history-profile.test.mjs
📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (1)
tests/**/*.mjs

📄 CodeRabbit inference engine (AGENTS.md)

tests/**/*.mjs: Use Node.js built-in node:test for test files in tests/ and tests/e2e/; do not use Jest or Mocha.
Write test assertions with node:assert/strict in test files under tests/ and tests/e2e/.

Files:

  • tests/history-profile.test.mjs
🔇 Additional comments (1)
tests/history-profile.test.mjs (1)

198-281: LGTM!


📝 Walkthrough

Walkthrough

The test suite now validates buildProfile scope and body usage ratios. It also validates zero-valued metrics for empty histories, including commit count, imperative rate, and sentence-case rate.

Changes

Profile metric tests

Layer / File(s) Summary
Profile metric validation
tests/history-profile.test.mjs
Added tests for scoped commits, commits with bodies, and empty-history metrics. Tests verify the expected 0.5 ratios and zero defaults.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: 404-page-found

Poem

I’m a rabbit checking commits in a row,
Scope and body rates now clearly show.
Empty histories return zeros neat,
Each profile metric stays complete.
Hop, hop—tests make the history sweet!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The tests cover scope usage, body usage, and empty history, but omit imperative-mood and common-prefix detection required by [#236]. Add assertions for imperative-mood detection and common-prefix detection using local JSONL history samples.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the added unit tests for buildProfile style analysis.
Out of Scope Changes check ✅ Passed The changes add tests directly related to buildProfile style analysis and contain no unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@sonarqubecloud

sonarqubecloud Bot commented Aug 6, 2026

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/history-profile.test.mjs">

<violation number="1" location="tests/history-profile.test.mjs:199">
P3: The three new tests each repeat the same ~14-line environment setup/teardown block (saving HOME/APPDATA/XDG_CONFIG_HOME, creating a temp home, setting the three env vars, then restoring them and deleting the temp dir in `finally`). This boilerplate already appears three times earlier in the file, so it now exists six times. Consider extracting a small helper like `withTempHome(async (tempHome) => { ... })` that owns the env save/set/restore and `rmSync` cleanup, and have each test call `writeHistory` and `buildProfile` inside it. This keeps the new tests focused on the ratio logic and avoids six copies of the same fragile env/teardown code.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

});

test('buildProfile computes scope-usage ratio', async () => {
const originalHome = process.env.HOME;

@cubic-dev-ai cubic-dev-ai Bot Aug 6, 2026

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.

P3: The three new tests each repeat the same ~14-line environment setup/teardown block (saving HOME/APPDATA/XDG_CONFIG_HOME, creating a temp home, setting the three env vars, then restoring them and deleting the temp dir in finally). This boilerplate already appears three times earlier in the file, so it now exists six times. Consider extracting a small helper like withTempHome(async (tempHome) => { ... }) that owns the env save/set/restore and rmSync cleanup, and have each test call writeHistory and buildProfile inside it. This keeps the new tests focused on the ratio logic and avoids six copies of the same fragile env/teardown code.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/history-profile.test.mjs, line 199:

<comment>The three new tests each repeat the same ~14-line environment setup/teardown block (saving HOME/APPDATA/XDG_CONFIG_HOME, creating a temp home, setting the three env vars, then restoring them and deleting the temp dir in `finally`). This boilerplate already appears three times earlier in the file, so it now exists six times. Consider extracting a small helper like `withTempHome(async (tempHome) => { ... })` that owns the env save/set/restore and `rmSync` cleanup, and have each test call `writeHistory` and `buildProfile` inside it. This keeps the new tests focused on the ratio logic and avoids six copies of the same fragile env/teardown code.</comment>

<file context>
@@ -194,3 +194,88 @@ test('formatProfile renders dominant tone, capitalization, scope, body, and pref
 });
+
+test('buildProfile computes scope-usage ratio', async () => {
+  const originalHome = process.env.HOME;
+  const originalAppData = process.env.APPDATA;
+  const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
</file context>
Fix with cubic

@404-Page-Found 404-Page-Found left a comment

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.

These tests mutate process-global environment variables (HOME, APPDATA, and XDG_CONFIG_HOME) around an asynchronous buildProfile() call. That can make the suite flaky if tests run concurrently or in a shared process, since other tests may observe the temporary paths. Please avoid global environment mutation by injecting the history/config path, or explicitly serialize these tests and centralize the setup/cleanup.

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.

Add unit tests for buildProfile() style analysis

2 participants