gitgram/aitimemachine/beads/internal/tracker/engine_ratelimit_test.go
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

91 lines
2.3 KiB
Go

package tracker
import (
"context"
"fmt"
"strings"
"sync/atomic"
"testing"
"time"
"github.com/steveyegge/beads/internal/types"
)
type fakeRateLimitError struct {
retryAfter time.Duration
msg string
}
func (e *fakeRateLimitError) Error() string { return e.msg }
func (e *fakeRateLimitError) RateLimitRetryAfter() time.Duration { return e.retryAfter }
// countingMockTracker counts CreateIssue invocations including failures
// (mockTracker.created only records successes).
type countingMockTracker struct {
*mockTracker
createAttempts int32
failWith error
}
func (m *countingMockTracker) CreateIssue(ctx context.Context, issue *types.Issue) (*TrackerIssue, error) {
atomic.AddInt32(&m.createAttempts, 1)
if m.failWith != nil {
return nil, m.failWith
}
return m.mockTracker.CreateIssue(ctx, issue)
}
// On a provider rate limit, the push loop must stop after the first failure
// rather than re-running the same doomed request for every remaining issue.
func TestEnginePushAbortsLoopOnRateLimit(t *testing.T) {
ctx := context.Background()
const numIssues = 5
issues := make([]*types.Issue, 0, numIssues)
for i := 0; i < numIssues; i++ {
issues = append(issues, &types.Issue{
ID: fmt.Sprintf("bd-rl%d", i),
Title: fmt.Sprintf("Rate-limit issue %d", i),
Status: types.StatusOpen,
IssueType: types.TypeTask,
Priority: 2,
})
}
store := newPureTestStore(issues...)
tracker := &countingMockTracker{
mockTracker: newMockTracker("test"),
failWith: &fakeRateLimitError{
retryAfter: 60 * time.Second,
msg: "github secondary rate limit",
},
}
engine := NewEngine(tracker, store, "test-actor")
var warnings []string
engine.OnWarning = func(msg string) { warnings = append(warnings, msg) }
result, err := engine.Sync(ctx, SyncOptions{Push: true})
if err != nil {
t.Fatalf("Sync() error: %v", err)
}
if got := atomic.LoadInt32(&tracker.createAttempts); got != 1 {
t.Errorf("expected 1 CreateIssue attempt before abort, got %d", got)
}
if result.Stats.Errors > 1 {
t.Errorf("expected at most 1 error in stats, got %d", result.Stats.Errors)
}
found := false
for _, w := range warnings {
if strings.Contains(strings.ToLower(w), "rate limit") {
found = true
break
}
}
if !found {
t.Errorf("expected a warning mentioning the rate limit, got: %v", warnings)
}
}