Skip to content

fix: forge bugfix exits non-zero on LLM failure (closes #18)#19

Merged
teragrid merged 3 commits into
mainfrom
feature/ship-hooks-learning-loop
May 31, 2026
Merged

fix: forge bugfix exits non-zero on LLM failure (closes #18)#19
teragrid merged 3 commits into
mainfrom
feature/ship-hooks-learning-loop

Conversation

@teragrid
Copy link
Copy Markdown
Owner

Closes #18.

Problem

Three code paths in internal/cli/cmdbugfix silently returned (result, nil) when the LLM provider was unavailable or its response was unparseable. This caused forge bugfix to exit 0 with an empty result, bypassing all quality gates and leading AI tools to fall through to direct file edits instead of failing loudly.

Changes

File Change
internal/cli/cmdbugfix/bugfix.go Return ErrNoLLMProvider (FORGE-6554) when llmprovider.Detect fails; return ErrLLMCallFailed (FORGE-6553) when provider.Complete fails or response is not valid JSON; add testProvider injection seam to RunContext
internal/cli/cmdbugfix/bugfix_test.go Add mockProvider; add 4 new regression/boundary tests; update 13 existing tests to use mock or accept correct error behavior
docs/ERROR_CODES.md Document FORGE-6553 and FORGE-6554

New error codes

  • FORGE-6553LLM call failed — forge bugfix cannot proceed without a working LLM
  • FORGE-6554no LLM provider configured

Tests (23/23 pass)

Test Purpose
TestRun_LLMCallFailed_ExitsNonZero Primary regression guard for #18 — mock error → non-nil return
TestRun_LLMResponse_ValidJSON_HappyPath Happy path with mock provider
TestRun_LLMResponse_InvalidJSON_ExitsNonZero Boundary: corrupt/non-JSON LLM output → error
TestRun_LLMCallFailed_FalsePositiveGuard Valid LLM response must NOT produce an error

Pre-push: all 13/13 quality gates passed (gofmt, go vet, golangci-lint, go build, go test, govulncheck, go mod verify, forge scan, forge lint, forge check, forge qa 33/33).

vietking added 3 commits May 28, 2026 20:54
P1: model tier routing (tierrouter), 3-layer KB (knowledge/layered.go)
P2: OTEL checkpoint spans, Prometheus metrics (forge metrics), forge undo wiring
feat: forge companion — zero-setup AI pairing (install/update/status/guide)
feat: forge init companion hint
feat: 7 command groups in forge --help (50 commands organised)
feat: vibe-coding daily workflows in all skill templates
fix: errcode ranges 6600-6649 (metrics), 6650-6699 (companion)
test: companion_test.go (12), prometheus_test.go (6), ship_undo_test.go (10), llmpipe_tier_test.go (4)
All tests: EXIT 0
SetUsageTemplate was comparing .GroupID (string) against \$.Groups (slice),
which always evaluates false in Go templates. Capture the current group's ID
with {{\\ := .ID}} before the inner {{range \$.Commands}} loop.

Add TestHelpCommandGroups regression test that verifies each group header
is followed by at least one expected command in the help output.

Fixes: forge help showing 7 empty group sections
Before this fix, three code paths in llmBugfix/Run silently returned
(result, nil) when the LLM provider was unavailable or its response
was invalid.  This caused forge bugfix to exit 0 with an empty result,
bypassing all quality gates and leading AI tools to apply direct file
edits instead.

Changes:
- Add FORGE-6553 (ErrLLMCallFailed) and FORGE-6554 (ErrNoLLMProvider)
- Run(): replace silent no-LLM placeholder with errcode.New(ErrNoLLMProvider)
- llmBugfix(): replace silent provider.Complete failure with errcode.New(ErrLLMCallFailed)
- llmBugfix(): replace silent JSON parse failure with errcode.New(ErrLLMCallFailed)
- Add unexported RunContext.testProvider and package-level testProviderHook
  as clean test-injection seams (zero-value nil, invisible to external callers)

Tests:
- TestRun_LLMCallFailed_ExitsNonZero: regression guard for issue #18
- TestRun_LLMResponse_ValidJSON_HappyPath: happy path with mock provider
- TestRun_LLMResponse_InvalidJSON_ExitsNonZero: boundary (corrupt LLM output)
- TestRun_LLMCallFailed_FalsePositiveGuard: valid LLM must NOT produce error
- All 13 previously broken tests updated to use mock provider or accept errors
- 23/23 tests pass
@teragrid teragrid merged commit fb1c99e into main May 31, 2026
16 of 21 checks passed
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.

bug: forge bugfix fails with LLM model issues and falls back to direct file edits

2 participants