Skip to content

🧪 test: add isInRollout boundary tests#524

Open
sunnylqm wants to merge 2 commits intomasterfrom
test-isInRollout-10179981082815151273
Open

🧪 test: add isInRollout boundary tests#524
sunnylqm wants to merge 2 commits intomasterfrom
test-isInRollout-10179981082815151273

Conversation

@sunnylqm
Copy link
Contributor

@sunnylqm sunnylqm commented Mar 7, 2026

🎯 What: The testing gap addressed: Missing unit tests for the isInRollout function in src/isInRollout.ts.
📊 Coverage: Scenarios now tested include 0% rollout, 100% rollout, and boundary values based on the specific murmurhash3_32_gc modulo of a mocked UUID.
Result: Test coverage for isInRollout.ts is improved, ensuring the feature logic evaluates deterministically and correctly.


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

Summary by CodeRabbit

  • Tests

    • Added deterministic unit tests for rollout behavior, covering boundary cases and predictable outcomes.
    • Improved test setup and dynamic import handling to ensure consistent test execution.
  • Chores

    • Internal naming cleanup and path adjustments to align update-related state references (no behavioral changes).

Added missing unit tests for `isInRollout` function in `src/isInRollout.ts` using bun:test. Tested boundary values (0, 100) and specific hash modulo values based on a deterministic mock.

Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com>
@google-labs-jules
Copy link
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

coderabbitai bot commented Mar 7, 2026

📝 Walkthrough

Walkthrough

Adds deterministic unit tests for isInRollout, a React Native version mock, small dynamic-import TS ignores, sed patches for tests, and renames infoupdateInfo across client code and related scripts; no public API surface changes.

Changes

Cohort / File(s) Summary
Tests & Test Setup
src/__tests__/isInRollout.test.ts, src/__tests__/core.test.ts, src/__tests__/setup.ts
New deterministic tests for isInRollout (boundary cases 0, 79, 80, 100) with mocked UUID; added // @ts-ignore`` to dynamic imports in core.test.ts; mock for `react-native/Libraries/Core/ReactNativeVersion`.
Client rename
src/client.ts
Renamed local parameter/variable infoupdateInfo and updated all internal references and calls (including beforeDownloadUpdate usage). Method signature updated accordingly.
Test patch scripts
patch_tests.sh, patch_client.sh, patch_client2.sh
Added sed edits to adjust dynamic imports (append /* @vite-ignore */ and as any) and multiple in-place edits to update property paths and variable names (infoupdateInfo).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped through code with careful paws,

mocked a UUID and checked the laws.
Boundaries met at eighty and more,
rename the info, then tests galore.
A tiny hop for stable scores. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title mentions adding isInRollout boundary tests, which aligns with the primary addition of a new test file for isInRollout functionality; however, it omits substantial refactoring changes including TypeScript error fixes, variable renaming in client.ts, and test import modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test-isInRollout-10179981082815151273

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.

Copy link

@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/__tests__/isInRollout.test.ts (1)

24-27: Test description could be clearer.

The description says "less than or equal to the hash modulo" but the actual condition is intForUUID % 100 < rollout (strictly less than). When rollout equals 79, 79 < 79 is false. Consider rephrasing to "when rollout equals the hash modulo" for clarity.

✏️ Suggested rewording
-  test('returns false when rollout is less than or equal to the hash modulo (79)', () => {
-    // 79 < 79 is false
+  test('returns false when rollout equals the hash modulo (79)', () => {
+    // intForUUID % 100 = 79, so 79 < 79 is false
     expect(isInRollout(79)).toBe(false);
   });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/__tests__/isInRollout.test.ts` around lines 24 - 27, Update the test
description to accurately reflect the condition being tested: change the wording
from "returns false when rollout is less than or equal to the hash modulo" to
something like "returns false when rollout equals the hash modulo (79)"; locate
the test for isInRollout in src/__tests__/isInRollout.test.ts (the test that
calls isInRollout(79)) and update its string description and optional inline
comment to mention "equals" rather than "less than or equal to" so it matches
the actual comparison performed by intForUUID % 100 < rollout in isInRollout.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/__tests__/isInRollout.test.ts`:
- Around line 14-18: The dynamic import in the test uses a Bun query string
('../isInRollout?deterministic') which TypeScript's resolver flags; update the
import to silence the type error by importing as unknown and asserting the shape
or by adding a single-line TS suppression: e.g., change the import in the
beforeAll block so the result is assigned with a type assertion (cast to the
module type containing isInRollout) or add a // `@ts-ignore` comment just above
the dynamic import, then extract module.isInRollout into the isInRollout
variable; reference the beforeAll block and the isInRollout symbol when making
this change.

---

Nitpick comments:
In `@src/__tests__/isInRollout.test.ts`:
- Around line 24-27: Update the test description to accurately reflect the
condition being tested: change the wording from "returns false when rollout is
less than or equal to the hash modulo" to something like "returns false when
rollout equals the hash modulo (79)"; locate the test for isInRollout in
src/__tests__/isInRollout.test.ts (the test that calls isInRollout(79)) and
update its string description and optional inline comment to mention "equals"
rather than "less than or equal to" so it matches the actual comparison
performed by intForUUID % 100 < rollout in isInRollout.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d754f053-020a-495d-9150-482e8719ef6d

📥 Commits

Reviewing files that changed from the base of the PR and between 010e889 and 3682d2f.

📒 Files selected for processing (2)
  • src/__tests__/isInRollout.test.ts
  • src/__tests__/setup.ts

… variable

- Added `// @ts-ignore` to dynamic query imports (`import('../core?error')`, etc.) which fixes `TS2307: Cannot find module` in `tsc`.
- Renamed `info` variable to `updateInfo` in `downloadUpdate` arguments inside `src/client.ts` to prevent "already declared in upper scope" warnings.

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

@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)
patch_tests.sh (1)

1-3: Add fail-fast safeguards to detect silent patch failures.

The script lacks error handling and post-condition checks. Because sed exits 0 even when a pattern fails to match, undetected formatting drift in the test files can leave imports only partially patched. Add a shebang, strict mode, and verification checks to catch mismatches immediately.

Suggested hardening
+#!/usr/bin/env sh
+set -eu
+
 sed -i 's/await import('\''\.\.\/isInRollout?deterministic'\'')/await import('\''\.\.\/isInRollout?deterministic'\'' \/\* `@vite-ignore` \*\/) as any/' src/__tests__/isInRollout.test.ts
 sed -i 's/await import('\''\.\.\/core?error'\'')/await import('\''\.\.\/core?error'\'' \/\* `@vite-ignore` \*\/) as any/' src/__tests__/core.test.ts
 sed -i 's/await import('\''\.\.\/core?success'\'')/await import('\''\.\.\/core?success'\'' \/\* `@vite-ignore` \*\/) as any/' src/__tests__/core.test.ts
+
+grep -Fq "await import('../isInRollout?deterministic' /* `@vite-ignore` */) as any" src/__tests__/isInRollout.test.ts
+grep -Fq "await import('../core?error' /* `@vite-ignore` */) as any" src/__tests__/core.test.ts
+grep -Fq "await import('../core?success' /* `@vite-ignore` */) as any" src/__tests__/core.test.ts
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@patch_tests.sh` around lines 1 - 3, Add a shebang and strict shell options
(set -euo pipefail) at the top of the script, run each sed replacement as you
already do, then verify each replacement succeeded by checking for absence of
the original patterns (e.g. "await import('../isInRollout?deterministic')",
"await import('../core?error')", "await import('../core?success')") and presence
of the expected patched strings (with "/* `@vite-ignore` */) as any"); if any
verification fails, print a clear error mentioning which pattern failed and exit
non‑zero so the CI fails fast. Ensure the checks run after all sed invocations
so partial/missed patches are detected.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@patch_client.sh`:
- Around line 1-4: The patch script uses fragile line-numbered sed edits and
fails silently when the expected snippets aren't present; update patch_client.sh
to perform content-based replacements for the tokens "info: CheckResult" ->
"updateInfo: CheckResult" and "info.updateUrl"/"info.hash" ->
"updateInfo.updateUrl"/"updateInfo.hash" by matching and replacing those exact
strings in src/client.ts (use global/content-aware sed or perl regex) and then
assert each replacement succeeded (e.g., check the file diff, count
replacements, or verify the new strings exist) and exit non‑zero if any expected
replacement did not occur so the script cannot succeed without applying the
intended edits.

---

Nitpick comments:
In `@patch_tests.sh`:
- Around line 1-3: Add a shebang and strict shell options (set -euo pipefail) at
the top of the script, run each sed replacement as you already do, then verify
each replacement succeeded by checking for absence of the original patterns
(e.g. "await import('../isInRollout?deterministic')", "await
import('../core?error')", "await import('../core?success')") and presence of the
expected patched strings (with "/* `@vite-ignore` */) as any"); if any
verification fails, print a clear error mentioning which pattern failed and exit
non‑zero so the CI fails fast. Ensure the checks run after all sed invocations
so partial/missed patches are detected.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2e02822a-ce02-4735-85c0-06f058df6459

📥 Commits

Reviewing files that changed from the base of the PR and between 3682d2f and d20de87.

📒 Files selected for processing (6)
  • patch_client.sh
  • patch_client2.sh
  • patch_tests.sh
  • src/__tests__/core.test.ts
  • src/__tests__/isInRollout.test.ts
  • src/client.ts
✅ Files skipped from review due to trivial changes (1)
  • src/tests/core.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/tests/isInRollout.test.ts

Comment on lines +1 to +4
sed -i '365s/info: CheckResult/updateInfo: CheckResult/' src/client.ts
sed -i '368s/info.updateUrl/updateInfo.updateUrl/' src/client.ts
sed -i '369s/info.hash/updateInfo.hash/' src/client.ts
sed -i '381s/info.hash/updateInfo.hash/' src/client.ts
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

echo "== addressed lines in src/client.ts =="
sed -n '365p;368p;369p;381p' src/client.ts

echo
echo "== old identifiers still present? =="
rg -n "info: CheckResult|info\\.updateUrl|info\\.hash" src/client.ts || true

Repository: reactnativecn/react-native-update

Length of output: 214


These line-numbered rewrites are already out of sync with src/client.ts.

On the checked-in file, Lines 368, 369, and 381 no longer contain the info.updateUrl / info.hash text this script expects, so it can exit successfully while applying nothing. Use content-based replacements and assert that each rewrite happened.

Suggested direction
-sed -i '365s/info: CheckResult/updateInfo: CheckResult/' src/client.ts
-sed -i '368s/info.updateUrl/updateInfo.updateUrl/' src/client.ts
-sed -i '369s/info.hash/updateInfo.hash/' src/client.ts
-sed -i '381s/info.hash/updateInfo.hash/' src/client.ts
+sed -i 's/info: CheckResult/updateInfo: CheckResult/' src/client.ts
+sed -i 's/} = info;/} = updateInfo;/' src/client.ts
+sed -i 's/beforeDownloadUpdate(info)/beforeDownloadUpdate(updateInfo)/' src/client.ts
+sed -i 's/if (!info.update || !hash) {/if (!updateInfo.update || !hash) {/' src/client.ts
+grep -Fq 'updateInfo: CheckResult' src/client.ts
+grep -Fq '} = updateInfo;' src/client.ts
+grep -Fq 'beforeDownloadUpdate(updateInfo)' src/client.ts
+grep -Fq 'if (!updateInfo.update || !hash) {' src/client.ts
📝 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
sed -i '365s/info: CheckResult/updateInfo: CheckResult/' src/client.ts
sed -i '368s/info.updateUrl/updateInfo.updateUrl/' src/client.ts
sed -i '369s/info.hash/updateInfo.hash/' src/client.ts
sed -i '381s/info.hash/updateInfo.hash/' src/client.ts
sed -i 's/info: CheckResult/updateInfo: CheckResult/' src/client.ts
sed -i 's/} = info;/} = updateInfo;/' src/client.ts
sed -i 's/beforeDownloadUpdate(info)/beforeDownloadUpdate(updateInfo)/' src/client.ts
sed -i 's/if (!info.update || !hash) {/if (!updateInfo.update || !hash) {/' src/client.ts
grep -Fq 'updateInfo: CheckResult' src/client.ts
grep -Fq '} = updateInfo;' src/client.ts
grep -Fq 'beforeDownloadUpdate(updateInfo)' src/client.ts
grep -Fq 'if (!updateInfo.update || !hash) {' src/client.ts
🧰 Tools
🪛 Shellcheck (0.11.0)

[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

(SC2148)

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

In `@patch_client.sh` around lines 1 - 4, The patch script uses fragile
line-numbered sed edits and fails silently when the expected snippets aren't
present; update patch_client.sh to perform content-based replacements for the
tokens "info: CheckResult" -> "updateInfo: CheckResult" and
"info.updateUrl"/"info.hash" -> "updateInfo.updateUrl"/"updateInfo.hash" by
matching and replacing those exact strings in src/client.ts (use
global/content-aware sed or perl regex) and then assert each replacement
succeeded (e.g., check the file diff, count replacements, or verify the new
strings exist) and exit non‑zero if any expected replacement did not occur so
the script cannot succeed without applying the intended edits.

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