Skip to content

fix(task): 启动参数含引号或空格时不再把引号一起传给进程 - #866

Open
beichen24a1 wants to merge 1 commit into
AUTO-MAS-Project:devfrom
beichen24a1:fix/split-args-quote-handling
Open

beichen24a1 wants to merge 1 commit into
AUTO-MAS-Project:devfrom
beichen24a1:fix/split-args-quote-handling

Conversation

@beichen24a1

@beichen24a1 beichen24a1 commented Sep 18, 2026

Copy link
Copy Markdown

现象:用户在脚本里配的启动参数(例如 --path "C:\Program Files\Game\game.exe")在界面上看着正常、保存也成功,运行时却不生效。

  • 根因:split_args()shlex.split(..., posix=False),引号会被留在词元里——--flag "a b" 拆成 ['"a b"'],交给 CreateProcess 后游戏收到的是一个带引号的参数,多半当无效参数丢掉
  • 而配置校验用的 ArgumentValidator 走 posix 模式(引号只用于分组),所以界面校验一切正常,这类参数只在运行时静默失效
  • 改成 posix 解析但关掉转义处理(shlex.shlex + escape = ""):引号只用于分组,Windows 路径里的反斜杠原样保留,不会像裸 posix 模式那样被当转义符吃掉

验证

python.exe 当假游戏,把 MAS 的真实启动链路(split_argsProcessManager.open_process → 进程实际 argv)整条跑穿,不启动任何真实游戏客户端

输入(界面里填的) 修复前进程收到 修复后进程收到
-Res=1920x1080 ["-Res=1920x1080"] ["-Res=1920x1080"](逐字不变)
-Res=1920x1080 --windowed ["-Res=1920x1080", "--windowed"] 同上(不变)
--path "C:\Program Files\Game\game.exe" ["--path", "\"C:\\Program Files\\Game\\game.exe\""] ← 带引号 ["--path", "C:\\Program Files\\Game\\game.exe"]
--flag "a b" --end ['--flag', '"a b"', '--end'] ← 带引号 ['--flag', 'a b', '--end']
--name 'my game' -v ["--name", "'my game'", "-v"] ← 带引号 ["--name", "my game", "-v"]

其余检查:

  • ruff check / ruff format --check app/task/proxy_helpers.py:通过
  • python -m pytest tests/task -q:17 passed
  • python -m pytest tests --collect-only -q:308 collected,exit 0

说明

  • 带引号/空格的参数属于行为变更(从"带着引号发出去"变成"按 shell 语义分组后传递"),这正是本次要修的;无引号参数(绝大多数用法)行为逐字不变。
  • 按仓库最新口径,bug 边界的验证属一次性产物,未随 PR 提交测试文件;上表就是本次的验证记录。

Sourcery 摘要

修复任务启动参数解析问题,确保带引号的值能够正确分组,同时不会将引号字符传递给启动的进程。

错误修复:

  • 修复包含引号或空格的启动参数被传递给启动进程时仍包含引号字符的问题,避免这些参数被忽略或错误解释。

功能增强:

  • 按照 Shell 分组语义解析带引号的参数时,保留 Windows 路径中的反斜杠。

日常维护:

  • 为启动参数解析修复添加变更日志条目。
Original summary in English

Summary by Sourcery

Fix task startup argument parsing so quoted values are grouped correctly without passing quote characters to launched processes.

Bug Fixes:

  • Fix startup arguments containing quotes or spaces being passed to launched processes with the quote characters included, causing them to be ignored or misinterpreted.

Enhancements:

  • Preserve backslashes in Windows paths while parsing quoted arguments according to shell grouping semantics.

Chores:

  • Add a changelog entry for the startup-argument parsing fix.

split_args 用 shlex.split(posix=False) 拆分,引号会被留在词元里:`--flag "a b"` 拆成
`['"a b"']`,交给 CreateProcess 后游戏收到的是一个带引号的参数,多半当无效参数丢掉。
而配置校验用的 ArgumentValidator 走 posix 模式,界面上看着一切正常、保存也成功,于是这类
参数只在运行时静默失效——「界面里还在、跑起来不生效」。

改成 posix 解析但关掉转义处理(shlex.shlex + escape=""):引号只用于分组,Windows 路径里
的反斜杠原样保留,不会像裸 posix 模式那样被当转义符吃掉。

验证(用 python.exe 当假游戏,把 MAS 的真实启动链路 split_args → ProcessManager.
open_process → 进程 argv 跑穿,不启动真实游戏客户端):
- `-Res=1920x1080` 等无引号参数:进程收到的 argv 与修复前逐字相同
- `--path "C:\Program Files\Game\game.exe"`:修复前进程收到带引号的整个串,修复后收到
  `C:\Program Files\Game\game.exe`(反斜杠保留)
- `--flag "a b"`:修复前 `'"a b"'`,修复后 `a b`;`--name 'my game'` 同理
- ruff check / ruff format --check app/task/proxy_helpers.py:通过
- python -m pytest tests/task -q:17 passed
- python -m pytest tests --collect-only -q:308 collected,exit 0

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

Sorry @beichen24a1, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 days and 5 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 18, 2026

Copy link
Copy Markdown
审查者指南(在较小的 PR 中折叠)

审查者指南

本 PR 修复启动参数运行时解析与界面校验语义不一致的问题:通过 POSIX 分组规则并禁用转义处理,让带空格或引号的参数以去除包裹引号、保留 Windows 反斜杠的形式传递给进程,同时记录该行为修复。验证覆盖真实启动链路及现有任务测试,但边界验证未作为测试文件提交。

修正后的任务参数解析时序图

sequenceDiagram
    participant Task as Task
    participant split_args as split_args
    participant ProcessManager as ProcessManager
    participant Game as TargetProcess

    Task->>split_args: split_args(raw)
    split_args->>split_args: shlex.shlex(value, posix=True)
    split_args->>split_args: lexer.escape = ""
    split_args-->>Task: list[str] without grouping quotes
    Task->>ProcessManager: open_process(args)
    ProcessManager->>Game: CreateProcess(args)
    Game-->>ProcessManager: argv preserves spaces and backslashes
Loading

文件级变更

变更 详细信息 文件
调整启动参数解析,使引号仅用于分组且保留 Windows 路径中的反斜杠。
  • shlex.split(..., posix=False) 替换为 shlex.shlex 的 POSIX 解析模式。
  • 禁用转义处理,确保反斜杠原样传递,同时去除包裹参数的引号。
  • 保留空输入处理及无引号参数的逐字行为。
app/task/proxy_helpers.py
补充该修复的变更记录。
  • 新增启动参数引号和空格处理修复的 changelog 条目。
changelog.d/fix-split-args-quote-handling.fix.md

提示和命令

与 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 以触发新的审查!

自定义你的使用体验

访问你的 仪表板 以:

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

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

本 PR 修复启动参数运行时解析与界面校验语义不一致的问题:通过 POSIX 分组规则并禁用转义处理,让带空格或引号的参数以去除包裹引号、保留 Windows 反斜杠的形式传递给进程,同时记录该行为修复。验证覆盖真实启动链路及现有任务测试,但边界验证未作为测试文件提交。

Sequence diagram for corrected task argument parsing

sequenceDiagram
    participant Task as Task
    participant split_args as split_args
    participant ProcessManager as ProcessManager
    participant Game as TargetProcess

    Task->>split_args: split_args(raw)
    split_args->>split_args: shlex.shlex(value, posix=True)
    split_args->>split_args: lexer.escape = ""
    split_args-->>Task: list[str] without grouping quotes
    Task->>ProcessManager: open_process(args)
    ProcessManager->>Game: CreateProcess(args)
    Game-->>ProcessManager: argv preserves spaces and backslashes
Loading

File-Level Changes

Change Details Files
调整启动参数解析,使引号仅用于分组且保留 Windows 路径中的反斜杠。
  • shlex.split(..., posix=False) 替换为 shlex.shlex 的 POSIX 解析模式。
  • 禁用转义处理,确保反斜杠原样传递,同时去除包裹参数的引号。
  • 保留空输入处理及无引号参数的逐字行为。
app/task/proxy_helpers.py
补充该修复的变更记录。
  • 新增启动参数引号和空格处理修复的 changelog 条目。
changelog.d/fix-split-args-quote-handling.fix.md

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

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