Skip to content

test: 补充 zip-options / i18n / user / plugin-config 测试#52

Merged
sunnylqm merged 3 commits into
masterfrom
feat/add-more-tests
Jun 8, 2026
Merged

test: 补充 zip-options / i18n / user / plugin-config 测试#52
sunnylqm merged 3 commits into
masterfrom
feat/add-more-tests

Conversation

@sunnylqm

@sunnylqm sunnylqm commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

新增测试文件

新增 4 个测试文件,32 个新测试用例,覆盖之前完全没有测试的模块。

tests/zip-options-file.test.ts (8 tests)

zipOptionsForPayloadFile — 通过真实文件系统测试魔数检测和压缩策略:

  • PNG/JPEG 文件 → 不压缩
  • JS/文本文件 → 压缩 level 9
  • Hermes 字节码 → 压缩
  • 空文件 edge case
  • entryName 覆盖路径

tests/i18n.test.ts (7 tests)

i18n t() 翻译函数:

  • 中英文翻译输出
  • 插值参数替换
  • 多参数插值
  • 未知 key fallback

tests/user.test.ts (11 tests)

userCommands login/logout/me:

  • md5 密码哈希
  • session 管理 (replaceSession + saveSession)
  • 交互式输入回退
  • 字段输出过滤 (排除 ok)

tests/plugin-config.test.ts (6 tests)

Sentry 插件检测:

  • detect() 文件系统探测
  • ios/android sentry.properties 存在性
  • bundleParams 配置验证

测试结果:234 pass, 0 fail

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suites covering internationalization (translation lookup and interpolation across languages), plugin detection behavior for Sentry configuration, user authentication commands (login/logout/me and session handling), and file compression option selection based on file contents and extensions to improve reliability across scenarios.

…and plugin-config

New test files:
- tests/zip-options-file.test.ts: zipOptionsForPayloadFile with real files (magic bytes, extensions, empty files)
- tests/i18n.test.ts: t() translation function (en/zh, interpolation, fallback)
- tests/user.test.ts: userCommands login/logout/me with API mocking
- tests/plugin-config.test.ts: sentry plugin detection via filesystem

234 tests pass, 0 failures.
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 517144f6-a022-424f-8c35-45fba847be74

📥 Commits

Reviewing files that changed from the base of the PR and between 076c8e0 and 619360e.

📒 Files selected for processing (4)
  • tests/i18n.test.ts
  • tests/plugin-config.test.ts
  • tests/user.test.ts
  • tests/zip-options-file.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • tests/i18n.test.ts
  • tests/zip-options-file.test.ts
  • tests/user.test.ts
  • tests/plugin-config.test.ts

📝 Walkthrough

Walkthrough

This PR adds four Bun test suites covering i18n translation behavior, Sentry plugin detection, user authentication commands, and file compression option selection.

Changes

Unit Test Coverage

Layer / File(s) Summary
i18n Translation Tests
tests/i18n.test.ts
Tests t() translations across en and zh, validates parameter interpolation (single and multiple), unknown-key fallback behavior, and confirms output differs by language.
Plugin Configuration Tests
tests/plugin-config.test.ts
Tests Sentry plugin presence, bundleParams shape ({ sentry: true, sourcemap: true }), and detect() behavior by creating temporary directories with none/iOS/Android/both sentry.properties file combinations.
User Command Tests
tests/user.test.ts
Tests userCommands for login, logout, and me operations with mocked API calls and user prompts; verifies MD5 password hashing, session management call order, prompting fallback, and console output filtering.
File Compression Options Tests
tests/zip-options-file.test.ts
Tests zipOptionsForPayloadFile compression detection using file magic bytes (PNG, JPEG, Hermes bytecode) and extensions (.js, .txt, .dat, .mp4), including override behavior with custom entryName and filePath fallback.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Four test suites hop into place,
New checks that stitch each codepath's seam,
Translations, plugins, users, files—embrace,
Console logs and bytes now meet the beam.
Tests hum softly; the repo dreams.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 main change: adding comprehensive tests for four previously untested modules (zip-options, i18n, user, plugin-config).
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 feat/add-more-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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 9

🤖 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/i18n.test.ts`:
- Around line 48-54: The test currently only asserts a non-empty string for
unknown keys; update the test in the 'returns the key itself or a fallback for
an unknown key' case to assert the exact fallback by checking that
t('this_key_does_not_exist_at_all') strictly equals the input key (i.e., result
=== 'this_key_does_not_exist_at_all') after calling i18next.changeLanguage('en')
so the test fails if a different fallback is returned; reference the existing
test block, the t(...) call, and the literal key string to locate and change the
expectation.
- Line 7: Await the i18next language switch and tighten the unknown-key
assertion: change the test to await i18next.changeLanguage('en') before calling
i18next.t(...) to ensure deterministic results, and update the unknown-key test
to assert that i18next.t('some_missing_key') returns the key itself (i.e. equals
'some_missing_key') instead of merely checking for a non-empty string; refer to
i18next.changeLanguage and i18next.t in tests/i18n.test.ts to locate and fix the
two spots.

In `@tests/plugin-config.test.ts`:
- Around line 1-7: The import from 'bun:test' is spread across multiple lines
and fails Biome's single-line import rule; collapse it into a single-line import
so the named symbols (afterEach, beforeEach, describe, expect, test) are
imported in one statement from 'bun:test' (i.e., replace the multi-line import
block with a single-line import that lists those identifiers and imports from
'bun:test').
- Around line 25-29: The test currently force-unwraps the result with a non-null
assertion on sentryPlugin which can throw before the assertion runs; remove the
`!` so `sentryPlugin` is allowed to be undefined (e.g., const sentryPlugin =
plugins.find(...)) and let the existing test
`expect(sentryPlugin).toBeDefined()` fail naturally; update any TypeScript
typing only if needed so the variable can be undefined rather than
force-unwrapped.

In `@tests/user.test.ts`:
- Around line 1-8: Run Biome's automated organize-imports and formatting on the
test file to resolve CI failures: re-run the import organizer on the top import
statement that includes afterEach, beforeEach, describe, expect, spyOn, test so
the named imports are ordered per Biome rules, and apply Biome/formatting to fix
the malformed block around lines 121-126 (the test/assert block causing
formatting errors); you can do this by running Biome (e.g., biome format --apply
or biome check --apply) on the file and committing the resulting changes.
- Around line 89-93: Remove the unused callCount variable and its increment
inside the mock implementation to satisfy the linter: delete the `let callCount
= 0;` declaration and the `callCount++;` line in the
`questionSpy.mockImplementation(async (prompt: string) => { ... })` block so the
mock only returns the expected values without tracking an unused counter.
- Around line 80-86: The test "calls saveSession after replaceSession" only
asserts saveSessionSpy was called; change it to assert call order by ensuring
replaceSessionSpy was called before saveSessionSpy after invoking
userCommands.login (e.g., compare replaceSessionSpy.mock.invocationCallOrder[0]
and saveSessionSpy.mock.invocationCallOrder[0] or use a Jest helper that checks
call order). Reference the existing spies saveSessionSpy and replaceSessionSpy
and update the expectation(s) to fail if saveSessionSpy executes before
replaceSessionSpy.

In `@tests/zip-options-file.test.ts`:
- Around line 1-8: The import block in tests/zip-options-file.test.ts
incorrectly imports the unused symbol ZIP_ENTRY_SNIFF_BYTES and the imports are
not organized; remove ZIP_ENTRY_SNIFF_BYTES from the import list and
reorder/organize the imports (e.g., group and alphabetize module imports) so
only used symbols like zipOptionsForPayloadFile are imported from
'../src/utils/zip-options' and the top-level imports (bun:test, fs, os, path)
follow the project's import ordering rules.
- Around line 23-58: The byte-array literals used in Buffer.from calls
(pngMagic, hermesMagic, jpegMagic in tests/zip-options-file.test.ts) are not
formatted to match the Biome formatter; run the repository formatter (Biome/your
project's format script) or your editor's autoformat on that file and commit the
resulting changes so the magic-byte arrays are rewrapped/spaced according to the
formatter, ensuring Buffer.from([...]) lines for pngMagic, hermesMagic and
jpegMagic match CI expectations.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: db493286-561a-4f68-9e02-8ee0d314ec62

📥 Commits

Reviewing files that changed from the base of the PR and between c4490f6 and 076c8e0.

📒 Files selected for processing (4)
  • tests/i18n.test.ts
  • tests/plugin-config.test.ts
  • tests/user.test.ts
  • tests/zip-options-file.test.ts

Comment thread tests/i18n.test.ts Outdated
Comment thread tests/i18n.test.ts Outdated
Comment thread tests/plugin-config.test.ts Outdated
Comment thread tests/plugin-config.test.ts Outdated
Comment thread tests/user.test.ts Outdated
Comment thread tests/user.test.ts
Comment thread tests/user.test.ts Outdated
Comment thread tests/zip-options-file.test.ts Outdated
Comment thread tests/zip-options-file.test.ts
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 3 file(s) based on 4 unresolved review comments.

Files modified:

  • tests/i18n.test.ts
  • tests/plugin-config.test.ts
  • tests/user.test.ts

Commit: 619360e6c17e91f70a3c8b78a0ed15476dc9cfeb

The changes have been pushed to the feat/add-more-tests branch.

Time taken: 3m 55s

Fixed 3 file(s) based on 4 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
@sunnylqm sunnylqm merged commit 9744312 into master Jun 8, 2026
4 checks passed
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