Skip to content

Commit 66940c0

Browse files
authored
fix(observability-map): narrow the required check and the report bot's comment lookup (#4507)
## Findings addressed - **Report bot edited the wrong comment.** The comment-lookup step matched on the marker body text with no author predicate, so it would silently PATCH a human's comment that happened to quote the marker (GitHub gates comment editing on write access, not authorship, so it never 403'd). Now constrained to `.user.login == "github-actions[bot]"`, the same identity `helm-prerelease.yml` already pins. - **A required check asserted facts about the whole webapp namespace.** `webappSymbols.test.ts` asserted that nobody anywhere in `apps/webapp` (walking locals, params, object keys) declares names like `createJWT`/`updateEnvVars`, so an unrelated PR naming a local variable failed a required check with a message pointing at nothing. Those negative self-tests move onto a package-owned fixture tree; the positive resolution assertions stay required (their absence rotted the tool before) but now name the list to edit. - **The suite ran twice on shared paths.** `obsmap` and `internal` path filters shared four generic paths (`package.json`, both lockfiles, `pr_checks.yml`), so any lockfile bump ran the observability-map suite in both jobs. Dropped from `obsmap` (where `internal` already covers them). The test that should have caught it only checked the package's own source path; it now asserts the two filters' path intersection is empty. - **PR-comment footer** reworded: it said the report gates nothing, which is true of the report but misled now that the tool's test suite does gate webapp PRs. Names both failure directions and where to read the rules. - **Nightly corpus** comment corrected (stale entry count; the failure-notification gap is documented, not silently implied). ## Review Two adversarial reviewers ran over the diff; both findings were verified and fixed: a hollow fixture assertion (a shared name satisfied either walker branch — now one name per declaration form, revert-confirmed) and a filter-intersection test that could be fooled by apostrophes in comment prose (now strips comment lines first). Full package suite green (877 passed), typecheck and format clean.
1 parent b208062 commit 66940c0

10 files changed

Lines changed: 172 additions & 54 deletions

File tree

.github/workflows/observability-map.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ jobs:
8989
found=""
9090
ok=""
9191
for attempt in 1 2 3; do
92+
# Matched by login, not .user.type == "Bot": other bots and apps on the same PR are
93+
# also type Bot, and login is the exact identity this token's own comments carry.
9294
if found=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --paginate \
93-
--jq '[.[] | select((.body // "") | startswith("<!-- observability-map-report -->"))][0].id // empty'); then
95+
--jq '[.[] | select(.user.login == "github-actions[bot]" and ((.body // "") | startswith("<!-- observability-map-report -->")))][0].id // empty'); then
9496
ok=1
9597
break
9698
fi
@@ -116,23 +118,32 @@ jobs:
116118
} >> "$GITHUB_OUTPUT"
117119
118120
# The tree-scale mutation corpus: every known laundering shape applied to the whole route tree,
119-
# asserting the score does not rise. Roughly four and a half minutes for 45 entries, which is why
120-
# it is gated out of the package's default `pnpm test` and run here instead. Unlike the report
121-
# job below it has no token to lose, so it runs for fork PRs too, and unlike the report job it is
121+
# asserting the score does not rise. 53 entries, a couple of minutes of a runner and a good deal
122+
# longer on a laptop, which is why it is gated out of the package's default `pnpm test` and run
123+
# here instead. Unlike the report job
124+
# below it has no token to lose, so it runs for fork PRs too, and unlike the report job it is
122125
# allowed to fail the build.
123126
#
124127
# Gated to this package's own paths rather than running on every route pull request. What the
125128
# corpus measures is the TOOL's resistance to laundering, and only an edit to the tool can weaken
126-
# that, so a routes-only change was paying four and a half minutes of a 4x runner for a result
127-
# that could not differ from the last one. It was also the worst kind of job to spend that on: a
128-
# red x that fires on a large share of webapp pull requests, is allowed to fail, and gates
129-
# nothing, which is the shape people learn to scroll past.
129+
# that, so a routes-only change was paying a couple of minutes of a 4x runner for a result that
130+
# could not differ from the last one. It was also the worst kind of job to spend that on: a red x
131+
# that fires on a large share of webapp pull requests, is allowed to fail, and gates nothing, which is
132+
# the shape people learn to scroll past.
130133
#
131134
# What this gives up is real and small. A route landing a shape no corpus entry has seen can make
132135
# a known laundering mutation start paying, and that is now caught by the nightly rather than by
133136
# the pull request that caused it. Tree drift accrues over months, so a day is the right
134137
# granularity for it; the tool's own regressions, which are the ones a single commit can cause,
135138
# still gate per pull request.
139+
#
140+
# Nothing in this repo watches whether the nightly itself succeeds: no Slack webhook and no
141+
# issue-on-failure step here or in e2e-webapp-auth-full.yml, the only other scheduled workflow, so
142+
# there is no house pattern to follow. A broken corpus fails quietly on the 3am cron, red only in
143+
# the Actions tab,
144+
# for as long as nobody checks it. Wiring up a real notification needs infrastructure (a Slack
145+
# webhook secret, at minimum) that does not exist here yet, so this is a known, unfixed gap
146+
# rather than a fixed one.
136147
mutation-corpus:
137148
name: 🧬 Mutation corpus
138149
needs: changes

.github/workflows/pr_checks.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,16 @@ jobs:
104104
# `unit-tests-internal.yml` runs `turbo run test --filter "@internal/*"`, which picks up
105105
# @internal/observability-map and runs the same vitest suite. Listing them here as well
106106
# ran the suite twice on every PR touching them, which was this filter's own doing.
107+
#
108+
# Also deliberately NOT here: pr_checks.yml, package.json, pnpm-lock.yaml,
109+
# pnpm-workspace.yaml. `internal` already lists all four, so a PR touching only one of
110+
# them ran this suite twice for the same reason as above. Editing pr_checks.yml no
111+
# longer runs this job live as a result; integration.test.ts still asserts on its text
112+
# via the `internal` job.
107113
obsmap:
108114
- 'apps/webapp/app/**'
109-
- '.github/workflows/pr_checks.yml'
110115
- '.github/workflows/unit-tests-observability-map.yml'
111116
- '.github/workflows/observability-map.yml'
112-
- 'package.json'
113-
- 'pnpm-lock.yaml'
114-
- 'pnpm-workspace.yaml'
115117
cli:
116118
- 'packages/cli-v3/**'
117119
- 'packages/build/**'

internal-packages/observability-map/INTERNALS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,4 +497,5 @@ steps degrade to a stale report, which at least stays one comment.
497497

498498
The corpus runs on the package's own paths and on a schedule rather than on every route pull request,
499499
because it measures the tool's resistance to laundering, which only an edit to the tool can weaken,
500-
and it costs four and a half minutes. The nightly covers tree drift late rather than not at all.
500+
and it costs a couple of minutes of a runner. The nightly covers tree drift late rather than not at
501+
all.

internal-packages/observability-map/README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ A pull request touching `apps/webapp/app/routes` or this package gets a sticky c
3131
against the tip of the base branch, with the score, what changed, and the current fix list. Every
3232
comment names the head commit it was rendered for, as a link to the compare range, because the
3333
comment is edited in place across pushes and otherwise says nothing about which push it reflects. It
34-
is report-only: nothing here fails the build or blocks a merge. See
35-
`.github/workflows/observability-map.yml`.
34+
is report-only: nothing in the comment or its score fails the build or blocks a merge. Separately,
35+
this package's test suite runs as a required check, on pull requests touching `apps/webapp/app` and
36+
on any other package through the internal job, and fails when a symbol the tool references stops
37+
resolving in one of the three trees it reads (`apps/webapp/app`, `packages/plugins/src`,
38+
`internal-packages/rbac/src`), or when the first route with an anticipated sensitive segment lands.
39+
Each failure names the list to update (`src/webappSymbols.test.ts`).
40+
See `.github/workflows/observability-map.yml`.
3641

3742
The workflow runs on every pull request and applies the path list as a gate inside the job rather
3843
than as a `paths:` filter on the trigger. GitHub evaluates one of those per workflow, so a pull
@@ -86,7 +91,7 @@ find there.
8691

8792
### What stops it being gamed
8893

89-
`src/mutationCorpus.test.ts` applies 44 semantics-preserving or handling-deleting rewrites to the
94+
`src/mutationCorpus.test.ts` applies 53 semantics-preserving or handling-deleting rewrites to the
9095
whole route tree in a temp copy and asserts three things for each: the published global does not
9196
rise, the mean over the routes measured in both runs does not rise, and for a semantics-preserving
9297
rewrite no individual route's score rises or drops out of the measured set. Every laundering shape a
@@ -97,14 +102,17 @@ score from 19 to 8, so the metric does not pay you for removing error handling.
97102
in `try { ... } catch (e) { throw e }` leaves the global at 19 and raises no route, so it does not
98103
pay you for adding error handling that does nothing either.
99104

100-
One hole is open and the corpus says so. A catch over `try { 0; }` is refused, but `canRaise`
105+
Two holes are open and the corpus says so. A catch over `try { 0; }` is refused, but `canRaise`
101106
accepts any call, so `try { String(0); }` reads as real error handling: it takes the tree from 19 to
102107
44 and raises 224 routes. Telling an inert call from one that can throw needs types the scanner does
103-
not have. That entry, `dead-classifying-try-with-call`, runs as an expected failure with the
104-
residual written out beside it, so the claim is "43 rewrites are defended and here is the one that
105-
is not", never "unpaddable".
106-
107-
The corpus takes about four and a half minutes, so it is gated behind `OBS_MAP_MUTATION_CORPUS=1`
108+
not have. The second, `dead-conjunction-instanceof-if`, is a dead condition rather than a dead arm:
109+
`selectsADistinctPath` folds the arm, and `literalTruth` treats `&&` as always null on purpose so a
110+
live guard is never read as dead, so widening that fold is a different rule needing its own
111+
measurement. Both run as expected failures with the residual written out beside them, so the claim
112+
is "51 rewrites are defended and here are the two that are not", never "unpaddable".
113+
114+
The corpus takes minutes rather than seconds, under two on CI's runner and closer to eight on a
115+
laptop, so it is gated behind `OBS_MAP_MUTATION_CORPUS=1`
108116
and runs as its own CI job rather than in `pnpm test`. Run it if you change this package:
109117

110118
```bash
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// webappSymbols.test.ts's self-test tree. One name per declaration form, never two forms of the same
2+
// name: a single `has` assertion cannot say which branch of the walker answered it, so a shared name
3+
// would let a branch be deleted with the fixture test still green. `helper` covers the function
4+
// declaration, `createJWT` the local, `mintSessionToken` the member. `signJWT` is read and declared
5+
// nowhere, so a walker that collected references as declarations would find it.
6+
export function helper(kind: string): boolean {
7+
const createJWT = kind === "jwt";
8+
return createJWT;
9+
}
10+
11+
export const api = {
12+
mintSessionToken: false,
13+
};
14+
15+
export function reads(payload: Record<string, unknown>): unknown {
16+
return payload.signJWT;
17+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Only the file name matters: `routeSegments` reads directory entries, never content.
2+
export {};

internal-packages/observability-map/src/integration.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ describe("the report workflow's one source of the comment id", () => {
128128
expect(lookup).toBeDefined();
129129
expect(lookup).toContain("exit }'");
130130
});
131+
132+
it("only reconciles a comment github-actions[bot] posted, not anyone quoting the marker", () => {
133+
const lookup = steps(job("changes")).find((step) =>
134+
step.includes('startswith("<!-- observability-map')
135+
)!;
136+
expect(lookup).toContain('.user.login == "github-actions[bot]"');
137+
});
131138
});
132139

133140
/**
@@ -257,6 +264,32 @@ describe("the package's tests are wired into the gate", () => {
257264
).toContain('--filter "@internal/*"');
258265
});
259266

267+
// The test above only checks the package's own source path, a different overlap that was already
268+
// fixed. It has no way to catch a shared *generic* path (package.json, a lockfile, this workflow
269+
// file itself) added to both filters, which is its own way to run the suite twice. Asserted as the
270+
// actual set intersection, not another hardcoded path, so any future shared path fails this too.
271+
it("shares no path with the internal filter, so the suite runs once", () => {
272+
const text = read(PR_CHECKS);
273+
// Comment lines are dropped before matching: an apostrophe in prose ("this filter's own doing")
274+
// otherwise pairs with a real path's quote and swallows it, which would be a silent false pass.
275+
const pathsOf = (name: string, next: string) =>
276+
new Set(
277+
[
278+
...text
279+
.split(` ${name}:`)[1]!
280+
.split(` ${next}:`)[0]!
281+
.split("\n")
282+
.filter((line) => !line.trim().startsWith("#"))
283+
.join("\n")
284+
.matchAll(/'([^']+)'/g),
285+
].map((m) => m[1])
286+
);
287+
const internal = pathsOf("internal", "obsmap");
288+
const obsmap = pathsOf("obsmap", "cli");
289+
const shared = [...obsmap].filter((p) => internal.has(p));
290+
expect(shared).toEqual([]);
291+
});
292+
260293
it("is in the all-checks needs list, or it gates nothing", () => {
261294
const needs = read(PR_CHECKS).split(" needs:").pop()!.split(" if: always()")[0]!;
262295
expect(needs).toContain("- obsmap");

internal-packages/observability-map/src/report/prComment.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,15 @@ describe("renderPrComment", () => {
432432
expect(renderPrComment(head, null)).not.toContain("Warning: parse failures");
433433
});
434434

435-
it("footer names the report-only rule and the readme", () => {
435+
it("footer names the report-only rule, the required suite that is not it, and the readme", () => {
436436
const head = buildReport([scanFile("api.v1.a.ts", cleanSource)!], []);
437437
const out = renderPrComment(head, null);
438-
expect(out).toContain("Report only, nothing here gates the merge.");
438+
expect(out).toContain("report-only and never gate the merge");
439+
expect(out).toContain("a required test suite");
440+
// Both directions. A footer naming only the rename case sends the author who added the first
441+
// `secrets` route looking for a rename they never made.
442+
expect(out).toContain("renames or removes a symbol");
443+
expect(out).toContain("adds the first route with a segment");
439444
expect(out).toContain("internal-packages/observability-map/README.md");
440445
});
441446
});

internal-packages/observability-map/src/report/prComment.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ export type CommitContext = {
2525

2626
const SHORT_SHA_LENGTH = 7;
2727

28+
/**
29+
* Closes every comment this job posts. The second sentence is there because the package's own test
30+
* suite does gate webapp pull requests, and a blocked author's first stop is this footer, which used
31+
* to tell them nothing gates anything.
32+
*/
33+
const FOOTER =
34+
"The score and findings here are report-only and never gate the merge. Separately, a required " +
35+
"test suite keeps this tool's symbol and route lists in sync with the code they name, and can " +
36+
"fail a pull request that renames or removes a symbol they reference, or that adds the first " +
37+
"route with a segment they anticipate. Each failure names the list to edit. The rules and their " +
38+
"reasons: internal-packages/observability-map/README.md.";
39+
2840
/** Directly under the heading, because the comment is edited in place across pushes and the first
2941
* question about it is which push it reflects. */
3042
function commitLines(commit: CommitContext | undefined): string[] {
@@ -255,8 +267,7 @@ export function renderResolvedComment(commit?: CommitContext): string {
255267
"Nothing in this pull request moves the report any more. The findings an earlier push " +
256268
"reported are gone.",
257269
"",
258-
"Report only, nothing here gates the merge. The rules and their reasons: " +
259-
"internal-packages/observability-map/README.md.",
270+
FOOTER,
260271
].join("\n");
261272
}
262273

@@ -275,8 +286,7 @@ export function renderScanFailedComment(commit?: CommitContext): string {
275286
"The scan failed for this run, so there is no report. Anything above is from an earlier push " +
276287
"and is stale. The workflow log has the error.",
277288
"",
278-
"Report only, nothing here gates the merge. The rules and their reasons: " +
279-
"internal-packages/observability-map/README.md.",
289+
FOOTER,
280290
].join("\n");
281291
}
282292

@@ -319,10 +329,7 @@ export function renderPrComment(
319329
lines.push("```", "", "</details>", "");
320330
}
321331

322-
lines.push(
323-
"Report only, nothing here gates the merge. The rules and their reasons: " +
324-
"internal-packages/observability-map/README.md."
325-
);
332+
lines.push(FOOTER);
326333

327334
const headFailures = head.parseFailures.length;
328335
const baseFailures = base?.parseFailures.length ?? 0;

0 commit comments

Comments
 (0)