From 6c5e60aafdfb849fe2ab51fde3654dbde325f1fb Mon Sep 17 00:00:00 2001 From: Gauge Date: Sun, 15 Nov 2026 09:45:09 +0800 Subject: [PATCH] ci(fork): accept same-repo PRs into the fork release line as a correct target Rebased on dev after #28. Same two changes as the QA-approved head 8f13b48e17: the release-line allowance in enforce-pr-target.yml with its test, and the test's entry in the tests/ layout tables. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/enforce-pr-target.yml | 18 ++- scripts/test-layout/layout.json | 1 + .../enforce-pr-target-release-line.test.ts | 116 ++++++++++++++++++ tests/fixtures/test-layout-expected.json | 1 + 4 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 tests/ci-workflows/enforce-pr-target-release-line.test.ts diff --git a/.github/workflows/enforce-pr-target.yml b/.github/workflows/enforce-pr-target.yml index 6743730206e..8ee7f9e3e28 100644 --- a/.github/workflows/enforce-pr-target.yml +++ b/.github/workflows/enforce-pr-target.yml @@ -531,7 +531,17 @@ jobs: let behindBase = 0; let aheadMain = 0; let ancestryLookupFailed = false; - const baseAllowed = ALLOWED_BASES.includes(pr.base.ref); + // This fork cuts tagged releases from release/-vadymhimself. + // and fixes for a cut release target that line directly. Only a + // branch pushed to this same repository may target it; a fork PR + // into a release line still fails as wrong_base. + const FORK_RELEASE_LINE = /^release\/\d+\.\d+\.\d+-vadymhimself\.\d+$/; + const releaseLineBase = + FORK_RELEASE_LINE.test(pr.base.ref) && + pr.head?.repo?.owner?.login === owner && + pr.head?.repo?.name === repo; + const baseAllowed = + ALLOWED_BASES.includes(pr.base.ref) || releaseLineBase; // Stacked PR exception: base is another open PR's head branch (same // head repo as this PR's base repo). Closed/missing parent stays wrong_base. @@ -640,7 +650,11 @@ jobs: let failures = collectPrQualityFailures({ baseRef: pr.base.ref, - allowedBases: ALLOWED_BASES, + // pr-quality.cjs is checked out from dev; widen its allow-list + // here for an accepted release-line base only. + allowedBases: releaseLineBase + ? [...ALLOWED_BASES, pr.base.ref] + : ALLOWED_BASES, title: pr.title, body: pr.body, behindMain, diff --git a/scripts/test-layout/layout.json b/scripts/test-layout/layout.json index 29dd2c5f1ca..460a840c215 100644 --- a/scripts/test-layout/layout.json +++ b/scripts/test-layout/layout.json @@ -597,6 +597,7 @@ "empty-completion-guard.test.ts": "responses", "empty-completion-hardening.test.ts": "responses", "empty-tool-output-annotation.test.ts": "adapters", + "enforce-pr-target-release-line.test.ts": "ci-workflows", "ensure-desired-integrations-race.test.ts": "cli", "error-fidelity.test.ts": "server", "errors-adapter-failure.test.ts": "server", diff --git a/tests/ci-workflows/enforce-pr-target-release-line.test.ts b/tests/ci-workflows/enforce-pr-target-release-line.test.ts new file mode 100644 index 00000000000..c4c7197d12e --- /dev/null +++ b/tests/ci-workflows/enforce-pr-target-release-line.test.ts @@ -0,0 +1,116 @@ +import { describe, expect, test } from "bun:test"; +import { join } from "node:path"; +import { + callsTo, + methodsOf, + runEnforcePrTarget, + type HarnessResult, +} from "../helpers/enforce-pr-target-harness"; +import { repoRoot } from "../helpers/repo-root"; + +// The fork cuts tagged releases from release/-vadymhimself., and +// fixes for a cut release target that line. These scenarios run the real +// enforce-target script: a same-repository branch into that exact line is a +// correct target, while a PR from another repository or any lookalike base +// stays wrong_base. + +const RELEASE_LINE = "release/2.65.0-vadymhimself.15"; +const SAME_REPO_HEAD = { + ref: "fix/release-line", + sha: "3f1c0de0a6a4d0a3f9a1b2c3d4e5f60718293a4b", + repo: { name: "opencodex", owner: { login: "lidge-jun" } }, +}; +const TITLE_PREFIX = "[WRONG BRANCH] "; + +async function enforceScript(): Promise { + const text = await Bun.file( + join(repoRoot(), ".github", "workflows", "enforce-pr-target.yml") + ).text(); + const workflow = Bun.YAML.parse(text) as { + jobs?: Record }>; + }; + const step = workflow.jobs?.["enforce-target"]?.steps?.find( + candidate => typeof candidate.with?.script === "string" + ); + expect(step).toBeDefined(); + return String(step!.with!.script); +} + +async function run(options: Parameters[1]) { + return runEnforcePrTarget(await enforceScript(), options); +} + +function failed(result: HarnessResult): boolean { + return result.warnings.some(warning => warning.startsWith("setFailed:")); +} + +function titleUpdates(result: HarnessResult): string[] { + return (callsTo(result, "pulls.update") as Array<{ title?: string }>) + .map(call => call.title) + .filter((title): title is string => typeof title === "string"); +} + +function draftConversions(result: HarnessResult): number { + return (callsTo(result, "graphql") as Array<{ query: string }>).filter(call => + call.query.includes("convertPullRequestToDraft") + ).length; +} + +describe("enforce-pr-target: fork release line", () => { + test("a same-repo branch into the release line is a correct target", async () => { + const result = await run({ + pr: { + base: { ref: RELEASE_LINE }, + head: SAME_REPO_HEAD, + title: "fix(pool): rotate accounts", + draft: false, + }, + authorPermission: "write", + }); + + // Ancestry compares run only for an accepted base; the stacked-base + // lookup (`pulls.list`) runs only for a rejected one. + expect(methodsOf(result)).toContain("repos.compareCommitsWithBasehead"); + expect(methodsOf(result)).not.toContain("pulls.list"); + expect(titleUpdates(result)).toEqual([]); + expect(draftConversions(result)).toBe(0); + expect(failed(result)).toBe(false); + expect(result.logs.join(" ")).toContain("All PR quality gates passed"); + }); + + test("a PR from another repository into the release line stays wrong_base", async () => { + const result = await run({ + pr: { + base: { ref: RELEASE_LINE }, + title: "fix(pool): rotate accounts", + draft: false, + }, + authorPermission: "write", + }); + + expect(titleUpdates(result)).toEqual([`${TITLE_PREFIX}fix(pool): rotate accounts`]); + expect(draftConversions(result)).toBe(1); + expect(failed(result)).toBe(true); + }); + + for (const base of [ + "release/2.65.0", + "release/maintenance", + "release/2.65.0-vadymhimself.15-extra", + "release/2.65.0-vadymhimself", + "release/2.65-vadymhimself.15", + "release/2.65.0-someoneelse.15", + "xrelease/2.65.0-vadymhimself.15", + ]) { + test(`a same-repo branch into lookalike base ${base} stays wrong_base`, async () => { + const result = await run({ + pr: { base: { ref: base }, head: SAME_REPO_HEAD, title: "Add a thing", draft: false }, + authorPermission: "write", + }); + + expect(titleUpdates(result)).toEqual([`${TITLE_PREFIX}Add a thing`]); + expect(draftConversions(result)).toBe(1); + expect(failed(result)).toBe(true); + }); + } +}); diff --git a/tests/fixtures/test-layout-expected.json b/tests/fixtures/test-layout-expected.json index 114c699eaf8..73c7914f8fb 100644 --- a/tests/fixtures/test-layout-expected.json +++ b/tests/fixtures/test-layout-expected.json @@ -434,6 +434,7 @@ "empty-completion-guard.test.ts": "responses", "empty-completion-hardening.test.ts": "responses", "empty-tool-output-annotation.test.ts": "adapters", + "enforce-pr-target-release-line.test.ts": "ci-workflows", "ensure-desired-integrations-race.test.ts": "cli", "error-fidelity.test.ts": "server", "errors-adapter-failure.test.ts": "server",