From ca2834dda364ea8c10adc8709b10eefef2f9ff6a Mon Sep 17 00:00:00 2001 From: TNTcraft <35992542+TNTcraftHIM@users.noreply.github.com> Date: Sun, 15 Nov 2026 19:08:16 -0400 Subject: [PATCH] fix(release): authenticate mirror preparation reads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem and outcome / 问题与结果 Preparing the missing v2.7.0 mirror fetched AtomGit repository metadata anonymously and failed with HTTP 401 before reaching tag creation. Publication preparation now uses the configured token for its GET requests, including the repository endpoint, while the public read-only readiness helper remains anonymous. GET 404 still means absent. Preparation uses one HTTP owner, and mutation errors are not retried. ## Verification / 验证 - The new mocked endpoint regression reproduces the original 401 before the change and passes afterward; it also checks that public readiness remains anonymous. - Publisher, preparation/readiness and source tests: 65 passed. TypeScript, diff and repository hygiene checks passed. - Actual changed paths are release tooling and tests only: `hasProductChanges(e25bd009, HEAD)` is false. With the published v2.7.0 tag fetched, the planner returns `publish: false`; the existing v2.7.0 packages are not rebuilt or replaced. ## Impact / 影响 No App/Server behavior, dependencies, wire or data format changes. Recovery continues from the original v2.7.0 CI artifacts and source marker. AtomGit's separate Pull-mirror tag restriction may remain the next platform blocker; this repair does not bypass it. --- scripts/release-mirror-prepare.mjs | 9 +++++---- tests/release-mirror-ready.test.ts | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/scripts/release-mirror-prepare.mjs b/scripts/release-mirror-prepare.mjs index 66f5729e2..146fa5a49 100644 --- a/scripts/release-mirror-prepare.mjs +++ b/scripts/release-mirror-prepare.mjs @@ -4,17 +4,18 @@ import { execFileSync } from "node:child_process"; import { appendFileSync } from "node:fs"; import { pathToFileURL } from "node:url"; -import { mirrorReadiness, readMirror, validateMirrorSource, validateMirrorRelease } from "./release-mirror-ready.mjs"; +import { mirrorReadiness, validateMirrorSource, validateMirrorRelease } from "./release-mirror-ready.mjs"; async function requestMirror(path, method = "GET", body) { - if (method === "GET") return readMirror(path); const token = process.env.ATOMGIT_TOKEN?.trim(); if (!token) throw new Error("ATOMGIT_TOKEN is required to prepare the mirror before downloading artifacts"); const response = await fetch(`https://api.atomgit.com/api/v5/repos/TNTcraftHIM/Piik${path}`, { method, redirect: "error", signal: AbortSignal.timeout(30_000), - headers: { Accept: "application/json", "PRIVATE-TOKEN": token, "Content-Type": "application/json" }, - body: JSON.stringify(body), + headers: { Accept: "application/json", "PRIVATE-TOKEN": token, + ...(body ? { "Content-Type": "application/json" } : {}) }, + body: body ? JSON.stringify(body) : undefined, }); + if (response.status === 404 && method === "GET") return null; if (!response.ok) { const detail = await response.json().catch(() => null); const reason = detail?.message ?? detail?.error_message ?? detail?.error; diff --git a/tests/release-mirror-ready.test.ts b/tests/release-mirror-ready.test.ts index 6e4ca7b3c..18c90d62d 100644 --- a/tests/release-mirror-ready.test.ts +++ b/tests/release-mirror-ready.test.ts @@ -83,6 +83,28 @@ test("preparation reports the platform rejection without logging its token or re } finally { vi.unstubAllGlobals(); vi.unstubAllEnvs(); } }); +test("preparation authenticates the repository GET while public readiness stays anonymous", async () => { + vi.stubEnv("ATOMGIT_TOKEN", "fixture-private-token"); + const origin = "https://api.atomgit.com/api/v5/repos/TNTcraftHIM/Piik"; + const requests: { url: string; token: string | null }[] = []; + vi.stubGlobal("fetch", vi.fn(async (url: string, options?: RequestInit) => { + const token = new Headers(options?.headers).get("PRIVATE-TOKEN"); + requests.push({ url, token }); + if (url === origin) { + return token === "fixture-private-token" ? Response.json({ private: false, default_branch: "main" }) + : Response.json({ message: "Authentication required" }, { status: 401 }); + } + if (options?.method === "POST") return Response.json({ ...mirror, prerelease: true, assets: [] }); + return new Response(null, { status: 404 }); + })); + try { + expect(await mirrorReadiness(source)).toEqual({ status: "ready", version, revision }); + expect(requests).toEqual([{ url: `${origin}/releases/tags/${version}`, token: null }]); + expect(await prepareMirror(source)).toEqual({ status: "ready", version, revision }); + expect(requests.find(request => request.url === origin)?.token).toBe("fixture-private-token"); + } finally { vi.unstubAllGlobals(); vi.unstubAllEnvs(); } +}); + test("a missing attachment or conflicting source marker fails rather than claiming a completed mirror", async () => { await expect(mirrorReadiness(source, async () => ({ ...mirror, assets: [] }))).rejects.toThrow("incomplete"); await expect(mirrorReadiness(source, async () => ({ ...mirror, body: `` }))).rejects.toThrow("different or unknown source revision");