* feat(linear): adopt issueBatchCreate/issueBatchUpdate for 50x efficiency
Implements tracker.BatchPushTracker interface on linear.Tracker.
Adds BatchCreateIssues and BatchUpdateIssues methods that chunk
inputs into groups of 50 (Linear's per-call limit). Graceful
fallback to per-issue mutations on batch failure.
* fix(linear): address BatchPush correctness blockers from maphew review
Three correctness issues flagged in PR #3654 review:
1. Skip semantics: BatchPush now fetches each existing issue before
updating and compares with PushFieldsEqual (title, description,
priority, status). Unchanged issues are added to result.Skipped
instead of being re-pushed unconditionally. forceIDs bypasses the
check, matching the single-issue path in engine.go:doPush.
2. Batch-create result mapping: results are now matched by title rather
than array index. Linear's issueBatchCreate API does not guarantee
response order matches input order; index-based mapping silently
associated wrong ExternalRefs with issues. Unmatched inputs are
recorded in result.Errors with the title for debugging.
3. Multi-team state cache: build a StateCache per configured team at the
start of BatchPush. Updates to issues belonging to non-primary teams
resolve workflow state IDs against that team's cache, not the primary
team's. The primary cache is used only for creates (which always target
the primary team).
Add four regression tests covering: unchanged-issue skip, forceIDs bypass,
title-based result mapping with reversed API response, and per-team state ID
selection in a two-team setup.
* fix(linear): prevent duplicate issues from batch-create correctness gaps
Two correctness fixes addressing maphew's re-review blockers on PR #3654:
1. Title-based result correlation is unsafe for duplicate titles.
BatchPush now detects duplicate titles before batching. Issues with
duplicate titles are routed through single-create with idempotency
markers (CreateIssueIdempotent) instead of the batch mutation where
title-based correlation would silently lose one duplicate.
2. Full-chunk fallback after ambiguous batch failure risks duplicates.
BatchCreateIssues no longer falls back to creating the entire chunk
when the batch mutation returns success=false or an API error. Instead
it searches for each issue's idempotency marker to discover which were
partially created, returns only confirmed issues, and errors on the
rest. If the recovery search itself fails, the error propagates rather
than risking duplicates.
Supporting infrastructure ported from feat/linear-idempotency-markers:
- idempotency.go: GenerateIdempotencyMarker, AppendIdempotencyMarker
- FindIssueByDescriptionContains, CreateIssueIdempotent on Client
* fix(linear): gofmt client.go and tracker_test.go
Fix Check formatting CI failure — two files had formatting drift
from the merge conflict resolution.
OAuth-only sync path (no LINEAR_API_KEY required):
- Tracker.Init() now checks for OAuth credentials first
(LINEAR_OAUTH_CLIENT_ID + LINEAR_OAUTH_CLIENT_SECRET), constructs
NewOAuthClient per team when present, and only falls back to API key
when OAuth is absent. Missing both is a clear error naming both options.
Lint fixes:
- oauth.go: add //nolint:gosec on DefaultOAuthTokenURL (G101 false
positive — URL path component, not a credential)
- oauth.go: change defer resp.Body.Close() to
defer func() { _ = resp.Body.Close() }() to satisfy errcheck
- .golangci.yml: add unparam exclusion for getLinearConfig (ctx param
kept for context propagation)
Docs/code precedence alignment:
- getLinearConfig: env vars now take precedence over config.yaml for
yaml-only keys (was reversed). Matches documented precedence:
OAuth > LINEAR_API_KEY > config file.
Tests:
- TestTrackerInitOAuthOnly: validates OAuth client construction without
API key
- TestTrackerInitNoAuthFails: validates error message when no auth
configured
Fix 1 (double description formatting): Tracker.CreateIssue was calling
BuildLinearDescription(issue) to format the description, but the sync
engine's FormatDescription hook already calls BuildLinearDescription
before invoking CreateIssue. For issues with AcceptanceCriteria/Design/
Notes, this caused those sections to be appended twice in the Linear
description. Fix: use issue.Description directly in CreateIssue, trusting
the caller to have pre-formatted it.
Fix 2 (retry race in CreateIssueIdempotent): The previous implementation
called CreateIssue (which goes through Execute's retry loop) after the
initial marker search. If issueCreate reached Linear but the HTTP response
was lost, Execute could retry the mutation and create a duplicate issue
with the same idempotency marker. Fix: add createIssueSingleAttempt that
runs the mutation exactly once. After any failure, re-search for the
marker before returning the error so callers can safely retry
CreateIssueIdempotent without creating duplicates.
Also documents the concurrent multi-source limitation (Linear provides no
server-side uniqueness enforcement; the dedup window is bounded by search
index propagation).
Adds regression tests:
- TestCreateIssueNoDoubleFormatDescription: verifies AC/Design sections
appear exactly once in the description sent to Linear
- TestCreateIssueIdempotentRecoverAfterAmbiguousFailure: verifies that an
ambiguous create failure (5xx response) followed by a recovery search
returns the already-created issue with deduped=true
Move IssueTracker implementations from internal/tracker/adapters/{linear,gitlab}/
directly into internal/{linear,gitlab}/ and create a new minimal Jira tracker.
Each package now registers itself via init(), eliminating the adapter indirection
layer. Delete the adapters/ directory entirely.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-02-14 16:18:37 -08:00
Renamed from internal/tracker/adapters/linear/adapter_test.go (Browse further)