fix(cicd): expose selfmedia GitHub hook authority errors

This commit is contained in:
Codex
2026-07-13 11:33:34 +02:00
parent 4387b63fb0
commit 52145321d8
4 changed files with 135 additions and 10 deletions
@@ -0,0 +1,69 @@
# R1 任务报告
## 任务回链
- MDTODO`docs/MDTODO/selfmedia-production-delivery.md` R1。
- Target`NC01`
- targetWorkspace`/root/.worktrees/unidesk/selfmedia-production-delivery`
- repository`pikasTech/unidesk`
- ref`feat/selfmedia-production-delivery`
- 状态:保持 `in_progress`,尚未取得修复合并后的真实自动链证据。
## 最小根因
- `platform-infra gitea mirror webhook status` 的 GitHub hooks 观察器在未校验 HTTP 结果和 JSON 形状时直接迭代响应。
- 私有仓库 `pikainc/selfmedia` 对 YAML 声明的 `gh_token.txt` authority 返回 HTTP `404`;错误对象被按 hook list 迭代,最终产生 `AttributeError: 'str' object has no attribute 'get'`,并把权限故障伪装成空 hook。
- owning YAML 已包含 `selfmedia-nc01`、GitHub→Gitea hook topology、Gitea repository、PaC consumer、GitOps/Argo、双 PVC、Secret、NetworkPolicy 和公网 `152.53.229.148:4317` 契约;不需要新增 Secret 或手工 apply。
- 自动链当前真正阻塞 authority:`config/platform-infra/gitea.yaml` 声明的 GitHub bridge credential `gh_token.txt` 无法读取或管理私有仓库 `pikainc/selfmedia` 的 hooks,也无法读取仓库 head。Git SSH push 可用不能替代 GitHub API hook authority。
## 源码修复
- `scripts/src/platform_infra_gitea_status_evaluator.py`
- 新增 GitHub hooks HTTP/JSON/list/item 的 fail-closed 解析。
- 错误仅输出 `github-hooks-http-<status>``github-hooks-response-not-list``github-hooks-item-not-object` 等有界 code,不回显 GitHub 错误正文或凭据。
- 统一支持 hook `config` 为对象 URL 或字符串 URL 的公开 API 形状。
- `scripts/src/platform-infra-gitea-remote.sh`
- embedded observer 复用 evaluator,不再直接迭代未校验响应。
- HTTP 失败、错误对象和畸形 list 不再伪装成空 hook。
- `scripts/src/platform-infra-gitea-status-evaluator.test.ts`
- 覆盖 HTTP 错误对象、非 list、含非对象元素、对象 config、字符串 config 和畸形 hook。
## Target 原入口验证
- `sh -n scripts/src/platform-infra-gitea-remote.sh`:通过。
- `python3 -m py_compile scripts/src/platform_infra_gitea_status_evaluator.py`:通过。
- `git diff --check`:通过。
- `bun test scripts/src/platform-infra-gitea-status-evaluator.test.ts``14 pass / 0 fail / 86 expect()`
- `platform-infra gitea mirror webhook status --target NC01 --repo selfmedia-nc01 --full`
- bridge `ready=true``1/1`
- durable inbox `ready=true`,无 pending/failed
- selfmedia `hookReady=false``authorityMatches=false`
- topology drift 为 `desired-url-missing`
- 有界错误为 `github-hooks-http-404`
- 不再出现 Python traceback,不打印 token 或 GitHub 错误正文。
- `platform-infra pipelines-as-code status --target NC01 --consumer selfmedia-nc01`
- consumer bootstrap readyrunner automount disabledArgo repository Secret keys ready
- Repository hook `0`Latest PipelineRun 为空;
- diagnosis 仍为 `pac-source-unknown`、registry missing、Argo sync Unknown。
- 公网补充证据:`152.53.229.148:4317` 健康但 WebTerm 显示“后端尚未声明内置终端能力”,`/api/v1/system` 无 terminal configRef;宿主 PID 自 01:44 运行。该入口是旧宿主进程证据,不是 K8s 自动发布证明,任务未执行重启或 cutover。
- Secret 补充证据:`secrets status --scope selfmedia --target selfmedia-nc01` 显示 runtime TOKEN 与 codex `auth.json` / `config.toml` 均存在且 keys exact、`valuesPrinted=false`;任务未新增或同步 Secret。
## Primary Workspace 边界
- primary workspace 仅用于读取 `$dad-dev``$unidesk-trans``$unidesk-cicd``$unidesk-ymalops``$cli-spec``$git-spec``$docs-spec``$unidesk-gh`
- 所有源码读取、编辑、测试、Git 和运行面只读观察均通过 `trans NC01:/root/.worktrees/unidesk/selfmedia-production-delivery ...` 完成。
- 未使用 runner 本地结果替代 Target 原入口证据,未递归派单。
## 保留与删除的特例
- `keep-domain-special`selfmedia 双 PVC、零 runtime RBAC、`automountServiceAccountToken=false`、非特权 runtime、YAML-first Secret、NetworkPolicy、公网 IP 与 GitOps branch 契约保持不变。
- `remove-code-default`:无新增代码默认值;修复只校验实际 GitHub API 形状。
- `legacy-retire`:不恢复 branch-follower、人工 mirror sync、人工 PipelineRun、Argo refresh/sync、rollout 或 cutover。
## 合并后自动验收
1. 由凭据 authority 管理者为 owning YAML 的 `gh_token.txt` 授予 `pikainc/selfmedia` 私有仓库读取与 webhook 管理权限;不得复制 root SSH 私钥或改变仓库可见性。
2. 合并本修复 PR 后,仅观察 `platform-infra-gitea-nc01` 自动 PipelineRun 与 Argo 收敛;不得 apply、sync、refresh 或手工 reconciler。
3. 待 hook reconciler 自动运行后,只读执行 `platform-infra gitea mirror webhook status --target NC01 --repo selfmedia-nc01`,应看到 hook ready、真实 delivery accepted→committed、GitHub head 与 Gitea branch/snapshot 对齐。
4. 合并一条 `pikainc/selfmedia/master` 正常 PR,观察自动产生唯一外层 selfmedia PipelineRun、镜像 digest、GitOps release state、Argo revision、runtime commitId 与 `/healthz` ready。
5.`platform-infra pipelines-as-code status|history --target NC01 --consumer selfmedia-nc01` 验证阶段耗时、失败归因和下一步;未取得上述真实自动事件前 R1 保持 `in_progress`