fix(framework): detect-platform get_gitea_token fail-loud on absent per-slot token (Patch 2b)
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
The per-agent identity resolution added to get_gitea_token() (Patch 2 / #873) resolves an explicit identity (MOSAIC_GIT_IDENTITY env, or git config mosaic.gitIdentity) and returns that identity's per-slot Gitea token when present. Gap: when the identity resolves but its per-slot token file is ABSENT for a recognized Gitea host, the function fell through to the shared/default credential-loader token instead of failing. API tooling (pr-create.sh, issue-create.sh, pr-review.sh) then silently posted the PR/issue/review as the WRONG agent — e.g. a reviewer seat's Gate-16 review getting attributed to the shared/default identity — corrupting author≠reviewer separation while also masking the missing-token misconfiguration. This surfaced most often on the tea-stale API-fallback path, which is exactly when tooling leans on get_gitea_token. Fix: in the step-0 explicit-identity branch, when the per-slot token for that identity is absent on a recognized Gitea host, print a stderr diagnostic naming the identity, its source (env vs git config), the host, and the expected token path, then return 1 instead of falling through. All three callers already `return 1` on a nonzero get_gitea_token, so fail-loud propagates with zero caller edits. Scope (deliberate, minimal blast radius): explicit-identity-only. Plain `git config user.name` is not an identity trigger — only MOSAIC_GIT_IDENTITY / git config mosaic.gitIdentity count, so ordinary shared/human repo usage is unaffected. Recognized-Gitea-hosts-only: unrecognized hosts have no per-slot token scheme, so identity-set + unknown-host still falls through unchanged (no fail-loud). The MOSAIC_STRICT_IDENTITY opt-in discussed as a possible future extension (gating the full `... > git username` chain) is deliberately NOT part of this patch — deferred per spec as a later, separate proposal. Red-first: stashed the source fix, ran the extended test-gitea-token-identity.sh — 16 assertions failed exactly as expected (shared token leaked, no fail-loud diagnostic). Restored the fix — all green, full test:framework-shell chain passes. Backward compat verified: the no-identity-requested case still returns the shared token unchanged. Extends test-gitea-token-identity.sh: the no-per-slot-token case (both identity sources: env and git config) on a recognized host now asserts nonzero return + empty stdout + stderr diagnostic naming identity/source/host/expected path, instead of asserting a shared-token fallback. Adds a same-identity cross-host case (token exists for one host, absent for another → fail-loud on the host lacking it, no cross-host token leak) and a scope-containment case (identity set + unrecognized host → existing fall-through behavior unchanged, fail-loud diagnostic does not fire). Gates: shellcheck clean on both changed files, sanitization gate (verify-sanitized.sh) passes, full test:framework-shell chain green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0158NZqN2n2ymKFeJAZ4GUCb
This commit is contained in:
@@ -511,7 +511,11 @@ get_gitea_token() {
|
||||
# (pr-create, issue-create, …) authors under the right identity — matching the
|
||||
# git credential helper. Backward-compatible: nothing resolvable → shared logic below.
|
||||
local _ident="${MOSAIC_GIT_IDENTITY:-}"
|
||||
[[ -z "$_ident" ]] && _ident="$(git config --get mosaic.gitIdentity 2>/dev/null || true)"
|
||||
local _ident_src="MOSAIC_GIT_IDENTITY"
|
||||
if [[ -z "$_ident" ]]; then
|
||||
_ident="$(git config --get mosaic.gitIdentity 2>/dev/null || true)"
|
||||
_ident_src="git config mosaic.gitIdentity"
|
||||
fi
|
||||
if [[ -n "$_ident" ]]; then
|
||||
local _idpfx=""
|
||||
case "$host" in
|
||||
@@ -524,6 +528,15 @@ get_gitea_token() {
|
||||
cat "$_idtok"
|
||||
return 0
|
||||
fi
|
||||
# FAIL LOUD: an explicit git identity was requested for a recognized Gitea host,
|
||||
# but no per-slot token exists for THAT identity. Refuse to fall through to the
|
||||
# shared/default credential loader below — silently borrowing another slot's token
|
||||
# would post PRs/issues/reviews under the WRONG agent (e.g. rev2's review attributed
|
||||
# to coder3), corrupting Gate-16 author≠reviewer separation. Hard-stop instead so the
|
||||
# caller aborts loudly rather than acting as the wrong identity.
|
||||
echo "Error: git identity '$_ident' requested (via $_ident_src) for host '$host', but no per-slot token at $_idtok." >&2
|
||||
echo " Refusing to borrow another slot's token. Provision the per-slot token, or unset the identity to use shared credentials." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user