feat(linear): add MCP-style save issue (#9670)

* feat(linear): add MCP-style save issue

* fix(linear): harden save issue parity

* fix(linear): close save issue contract gaps

* docs(linear): bundle project discovery with save issue
This commit is contained in:
Brennan Benson
2026-07-21 13:25:22 -07:00
committed by GitHub
parent 87af1c8673
commit a10a2ba53c
33 changed files with 1094 additions and 61 deletions
@@ -54,6 +54,7 @@ describe('Linear agent access RPC methods', () => {
linearIssueUpdateTask: vi.fn().mockResolvedValue({ ok: true }),
linearIssueAddComment: vi.fn().mockResolvedValue({ ok: true }),
linearIssueAttachLink: vi.fn().mockResolvedValue({ ok: true }),
linearSaveIssue: vi.fn().mockResolvedValue({ ok: true }),
linearIssueCreate: vi.fn().mockResolvedValue({ ok: true })
} as unknown as OrcaRuntimeService
const dispatcher = new RpcDispatcher({ runtime, methods: LINEAR_AGENT_ACCESS_METHODS })
@@ -139,6 +140,16 @@ describe('Linear agent access RPC methods', () => {
workspaceId: 'workspace-1'
})
)
const saveResponse = await dispatcher.dispatch(
makeRequest('linear.saveIssue', {
input: 'ENG-1',
title: 'Updated title',
assignee: null,
labels: ['Bug'],
project: null,
workspaceId: 'workspace-1'
})
)
expect(setStateResponse.ok).toBe(true)
expect(teamListResponse.ok).toBe(true)
@@ -152,6 +163,7 @@ describe('Linear agent access RPC methods', () => {
expect(commentResponse.ok).toBe(true)
expect(attachResponse.ok).toBe(true)
expect(createResponse.ok).toBe(true)
expect(saveResponse.ok).toBe(true)
expect(runtime.linearIssueSetState).toHaveBeenCalledWith({
input: 'ENG-1',
to: 'In Review',
@@ -218,6 +230,15 @@ describe('Linear agent access RPC methods', () => {
writeId: '33333333-3333-4333-8333-333333333333',
workspaceId: 'workspace-1'
})
expect(runtime.linearSaveIssue).toHaveBeenCalledWith({
input: 'ENG-1',
title: 'Updated title',
assignee: null,
labels: ['Bug'],
project: null,
workspaceId: 'workspace-1',
writeId: undefined
})
})
it('rejects malformed write ids before the runtime is called', async () => {
@@ -336,6 +357,7 @@ type LinearUnconfirmedBuilder = {
): Error & { data?: { cause?: string; nextSteps?: string[] } }
resolveLinearAgentState(input: string, states: unknown[]): unknown | null
linearCreatedIssueMatchesIntent(issue: unknown, intent: unknown): boolean
linearSavedIssueMatchesIntent(issue: unknown, intent: unknown): boolean
notifyLinearLinkedIssueUpdated(
workspaceId: string,
identifier: string | readonly string[]
@@ -560,6 +582,43 @@ describe('Linear agent write recovery helpers', () => {
).toBe(false)
})
it('confirms save-issue updates including explicit relationship clears', () => {
const runtime = new OrcaRuntimeService()
const builder = runtime as unknown as LinearUnconfirmedBuilder
const issue = {
id: 'issue-2',
identifier: 'ENG-2',
title: 'Updated title',
description: 'Updated description',
url: 'https://example.invalid/ENG-2',
team: { id: 'team-1', key: 'ENG', name: 'Engineering' },
state: { id: 'state-review', name: 'In Review' },
parent: null,
project: null,
assignee: null,
priority: 2,
estimate: null,
dueDate: null,
labelIds: ['label-1']
}
expect(
builder.linearSavedIssueMatchesIntent(issue, {
title: 'Updated title',
description: 'Updated description',
stateId: 'state-review',
parentId: null,
projectId: null,
assigneeId: null,
priority: 2,
estimate: null,
dueDate: null,
labelIds: ['label-1']
})
).toBe(true)
expect(builder.linearSavedIssueMatchesIntent(issue, { projectId: 'project-2' })).toBe(false)
})
it('resolves workflow states by UUID or case-insensitive exact name', () => {
const runtime = new OrcaRuntimeService()
const states = [
@@ -130,6 +130,21 @@ const LinearIssueCreate = z.object({
context: LinearCurrentContext
})
const LinearSaveIssue = LinearWriteTarget.extend({
team: OptionalString,
title: OptionalString,
description: z.string().optional(),
state: OptionalString,
assignee: z.string().nullable().optional(),
priority: z.number().int().min(0).max(4).optional(),
estimate: z.number().min(0).nullable().optional(),
dueDate: OptionalLinearDueDateOrClear,
labels: z.array(z.string()).optional(),
project: z.string().nullable().optional(),
parentId: z.string().nullable().optional(),
writeId: OptionalString
})
function parseLinearWriteId(writeId: string | undefined): string | undefined {
if (writeId === undefined) {
return undefined
@@ -141,6 +156,12 @@ function parseLinearWriteId(writeId: string | undefined): string | undefined {
}
export const LINEAR_AGENT_ACCESS_METHODS: RpcMethod[] = [
defineMethod({
name: 'linear.saveIssue',
params: LinearSaveIssue,
handler: async (params, { runtime }) =>
runtime.linearSaveIssue({ ...params, writeId: parseLinearWriteId(params.writeId) })
}),
defineMethod({
name: 'linear.agentSearchIssues',
params: AgentSearchIssues,
@@ -74,6 +74,29 @@ describe('Linear agent project access helpers', () => {
expect(readExactName).toHaveBeenCalledWith('launch', 'workspace-1')
})
it('resolves Linear projects by URL slug without a paginated exact-name scan', async () => {
const runtime = new OrcaRuntimeService()
const tester = runtime as unknown as LinearProjectResolverTester
vi.spyOn(tester, 'readLinearProjectByIdForCreate').mockResolvedValue(null as never)
vi.spyOn(tester, 'readLinearProjectsForCreate').mockResolvedValue([
{
id: 'project-1',
slugId: 'launch-d8f6c7e7',
name: 'Launch',
teams: [{ id: 'team-1', name: 'Engineering', key: 'ENG' }]
}
] as never)
const readExactName = vi.spyOn(tester, 'readLinearProjectsByExactNameForCreate')
await expect(
tester.resolveLinearCreateProject('LAUNCH-D8F6C7E7', {
id: 'team-1',
workspaceId: 'workspace-1'
})
).resolves.toMatchObject({ id: 'project-1' })
expect(readExactName).not.toHaveBeenCalled()
})
it('resolves same-named Linear projects by target team compatibility', async () => {
const runtime = new OrcaRuntimeService()
const tester = runtime as unknown as LinearProjectResolverTester