From ed4378bc4f1ff4fb947f5b18792c6f35aa40b34a Mon Sep 17 00:00:00 2001 From: tr00d Date: Thu, 26 Nov 2026 11:54:59 +0100 Subject: [PATCH] ci(quality-gate): check the declared public API in the fast loop The "Public API declared" stage ran only in the full gate, so a lane iterating with --fast first learned about an undeclared public member from CI (#905). It costs seconds on a warm build, so it now runs in --fast too, after the tests and skipped causally when the build fails. The fixture package now tracks its public surface like the SDK packages (PublicApiAnalyzers, RS0016/RS0017 at suggestion), clean and build-broken pin stage 5a, and a new api-undeclared fixture fails the fast loop on an undeclared public type. --- .claude/skills/sdk-quality-gate/SKILL.md | 12 ++++++------ scripts/quality-gate/README.md | 6 +++--- scripts/quality-gate/fixtures/_base/.editorconfig | 5 +++++ .../fixtures/_base/Sample/PublicAPI.Shipped.txt | 1 + .../fixtures/_base/Sample/PublicAPI.Unshipped.txt | 3 +++ .../fixtures/_base/Sample/Sample.csproj | 9 +++++++++ .../fixtures/api-undeclared/expect.json | 12 ++++++++++++ .../api-undeclared/overlay/Sample/Gadget.cs | 6 ++++++ .../quality-gate/fixtures/build-broken/expect.json | 5 +++-- scripts/quality-gate/fixtures/clean/expect.json | 5 +++-- scripts/quality-gate/gate.sh | 13 ++++++++----- scripts/quality-gate/lib/report.sh | 2 +- 12 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 scripts/quality-gate/fixtures/_base/Sample/PublicAPI.Shipped.txt create mode 100644 scripts/quality-gate/fixtures/_base/Sample/PublicAPI.Unshipped.txt create mode 100644 scripts/quality-gate/fixtures/api-undeclared/expect.json create mode 100644 scripts/quality-gate/fixtures/api-undeclared/overlay/Sample/Gadget.cs diff --git a/.claude/skills/sdk-quality-gate/SKILL.md b/.claude/skills/sdk-quality-gate/SKILL.md index 6de1f2e09..b89614093 100644 --- a/.claude/skills/sdk-quality-gate/SKILL.md +++ b/.claude/skills/sdk-quality-gate/SKILL.md @@ -13,15 +13,15 @@ are relative to the repository root; the script itself is location-independent. ``` scripts/quality-gate/gate.sh # full gate — before a PR -scripts/quality-gate/gate.sh --fast # inner loop only +scripts/quality-gate/gate.sh --fast # inner loop + public-API declaration scripts/quality-gate/gate.sh --mutation # evaluate a Stryker report ``` -There are two modes. `--fast` is the inner loop only (build, format, tests) — the -fast local red/green cycle; the default is the full gate and adds security, the -public-API check, E2E and a line-coverage baseline. `` is a directory — -e.g. `packages/Gotrue`, or `packages` for the whole solution. Run with -`bash ` if the executable bit is unset. +There are two modes. `--fast` is the inner loop (build, format, tests) plus the +public-API declaration check — the fast local red/green cycle; the default is the +full gate and adds security, the public-API diff, E2E and a line-coverage +baseline. `` is a directory — e.g. `packages/Gotrue`, or `packages` for +the whole solution. Run with `bash ` if the executable bit is unset. **Mutation runs in its own workflow, on every PR.** `mutation.yml` runs Stryker `--since:origin/master` on changed packages, then `gate.sh packages --mutation` diff --git a/scripts/quality-gate/README.md b/scripts/quality-gate/README.md index 112d59785..bcaf3a167 100644 --- a/scripts/quality-gate/README.md +++ b/scripts/quality-gate/README.md @@ -15,7 +15,7 @@ run INCOMPLETE rather than green. ```sh ./scripts/quality-gate/gate.sh packages # full gate over the solution ./scripts/quality-gate/gate.sh packages/Gotrue # one package -./scripts/quality-gate/gate.sh . --fast # inner loop only (fast red/green cycle) +./scripts/quality-gate/gate.sh . --fast # inner loop + public-API declaration (fast red/green cycle) ./scripts/quality-gate/gate.sh --help ``` @@ -37,7 +37,7 @@ Requirements: `dotnet`, `jq`, and `git`. For the E2E stage, a running Supabase s | 2b | Coverage (line) | block | Line coverage of the hermetic (unit+contract) run must not drop below baseline. Full-suite coverage is shown for info, not gated. | | 3 | Mutation (new survivors) | block² | Reads a Stryker report and FAILs on a surviving mutant **on a changed line**. See [Mutation](#mutation-testing). | | 4 | Dependency vulnerabilities | signal | `dotnet list package --vulnerable`. Reported, never blocks — a vuln may have no fix available. | -| 5a | Public API declared | block | Committed `PublicAPI.*.txt` must match the compiled public surface. | +| 5a | Public API declared | block | Committed `PublicAPI.*.txt` must match the compiled public surface. Runs in `--fast` too: it costs seconds. | | 5 | Public API diff | signal | Flags added/removed public members; a **removal** is a breaking change needing sign-off. | | 7 | E2E / acceptance | block | Runs as part of stage 2 in full mode (no separate row). | @@ -49,7 +49,7 @@ Requirements: `dotnet`, `jq`, and `git`. For the E2E stage, a running Supabase s | Flag | Effect | |------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------| | *(none)* | Full gate. | -| `--fast` | Inner loop only (build + format + unit/contract). No coverage, E2E, scan, or API checks. Verdict is PARTIAL on success — it's a subset, not the full bar. | +| `--fast` | Inner loop (build + format + unit/contract) and the Public API declared check. No coverage, E2E, scan or API diff. PARTIAL on success — not the full bar. | | `--mutation` | Evaluate a Stryker report only. Does not build or run Stryker. | | `--bypass-format` | Format reports as a signal, not a blocker, for this run. | | `--overwrite-baseline` | Persist improvements (warnings down, coverage up) to `.gate-baseline.json`. Without it the gate is **read-only** and never edits the file. | diff --git a/scripts/quality-gate/fixtures/_base/.editorconfig b/scripts/quality-gate/fixtures/_base/.editorconfig index cf2bb0aab..4ad7933c9 100644 --- a/scripts/quality-gate/fixtures/_base/.editorconfig +++ b/scripts/quality-gate/fixtures/_base/.editorconfig @@ -5,3 +5,8 @@ indent_style = space indent_size = 4 insert_final_newline = true trim_trailing_whitespace = true + +# Mirrors the repository's .globalconfig: undeclared public surface is the gate's +# concern (stage 5a), never a build warning that would move the warning baseline. +dotnet_diagnostic.RS0016.severity = suggestion +dotnet_diagnostic.RS0017.severity = suggestion diff --git a/scripts/quality-gate/fixtures/_base/Sample/PublicAPI.Shipped.txt b/scripts/quality-gate/fixtures/_base/Sample/PublicAPI.Shipped.txt new file mode 100644 index 000000000..7dc5c5811 --- /dev/null +++ b/scripts/quality-gate/fixtures/_base/Sample/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/scripts/quality-gate/fixtures/_base/Sample/PublicAPI.Unshipped.txt b/scripts/quality-gate/fixtures/_base/Sample/PublicAPI.Unshipped.txt new file mode 100644 index 000000000..7f65331b9 --- /dev/null +++ b/scripts/quality-gate/fixtures/_base/Sample/PublicAPI.Unshipped.txt @@ -0,0 +1,3 @@ +#nullable enable +Sample.Widget +static Sample.Widget.Add(int a, int b) -> int diff --git a/scripts/quality-gate/fixtures/_base/Sample/Sample.csproj b/scripts/quality-gate/fixtures/_base/Sample/Sample.csproj index 30380c283..198eb534a 100644 --- a/scripts/quality-gate/fixtures/_base/Sample/Sample.csproj +++ b/scripts/quality-gate/fixtures/_base/Sample/Sample.csproj @@ -11,4 +11,13 @@ false false + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + diff --git a/scripts/quality-gate/fixtures/api-undeclared/expect.json b/scripts/quality-gate/fixtures/api-undeclared/expect.json new file mode 100644 index 000000000..f7f768a1c --- /dev/null +++ b/scripts/quality-gate/fixtures/api-undeclared/expect.json @@ -0,0 +1,12 @@ +{ + "description": "A new public type is added but not declared in PublicAPI.Unshipped.txt — the miss that reached CI on a real PR because --fast skipped the check. Build, format and tests are green (RS0016 is a suggestion, so the build stays at baseline), and the Public API stage must FAIL in --fast. Guards that the inner loop, not CI, is where undeclared surface is first reported.", + "mode": "--fast", + "exit": 1, + "verdict": "FAIL", + "stages": [ + { "id": "1a", "status": "PASS" }, + { "id": "1b", "status": "PASS" }, + { "id": "2", "status": "PASS" }, + { "id": "5a", "status": "FAIL", "detailContains": "undeclared" } + ] +} diff --git a/scripts/quality-gate/fixtures/api-undeclared/overlay/Sample/Gadget.cs b/scripts/quality-gate/fixtures/api-undeclared/overlay/Sample/Gadget.cs new file mode 100644 index 000000000..f5a4f4bba --- /dev/null +++ b/scripts/quality-gate/fixtures/api-undeclared/overlay/Sample/Gadget.cs @@ -0,0 +1,6 @@ +namespace Sample; + +public static class Gadget +{ + public static int Double(int value) => value * 2; +} diff --git a/scripts/quality-gate/fixtures/build-broken/expect.json b/scripts/quality-gate/fixtures/build-broken/expect.json index 132a9f0b1..695d8f2ac 100644 --- a/scripts/quality-gate/fixtures/build-broken/expect.json +++ b/scripts/quality-gate/fixtures/build-broken/expect.json @@ -1,11 +1,12 @@ { - "description": "Production code does not compile. Build must FAIL, and format + tests must SKIP causally (not PASS) because a failed build makes them impossible. This is the core invariant: a check that could not run must never read as passed.", + "description": "Production code does not compile. Build must FAIL, and format + tests must SKIP causally (not PASS) because a failed build makes them impossible. This is the core invariant: a check that could not run must never read as passed. The Public API check compiles too, so it must SKIP for the same reason.", "mode": "--fast", "exit": 1, "verdict": "FAIL", "stages": [ { "id": "1a", "status": "FAIL" }, { "id": "1b", "status": "SKIP" }, - { "id": "2", "status": "SKIP" } + { "id": "2", "status": "SKIP" }, + { "id": "5a", "status": "SKIP", "detailContains": "build failed" } ] } diff --git a/scripts/quality-gate/fixtures/clean/expect.json b/scripts/quality-gate/fixtures/clean/expect.json index bf9d564d9..925c14910 100644 --- a/scripts/quality-gate/fixtures/clean/expect.json +++ b/scripts/quality-gate/fixtures/clean/expect.json @@ -1,11 +1,12 @@ { - "description": "A well-formed package: builds, no warnings, formatted, tests green.", + "description": "A well-formed package: builds, no warnings, formatted, tests green. Its declared public surface matches the compiled one, so the Public API stage runs in --fast and passes.", "mode": "--fast", "exit": 0, "verdict": "PARTIAL", "stages": [ { "id": "1a", "status": "PASS" }, { "id": "1b", "status": "PASS" }, - { "id": "2", "status": "PASS" } + { "id": "2", "status": "PASS" }, + { "id": "5a", "status": "PASS" } ] } diff --git a/scripts/quality-gate/gate.sh b/scripts/quality-gate/gate.sh index 286c34abd..620cfafd8 100755 --- a/scripts/quality-gate/gate.sh +++ b/scripts/quality-gate/gate.sh @@ -3,7 +3,7 @@ # gate.sh — the Supabase C# SDK quality gauntlet (QUALITY_RUBRIC §4), as a program. # # gate.sh [dir] full gate — build, tests, security, public API, E2E -# gate.sh [dir] --fast inner loop only — the agent's red/green cycle +# gate.sh [dir] --fast inner loop + public-API declaration — the agent's red/green cycle # gate.sh [dir] --mutation evaluate a Stryker report (a separate CI job produces # it; not run here). Opt-in — off the default/PR path. # gate.sh [dir] --bypass-format format + naming reports as a signal, not a @@ -189,12 +189,15 @@ else add 2 "Inner loop (Unit + Contract)" block "" SKIP "not run — build failed" "" fi + # The sync check compiles (dotnet format runs the analyzers), so a failed build + # makes it impossible, not failing — skip it causally, as with format and tests. + # It runs in --fast too: it costs seconds on a warm build, and an undeclared + # public member that only CI reports is found after the push instead of before. + if [[ $BUILD_OK -eq 1 ]]; then stage_api_sync + else add 5a "Public API declared" block "" SKIP "not run — build failed" ""; fi + if [[ "$MODE" != "fast" ]]; then stage_security - # The sync check compiles (dotnet format runs the analyzers), so a failed build - # makes it impossible, not failing — skip it causally, as with format and tests. - if [[ $BUILD_OK -eq 1 ]]; then stage_api_sync - else add 5a "Public API declared" block "" SKIP "not run — build failed" ""; fi stage_api_diff if [[ $BUILD_OK -eq 0 ]]; then diff --git a/scripts/quality-gate/lib/report.sh b/scripts/quality-gate/lib/report.sh index 0abc3f71b..3aa0419cc 100644 --- a/scripts/quality-gate/lib/report.sh +++ b/scripts/quality-gate/lib/report.sh @@ -66,7 +66,7 @@ print_verdict() { # print_verdict echo case "$1" in PASS) echo "${GRN}${BLD}GATE: PASS${OFF} (exit 0) — blocking stages green; signal stages are the maintainer's call." ;; - PARTIAL) echo "${YEL}${BLD}GATE: PARTIAL${OFF} (exit 0) — inner loop only. Re-run without --fast before a PR." ;; + PARTIAL) echo "${YEL}${BLD}GATE: PARTIAL${OFF} (exit 0) — fast mode, a subset of the gate. Re-run without --fast before a PR." ;; INCOMPLETE) echo "${YEL}${BLD}GATE: INCOMPLETE${OFF} (exit 2) — a blocking stage could not run. Unverified ≠ verified." ;; FAIL) echo "${RED}${BLD}GATE: FAIL${OFF} (exit 1) — fix the cause, not the check: no #pragma disable, no" echo "severity downgrade, no re-categorising to dodge the filter, no deleting a red test." ;;