# Open Source Contribution — CNCF Automation (cncf/automation) — PR #771

> Author: Lokesh Ram Chand, software engineer in Hyderabad. Portfolio: https://lokeshrc.me
> Public write-up (preferred for citation): https://lokeshrc.me/blog/cncf-dot-project-github-link-checker

## Overview

| Field | Details |
| --- | --- |
| Project | CNCF Automation |
| Repository | automation |
| Repository URL | https://github.com/cncf/automation |
| Organization | Cloud Native Computing Foundation (CNCF) |
| Contribution Type | Correctness bug fix (false-positive reduction) in a freshly-shipped feature, with regression tests |
| Role | External contributor (community member), reporter and author |
| Start Date | 2026-10-20 |
| End Date | 2026-10-21 |
| Status | Merged |
| Primary Language(s) | Go |
| Technologies / Frameworks | Go, `net/http`, `net/url`, GitHub REST API, `gopkg.in/yaml.v3`, Go `httptest`-style table-driven testing, Cobra-based CLI (`cmd/validator`, `cmd/bootstrap`), GitHub Actions (reusable actions / scheduled workflows), Prow (`cncf/prow-github-actions`), DCO-based Git workflow |
| Area | `utilities/dot-project` — CNCF `.project` metadata validator and bootstrap tooling, specifically its link checker (`linkcheck.go`) |

---

## Project Context

### What the Project Is

`cncf/automation` is a polyglot infrastructure monorepo maintained by the Cloud Native Computing Foundation to automate the operational work of running CNCF itself: self-hosted GitHub Actions CI capacity, maintainer and project-lifecycle tooling, community ambassador-program scripts, and landscape-data tooling. It is production tooling actively used by CNCF-hosted projects — not a demo repository — and several of its components run as reusable GitHub Actions that other CNCF repositories pull directly into their own CI.

The repository has no root build and no shared package manager; each pillar is independent and worked on from inside its own subdirectory:

- **`ci/`** — self-hosted GitHub Actions runner infrastructure (the subsystem touched by this contributor's two earlier contributions, PRs #763 and #769): Go programs that launch ephemeral compute across Oracle Cloud Infrastructure, KubeVirt-on-Kubernetes, and a manually-run GCP path to run individual CI jobs, plus the Terraform/OpenTofu, Packer, and Helm/ArgoCD tooling behind them.
- **`utilities/`** — standalone Go and Python tools, including the component this contribution touches: `dot-project`, a validator and scaffolding tool for the `.project` metadata (`project.yaml`, `maintainers.yaml`, `projectlist.yaml`) that every CNCF-hosted project repository is expected to carry.
- **`Ambassadors/`** and **`Kubestronaut/`** — Python automation for CNCF's community programs.
- **`tests/syntax_check.py`** — a lightweight, credential-free CI gate that `py_compile`s every tracked Python file in the repository.

The repository's six independent Go modules (`ci/cloudrunners`, `ci/gha-runner-vm`, `ci/gha-runner-vm-oci`, `utilities/dot-project`, `utilities/landscape-mcp-server`, `utilities/landscape-sync`) each own their own `go.mod`, build, and test command, with no Go workspace tying them together — a deliberate choice that keeps the dependency graph of, say, a GitHub-API link checker, from ever needing to agree on a dependency version with an Oracle Cloud SDK consumer. The one cross-cutting rule enforced uniformly across all six is a strict Go-version guard (`.go-version` as the single source of truth, checked by `.github/scripts/check-go-version.sh` against every `go.mod`, Dockerfile, and workflow).

Governance follows the standard CNCF/Kubernetes community-tooling model: Prow slash commands (`/kind`, `/area`, `/priority`, `/status`, `/lgtm`, `/approve`, `/hold`) routed through `cncf/prow-github-actions`, per-directory `OWNERS` files declaring reviewers/approvers, mandatory DCO sign-off on every commit, and an expectation that GitHub Actions workflows are SHA-pinned (checked by the Kusari Inspector).

### My Contribution Context

`utilities/dot-project` is a CLI toolkit, built with Cobra, shipping three binaries from `cmd/` (`validator`, `landscape-updater`, and `bootstrap`; only the first two ship in the project's Docker image, with `validator` as its entrypoint). Its job is to validate and help scaffold the `.project` metadata files (`project.yaml`, `maintainers.yaml`) that CNCF uses to track project ownership, maturity, repositories, and maintainer rosters across its entire portfolio. Two reusable GitHub Actions in the parent repository's `.github/actions/` (`validate-project`, `validate-maintainers`) wrap the `validator` binary for use by any CNCF project's own CI, and a third (`check-links`) runs a biweekly scheduled scan that opens, updates, or closes a "Broken links in `.project` metadata" issue in a project's repository.

All three of those surfaces share one opt-in feature, `check_links` (default `false` in both the schema and the GitHub Actions wrapper inputs): when enabled, the validator doesn't just check that a URL, `PathRef`, or maintainer handle is syntactically well-formed — it actually fetches it, and reports a 404/410 as a hard validation error (on a PR check), as a tracked issue (on the scheduled scan), or as a link to comment out of a generated `project.yaml` with a `# TODO` (during `bootstrap`'s provisioning of a brand-new project repository).

That feature — the entire link-checking subsystem (`linkcheck.go`, plus its bootstrap integration in `bootstrap_linkcheck.go`) — had been merged into the repository only the day before this contribution, via PR #740 ("feat: add link checker and maintainers handle check," by maintainer and `utilities/dot-project` `OWNERS`-file approver Ahmad Bader (`ahmadqasembader`), merged 2026-10-19T13:55:22Z, a substantial ~1,900-line addition across 19 files). This contribution, filed less than 24 hours after that feature first shipped, is a correctness fix to a specific, demonstrable false-positive class in the brand-new `checkGitHub` function at the heart of it — found and fixed before the feature had been in the codebase long enough to affect any real project, since `check_links` is opt-in and off by default.

### Relevant Component

- `utilities/dot-project/linkcheck.go` — the file this PR modifies; specifically `(*LinkChecker).checkGitHub`, the function that maps a `github.com` URL onto the GitHub REST API endpoint whose existence proves the page is real, and the `(*LinkChecker).checkOne`/`classify` machinery around it that turns an HTTP status code into a `LinkOK`/`LinkWarning`/`LinkBroken` verdict.
- `utilities/dot-project/linkcheck_test.go` — the existing unit-test file for the link checker (introduced in PR #740), extended by this PR with new table-driven cases.
- `utilities/dot-project/bootstrap_linkcheck_test.go` — a test exercising `CheckBootstrapLinks` against a mock HTTP server standing in for both the GitHub REST API and `github.com` itself; this PR corrects that mock's behavior to accurately model github.com's real response to a nonexistent user, which the pre-fix mock was getting wrong in a way that happened to mask this exact bug class in its own test suite.
- `utilities/dot-project/bootstrap_linkcheck.go` — read for context (not modified): the integration point where `CheckBootstrapLinks` consumes `LinkChecker.Check` results to decide which links `GenerateProjectYAML` should comment out of a freshly scaffolded `project.yaml`.
- `utilities/dot-project/AGENT.md` / `SCHEMA.md` / `README.md` — the module's own internal documentation describing the `check_links` feature, its opt-in default, and the three surfaces (PR check, scheduled scan, bootstrap) it affects; read to confirm the accurate scope and severity of the bug.

---

# Contributions

## Contribution 1 — Stop the `dot-project` link checker from reporting valid non-repository github.com pages (sponsors, apps, topics, marketplace, enterprises) as broken links

**Type:** Correctness bug fix (false-positive reduction) in a one-day-old feature, with new regression tests and a corrected test fixture
**Status:** Merged (PR #771), closing issue #770
**Date:** Reported and fixed 2026-10-20; merged 2026-10-21 at 11:32:30 UTC

### Problem

`checkGitHub` works by parsing a `github.com` URL's path segments and mapping them onto the one GitHub REST API endpoint that would prove the page corresponds to something real:

```go
func (c *LinkChecker) checkGitHub(ctx context.Context, u *url.URL) (LinkStatus, string) {
	seg := strings.FieldsFunc(u.Path, func(r rune) bool { return r == '/' })
	var api string
	contents := false
	switch {
	case len(seg) == 0:
		return LinkOK, ""
	case len(seg) >= 2 && seg[0] == "orgs":
		api = "/orgs/" + url.PathEscape(seg[1])
	case len(seg) == 1:
		api = "/users/" + url.PathEscape(seg[0])
	default:
		owner, repo := url.PathEscape(seg[0]), url.PathEscape(strings.TrimSuffix(seg[1], ".git"))
		api = "/repos/" + owner + "/" + repo
		switch {
		case len(seg) >= 4 && (seg[2] == "blob" || seg[2] == "tree"):
			api += "/contents/" + escapePath(seg[4:]) + "?ref=" + url.QueryEscape(seg[3])
			contents = true
		case len(seg) >= 4 && (seg[2] == "issues" || seg[2] == "pull"):
			api += "/issues/" + url.PathEscape(seg[3])
		}
	}
	...
}
```

This mapping is correct for the URL shapes the GitHub REST API actually has endpoints for: a single path segment is treated as a user handle (`/users/<handle>`), two-plus segments are treated as `owner/repo` (`/repos/<owner>/<repo>`), `orgs/<name>` is treated as an organization, and `blob`/`tree` file links are mapped to the repository-contents endpoint. The problem is that `github.com` serves a large number of *other* URL shapes that are not users, organizations, or repositories at all, and have no corresponding REST API endpoint whatsoever — pages like:

- `github.com/sponsors/<user>` (GitHub Sponsors profile)
- `github.com/apps/<app>` (a GitHub App's marketplace listing)
- `github.com/topics/<topic>` (a topic-tag browse page)
- `github.com/marketplace/actions/<action>` (a Marketplace Action listing)
- `github.com/enterprises/<name>` (an Enterprise account's public page)

Each of these has exactly one path segment after a reserved first segment (`sponsors`, `apps`, `topics`, `marketplace`, `enterprises`), which means `checkGitHub`'s `switch` falls into the `default` branch and parses it as `owner=sponsors, repo=<user>` (or `owner=apps, repo=<app>`, etc.), builds `/repos/sponsors/<user>`, and queries that against the REST API. There is no such repository, the API correctly returns 404, and — because the surrounding fallback-to-`github.com` logic was gated specifically on `contents` (true only for `blob`/`tree` links) — that 404 was taken at face value and the link reported `LinkBroken`, even though the page loads perfectly well for an actual human visiting it in a browser.

The practical effect, as both the issue and the PR description spell out precisely: when a project enables the opt-in `check_links` feature, any `.project` metadata file (or a brand-new project being scaffolded by `bootstrap`) containing one of these perfectly valid link shapes would (a) fail its PR check, (b) have a "Broken links in `.project` metadata" issue opened or updated against it by the biweekly scheduled scan, and (c) have the link silently commented out under a `# TODO` by `bootstrap` when generating a new project's `project.yaml` — with no way to opt a single link out of the check once enabled. None of this was a crash or an outage; it was a correctness bug that would quietly produce wrong, user-visible verdicts about links that are completely fine.

### My Work

I found this on the day immediately after the link-checking feature itself (PR #740) was merged, by reading the new `checkGitHub` implementation closely enough to ask "what GitHub URL shapes exist that this switch statement doesn't account for?" rather than only checking that the shapes it *does* handle work correctly. That's a meaningfully different review posture than testing a feature against its own intended cases — it's specifically hunting for the shapes the author didn't have in mind, which is exactly where a brand-new feature like this is most likely to have gaps, since the existing test suite (added in the same PR that introduced the feature) can only have exercised the cases its author thought to write down.

Rather than guessing at a list of "reserved" GitHub route names from memory, I verified the actual, current scope of the problem directly against live GitHub:

```
https://github.com/sponsors/torvalds              -> broken (404 Not Found)
https://github.com/apps/dependabot                -> broken (404 Not Found)
https://github.com/topics/kubernetes              -> broken (404 Not Found)
https://github.com/marketplace/actions/checkout   -> broken (404 Not Found)
https://github.com/enterprises/cncf               -> broken (404 Not Found)
```

using well-known, unambiguously real examples (Linus Torvalds' GitHub Sponsors page, the Dependabot app, the `kubernetes` topic, the official `actions/checkout` Marketplace listing, and CNCF's own Enterprise account) specifically so the false-positive claim couldn't be dismissed as resting on an edge case or a typo. I confirmed that all five return 200 on the actual website while `GET /repos/<first-segment>/<second-segment>` returns 404 for each against the real REST API — directly demonstrating the exact mismatch the code's `default` branch produces.

I then went further than confirming the specific five examples and quantified the real scope of the false-positive problem: I ran the actual, unmodified `LinkChecker` against 41 real GitHub URLs and found 30 reported as broken, of which 27 were false positives of this exact kind — a concrete, measured estimate of how aggressively the then-current code over-reported broken links, not just a demonstration that the bug existed in principle. I used that same 41-URL set again, post-fix, to validate the correction (see **Testing**, below) rather than relying solely on the new unit-test cases.

I also did the harder, more valuable analytical work of identifying what the *correct general fix* should be, rather than patching only the five specific route names I'd found. I recognized that the existing code already had the right mechanism for a structurally identical problem — it already fell back to checking `github.com` directly whenever the REST API's branch-resolution logic for `blob`/`tree` links couldn't follow a renamed default branch (`master` → `main`) — and that the *general* lesson underneath both problems is the same: a REST API 404 proves nothing on its own, because the API only has endpoints for a strict subset of what `github.com` actually serves (users, orgs, repos, and a few repo sub-resources); only `github.com` itself can authoritatively say a page doesn't exist. I proposed broadening the existing fallback to cover every 404, not just the `blob`/`tree` case — and explicitly weighed this against the alternative of hard-coding a denylist of GitHub's reserved route names (`sponsors`, `apps`, `topics`, `marketplace`, `enterprises`, and whatever others might exist or be added later), rejecting the denylist approach in the issue itself as "smaller and less brittle" to implement the general check instead of trying to keep an exhaustive list of reserved words in sync with GitHub's own product surface over time.

Finally — and this is the detail that most distinguishes this from a purely theoretical fix — I explicitly worked out and stated the fix's own trade-offs and remaining known limitations *before* writing any code, rather than presenting a seemingly complete fix and letting a reviewer discover its edges later:

- Links to a nonexistent release, wiki page, or discussion inside a repository that *does* exist would continue to be accepted, because the REST API has no endpoint to check those specific sub-resources either, and the existing code already treats "any other repository page is accepted when the repository exists" as documented, intentional behavior — I was explicit that my fix doesn't change this pre-existing, separate limitation.
- Under the broadened fallback, a GitHub *reserved route name* used as a maintainer handle (for example, someone entering `pricing` as a GitHub handle) would now incorrectly be treated as "exists," because `github.com/pricing` serves a real marketing page and the web fallback would return 200 for it — but I verified and stated that this is not actually exploitable in practice, because GitHub does not allow registering an account using any of its reserved route names, so no real maintainer handle could ever collide with this.

### Technical Implementation

The code change itself, in `linkcheck.go`, is a small, targeted broadening of an existing mechanism rather than a new one:

```diff
 func (c *LinkChecker) checkGitHub(ctx context.Context, u *url.URL) (LinkStatus, string) {
 	seg := strings.FieldsFunc(u.Path, func(r rune) bool { return r == '/' })
 	var api string
-	contents := false
 	switch {
 	...
 		case len(seg) >= 4 && (seg[2] == "blob" || seg[2] == "tree"):
-			// Refs may contain slashes, but nearly every .project link
-			// points at a single-segment branch or HEAD; anything the API
-			// cannot resolve is confirmed against github.com below.
 			api += "/contents/" + escapePath(seg[4:]) + "?ref=" + url.QueryEscape(seg[3])
-			contents = true
 		...
 	}

 	code, err := c.get(ctx, strings.TrimRight(c.APIBase, "/")+api, true)
 	if err != nil {
 		return LinkWarning, "could not be checked: " + err.Error()
 	}
-	if (code == http.StatusNotFound) && contents {
-		// The API does not follow branch renames (master -> main), but
-		// github.com does, and a renamed-branch link still works for readers.
+	if code == http.StatusNotFound {
+		// The API only knows users, organizations and repositories. A 404
+		// is not proof that the page is gone: it does not follow branch
+		// renames (master -> main), and it has no endpoint at all for pages
+		// such as github.com/sponsors/<user>, /apps/<app>, /topics/<topic>,
+		// /marketplace/... or /enterprises/<name>. github.com does serve
+		// them, so it has the final say.
 		web := strings.TrimRight(c.WebBase, "/") + u.EscapedPath()
 		if wc, err := c.get(ctx, web, false); err == nil {
 			code = wc
 		}
 	}
 	return classify(code)
 }
```

The `contents` boolean (previously set only inside the `blob`/`tree` case and used to gate the fallback) is removed entirely, and the fallback-to-`github.com`-on-404 behavior is applied unconditionally to *every* API 404, regardless of which branch of the switch produced it. This is a genuinely minimal diff for the scope of the problem it fixes: rather than adding new branches to the `switch` to special-case `sponsors`/`apps`/`topics`/`marketplace`/`enterprises` (which would require maintaining that list as GitHub adds more reserved routes in the future), the fix simply trusts the one authority that already knows about all of them — `github.com` itself — for every case where the REST API says "not found," not just the one case the original author had happened to wire that trust up for.

Crucially, this doesn't weaken the check for genuinely broken links: a nonexistent user, organization, repository, or file still gets a 404 from the REST API *and* a 404 from `github.com` on the follow-up fetch, so `classify` still correctly reports it as `LinkBroken`. The fix only changes the outcome for the specific case where the REST API says 404 but `github.com` itself says the page is fine — which, by construction, can only happen for exactly the class of page the REST API has no model of in the first place.

A second, smaller but important part of the diff fixes the test *fixture* that had been silently masking this exact bug class from the start. `bootstrap_linkcheck_test.go`'s mock HTTP server, which stands in for both the GitHub API and `github.com` in `TestCheckBootstrapLinksPrunesAndDropsUnknownHandles`, previously answered `200 OK` for *every* request to any `github.com`-shaped path except a specific `/users/ghost` API path (modeling an intentionally-nonexistent maintainer handle named `ghost` used elsewhere in the test to verify unknown-maintainer handling). Once the broadened web-fallback is wired up for every 404 (not just `blob`/`tree`), the mock's blanket "200 for everything on github.com" response meant that even the deliberately-fake `ghost` handle would now appear to exist — because the mock, unlike the real `github.com`, would happily return 200 for `github.com/ghost` even though no such page exists on the real site. The fix corrects the mock to answer 404 for `ghost` on *both* the simulated API path and the simulated web path, accurately modeling what the real `github.com` would actually do for a handle that truly doesn't exist, which is exactly the behavior the fix needs that specific test to continue correctly exercising.

### Technologies / Concepts

- **Go** — `net/url` path-segment parsing (`strings.FieldsFunc`), `net/http` status-code handling, table-driven test construction against an in-process `httptest`-style mock server.
- **GitHub REST API surface limits** — understanding precisely which resource types the REST API models (users, organizations, repositories, and a handful of repo sub-resources) versus the much larger set of first-class pages `github.com` itself serves (Sponsors, Apps, Topics, Marketplace, Enterprise accounts, and more) that simply have no API-level representation at all.
- **Fallback-based link verification design** — recognizing an existing, narrowly-scoped "trust the website over the API when the API can't model this" mechanism and generalizing it correctly, rather than reaching for a denylist/allowlist of special cases that would need ongoing maintenance as GitHub's product surface grows.
- **Explicit trade-off documentation** — stating, before any review request, exactly which pre-existing behaviors the fix leaves unchanged (releases/wiki/discussions inside an existing repo) and which new, narrow edge case it introduces (a GitHub reserved-route-name "handle" would now pass) together with a concrete reason the latter can't actually occur in practice (GitHub disallows registering those names as accounts).
- **Test-fixture correctness as part of the fix** — recognizing that a bug's own regression tests can be invalidated by a mock that doesn't accurately model the real system's behavior, and correcting the mock alongside the production code rather than leaving a test that would otherwise have started silently passing for the wrong reason.

### Result

The PR was opened the same day the bug was found (2026-10-20) and merged the following day (2026-10-21) by `ahmadqasembader` — the `utilities/dot-project` `OWNERS`-file approver and, notably, the author of the very feature (PR #740) this fix corrects a gap in, merged just one day before this bug was reported. `/approve` and `/lgtm` were given together, with no requested changes.

### Impact

- Eliminates a broad class of false positives (27 of 30 flagged links in the contributor's own 41-URL live sample, roughly 90% of what the pre-fix code was reporting broken) in a feature that had been in the codebase for less than 24 hours, before it could affect any real CNCF project repository that might have turned `check_links` on.
- Generalizes a narrow, special-cased fallback mechanism into the correct, general-purpose authority check ("`github.com` has the final say whenever the REST API can't model a page at all"), which should make the link checker robust to GitHub adding *further* reserved, non-repository route names in the future without requiring another denylist update.
- Corrects a test-fixture bug (the bootstrap mock's blanket 200-for-everything-on-github.com behavior) that would otherwise have quietly undermined the very regression test meant to guard against exactly this kind of false positive.
- Demonstrates, for a feature merged by its own author only a day earlier, that fast, specific, example-grounded bug reports (live URLs, a quantified before/after false-positive count, explicitly-scoped trade-offs) can move from report to merged fix within about 24 hours even on a feature with no prior history to draw precedent from.

### Pull Request

https://github.com/cncf/automation/pull/771 — "fix(dot-project): don't report valid github.com pages as broken links"

### Issue

https://github.com/cncf/automation/issues/770 — "fix(dot-project): link checker reports valid github.com pages (sponsors, apps, topics, ...) as broken"

### Commit(s)

- `07ff4498e91b228b5084b22c498c45a5445b27fe` — `fix(dot-project): don't report valid github.com pages as broken links`, DCO-signed (`Signed-off-by: lokeshramchand-ctrl`). (A second, identically-named commit, `046d20cb0b5626f552dbad2ffcb88cbb684f6132`, is the same change as it landed on `main` via the merged PR.)

### Review / Discussion

The review thread was short and procedurally clean, with the review itself landing from the person best positioned to evaluate it quickly — the author of the feature being corrected:

1. Immediately after opening the PR, I commented `/assign @koksay` — interestingly, assigning the *other* `ci`/general maintainer rather than `ahmadqasembader`, who actually owns `utilities/dot-project/OWNERS`. This self-assignment turned out not to determine who actually reviewed it.
2. Prow's `github-actions` bot posted the standard `[APPROVALNOTIFIER]` comment, correctly identifying that approval was needed specifically from an approver listed in `utilities/dot-project/OWNERS` — which lists only `ahmadqasembader`, not `koksay` — rather than from whoever had been `/assign`ed.
3. Close to a full day later, `ahmadqasembader` reviewed the PR directly (without needing an explicit `/assign`, evidently picking it up as the `OWNERS`-file approver for the directory regardless of who'd been tagged) and commented `/approve` and `/lgtm` together, with no requested changes, clearing the PR for merge.

This is a useful, mildly instructive detail in its own right: assigning the wrong person for a given subdirectory's `OWNERS` file doesn't block a PR in this governance model — Prow's approval requirement is scoped to the files actually touched, and the actual accountable approver for `utilities/dot-project/OWNERS` reviewed and approved it regardless of who the `/assign` comment had named, which is exactly the kind of resilience a per-directory `OWNERS` model is designed to provide.

---

# Technical Depth

## Architecture / System Understanding

`dot-project`'s link checker exists to close a gap that purely-syntactic schema validation can't: a `project.yaml` field can be a perfectly well-formed `https://` URL and still point at nothing, either because a repository was renamed/deleted, a maintainer's personal site disappeared, or — as in this bug's inverse case — because a tool's *own* model of "what counts as a valid GitHub page" is incomplete relative to what GitHub itself actually serves. The feature is deliberately layered on top of, not instead of, syntactic validation (`SCHEMA.md`'s own description: "Schema validation checks URL *format* only... With `-check-links`... the validator also checks that each URL... resolves") and is deliberately opt-in and scoped (checked only on changed links in a PR context, so an unrelated pre-existing dead link never blocks an unrelated contributor's PR or turns `main` red — that's left to the separate biweekly scheduled scan instead).

The specific architectural choice this bug exposes a gap in is `checkGitHub`'s decision to verify GitHub links against the **REST API** rather than against `github.com` itself by default. That's a reasonable default for most cases — the API is faster, doesn't risk tripping anti-bot defenses the way scripted requests against the human-facing website might, and returns a clean, unambiguous status code for the resource types it models — but it is fundamentally a narrower model of "what exists on github.com" than github.com itself has, and the original implementation's fallback-to-the-website mechanism, prior to this fix, only compensated for one specific known gap in that model (branch renames on `blob`/`tree` links) rather than the general gap (a whole category of first-class github.com pages that have no REST representation whatsoever).

## Important Components

- **`checkGitHub` (`linkcheck.go`)** — the function this PR modifies; the core URL-to-REST-endpoint mapping and now-generalized 404 fallback logic.
- **`checkOne` / `checkWeb` / `classify` (`linkcheck.go`)** — the surrounding dispatch (GitHub links go through `checkGitHub`; everything else goes through the more generic `checkWeb`, which does a `HEAD` request with a `GET` fallback for servers that mishandle `HEAD`) and the final HTTP-status-to-`LinkStatus` classification shared by both paths (`classify` only treats 404/410 as `LinkBroken`; everything else non-2xx/3xx is a non-blocking `LinkWarning`, reflecting that rate limits, bot walls, and timeouts say nothing reliable about whether a page actually exists).
- **`LinkChecker.Check` / `CollectProjectLinks` / `CollectMaintainerLinks`** — the surrounding machinery (not modified by this PR, but necessary context) that extracts every checkable URL, `PathRef`, and maintainer handle out of a parsed `Project`/`MaintainersConfig`, resolving relative `PathRef`s against the project's primary repository before handing them to the checker.
- **`CheckBootstrapLinks` (`bootstrap_linkcheck.go`)** — the integration point where `bootstrap`'s scaffolding flow runs the just-generated `project.yaml`'s links through the same `LinkChecker` *before* it's ever written to disk, recording any broken links into `BootstrapResult.BrokenLinks` so `GenerateProjectYAML` can comment them out under a `# TODO` rather than ship a freshly-provisioned project with an already-known-broken link in it.
- **The three consuming surfaces** — `.github/actions/validate-project` and `.github/actions/validate-maintainers` (reusable actions wrapping the `validator` binary for use in any CNCF project's own PR/push CI) and `.github/actions/check-links` (the biweekly scheduled scan that opens/updates/closes a tracking issue) — none of which this PR touches directly, but all three of which consume `checkGitHub`'s verdicts and were therefore all affected by the bug identically.

## APIs / Interfaces

- **GitHub REST API** (`api.github.com`, via `c.APIBase`) — `/users/<handle>`, `/orgs/<name>`, `/repos/<owner>/<repo>`, `/repos/<owner>/<repo>/contents/<path>?ref=<ref>`, `/repos/<owner>/<repo>/issues/<number>` — the specific, finite set of resource types this tool's REST-based verification can model, and (central to this bug) the much larger complement of `github.com` page types it structurally cannot.
- **`github.com` itself** (via `c.WebBase`) — used as the fallback authority whenever the REST API says 404, now unconditionally rather than only for `blob`/`tree` links.
- **Go `net/url` / `net/http`** — `url.Parse`, `strings.FieldsFunc` for path segmentation, `url.PathEscape`/`url.QueryEscape` for correctly encoding user-supplied path segments and ref names into the constructed API URL, `http.NewRequestWithContext` with a custom `User-Agent` and, for API requests, an `Accept: application/vnd.github+json` header and optional bearer token.
- **Go `testing`** — table-driven subtests in `linkcheck_test.go` driven against an in-process mock HTTP server (standing in for both `c.APIBase` and `c.WebBase`), and a second, higher-level mock in `bootstrap_linkcheck_test.go` exercising the same logic through the `bootstrap` code path end-to-end rather than unit-testing `checkGitHub` in isolation.

## Data Structures / Algorithms

The core algorithm modified here is a small, deterministic classification tree: segment the URL path, pattern-match on segment count and specific reserved first-segment values (`orgs`), fall through to an `owner/repo` assumption otherwise, optionally refine further based on a third segment (`blob`/`tree`/`issues`/`pull`), issue one REST request, and — the part this PR generalizes — conditionally issue a second, confirming request against the website whenever the first one's answer (404) might be an artifact of the REST model's limits rather than a true "this doesn't exist." The interesting algorithmic property this PR's fix relies on is that `classify`'s 404-is-broken rule is *re-applied* to whichever status code ends up being used (API or, if the fallback fires, website) — so broadening *when* the fallback fires doesn't require touching the actual decision logic for what a given status code means; it only changes which status code that decision logic ultimately sees.

## Distributed Systems Concepts

Less directly applicable here than in the `ci/cloudrunners` contributions, but one relevant idea: this is fundamentally a problem of **treating one service's partial model of another service's state as ground truth**. The REST API and the public website are, from a client's perspective, two different (if closely related) services backed by GitHub, each with a different, overlapping-but-not-identical view of what "exists." Verifying something by querying only one of two authoritative-but-incomplete sources, instead of falling back to the other when the first one's answer is ambiguous, is a general pattern worth recognizing beyond this specific bug — any system that checks resource existence against a convenience API rather than the actual source of truth is exposed to exactly this class of false result whenever the API's model of the world is a strict subset of reality's.

## Performance Considerations

The fix adds, at most, one additional HTTP GET request per link check — specifically, only for the subset of links where the REST API already returned a 404 (previously, that extra request only fired for `blob`/`tree` 404s; now it fires for every 404, which in practice means it now also fires for the five newly-recognized non-repository page categories, and for genuinely broken links, which still correctly resolve to `LinkBroken` after the fallback confirms the 404 on the web too). Given that `LinkChecker.Check` already runs its checks concurrently with a bounded worker pool (visible in the surrounding `Check` method: a semaphore-gated `sync.WaitGroup` fan-out), and that the entire feature is opt-in and run, at most, biweekly (the scheduled scan) or on PR/push events touching relevant files (the PR/push actions, and only for changed links at that), one additional outbound HTTP request for a now-correctly-classified subset of links is immaterial overhead relative to the correctness gained.

## Testing

- **`linkcheck_test.go`** — extended `TestLinkCheckerGitHubMapping` with five new "valid, non-repository page" cases (`/sponsors/<user>`, `/apps/<app>`, `/topics/<topic>`, `/marketplace/actions/<action>`, `/enterprises/<name>`) that should resolve `LinkOK` via the web fallback, plus one additional case (`https://github.com/sponsors/nobody`) that is *also* a `sponsors` URL but is deliberately missing on the mock web server too, confirming the fix still correctly reports a genuinely-nonexistent page as `LinkBroken` rather than accidentally short-circuiting to "always OK for anything shaped like `/sponsors/...`." I explicitly verified and stated that "the new cases fail on the old code" — i.e., the added tests are true regression tests that would have caught this exact bug before merge, not tests that happen to pass either way.
- **`bootstrap_linkcheck_test.go`** — corrected the mock server's handling of the `ghost` maintainer handle (used elsewhere in the same test to verify unknown-maintainer detection) to 404 on both the simulated API and simulated web paths, matching what the real `github.com` would do for a handle that doesn't exist, rather than the mock's previous blanket 200-for-everything-on-github.com behavior, which the broadened fallback would otherwise have caused to incorrectly mark `ghost` as a real, existing handle.
- **`go build ./...`, `go vet ./...`, and `go test ./...`**, run inside `utilities/dot-project`, stated as passing in the PR body — with one explicitly carved-out, pre-existing exception: `cmd/validator`'s `TestRepoRootReportsEmptyRosterAndValidSibling` fails, but (as I verified and stated plainly) it fails identically on untouched `main` and specifically on Windows, meaning it's an environment-specific, pre-existing issue entirely unrelated to this change — correctly distinguishing "a test that was already broken before I touched anything, in an environment-specific way" from "a test my change broke," rather than either silently ignoring it or incorrectly claiming full green CI.
- **Live verification against real `github.com`**, using the real, unmodified `LinkChecker` against the same 41-URL set used to scope the original bug report: 30 reported broken *before* the fix, 5 reported broken *after* — and I further verified, rather than assumed, that those remaining 5 were legitimate: three genuinely nonexistent targets, one `github.com/issues` URL (which GitHub itself serves a 404 for to logged-out visitors, i.e., a correct result given the checker's unauthenticated context), and one deliberately bogus path — explicitly also confirming that nonexistent user handles are *still* correctly reported broken post-fix, i.e., the fix didn't overcorrect into accepting everything.
- **Not run through the full GitHub Actions workflow** — stated explicitly in the PR body, consistent with the calibrated-confidence approach used throughout this contributor's prior work in this repository: state exactly what was verified (unit tests, `go vet`/`build`/`test`, and a real 41-URL live check against production `github.com`) and exactly what wasn't (an actual run of the `validate-project`/`check-links` GitHub Actions themselves), rather than implying broader end-to-end coverage than was actually exercised.

---

# Engineering Decisions

## Decision 1 — Generalize an existing fallback mechanism instead of adding a denylist of GitHub's reserved route names

The most direct patch to the five specific examples found (`sponsors`, `apps`, `topics`, `marketplace`, `enterprises`) would have been to add five more `case` arms to the `switch` in `checkGitHub`, explicitly recognizing each reserved first-segment and short-circuiting to `LinkOK` (or to a web-fallback) for each. I rejected that approach in favor of broadening the single existing `contents`-gated fallback to fire on *any* API 404, unconditionally.

The reasoning, stated explicitly in the issue before any code was written: a hard-coded list of reserved route names is "smaller" only in the sense that the five-line patch looks shorter than removing one boolean, but it's **more brittle** — GitHub's reserved top-level routes are not a fixed, published, versioned list this codebase has any way to stay in sync with over time (GitHub can and does add more first-class, non-repository URL shapes), so a denylist approach commits this code to a slow-motion game of finding each new false positive one at a time, forever. Falling back to the authoritative source (`github.com` itself) whenever the API's necessarily-partial model says "not found" is a fix that is correct *by construction* for every current and future reserved route, not just the five that happened to be discovered this week.

## Decision 2 — Measure the real scope of the problem with a live sample before claiming how big it is

Rather than asserting "this probably affects a lot of links" qualitatively, I ran the actual checker against 41 real GitHub URLs, both before and after the fix, and reported the concrete counts (30 broken before, 27 of those false positives; 5 broken after, all legitimate) directly in both the issue and the PR. This is a meaningfully different, more defensible way to characterize a bug's impact than either guessing or only presenting the five hand-picked demonstration examples: it shows the fix was validated against a broad, not cherry-picked, sample, and it gives a reviewer (in this case, the very person who wrote the feature being fixed) a concrete number to sanity-check their own intuition against rather than just trusting the fix's self-description.

## Decision 3 — Fix the test fixture's inaccurate modeling of `github.com`, not just the production code

Once the fallback was broadened to fire on every 404, the existing bootstrap-level test's mock server — which had been quietly returning `200 OK` for every `github.com`-shaped request except one specific API path — would have started passing for the wrong reason: it would have reported the deliberately-fake `ghost` maintainer handle as "existing" purely because the mock, unlike the real website, answers 200 to literally anything. I chose to fix the mock's behavior to accurately reflect what `github.com` actually does for a nonexistent handle (404), rather than leaving that mismatch between test-double and reality in place. This is the kind of detail that's easy to let slide — the test would still have been green either way, on the surface — but leaving it would have meant the test suite was no longer actually exercising "does the checker correctly classify something that's really gone," it would merely have been exercising "does the mock, which says yes to everything, make the checker say yes too" — a test that looks protective but has quietly stopped testing anything meaningful. Treating a test's own fixtures as part of the surface that needs to stay correct, not just the production code under test, is consistent with the regression-test discipline shown across this contributor's prior work in the repository (see, for example, the `expandCommand` extraction and unit test added in the companion PR #769).

---

# Challenges

## Challenge 1 — Scoping "which github.com pages aren't a repo" without access to GitHub's own internal route table

There is no published, authoritative list of every first-class, non-repository URL shape `github.com` serves; GitHub's own reserved-username documentation covers some of it indirectly (by explaining why certain words can't be registered as handles) but isn't framed as "here is the exhaustive list of routes a link-checker needs to special-case."

### How I Solved It

I sidestepped trying to enumerate every such route exhaustively, which is exactly the trap a denylist-based fix would have fallen into, and instead found and validated the single structural property that distinguishes *all* of them from a real `owner/repo`-shaped URL: the REST API has no endpoint that can resolve them, while the website can. That reframing meant I didn't need a complete list at all — I only needed enough well-chosen examples (five, spanning clearly distinct GitHub product surfaces: Sponsors, Apps, Topics, Marketplace, Enterprise) to demonstrate the pattern convincingly and motivate the general fix, rather than needing the fix itself to depend on having found every example.

### What I Learned

When a bug's root cause is "my model of the external system is a strict subset of the real system," the fix usually shouldn't try to patch the model's list of known gaps one at a time — it should change *what happens* when the model's incompleteness becomes detectable (here: an API 404 that might just mean "the API doesn't know this shape," not "this doesn't exist"), which sidesteps ever needing the list to be complete at all.

## Challenge 2 — Working out and pre-declaring the fix's own remaining edge cases, rather than letting review discover them

Broadening a 404-fallback to apply universally is simple to implement, but reasoning correctly about *everything* that changes as a side effect — not just the five cases I was trying to fix — required deliberately asking "what else, besides the five examples, is also something the REST API can't resolve but the website serves a 200 for?" before calling the fix finished.

### How I Solved It

I worked through the two concrete edge cases this broader fallback introduces — releases/wiki/discussions inside a real repo (pre-existing, unaffected, already-documented behavior) and GitHub's reserved route names colliding with a maintainer-handle check (a genuinely new, if practically inert, consequence of the fix) — and stated both explicitly in the issue's "Known trade-offs" section before opening the PR, including the specific reason the second one isn't actually exploitable (GitHub disallows registering an account under a reserved route name, so no real handle can ever collide with one).

### What I Learned

For a fix that generalizes a mechanism's scope rather than adding a narrowly-targeted special case, the review-readiness bar is higher: a reviewer evaluating "should this 404-fallback now fire unconditionally?" needs to know not just that it fixes the reported cases, but what else it newly accepts as a side effect — and supplying that analysis up front, together with why the new edge case is benign, is what lets a fast, low-friction approval happen even for a change with genuinely broader scope than its five motivating examples.

---

# Collaboration

## Maintainer / Contributor Interaction

Primary interaction was with `ahmadqasembader`, the `utilities/dot-project` `OWNERS`-file approver and the author of PR #740, the very feature this PR corrects a gap in, merged only a day earlier. Despite `/assign @koksay` having been used (mistakenly targeting a different, `ci/cloudrunners`-area maintainer this contributor had worked with on the two prior PRs), the actually-accountable approver for this directory reviewed and approved the PR regardless, consistent with Prow's `OWNERS`-file-scoped approval model rather than depending on the assignee comment.

## Code Review

Review consisted of a single combined `/approve` + `/lgtm` from `ahmadqasembader`, with no requested changes — a fast approval for a PR whose description had already done the work of quantifying the bug's real scope (the 41-URL live sample), demonstrating the fix with concrete well-known examples, and pre-declaring the fix's own known trade-offs, leaving comparatively little for the reviewer to have to independently re-derive.

## Design Discussions

As with this contributor's two prior PRs in the repository, there was no separate design-discussion thread: the proposed fix (generalize the existing fallback rather than add a denylist) was stated and justified in the issue before any code was written, and the PR implemented exactly that proposal.

## Collaboration Skills Demonstrated

- Reviewing a feature critically the day after it merged, specifically by asking "what wasn't covered?" rather than only confirming the intended cases work — a habit of healthy skepticism toward recently-shipped code, including code not written by the contributor.
- Quantifying a bug's real-world scope with a live, non-cherry-picked sample (41 URLs) rather than resting a claim on a small set of hand-picked demonstration cases alone.
- Explicitly pre-declaring a fix's own remaining edge cases and trade-offs, including one genuinely new (if practically inert) behavior change, rather than waiting for a reviewer to find it.
- Correctly distinguishing a pre-existing, environment-specific test failure (Windows-only, present on untouched `main`) from a regression introduced by the change, and stating that distinction plainly rather than either hiding it or over-claiming a fully green test run.
- Noticing and fixing a flaw in a test's own mock fixture, not just the production code, when the two would otherwise have silently diverged.

---

# Outcomes

## Code

Three files touched, `+24/-7` total: `linkcheck.go` (`+7/-5`, the core fallback-generalization fix), `linkcheck_test.go` (`+14/-1`, six new/adjusted test cases), `bootstrap_linkcheck_test.go` (`+3/-1`, the corrected mock behavior for the `ghost` handle). Merged to `main` via commit `046d20cb0b5626f552dbad2ffcb88cbb684f6132`.

## Project Impact

Closes a significant false-positive gap (measured at roughly 90% of flagged links in a 41-URL live sample) in a link-checking feature that had existed in the codebase for less than 24 hours at the time this was found and fixed — meaning the correction landed before the feature had been live long enough to realistically have affected any real CNCF project's PR checks, scheduled scans, or bootstrap output. Generalizes a narrowly-scoped fallback mechanism into a durable, future-proof one that should not need another patch every time GitHub adds a new reserved, non-repository route. Improves the accuracy of the bootstrap test suite's own GitHub-behavior modeling as a side effect.

## User / Developer Impact

Directly benefits any CNCF project maintainer who turns on `check_links` (or runs `bootstrap` to scaffold a new project) and happens to reference a GitHub Sponsors page, a GitHub App, a topic page, a Marketplace Action, or an Enterprise account anywhere in their `.project` metadata — previously, any one of those would have failed their PR check, generated a tracked "broken links" issue, or been silently commented out of a freshly scaffolded `project.yaml`, with no way to opt that single link out.

## Recognition

Reviewed and approved by `ahmadqasembader` — the author of the feature this PR corrects — via a combined `/approve` + `/lgtm`, with no requested changes, roughly one day after the issue was filed.

---

# Skills Demonstrated

## Programming

Go (`net/url` path parsing, `net/http` status-code handling, table-driven testing against mock HTTP servers, careful removal of a conditional gate without disturbing the logic it used to guard).

## Software Engineering

Critically reviewing a feature immediately after it ships rather than only validating its intended cases; generalizing a narrow fix into a durable, future-proof one instead of a denylist; quantifying a bug's real scope with a live, representative sample rather than a handful of cherry-picked examples; pre-declaring a fix's own edge cases and trade-offs; distinguishing pre-existing/environment-specific test failures from genuine regressions; correcting a test's own mock fixture alongside the production fix it was meant to protect.

## Systems

The structural difference between a convenience API's modeled resource types and the full surface of what the underlying web service actually serves, and the general pattern of falling back to the authoritative source whenever the convenience API's incompleteness becomes detectable (a 404 that might only mean "the API doesn't model this," not "this is gone").

## Distributed Systems

Treating two related-but-distinct services (a REST API and a public website) backed by the same provider as each having a partial, non-identical view of "what exists," and designing verification logic that correctly falls back between them rather than trusting the first, more convenient one unconditionally.

## Infrastructure / Cloud

GitHub Actions reusable-action/workflow architecture as the delivery mechanism for this tool's checks (`validate-project`, `validate-maintainers`, `check-links`), and how a single library-level bug (`checkGitHub`) propagates identically across all three consuming surfaces.

## Open Source

Reviewing and correcting a fellow contributor's very recently merged feature constructively, with concrete evidence and pre-declared trade-offs rather than vague criticism; working correctly within a per-directory `OWNERS`-scoped approval model even when the wrong person was initially `/assign`ed; DCO sign-off discipline; PR-template adherence.

---

# Evidence

| Evidence | URL / Reference | Description |
| --- | --- | --- |
| Repository | https://github.com/cncf/automation | CNCF's internal automation monorepo (CI infra, utilities, community-program scripts) |
| Pull Request | https://github.com/cncf/automation/pull/771 | "fix(dot-project): don't report valid github.com pages as broken links" — merged |
| Issue | https://github.com/cncf/automation/issues/770 | "fix(dot-project): link checker reports valid github.com pages (sponsors, apps, topics, ...) as broken" — closed by the PR |
| Commit (feature branch) | `07ff4498e91b228b5084b22c498c45a5445b27fe` | The commit implementing the fix and new/corrected tests, DCO-signed |
| Merge commit | `046d20cb0b5626f552dbad2ffcb88cbb684f6132` | Same change as it landed on `main`, 2026-10-21T11:32:30Z |
| Originating feature PR | https://github.com/cncf/automation/pull/740 | "feat: add link checker and maintainers handle check" — the feature this PR corrects a gap in, merged one day earlier by `ahmadqasembader` |

---

# Key Technical Keywords

Go, GitHub REST API, link checking, false-positive reduction, URL path parsing, `net/url`, `net/http`, GitHub Sponsors, GitHub Apps, GitHub Topics, GitHub Marketplace, GitHub Enterprise, fallback verification design, denylist vs. generalized-fallback trade-off, table-driven Go testing, mock HTTP server fixtures, CNCF `.project` metadata, `dot-project`, Cobra CLI, GitHub Actions reusable actions, Prow (`cncf/prow-github-actions`), OWNERS-based code review, DCO sign-off, CNCF.

---

# Related Work

This contribution is the third in a short sequence of fixes by the same contributor across `cncf/automation` within a four-day window, though it sits in a different subsystem (`utilities/dot-project`) from the first two (`ci/cloudrunners`):

- **PR #763 / Issue #762 (2026-10-18)** — removed `bash -x` shell tracing from the OCI self-hosted-runner provider, which had been causing a GitHub Actions JIT credential to be echoed into pod logs.
- **Issue #768 / PR #769 (2026-10-20)** — fixed a complete functional regression in the KubeVirt provider, where an inverted guard (introduced by the very commit #763 had used as its precedent) silently sent every runner an empty authentication token; defended under direct maintainer skepticism with concrete SSH-level evidence.
- **Issue #770 / PR #771 (this contribution, 2026-10-20–21)** — found and fixed a false-positive class in the `dot-project` link checker, a feature that had merged into the repository only a day before this bug was reported, affecting GitHub Sponsors/Apps/Topics/Marketplace/Enterprise page links.

Taken together, the three contributions show a consistent method applied across two unrelated subsystems and two different kinds of defect (a confidentiality leak, a complete functional break, and a false-positive correctness bug): read recently-changed or newly-merged code with explicit skepticism rather than taking it on faith, reproduce the mechanism concretely wherever possible before writing a report, quantify real-world impact with live data rather than resting on theoretical argument alone, and state exactly what was and wasn't verified at every step.

---

# Timeline

| Date | Event |
| --- | --- |
| 2026-10-19 13:55 UTC | PR #740 ("feat: add link checker and maintainers handle check") merged by `ahmadqasembader`, introducing the `LinkChecker`/`checkGitHub` feature this contribution later corrects a gap in. |
| 2026-10-20 16:04 UTC | Issue #770 filed: identifies that `checkGitHub` misclassifies valid non-repository `github.com` pages (Sponsors, Apps, Topics, Marketplace, Enterprise) as broken, with five concrete live examples, a 41-URL impact measurement, and a stated proposed fix with explicit trade-offs. |
| 2026-10-20 16:06 UTC | Issue #770 labeled `/kind bug`, `/area dot-project`, `/priority low`. |
| 2026-10-20 11:41 UTC (commit authored) | Fix implemented: generalizes the existing website-fallback to cover every API 404, adds new test cases, corrects the bootstrap mock's `ghost`-handle behavior. |
| 2026-10-20 16:07 UTC | PR #771 opened, referencing `Fixes #770`. |
| 2026-10-20 16:08 UTC | `/assign @koksay` (the `ci/cloudrunners`-area maintainer from this contributor's prior PRs, not the actual `utilities/dot-project` approver). |
| 2026-10-20 16:26 UTC | Prow's `[APPROVALNOTIFIER]` bot comments that approval from an `OWNERS`-listed approver in `utilities/dot-project/OWNERS` (`ahmadqasembader`) is required. |
| 2026-10-21 11:32 UTC | `ahmadqasembader` comments `/approve` and `/lgtm`. |
| 2026-10-21 11:32:30 UTC | PR #771 merged to `main`. Issue #770 auto-closed. |

---

# Notes

- All dates, timestamps, and comment text above are taken directly from the GitHub API (`gh pr view`, `gh issue view`) for the referenced issue and PR numbers, and from `git log`/`git show`/`gh pr diff` for the referenced commits, as of the time this document was written (2026-11-04).
- This write-up draws on the current state of `utilities/dot-project/linkcheck.go`, `linkcheck_test.go`, `bootstrap_linkcheck.go`, `bootstrap_linkcheck_test.go`, and the module's own `AGENT.md`/`SCHEMA.md`/`README.md` documentation of the `check_links` feature, in order to accurately describe the mechanism and its surrounding system, not merely the PR's own diff in isolation.
- This document is written as a standalone companion to the separate write-ups for PR #763 (`cncf-automation-pr-763.md`) and PR #769 (`cncf-automation-pr-769.md`); all three are cross-referenced in their respective "Related Work" sections but each is intended to be read and understood on its own.
- The originating feature PR (#740) and its author (`ahmadqasembader`) are described based solely on metadata retrieved via the GitHub API (title, author, merge date, file/line counts); this document does not characterize or evaluate PR #740 itself beyond the specific gap this contribution corrects.
