Skip to content

🧪 Add test coverage for cross-brand constants logic#36

Open
sunnylqm wants to merge 2 commits into
masterfrom
test-constants-module-17454415258068094899
Open

🧪 Add test coverage for cross-brand constants logic#36
sunnylqm wants to merge 2 commits into
masterfrom
test-constants-module-17454415258068094899

Conversation

@sunnylqm
Copy link
Copy Markdown
Collaborator

@sunnylqm sunnylqm commented May 17, 2026

🎯 What:
Added a test suite (tests/constants.test.ts) to verify the module-level evaluation of constants within src/utils/constants.ts. The script evaluates values depending on process.argv dynamically.

📊 Coverage:

  • Tests IS_CRESC, scriptName, credentialFile, updateJson, tempDir, pricingPageUrl, and defaultEndpoints mapping when process.argv mimics a "cresc" run.
  • Tests the exact same mappings when process.argv mimics a "pushy" run.
  • Validates the isPPKBundleFileName utility logic.

Result:
The constants logic is now deterministically tested and guarded against accidental modifications that would break cross-brand behaviors. Module cache busting via dynamic imports guarantees clean independent tests.


PR created automatically by Jules for task 17454415258068094899 started by @sunnylqm

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suite for core utilities to verify script-specific constant exports function correctly and validate bundle filename classification logic. Tests cover multiple scenarios and edge cases, ensuring robust and reliable behavior across different configurations, script paths, and various bundle naming conventions used throughout the system.

Review Change Stack

Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

Warning

Rate limit exceeded

@sunnylqm has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 57 minutes and 51 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3e720da9-861a-4fdb-bafa-8f4911e65b1f

📥 Commits

Reviewing files that changed from the base of the PR and between d0524f6 and 56ed862.

📒 Files selected for processing (1)
  • tests/constants.test.ts
📝 Walkthrough

Walkthrough

New test suite for src/utils/constants.ts using Bun. Tests verify constants derivation under different script contexts (cresc, pushy) via process.argv simulation and dynamic imports, and validate the isPPKBundleFileName utility function for recognizing PPK bundle filenames.

Changes

Constants Module Test Coverage

Layer / File(s) Summary
Test helper for dynamic module loading
tests/constants.test.ts
Helper function overrides process.argv and dynamically imports constants with cache-busting to simulate different script execution contexts.
Script-context constant assertions
tests/constants.test.ts
Tests verify that constants export correct values (scriptName, IS_CRESC flag, credential/update/temp filenames, pricing URL, default endpoints) when module initializes under cresc and pushy script paths.
Bundle filename classifier tests
tests/constants.test.ts
Unit tests confirm isPPKBundleFileName correctly identifies PPK bundle filenames, accepting index.bundlejs and bundle.harmony.js, rejecting index.js and main.bundlejs.

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 A suite of tests so fine,
Constants dancing in a line,
Script paths cresc and pushy play,
Bundle names we classify today! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title includes a decorative emoji (🧪) and uses vague phrasing ('cross-brand constants logic'). While it references a real aspect of the change (test coverage for constants), it lacks the specificity and clarity needed to clearly communicate the main purpose to someone scanning commit history. Consider revising to remove the emoji and use more specific language, such as: 'Add tests for constants module with cross-brand script detection' to better convey what is actually being tested.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test-constants-module-17454415258068094899

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.

Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com>
Copy link
Copy Markdown

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/constants.test.ts`:
- Around line 13-33: Run the Biome formatter to fix the formatting issues in the
test file so CI passes: run the provided formatter command (biome format --write
tests/constants.test.ts) or reformat the two defaultEndpoints array literals in
the tests (in the "should initialize correctly when script is cresc" and "should
initialize correctly when script is pushy" test blocks) to the multiline style
Biome expects; then commit the formatted changes so the arrays and surrounding
whitespace match the project's Biome formatting rules.
- Around line 3-10: The helper loadConstantsWithArgv mutates process.argv but
doesn’t guarantee restoration if the dynamic import throws; wrap the import and
return in a try block and move the process.argv = originalArgv into a finally
block so originalArgv is always restored, referencing loadConstantsWithArgv,
originalArgv, process.argv and the dynamic import url to locate where to add the
try/finally.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3e03e16f-02e9-45f8-ba46-dab2fff700b9

📥 Commits

Reviewing files that changed from the base of the PR and between 2be3698 and d0524f6.

📒 Files selected for processing (1)
  • tests/constants.test.ts

Comment thread tests/constants.test.ts
Comment on lines +3 to +10
const loadConstantsWithArgv = async (argv1: string) => {
const originalArgv = process.argv;
process.argv = ['node', argv1];
const url = `../src/utils/constants.ts?t=${Date.now()}_${Math.random()}`;
const mod = await import(url);
process.argv = originalArgv;
return mod;
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Add try-finally block to guarantee cleanup of process.argv.

If the dynamic import throws (e.g., due to a syntax error in constants.ts during development), originalArgv will never be restored. This will pollute process.argv for all subsequent tests in the suite, potentially causing cascading failures or masking the root cause.

🛡️ Proposed fix to ensure cleanup
 const loadConstantsWithArgv = async (argv1: string) => {
   const originalArgv = process.argv;
-  process.argv = ['node', argv1];
-  const url = `../src/utils/constants.ts?t=${Date.now()}_${Math.random()}`;
-  const mod = await import(url);
-  process.argv = originalArgv;
-  return mod;
+  try {
+    process.argv = ['node', argv1];
+    const url = `../src/utils/constants.ts?t=${Date.now()}_${Math.random()}`;
+    return await import(url);
+  } finally {
+    process.argv = originalArgv;
+  }
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const loadConstantsWithArgv = async (argv1: string) => {
const originalArgv = process.argv;
process.argv = ['node', argv1];
const url = `../src/utils/constants.ts?t=${Date.now()}_${Math.random()}`;
const mod = await import(url);
process.argv = originalArgv;
return mod;
};
const loadConstantsWithArgv = async (argv1: string) => {
const originalArgv = process.argv;
try {
process.argv = ['node', argv1];
const url = `../src/utils/constants.ts?t=${Date.now()}_${Math.random()}`;
return await import(url);
} finally {
process.argv = originalArgv;
}
};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/constants.test.ts` around lines 3 - 10, The helper
loadConstantsWithArgv mutates process.argv but doesn’t guarantee restoration if
the dynamic import throws; wrap the import and return in a try block and move
the process.argv = originalArgv into a finally block so originalArgv is always
restored, referencing loadConstantsWithArgv, originalArgv, process.argv and the
dynamic import url to locate where to add the try/finally.

Comment thread tests/constants.test.ts
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