fix(release): authenticate mirror preparation reads

## 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.
This commit is contained in:
TNTcraft authored and GitHub committed 2026-11-15 19:08:16 -04:00 Unverified
1 parent e25bd00950
commit ca2834dda3
2 files changed
+27 -4

No files matched your search

+5 -4
View File
@@ -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;
+22
View File
@@ -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: `<!-- piik-source: ${"c".repeat(40)} -->` }))).rejects.toThrow("different or unknown source revision");