Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/guides/dev/cli-internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ fullsend
│ ├── --number <int> # Issue number
│ ├── --marker <string> # Sticky marker for idempotent updates (HTML comment or Jira property)
│ ├── --keep-history # Append previous content as collapsed history (default true)
│ ├── --only-if-exists # Update an existing marked comment, never create one
│ └── --fullsend-dir <path> # .fullsend config directory (resolves keep_history default)
├── post-review # Post sticky PR/MR review comments (formal review is best-effort)
│ ├── --forge <forge> # Forge backend: github (default) or gitlab
Expand Down
7 changes: 4 additions & 3 deletions docs/guides/user/issues-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ echo "Triage complete. See PR #99." | fullsend issues post-comment \
| `--jira-email` | Jira only | Jira user email for auth (default: `$JIRA_USER_EMAIL`) |
| `--dry-run` | No | Print what would be posted without posting or editing anything |
| `--keep-history` | No | Append previous content as collapsed history blocks (default: `true`; set `false` to replace in-place) |
| `--only-if-exists` | No | Update an existing comment with this marker but never create one. Use it for an all-clear result, so a findings comment from an earlier run is updated in place (the old findings are kept as collapsed history unless `--keep-history=false`) while a clean first run posts nothing. Only a comment whose author is exactly the identity posting matches; if that identity cannot be resolved, the command fails without posting. |
| `--fullsend-dir` | No | Path to `.fullsend` config directory (sources defaults from its `config.yaml` when flags are omitted) |

### Jira marker storage
Expand Down Expand Up @@ -127,9 +128,9 @@ or a Jira user with Edit All Comments) is still trusted: their edits are
kept as history when the comment is next updated.

If that identity cannot be resolved after a short retry, the command
fails with an error naming the cause and posts or edits nothing. Posting
a new comment instead would leave the earlier one behind with content no
later run updates. To recover:
fails with an error naming the cause and posts or edits nothing, with or
without `--only-if-exists`. Posting a new comment instead would leave the
earlier one behind with content no later run updates. To recover:

1. Rerun the command. A transient API failure clears on its own.
2. If it fails again, check that the token can read its own identity:
Expand Down
200 changes: 200 additions & 0 deletions internal/agentnew/postscript_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,203 @@ func TestGeneratedPostScriptRunsFromTheRunDirectory(t *testing.T) {
}
})
}

// TestGeneratedPostScriptOkDryRunPostsNothing pins the ok path under dry
// run: the script exits 0 and says nothing was posted, without looking for
// an earlier comment. The live path is covered by the stubbed-fullsend tests
// below; the author check it relies on is tested in internal/cli.
func TestGeneratedPostScriptOkDryRunPostsNothing(t *testing.T) {
if _, err := exec.LookPath("jq"); err != nil {
t.Skip("jq not installed; the generated post-script needs it")
}
script := renderPostScriptTo(t, t.TempDir())
runDir := writeRunDir(t, map[string]any{
"iteration-1": map[string]any{"status": "ok", "summary": "All clear", "comment": "All added documentation links resolve."},
})
// A fullsend that knows the flag sits first on PATH and records any
// call: a dry run must never reach it.
binDir := t.TempDir()
calledFile := filepath.Join(binDir, "called")
stub := "#!/usr/bin/env bash\ntouch " + calledFile + "\nif [[ \"$*\" == *--help* ]]; then echo ' --only-if-exists update an existing comment but never create one'; fi\nexit 0\n"
if err := os.WriteFile(filepath.Join(binDir, "fullsend"), []byte(stub), 0o755); err != nil {
t.Fatal(err)
}
stdout, stderr, err := runPostScript(t, script, runDir, "PATH="+binDir+string(os.PathListSeparator)+os.Getenv("PATH"))
if err != nil {
t.Fatalf("ok status must exit 0, got %v; stderr:\n%s", err, stderr)
}
if !strings.Contains(stderr, "dry run: did not check") {
t.Fatalf("expected the dry-run ok notice, got stderr:\n%s", stderr)
}
if strings.TrimSpace(stdout) != "" {
t.Fatalf("ok under dry run must print no comment body, got:\n%s", stdout)
}
if _, err := os.Stat(calledFile); err == nil {
t.Fatal("a dry run must not call fullsend")
}
}

// TestGeneratedPostScriptOkReplacesEarlierFindingsViaOnlyIfExists runs the
// live ok path (no dry run) against a stub `fullsend` on PATH that records
// its arguments. The script must delegate the "is there an earlier findings
// comment" decision to `fullsend issues post-comment --only-if-exists`
// rather than reimplementing it with raw API calls in shell.
func TestGeneratedPostScriptOkReplacesEarlierFindingsViaOnlyIfExists(t *testing.T) {
if _, err := exec.LookPath("jq"); err != nil {
t.Skip("jq not installed; the generated post-script needs it")
}
binDir := t.TempDir()
argsFile := filepath.Join(binDir, "args")
stub := "#!/usr/bin/env bash\nif [[ \"$*\" == *--help* ]]; then echo ' --only-if-exists update an existing comment but never create one'; exit 0; fi\nprintf '%s\\n' \"$@\" > " + argsFile + "\ncat >/dev/null\n"
if err := os.WriteFile(filepath.Join(binDir, "fullsend"), []byte(stub), 0o755); err != nil {
t.Fatal(err)
}
script := renderPostScriptTo(t, t.TempDir())
runDir := writeRunDir(t, map[string]any{
"iteration-1": map[string]any{"status": "ok", "summary": "All clear", "comment": "All added documentation links resolve."},
})
cmd := exec.Command("bash", script)
cmd.Dir = runDir
cmd.Env = append(os.Environ(),
"PATH="+binDir+string(os.PathListSeparator)+os.Getenv("PATH"),
"ISSUE_URL=https://github.com/fullsend-ai/demo/pull/99",
"GH_TOKEN=test-token",
)
var stderr strings.Builder
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
t.Fatalf("ok live path must exit 0, got %v; stderr:\n%s", err, stderr.String())
}
got, err := os.ReadFile(argsFile)
if err != nil {
t.Fatalf("the script never invoked fullsend on the ok path: %v; stderr:\n%s", err, stderr.String())
}
args := string(got)
for _, want := range []string{"issues\npost-comment\n", "--only-if-exists\n", "--keep-history=false\n", "--marker\n", "fullsend-ai/demo\n", "99\n"} {
if !strings.Contains(args, want) {
t.Errorf("fullsend was called without %q; args:\n%s", strings.TrimSpace(want), args)
}
}
}

// TestGeneratedPostScriptOkOnAnOlderFullsendPostsNothing pins the
// degradation path: the runner's fullsend is pinned by the repository, not
// by the CLI that generated the script, so when its post-comment has no
// --only-if-exists the ok path must post nothing and exit 0 rather than fail
// on an unknown flag.
func TestGeneratedPostScriptOkOnAnOlderFullsendPostsNothing(t *testing.T) {
if _, err := exec.LookPath("jq"); err != nil {
t.Skip("jq not installed; the generated post-script needs it")
}
binDir := t.TempDir()
argsFile := filepath.Join(binDir, "args")
// An older CLI: --help lists no --only-if-exists, and any real call
// with that flag would fail — so the stub fails loudly if invoked to post.
stub := "#!/usr/bin/env bash\nif [[ \"$*\" == *--help* ]]; then echo ' --dry-run print what would be posted'; exit 0; fi\nprintf '%s\\n' \"$@\" > " + argsFile + "\necho 'Error: unknown flag: --only-if-exists' >&2; exit 1\n"
if err := os.WriteFile(filepath.Join(binDir, "fullsend"), []byte(stub), 0o755); err != nil {
t.Fatal(err)
}
script := renderPostScriptTo(t, t.TempDir())
runDir := writeRunDir(t, map[string]any{
"iteration-1": map[string]any{"status": "ok", "summary": "All clear", "comment": "All added documentation links resolve."},
})
cmd := exec.Command("bash", script)
cmd.Dir = runDir
cmd.Env = append(os.Environ(),
"PATH="+binDir+string(os.PathListSeparator)+os.Getenv("PATH"),
"ISSUE_URL=https://github.com/fullsend-ai/demo/pull/99",
"GH_TOKEN=test-token",
)
var stderr strings.Builder
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
t.Fatalf("ok on an older fullsend must exit 0, got %v; stderr:\n%s", err, stderr.String())
}
if !strings.Contains(stderr.String(), "nothing to post") {
t.Fatalf("expected the nothing-to-post notice, got:\n%s", stderr.String())
}
if _, err := os.Stat(argsFile); err == nil {
t.Fatalf("an older fullsend must not be asked to post on the ok path")
}
}

// TestGeneratedPostScriptOkFailsWhenThePostFails pins that the ok path does
// not swallow a failed post: when fullsend cannot verify its identity (or the
// API fails) it exits non-zero, and the run must fail visibly.
func TestGeneratedPostScriptOkFailsWhenThePostFails(t *testing.T) {
if _, err := exec.LookPath("jq"); err != nil {
t.Skip("jq not installed; the generated post-script needs it")
}
binDir := t.TempDir()
stub := "#!/usr/bin/env bash\nif [[ \"$*\" == *--help* ]]; then echo ' --only-if-exists update an existing comment but never create one'; exit 0; fi\ncat >/dev/null\necho 'Error: cannot verify which identity this command posts as' >&2; exit 1\n"
if err := os.WriteFile(filepath.Join(binDir, "fullsend"), []byte(stub), 0o755); err != nil {
t.Fatal(err)
}
script := renderPostScriptTo(t, t.TempDir())
runDir := writeRunDir(t, map[string]any{
"iteration-1": map[string]any{"status": "ok", "summary": "All clear", "comment": "All added documentation links resolve."},
})
cmd := exec.Command("bash", script)
cmd.Dir = runDir
cmd.Env = append(os.Environ(),
"PATH="+binDir+string(os.PathListSeparator)+os.Getenv("PATH"),
"ISSUE_URL=https://github.com/fullsend-ai/demo/pull/99",
"GH_TOKEN=test-token",
)
if err := cmd.Run(); err == nil {
t.Fatal("ok must fail when fullsend issues post-comment fails")
}
}

// TestGeneratedPostScriptOkFailsWhenFullsendHelpFails pins that a broken
// runner is not mistaken for an older CLI: a fullsend that is missing or
// whose --help fails must fail the ok path, not silently post nothing.
func TestGeneratedPostScriptOkFailsWhenFullsendHelpFails(t *testing.T) {
if _, err := exec.LookPath("jq"); err != nil {
t.Skip("jq not installed; the generated post-script needs it")
}
binDir := t.TempDir()
stub := "#!/usr/bin/env bash\necho 'error: unable to load config' >&2\nexit 2\n"
if err := os.WriteFile(filepath.Join(binDir, "fullsend"), []byte(stub), 0o755); err != nil {
t.Fatal(err)
}
script := renderPostScriptTo(t, t.TempDir())
runDir := writeRunDir(t, map[string]any{
"iteration-1": map[string]any{"status": "ok", "summary": "All clear", "comment": "All added documentation links resolve."},
})
cmd := exec.Command("bash", script)
cmd.Dir = runDir
cmd.Env = append(os.Environ(),
"PATH="+binDir+string(os.PathListSeparator)+os.Getenv("PATH"),
"ISSUE_URL=https://github.com/fullsend-ai/demo/pull/99",
"GH_TOKEN=test-token",
)
var stderr strings.Builder
cmd.Stderr = &stderr
if err := cmd.Run(); err == nil {
t.Fatalf("ok must fail when fullsend --help fails; stderr:\n%s", stderr.String())
}
if !strings.Contains(stderr.String(), "unable to load config") {
t.Fatalf("expected fullsend's own error in the log, got:\n%s", stderr.String())
}
}

// TestGeneratedPostScriptOkRejectsANonGitHubIssueURL pins that an ok result
// is validated like any other: the ok path runs after the ISSUE_URL check,
// so a non-GitHub work-item URL fails the run instead of exiting 0 unseen.
func TestGeneratedPostScriptOkRejectsANonGitHubIssueURL(t *testing.T) {
if _, err := exec.LookPath("jq"); err != nil {
t.Skip("jq not installed; the generated post-script needs it")
}
script := renderPostScriptTo(t, t.TempDir())
runDir := writeRunDir(t, map[string]any{
"iteration-1": map[string]any{"status": "ok", "summary": "All clear", "comment": "All added documentation links resolve."},
})
_, stderr, err := runPostScript(t, script, runDir, "ISSUE_URL=https://evil.example.com/fullsend-ai/demo/pull/99")
if err == nil {
t.Fatalf("ok with a non-GitHub ISSUE_URL must fail; stderr:\n%s", stderr)
}
if !strings.Contains(stderr, "ISSUE_URL is not a GitHub issue or pull request URL") {
t.Fatalf("expected the ISSUE_URL rejection, got:\n%s", stderr)
}
}
53 changes: 46 additions & 7 deletions internal/agentnew/templates/post.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ if (( ${#comment} > MAX_COMMENT_CHARS )); then
comment="${comment:0:${keep}}${TRUNCATION_MARKER}"
fi

if [[ "${status}" == "ok" ]]; then
echo "post-__AGENT_NAME__: status=ok, nothing to post" >&2
exit 0
fi

# Derive the repo and number from the work item URL rather than trusting extra
# environment. The pattern also rejects anything that is not a github.com URL.
url_re='^https://github[.]com/([A-Za-z0-9._-]+/[A-Za-z0-9._-]+)/(issues|pull)/([0-9]+)$'
Expand All @@ -126,6 +121,50 @@ fi
REPO="${BASH_REMATCH[1]}"
NUMBER="${BASH_REMATCH[3]}"

# On ok, post nothing — unless an earlier run left a findings comment on
Comment thread
waynesun09 marked this conversation as resolved.
Resolved
# this work item. The harness trigger fires again on later pushes, so a
# problem the author has since fixed would otherwise stay reported.
# --only-if-exists makes fullsend replace that comment with the all-clear,
# and post nothing when there is no earlier comment. It matches only a
# comment carrying this marker whose author is exactly the login fullsend
# posts as, so a comment anyone else planted with the marker is never
# edited. When that login cannot be resolved it exits non-zero without
# posting; under `set -e` this script, and so the run, then fails
# visibly — rerun it.
if [[ "${status}" == "ok" ]]; then
Comment thread
waynesun09 marked this conversation as resolved.
Resolved
if [[ "${__DRY_RUN_VAR__:-}" == "1" ]]; then
Comment thread
waynesun09 marked this conversation as resolved.
Resolved
echo "post-__AGENT_NAME__: status=ok, nothing to post (dry run: did not check for an earlier findings comment to replace)" >&2
exit 0
fi
# The runner's fullsend may predate --only-if-exists (it is pinned by the
# repository's fullsend-ref, not by the CLI that generated this script).
# Detect the flag instead of assuming it. A fullsend that is missing or
# whose --help fails is a broken runner, not an older CLI: fail the run.
# Only a working CLI without the flag keeps the old behaviour — post
# nothing.
if ! help_text=$(fullsend issues post-comment --help 2>&1); then
printf '%s\n' "post-__AGENT_NAME__: 'fullsend issues post-comment --help' failed; cannot replace an earlier findings comment" >&2
printf '%s\n' "${help_text}" >&2
exit 1
fi
if [[ "${help_text}" != *--only-if-exists* ]]; then
echo "post-__AGENT_NAME__: status=ok, nothing to post (this fullsend has no --only-if-exists; an earlier findings comment, if any, stays until a later run with findings)" >&2
exit 0
fi
Comment thread
waynesun09 marked this conversation as resolved.
Resolved
# --keep-history=false: the all-clear replaces the comment in place, so
# repeated clean runs do not stack identical "Previous run" blocks.
printf '**%s**\n\n%s\n' "${summary}" "${comment}" \
| fullsend issues post-comment \
Comment thread
waynesun09 marked this conversation as resolved.
Resolved
--tracker github \
--project "${REPO}" \
--number "${NUMBER}" \
--marker "${MARKER}" \
--only-if-exists \
--keep-history=false \
--result -
exit 0
Comment thread
waynesun09 marked this conversation as resolved.
Resolved
fi

if [[ "${__DRY_RUN_VAR__:-}" == "1" ]]; then
# The preview prints model output. Under GitHub Actions a line starting
# with "::" is a workflow command (the runner even trims leading spaces
Expand All @@ -142,8 +181,8 @@ if [[ "${__DRY_RUN_VAR__:-}" == "1" ]]; then
fi

# fullsend issues post-comment is the repo's sticky-comment primitive: it
# finds this agent's previous comment by marker and edits it in place, so
# re-runs do not flood the work item.
# finds this agent's previous comment by marker and its own author and edits
# it in place, so re-runs do not flood the work item.
printf '**%s**\n\n%s\n' "${summary}" "${comment}" \
| fullsend issues post-comment \
--tracker github \
Expand Down
53 changes: 46 additions & 7 deletions internal/agentnew/testdata/golden/triage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,6 @@ if (( ${#comment} > MAX_COMMENT_CHARS )); then
comment="${comment:0:${keep}}${TRUNCATION_MARKER}"
fi

if [[ "${status}" == "ok" ]]; then
echo "post-lint-docs: status=ok, nothing to post" >&2
exit 0
fi

# Derive the repo and number from the work item URL rather than trusting extra
# environment. The pattern also rejects anything that is not a github.com URL.
url_re='^https://github[.]com/([A-Za-z0-9._-]+/[A-Za-z0-9._-]+)/(issues|pull)/([0-9]+)$'
Expand All @@ -278,6 +273,50 @@ fi
REPO="${BASH_REMATCH[1]}"
NUMBER="${BASH_REMATCH[3]}"

# On ok, post nothing — unless an earlier run left a findings comment on
# this work item. The harness trigger fires again on later pushes, so a
# problem the author has since fixed would otherwise stay reported.
# --only-if-exists makes fullsend replace that comment with the all-clear,
# and post nothing when there is no earlier comment. It matches only a
# comment carrying this marker whose author is exactly the login fullsend
# posts as, so a comment anyone else planted with the marker is never
# edited. When that login cannot be resolved it exits non-zero without
# posting; under `set -e` this script, and so the run, then fails
# visibly — rerun it.
if [[ "${status}" == "ok" ]]; then
if [[ "${POST_LINT_DOCS_DRY_RUN:-}" == "1" ]]; then
echo "post-lint-docs: status=ok, nothing to post (dry run: did not check for an earlier findings comment to replace)" >&2
exit 0
fi
# The runner's fullsend may predate --only-if-exists (it is pinned by the
# repository's fullsend-ref, not by the CLI that generated this script).
# Detect the flag instead of assuming it. A fullsend that is missing or
# whose --help fails is a broken runner, not an older CLI: fail the run.
# Only a working CLI without the flag keeps the old behaviour — post
# nothing.
if ! help_text=$(fullsend issues post-comment --help 2>&1); then
printf '%s\n' "post-lint-docs: 'fullsend issues post-comment --help' failed; cannot replace an earlier findings comment" >&2
printf '%s\n' "${help_text}" >&2
exit 1
fi
if [[ "${help_text}" != *--only-if-exists* ]]; then
echo "post-lint-docs: status=ok, nothing to post (this fullsend has no --only-if-exists; an earlier findings comment, if any, stays until a later run with findings)" >&2
exit 0
fi
# --keep-history=false: the all-clear replaces the comment in place, so
# repeated clean runs do not stack identical "Previous run" blocks.
printf '**%s**\n\n%s\n' "${summary}" "${comment}" \
| fullsend issues post-comment \
--tracker github \
--project "${REPO}" \
--number "${NUMBER}" \
--marker "${MARKER}" \
--only-if-exists \
--keep-history=false \
--result -
exit 0
fi

if [[ "${POST_LINT_DOCS_DRY_RUN:-}" == "1" ]]; then
# The preview prints model output. Under GitHub Actions a line starting
# with "::" is a workflow command (the runner even trims leading spaces
Expand All @@ -294,8 +333,8 @@ if [[ "${POST_LINT_DOCS_DRY_RUN:-}" == "1" ]]; then
fi

# fullsend issues post-comment is the repo's sticky-comment primitive: it
# finds this agent's previous comment by marker and edits it in place, so
# re-runs do not flood the work item.
# finds this agent's previous comment by marker and its own author and edits
# it in place, so re-runs do not flood the work item.
printf '**%s**\n\n%s\n' "${summary}" "${comment}" \
| fullsend issues post-comment \
--tracker github \
Expand Down
Loading
Loading