Skip to content

Add a report-only risk-tier workflow (Related #3393) - #3396

Open
Birfy wants to merge 6 commits into
mainfrom
dev/3393-risk-ci
Open

Birfy wants to merge 6 commits into
mainfrom
dev/3393-risk-ci

Conversation

@Birfy

@Birfy Birfy commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Related #3393

Slice: one workflow file, .github/workflows/risk-tier.yml.

Report-only. pull_request (opened, synchronize, reopened) → job id and check name risk-tier → node .github/scripts/risk-gate.mjs with the facts passed as env (PR, GITHUB_REPOSITORY, GITHUB_TOKEN), no new flags. The runner sets GITHUB_STEP_SUMMARY, so the tier table lands in the job summary and the console line carries the one-line verdict. No labels, no comments, no required check: risk-gate.mjs exits 0 for T0–T3 (T3 means "a human approves", not "the build fails") and 1 only when it could not compute a tier.

Stacked on #3394 head bdf1a871a1 (Lead approved this base: risk-gate.mjs / risk-tier.mjs / .github/agent/risk-rules.json are not on main yet, and a real run needs them). The diff against main therefore shows 8 files — the 7 from #3394 plus this one. After #3394 merges this must be rebased onto main and re-checked; the slice itself is the single new file.

Check name is risk-tier: not FlyBot required checks, and no tests-ok / enqueue-guard anywhere.

Evidence (local, on the tree exported from bdf1a871a1):

  • PR=3394 GITHUB_REPOSITORY=ThinkFlowLab/FlyBot node .github/scripts/risk-gate.mjs → risk-gate (report only): PR #3394 tier T3; … , exit 0, and GITHUB_STEP_SUMMARY file starts with ### Risk tier: T3.
  • grep -E "FlyBot required checks|tests-ok|enqueue-guard" .github/workflows/risk-tier.yml → no match.
  • sha256sum .github/workflows/tests.yml → 6f60af36d734e48933f585e05857c2878f6673430065742568603fdea57fe2a9, identical to the same file on 34a80ca5a1. tests.yml is not touched.

Path table rewritten for the tree that exists now: .github/, scripts/,
deploy/, the vendor tree and the dependency/deploy manifests are T3 (the old
table named core/, plugins/ and ds-bot/, none of which exist); services/,
manager/, runtime/flybot* and flybot_workspace code are T2; client code,
tests and checked-in pages T1; docs T0. unknownPathTier stays T2 so a path no
rule names is never silently passed as low risk.

Size caps are recomputed from six real changes in this tree (#3390 5L/1F,
#3389 54L/5F, #3386 280L/11F, #3391 386L/13F, #3382 633L/7F, #3388
1128L/14F): the old caps would have called #3388 T3. limitsNote records it.

The T3 meaning no longer claims a self-PASS lets the gate merge by itself;
this file only reports a tier.
The 0.2 script mixed the rules engine, the network reads and the CLI in one file. The engine
(tier paths, glob matching, judge, size caps, report) is pure over the rules file and the list of
changed files, so it moves to risk-tier.mjs on its own; the command and the REST reads follow in
risk-gate.mjs, which re-exports this module.

No behaviour change: same ORDER, globToRe, judge, summaryLine, render, loadRules as the 0.2
version, and the two intended differences of the port (a reason for T1/T2 as well as T3, and a
`--replay` that filters on merged_at instead of `gh pr list`) live here and in the CLI.
The 0.2 script shelled out to `gh api`, which does not exist here. This reads the REST API with the
global fetch, so the command runs with no `gh` and no token: `node .github/scripts/risk-gate.mjs
--pr 3382` is the acceptance command. A token is used when the environment has one (the anonymous
core quota is 60/h and shared) and is never required; a spent quota is named in the error with its
reset time instead of a bare 403.

The changed-file list is read page by page off the Link header, so a PR with more than 100 files is
read whole (#3112 has 194), and `--replay` filters closed PRs on merged_at rather than calling
`gh pr list --state merged`, which no longer exists.

Report only: it prints a tier and exits 0; it does not block, label, merge or touch tests.yml.
The 0.2 test file is carried over as-is: glob matching, tierOf precedence, judge over a set of
files, content red flags (JS and Python), renames, size caps, the truncated-list rule, the report
and the summary line, plus the #679 topic narrowing. Added for this layout: every tier path and cap
in .github/agent/risk-rules.json is asserted against real paths of this tree, and the unknown-path
default must stay at T2 or above.

The set-up shared by the test files (rules, gate, a changed-file factory) moves to
risk-gate.fixtures.mjs so each test file stays small.

Local: node --test '.github/scripts/*.test.mjs' -> 24 tests, 24 pass, 0 fail.
… without a network

Second and third test file of the same 24-test suite, split only so no file is oversized:
- risk-gate-judge.test.mjs: what must not raise a tier (removed lines, prose, allowed hosts), what
  must (an unreadable diff, generated-file counting, size caps at the tier reached, a possibly
  truncated list), the T2-is-quotable report, the summary line, and the rules file's own shape.
- risk-gate-api.test.mjs: the REST layer with a stubbed fetch and no token: an anonymous request
  sends no authorization header, a token is sent when one is set, the Link header is followed, a
  spent quota is named in the error, --replay keeps only merged PRs, and the command does not shell
  out to `gh`.

Local: node --test '.github/scripts/*.test.mjs' -> 24 tests, 24 pass, 0 fail.
Runs risk-gate.mjs on pull_request and writes the tier table to the job
summary. It never labels, comments, or blocks, and its check name is
risk-tier, not the required aggregate gate.
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