Skip to content
Draft
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
6 changes: 5 additions & 1 deletion internal/linear/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,11 @@ func (c *Client) createIssueSingleAttempt(ctx context.Context, title, descriptio
}

httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", c.APIKey)
authValue, err := c.authHeader()
if err != nil {
return nil, err
}
httpReq.Header.Set("Authorization", authValue)

resp, err := c.HTTPClient.Do(httpReq)
if err != nil {
Expand Down
91 changes: 91 additions & 0 deletions internal/linear/idempotency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,97 @@ func TestCreateIssueEmbedsMarker(t *testing.T) {
}
}

func TestCreateIssueIdempotentOAuthUsesBearerToken(t *testing.T) {
var createAuthHeader string

mux := http.NewServeMux()
mux.HandleFunc("/oauth/token", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]interface{}{
"access_token": "oauth-test-token",
"token_type": "Bearer",
"expires_in": 3600,
})
})
mux.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) {
var req GraphQLRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
t.Fatalf("failed to decode request: %v", err)
}

w.Header().Set("Content-Type", "application/json")

if strings.Contains(req.Query, "FindByDescription") {
_ = json.NewEncoder(w).Encode(map[string]interface{}{
"data": map[string]interface{}{
"issues": map[string]interface{}{
"nodes": []Issue{},
"pageInfo": map[string]interface{}{"hasNextPage": false, "endCursor": ""},
},
},
})
return
}

if strings.Contains(req.Query, "issueCreate") {
createAuthHeader = r.Header.Get("Authorization")
input, _ := req.Variables["input"].(map[string]interface{})
_ = json.NewEncoder(w).Encode(map[string]interface{}{
"data": map[string]interface{}{
"issueCreate": map[string]interface{}{
"success": true,
"issue": map[string]interface{}{
"id": "oauth-new-uuid",
"identifier": "TEAM-123",
"title": input["title"],
"description": input["description"],
"url": "https://linear.app/team/issue/TEAM-123",
"priority": 2,
"state": map[string]interface{}{
"id": "state-1",
"name": "Todo",
"type": "unstarted",
},
"createdAt": "2026-05-01T10:00:00Z",
"updatedAt": "2026-05-01T10:00:00Z",
},
},
},
})
return
}

t.Fatalf("unexpected query: %s", req.Query)
})

server := httptest.NewServer(mux)
defer server.Close()

client := NewOAuthClient(OAuthConfig{
ClientID: "test-client-id",
ClientSecret: "test-client-secret",
TokenURL: server.URL + "/oauth/token",
}, "team-1").WithEndpoint(server.URL + "/graphql")

marker := GenerateIdempotencyMarker("bead-oauth", "dev@test.com", 123)
_, deduped, err := client.CreateIssueIdempotent(
context.Background(),
"OAuth Create",
"desc",
2, "", nil,
marker,
)
if err != nil {
t.Fatalf("CreateIssueIdempotent failed: %v", err)
}
if deduped {
t.Fatal("expected deduped=false for fresh OAuth create")
}
if createAuthHeader != "Bearer oauth-test-token" {
t.Fatalf("Authorization header = %q, want %q", createAuthHeader, "Bearer oauth-test-token")
}
}

func TestCreateIssueDedups(t *testing.T) {
existing := Issue{
ID: "existing-uuid",
Expand Down
Loading