Skip to content

feat: 支持源码模式运行脚本链#64

Open
LevelDownRefine wants to merge 5 commits into
OneDragon-Anything:mainfrom
LevelDownRefine:lvdown/support_source_code
Open

feat: 支持源码模式运行脚本链#64
LevelDownRefine wants to merge 5 commits into
OneDragon-Anything:mainfrom
LevelDownRefine:lvdown/support_source_code

Conversation

@LevelDownRefine

@LevelDownRefine LevelDownRefine commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

变更

build_runner_command 新增源码模式支持:
非 frozen 环境下, 获得项目的根路径后运行
python ${abspath}/OneDragon-ScriptChainer/src/script_chainer/win_exe/launcher.py --onedragon --chain ...

价值

  • 本地开发可直接在源码模式运行脚本链,无需先打包 exe
  • 显著简化联调/回归测试流程,缩短验证时间

测试

进过测试,以下两种方式均成功在launcher中运行单个及全体脚本

  • 在OneDragon-ScriptChainer下测试uv run python src\script_chainer\win_exe\launcher.py
  • 在OneDragon-ScriptChainer\src下测试uv run python script_chainer\win_exe\launcher.py

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • 修复源码模式下启动异常:现在会自动生成可直接运行的启动命令与工作目录,无需先编译或打包。
    • 优化源码模式启动方式:会正确定位并加载启动器路径,确保链式任务参数(含调试索引)传递一致。
    • 改进工作目录识别:冻结/打包与源码模式下的工作目录返回更准确,提升资源加载稳定性。

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@LevelDownRefine, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 1 minute and 6 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 80a631bb-2ce9-4b55-9bbe-f0a47690f909

📥 Commits

Reviewing files that changed from the base of the PR and between c5269fa and 6317141.

📒 Files selected for processing (1)
  • src/script_chainer/utils/runner_utils.py

Walkthrough

新增 get_launcher_path() 函数定位 launcher 脚本,修改 build_runner_command() 的源码模式分支从抛出 RuntimeError 改为通过 launcher 脚本构造可执行命令,返回仓库根目录作为工作目录。

变更详情

源码模式 runner 命令实现

Layer / File(s) Summary
launcher 路径获取函数
src/script_chainer/utils/runner_utils.py
新增 one_dragon.utils.os_utils 导入,实现 get_launcher_path() 函数,基于 get_work_dir() 获取仓库工作目录,拼接并返回 src/script_chainer/win_exe/launcher.py 的完整路径。
源码模式命令构建实现
src/script_chainer/utils/runner_utils.py
修改 build_runner_command() 函数,统一先构造 common_args(包含 --onedragon --chain <chain_name>,当 script_index 非空时追加 --debug-index);冻结模式继续使用 sys.executable 并返回其所在目录;源码模式改为通过 sys.executable 执行 get_launcher_path() 指向的 launcher 脚本,返回仓库根目录作为工作目录,替换原有的 RuntimeError

估算的代码审查工作量

🎯 3 (Moderate) | ⏱️ ~20 分钟

小诗

🐇 从前源码模式只报错,
如今握起 launcher 之手~
get_launcher_path 寻根问祖,
统一命令参数新节奏,
小兔欢呼:模式真完整!🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了核心变更:为 build_runner_command() 函数添加源码模式支持,使脚本链能在非冻结环境直接运行。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit 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.

@LevelDownRefine LevelDownRefine changed the title feat(runner): 支持源码模式运行脚本链 feat: 支持源码模式运行脚本链 Jun 14, 2026

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/script_chainer/utils/runner_utils.py (1)

41-41: 💤 Low value

建议添加路径深度检查以增强健壮性。

当前实现假设文件始终位于仓库根目录下三级深度,如果文件位置发生变化或在异常环境下运行,.parents[3] 可能引发 IndexError

🛡️ 建议的防御性检查
-        repo_root = str(Path(__file__).resolve().parents[3])
+        file_path = Path(__file__).resolve()
+        if len(file_path.parents) < 4:
+            raise RuntimeError(f"无法确定仓库根目录:文件路径 {file_path} 层级不足")
+        repo_root = str(file_path.parents[3])
🤖 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 `@src/script_chainer/utils/runner_utils.py` at line 41, The current
implementation directly accesses `.parents[3]` on the resolved path without
validating that enough parent directories exist, which can raise an IndexError
if the file is not at the expected depth or runs in certain environments. Add a
defensive check before accessing `.parents[3]` to verify that the parents tuple
has at least 4 elements (indices 0-3 are valid), and either handle the
insufficient depth case gracefully (such as using a fallback value or raising a
more informative error) or validate the file location at runtime to ensure it
meets the expected directory structure requirements.
🤖 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 `@src/script_chainer/utils/runner_utils.py`:
- Around line 28-42: The module execution using python -m requires a complete
package hierarchy, but the src/__init__.py file is missing, which prevents src
from being recognized as a valid Python package. Create an empty __init__.py
file in the src/ directory to establish the proper package structure required
for the -m flag to work correctly with the command being constructed in the else
block that references sys.executable and the src.script_chainer.win_exe.launcher
module path.

---

Nitpick comments:
In `@src/script_chainer/utils/runner_utils.py`:
- Line 41: The current implementation directly accesses `.parents[3]` on the
resolved path without validating that enough parent directories exist, which can
raise an IndexError if the file is not at the expected depth or runs in certain
environments. Add a defensive check before accessing `.parents[3]` to verify
that the parents tuple has at least 4 elements (indices 0-3 are valid), and
either handle the insufficient depth case gracefully (such as using a fallback
value or raising a more informative error) or validate the file location at
runtime to ensure it meets the expected directory structure requirements.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5c7896ae-b989-452f-9d2f-d9320c77a9c3

📥 Commits

Reviewing files that changed from the base of the PR and between b7b55f9 and 36cbf80.

📒 Files selected for processing (1)
  • src/script_chainer/utils/runner_utils.py

Comment thread src/script_chainer/utils/runner_utils.py Outdated

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

Actionable comments posted: 1

🤖 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 `@src/script_chainer/utils/runner_utils.py`:
- Around line 10-11: The call to get_path_under_work_dir on line 11 incorrectly
passes repo_root (an absolute path) as the first argument, but according to the
pattern of all other call sites in the repository, this function expects only
relative path segments. The function internally calls get_work_dir() for path
construction, so remove the repo_root parameter and pass only the relative path
components ("src", "script_chainer", "win_exe", "launcher.py") to
get_path_under_work_dir. This will fix the launcher path construction failure in
source code mode that causes build_runner_command to fail.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 505449ea-a990-43b8-b87c-256b079fbc8b

📥 Commits

Reviewing files that changed from the base of the PR and between cd3ac74 and c5269fa.

📒 Files selected for processing (1)
  • src/script_chainer/utils/runner_utils.py

Comment thread src/script_chainer/utils/runner_utils.py Outdated
@LevelDownRefine

Copy link
Copy Markdown
Contributor Author

@ShadowLemoon Could you help check this pr?

@LevelDownRefine

Copy link
Copy Markdown
Contributor Author

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews resumed.

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