Sync Linear issues and documents into Knowledge with the Linear sign-in

The Linear connector now syncs as well as giving agents its tools, from
one connection. Linear's MCP server is its own OAuth issuer, so its
tokens are read through the same MCP tools the agents use (list_issues,
get_issue, list_comments, list_documents) rather than Linear's GraphQL
API, and no OAuth app has to be registered.

A source picks teams and projects, with comments (on by default) and the
projects' documents. Each issue becomes one document with its state,
assignee, priority, labels, description and comments, filed under its
team and citing its Linear URL. Each sync reads up to 500 issues and 100
documents again. /api/connections/<id>/linear lists the teams and
projects to pick from. Sources sync on their schedule with the owner's
connection, and pause when the sign-in needs reconnecting.
This commit is contained in:
arc53-machine committed 2026-09-29 11:32:40 +01:00
1 parent 805e65eeb4
commit 03d1b10897
9 files changed
+1168 -16

No files matched your search

+279
View File
@@ -0,0 +1,279 @@
"""Linear as Knowledge: the same MCP sign-in that gives agents Linear's tools syncs its issues."""
from __future__ import annotations
import asyncio
from contextlib import contextmanager
from unittest.mock import MagicMock, patch
import pytest
from flask import Flask
from sqlalchemy import text
import docsgpt.api.user # noqa: F401 (loads mcp_tool without the circular import)
from docsgpt.connectors import catalog, linear, service
from docsgpt.security.encryption import encrypt_json
@pytest.fixture
def app():
return Flask(__name__)
@contextmanager
def _db(conn):
@contextmanager
def _yield():
yield conn
with patch.multiple("docsgpt.api.connector.connections", db_session=_yield, db_readonly=_yield), \
patch.multiple("docsgpt.connectors.service", db_session=_yield, db_readonly=_yield):
yield
def _call(app, resource, method, path, user="alice", body=None, args=()):
with app.test_request_context(path, method=method.upper(), json=body):
from flask import request
request.decoded_token = {"sub": user} if user else None
return getattr(resource(), method)(*args)
def _linear(conn, user="alice", status="connected") -> str:
tokens = {"tokens": {"access_token": "lin-mcp", "token_type": "Bearer", "refresh_token": "r"}}
return str(conn.execute(
text(
"INSERT INTO connector_sessions (user_id, provider, connector_key, auth_kind, status, account_label, "
"server_url, encrypted_credentials) VALUES (:u, 'mcp:https://mcp.linear.app', 'mcp:linear', "
"'mcp_oauth', :s, 'alice@acme.com', 'https://mcp.linear.app', :e) RETURNING id"
),
{"u": user, "s": status, "e": encrypt_json(tokens, user)},
).scalar())
class FakeLinear:
def __init__(self, answers):
self.answers = answers
async def input_schema(self, name):
return {"properties": {"limit": {}, "cursor": {}}} if name in self.answers else None
async def call(self, name, arguments):
return self.answers[name]
def _session(answers):
"""``run_connection_session`` answering from ``answers``, recording the connection it was given."""
seen = {}
def run(connection, server_url, work, **kwargs):
seen.update(connection=connection, server_url=server_url)
return asyncio.run(work(FakeLinear(answers)))
return run, seen
class TestCatalog:
@pytest.fixture(autouse=True)
def _fresh_registry(self):
catalog.reset_registry_for_tests()
yield
catalog.reset_registry_for_tests()
def test_one_linear_sign_in_syncs_and_gives_tools(self):
definition = catalog.get_definition("mcp:linear")
assert definition.capabilities == ("sync", "read", "write")
assert definition.sync_ingestor == "linear"
assert definition.setup == {"tools": "auto", "sync": "ask"}
assert definition.tool_templates == ("mcp_tool",)
assert definition.auth_kind == "mcp_oauth"
def test_other_presets_still_only_give_tools(self):
notion = catalog.get_definition("mcp:notion")
assert notion.sync_ingestor is None
assert notion.setup == {"tools": "auto", "sync": "off"}
assert "sync" not in notion.capabilities
def test_linear_sources_have_a_loader(self):
from docsgpt.parser.remote.linear_loader import LinearLoader
from docsgpt.parser.remote.remote_creator import RemoteCreator, normalize_remote_data
assert isinstance(RemoteCreator.create_loader("linear"), LinearLoader)
stored = {"teams": [{"id": "t1"}], "include_comments": True}
assert normalize_remote_data("linear", stored) == stored
class TestWorkspace:
def test_lists_the_teams_and_projects_to_pick(self, app, pg_conn):
from docsgpt.api.connector.connections import LinearWorkspace
cid = _linear(pg_conn)
run, seen = _session({
"list_teams": {"teams": [{"id": "t2", "key": "OPS", "name": "Operations"},
{"id": "t1", "key": "ENG", "name": "Engineering"}]},
"list_projects": [{"id": "p1", "name": "Acme", "state": {"name": "Started"}, "teams": ["Engineering"]}],
})
with _db(pg_conn), patch("docsgpt.connectors.mcp.run_connection_session", side_effect=run):
resp = _call(app, LinearWorkspace, "get", f"/api/connections/{cid}/linear", args=[cid])
assert resp.status_code == 200
data = resp.get_json()
assert data["teams"] == [
{"id": "t1", "key": "ENG", "name": "Engineering"}, {"id": "t2", "key": "OPS", "name": "Operations"},
]
assert data["projects"] == [{"id": "p1", "name": "Acme", "state": "Started", "teams": ["Engineering"]}]
assert str(seen["connection"]["id"]) == cid
assert seen["server_url"] == "https://mcp.linear.app/mcp"
assert "lin-mcp" not in resp.get_data(as_text=True)
def test_a_lost_sign_in_asks_to_reconnect(self, app, pg_conn):
from docsgpt.api.connector.connections import LinearWorkspace
cid = _linear(pg_conn)
with _db(pg_conn), patch("docsgpt.connectors.mcp.run_connection_session",
side_effect=service.ConnectionUnavailable("expired", connection_id=cid)):
resp = _call(app, LinearWorkspace, "get", f"/api/connections/{cid}/linear", args=[cid])
assert resp.status_code == 409
assert resp.get_json()["code"] == "reconnect"
def test_linear_not_answering_is_worth_a_retry(self, app, pg_conn):
from docsgpt.api.connector.connections import LinearWorkspace
cid = _linear(pg_conn)
with _db(pg_conn), patch("docsgpt.connectors.mcp.run_connection_session",
side_effect=service.TransientConnectionError("rate limit")):
resp = _call(app, LinearWorkspace, "get", f"/api/connections/{cid}/linear", args=[cid])
assert resp.status_code == 503
def test_only_the_owner_and_only_linear(self, app, pg_conn):
from docsgpt.api.connector.connections import LinearWorkspace
theirs = _linear(pg_conn, user="bob")
github = str(pg_conn.execute(text(
"INSERT INTO connector_sessions (user_id, provider, connector_key, auth_kind, status) "
"VALUES ('alice', 'github', 'github', 'api_key', 'connected') RETURNING id"
)).scalar())
with _db(pg_conn):
for cid in (theirs, github):
resp = _call(app, LinearWorkspace, "get", f"/api/connections/{cid}/linear", args=[cid])
assert resp.status_code == 404
class TestSetup:
def test_sync_queues_the_picked_teams_with_the_connection(self, app, pg_conn):
from docsgpt.api.connector.connections import ConnectionSetup
cid = _linear(pg_conn)
with _db(pg_conn), patch("docsgpt.api.user.tasks.ingest_remote.apply_async",
return_value=MagicMock(id="t")) as apply:
resp = _call(app, ConnectionSetup, "post", f"/api/connections/{cid}/setup", body={
"create_tools": False,
"sync": {"items": {"teams": [{"id": "t1", "key": "ENG", "name": "Engineering"}],
"include_comments": False}, "frequency": "daily"},
}, args=[cid])
assert resp.status_code == 200
kwargs = apply.call_args.kwargs["kwargs"]
assert kwargs["loader"] == "linear"
assert kwargs["connection_id"] == cid
assert kwargs["sync_frequency"] == "daily"
assert kwargs["source_data"] == {
"teams": [{"id": "t1", "key": "ENG", "name": "Engineering"}], "projects": [],
"include_comments": False, "include_documents": False,
}
assert resp.get_json()["sources"][0]["name"] == "Linear · Engineering"
def test_nothing_picked_is_a_bad_request(self, app, pg_conn):
from docsgpt.api.connector.connections import ConnectionSetup
cid = _linear(pg_conn)
with _db(pg_conn), patch("docsgpt.api.user.tasks.ingest_remote.apply_async") as apply:
resp = _call(app, ConnectionSetup, "post", f"/api/connections/{cid}/setup", body={
"create_tools": False, "sync": {"items": {"teams": []}},
}, args=[cid])
assert resp.status_code == 400
apply.assert_not_called()
class TestWorker:
@staticmethod
@contextmanager
def _readonly(conn):
from docsgpt import worker
@contextmanager
def _yield():
yield conn
with patch.object(worker, "db_readonly", _yield):
yield worker
def test_the_loader_gets_the_connection_not_its_tokens(self, pg_conn):
cid = _linear(pg_conn)
with self._readonly(pg_conn) as worker:
data = worker._with_connection_credentials({"teams": [{"id": "t1"}]}, cid)
assert data == {"teams": [{"id": "t1"}], "connection_id": cid}
def test_a_connection_that_needs_reconnecting_gives_nothing(self, pg_conn):
cid = _linear(pg_conn, status="reconnect_needed")
with self._readonly(pg_conn) as worker:
assert worker._with_connection_credentials({"teams": [{"id": "t1"}]}, cid) is None
def test_scheduled_sync_reads_with_the_connection(self, pg_conn):
cid = _linear(pg_conn)
pg_conn.execute(text(
"INSERT INTO sources (user_id, name, type, sync_frequency, connection_id, remote_data) "
"VALUES ('alice', 'Linear · Engineering', 'linear', 'daily', CAST(:c AS uuid), "
"'{\"teams\": [{\"id\": \"t1\"}]}')"
), {"c": cid})
with self._readonly(pg_conn) as worker, patch.object(worker, "sync", return_value={"status": "success"}) as sync:
counts = worker.sync_worker(MagicMock(), "daily")
assert counts["sync_success"] == 1
args, kwargs = sync.call_args
assert args[1] == {"teams": [{"id": "t1"}]}
assert args[4] == "linear"
assert kwargs["connection_id"] == cid
def test_scheduled_sync_skips_a_source_paused_for_reconnect(self, pg_conn):
cid = _linear(pg_conn, status="reconnect_needed")
pg_conn.execute(text(
"INSERT INTO sources (user_id, name, type, sync_frequency, connection_id, remote_data, metadata) "
"VALUES ('alice', 'Linear', 'linear', 'daily', CAST(:c AS uuid), '{\"teams\": [{\"id\": \"t1\"}]}', "
"'{\"sync_state\": \"paused_reconnect\"}')"
), {"c": cid})
with self._readonly(pg_conn) as worker, patch.object(worker, "sync") as sync:
counts = worker.sync_worker(MagicMock(), "daily")
sync.assert_not_called()
assert counts["sync_skipped"] == 1
def test_scheduled_sync_skips_a_source_whose_connection_was_removed(self, pg_conn):
pg_conn.execute(text(
"INSERT INTO sources (user_id, name, type, sync_frequency, remote_data) "
"VALUES ('alice', 'Linear', 'linear', 'daily', '{\"teams\": [{\"id\": \"t1\"}]}')"
))
with self._readonly(pg_conn) as worker, patch.object(worker, "sync") as sync:
counts = worker.sync_worker(MagicMock(), "daily")
sync.assert_not_called()
assert counts["sync_skipped"] == 1
def test_a_lost_sign_in_fails_the_ingest_without_retrying_forever(self):
from docsgpt import worker
loader = MagicMock()
loader.load_data.side_effect = service.ConnectionUnavailable("expired", connection_id="c-1")
task = MagicMock()
task.request.retries = 1
with patch.object(worker.RemoteCreator, "create_loader", return_value=loader), patch.object(
worker, "_with_connection_credentials", return_value={"teams": [{"id": "t1"}], "connection_id": "c-1"},
), patch.object(worker, "publish_user_event") as publish:
with pytest.raises(service.ConnectionUnavailable):
worker.remote_worker(task, {"teams": [{"id": "t1"}]}, "Linear", "alice", "linear",
connection_id="c-1")
assert publish.call_args.args[1] == "source.ingest.failed"
def test_the_picker_lists_are_capped(monkeypatch):
monkeypatch.setattr(linear, "MAX_PICKER_ITEMS", 2)
session = FakeLinear({
"list_teams": {"teams": [{"id": f"t{n}", "name": f"Team {n}"} for n in range(5)]},
"list_projects": {"projects": []},
})
assert len(asyncio.run(linear.list_workspace(session))["teams"]) == 2
+290
View File
@@ -0,0 +1,290 @@
"""Linear issues and documents as Knowledge, read through Linear's MCP server (mocked)."""
from __future__ import annotations
import asyncio
from unittest.mock import patch
import pytest
from docsgpt.connectors import linear
from docsgpt.parser.remote.linear_loader import LinearLoader
# Input schemas shaped like the ones Linear's MCP server publishes.
SCHEMAS = {
"list_issues": {"properties": {
"team": {}, "project": {}, "limit": {"maximum": 250}, "cursor": {}, "orderBy": {}, "includeArchived": {},
}},
"get_issue": {"properties": {"id": {}}},
"list_comments": {"properties": {"issueId": {}}},
"list_documents": {"properties": {"projectId": {}, "limit": {}, "cursor": {}}},
"get_document": {"properties": {"id": {}}},
"list_teams": {"properties": {"limit": {}, "cursor": {}}},
"list_projects": {"properties": {"limit": {}, "cursor": {}, "includeArchived": {}}},
}
ISSUE = {
"id": "ENG-1310",
"title": "Fix the loader",
"description": "The spinner stays for 10 s.",
"url": "https://linear.app/acme/issue/ENG-1310/fix-the-loader",
"status": "In Progress",
"priority": {"value": 2, "name": "High"},
"assignee": "Sam",
"labels": ["bug", {"id": "l2", "name": "ui"}],
"project": "Acme",
"team": "Engineering",
"createdAt": "2026-09-20T10:00:00.000Z",
"updatedAt": "2026-09-25T09:30:00.000Z",
}
class FakeLinear:
"""Linear's MCP server, answering tool calls from handlers."""
def __init__(self, handlers, schemas=None):
self.handlers = handlers
self.schemas = SCHEMAS if schemas is None else schemas
self.calls: list[tuple[str, dict]] = []
async def input_schema(self, name):
return self.schemas.get(name)
async def call(self, name, arguments):
self.calls.append((name, dict(arguments)))
return self.handlers[name](arguments)
def called(self, name):
return [args for tool, args in self.calls if tool == name]
def _collect(session, **selection):
selection = linear.normalize_selection({"teams": [], "projects": [], **selection})
return asyncio.run(LinearLoader().collect(session, selection))
class TestIssues:
def test_one_document_per_issue_with_what_it_says(self):
session = FakeLinear({
"list_issues": lambda args: {"issues": [ISSUE], "hasNextPage": False},
"list_comments": lambda args: {"comments": [
{"id": "c1", "body": "Reproduced on the current release.", "user": {"name": "Alex"},
"createdAt": "2026-09-21T11:00:00.000Z"},
{"id": "c2", "body": "Fixed.", "author": "Sam", "createdAt": "2026-09-22T11:00:00.000Z"},
]},
})
[doc] = _collect(session, teams=[{"id": "team-1", "key": "ENG", "name": "Engineering"}])
text = doc.text
assert text.startswith("# ENG-1310: Fix the loader")
for fragment in ("In Progress", "Sam", "High", "bug, ui", "Acme", "The spinner stays for 10 s.",
"Reproduced on the current release.", "Alex", "Fixed."):
assert fragment in text
assert doc.extra_info["title"] == "ENG-1310: Fix the loader"
assert doc.extra_info["source"] == ISSUE["url"]
assert doc.extra_info["file_path"] == "ENG/ENG-1310.md"
assert session.called("list_comments") == [{"issueId": "ENG-1310"}]
def test_pages_through_a_teams_issues(self):
pages = {
None: {"issues": [{**ISSUE, "id": "ENG-2"}], "hasNextPage": True, "cursor": "p2"},
"p2": {"issues": [{**ISSUE, "id": "ENG-1"}], "hasNextPage": False},
}
session = FakeLinear({"list_issues": lambda args: pages[args.get("cursor")]})
docs = _collect(session, teams=["team-1"], include_comments=False)
assert [d.extra_info["title"].split(":")[0] for d in docs] == ["ENG-2", "ENG-1"]
first, second = session.called("list_issues")
assert first == {"team": "team-1", "limit": 100, "orderBy": "updatedAt", "includeArchived": False}
assert second == {**first, "cursor": "p2"}
def test_a_clipped_description_is_read_in_full(self):
clipped = {**ISSUE, "description": "The spinner (truncated, use get_issue to read the full description)"}
session = FakeLinear({
"list_issues": lambda args: {"issues": [clipped]},
"get_issue": lambda args: {"issue": {**ISSUE, "description": "The whole story."}},
})
[doc] = _collect(session, teams=["team-1"], include_comments=False)
assert "The whole story." in doc.text
assert "truncated" not in doc.text
assert session.called("get_issue") == [{"id": "ENG-1310"}]
def test_comments_are_paged_through(self):
schemas = {**SCHEMAS, "list_comments": {"properties": {"issueId": {}, "cursor": {}}}}
pages = {
None: {"comments": [{"body": "First."}], "hasNextPage": True, "cursor": "c2"},
"c2": {"comments": [{"body": "Second."}], "hasNextPage": False},
}
session = FakeLinear({
"list_issues": lambda args: [ISSUE],
"list_comments": lambda args: pages[args.get("cursor")],
}, schemas)
[doc] = _collect(session, teams=["team-1"])
assert "First." in doc.text and "Second." in doc.text
def test_comments_linear_cannot_list_are_skipped(self):
schemas = {k: v for k, v in SCHEMAS.items() if k != "list_comments"}
session = FakeLinear({"list_issues": lambda args: [ISSUE]}, schemas)
[doc] = _collect(session, teams=["team-1"])
assert "## Comments" not in doc.text
def test_comments_are_left_out_when_not_wanted(self):
session = FakeLinear({"list_issues": lambda args: [ISSUE]})
[doc] = _collect(session, teams=["team-1"], include_comments=False)
assert session.called("list_comments") == []
assert "## Comments" not in doc.text
def test_an_issue_in_a_picked_team_and_project_is_synced_once(self):
session = FakeLinear({"list_issues": lambda args: {"issues": [ISSUE]}})
docs = _collect(session, teams=["team-1"], projects=["project-1"], include_comments=False)
assert len(docs) == 1
assert [args.get("team") or args.get("project") for args in session.called("list_issues")] == [
"team-1", "project-1",
]
def test_stops_at_the_cap(self, monkeypatch):
monkeypatch.setattr(linear, "MAX_ISSUES", 3)
pages = iter(range(100))
def endless(args):
page = next(pages)
issues = [{**ISSUE, "id": f"ENG-{page}{n}"} for n in range(2)]
return {"issues": issues, "hasNextPage": True, "cursor": f"p{page + 1}"}
session = FakeLinear({"list_issues": endless})
docs = _collect(session, teams=["team-1"], projects=["project-1"], include_comments=False)
assert len(docs) == 3
assert len(session.called("list_issues")) == 2
def test_a_repeated_cursor_ends_the_listing(self):
session = FakeLinear({"list_issues": lambda args: {"issues": [ISSUE], "hasNextPage": True, "cursor": "same"}})
_collect(session, teams=["team-1"], include_comments=False)
assert len(session.called("list_issues")) == 2
def test_nested_records_and_graphql_page_info_are_read(self):
record = {
"id": "5c1e3d2a-uuid", "identifier": "DES-7", "title": "Logo",
"state": {"id": "s", "name": "Done"}, "assignee": {"id": "u", "displayName": "kim"},
"team": {"id": "t", "key": "DES", "name": "Design"}, "labels": {"nodes": [{"name": "brand"}]},
}
session = FakeLinear({"list_issues": lambda args: {
"nodes": [record], "pageInfo": {"hasNextPage": False, "endCursor": "x"},
}})
[doc] = _collect(session, teams=["t"], include_comments=False)
assert doc.text.startswith("# DES-7: Logo")
assert "Done" in doc.text and "kim" in doc.text and "brand" in doc.text
assert doc.extra_info["file_path"] == "DES/DES-7.md"
def test_argument_names_follow_the_tools_schema(self):
schemas = {**SCHEMAS, "list_issues": {"properties": {"teamId": {}, "first": {"maximum": 50}, "after": {}}}}
pages = {None: {"issues": [ISSUE], "hasNextPage": True, "cursor": "p2"}, "p2": {"issues": []}}
session = FakeLinear({"list_issues": lambda args: pages[args.get("after")]}, schemas)
_collect(session, teams=["team-1"], include_comments=False)
assert session.called("list_issues") == [
{"teamId": "team-1", "first": 50}, {"teamId": "team-1", "first": 50, "after": "p2"},
]
def test_a_tool_that_cannot_filter_by_team_syncs_nothing(self):
schemas = {**SCHEMAS, "list_issues": {"properties": {"query": {}, "limit": {}}}}
session = FakeLinear({"list_issues": lambda args: pytest.fail("must not list the whole workspace")}, schemas)
with pytest.raises(linear.LinearSyncError, match="team"):
_collect(session, teams=["team-1"])
def test_a_missing_tool_is_an_error(self):
session = FakeLinear({}, schemas={})
with pytest.raises(linear.LinearSyncError, match="list_issues"):
_collect(session, teams=["team-1"])
class TestDocuments:
def test_documents_of_the_picked_projects(self):
session = FakeLinear({
"list_issues": lambda args: {"issues": []},
"list_documents": lambda args: {"documents": [
{"id": "d1", "title": "Launch plan", "url": "https://linear.app/acme/document/launch-plan-d1"},
]},
"get_document": lambda args: {"id": "d1", "title": "Launch plan", "content": "We ship on Monday.",
"url": "https://linear.app/acme/document/launch-plan-d1"},
})
[doc] = _collect(session, projects=[{"id": "project-1", "name": "Acme"}], include_documents=True)
assert doc.text.startswith("# Launch plan")
assert "We ship on Monday." in doc.text
assert doc.extra_info["source"] == "https://linear.app/acme/document/launch-plan-d1"
assert doc.extra_info["file_path"] == "Acme/Documents/Launch plan.md"
assert session.called("list_documents") == [{"projectId": "project-1", "limit": 100}]
def test_a_listed_document_with_its_content_is_not_read_again(self):
session = FakeLinear({
"list_issues": lambda args: [],
"list_documents": lambda args: [{"id": "d1", "title": "Notes", "content": "All here."}],
})
[doc] = _collect(session, projects=["project-1"], include_documents=True)
assert "All here." in doc.text
assert session.called("get_document") == []
def test_documents_with_one_title_stay_two_files(self):
session = FakeLinear({
"list_issues": lambda args: [],
"list_documents": lambda args: [
{"id": "d1aaaaaaaa", "title": "Notes", "content": "One."},
{"id": "d2bbbbbbbb", "title": "Notes", "content": "Two."},
],
})
docs = _collect(session, projects=[{"id": "p1", "name": "Acme"}], include_documents=True)
assert [d.extra_info["file_path"] for d in docs] == [
"Acme/Documents/Notes.md", "Acme/Documents/Notes (d2bbbbbb).md",
]
def test_documents_are_left_out_when_not_wanted(self):
session = FakeLinear({"list_issues": lambda args: []})
assert _collect(session, projects=["project-1"]) == []
assert session.called("list_documents") == []
class TestSelection:
def test_ids_or_records_are_kept_once(self):
selection = linear.normalize_selection({
"teams": ["t1", {"id": "t1", "key": "ENG", "name": "Engineering"}, {"id": "t2"}, "", None],
"projects": [{"id": "p1", "name": "Acme"}],
"include_comments": "false",
"include_documents": True,
"unrelated": "dropped",
})
assert selection == {
"teams": [{"id": "t1", "key": "ENG", "name": "Engineering"}, {"id": "t2", "key": "", "name": ""}],
"projects": [{"id": "p1", "name": "Acme"}],
"include_comments": False,
"include_documents": True,
}
def test_comments_are_on_by_default(self):
assert linear.normalize_selection({"teams": ["t1"]})["include_comments"] is True
def test_something_must_be_picked(self):
with pytest.raises(ValueError):
linear.normalize_selection({"teams": [], "projects": []})
def test_a_json_string_is_read(self):
assert linear.normalize_selection('{"teams": ["t1"]}')["teams"] == [{"id": "t1", "key": "", "name": ""}]
def test_default_name_lists_what_was_picked(self):
selection = linear.normalize_selection({
"teams": [{"id": "t1", "name": "Engineering"}], "projects": [{"id": "p1", "name": "Acme"}],
})
assert linear.selection_name(selection) == "Linear · Engineering, Acme"
assert linear.selection_name(linear.normalize_selection({"teams": ["t1"]})) == "Linear"
class TestLoadData:
def test_reads_with_the_sources_connection(self):
connection = {"id": "c1", "user_id": "alice", "server_url": "https://mcp.linear.app"}
loader = LinearLoader()
with patch("docsgpt.parser.remote.linear_loader._connection", return_value=connection) as load, \
patch("docsgpt.parser.remote.linear_loader.run_connection_session",
return_value=["doc"]) as run:
result = loader.load_data({"teams": ["t1"], "connection_id": "c1"})
assert result == ["doc"]
load.assert_called_once_with("c1")
assert run.call_args.args[:2] == (connection, "https://mcp.linear.app/mcp")
def test_needs_a_connection(self):
with pytest.raises(ValueError):
LinearLoader().load_data({"teams": ["t1"]})