-
Notifications
You must be signed in to change notification settings - Fork 1k
fix(tracker-linear): fall back to direct transport when @composio/core is missing #2010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
harshitsinghbhandari
wants to merge
2
commits into
AgentWrapper:main
Choose a base branch
from
harshitsinghbhandari:fix/tracker-linear-composio-fallback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+243
−26
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "@aoagents/ao-plugin-tracker-linear": patch | ||
| --- | ||
|
|
||
| fix(tracker-linear): fall back to the direct Linear transport when @composio/core is missing | ||
|
|
||
| The Linear tracker selects its transport by sniffing env: if `COMPOSIO_API_KEY` is set it routes through the Composio SDK, otherwise it uses the direct `LINEAR_API_KEY` API. But `@composio/core` is an optional dependency that isn't installed with the plugin, so any user who had `COMPOSIO_API_KEY` exported (commonly set globally for unrelated Composio work) got a hard `"Composio SDK (@composio/core) is not installed"` failure on every tracker call — even when a perfectly valid `LINEAR_API_KEY` was available. | ||
|
|
||
| The Composio transport now throws a typed `ComposioSdkMissingError` when the SDK can't be loaded. When that happens and a `LINEAR_API_KEY` is present, the tracker transparently falls back to the direct transport instead of failing. The `tracker.dep_missing` event is emitted only when there is genuinely no fallback (no `LINEAR_API_KEY`), so a successful fallback no longer raises a false error-level event. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
packages/plugins/tracker-linear/test/composio-fallback.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| /** | ||
| * Regression tests for Composio→direct transport fallback. | ||
| * | ||
| * When COMPOSIO_API_KEY is present but @composio/core cannot be loaded, the | ||
| * tracker must fall back to the direct LINEAR_API_KEY transport instead of | ||
| * hard-failing — provided a LINEAR_API_KEY is available. A bare COMPOSIO_API_KEY | ||
| * (commonly exported globally for unrelated Composio work) must not break an | ||
| * otherwise-valid Linear setup. | ||
| */ | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { EventEmitter } from "node:events"; | ||
|
|
||
| const { requestMock, recordActivityEventMock } = vi.hoisted(() => ({ | ||
| requestMock: vi.fn(), | ||
| recordActivityEventMock: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("node:https", () => ({ | ||
| request: requestMock, | ||
| })); | ||
|
|
||
| vi.mock("@aoagents/ao-core", async () => { | ||
| const actual = (await vi.importActual("@aoagents/ao-core")) as Record<string, unknown>; | ||
| return { | ||
| ...actual, | ||
| recordActivityEvent: recordActivityEventMock, | ||
| }; | ||
| }); | ||
|
|
||
| // @composio/core is intentionally not installed — the real dynamic import | ||
| // fails with ERR_MODULE_NOT_FOUND, exercising the fallback path. | ||
|
|
||
| import { create, _resetDepMissingEmittedForTesting } from "../src/index.js"; | ||
| import type { ProjectConfig } from "@aoagents/ao-core"; | ||
|
|
||
| const project: ProjectConfig = { | ||
| name: "test", | ||
| repo: "acme/integrator", | ||
| path: "/tmp/repo", | ||
| defaultBranch: "main", | ||
| sessionPrefix: "test", | ||
| tracker: { plugin: "linear", teamId: "team-uuid-1", workspaceSlug: "acme" }, | ||
| }; | ||
|
|
||
| const sampleIssueNode = { | ||
| id: "uuid-123", | ||
| identifier: "INT-123", | ||
| title: "Fix login bug", | ||
| description: "Users can't log in with SSO", | ||
| url: "https://linear.app/acme/issue/INT-123", | ||
| priority: 2, | ||
| branchName: "feat/INT-123", | ||
| state: { name: "In Progress", type: "started" }, | ||
| labels: { nodes: [{ name: "bug" }] }, | ||
| assignee: { name: "Alice Smith", displayName: "Alice" }, | ||
| team: { key: "INT" }, | ||
| }; | ||
|
|
||
| /** Queue a successful Linear API response for the direct transport. */ | ||
| function mockLinearAPI(responseData: unknown, statusCode = 200) { | ||
| const body = JSON.stringify({ data: responseData }); | ||
| requestMock.mockImplementationOnce( | ||
| ( | ||
| _opts: Record<string, unknown>, | ||
| callback: (res: EventEmitter & { statusCode: number }) => void, | ||
| ) => { | ||
| const req = Object.assign(new EventEmitter(), { | ||
| write: vi.fn(), | ||
| end: vi.fn(() => { | ||
| const res = Object.assign(new EventEmitter(), { statusCode }); | ||
| callback(res); | ||
| process.nextTick(() => { | ||
| res.emit("data", Buffer.from(body)); | ||
| res.emit("end"); | ||
| }); | ||
| }), | ||
| destroy: vi.fn(), | ||
| setTimeout: vi.fn(), | ||
| }); | ||
| return req; | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| let savedComposioKey: string | undefined; | ||
| let savedComposioEntity: string | undefined; | ||
| let savedLinearKey: string | undefined; | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| requestMock.mockReset(); | ||
| recordActivityEventMock.mockReset(); | ||
| _resetDepMissingEmittedForTesting(); | ||
| savedComposioKey = process.env["COMPOSIO_API_KEY"]; | ||
| savedComposioEntity = process.env["COMPOSIO_ENTITY_ID"]; | ||
| savedLinearKey = process.env["LINEAR_API_KEY"]; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (savedComposioKey === undefined) delete process.env["COMPOSIO_API_KEY"]; | ||
| else process.env["COMPOSIO_API_KEY"] = savedComposioKey; | ||
| if (savedComposioEntity === undefined) delete process.env["COMPOSIO_ENTITY_ID"]; | ||
| else process.env["COMPOSIO_ENTITY_ID"] = savedComposioEntity; | ||
| if (savedLinearKey === undefined) delete process.env["LINEAR_API_KEY"]; | ||
| else process.env["LINEAR_API_KEY"] = savedLinearKey; | ||
| }); | ||
|
|
||
| describe("Composio→direct transport fallback", () => { | ||
| it("falls back to the direct transport when @composio/core is missing but LINEAR_API_KEY is set", async () => { | ||
| process.env["COMPOSIO_API_KEY"] = "composio-key"; | ||
| process.env["LINEAR_API_KEY"] = "lin_api_test_key"; | ||
| mockLinearAPI({ issue: sampleIssueNode }); | ||
|
|
||
| const tracker = create(); | ||
| const issue = await tracker.getIssue("INT-123", project); | ||
|
|
||
| expect(issue.id).toBe("INT-123"); | ||
| expect(issue.title).toBe("Fix login bug"); | ||
| expect(requestMock).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("does not emit tracker.dep_missing when fallback succeeds", async () => { | ||
| process.env["COMPOSIO_API_KEY"] = "composio-key"; | ||
| process.env["LINEAR_API_KEY"] = "lin_api_test_key"; | ||
| mockLinearAPI({ issue: sampleIssueNode }); | ||
|
|
||
| const tracker = create(); | ||
| await tracker.getIssue("INT-123", project); | ||
|
|
||
| const depMissingCalls = recordActivityEventMock.mock.calls.filter( | ||
| ([event]) => event?.kind === "tracker.dep_missing", | ||
| ); | ||
| expect(depMissingCalls).toHaveLength(0); | ||
| }); | ||
|
|
||
| it("still throws when @composio/core is missing and no LINEAR_API_KEY is available", async () => { | ||
| process.env["COMPOSIO_API_KEY"] = "composio-key"; | ||
| delete process.env["LINEAR_API_KEY"]; | ||
|
|
||
| const tracker = create(); | ||
| await expect(tracker.getIssue("INT-123", project)).rejects.toThrow( | ||
| /Composio SDK.*not installed/, | ||
| ); | ||
| }); | ||
|
|
||
| it("surfaces the SDK-missing error even when activity logging throws", async () => { | ||
| process.env["COMPOSIO_API_KEY"] = "composio-key"; | ||
| delete process.env["LINEAR_API_KEY"]; | ||
| recordActivityEventMock.mockImplementation(() => { | ||
| throw new Error("activity sink failed"); | ||
| }); | ||
|
|
||
| const tracker = create(); | ||
| await expect(tracker.getIssue("INT-123", project)).rejects.toThrow( | ||
| /Composio SDK.*not installed/, | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.