Files
loki/scripts/test/github-org-token.ts
T
CatoandClaude Fable 5.1 a8a36de68b fix(kickoff): org repos are created with a server-held org token, not the person's OAuth grant (#634)
"Creating the repository" failed for every kickoff on 2026-09-11 with HTTP 403:
the bitbaum organisation restricts OAuth apps, and FleetCrown's app is not
approved there — so the person's OAuth token cannot create in the org, and the
route offered no other way in. Meanwhile the box's own site factory creates
repos in the same org every day, with an org admin's token.

Org writes — create, seed the starter, wire CD (the workflow shim), archive or
delete — now use `GITHUB_ORG_TOKEN` when the server has one, and the person's
token only as the fallback (`src/lib/github-org-token.ts`, one rule, tested).
Identity-scoped reads (the person's repo list, who they are) keep the person's
token. The 403 message names both remedies.

Verified: tsc, eslint, scripts/test/github-org-token.ts.


Claude-Session: https://claude.ai/code/session_01WSNERoZZqW2TgqbAGHSQZf

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-11 04:00:35 -07:00

20 lines
816 B
TypeScript

/**
* Pins which token an org-scoped GitHub write uses.
* Run: npx tsx scripts/test/github-org-token.ts
*/
import { pickRepoWriteToken } from "@/lib/github-org-token";
const org = pickRepoWriteToken("org-tok", "user-tok");
if (!org || org.source !== "org" || org.token !== "org-tok") {
throw new Error("a configured org token must win over the person's token");
}
const user = pickRepoWriteToken(null, "user-tok");
if (!user || user.source !== "user" || user.token !== "user-tok") {
throw new Error("without an org token the person's token is used");
}
if (pickRepoWriteToken(null, null) !== null) throw new Error("no token → null, never a guess");
if (pickRepoWriteToken("", "user-tok")?.source !== "user") {
throw new Error("an empty org token is no org token");
}
console.log("✓ github org token");