Skip to content

factory: 上游同步追平(2be9f99) - #31

Merged
im47cn merged 1 commit into
mainfrom
factory/sync-2be9f99
Sep 2, 2026
Merged

im47cn merged 1 commit into
mainfrom
factory/sync-2be9f99

Conversation

@im47cn-bot

@im47cn-bot im47cn-bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

上游同步追平

  • 锚点: awesome-rules@2be9f99(im47cn/awesome-rules main tip)
  • 上游增量: PR #111(issue 环境密封 + 正文预检)、#112(多 source_paths)、#114(evidence_edited 部分损坏防护)、#115(issue-create label 闸)
  • 模式: 中心版 sync-from-upstream.sh --apply --commit,full 面直接覆盖(零本地化),含 upstream-lock.json 锚点更新
  • Sourcery 回归闸: 追平时点本地前移执行

人工合并后下游即与上游 2be9f99 对齐。

Sourcery 总结

将工厂工具链同步追平至上游 2be9f99,并强化跨仓同步、门控校验、Codeup 适配、运行时自愈与故障告警。

新功能:

  • 集中巡检并追平登记的下游仓库,支持漂移检查、批量应用和单提交落库。
  • 为 issue 创建增加验收标准与 factory 标签命名空间预检,并为 PR 标签提供 Codeup 评论标记承载。
  • 为 fix-issue 和 validate-pr 增加可选 docstring 门。

Bug 修复:

  • 修复上游同步覆盖运行中脚本、缺失父目录、旧锁字段及下游字节码残留等问题。
  • 修复 Codeup 托管自动识别、远程仓库配置推导、标签状态读取及反馈路径中的兼容性问题。
  • 改善调度停摆、裸仓库和测试环境泄漏的诊断与告警,避免静默失败。

改进:

  • 增强同步流程的原子替换、脏工作树保护、Sourcery 前后置回归闸和 blame 忽略配置。
  • 完善 fresh clone、gitignored 周界路径和 Git 子进程环境的安全密闭与 fail-closed 行为。

测试:

  • 新增下游集中巡检、上游同步、环境密闭、fresh clone、Codeup 标记模型、门命令及 CLI 入口的回归测试。

杂项:

  • 更新上游同步锁定信息以对齐上游 2be9f99。
Original summary in English

Summary by Sourcery

将工厂工具链同步追平至上游 2be9f99,并强化跨仓同步、门控校验、Codeup 适配、运行时自愈与故障告警。

New Features:

  • 集中巡检并追平登记的下游仓库,支持漂移检查、批量应用和单提交落库。
  • 为 issue 创建增加验收标准与 factory 标签命名空间预检,并为 PR 标签提供 Codeup 评论标记承载。
  • 为 fix-issue 和 validate-pr 增加可选 docstring 门。

Bug Fixes:

  • 修复上游同步覆盖运行中脚本、缺失父目录、旧锁字段及下游字节码残留等问题。
  • 修复 Codeup 托管自动识别、远程仓库配置推导、标签状态读取及反馈路径中的兼容性问题。
  • 改善调度停摆、裸仓库和测试环境泄漏的诊断与告警,避免静默失败。

Enhancements:

  • 增强同步流程的原子替换、脏工作树保护、Sourcery 前后置回归闸和 blame 忽略配置。
  • 完善 fresh clone、gitignored 周界路径和 Git 子进程环境的安全密闭与 fail-closed 行为。

Tests:

  • 新增下游集中巡检、上游同步、环境密闭、fresh clone、Codeup 标记模型、门命令及 CLI 入口的回归测试。

Chores:

  • 更新上游同步锁定信息以对齐上游 2be9f99。

@im47cn-bot
im47cn-bot requested a review from im47cn as a code owner September 2, 2026 15:00
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: b472a6dc-5311-4d23-9d9b-dbe25bcdee5a


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.

@changeset-bot

changeset-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5bb3fc7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sourcery-ai

sourcery-ai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

审查者指南

该 PR 将工厂工具链追平到上游 2be9f99:以中心仓巡检脚本和增强版同步脚本管理多下游自动追平及单提交落库,同时强化运行时自愈、环境密封、配置质量门、Codeup/GitHub 适配和 issue 预检,并以大量回归测试覆盖同步安全、平台契约与故障场景。

中心化下游同步时序图

sequenceDiagram
    participant Operator
    participant Checker as downstream-check.sh
    participant Center as Center repository
    participant Sync as sync-from-upstream.sh
    participant Downstream as Downstream repository

    Operator->>Checker: --apply-commit
    Checker->>Center: Read downstream.json
    loop Each downstream repository
        Checker->>Sync: --repo path --anchor main --check
        Sync->>Center: Read upstream manifest and files
        Sync->>Downstream: Detect drift
        alt Drift detected
            Checker->>Sync: --repo path --anchor main --apply --commit
            Sync->>Downstream: Atomically replace full files
            Sync->>Downstream: Update upstream-lock.json
            Sync->>Downstream: Commit synchronization changes
        else Clean
            Sync-->>Checker: Clean
        end
    end
    Checker-->>Operator: Summary and exit status
Loading

同步安全门时序图

sequenceDiagram
    participant Sync as sync-from-upstream.sh
    participant Repo as Target repository
    participant Sourcery
    participant Git as Git repository

    Sync->>Repo: Resolve --repo to repository root
    Sync->>Git: Check tracked .factory changes
    alt Dirty .factory with --commit
        Git-->>Sync: Uncommitted changes
        Sync-->>Repo: Abort fail-closed
    else Clean target
        Sync->>Sourcery: Review .factory baseline
        Sourcery-->>Sync: Clean baseline
        Sync->>Repo: Atomically stage full-file updates
        Sync->>Sourcery: Review updated .factory
        alt Updated files clean
            Sync->>Git: Stage lock and files
            Sync->>Git: Commit synchronization
        else Regression detected
            Sync-->>Repo: Abort without updating lock
        end
    end
Loading

issue 创建预检流程图

flowchart TD
    Create[Issue create request] --> Body{Acceptance section or checkbox?}
    Body -->|No| RejectBody[Reject before platform request]
    Body -->|Yes| Label{factory:* label allowed?}
    Label -->|No, except needs-human| RejectLabel[Reject before platform request]
    Label -->|Yes| Platform[Create issue on hosting platform]
Loading

文件级变更

变更 详情 文件
将上游同步扩展为中心仓驱动的多下游巡检、可选自动追平和单提交落库流程。
  • 新增 downstream.json 清单解析、路径解析、互斥锁、逐仓 check/apply-commit、汇总与通知机制。
  • 为 sync-from-upstream.sh 增加 --repo/--commit,支持目标仓根规范化、提交前脏检查、原子文件替换、锁点 upstream 字段回填及 blame 忽略配置。
  • 在追平前后执行 Sourcery 回归闸,并通过临时文件 trap 确保失败清理。
.factory/downstream-check.sh
.factory/sync-from-upstream.sh
.factory/upstream-lock.json
.factory/tests/test_downstream_check.py
.factory/tests/test_sync_from_upstream.py
增强调度与运行时状态的自愈、故障诊断和告警能力。
  • 自动初始化 floor.json 与 ledger.jsonl,并记录账本缺失自愈事件。
  • 停摆时落盘 core.bare、git-toplevel、worktrees 环境快照,发送 macOS 通知及可去重的飞书告警。
  • 补充工厂入口在 bare/非仓库环境下的诊断信息。
.factory/cron-dispatch.sh
.factory/factory-state.sh
收紧配置与测试执行边界,新增可选 docstring 质量门并避免运行时污染下游仓。
  • 导入 hosting 时临时禁止字节码写入,防止下游产生 pycache。
  • 统一 final_gate/docstring_gate 的命令校验,拒绝空值、引号、反斜杠和换行;在 fix-issue 与 validate-pr 链路执行可选 docstring 门。
  • 测试环境密封 PATH、Git 全局/系统配置及 GIT_CONFIG 注入变量,降低宿主环境和网络工具泄漏。
  • 允许 fresh clone 缺失 gitignored 周界路径,同时保留非忽略路径缺失拦截。
.factory/factory_lib.py
.factory/fix-issue.sh
.factory/guard.py
.factory/validate-pr.sh
.factory/tests/gitenv.py
.factory/tests/test_factory_lib.py
.factory/tests/test_factory_local.py
.factory/tests/test_gitenv.py
.factory/tests/test_guard_fresh_clone.py
.factory/tests/test_mutations_run.py
完善多托管平台适配与 Codeup 的仓库、标签和评审状态模型。
  • 按 remote 自动识别 GitHub/Codeup,统一解析 HTTPS、SSH/scp remote,并支持 github-wop-bot 别名。
  • 从 remote 或本机 namespace 映射推导 Codeup 组织、仓库和 space ID,减少逐仓环境配置。
  • 以评论标记承载 Codeup 工厂标签的 add/remove/history 和 changes-requested 手势,同时与原生 Link 标签兼容并支持降级读取。
.factory/hosting.py
.factory/tests/test_dispatch.py
.factory/tests/test_hosting.py
在 issue 创建和上游反馈流程中增加 fail-closed 约束并修正路径展开。
  • issue create 预检正文必须包含 checkbox 或验收/acceptance 标题。
  • 禁止创建时占用 factory:* 状态机命名空间,仅保留 factory:needs-human 豁免。
  • 将 port_point 数据化到 factory-local.json,修正 upstream_path 的 ~/ 展开,并同步机器开单模板的验收段。
.factory/feedback-upstream.sh
.factory/feedback.py
.factory/hosting.py
.factory/upstream-sync-check.sh
.factory/tests/test_feedback.py
.factory/tests/test_hosting.py
补齐同步、配置、托管适配和 CLI 入口的回归测试覆盖。
  • 覆盖缺失父目录、中心驱动目标仓、原子自覆盖、提交幂等、旧锁回填和临时文件清理。
  • 覆盖 docstring/final gate 配置边界、issue 预检、Codeup 评论标签模型、fresh clone 及环境密封行为。
  • 补充 mutations CLI main 冒烟和多平台 remote 解析负例。
.factory/tests/test_downstream_check.py
.factory/tests/test_factory_lib.py
.factory/tests/test_factory_local.py
.factory/tests/test_feedback.py
.factory/tests/test_gitenv.py
.factory/tests/test_guard_fresh_clone.py
.factory/tests/test_hosting.py
.factory/tests/test_mutations_run.py
.factory/tests/test_sync_from_upstream.py

提示与命令

与 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

该 PR 将工厂工具链追平到上游 2be9f99:以中心仓巡检脚本和增强版同步脚本管理多下游自动追平及单提交落库,同时强化运行时自愈、环境密封、配置质量门、Codeup/GitHub 适配和 issue 预检,并以大量回归测试覆盖同步安全、平台契约与故障场景。

Sequence diagram for centralized downstream synchronization

sequenceDiagram
    participant Operator
    participant Checker as downstream-check.sh
    participant Center as Center repository
    participant Sync as sync-from-upstream.sh
    participant Downstream as Downstream repository

    Operator->>Checker: --apply-commit
    Checker->>Center: Read downstream.json
    loop Each downstream repository
        Checker->>Sync: --repo path --anchor main --check
        Sync->>Center: Read upstream manifest and files
        Sync->>Downstream: Detect drift
        alt Drift detected
            Checker->>Sync: --repo path --anchor main --apply --commit
            Sync->>Downstream: Atomically replace full files
            Sync->>Downstream: Update upstream-lock.json
            Sync->>Downstream: Commit synchronization changes
        else Clean
            Sync-->>Checker: Clean
        end
    end
    Checker-->>Operator: Summary and exit status
Loading

Sequence diagram for synchronization safety gates

sequenceDiagram
    participant Sync as sync-from-upstream.sh
    participant Repo as Target repository
    participant Sourcery
    participant Git as Git repository

    Sync->>Repo: Resolve --repo to repository root
    Sync->>Git: Check tracked .factory changes
    alt Dirty .factory with --commit
        Git-->>Sync: Uncommitted changes
        Sync-->>Repo: Abort fail-closed
    else Clean target
        Sync->>Sourcery: Review .factory baseline
        Sourcery-->>Sync: Clean baseline
        Sync->>Repo: Atomically stage full-file updates
        Sync->>Sourcery: Review updated .factory
        alt Updated files clean
            Sync->>Git: Stage lock and files
            Sync->>Git: Commit synchronization
        else Regression detected
            Sync-->>Repo: Abort without updating lock
        end
    end
Loading

Flow diagram for issue creation prechecks

flowchart TD
    Create[Issue create request] --> Body{Acceptance section or checkbox?}
    Body -->|No| RejectBody[Reject before platform request]
    Body -->|Yes| Label{factory:* label allowed?}
    Label -->|No, except needs-human| RejectLabel[Reject before platform request]
    Label -->|Yes| Platform[Create issue on hosting platform]
Loading

File-Level Changes

Change Details Files
将上游同步扩展为中心仓驱动的多下游巡检、可选自动追平和单提交落库流程。
  • 新增 downstream.json 清单解析、路径解析、互斥锁、逐仓 check/apply-commit、汇总与通知机制。
  • 为 sync-from-upstream.sh 增加 --repo/--commit,支持目标仓根规范化、提交前脏检查、原子文件替换、锁点 upstream 字段回填及 blame 忽略配置。
  • 在追平前后执行 Sourcery 回归闸,并通过临时文件 trap 确保失败清理。
.factory/downstream-check.sh
.factory/sync-from-upstream.sh
.factory/upstream-lock.json
.factory/tests/test_downstream_check.py
.factory/tests/test_sync_from_upstream.py
增强调度与运行时状态的自愈、故障诊断和告警能力。
  • 自动初始化 floor.json 与 ledger.jsonl,并记录账本缺失自愈事件。
  • 停摆时落盘 core.bare、git-toplevel、worktrees 环境快照,发送 macOS 通知及可去重的飞书告警。
  • 补充工厂入口在 bare/非仓库环境下的诊断信息。
.factory/cron-dispatch.sh
.factory/factory-state.sh
收紧配置与测试执行边界,新增可选 docstring 质量门并避免运行时污染下游仓。
  • 导入 hosting 时临时禁止字节码写入,防止下游产生 pycache。
  • 统一 final_gate/docstring_gate 的命令校验,拒绝空值、引号、反斜杠和换行;在 fix-issue 与 validate-pr 链路执行可选 docstring 门。
  • 测试环境密封 PATH、Git 全局/系统配置及 GIT_CONFIG 注入变量,降低宿主环境和网络工具泄漏。
  • 允许 fresh clone 缺失 gitignored 周界路径,同时保留非忽略路径缺失拦截。
.factory/factory_lib.py
.factory/fix-issue.sh
.factory/guard.py
.factory/validate-pr.sh
.factory/tests/gitenv.py
.factory/tests/test_factory_lib.py
.factory/tests/test_factory_local.py
.factory/tests/test_gitenv.py
.factory/tests/test_guard_fresh_clone.py
.factory/tests/test_mutations_run.py
完善多托管平台适配与 Codeup 的仓库、标签和评审状态模型。
  • 按 remote 自动识别 GitHub/Codeup,统一解析 HTTPS、SSH/scp remote,并支持 github-wop-bot 别名。
  • 从 remote 或本机 namespace 映射推导 Codeup 组织、仓库和 space ID,减少逐仓环境配置。
  • 以评论标记承载 Codeup 工厂标签的 add/remove/history 和 changes-requested 手势,同时与原生 Link 标签兼容并支持降级读取。
.factory/hosting.py
.factory/tests/test_dispatch.py
.factory/tests/test_hosting.py
在 issue 创建和上游反馈流程中增加 fail-closed 约束并修正路径展开。
  • issue create 预检正文必须包含 checkbox 或验收/acceptance 标题。
  • 禁止创建时占用 factory:* 状态机命名空间,仅保留 factory:needs-human 豁免。
  • 将 port_point 数据化到 factory-local.json,修正 upstream_path 的 ~/ 展开,并同步机器开单模板的验收段。
.factory/feedback-upstream.sh
.factory/feedback.py
.factory/hosting.py
.factory/upstream-sync-check.sh
.factory/tests/test_feedback.py
.factory/tests/test_hosting.py
补齐同步、配置、托管适配和 CLI 入口的回归测试覆盖。
  • 覆盖缺失父目录、中心驱动目标仓、原子自覆盖、提交幂等、旧锁回填和临时文件清理。
  • 覆盖 docstring/final gate 配置边界、issue 预检、Codeup 评论标签模型、fresh clone 及环境密封行为。
  • 补充 mutations CLI main 冒烟和多平台 remote 解析负例。
.factory/tests/test_downstream_check.py
.factory/tests/test_factory_lib.py
.factory/tests/test_factory_local.py
.factory/tests/test_feedback.py
.factory/tests/test_gitenv.py
.factory/tests/test_guard_fresh_clone.py
.factory/tests/test_hosting.py
.factory/tests/test_mutations_run.py
.factory/tests/test_sync_from_upstream.py

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

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

嘿——我发现了 2 个问题

面向 AI 代理的提示
请处理本次代码审查中的评论:

## 各条评论

### 评论 1
<location path=".factory/tests/gitenv.py" line_range="42-70" />
<code_context>
+# 测试子进程链锚定工具(所在目录进 PATH 白名单:python3 → bash → git)
</code_context>
<issue_to_address>
**issue (bug_risk):** `_sealed_path` 仅通过 `/usr/bin:/bin` 查找 `python3`、`git` 和 `bash`,然后返回这些目录及备用目录。在 macOS 安装中,如果 `python3` 仅位于 `/opt/homebrew/bin` 或其他非 POSIX 目录,返回的 `PATH` 将无法解析 `python3`,因此调用 `python3` 的测试子进程会在工厂链运行之前失败。

**触发条件:** 测试主机在 `/usr/bin` 或 `/bin` 中没有 `python3` 时;这在基于 Homebrew 的 macOS 配置中很常见。

**建议修复:** 从明确批准的工具路径中解析每个必需工具,或以清晰的配置错误终止;不要静默地将必需的解释器从密封的 PATH 中遗漏。
</issue_to_address>

### 评论 2
<location path=".factory/hosting.py" line_range="72" />
<code_context>
 import urllib.parse
 import urllib.request

-FACTORY_HOSTING = os.environ.get("FACTORY_HOSTING", "github")
+FACTORY_HOSTING = os.environ.get("FACTORY_HOSTING")


</code_context>
<issue_to_address>
**nitpick:** 模块文档说明 `FACTORY_HOSTING=github` 是默认值,但更改后的配置现在会使其保持未设置状态,而 `current_adapter` 会根据远程仓库自动检测 Codeup。对于使用 Codeup 远程仓库的仓库,文档中描述的平台选择契约并不成立,这可能会误导依赖所述默认行为的运维人员和调用方。

**触发条件:** 运维人员或集成依赖模块头部文档来预测适配器选择时。

**建议修复:** 更新模块文档字符串,说明显式设置的 `FACTORY_HOSTING` 值具有优先级;未设置时则根据 `origin` 推断,并回退到 GitHub。
</issue_to_address>

Sourcery 评估

需要人工审查。 需要优先处理 1 个发现;此外,此更改会影响计划调度行为、下游仓库写入、托管平台上的标签/评论以及 issue 创建策略,因此缺陷可能会发送外部警报、创建不正确的生命周期记录,或在多个仓库中提交更改。还原代码可以阻止未来的影响,但无法撤销已经产生的通知、评论、标签或提交。

阻塞性发现:.factory/tests/gitenv.py:70


Sourcery 对开源项目免费——如果您喜欢我们的审查,请考虑分享它们 ✨
请帮助我变得更有用!请在每条评论上点击 👍 或 👎,我会利用反馈来改进审查结果。
Original comment in English

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".factory/tests/gitenv.py" line_range="42-70" />
<code_context>
+# 测试子进程链锚定工具(所在目录进 PATH 白名单:python3 → bash → git)
</code_context>
<issue_to_address>
**issue (bug_risk):** `_sealed_path` resolves `python3`, `git`, and `bash` only through `/usr/bin:/bin` and then returns those directories plus the fallback directories. On macOS installations where `python3` is available only in `/opt/homebrew/bin` or another non-POSIX directory, the returned `PATH` cannot resolve `python3`, so test subprocesses that invoke `python3` fail before the factory chain runs.

**Triggers:** When the test host does not have `python3` in `/usr/bin` or `/bin`, which is common on Homebrew-based macOS setups.

**Suggested fix:** Resolve each required tool from an explicitly approved tool path or fail with a clear configuration error; do not silently omit a required interpreter from the sealed PATH.
</issue_to_address>

### Comment 2
<location path=".factory/hosting.py" line_range="72" />
<code_context>
 import urllib.parse
 import urllib.request

-FACTORY_HOSTING = os.environ.get("FACTORY_HOSTING", "github")
+FACTORY_HOSTING = os.environ.get("FACTORY_HOSTING")


</code_context>
<issue_to_address>
**nitpick:** The module documentation says `FACTORY_HOSTING=github` is the default, but the changed configuration now leaves it unset and `current_adapter` auto-detects Codeup from the remote. The documented platform-selection contract is false for repositories with Codeup remotes, which can mislead operators and callers that rely on the stated default behavior.

**Triggers:** When an operator or integration relies on the module header documentation to predict adapter selection.

**Suggested fix:** Update the module docstring to state that an explicit `FACTORY_HOSTING` value takes precedence and that an unset value is inferred from `origin`, falling back to GitHub.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and this changes scheduled dispatch behavior, downstream repository writes, hosting-side labels/comments and issue-creation policy, so a defect could send external alerts, create incorrect lifecycle records, or commit changes across multiple repositories. Reverting the code would stop future effects, but it would not undo notifications, comments, labels, or commits already produced.

Blocking findings: .factory/tests/gitenv.py:70


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.

Comment thread .factory/tests/gitenv.py
Comment on lines +42 to +70
# 测试子进程链锚定工具(所在目录进 PATH 白名单:python3 → bash → git)
_ANCHOR_TOOLS = ("python3", "git", "bash")
# POSIX 标准目录兜底(sed/grep/sh 等 coreutils 所在)
_FALLBACK_DIRS = ("/usr/bin", "/bin")


def _sealed_path() -> str:
"""PATH 白名单:锚定工具所在目录 ∪ POSIX 标准目录。

目录级白名单(非工具级):够跑 python3→bash→git 测试链即可,
宿主私有目录(pip user bin 等)整体剥除——sourcery 不可见 →
夹具闸 command -v 探测跳过 → 零出网(issue #109 陷阱①)。

锚定解析强制走 POSIX 标准目录(PR #111 Sourcery 评论①):宿主
PATH 永不参与白名单推导——锚定工具与 sourcery 同目录共存时
(如 homebrew bin 同时装 python3 与 sourcery),该目录不可再
泄漏进白名单。锚定工具均在标准目录内可解析(/usr/bin/python3、
/usr/bin/git、/bin/bash),解析失败亦有 _FALLBACK_DIRS 兜底。
"""
dirs: list[str] = []
for tool in _ANCHOR_TOOLS:
where = shutil.which(tool, path=os.pathsep.join(_FALLBACK_DIRS))
d = os.path.dirname(where) if where else None
if d and d not in dirs:
dirs.append(d)
for d in _FALLBACK_DIRS:
if d not in dirs:
dirs.append(d)
return os.pathsep.join(dirs)

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.

issue (bug_risk): _sealed_path 仅通过 /usr/bin:/bin 查找 python3、git 和 bash,然后返回这些目录及备用目录。在 macOS 安装中,如果 python3 仅位于 /opt/homebrew/bin 或其他非 POSIX 目录,返回的 PATH 将无法解析 python3,因此调用 python3 的测试子进程会在工厂链运行之前失败。

触发条件: 测试主机在 /usr/bin 或 /bin 中没有 python3 时;这在基于 Homebrew 的 macOS 配置中很常见。

建议修复: 从明确批准的工具路径中解析每个必需工具,或以清晰的配置错误终止;不要静默地将必需的解释器从密封的 PATH 中遗漏。

Original comment in English

issue (bug_risk): _sealed_path resolves python3, git, and bash only through /usr/bin:/bin and then returns those directories plus the fallback directories. On macOS installations where python3 is available only in /opt/homebrew/bin or another non-POSIX directory, the returned PATH cannot resolve python3, so test subprocesses that invoke python3 fail before the factory chain runs.

Triggers: When the test host does not have python3 in /usr/bin or /bin, which is common on Homebrew-based macOS setups.

Suggested fix: Resolve each required tool from an explicitly approved tool path or fail with a clear configuration error; do not silently omit a required interpreter from the sealed PATH.

Comment thread .factory/hosting.py
import urllib.parse
import urllib.request

FACTORY_HOSTING = os.environ.get("FACTORY_HOSTING", "github")

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.

nitpick: 模块文档说明 FACTORY_HOSTING=github 是默认值,但更改后的配置现在会使其保持未设置状态,而 current_adapter 会根据远程仓库自动检测 Codeup。对于使用 Codeup 远程仓库的仓库,文档中描述的平台选择契约并不成立,这可能会误导依赖所述默认行为的运维人员和调用方。

触发条件: 运维人员或集成依赖模块头部文档来预测适配器选择时。

建议修复: 更新模块文档字符串,说明显式设置的 FACTORY_HOSTING 值具有优先级;未设置时则根据 origin 推断,并回退到 GitHub。

Original comment in English

nitpick: The module documentation says FACTORY_HOSTING=github is the default, but the changed configuration now leaves it unset and current_adapter auto-detects Codeup from the remote. The documented platform-selection contract is false for repositories with Codeup remotes, which can mislead operators and callers that rely on the stated default behavior.

Triggers: When an operator or integration relies on the module header documentation to predict adapter selection.

Suggested fix: Update the module docstring to state that an explicit FACTORY_HOSTING value takes precedence and that an unset value is inferred from origin, falling back to GitHub.

@im47cn-bot

Copy link
Copy Markdown
Contributor Author

处置:①已修复 ②不改码(真源 awesome-rules#116,commit d6e6b57)

① 平台选择 docstring 过时:真源已改为「FACTORY_HOSTING 显式设置优先;未设置按 origin remote 检测(codeup.aliyun.com → codeup,github.com/无 remote → github 历史默认)」,与实现对齐。

② _sealed_path 建议 Homebrew-aware 真实路径解析:不改码。当前形态是 PR #111 收口的刻意设计——POSIX-only 锚定 + _FALLBACK_DIRS 兜底,docstring 明示「宿主 PATH 永不参与白名单推导」。若按 Homebrew 前缀解析真实安装路径,会重新打开 issue #109 陷阱①(sourcery 与 python3 同目录时工具链泄漏进密封 PATH,出网门挂起)。密封性优先级高于路径保真度。

真源合入 main 后随下次 sync 分发(①部分)。

@im47cn
im47cn enabled auto-merge September 2, 2026 16:40
@im47cn
im47cn merged commit 89e9852 into main Sep 2, 2026
24 checks passed
@im47cn
im47cn deleted the factory/sync-2be9f99 branch September 2, 2026 16:41
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.

2 participants