Skip to content

Add ecapture mock, fake sing-box tun bypass, and use /sdcard/Download for AVD pushes#16

Merged
LIghtJUNction merged 1 commit into
mainfrom
codex/issue
Jun 24, 2026
Merged

Add ecapture mock, fake sing-box tun bypass, and use /sdcard/Download for AVD pushes#16
LIghtJUNction merged 1 commit into
mainfrom
codex/issue

Conversation

@LIghtJUNction

@LIghtJUNction LIghtJUNction commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Improve fake Magisk smoke test coverage by faking additional runtime binaries and avoiding host-only tun checks during smoke runs.
  • Make AVD file pushes more reliable by using a stable user-writable path on the emulator (/sdcard/Download/MagicNet) instead of /data/local/tmp.
  • Ensure temporary files pushed to the device are cleaned up after use to reduce stale state on the emulator.

Description

  • Append a small snippet to lib/kamfw/__singbox__.sh in the fake Magisk module that defines singbox_tun() to skip host /dev/net/tun checks when MAGICNET_FAKE_LOG is set.
  • Add a mock implementation for ecapture via write_mock ecapture and copy the mock into the module ($MODDIR/bin/ecapture) so the smoke environment can exercise ecapture calls.
  • Ensure the fake environment copies ecapture and pidof mocks into $MODDIR/bin and add lightweight PID tracking for the fake sing-box process in mocks.
  • Change AVD push/install paths in scripts/kam-test.sh to use /sdcard/Download/MagicNet for temporary device files in install_zip_on_avd, push_x86_core_binaries, and prepare_avd_node_fixtures, including creating the directory before pushes and removing pushed artifacts after copying into module locations.
  • Remove the pushed module zip from the device after installation and remove temporary pushed files after copying the sing-box binary and fixture JSON to module locations.

Testing

  • No automated tests were executed as part of this change.

Codex Task

Summary by Sourcery

通过在模拟环境中mock更多二进制文件,并在模拟器上使用更可靠的临时路径,提升 fake Magisk 烟雾测试环境的覆盖率并稳定 AVD 文件处理。

新功能:

  • 当启用 MAGICNET_FAKE_LOG 时,在 Magisk mock 环境中添加一个 fake sing-box tun 覆盖。
  • 在 fake Magisk 模块的 bin 目录中引入一个 mock ecapture 二进制文件,并包含基础的子命令处理。

增强点:

  • 将 mock ecapturepidof 二进制文件复制到模块的 bin 目录中,以在烟雾测试中更好地模拟运行时行为。
  • 调整 AVD 安装和推送流程,将 /sdcard/Download/MagicNet 用作模块压缩包、核心二进制文件和夹具配置的稳定临时目录,并在使用后清理临时产物。
Original summary in English

Summary by Sourcery

Improve fake Magisk smoke environment coverage and stabilize AVD file handling by mocking additional binaries and using a more reliable temporary path on the emulator.

New Features:

  • Add a fake sing-box tun override in the Magisk mock environment when MAGICNET_FAKE_LOG is enabled.
  • Introduce a mock ecapture binary, including basic subcommand handling, into the fake Magisk module bin directory.

Enhancements:

  • Copy mock ecapture and pidof binaries into the module bin directory to better simulate runtime behavior in smoke tests.
  • Adjust AVD install and push workflows to use /sdcard/Download/MagicNet as a stable temporary directory for module zips, core binaries, and fixture configs, with cleanup of temporary artifacts after use.

@sourcery-ai

sourcery-ai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

更新 fake Magisk smoke 环境,以更好地模拟 sing-box/ecapture 的行为,并调整 AVD 测试脚本,将模块 zip、二进制文件和 fixtures 的临时目录从 /data/local/tmp 切换到更可靠且干净的 /sdcard/Download/MagicNet

/sdcard/Download/MagicNet 下 AVD 临时文件处理流程图

flowchart TD
    A[install_zip_on_avd / push_x86_core_binaries / prepare_avd_node_fixtures] --> B[adb shell mkdir -p /sdcard/Download/MagicNet]
    B --> C[adb push artifacts to /sdcard/Download/MagicNet]
    C --> D[adb shell install module zip or copy binaries/fixtures into module paths]
    D --> E[adb shell rm /sdcard/Download/MagicNet/module-zip.zip]
    D --> F[adb shell rm /sdcard/Download/MagicNet/pushed binaries and fixtures]
    E --> G[AVD ready for tests with clean temp dir]
    F --> G
Loading

File-Level Changes

Change Details Files
增强 fake Magisk 中的 sing-box 行为,在 fake smoke 环境运行时绕过宿主机 tun 检查。
  • 在 fake Magisk 模块中的 sing-box 包装脚本里追加一段 shell 代码片段,当设置了 MAGICNET_FAKE_LOG 时有条件地重新定义 singbox_tun()
  • 在该假模式下记录日志,说明正在跳过宿主机 /dev/net/tun 检查
scripts/fake-magisk-smoke.sh
引入 ecapture mock,并确保关键 mock 安装到 fake Magisk 模块的 bin 目录中。
  • 定义一个 write_mock ecapture 脚本,伪造版本输出以及基本的 tls / gotls / nspr 子命令,并包含短暂的 sleep 和成功退出码
  • 将生成的 ecapture mock 复制到 $MODDIR/bin 中,与现有的 sing-box 和其他 mock 并存
  • 保留 pidof mock 以及现有的 sing-box mock 行为
scripts/fake-magisk-smoke.sh
将 AVD 模块 zip 安装流程切换为使用 /sdcard/Download/MagicNet,并在使用后清理临时产物。
  • 修改 install_zip_on_avd,将模块 zip 推送到 /sdcard/Download/MagicNet/MagicNet.zip,而不是 /data/local/tmp
  • 在推送前确保设备上的临时目录已存在,并在 Magisk CLI 安装完成后删除已推送的 zip
scripts/kam-test.sh
在 AVD 上使用稳定的 /sdcard/Download/MagicNet 路径来推送 sing-box 二进制文件和 fixture JSON,并确保在复制到模块目录后将其删除。
  • 更新 push_x86_core_binaries,将 sing-box 推送到 /sdcard/Download/MagicNet,再从那里复制到模块 bin 路径,然后删除临时文件
  • 更新 prepare_avd_node_fixtures,将修改后的 sing-box 配置 JSON 推送到 /sdcard/Download/MagicNet,再复制到模块配置路径,随后删除临时 JSON 文件
  • 确保在这些流程中每次推送前都会创建 /sdcard/Download/MagicNet 目录
scripts/kam-test.sh

Tips and commands

Interacting with Sourcery

  • 触发新一次评审: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的评审评论即可。
  • 从评审评论生成 GitHub issue: 在某条评审评论下回复,请 Sourcery 从该评论创建 issue。你也可以直接回复 @sourcery-ai issue 来从该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文任意位置写上 @sourcery-ai summary,即可在该位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来在任何时候(重新)生成摘要。
  • 生成评审者指南: 在 pull request 中评论 @sourcery-ai guide,即可在任何时候(重新)生成评审者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 取消所有 Sourcery 评审: 在 pull request 中评论 @sourcery-ai dismiss,即可取消所有现有的 Sourcery 评审。如果你想从头开始一次新的评审,这尤其有用——不要忘记再评论 @sourcery-ai review 以触发新的评审!

Customizing Your Experience

打开你的 dashboard 以:

  • 启用或禁用评审特性,例如 Sourcery 自动生成的 pull request 摘要、评审者指南等。
  • 更改评审语言。
  • 添加、移除或编辑自定义评审说明。
  • 调整其他评审设置。

Getting Help

Original review guide in English

Reviewer's Guide

Updates the fake Magisk smoke environment to better simulate sing-box/ecapture behavior and adjusts AVD test scripts to use a more reliable, cleaned-up /sdcard/Download/MagicNet temp area instead of /data/local/tmp for module zips, binaries, and fixtures.

Flow diagram for AVD temp file handling under /sdcard/Download/MagicNet

flowchart TD
    A[install_zip_on_avd / push_x86_core_binaries / prepare_avd_node_fixtures] --> B[adb shell mkdir -p /sdcard/Download/MagicNet]
    B --> C[adb push artifacts to /sdcard/Download/MagicNet]
    C --> D[adb shell install module zip or copy binaries/fixtures into module paths]
    D --> E[adb shell rm /sdcard/Download/MagicNet/module-zip.zip]
    D --> F[adb shell rm /sdcard/Download/MagicNet/pushed binaries and fixtures]
    E --> G[AVD ready for tests with clean temp dir]
    F --> G
Loading

File-Level Changes

Change Details Files
Enhance fake Magisk sing-box behavior to bypass host tun checks when running in the fake smoke environment.
  • Append a shell snippet to the sing-box wrapper script in the fake Magisk module to conditionally redefine singbox_tun() when MAGICNET_FAKE_LOG is set
  • Log that host /dev/net/tun checks are being skipped in this fake mode
scripts/fake-magisk-smoke.sh
Introduce an ecapture mock and ensure key mocks are installed into the fake Magisk module bin directory.
  • Define a write_mock ecapture script that fakes version output and basic tls/gotls/nspr subcommands with short sleeps and success exits
  • Copy the generated ecapture mock into $MODDIR/bin alongside existing sing-box and other mocks
  • Retain the pidof mock and existing sing-box mock behavior
scripts/fake-magisk-smoke.sh
Switch AVD module zip installation to use /sdcard/Download/MagicNet and clean up temporary artifacts after use.
  • Change install_zip_on_avd to push the module zip into /sdcard/Download/MagicNet/MagicNet.zip instead of /data/local/tmp
  • Ensure the device temp directory exists before pushing and remove the pushed zip after Magisk CLI installation completes
scripts/kam-test.sh
Use a stable /sdcard/Download/MagicNet path for pushing sing-box binaries and fixture JSONs on AVD and ensure they are removed after copying into module locations.
  • Update push_x86_core_binaries to push sing-box to /sdcard/Download/MagicNet, copy from there into the module bin path, and delete the temp file
  • Update prepare_avd_node_fixtures to push the modified sing-box config JSON into /sdcard/Download/MagicNet, copy it into the module config path, and delete the temp JSON file
  • Ensure the /sdcard/Download/MagicNet directory is created before each push in these flows
scripts/kam-test.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@LIghtJUNction LIghtJUNction merged commit b70aa35 into main Jun 24, 2026
3 checks passed
@LIghtJUNction LIghtJUNction deleted the codex/issue branch June 24, 2026 19:09

@sourcery-ai sourcery-ai 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.

Hey - 我在这里给出了一些高层次的反馈:

  • /sdcard/Download/MagicNet 路径及其相关的设置/清理逻辑现在在 kam-test.sh 的多个函数中都有重复;可以考虑把这部分逻辑集中到一个共享的辅助函数中(例如 device_tmp_dirensure_device_tmp_dir),以减少重复,同时将来如果需要修改路径时只需要改一处。
  • 追加在 __singbox__.sh 里的 singbox_tun() 覆盖实现目前只由 MAGICNET_FAKE_LOG 来控制;如果这个函数在 fake-smoke 场景之外也会被使用,建议让该覆盖更明确地与 fake 环境绑定(比如检查一个专门的 fake 模式开关,或者仅在 fake 运行时去 source 它),从而降低被意外复用的可能性。
给 AI Agents 的提示
请根据这次代码评审中的评论进行修改:

## 总体评论
- `/sdcard/Download/MagicNet` 路径及其相关的设置/清理逻辑现在在 `kam-test.sh` 的多个函数中都有重复;可以考虑把这部分逻辑集中到一个共享的辅助函数中(例如 `device_tmp_dir``ensure_device_tmp_dir`),以减少重复,同时将来如果需要修改路径时只需要改一处。
- 追加在 `__singbox__.sh` 里的 `singbox_tun()` 覆盖实现目前只由 `MAGICNET_FAKE_LOG` 来控制;如果这个函数在 fake-smoke 场景之外也会被使用,建议让该覆盖更明确地与 fake 环境绑定(比如检查一个专门的 fake 模式开关,或者仅在 fake 运行时去 source 它),从而降低被意外复用的可能性。

Sourcery 对开源项目免费——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审质量。
Original comment in English

Hey - I've left some high level feedback:

  • The /sdcard/Download/MagicNet path and its setup/cleanup logic are now duplicated across several functions in kam-test.sh; consider centralizing this into a shared helper (e.g., device_tmp_dir + ensure_device_tmp_dir) to reduce repetition and keep future path changes in one place.
  • The appended singbox_tun() override in __singbox__.sh is guarded only by MAGICNET_FAKE_LOG; if this function is used outside the fake-smoke context, it may be helpful to make the override more explicitly tied to the fake environment (e.g., by checking a dedicated fake-mode flag or sourcing it only for fake runs) to reduce the chance of accidental reuse.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `/sdcard/Download/MagicNet` path and its setup/cleanup logic are now duplicated across several functions in `kam-test.sh`; consider centralizing this into a shared helper (e.g., `device_tmp_dir` + `ensure_device_tmp_dir`) to reduce repetition and keep future path changes in one place.
- The appended `singbox_tun()` override in `__singbox__.sh` is guarded only by `MAGICNET_FAKE_LOG`; if this function is used outside the fake-smoke context, it may be helpful to make the override more explicitly tied to the fake environment (e.g., by checking a dedicated fake-mode flag or sourcing it only for fake runs) to reduce the chance of accidental reuse.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant