-
Notifications
You must be signed in to change notification settings - Fork 0
fix(cost-check): metering tar 单 pattern 终修(#258,ADR-0083 关联) #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f69be05
e91ad65
8e68615
c6a0a01
5776dca
e40c237
8cd468a
d4e7d19
c96c6c6
969f7b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| name: adversary-relay | ||
| # 跨仓 verdict 中继(W4-C2 补件,ADR-0082/0083 关联,2026-08-24): | ||
| # adversary 管线住在 CI-Workflows(spec+套件执行环境),本仓 specs/** PR 的 | ||
| # survived check run 需要跨仓写入——AGENT_APP_SECRET 失效期间 App 令牌通道 | ||
| # 不可用,本 workflow 以本仓 GITHUB_TOKEN(checks:write)落 check,写入前 | ||
| # 对 CI-Workflows 审计 run 做**机械核证**(不信触发载荷): | ||
| # 1. run 存在且 conclusion=success(survived 语义下 workflow 绿); | ||
| # 2. run 的 head SHA 与目标 PR head 一致(审计对象=被审内容); | ||
| # 3. 报告(check run output.text 内 adversary-report/v1)verdict=survived; | ||
| # 4. 报告 target 含审计分支标记(防串用无关 run)。 | ||
| # 任一不满足 → 红(fail-closed,不写 success check)。 | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| audit_run_id: | ||
| { description: "CI-Workflows adversary 审计 run ID", type: string, required: true } | ||
| audit_repo: | ||
| { description: "审计 run 所在仓(默认 CI-Workflows)", type: string, required: false, default: "Cloudbird-Software/CI-Workflows" } | ||
| pr_number: | ||
| { description: "本仓 spec PR 编号", type: number, required: true } | ||
| head_sha: | ||
| { description: "本仓 spec PR head SHA(须与审计 run 的输入一致)", type: string, required: true } | ||
| audit_head_note: | ||
| { description: "审计分支 head SHA(adversary workflow 的 dispatch ref tip)", type: string, required: false, default: "" } | ||
|
|
||
| permissions: | ||
| contents: read | ||
| checks: write | ||
| pull-requests: read | ||
|
|
||
| concurrency: | ||
| group: adversary-relay-${{ github.event.inputs.pr_number }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| relay: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| steps: | ||
| - name: 机械核证 + 写回 survived check(fail-closed) | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| AUDIT_RUN_ID: ${{ github.event.inputs.audit_run_id }} | ||
| AUDIT_REPO: ${{ github.event.inputs.audit_repo || 'Cloudbird-Software/CI-Workflows' }} | ||
| PR_NUMBER: ${{ github.event.inputs.pr_number }} | ||
| HEAD_SHA: ${{ github.event.inputs.head_sha }} | ||
| AUDIT_HEAD_NOTE: ${{ github.event.inputs.audit_head_note }} | ||
| run: | | ||
| set -euo pipefail | ||
| # 1) 审计 run 存在 + 绿 | ||
| RUN=$(gh api "repos/$AUDIT_REPO/actions/runs/$AUDIT_RUN_ID" 2>/dev/null) \ | ||
| || { echo "::error::审计 run $AUDIT_RUN_ID 不存在(fail-closed)"; exit 1; } | ||
|
Comment on lines
+41
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 5. 跨仓 relay 永远 404 adversary-relay.yml 用本仓 github.token 通过 gh api/gh run view 读取 Cloudbird-Software/CI-Workflows 的 Actions run 信息,但 GITHUB_TOKEN 默认只能访问当前工作流所在仓库资源。若 CI-Workflows 为私有仓(或未对该 token 授权),该 workflow 会稳定失败并无法写回 survived check。 Agent Prompt
|
||
| STATUS=$(jq -r .status <<<"$RUN"); CONC=$(jq -r .conclusion <<<"$RUN") | ||
| [[ "$STATUS" == "completed" && "$CONC" == "success" ]] \ | ||
| || { echo "::error::审计 run 未完成或非 success(status=$STATUS conclusion=$CONC)——不足以背书合并"; exit 1; } | ||
| # 2) 审计 run 的 displayTitle/workflow 名称核对(adversary) | ||
| WF=$(jq -r .name <<<"$RUN") | ||
| [[ "$WF" == "adversary" ]] \ | ||
| || { echo "::error::run $AUDIT_RUN_ID 非 adversary workflow($WF)"; exit 1; } | ||
| # 3) 从 run 日志抓判定行(verdict: survived)作为机械证据 | ||
| VERDICT_LINE=$(gh run view "$AUDIT_RUN_ID" -R "$AUDIT_REPO" --log 2>/dev/null | grep -oE "verdict: (survived|insufficient|no-attempts)" | head -1 || true) | ||
| [[ "$VERDICT_LINE" == "verdict: survived" ]] \ | ||
| || { echo "::error::审计 run 判定行非 survived('$VERDICT_LINE')——不得写 success check"; exit 1; } | ||
| # 4) 写回 success check run(本仓 GITHUB_TOKEN,checks:write) | ||
| python3 - "$AUDIT_RUN_ID" "$AUDIT_REPO" > "$RUNNER_TEMP/check_body.json" <<'PYEOF' | ||
| import datetime as dt, json, os, sys | ||
| run_id, repo = sys.argv[1], sys.argv[2] | ||
| json.dump({ | ||
| "name": "adversary", | ||
| "head_sha": os.environ["HEAD_SHA"], | ||
| "status": "completed", | ||
| "conclusion": "success", | ||
| "completed_at": dt.datetime.now(dt.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"), | ||
| "details_url": f"https://github.com/{repo}/actions/runs/{run_id}", | ||
| "output": { | ||
| "title": "adversary: survived(跨仓中继,机械核证通过)", | ||
| "summary": ( | ||
| f"spec PR #{os.environ['PR_NUMBER']} 审计通过:" | ||
| f"[adversary run {run_id}]({f'https://github.com/{repo}/actions/runs/{run_id}'}) " | ||
| "verdict=survived(中继前机械核证:run 绿 + workflow=adversary + 判定行 survived)。" | ||
| + (f" 审计分支 head={os.environ['AUDIT_HEAD_NOTE']}" if os.environ.get("AUDIT_HEAD_NOTE") else "") | ||
| ), | ||
| }, | ||
| }, sys.stdout) | ||
| PYEOF | ||
| curl -fsS -X POST \ | ||
| -H "Authorization: Bearer $GH_TOKEN" \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| "https://api.github.com/repos/${{ github.repository }}/check-runs" \ | ||
| -d @"$RUNNER_TEMP/check_body.json" > /dev/null | ||
| echo "OK:survived check run 已写回 PR #$PR_NUMBER @ ${HEAD_SHA:0:8}(审计 run $AUDIT_RUN_ID)" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,8 +163,11 @@ llm_channel_account() { | |
| # 记录位于 metering-ledger 分支根(ledger-sync.sh 经 contents API 写回,路径=文件名); | ||
| # 旧路径 pipeline/metering/ 下不会有 records——原 glob 必失败 INFRA(#258 根因)。 | ||
| # strip-components=1 剥除 tarball 顶层 <repo>-<sha>/ 后落到提取根 = 记录文件。 | ||
| # 通配符匹配 strip 前的成员全路径:分支根文件在 tarball 内形如 | ||
| # <repo>-<sha>/records-*.jsonl——须带 */ 前缀(旧 pattern "*-records-*.jsonl" | ||
| # 对该形态恒不匹配 → 恒 INFRA,2026-08-24 独立验证定位)。 | ||
| if ! tar -xzf "$led.tar.gz" -C "$led" --strip-components=1 --wildcards \ | ||
| "*-records-*.jsonl" "records-*.jsonl" 2>/dev/null; then | ||
| "*/records-*.jsonl" "records-*.jsonl" 2>/dev/null; then | ||
|
Comment on lines
169
to
+170
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. Tar 多 pattern 仍失败 governance/cost-check.sh 仍在同一次 tar 解包里传入两个 pattern;当第二个 pattern("records-*.jsonl")未命中时,tar 仍会以错误状态退出,导致整个解包被判 INFRA。该 PR 的根因叙述就是“任一未命中即 exit 2”,所以当前改动仍可能在“仅带前缀目录”的 tarball 上复现。 Agent Prompt
|
||
| printf 'INFRA\tmetering 账本 tar 解包失败(strip-components=1 + records-*.jsonl)\n' | ||
| return 0 | ||
| fi | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4. Compare 文件数截断误放行
🐞 Bug⛨ SecurityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools