Skip to content

feat(#9062): add push-signed CLI command for signed agent commits - #9281

Open
aoguntayo wants to merge 1 commit into
fullsend-ai:mainfrom
aoguntayo:agent/9062-push-signed-commits
Open

aoguntayo wants to merge 1 commit into
fullsend-ai:mainfrom
aoguntayo:agent/9062-push-signed-commits

Conversation

@aoguntayo

@aoguntayo aoguntayo commented Nov 10, 2026 •

Copy link
Copy Markdown

Summary

Add fullsend push-signed subcommand that pushes local git commits to a remote GitHub branch via the GraphQL createCommitOnBranch mutation, producing server-side verified signatures. This enables post-code.sh (in fullsend-ai/agents) to create signed commits that comply with repository rulesets requiring verified signatures (GH013).

The command reads local commits between --base and HEAD, creates the remote branch if needed, then replays each commit individually through the forge.Client.CommitFilesToBranch method, preserving commit messages and handling additions, modifications, deletions, renames, and copies.

Related Issue

#9062

Changes

  • internal/cli/pushsigned.go — New command that pushes local git commits to a remote GitHub branch via the createCommitOnBranch GraphQL mutation, producing server-side verified signatures. It lists commits
    between --base and HEAD, creates the remote branch if needed, then replays each commit individually through forge.Client.CommitFilesToBranch, handling additions, modifications, deletions, renames, and
    copies.
  • internal/cli/pushsigned_test.go — Comprehensive tests covering commit parsing, diff-tree parsing, tree file building, multi-commit pushes, branch-already-exists handling, file deletions, and CLI flag
    validation. Uses a forge.FakeClient for integration-style tests.
  • internal/cli/root.go — Registers newPushSignedCmd() in the CLI command tree (one-line addition).

Testing

  • make lint passes (stage changes first, then run)
  • Tests added/updated for new or modified logic

Checklist

  • PR title follows Conventional Commits (correct type, ! for breaking changes)
  • Commits are signed off (DCO) — human and human-directed agent sessions only
  • I wrote this contribution myself and can explain all changes in it

@aoguntayo
aoguntayo requested a review from a team as a code owner November 10, 2026 15:45
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add push-signed CLI command to replay local commits on GitHub

✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Add fullsend push-signed so agent workflows can create commits accepted by signed-commit
 rulesets.
• Replay local commits in order, preserving messages and translating file changes for the forge
 client.
• Test parsing, branch creation, multi-commit replay, deletions, and command validation.
Diagram

graph TD
  A["CLI command"] --> B["Local Git history"] --> C["Commit changes"] --> D["Forge client"] --> E["GitHub APIs"] --> F["Remote branch"]
  D --> F
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Reject changes that cannot use signed GraphQL commits
  • ➕ Makes the command's signed-commit guarantee explicit for executable and other unsupported file modes.
  • ➖ Cannot replay some local commits without changing their contents or mode requirements.
2. Sign commits locally and push with Git
  • ➕ Preserves Git commit semantics, including modes, without API replay.
  • ➖ Requires usable signing credentials in the agent environment, which this feature aims to avoid.

Recommendation: Reusing the forge client is sensible, but enforce its signed GraphQL path before promising a signed push. The existing client falls back to Git Data REST for non-100644 modes, so an executable or symlink change may produce an unsigned commit and still fail the ruleset. Consider rejecting those commits with an actionable error; local signing is less suitable for the stated agent workflow.

Files changed (3) +784 / -0

Enhancement (2) +326 / -0
pushsigned.goImplement local-commit replay command +325/-0

Implement local-commit replay command

• Adds flags and authentication for 'push-signed', creates the remote branch if absent, and replays commits from the local base ref to HEAD through the forge client. Parses commit messages and file changes, including deletions, renames, and copies.

internal/cli/pushsigned.go

root.goRegister push-signed in the CLI +1/-0

Register push-signed in the CLI

• Adds the new command to the root Cobra command tree.

internal/cli/root.go

Tests (1) +458 / -0
pushsigned_test.goTest parsing and commit replay +458/-0

Test parsing and commit replay

• Adds parser and file-building tests plus temporary-Git-repository tests using a fake forge client. Covers multiple commits, existing branches, deletions, no-commit behavior, and selected flag errors.

internal/cli/pushsigned_test.go

@qodo-code-review

qodo-code-review Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🔗 Cross-repo conflicts (3) 📜 Skill insights (0)

Grey Divider


Action required

1. Removing an executable bit is silently lost 🐞 Bug ≡ Correctness
Description
buildTreeFiles supplies mode 100644 for a local commit that removes an executable bit, but
commitFilesTo discards a mode-only change before invoking GraphQL. When the file's content is
unchanged, the command reports the commit as skipped and leaves the remote file executable; when
content also changes, GraphQL still cannot set the requested mode.
Code

internal/cli/pushsigned.go[R187-195]

+		mode := change.Mode
+		if mode == "" {
+			mode = "100644"
+		}
+		files = append(files, forge.TreeFile{
+			Path:    change.Path,
+			Content: content,
+			Mode:    mode,
+		})
Relevance

●● Moderate

Mode-only removal loss depends on forge GraphQL limits; no close precedent either way.

PR-#8368

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The CLI passes the new mode, but the forge's GraphQL route filters mode-only changes and its
mutation does not support setting modes.

internal/cli/pushsigned.go[187-195]
internal/cli/pushsigned.go[156-164]
internal/forge/github/commit_graphql.go[9-48]
internal/forge/github/github.go[1700-1739]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A local change from executable to regular mode is routed to a mutation that cannot apply that mode change.
## Fix Focus Areas
- internal/cli/pushsigned.go[187-195]
- internal/cli/pushsigned.go[151-156]
## Recommended Fix
Compare the requested mode with the target branch mode before committing. Apply mode changes through a signing-capable mode-preserving path, or return an explicit error rather than treating them as successful or unchanged; cover mode-only and content-plus-mode changes.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗



Remediation recommended

2. Merge resolutions disappear from pushes ✓ Resolved

Resolving commit: 6219783

Resolution reason
The fix was made in the PR's current code: listCommitChanges now uses -m --first-parent in git
diff-tree so merge commits are diffed against the first parent, and a merge-commit test was added.
Description
listCommitChanges runs git diff-tree on each commit without selecting a parent diff for merge
commits, so its default invocation produces no ordinary file changes for a merge. When a merge
resolves conflicts or otherwise changes the resulting tree, pushSignedCommits treats it as empty
and never applies that resolution to the remote branch.

3. Existing agent branches gain stale commits 🔗 Cross-repo conflict ≡ Correctness
Description
pushSignedCommits replays the full base..HEAD range onto an existing remote branch without
checking its ancestry or determining which local commits were already applied. When an agent PR
branch is retained or a push is retried after a later commit fails, it can append changes from a
divergent run or reapply earlier file versions over newer ones, creating duplicate commits.
Code

internal/cli/pushsigned.go[R131-135]

+	if createErr := client.CreateBranchFromSHA(ctx, owner, repo, branch, baseSHA); createErr != nil {
+		if !forge.IsAlreadyExists(createErr) {
+			return fmt.Errorf("creating remote branch %q: %w", branch, createErr)
+		}
+		fmt.Fprintf(os.Stderr, "push-signed: branch %q already exists, pushing to it\n", branch)
Relevance

●● Moderate

Stale-branch and already-exists handling precedent exists but is older (June) and only loosely
matches; semantic change needs judgment.

PR-#2201

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Every invocation lists the full local commit range, and the CLI continues after an already-exists
response without inspecting the remote branch's progress. The forge compares files against the
current remote tree rather than local commit identity, so a retry can replay commits already
published; the agents script retains branches with open PRs, while its existing push helper checks
ancestry and provides a lease-based fallback.

fullsend -> agents
internal/cli/pushsigned.go[114-156]
internal/cli/pushsigned.go[114-165]
internal/cli/pushsigned.go[200-212]
internal/forge/github/github.go[1669-1739]
External repo: fullsend-ai/agents, scripts/post-code.sh [3988-4036]
External repo: fullsend-ai/agents, scripts/lib/github-signed-push.lib.sh [270-305]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
An existing agent PR branch can receive commits from divergent local history, and an interrupted push can replay commits the branch already contains.

## Fix Focus Areas
- internal/cli/pushsigned.go[114-165]
- /cross_repos/agents/scripts/post-code.sh[3988-4036]

## Recommended Fix
Fetch and compare the remote branch with local history before writing, then determine which local commits have already been applied and replay only those not yet published. Refuse an unrecognized or divergent branch state unless the agents workflow explicitly requests a guarded, lease-based replacement. Test a push interrupted after two commits change the same file, followed by a rerun.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


4. Fix agents lose original authors ✓ Resolved

Resolving commit: 57288d6

Resolution reason
The PR head adds appendAuthoredByTrailer(message, author), which appends an "Authored-by: Name
<email>" trailer to each commit message built from the local commit author (populated via git log
%aN <%aE>). pushSignedCommits calls it at line 194 before CommitFilesToBranch (line 195), so each
replayed signed commit carries the original sandbox author identity. It is idempotent and has unit
tests. This is a different mechanism than the suggested fix's trusted publisher policy, but it
addresses the same concern.
Description
pushSignedCommits forwards the original message unchanged, although GitHub-authored signed commits
need an Authored-by trailer to retain the sandbox author's identity. If this command publishes
code-agent commits, the agents fix workflow reads those commits as bot-authored and cannot recover
the original identity used by its history checks.

View medium (5)
5. Some agent commits remain unsigned 🔗 Cross-repo conflict ≡ Correctness
Description
pushSignedCommits treats a successful CommitFilesToBranch call as a signed publish, even though
non-100644 modes route through the Git Data REST API, whose commits are signed only with App
installation tokens. With a user or gh token, an executable or symlink change can produce an
unverified commit that the command reports as successful without checking, while a repository
requiring verified signatures rejects the ref update.
Code

internal/cli/pushsigned.go[R156-161]

+		committed, err := client.CommitFilesToBranch(ctx, owner, repo, branch, commit.Message, files)
+		if err != nil {
+			return fmt.Errorf("pushing commit %s: %w", commit.SHA[:12], err)
+		}
+		if committed {
+			fmt.Fprintf(os.Stderr, "push-signed: [%d/%d] pushed %s\n", i+1, len(commits), commit.SHA[:12])
Relevance

●● Moderate

Docs from PR 8368 state non-100644 modes intentionally use REST and are signed only with App tokens;
the team knows this limitation, so the finding is not clearly actionable.

PR-#8368

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
buildTreeFiles preserves modes such as 100755 and 120000, and the forge client routes every
non-default mode through Git Data REST rather than the signing GraphQL mutation. The forge client
documents that REST commits are signed only with App installation tokens, while the CLI accepts
ordinary user credentials; the agents publisher checks verification and distinguishes App tokens
from tokens that do not receive a signature.

fullsend -> agents
internal/cli/pushsigned.go[151-163]
internal/forge/github/commit_graphql.go[17-55]
internal/cli/pushsigned.go[183-195]
internal/cli/pushsigned.go[65-73]
internal/forge/github/commit_graphql.go[9-48]
internal/forge/github/github.go[1728-1739]
internal/forge/github/github.go[1828-1868]
External repo: fullsend-ai/agents, scripts/lib/github-signed-push.lib.sh [196-211]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Non-default file modes route commits through the forge client's REST fallback, which is not signed with user or `gh` tokens. The CLI must not report such a commit as a signed publish without verifying it, and should avoid creating or partially pushing commits when the required signing path is unavailable.

## Fix Focus Areas
- internal/cli/pushsigned.go[151-161]
- internal/cli/pushsigned.go[187-195]
- internal/forge/github/commit_graphql.go[17-55]
- /cross_repos/agents/scripts/lib/github-signed-push.lib.sh[196-211]

## Recommended Fix
Identify commits requiring non-default modes before writing. For those commits, use a signing-capable credential and path that preserves the modes, requiring an App installation token when verified signatures are required; otherwise fail explicitly before creating or partially pushing commits. Verify the returned signature status before reporting a signed publish, and test executable and symlink changes against the live-client routing behavior.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


6. New push-signed command has no CLI reference page ✓ Resolved

Resolving commit: 6219783

Resolution reason
The PR adds docs/cli/push-signed.md documenting purpose, usage, required flags, each flag's default
(GITHUB_REPOSITORY, REPO_DIR, GH_TOKEN/GITHUB_TOKEN/gh auth token), limitations and examples, and
links it from docs/cli/README.md via a new table row. This closely follows the suggested fix prompt,
so the documentation gap is resolved.
Description
The push-signed command is registered in the CLI command tree, but no page in docs/cli/ (which
has one manually maintained page per command) or in docs/guides/ mentions it, so users have no
documented flags, defaults, or usage. The new --repo, --branch, --base, --repo-dir and
--token flags, along with their environment-variable fallbacks (GITHUB_REPOSITORY, REPO_DIR,
GH_TOKEN), are equally undocumented. Existing commands such as check-protected-branch and
resolve-mr-source also lack doc references, so this is partly a repo-wide gap, but the rule
requires a reference for each changed CLI command.

7. Submodule changes cannot be replayed 🔗 Cross-repo conflict ≡ Correctness
Description
buildTreeFiles reads every non-deletion as file content, and the GitHub REST writer submits it as
a blob even when its mode is 160000. When an agent commit updates a submodule, the replay cannot
produce the commit-type tree entry with the submodule SHA that the agents signed-push helper
represents.
Code

internal/cli/pushsigned.go[R183-195]

+		content, err := readFileAtCommit(repoDir, commitSHA, change.Path)
+		if err != nil {
+			return nil, fmt.Errorf("reading %s at %s: %w", change.Path, commitSHA[:12], err)
+		}
+		mode := change.Mode
+		if mode == "" {
+			mode = "100644"
+		}
+		files = append(files, forge.TreeFile{
+			Path:    change.Path,
+			Content: content,
+			Mode:    mode,
+		})
Relevance

●● Moderate

Submodule replay is a risky semantic gap with no close historical acceptance or rejection precedent.

PR-#8368

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The converter reads content for every non-deletion and forwards its mode, while the GitHub REST
writer hardcodes those entries as blobs. The agents publisher handles submodule entries separately
as commit-type entries with the submodule SHA, showing why forwarding the mode alone cannot
reproduce that tree.

fullsend -> agents
internal/cli/pushsigned.go[173-195]
internal/forge/github/github.go[1763-1782]
internal/cli/pushsigned.go[175-195]
internal/cli/pushsigned.go[315-324]
internal/forge/github/github.go[1779-1803]
External repo: fullsend-ai/agents, scripts/lib/github-signed-push.lib.sh [124-143]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Gitlink changes are treated as blob files, although submodule tree entries require a commit-type entry and the gitlink SHA.

## Fix Focus Areas
- internal/cli/pushsigned.go[173-195]
- internal/cli/pushsigned.go[315-324]
- internal/forge/github/github.go[1763-1782]
- /cross_repos/agents/scripts/lib/github-signed-push.lib.sh[124-143]

## Recommended Fix
Detect mode `160000` before reading file content, read the gitlink SHA from the local tree, and extend the forge write path to create a commit-type tree entry with that SHA using a signing-capable credential. Alternatively, reject submodule commits before any remote writes. Test the result against the agents publisher's submodule representation.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


8. Orphan-branch root files are omitted ✓ Resolved

Resolving commit: 6219783

Resolution reason
Added --root to the git diff-tree invocation in listCommitChanges so root commits report their
files as additions instead of being skipped as empty.
Description
listCommitChanges invokes git diff-tree without --root, which yields no file changes for a
root commit. If base..HEAD contains the root of an orphan branch, the push skips that commit and
omits its files while continuing with later commits.

9. Unusual filenames stop signed pushes ✓ Resolved

Resolving commit: 57288d6

Resolution reason
The PR head code now calls `git diff-tree -r --root --no-commit-id -z --diff-merges=first-parent
sha` (line 687 of the current file), requesting NUL-delimited output as the finding suggests.
parseDiffTreeNUL splits on NUL bytes without whole-output whitespace trimming (only leading newlines
are trimmed per record). Tests cover paths with tabs and trailing spaces (TestParseDiffTreeNUL "path
with special characters" and "path with trailing space"), and rename/copy handling is NUL-aware. The
issue as described is addressed in the current code.
Description
listCommitChanges omits the -z flag despite its comment, while parseDiffTree splits Git's
quoted, line-delimited output and trims whitespace from the whole result. A changed path containing
a tab, newline, backslash, quote, or trailing space is then parsed as a different path or malformed
record, causing a failed read or an incorrect remote file change.

Grey Divider

Context sources
✅ Compliance rules (platform): 96 rules
✅ Skills: 5 invoked
  writing-user-docs
  writing-adrs
  check-patch-coverage
  cutting-releases
  adr-corner
✅ Web pages:
  +8 more
✅ Cross-repo context — repo relationships
  Explored: repo: fullsend-ai/agents (sha: c5af579b) — View relationship
✅ REVIEW.md
Review mode: Auto: ⚖️ Balanced: New remote-write command with token auth and rename/delete logic; risky but localized.

Grey Divider

Tip of the day
💡 Did you know, you can move or hide resolved findings to focus on what still needs action

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread internal/cli/root.go Resolved
Comment thread internal/cli/pushsigned.go Resolved
Comment thread internal/cli/pushsigned.go Resolved
Comment thread internal/cli/pushsigned.go Resolved
Comment thread internal/cli/pushsigned.go Resolved
Comment thread internal/cli/pushsigned.go Resolved
Comment thread internal/cli/pushsigned.go Resolved
Comment on lines +183 to +195
content, err := readFileAtCommit(repoDir, commitSHA, change.Path)
if err != nil {
return nil, fmt.Errorf("reading %s at %s: %w", change.Path, commitSHA[:12], err)
}
mode := change.Mode
if mode == "" {
mode = "100644"
}
files = append(files, forge.TreeFile{
Path: change.Path,
Content: content,
Mode: mode,
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

8. Submodule changes cannot be replayed 🔗 Cross-repo conflict ≡ Correctness

buildTreeFiles reads every non-deletion as file content, and the GitHub REST writer submits it as
a blob even when its mode is 160000. When an agent commit updates a submodule, the replay cannot
produce the commit-type tree entry with the submodule SHA that the agents signed-push helper
represents.
Agent Prompt
## Issue description
Gitlink changes are treated as blob files, although submodule tree entries require a commit-type entry and the gitlink SHA.

## Fix Focus Areas
- internal/cli/pushsigned.go[173-195]
- internal/cli/pushsigned.go[315-324]
- internal/forge/github/github.go[1763-1782]
- /cross_repos/agents/scripts/lib/github-signed-push.lib.sh[124-143]

## Recommended Fix
Detect mode `160000` before reading file content, read the gitlink SHA from the local tree, and extend the forge write path to create a commit-type tree entry with that SHA using a signing-capable credential. Alternatively, reject submodule commits before any remote writes. Test the result against the agents publisher's submodule representation.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment thread internal/cli/pushsigned.go Resolved
@aoguntayo
aoguntayo force-pushed the agent/9062-push-signed-commits branch from 1fef6c5 to 6219783 Compare November 10, 2026 16:19

@waynesun09 waynesun09 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review findings (9 inline comments: 1 HIGH, 8 MEDIUM). Main issue: the local base is never matched against the remote base, and the final tree is never compared with local HEAD, so a moved or diverged base gives a wrong tree while the command still exits 0.

Comment thread internal/cli/pushsigned.go Resolved
Comment thread internal/cli/pushsigned.go Resolved
Comment thread internal/cli/pushsigned.go Resolved
if err != nil {
return fmt.Errorf("listing local commits: %w", err)
}
if len(commits) == 0 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM: Remote branch is created before any commit is validated, so a later failure leaves a stray branch and a partial push; zero commits is a hard error

Lines 129-138 create the remote branch before any commit's changes are listed or validated. A later submodule rejection (line 184), a git show failure or an API error leaves a new branch that holds some of the commits. Lines 119-121 also return an error when base..HEAD is empty, which fails a post-script that legitimately produced nothing to push.

Suggestion: List and build the tree files for every commit first, then create the branch only when at least one non-empty commit exists. Treat 'nothing to push' as success, or document the non-zero exit.

Comment thread internal/cli/pushsigned.go Resolved
Comment thread internal/cli/pushsigned.go Resolved
Comment thread docs/cli/push-signed.md
@@ -0,0 +1,64 @@
---

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM: New CLI page is missing from the VitePress sidebar and the CLI internals command tree

docs/.vitepress/config.ts (lines 227-239) lists each /cli/ page explicitly, and /cli/push-signed is not among them, so the new page cannot be reached from the site navigation. docs/guides/dev/cli-internals.md has the full command tree, and push-signed is missing there too. The qodo thread on root.go asked for a page, and this PR added one. This finding is about the navigation entries, which are still missing.

Suggestion: Add { text: "fullsend push-signed", link: "/cli/push-signed" } to the /cli/ sidebar, and add push-signed to the command tree in cli-internals.md.

Comment thread docs/cli/push-signed.md Resolved
assert.True(t, hasSideTxt, "merge commit changes should include side.txt")
}

func TestPushSignedCommits_rootCommit(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM: Tests do not exercise the root-commit path or the main failure modes, and there is no real-GitHub validation

Despite its name, TestPushSignedCommits_rootCommit pushes an ordinary child of main, so a root commit inside base..HEAD (the --root path) is never tested. Also untested: the --branch and --base required-flag checks (only --repo is covered), error propagation from GetBranchRef, CreateBranchFromSHA and CommitFilesToBranch, and a moved remote base. FakeClient always returns changed=true and does not model the GraphQL/REST split. Issue #9062's validation criterion (a re-dispatch on a required_signatures repo that produces a PR without GH013) has no recorded run.

Suggestion: Add a real orphan or root commit test, tests for required flags and error propagation, and an httptest-based LiveClient test asserting a single createCommitOnBranch mutation. Run against a scratch repo with a required_signatures ruleset and record the commit verification output in the PR.

…commits

Add `fullsend push-signed` subcommand that pushes local git commits to a
remote GitHub branch via the GraphQL `createCommitOnBranch` mutation,
producing server-side verified signatures. This enables post-code.sh
(in fullsend-ai/agents) to create signed commits that comply with
repository rulesets requiring verified signatures (GH013).

The command reads local commits between --base and HEAD, creates the
remote branch if needed, then replays each commit individually through
the forge.Client.CommitFilesToBranch method, preserving commit messages
and handling additions, modifications, deletions, renames, and copies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Anu Oguntayo <aoguntay@redhat.com>
@aoguntayo
aoguntayo force-pushed the agent/9062-push-signed-commits branch from 6219783 to 57288d6 Compare November 10, 2026 16:52

@waynesun09 waynesun09 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review-only pass at 57288d6: 1 HIGH and 5 MEDIUM findings, posted inline. The HIGH one is a failing test (TestPushSignedCommits_mergeCommit) with no Go test or lint job in CI to catch it.

assert.True(t, files[0].Delete)
}

func TestPushSignedCommits_mergeCommit(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HIGH: TestPushSignedCommits_mergeCommit fails on the PR head, and no Go test or lint job ran in CI

I ran go test ./internal/cli/ -run PushSigned -count=1 at 57288d6 and it fails at pushsigned_test.go:476 with local base main (77c9749dc532) does not match remote base (611b72039e8a); pull or rebase before pushing. The test commits "main commit" onto local main at lines 461-463, but the fake remote main is still baseSHA (lines 466-470). The new base check at pushsigned.go:147 correctly refuses.

The expectations are also wrong. git log --first-parent main..HEAD leaves out commits already on main, so require.Len(..., 2, "expect main commit + merge commit") at line 481 could not pass even if the bases matched.

gh pr checks 9281 lists only DCO and dispatch jobs, with no Go test, lint or coverage job, so the PR's tests and lint checkboxes have nothing in CI behind them.

Suggestion: Make the side-branch commit the only change the merge brings in. Either keep local main at baseSHA and make "main commit" on feature, or set the fake remote main to the new local main SHA and expect only the merge commit, with its exact change list. Then run make go-test and make lint (or hack/ci-local, coverage included) and paste the output in the PR.

if change.Mode == "160000" {
return nil, fmt.Errorf("submodule change at %s cannot be replayed via the GraphQL API", change.Path)
}
if change.Mode != "" && change.Mode != "100644" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM: Non-100644 modes are always rejected, but the stated reason is wrong for the App installation tokens post-code.sh uses

buildTreeFiles rejects every file whose new mode is not 100644, so an executable script (100755) or a symlink (120000) aborts the whole push. The error message and the Limitations section of docs/cli/push-signed.md say non-default modes go through REST, "which does not produce signed commits with user tokens". That is true only for user tokens. internal/forge/github/commit_graphql.go:17 says "GitHub signs Git Data REST commits only for App installation tokens", and the target caller (agent post-scripts) pushes with an installation token.

An agent commit that adds or chmod +xes a script is common, and today it fails even though a signed path exists for that token type. The earlier qodo thread said user tokens produce unsigned commits; the PR fixed that by rejecting the mode for every token, App tokens included.

Suggestion: Pass the real mode through so CommitFilesToBranch takes the Git Data path that GitHub signs for installation tokens. Reject only when the token is a user token, or put the fallback behind an explicit opt-in flag that warns loudly. In the docs, change "rejected" to "requires an App installation token".

@@ -0,0 +1,405 @@
package cli

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM: fullsend-ai/agents already ships a signed-push path; this PR duplicates it with different behaviour, and nothing calls the new command

fullsend-ai/agents already has forge_push_branch with GITHUB_SIGNED_COMMITS in scripts/lib/github-signed-push.lib.sh, used by post-code.sh, post-fix.sh, pre-code.sh and pre-fix.sh. It rebuilds commits through the Git Data API with the installation token. It supports existing branches and --force-with-lease (lines 244-277). It strips any Authored-by line the agent wrote and then adds the trailer with git interpret-trailers --if-exists doNothing (lines 163-175). The fix-history checks depend on that trailer format.

This PR adds a second implementation with weaker behaviour: modes are rejected, existing branches are refused, the local ref is not updated, and trailers are not stripped. No agents change wires it in, while #9062's triage named post-code.sh in agents as the fix target.

Suggestion: Before merging, ask the #9062 owners whether turning on GITHUB_SIGNED_COMMITS, or making it the default for repos with a signature ruleset, already fixes the reported GH013. If a Go CLI is still wanted, match the agents behaviour (modes, existing branches, moving the local ref, trailer stripping) and link the agents PR that will call it.

}
}

fmt.Fprintf(os.Stderr, "push-signed: done\n")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM: The local branch stays on the unsigned commits after the push, so local and remote history diverge

After the loop the remote branch holds new GitHub-created commits with different SHAs. Local HEAD and any upstream tracking still point at the unsigned originals, and the command just prints done. A later git push, git rebase origin/<branch>, PR-head comparison or a second push-signed run in the same job then sees diverged history. The agents implementation fetches the branch and resets the local branch onto the created commits for this reason. The docs say nothing about it.

Suggestion: Collect the commit OIDs that createCommitOnBranch returns (or fetch the branch at the end) and update the local branch ref. At minimum, document that callers must run git fetch && git reset --hard origin/<branch> afterwards.

if err != nil {
return fmt.Errorf("getting remote base branch %q ref: %w", base, err)
}
if localBaseSHA != remotBaseSHA {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM: The new base check compares branch tips but never checks that base is an ancestor of HEAD

The fix for the earlier base-mismatch thread checks only localBaseSHA == remoteBaseSHA. It never checks that base is an ancestor of HEAD (git merge-base --is-ancestor <base> HEAD). Suppose the working branch was cut from an older main and local main was then fast-forwarded to match the remote. The tip check passes, base..HEAD lists the feature commits, and each replay sends whole-file content onto the newer remote base. That overwrites upstream edits to the touched paths and publishes a tree that never existed locally, and the command still exits 0.

The earlier thread (the unresolved HIGH comment on the base check) also asked for a final remote-tree vs HEAD^{tree} comparison, and that comparison is still missing, so nothing catches this case.

Suggestion: Add git merge-base --is-ancestor <base> HEAD and fail with a clear message when it is false. Add a test where the feature branch is cut from an older base.

return message
}
message = strings.TrimRight(message, "\n")
return message + "\n\nAuthored-by: " + author

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM: The Authored-by trailer starts a new paragraph, and agent-written Authored-by lines are kept

The doc comment says the trailer is placed "in the last paragraph per git trailer conventions", but the code always adds \n\n, which starts a new paragraph. For a message that already ends in a trailer block (Co-authored-by:, Signed-off-by:), git interpret-trailers and GitHub now see only Authored-by as a trailer, and GitHub stops showing the co-authors.

The duplicate check at line 400 is a plain substring match, so (a) quoted text in the body suppresses the trailer and (b) an agent-written Authored-by: line for a different identity is kept next to the real one. The agents publisher strips existing Authored-by lines for this reason, because downstream fix-history checks (.github/scripts/count-fix-commits.jq) trust that trailer.

Suggestion: Remove any existing Authored-by: lines, then add the trailer to the existing trailer block: a single \n when the last paragraph is all trailers, otherwise \n\n. Keep it in the last paragraph so count-fix-commits.jq still matches, and add tests for a message with an existing trailer block and one with a spoofed Authored-by line.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants