⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(ci): handle change boundaries
justin9695520c09ae
diff --git a/scripts/ci/pr-change-classification.mjs b/scripts/ci/pr-change-classification.mjsindex 1d9fc3058..65447ddac 100644--- a/scripts/ci/pr-change-classification.mjs+++ b/scripts/ci/pr-change-classification.mjs@@ -15,7 +15,8 @@ function allowedPath(path) {)return false;if (path.split("/").some((segment) => segment.startsWith("."))) return false;- if (configName.test(path)) return false;+ if (configName.test(path) && path !== "apps/site/constants/sponsors.json")+ return false;return (path === "README.md" || /^(docs|apps\/docs|apps\/site)\/[^/].*$/.test(path));@@ -136,7 +137,6 @@ export async function getPrFiles({if (!Array.isArray(batch)) throw new Error("Malformed PR files response");files.push(...batch);if (batch.length < 100) break;- if (page === 30) throw new Error("PR file pagination limit reached");}if (files.length !== pull.changed_files)throw new Error("Incomplete PR file list");diff --git a/scripts/ci/pr-change-classification.test.mjs b/scripts/ci/pr-change-classification.test.mjsindex 51f0d70a8..94a7c7d8d 100644--- a/scripts/ci/pr-change-classification.test.mjs+++ b/scripts/ci/pr-change-classification.test.mjs@@ -1,6 +1,10 @@import test from "node:test";import assert from "node:assert/strict";-import { classifyChanges, assessGate } from "./pr-change-classification.mjs";+import {+ assessGate,+ classifyChanges,+ getPrFiles,+} from "./pr-change-classification.mjs";test("known GitHub modified-file status allows an allowlisted docs path", () => {assert.equal(@@ -49,6 +53,31 @@ test("hidden and environment configuration paths require full validation", () =>}});+test("allowlisted sponsor data skips while nearby JSON configuration does not", () => {+ assert.equal(+ classifyChanges({+ eventName: "pull_request",+ files: ["apps/site/constants/sponsors.json"],+ complete: true,+ }).skipExpensive,+ true,+ );+ for (const path of [+ "apps/site/constants/other.json",+ "apps/site/data/sponsors.json",+ ]) {+ assert.equal(+ classifyChanges({+ eventName: "pull_request",+ files: [path],+ complete: true,+ }).skipExpensive,+ false,+ path,+ );+ }+});+test("only complete docs-only PR changes skip the expensive suites", () => {for (const path of ["README.md",@@ -145,6 +174,128 @@ test("rename endpoints are both classified and incomplete/unknown detection failassert.equal(classifyChanges(input).skipExpensive, false);});+const expectedBase = "a".repeat(40);+const expectedHead = "b".repeat(40);++function prMetadata(changedFiles, overrides = {}) {+ return {+ base: { sha: expectedBase },+ head: { sha: expectedHead },+ changed_files: changedFiles,+ ...overrides,+ };+}++function apiResponse(value) {+ return Response.json(value);+}++function prApiUrl(input) {+ return new URL(input).pathname + new URL(input).search;+}++test("complete 3000-file PR fetch succeeds through page 30 and revision recheck", async (t) => {+ const file = { filename: "apps/site/page.md", status: "modified" };+ const page = Array.from({ length: 100 }, () => file);+ const fetch = t.mock.method(globalThis, "fetch", async (input) => {+ const url = prApiUrl(input);+ if (url === "/repos/owner/repo/pulls/12")+ return apiResponse(prMetadata(3000));+ const requestUrl = new URL(input);+ if (+ requestUrl.pathname !== "/repos/owner/repo/pulls/12/files" ||+ requestUrl.searchParams.get("per_page") !== "100"+ )+ throw new Error(`Unexpected PR API request: ${url}`);+ const pageNumber = Number(requestUrl.searchParams.get("page"));+ if (pageNumber > 30) throw new Error("Unexpected request past page 30");+ return apiResponse(page);+ });++ const files = await getPrFiles({+ token: "read-only-token",+ repository: "owner/repo",+ pullNumber: 12,+ expectedBase,+ expectedHead,+ });++ assert.equal(files.length, 3000);+ assert.equal(fetch.mock.callCount(), 32);+});++test("PR file API refuses metadata counts above 3000", async (t) => {+ const fetch = t.mock.method(globalThis, "fetch", async () =>+ apiResponse(prMetadata(3001)),+ );+ await assert.rejects(+ getPrFiles({+ token: "read-only-token",+ repository: "owner/repo",+ pullNumber: 12,+ expectedBase,+ expectedHead,+ }),+ /file count exceeds API limit/,+ );+ assert.equal(fetch.mock.callCount(), 1);+});++test("PR file API refuses an incomplete page list", async (t) => {+ t.mock.method(globalThis, "fetch", async (input) => {+ const url = prApiUrl(input);+ if (url === "/repos/owner/repo/pulls/12")+ return apiResponse(prMetadata(101));+ if (url.endsWith("page=1"))+ return apiResponse(+ Array.from({ length: 100 }, () => ({+ filename: "docs/page.md",+ status: "modified",+ })),+ );+ if (url.endsWith("page=2")) return apiResponse([]);+ throw new Error(`Unexpected PR API request: ${url}`);+ });+ await assert.rejects(+ getPrFiles({+ token: "read-only-token",+ repository: "owner/repo",+ pullNumber: 12,+ expectedBase,+ expectedHead,+ }),+ /Incomplete PR file list/,+ );+});++test("PR file API refuses a base or head revision change during pagination", async (t) => {+ let metadataReads = 0;+ t.mock.method(globalThis, "fetch", async (input) => {+ const url = prApiUrl(input);+ if (url === "/repos/owner/repo/pulls/12") {+ metadataReads += 1;+ return apiResponse(+ metadataReads === 1+ ? prMetadata(1)+ : prMetadata(1, { head: { sha: "c".repeat(40) } }),+ );+ }+ if (url.endsWith("page=1"))+ return apiResponse([{ filename: "docs/page.md", status: "modified" }]);+ throw new Error(`Unexpected PR API request: ${url}`);+ });+ await assert.rejects(+ getPrFiles({+ token: "read-only-token",+ repository: "owner/repo",+ pullNumber: 12,+ expectedBase,+ expectedHead,+ }),+ /PR changed while files were fetched/,+ );+});+test("non-PR events always run the full checks", () => {for (const eventName of ["push",