Repository navigation
Fix first bug-fix tutorial checks in Python safe-path mode - #9305
Conversation
Signed-off-by: LoopX Agent <[email protected]>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
首次使用教程的读者只复制 cart.py 和 checks.py,按说明运行 Python。 在通常环境下原版执行六项检查。开启安全路径后,原版可在导入 cart 时退出。同名模块位于搜索路径时还可能运行另一份实现。 用同目录的 cart.py 运行原有六项断言,让首次运行产生空车和恰好达到免邮门槛的两项预期失败。修好 cart.py 后应全部通过。
把确切版本的两个文件复制到 checkout 外的全新目录,分别使用 Python 3.11、3.12、3.13 和 3.14。 候选头 64 次运行均达到原六项检查。每个未修副本恰好两项失败,退出 1。只修空车与等于门槛的规则后,每次六项全过,退出 0。
分别启用 PYTHONSAFEPATH、-P 和 -I,再额外放一份会返回明显不同结果的同名 cart.py 到 PYTHONPATH。 配对基线 32 次 import 错误。16 次安全路径且有同名模块时使用了不同实现。 候选头未读取同名实现,边界用例仍给出原来的两项失败和修复后的全过。CartChecks 的 AST 与主干相同,所有练习前后 checker 哈希相同。 覆盖 macOS 上的 Python 3.11 至 3.14 和文件、SQLite 的 Chat 集成。模型响应由测试脚本提供,远端 CI 未查询。
改动思路 / Approach
检查器按路径加载与 checks.py 相邻的 cart.py,调用原函数并继续使用原 unittest 断言。集成测试则用 -I 启动这个同一文件。 不修改解释器搜索路径,仅用 Python 标准库加载固定的相邻文件。集成沿用现有旁路执行和哈希验证。
具体改动 / Changes
关键代码讲解
评审头 29fe095,合并基线 3070de3。2 个文件,+6/−2。 依据 Documented two-file exercise reaches its six original assertions 和 Safe-path and same-name module isolation 核对现有入口。 仓库规范 示例的两文件入口
- cart_path and run_path。从当前 checker 的路径找到相邻的练习文件,取回既有函数。 代码
- CartChecks。六项断言的 AST 与基线一致,仍报告空车与免邮门槛的预期失败。 代码
- test_original_http_task_reuses_requested_checker_and_session。真实 Chat 路径读回练习后以隔离解释器运行六项检查,核对 checker 内容未修改。 代码
对主干的风险 / Risks
语义与 CI 对齐
基线和候选各 64 次配对运行,覆盖确定失败和修复结果。集成套件 10 项全部通过。快速 premerge 5 项直接检查和 3 项选中检查均通过。 配对 Ruff 诊断显示 checker 通过,集成测试文件的五项既有诊断与主干一致。此次只检查教程相邻文件与同名模块,不推导更宽的环境隔离保证。
我的整体评价 / Verdict
同意此提交的代码改动。已有文档命令和 Python 3.11+ 支持范围足以完成练习。仍可用失败输出定位两条价格规则。 测试以两个独立副本复现安装前的命令,并证明修复只发生在 cart.py。
English verdict: APPROVE — the two-file exercise reliably reaches its six unchanged checks in safe-path and isolated modes, ignores a same-named cart elsewhere, and passes all six after fixing only cart.py. Exact head 29fe095.
The first bug-fix tutorial asks a newcomer to copy two files and run
python3 checks.py. With Python safe-path mode enabled, the checker could fail while importingcartbefore reaching either of the two intended pricing failures.The checker now loads the sibling
cart.pyby its file path. The documented command and the six pricing assertions stay the same. The existing Chat task integration test also runs the repaired copy with an isolated interpreter.Validation
cart.pyon the search path. All 32 before/after runs reached the six assertions. Only the empty cart and the exact shipping threshold failed initially. Fixing the copied cart made all six pass.