Repository navigation
op(forgejo): lift the comment finding-mode refusal, over a full-URL gh api call (#2291) - #2304
Merged
Merged
Conversation
…h api call (#2291) Settled against a real Forgejo 12.0.4+gitea-1.22.0 instance (INTENTIUS/choudoufu#1027): the refusal's premise was false. `gh api` resolves a *relative* path against `/api/v3` for any host but github.com, and Forgejo does not serve `/api/v3` — that is what failed, not the forge. Handed a full URL built from `GITHUB_API_URL` (a default env var every GitHub Actions *and* Forgejo Actions job carries, already correct on both), the same `gh` reaches Forgejo's `/api/v1`, which takes the identical GET/POST/PATCH sticky-comment calls. No forge branch needed: the fix is generic across github.com, GHES and Forgejo alike. - `reconcilePr`'s `postOrUpdateComment` now builds every `gh api` call from `githubApiBaseFrom(process.env)` instead of a bare relative path, and resolves its token explicitly via `commentTokenFrom` (GH_TOKEN/GITHUB_TOKEN out of the box — what the generated workflow already sets from `github.token` — CHANT_FORGEJO_TOKEN first, for the cross-instance case), forwarding it as GH_TOKEN and refusing by name (`noCommentTokenMessage`) when neither is set, mirroring `gitlabNoteTokenFrom`/`noGitlabNoteTokenMessage`'s shape. - The forgejo Op generator's build-time refusal of `findingMode: "comment"` is lifted; `buildGithubOpPipelineDocs` already puts GH_TOKEN on the job for any non-report mode, forgejo included. - `chant-lexicon-forgejo`'s `serializer.test.ts` had it half right: Forgejo's API does accept the same calls, but the untouched sticky-comment *script* it inherits from `PrPlanReport` targets a bare relative path — the exact #2291 bug — so "passes through untouched" was never proof it works on Forgejo. Corrected the comment; `PrPlanReport`'s own script (a different, component-level composite) is unfixed and out of #2291's scope. Scope: issue- and pull-request-COMMENT posting only. `gh issue create` (ReconcileMode "issue") and the "pull-request"/GitLab "merge-request" create paths were not exercised against a real Forgejo instance and are left unverified and unchanged, on both GitHub and Forgejo. Mocked-transport tests (packages/core/src/op/activities/reconcile.test.ts) prove the emitted call targets the resolved API base and that a re-run PATCHes the comment it already owns rather than POSTing a second — each shown red by a deliberate tamper before the fix. Part of #2289. Closes #2291. Claude-Session: https://claude.ai/code/session_01KCvXZWJq4nrMCBRe98TX1v Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
lex00
added a commit
that referenced
this pull request
Sep 9, 2026
…API base, not a bare path (#2308) `gh api` resolves a *relative* path against `/api/v3` for any host but github.com. GitHub Enterprise Server serves that path, so the guess is right there; Forgejo does not, and answers 404 for GET and POST alike (settled against a real Forgejo 12.0.4+gitea-1.22.0 instance in #2291/#2304, for the Op path's `reconcilePr`). `PrPlanReport`'s sticky-comment script — the component-level composite `#2291` explicitly left out of scope — had the identical bug: `gh api "repos/$REPO/issues/$PR_NUMBER/comments"` and its PATCH/POST siblings all took a bare relative path, so the composite worked on github.com and GHES and could not work on Forgejo, even though the forgejo lexicon inherits it unchanged through its github re-export. `stickyCommentScript` now resolves `$api_base` from `$GITHUB_API_URL` first (trimming a trailing slash, falling back to `https://api.github.com` when unset) and builds every `gh api` call from it — the same semantics `githubApiBaseFrom` (`packages/core/src/op/activities/reconcile.ts`) gives `reconcilePr`, inlined into shell because this is a script string emitted into YAML, not a TypeScript call that could import the helper. On github.com and GHES the resolved URL is byte-identical to `gh`'s own bare-path guess, so existing consumers there see no change. Also fixed `generate-op-pipeline.ts`'s gate-notice job (the Op pipeline's own emitted sticky-comment script), which shells to `gh api` the same bare way. Checked whether it actually inherits into Forgejo the way the issue assumed: it does not — `#2294` (this repo's own immediately-prior commit) stopped the forgejo Op generator from ever carrying `gatedNoticeDoc` across the dialect, so this job runs only on github.com/GHES today, where the bare path already resolved correctly. Fixed anyway, since it is a no-op there and the doc comment already anticipates a future Forgejo notice job inheriting this script whole. Updated the two test files that pinned the old bare-path strings (`generate-op-pipeline.test.ts`, `lexicons/terraform/examples/examples.test.ts`) and the forgejo serializer test whose own comment argued the untouched script was "not itself proof this composite posts a working comment on Forgejo" — now it is, since the dialect leaves step content untouched and the fixed script crosses over as-is. Part of #2289. Closes #2305. Claude-Session: https://claude.ai/code/session_01Ba8bBNoVmfrpiVKnwYLBzM Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
lex00
added a commit
that referenced
this pull request
Sep 10, 2026
…t a real instance (#2315) (#2332) #2304 lifted the forgejo generator's `comment`-mode refusal after checking it against a real Forgejo instance, and left `issue` mode un-refused-but- unverified — the worst of both states: it generates cleanly and fails on every run. #2315 asks to settle that gap the same way #2304 settled comment mode: against a real instance, not a mock. Brought up codeberg.org/forgejo/forgejo:12 in Docker — reports 12.0.4+gitea-1.22.0, the same version #2304 tested against — with a repo, an issue, and a pull request. `postOrUpdateGithubIssue`'s read half checks out: plain paginated `GET .../issues?state=open` interleaves the pull request with the issues exactly as GitHub's endpoint does, and the `.pull_request == null` filter plus the marker `startswith` match both behave identically to GitHub. No `/search/issues` on this instance either, confirming #2311's choice to avoid it holds for issue mode too. The write half does not clear the same instance. `gh`'s own documented environment variables (`gh help environment`) scope `GH_TOKEN`/`GITHUB_TOKEN` to "github.com or a subdomain of ghe.com" — never a self-hosted Forgejo — and `postOrUpdateGithubIssue`'s POST/PATCH calls carry only `GH_TOKEN` (on the `issue` path, `reconcilePr` does not even set that — #2320). With `GH_DEBUG=api`, a POST against the live instance using exactly the env vars the generated workflow sets sent no `Authorization` header at all: > POST /api/v1/repos/chantadmin/infra/issues HTTP/1.1 > Host: localhost:3000 < HTTP/1.1 401 Unauthorized {"message":"token is required","url":"http://localhost:3000/api/swagger"} gh: token is required (HTTP 401) Adding `GH_HOST` alongside `GH_TOKEN` made no difference — same 401. Only `GH_ENTERPRISE_TOKEN` paired with a matching `GH_HOST` authenticated. Since neither `postOrUpdateGithubIssue` nor its caller sets either, every write this mode makes on Forgejo fails, not intermittently — every run, HTTP 401. That settles it: reinstate the forgejo generator's named refusal for `findingMode: "issue"`, citing the real failure rather than the pre-#2304 "chant has no Forgejo client" premise #2291 already disproved for reads. Module doc comments in both the generator and `reconcile.ts` are updated to record what was and wasn't verified, matching how `comment` mode's crossing was documented. One thing found on the way: `postOrUpdateComment`'s write calls are built the identical way (`GH_TOKEN` only, no `GH_HOST`/`GH_ENTERPRISE_TOKEN`), which means #2304's "verified against a real Forgejo instance" could not have gone through the generated workflow's own credential path — either that session had a `gh auth login` already stored for the test instance (a real Actions job's fresh checkout never has one), or a different `gh` build was in play. Flagged in both doc comments; re-verifying `comment` mode is out of scope here and left to a follow-up. #2319 (the marker carries no Op identity) and #2320 (the issue path drops CHANT_FORGEJO_TOKEN and the named no-token refusal) do not block this: with `issue` mode refused for forgejo, neither can be exercised through this generator; #2319 still applies to GitHub's issue mode, and #2320's proposed fix (forwarding a resolved token as `GH_TOKEN`) would not by itself have cleared Forgejo either, per the same host-scoping this change found. Proof: `lexicons/forgejo/src/components/generate-op-pipeline.test.ts` gains "issue finding mode is refused by name (#2315)", shown red first — with the refusal loop's condition tampered to `false`, both new assertions fail (`expected [Function] to throw an error` / `- null + undefined`); restoring the loop turns the file green (32/32). Three existing tests used `findingMode: "issue"` incidentally (not testing issue mode itself); moved to `findingMode: "pull-request"`, unaffected by this refusal and byte-identical in the two cases asserting exact YAML. Gates: `npx tsc --noEmit -p packages/core/tsconfig.json` clean. `npm run build -w @intentius/chant-lexicon-forgejo` clean. `npx tsx scripts/typecheck.ts`: 31 known/0 new. `just lint`: 2 pre-existing warnings in an unrelated file, 0 errors. `just docs-check`: 20 tutorial, 52 how-to, 58 reference, 34 explanation, clean. `node scripts/lint-docs-sentences.mjs`: 4084 baselined, no regressions (no docs touched). Targeted: `npx vitest run lexicons/forgejo packages/core/src/op` — 812 passed, 0 failed. Closes #2315. Claude-Session: https://claude.ai/code/session_01Ba8bBNoVmfrpiVKnwYLBzM Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Sep 10, 2026
lex00
added a commit
that referenced
this pull request
Sep 10, 2026
…so it reaches a self-hosted forge (#2333) (#2350) #2291 fixed the URL half of reaching a non-github.com host and left the credential half untouched. `postOrUpdateComment` and `postOrUpdateGithubIssue` both forwarded their resolved token as `GH_TOKEN` and nothing else, and `gh` picks its token per request host: `GH_TOKEN` and `GITHUB_TOKEN` are scoped to github.com and ghe.com subdomains, and every other host reads `GH_ENTERPRISE_TOKEN` instead (`gh help environment`). So the full URL #2291 built arrived at a self-hosted Forgejo carrying no `Authorization` header at all. That shipped in 0.62.0 and again in 0.63.0, `comment` mode included — the mode #2304 lifted the refusal on. Both paths now build their environment through `ghCredentialEnv`, which sets `GH_TOKEN` and `GH_ENTERPRISE_TOKEN` to the one value `commentTokenFrom` resolved. One value under both names, so whichever class `gh` decides the host falls into, the credential it finds there is the right one. That is what stops chant depending on a host classification it does not control, without a forge branch and without detecting the host itself. Settled against a live `codeberg.org/forgejo/forgejo:12` instance reporting 12.0.4+gitea-1.22.0, driven from a shell whose GH_CONFIG_DIR held no `gh auth login` — `gh auth status` there says "You are not logged into any GitHub hosts", which is the fresh-checkout condition #2304's verification did not reproduce and the reason this shipped. Running `reconcilePr`'s own comment mode against that instance POSTs on the first run and PATCHes the same comment on the second; reverting `ghCredentialEnv` to its shipped shape and re-running the identical script fails both with `gh: token is required (HTTP 401)`. `GH_HOST` is deliberately not set, which narrows what #2333 proposed. The issue reported that `GH_ENTERPRISE_TOKEN` authenticated only when paired with a matching `GH_HOST`; the probe here has it authenticating on its own, with no `GH_HOST` anywhere in the environment, because the full URL already names the host and `GH_HOST` only supplies a default for calls that do not. Setting it would have put a variable into the environment of calls that want `gh`'s own default — `gh issue create`'s ambient fallback is one — for nothing. github.com is unchanged, and both variables carrying the same value is why: the question is only which name `gh` reads. Probed against the real api.github.com, a valid `GH_TOKEN` beside a deliberately garbage `GH_ENTERPRISE_TOKEN` succeeded, and a garbage `GH_TOKEN` beside a valid `GH_ENTERPRISE_TOKEN` failed `Bad credentials`. `GH_TOKEN` wins there whatever the enterprise variable holds, so a github.com call sends the same header it sent before. A self-hosted GHES host is in the same class as Forgejo and was equally broken, so it is fixed by the same variable rather than merely preserved — inferred from `gh`'s documented scoping, not exercised, since no GHES instance was available. The forgejo generator's `issue`-mode refusal is corrected but left standing. Its doc comment stated the premise this change removes, and both halves of `postOrUpdateGithubIssue` were driven green against the same live instance, so the refusal no longer rests on a fact. Lifting it is a generator behavior change with its own YAML surface to settle and is filed separately; the comment is corrected so its stated reason does not outlive what it rested on. Claude-Session: https://claude.ai/code/session_01Ba8bBNoVmfrpiVKnwYLBzM Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2291. Part of #2289. This is the last open sub-issue of that epic.
What the observation changed
Settled against a real Forgejo 12.0.4+gitea-1.22.0 instance during
INTENTIUS/choudoufu#1027. The refusal's premise was false, and the reason is
narrower than "chant has no Forgejo client":
gh apiresolves a RELATIVE pathagainst
/api/v3for any host but github.com, and Forgejo does not serve/api/v3. That is what failed. Handed a full URL, the sameghbinary reachesForgejo's
/api/v1, which takes the identical sticky-comment GET, POST andPATCH triple.
What changed
postOrUpdateCommentbuilds everygh apicall fromgithubApiBaseFrom, whichreads
GITHUB_API_URL. That variable is present and already correct in everyGitHub Actions job and every Forgejo Actions job, so the fix is forge-agnostic
rather than a Forgejo branch: the same code path serves github.com, GitHub
Enterprise and Forgejo.
Token resolution mirrors
gitlabNoteTokenFromandnoGitlabNoteTokenMessage:CHANT_FORGEJO_TOKENas a cross-instance override, thenGH_TOKENandGITHUB_TOKEN, which the generated workflow already sets fromgithub.tokenand which the real instance proved sufficient. It refuses by name before any
shell-out when none is set.
The forgejo Op generator no longer refuses
findingMode: "comment".chant-lexicon-forgejo's serializer test claimed the inherited sticky-commentstep "passes through untouched", as if that meant it worked. Corrected.
Proof
Each new assertion shown red by a deliberate tamper, then green:
expected 'gh api \'repos/acme/infra/issues/5/co…' to contain 'http://forgejo.example/api/v1/repos/a…'a re-run PATCHes the comment it already owns instead of posting a secondfails withexpected '' to be 'http://forgejo.example/acme/infra/iss…'findingMode comment generates cleanly on the pull_request trigger it needsfails withexpected [Function] to not throw an errorVerdicts
just buildcleanjust lint2 pre-existing warnings in an unrelated filejust testTest Files 1206 passed, 5 skipped; Tests 16982 passed, 39 skippedjust check-lexiconsforgejo 23/23 tier-1, no untracked tier-1 failuresConsumer
Regenerated INTENTIUS/choudoufu's examples/ci-pipelines against these packages in a
scratch copy. With that project's own one-line change to stop forcing
reportonforgejo, its generator now reports
live-plan: pull_request findingMode=comment,and the emitted workflow gains
GH_TOKENbeside the existingGITHUB_TOKEN.So
live-plancan post its plan as a sticky pull-request comment on Forgejo. Thatcloses the "run log only" row the consuming epic has carried for Forgejo since it
was written.
Scope, and one thing found on the way
Pull-request and issue COMMENT posting only.
gh issue createand thepull-request and merge-request creation modes were not exercised against a real
instance and are unchanged.
PrPlanReportin the github lexicon has the identical bare-path bug and is notfixed here, being a component-level composite rather than an Op-level one. Worth
its own issue.
🤖 Generated with Claude Code
https://claude.ai/code/session_01KCvXZWJq4nrMCBRe98TX1v