Merge pull request #980 from tdurieux/fix/cdn-miss-classification

fix: report a deleted source repo as repo_not_found, not token_expired
This commit is contained in:
Thomas Durieux authored and GitHub committed 2026-11-28 14:41:01 -08:00
commit 0640d741f1
2 files changed
+11

No files matched your search

+5
View File
@@ -3,6 +3,7 @@ import AnonymousError from "../AnonymousError";
import { ExpiringMap } from "../expiring-map";
import { octokit, waitForTokenGate, RateLimitDelayError } from "../GitHubUtils";
import { GitHubBaseData } from "./GitHubBase";
import { githubTokenContext } from "../github-token-context";
type Miss = "file_not_found" | "repo_not_found" | "commit_not_found";
const results = new ExpiringMap<Miss>(2048);
@@ -27,6 +28,10 @@ export async function classifyContentMiss(data: GitHubBaseData, token: string):
if (active) return active;
if (pending.size >= 64) throw new AnonymousError("cache_busy", { httpStatus: 503 });
const probe = (async (): Promise<Miss> => {
// A CDN read is commit-pinned and the path comes from that commit's stored
// tree, so a CDN 404 means the repository is no longer public. The GitHub
// API cannot be asked without the owner's access.
if (githubTokenContext(token)?.cdnOnly) return "repo_not_found";
const oct = octokit(token);
const options = { owner: data.organization, repo: data.repoName, request: { timeout: 15_000 } };
try {
+6
View File
@@ -56,6 +56,12 @@ describe("jsDelivr access without owner credentials", function () {
await repo.refreshIfNeeded();
});
it("reports a CDN 404 as an unavailable repository, not an expired token", async () => {
const { classifyContentMiss } = require("../src/core/source/github-content-miss");
const data = { repoId: "r", organization: "owner", repoName: "gone", commit, getToken: () => PUBLIC_CDN_TOKEN };
expect(await classifyContentMiss(data, PUBLIC_CDN_TOKEN)).to.equal("repo_not_found");
});
it("encodes owner, repository and path segments", () => {
expect(jsDelivrFileUrl("o", "r", commit, "x/%2e")).to.equal(`https://cdn.jsdelivr.net/gh/o/r@${commit}/x/%252e`);
for (const path of ["../x", "a/./b", "a//b", ""]) expect(() => jsDelivrFileUrl("o", "r", commit, path)).to.throw("invalid_path");