@openchamber/web 1.21.1 → 1.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CodeMirrorCommentWidgets-BGj8TJxW.js → CodeMirrorCommentWidgets-BO_2OW4E.js} +1 -1
- package/dist/assets/DiffView-CNnDxRmO.js +4 -0
- package/dist/assets/DirtyBranchSwitchDialog-jADfXQnR.js +1 -0
- package/dist/assets/FilesView-8wdiG2mj.js +17 -0
- package/dist/assets/GitView-Cv2xH-S6.js +6 -0
- package/dist/assets/{JsonTreeView-CggOsLot.js → JsonTreeView-DUiIpERC.js} +1 -1
- package/dist/assets/LinearIssuesView-CoZ7pQN5.js +1 -0
- package/dist/assets/MarkdownImageGallery-DffjmciG.js +1 -0
- package/dist/assets/MarkdownRendererImpl-DxqdYDAx.js +12 -0
- package/dist/assets/OnboardingScreen-CTZe6HZn.js +1 -0
- package/dist/assets/{PatchDiff-DJYMUiXA.js → PatchDiff-BymkP9JA.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CY2bx_SB.js → PierreDiffViewer-BvwtCxW4.js} +3 -3
- package/dist/assets/{PlanView-PkiOY_9H.js → PlanView-C1qvAm7m.js} +3 -3
- package/dist/assets/SettingsView-xGONHFGS.js +28 -0
- package/dist/assets/{SettingsWindow-oyOm2fHR.js → SettingsWindow-COzgfFxM.js} +1 -1
- package/dist/assets/{ToolOutputDialog-lKyeQTPL.js → ToolOutputDialog-Dlhh_-oe.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-b9joNtXH.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-BP7ebDFF.js → VirtualizedFileDiff-vqW3KKo5.js} +1 -1
- package/dist/assets/WalkthroughView-D-HFgdmM.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-CZ0xPeaT.js → computeVirtualFileMetrics-DUnyszhW.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-C9abMBTb.js → contextPanelEmbeddedChat-CV-DwAiX.js} +1 -1
- package/dist/assets/{de-CEoCz3j6.js → de-Cv_4FoXm.js} +6 -5
- package/dist/assets/es-BIWNEbnS.js +16 -0
- package/dist/assets/{fr-CS7Csln9.js → fr-SD3OfMHJ.js} +6 -5
- package/dist/assets/index-CHUT_bDS.css +1 -0
- package/dist/assets/index-DDInLQDd.js +40 -0
- package/dist/assets/{index-CaPAjwXQ.js → index-DLiD86ge.js} +1 -1
- package/dist/assets/{isDiffPlainText-ZBvDxhVB.js → isDiffPlainText-TNageFjy.js} +1 -1
- package/dist/assets/{isFilePlainText-DiLRrkJr.js → isFilePlainText-JPmZOYSp.js} +1 -1
- package/dist/assets/{ja-vnwqLcx6.js → ja-D7I9HofF.js} +7 -6
- package/dist/assets/{ko-CXuSfZv5.js → ko-BsVJM_PQ.js} +7 -6
- package/dist/assets/{main-D5RWr6sJ.js → main-DCB4JgVe.js} +2 -2
- package/dist/assets/main-De8Z5w49.js +928 -0
- package/dist/assets/markdownCore-BoQVG5-a.js +3 -0
- package/dist/assets/{miniChat-CqR3icsk.js → miniChat-BtV7N5OF.js} +2 -2
- package/dist/assets/{mobile-RN_UTTlB.js → mobile-DZV_sfX7.js} +2 -2
- package/dist/assets/{patchFileDiff-CjRR5ESs.js → patchFileDiff-Chmiz6hq.js} +4 -4
- package/dist/assets/{pl-BJxry0Mi.js → pl-XR9Bs8Be.js} +6 -5
- package/dist/assets/pt-BR-Due4be8g.js +16 -0
- package/dist/assets/{renderElectronMiniChatApp-1wC94fQK.js → renderElectronMiniChatApp-8tXADjfl.js} +2 -2
- package/dist/assets/renderMobileApp-Cji7Hma5.js +25 -0
- package/dist/assets/runtimeEndpointReset-gWt3Lb5D.js +16 -0
- package/dist/assets/scheduledTasksApi-9e-UX6im.js +1 -0
- package/dist/assets/{shikiHighlight-fGmFkxAM.js → shikiHighlight-CRpCl7UT.js} +1 -1
- package/dist/assets/tr-DBJcAv4y.js +7 -0
- package/dist/assets/uk-COYh2BaN.js +16 -0
- package/dist/assets/{useAppFontEffects-KP8_yiGW.js → useAppFontEffects-CCgvcQ6u.js} +178 -170
- package/dist/assets/useInlineCommentController-BkfXnjNZ.js +2 -0
- package/dist/assets/useRootScrollLock-KzOUytpn.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-DrTPkHl4.js → vendor-codemirror-language-data-BxpoC5Fp.js} +2 -2
- package/dist/assets/vendor-zod-DVWEh-IS.js +39 -0
- package/dist/assets/{web-components-DOXvU-tB.js → web-components-B6QgbmTo.js} +4 -4
- package/dist/assets/zh-CN-Cjk6lzhc.js +16 -0
- package/dist/assets/{zh-TW-Dv8yyhN1.js → zh-TW-Dk0dOg03.js} +6 -5
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +2 -2
- package/server/index.js +35 -4
- package/server/lib/agent-tool/runtime.js +2 -19
- package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
- package/server/lib/dev-tunnel/runtime.js +4 -4
- package/server/lib/dev-tunnel/tunnel.test.js +20 -0
- package/server/lib/dictation/DOCUMENTATION.md +19 -6
- package/server/lib/dictation/local/model-catalog.js +220 -0
- package/server/lib/dictation/local/model-catalog.test.js +42 -0
- package/server/lib/dictation/local/sherpa-tts.js +41 -20
- package/server/lib/dictation/local/worker-process.js +2 -0
- package/server/lib/dictation/runtime.js +4 -0
- package/server/lib/dictation/service.js +27 -4
- package/server/lib/fs/DOCUMENTATION.md +4 -0
- package/server/lib/fs/routes.js +129 -0
- package/server/lib/fs/routes.test.js +219 -0
- package/server/lib/git/DOCUMENTATION.md +3 -1
- package/server/lib/git/routes.js +16 -0
- package/server/lib/git/service.js +97 -17
- package/server/lib/git/service.test.js +153 -0
- package/server/lib/linear/DOCUMENTATION.md +97 -0
- package/server/lib/linear/OAUTH-BROKER-HANDOFF.md +91 -0
- package/server/lib/linear/auth.js +436 -0
- package/server/lib/linear/auth.test.js +242 -0
- package/server/lib/linear/client.js +191 -0
- package/server/lib/linear/index.js +61 -0
- package/server/lib/linear/issues.js +499 -0
- package/server/lib/linear/issues.test.js +512 -0
- package/server/lib/linear/mapping.js +188 -0
- package/server/lib/linear/mapping.test.js +147 -0
- package/server/lib/linear/oauth.js +345 -0
- package/server/lib/linear/oauth.test.js +166 -0
- package/server/lib/linear/parse.js +23 -0
- package/server/lib/linear/routes.js +432 -0
- package/server/lib/linear/routes.test.js +661 -0
- package/server/lib/linear/status-runtime.js +64 -0
- package/server/lib/linear/status-runtime.test.js +167 -0
- package/server/lib/linear/status.js +280 -0
- package/server/lib/linear/status.test.js +271 -0
- package/server/lib/linear/teams.js +72 -0
- package/server/lib/linear/teams.test.js +94 -0
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
- package/server/lib/mcp-reconnect/runtime.js +122 -0
- package/server/lib/mcp-reconnect/runtime.test.js +140 -0
- package/server/lib/message-queue/DOCUMENTATION.md +148 -0
- package/server/lib/message-queue/runtime.js +818 -0
- package/server/lib/message-queue/runtime.test.js +426 -0
- package/server/lib/openchamber-sessions/routes.js +102 -0
- package/server/lib/openchamber-sessions/routes.test.js +88 -0
- package/server/lib/opencode/DOCUMENTATION.md +5 -1
- package/server/lib/opencode/core-routes.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.js +5 -0
- package/server/lib/opencode/managed-plugin-config.js +35 -0
- package/server/lib/opencode/settings-runtime.js +2 -2
- package/server/lib/opencode/settings-runtime.test.js +29 -0
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/static-routes-runtime.js +3 -3
- package/server/lib/projects/project-config.js +33 -5
- package/server/lib/projects/project-config.test.js +85 -0
- package/server/lib/quota/DOCUMENTATION.md +2 -1
- package/server/lib/quota/credentials/providers.js +4 -0
- package/server/lib/quota/credentials/store.js +1 -1
- package/server/lib/quota/credentials/store.test.js +4 -4
- package/server/lib/quota/providers/exe-dev.js +75 -0
- package/server/lib/quota/providers/exe-dev.test.js +47 -0
- package/server/lib/quota/providers/index.js +7 -0
- package/server/lib/quota/providers/opencode-go.js +1 -0
- package/server/lib/quota/providers/opencode-go.test.js +5 -1
- package/server/lib/quota/routes.js +2 -0
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/relay/tunnel-host.js +3 -1
- package/server/lib/relay/tunnel-host.test.js +9 -1
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
- package/server/lib/security/request-security.js +21 -6
- package/server/lib/security/request-security.test.js +42 -8
- package/server/lib/session-assist/runtime.js +1 -0
- package/server/lib/session-goal/create.js +3 -1
- package/server/lib/session-goal/runtime.js +1 -0
- package/server/lib/small-model/DOCUMENTATION.md +4 -0
- package/server/lib/small-model/call.js +8 -2
- package/server/lib/small-model/call.test.js +23 -0
- package/server/lib/small-model/index.js +2 -1
- package/server/lib/small-model/routes.js +2 -1
- package/server/lib/system-prompt/runtime.js +2 -21
- package/server/lib/terminal/runtime.js +30 -7
- package/server/lib/tts/DOCUMENTATION.md +1 -0
- package/server/lib/tts/language-detect.js +210 -0
- package/server/lib/tts/language-detect.test.js +76 -0
- package/server/lib/tts/routes.js +23 -1
- package/server/lib/tts/routes.test.js +26 -0
- package/server/lib/ui-auth/ui-auth.js +4 -1
- package/server/lib/ui-auth/ui-auth.test.js +16 -0
- package/server/lib/walkthrough/index.js +1 -0
- package/dist/assets/CommitSection-DwGiXyjf.js +0 -1
- package/dist/assets/DiffView-Db6bjVv1.js +0 -4
- package/dist/assets/FilesView-DQOa7Lgz.js +0 -17
- package/dist/assets/GitView-CHzJxTi0.js +0 -6
- package/dist/assets/MarkdownImageGallery-DoZpaHev.js +0 -1
- package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +0 -12
- package/dist/assets/OnboardingScreen-C98d69Fp.js +0 -1
- package/dist/assets/SettingsView-D-K3ELCM.js +0 -28
- package/dist/assets/ToolPartDiffPreview-C7kBQNAA.js +0 -8
- package/dist/assets/WalkthroughView-MuJodAHD.js +0 -4
- package/dist/assets/es-DwyXCqaL.js +0 -15
- package/dist/assets/index-CUKcHnUA.css +0 -1
- package/dist/assets/index-DIvDEKE-.js +0 -7
- package/dist/assets/main-DLlfDjQ_.js +0 -926
- package/dist/assets/markdownCore-CcTcLsQF.js +0 -3
- package/dist/assets/pt-BR-DxLmkhdv.js +0 -15
- package/dist/assets/renderMobileApp-ltva2Plg.js +0 -25
- package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +0 -15
- package/dist/assets/scheduledTasksApi-mjMDet_H.js +0 -1
- package/dist/assets/tr-5Mk_hQ2Q.js +0 -6
- package/dist/assets/uk-ClgQjmlw.js +0 -15
- package/dist/assets/useInlineCommentController-HIjtuhxD.js +0 -2
- package/dist/assets/useRootScrollLock-BSiQ5F75.js +0 -1
- package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
- package/dist/assets/zh-CN-Ba6y8H-i.js +0 -15
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { setLinearAuth, clearLinearAuth } from './auth.js';
|
|
6
|
+
import { getLinearIssue, listLinearIssues, listLinearIssueStates, parseLinearIssueRef, createLinearIssueComment, updateLinearIssue } from './issues.js';
|
|
7
|
+
|
|
8
|
+
const makeTempDir = () => fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-linear-issues-'));
|
|
9
|
+
|
|
10
|
+
const jsonResponse = (payload, status = 200) => new Response(JSON.stringify(payload), {
|
|
11
|
+
status,
|
|
12
|
+
headers: { 'Content-Type': 'application/json' },
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const issueNode = {
|
|
16
|
+
id: 'issue-uuid-1',
|
|
17
|
+
identifier: 'ENG-12',
|
|
18
|
+
title: 'Broken login',
|
|
19
|
+
url: 'https://linear.app/openchamber/issue/ENG-12',
|
|
20
|
+
priority: 1,
|
|
21
|
+
state: { id: 'state-started', name: 'In Progress', type: 'started' },
|
|
22
|
+
assignee: { name: 'Ada', displayName: 'Ada Lovelace', avatarUrl: 'https://example.com/a.png' },
|
|
23
|
+
team: { id: 'team-eng', key: 'ENG', name: 'Engineering' },
|
|
24
|
+
labels: { nodes: [{ id: 'label-bug', name: 'Bug', color: 'EB5757' }] },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe('parseLinearIssueRef', () => {
|
|
28
|
+
it('reads identifiers, URLs, and UUIDs', () => {
|
|
29
|
+
expect(parseLinearIssueRef('eng-12')).toEqual({ kind: 'identifier', value: 'ENG-12' });
|
|
30
|
+
expect(parseLinearIssueRef('https://linear.app/openchamber/issue/ENG-12/broken-login'))
|
|
31
|
+
.toEqual({ kind: 'identifier', value: 'ENG-12' });
|
|
32
|
+
expect(parseLinearIssueRef('11111111-2222-3333-4444-555555555555'))
|
|
33
|
+
.toEqual({ kind: 'id', value: '11111111-2222-3333-4444-555555555555' });
|
|
34
|
+
expect(parseLinearIssueRef('login redirect')).toBeNull();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('Linear issue list/get', () => {
|
|
39
|
+
let dataDir;
|
|
40
|
+
let previousDataDir;
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
previousDataDir = process.env.OPENCHAMBER_DATA_DIR;
|
|
44
|
+
dataDir = makeTempDir();
|
|
45
|
+
process.env.OPENCHAMBER_DATA_DIR = dataDir;
|
|
46
|
+
setLinearAuth({
|
|
47
|
+
accessToken: 'access-1',
|
|
48
|
+
refreshToken: 'refresh-1',
|
|
49
|
+
tokenType: 'Bearer',
|
|
50
|
+
expiresAt: Date.now() + 86_400_000,
|
|
51
|
+
scope: 'read,write,comments:create',
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
afterEach(() => {
|
|
56
|
+
vi.unstubAllGlobals();
|
|
57
|
+
clearLinearAuth();
|
|
58
|
+
if (previousDataDir === undefined) {
|
|
59
|
+
delete process.env.OPENCHAMBER_DATA_DIR;
|
|
60
|
+
} else {
|
|
61
|
+
process.env.OPENCHAMBER_DATA_DIR = previousDataDir;
|
|
62
|
+
}
|
|
63
|
+
fs.rmSync(dataDir, { recursive: true, force: true });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('returns disconnected without calling Linear when there is no auth', async () => {
|
|
67
|
+
clearLinearAuth();
|
|
68
|
+
const graphql = vi.fn();
|
|
69
|
+
vi.stubGlobal('fetch', graphql);
|
|
70
|
+
await expect(listLinearIssues()).resolves.toEqual({ connected: false });
|
|
71
|
+
expect(graphql).not.toHaveBeenCalled();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('lists incomplete issues and never returns the token', async () => {
|
|
75
|
+
vi.stubGlobal('fetch', vi.fn(async (_url, options) => {
|
|
76
|
+
const body = JSON.parse(options.body);
|
|
77
|
+
expect(body.query).toContain('query ListLinearIssues');
|
|
78
|
+
expect(body.variables.filter.state.type.nin).toEqual(['completed', 'canceled', 'duplicate']);
|
|
79
|
+
expect(options.headers.Authorization).toBe('Bearer access-1');
|
|
80
|
+
expect(options.headers['public-file-urls-expire-in']).toBe('3600');
|
|
81
|
+
return jsonResponse({
|
|
82
|
+
data: {
|
|
83
|
+
issues: {
|
|
84
|
+
nodes: [issueNode],
|
|
85
|
+
pageInfo: { hasNextPage: true, endCursor: 'cursor-2' },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}));
|
|
90
|
+
|
|
91
|
+
const result = await listLinearIssues();
|
|
92
|
+
expect(result).toEqual({
|
|
93
|
+
connected: true,
|
|
94
|
+
issues: [{
|
|
95
|
+
id: 'issue-uuid-1',
|
|
96
|
+
identifier: 'ENG-12',
|
|
97
|
+
title: 'Broken login',
|
|
98
|
+
url: 'https://linear.app/openchamber/issue/ENG-12',
|
|
99
|
+
state: { id: 'state-started', name: 'In Progress', type: 'started' },
|
|
100
|
+
assignee: { name: 'Ada', displayName: 'Ada Lovelace', avatarUrl: 'https://example.com/a.png' },
|
|
101
|
+
team: { id: 'team-eng', key: 'ENG', name: 'Engineering' },
|
|
102
|
+
priority: 1,
|
|
103
|
+
labels: [{ id: 'label-bug', name: 'Bug', color: '#eb5757' }],
|
|
104
|
+
}],
|
|
105
|
+
cursor: 'cursor-2',
|
|
106
|
+
hasMore: true,
|
|
107
|
+
});
|
|
108
|
+
expect(JSON.stringify(result)).not.toContain('access-1');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('includes priority and labels and drops invalid values', async () => {
|
|
112
|
+
vi.stubGlobal('fetch', vi.fn(async () => jsonResponse({
|
|
113
|
+
data: {
|
|
114
|
+
issues: {
|
|
115
|
+
nodes: [{
|
|
116
|
+
...issueNode,
|
|
117
|
+
priority: 9,
|
|
118
|
+
labels: {
|
|
119
|
+
nodes: [
|
|
120
|
+
{ id: 'label-ok', name: 'Bug', color: '#EB5757' },
|
|
121
|
+
{ id: 'label-bad-color', name: 'Nope', color: 'red' },
|
|
122
|
+
{ id: '', name: 'Missing id' },
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
}],
|
|
126
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
})));
|
|
130
|
+
|
|
131
|
+
const result = await listLinearIssues();
|
|
132
|
+
expect(result.issues?.[0]?.priority).toBeNull();
|
|
133
|
+
expect(result.issues?.[0]?.labels).toEqual([
|
|
134
|
+
{ id: 'label-ok', name: 'Bug', color: '#eb5757' },
|
|
135
|
+
{ id: 'label-bad-color', name: 'Nope', color: null },
|
|
136
|
+
]);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('searches by text and looks up an identifier directly', async () => {
|
|
140
|
+
const graphql = vi.fn(async (_url, options) => {
|
|
141
|
+
const body = JSON.parse(options.body);
|
|
142
|
+
if (body.query.includes('SearchLinearIssues')) {
|
|
143
|
+
expect(body.variables.term).toBe('login');
|
|
144
|
+
return jsonResponse({
|
|
145
|
+
data: {
|
|
146
|
+
searchIssues: {
|
|
147
|
+
nodes: [issueNode],
|
|
148
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
expect(body.variables.id).toBe('ENG-12');
|
|
154
|
+
return jsonResponse({
|
|
155
|
+
data: {
|
|
156
|
+
issue: {
|
|
157
|
+
...issueNode,
|
|
158
|
+
description: 'Users cannot sign in.',
|
|
159
|
+
comments: {
|
|
160
|
+
nodes: [{
|
|
161
|
+
id: 'comment-1',
|
|
162
|
+
body: 'Still broken',
|
|
163
|
+
createdAt: '2026-08-24T10:00:00.000Z',
|
|
164
|
+
user: { name: 'Ada', displayName: 'Ada Lovelace' },
|
|
165
|
+
}],
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
vi.stubGlobal('fetch', graphql);
|
|
172
|
+
|
|
173
|
+
const search = await listLinearIssues({ query: 'login' });
|
|
174
|
+
expect(search.issues).toHaveLength(1);
|
|
175
|
+
expect(search.hasMore).toBe(false);
|
|
176
|
+
|
|
177
|
+
const byId = await listLinearIssues({ query: 'https://linear.app/openchamber/issue/ENG-12' });
|
|
178
|
+
expect(byId.issues?.[0]?.identifier).toBe('ENG-12');
|
|
179
|
+
expect(byId.hasMore).toBe(false);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('applies status, assignee, team, and priority list filters', async () => {
|
|
183
|
+
vi.stubGlobal('fetch', vi.fn(async (_url, options) => {
|
|
184
|
+
const body = JSON.parse(options.body);
|
|
185
|
+
expect(body.variables.filter).toEqual({
|
|
186
|
+
state: { type: { eq: 'started' }, name: { neqIgnoreCase: 'In Review' } },
|
|
187
|
+
assignee: { isMe: { eq: true } },
|
|
188
|
+
team: { id: { eq: 'team-eng' } },
|
|
189
|
+
priority: { eq: 1 },
|
|
190
|
+
});
|
|
191
|
+
return jsonResponse({
|
|
192
|
+
data: {
|
|
193
|
+
issues: {
|
|
194
|
+
nodes: [issueNode],
|
|
195
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
}));
|
|
200
|
+
|
|
201
|
+
const result = await listLinearIssues({
|
|
202
|
+
status: 'started',
|
|
203
|
+
assignee: 'me',
|
|
204
|
+
teamId: 'team-eng',
|
|
205
|
+
priority: 'urgent',
|
|
206
|
+
});
|
|
207
|
+
expect(result.issues).toHaveLength(1);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('filters each panel status to a Linear state type or name', async () => {
|
|
211
|
+
const filters = [];
|
|
212
|
+
vi.stubGlobal('fetch', vi.fn(async (_url, options) => {
|
|
213
|
+
filters.push(JSON.parse(options.body).variables.filter);
|
|
214
|
+
return jsonResponse({
|
|
215
|
+
data: {
|
|
216
|
+
issues: {
|
|
217
|
+
nodes: [issueNode],
|
|
218
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
}));
|
|
223
|
+
|
|
224
|
+
await listLinearIssues({ status: 'todo' });
|
|
225
|
+
await listLinearIssues({ status: 'backlog' });
|
|
226
|
+
await listLinearIssues({ status: 'started' });
|
|
227
|
+
await listLinearIssues({ status: 'inReview' });
|
|
228
|
+
await listLinearIssues({ status: 'completed' });
|
|
229
|
+
await listLinearIssues({ status: 'canceled' });
|
|
230
|
+
await listLinearIssues({ status: 'duplicate' });
|
|
231
|
+
expect(filters).toEqual([
|
|
232
|
+
{ state: { type: { eq: 'unstarted' } } },
|
|
233
|
+
{ state: { type: { eq: 'backlog' } } },
|
|
234
|
+
{ state: { type: { eq: 'started' }, name: { neqIgnoreCase: 'In Review' } } },
|
|
235
|
+
{ state: { name: { eqIgnoreCase: 'In Review' } } },
|
|
236
|
+
{ state: { type: { eq: 'completed' } } },
|
|
237
|
+
{ state: { type: { eq: 'canceled' }, name: { neqIgnoreCase: 'Duplicate' } } },
|
|
238
|
+
{ state: { or: [{ type: { eq: 'duplicate' } }, { name: { eqIgnoreCase: 'Duplicate' } }] } },
|
|
239
|
+
]);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('omits the state filter when listing all issues', async () => {
|
|
243
|
+
vi.stubGlobal('fetch', vi.fn(async (_url, options) => {
|
|
244
|
+
const body = JSON.parse(options.body);
|
|
245
|
+
expect(body.variables.filter).toBeUndefined();
|
|
246
|
+
return jsonResponse({
|
|
247
|
+
data: {
|
|
248
|
+
issues: {
|
|
249
|
+
nodes: [issueNode],
|
|
250
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
}));
|
|
255
|
+
|
|
256
|
+
await listLinearIssues({ status: 'all' });
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('filters no-priority issues as Linear priority 0', async () => {
|
|
260
|
+
vi.stubGlobal('fetch', vi.fn(async (_url, options) => {
|
|
261
|
+
const body = JSON.parse(options.body);
|
|
262
|
+
expect(body.variables.filter).toEqual({
|
|
263
|
+
priority: { eq: 0 },
|
|
264
|
+
});
|
|
265
|
+
return jsonResponse({
|
|
266
|
+
data: {
|
|
267
|
+
issues: {
|
|
268
|
+
nodes: [issueNode],
|
|
269
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
}));
|
|
274
|
+
|
|
275
|
+
await listLinearIssues({ status: 'all', priority: 'none' });
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('looks up an identifier without applying list filters', async () => {
|
|
279
|
+
vi.stubGlobal('fetch', vi.fn(async (_url, options) => {
|
|
280
|
+
const body = JSON.parse(options.body);
|
|
281
|
+
expect(body.query).toContain('GetLinearIssue');
|
|
282
|
+
expect(body.variables.id).toBe('ENG-12');
|
|
283
|
+
expect(body.variables.filter).toBeUndefined();
|
|
284
|
+
return jsonResponse({ data: { issue: issueNode } });
|
|
285
|
+
}));
|
|
286
|
+
|
|
287
|
+
const result = await listLinearIssues({
|
|
288
|
+
query: 'ENG-12',
|
|
289
|
+
status: 'completed',
|
|
290
|
+
assignee: 'me',
|
|
291
|
+
teamId: 'team-eng',
|
|
292
|
+
priority: 'urgent',
|
|
293
|
+
});
|
|
294
|
+
expect(result.issues?.[0]?.identifier).toBe('ENG-12');
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('loads one issue with comments', async () => {
|
|
298
|
+
vi.stubGlobal('fetch', vi.fn(async () => jsonResponse({
|
|
299
|
+
data: {
|
|
300
|
+
issue: {
|
|
301
|
+
...issueNode,
|
|
302
|
+
description: 'Users cannot sign in.',
|
|
303
|
+
comments: { nodes: [{ id: 'comment-1', body: 'Still broken', createdAt: '2026-08-24T10:00:00.000Z', user: { name: 'Ada', displayName: null, avatarUrl: 'https://linear.app/avatar/ada.png' } }] },
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
})));
|
|
307
|
+
|
|
308
|
+
const result = await getLinearIssue('ENG-12');
|
|
309
|
+
expect(result.connected).toBe(true);
|
|
310
|
+
expect(result.issue?.description).toBe('Users cannot sign in.');
|
|
311
|
+
expect(result.issue?.priority).toBe(1);
|
|
312
|
+
expect(result.issue?.labels).toEqual([{ id: 'label-bug', name: 'Bug', color: '#eb5757' }]);
|
|
313
|
+
expect(result.issue?.comments).toEqual([{
|
|
314
|
+
id: 'comment-1',
|
|
315
|
+
body: 'Still broken',
|
|
316
|
+
createdAt: '2026-08-24T10:00:00.000Z',
|
|
317
|
+
user: { name: 'Ada', displayName: null, avatarUrl: 'https://linear.app/avatar/ada.png' },
|
|
318
|
+
}]);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('creates a comment on the resolved issue UUID', async () => {
|
|
322
|
+
vi.stubGlobal('fetch', vi.fn(async (_url, options) => {
|
|
323
|
+
const body = JSON.parse(options.body);
|
|
324
|
+
if (body.query.includes('query GetLinearIssue')) {
|
|
325
|
+
expect(body.variables.id).toBe('ENG-12');
|
|
326
|
+
return jsonResponse({
|
|
327
|
+
data: {
|
|
328
|
+
issue: {
|
|
329
|
+
...issueNode,
|
|
330
|
+
description: null,
|
|
331
|
+
comments: { nodes: [] },
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
expect(body.query).toContain('mutation CommentCreate');
|
|
337
|
+
expect(body.variables.input).toEqual({
|
|
338
|
+
issueId: 'issue-uuid-1',
|
|
339
|
+
body: 'OpenChamber session started.',
|
|
340
|
+
});
|
|
341
|
+
expect(options.headers.Authorization).toBe('Bearer access-1');
|
|
342
|
+
return jsonResponse({
|
|
343
|
+
data: {
|
|
344
|
+
commentCreate: {
|
|
345
|
+
success: true,
|
|
346
|
+
comment: { id: 'comment-9' },
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
}));
|
|
351
|
+
|
|
352
|
+
const result = await createLinearIssueComment({
|
|
353
|
+
issueId: 'ENG-12',
|
|
354
|
+
body: 'OpenChamber session started.',
|
|
355
|
+
});
|
|
356
|
+
expect(result).toEqual({ connected: true, comment: { id: 'comment-9' } });
|
|
357
|
+
expect(JSON.stringify(result)).not.toContain('access-1');
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it('clears auth and reports disconnected after a GraphQL 401', async () => {
|
|
361
|
+
vi.stubGlobal('fetch', vi.fn(async () => jsonResponse({ errors: [{ message: 'Unauthorized' }] }, 401)));
|
|
362
|
+
await expect(listLinearIssues()).resolves.toEqual({ connected: false });
|
|
363
|
+
await expect(listLinearIssues()).resolves.toEqual({ connected: false });
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it('lists team workflow states in Linear workflow order', async () => {
|
|
367
|
+
vi.stubGlobal('fetch', vi.fn(async (_url, options) => {
|
|
368
|
+
const body = JSON.parse(options.body);
|
|
369
|
+
expect(body.query).toContain('query TeamWorkflowStates');
|
|
370
|
+
expect(body.variables.id).toBe('team-eng');
|
|
371
|
+
expect(options.headers.Authorization).toBe('Bearer access-1');
|
|
372
|
+
return jsonResponse({
|
|
373
|
+
data: {
|
|
374
|
+
team: {
|
|
375
|
+
states: {
|
|
376
|
+
nodes: [
|
|
377
|
+
{ id: 'state-done', name: 'Done', type: 'completed', position: 0 },
|
|
378
|
+
{ id: 'state-review', name: 'In Review', type: 'started', position: 1 },
|
|
379
|
+
{ id: 'state-todo', name: 'Todo', type: 'unstarted', position: 0 },
|
|
380
|
+
{ id: 'state-dup', name: 'Duplicate', type: 'canceled', position: 1 },
|
|
381
|
+
{ id: 'state-progress', name: 'In Progress', type: 'started', position: 0 },
|
|
382
|
+
{ id: 'state-backlog', name: 'Backlog', type: 'backlog', position: 0 },
|
|
383
|
+
{ id: 'state-canceled', name: 'Canceled', type: 'canceled', position: 0 },
|
|
384
|
+
],
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
});
|
|
389
|
+
}));
|
|
390
|
+
|
|
391
|
+
const result = await listLinearIssueStates('team-eng');
|
|
392
|
+
expect(result.states?.map((state) => state.name)).toEqual([
|
|
393
|
+
'Backlog',
|
|
394
|
+
'Todo',
|
|
395
|
+
'In Progress',
|
|
396
|
+
'In Review',
|
|
397
|
+
'Done',
|
|
398
|
+
'Canceled',
|
|
399
|
+
'Duplicate',
|
|
400
|
+
]);
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it('rejects workflow states without a team id', async () => {
|
|
404
|
+
await expect(listLinearIssueStates('')).rejects.toMatchObject({
|
|
405
|
+
message: 'teamId is required',
|
|
406
|
+
code: 'INVALID',
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it('updates an issue state and returns the issue', async () => {
|
|
411
|
+
vi.stubGlobal('fetch', vi.fn(async (_url, options) => {
|
|
412
|
+
const body = JSON.parse(options.body);
|
|
413
|
+
expect(body.query).toContain('mutation IssueUpdate');
|
|
414
|
+
expect(body.variables).toEqual({
|
|
415
|
+
id: 'issue-uuid-1',
|
|
416
|
+
input: { stateId: 'state-done' },
|
|
417
|
+
});
|
|
418
|
+
expect(options.headers.Authorization).toBe('Bearer access-1');
|
|
419
|
+
return jsonResponse({
|
|
420
|
+
data: {
|
|
421
|
+
issueUpdate: {
|
|
422
|
+
success: true,
|
|
423
|
+
issue: {
|
|
424
|
+
...issueNode,
|
|
425
|
+
state: { id: 'state-done', name: 'Done', type: 'completed' },
|
|
426
|
+
description: null,
|
|
427
|
+
comments: { nodes: [] },
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
});
|
|
432
|
+
}));
|
|
433
|
+
|
|
434
|
+
const result = await updateLinearIssue({ id: 'issue-uuid-1', stateId: 'state-done' });
|
|
435
|
+
expect(result.connected).toBe(true);
|
|
436
|
+
expect(result.issue?.state).toEqual({ id: 'state-done', name: 'Done', type: 'completed' });
|
|
437
|
+
expect(JSON.stringify(result)).not.toContain('access-1');
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it('rejects an issue update without id or stateId', async () => {
|
|
441
|
+
await expect(updateLinearIssue({ id: 'issue-uuid-1' })).rejects.toMatchObject({
|
|
442
|
+
message: 'id and stateId are required',
|
|
443
|
+
code: 'INVALID',
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('resolves an issue identifier before issueUpdate', async () => {
|
|
448
|
+
vi.stubGlobal('fetch', vi.fn(async (_url, options) => {
|
|
449
|
+
const body = JSON.parse(options.body);
|
|
450
|
+
if (body.query.includes('query GetLinearIssue')) {
|
|
451
|
+
expect(body.variables.id).toBe('ENG-12');
|
|
452
|
+
return jsonResponse({
|
|
453
|
+
data: {
|
|
454
|
+
issue: {
|
|
455
|
+
...issueNode,
|
|
456
|
+
description: null,
|
|
457
|
+
comments: { nodes: [] },
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
expect(body.query).toContain('mutation IssueUpdate');
|
|
463
|
+
expect(body.variables).toEqual({
|
|
464
|
+
id: 'issue-uuid-1',
|
|
465
|
+
input: { stateId: 'state-done' },
|
|
466
|
+
});
|
|
467
|
+
return jsonResponse({
|
|
468
|
+
data: {
|
|
469
|
+
issueUpdate: {
|
|
470
|
+
success: true,
|
|
471
|
+
issue: {
|
|
472
|
+
...issueNode,
|
|
473
|
+
state: { id: 'state-done', name: 'Done', type: 'completed' },
|
|
474
|
+
description: null,
|
|
475
|
+
comments: { nodes: [] },
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
},
|
|
479
|
+
});
|
|
480
|
+
}));
|
|
481
|
+
|
|
482
|
+
const result = await updateLinearIssue({ id: 'ENG-12', stateId: 'state-done' });
|
|
483
|
+
expect(result.connected).toBe(true);
|
|
484
|
+
expect(result.issue?.id).toBe('issue-uuid-1');
|
|
485
|
+
expect(result.issue?.state).toEqual({ id: 'state-done', name: 'Done', type: 'completed' });
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it('surfaces Linear validation constraints from GraphQL errors', async () => {
|
|
489
|
+
vi.stubGlobal('fetch', vi.fn(async () => jsonResponse({
|
|
490
|
+
data: null,
|
|
491
|
+
errors: [{
|
|
492
|
+
message: 'Argument Validation Error',
|
|
493
|
+
extensions: {
|
|
494
|
+
code: 'INVALID_INPUT',
|
|
495
|
+
userError: true,
|
|
496
|
+
userPresentableMessage: 'stateId must be a UUID.',
|
|
497
|
+
validationErrors: [{
|
|
498
|
+
property: 'stateId',
|
|
499
|
+
constraints: { isUuid: 'stateId must be a UUID.' },
|
|
500
|
+
}],
|
|
501
|
+
},
|
|
502
|
+
}],
|
|
503
|
+
})));
|
|
504
|
+
|
|
505
|
+
await expect(updateLinearIssue({ id: 'issue-uuid-1', stateId: 'not-a-uuid' })).rejects.toMatchObject({
|
|
506
|
+
name: 'LinearApiError',
|
|
507
|
+
message: 'stateId must be a UUID.',
|
|
508
|
+
status: 400,
|
|
509
|
+
userError: true,
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getLinearAuth, getLinearAuthFilePath } from './auth.js';
|
|
4
|
+
import { isPlainObject, readTrimmedString } from './parse.js';
|
|
5
|
+
|
|
6
|
+
export class LinearMappingError extends Error {
|
|
7
|
+
constructor(message, code) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'LinearMappingError';
|
|
10
|
+
this.code = code;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function mappingFile() {
|
|
15
|
+
return path.join(path.dirname(getLinearAuthFilePath()), 'linear-mapping.json');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const UNSCOPED_MAPPING_KEY = '__unscoped__';
|
|
19
|
+
|
|
20
|
+
function mappingOrgKey() {
|
|
21
|
+
const auth = getLinearAuth();
|
|
22
|
+
return readTrimmedString(auth?.workspaceId) || UNSCOPED_MAPPING_KEY;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function emptyMapping() {
|
|
26
|
+
return {
|
|
27
|
+
defaultProjectPath: null,
|
|
28
|
+
teamProjectPaths: {},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function readTeamProjectPaths(value) {
|
|
33
|
+
if (!isPlainObject(value)) {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
const next = {};
|
|
37
|
+
for (const key of Object.keys(value)) {
|
|
38
|
+
const teamId = readTrimmedString(key);
|
|
39
|
+
const projectPath = readTrimmedString(value[key]);
|
|
40
|
+
if (teamId && projectPath) {
|
|
41
|
+
next[teamId] = projectPath;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return next;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function normalizeMappingSlice(raw) {
|
|
48
|
+
if (!isPlainObject(raw)) {
|
|
49
|
+
return emptyMapping();
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
defaultProjectPath: readTrimmedString(raw.defaultProjectPath) || null,
|
|
53
|
+
teamProjectPaths: readTeamProjectPaths(raw.teamProjectPaths),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function readMappingDocument(raw) {
|
|
58
|
+
if (!isPlainObject(raw)) {
|
|
59
|
+
return { workspaces: {} };
|
|
60
|
+
}
|
|
61
|
+
if (isPlainObject(raw.workspaces)) {
|
|
62
|
+
const workspaces = {};
|
|
63
|
+
for (const key of Object.keys(raw.workspaces)) {
|
|
64
|
+
const orgKey = readTrimmedString(key);
|
|
65
|
+
if (!orgKey) continue;
|
|
66
|
+
workspaces[orgKey] = normalizeMappingSlice(raw.workspaces[key]);
|
|
67
|
+
}
|
|
68
|
+
return { workspaces };
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
workspaces: {
|
|
72
|
+
[mappingOrgKey()]: normalizeMappingSlice(raw),
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function writeJsonFile(filePath, payload) {
|
|
78
|
+
const dir = path.dirname(filePath);
|
|
79
|
+
if (!fs.existsSync(dir)) {
|
|
80
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
81
|
+
}
|
|
82
|
+
const tmpFile = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
83
|
+
fs.writeFileSync(tmpFile, JSON.stringify(payload, null, 2), 'utf8');
|
|
84
|
+
try {
|
|
85
|
+
fs.chmodSync(tmpFile, 0o600);
|
|
86
|
+
} catch {
|
|
87
|
+
// best-effort
|
|
88
|
+
}
|
|
89
|
+
fs.renameSync(tmpFile, filePath);
|
|
90
|
+
try {
|
|
91
|
+
fs.chmodSync(filePath, 0o600);
|
|
92
|
+
} catch {
|
|
93
|
+
// best-effort
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function getLinearMappingFilePath() {
|
|
98
|
+
return mappingFile();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function readStoredLinearMapping() {
|
|
102
|
+
const filePath = mappingFile();
|
|
103
|
+
if (!fs.existsSync(filePath)) {
|
|
104
|
+
return emptyMapping();
|
|
105
|
+
}
|
|
106
|
+
let parsed;
|
|
107
|
+
try {
|
|
108
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
109
|
+
const trimmed = raw.trim();
|
|
110
|
+
if (!trimmed) {
|
|
111
|
+
return emptyMapping();
|
|
112
|
+
}
|
|
113
|
+
parsed = JSON.parse(trimmed);
|
|
114
|
+
} catch {
|
|
115
|
+
throw new LinearMappingError('Linear mapping file is malformed', 'MALFORMED');
|
|
116
|
+
}
|
|
117
|
+
if (!isPlainObject(parsed)) {
|
|
118
|
+
throw new LinearMappingError('Linear mapping file is malformed', 'MALFORMED');
|
|
119
|
+
}
|
|
120
|
+
const document = readMappingDocument(parsed);
|
|
121
|
+
return document.workspaces[mappingOrgKey()] || emptyMapping();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function setStoredLinearMapping(input) {
|
|
125
|
+
if (!isPlainObject(input)) {
|
|
126
|
+
throw new LinearMappingError('Mapping body must be an object', 'INVALID');
|
|
127
|
+
}
|
|
128
|
+
const filePath = mappingFile();
|
|
129
|
+
let document = { workspaces: {} };
|
|
130
|
+
if (fs.existsSync(filePath)) {
|
|
131
|
+
try {
|
|
132
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
133
|
+
const trimmed = raw.trim();
|
|
134
|
+
if (trimmed) {
|
|
135
|
+
const parsed = JSON.parse(trimmed);
|
|
136
|
+
if (!isPlainObject(parsed)) {
|
|
137
|
+
throw new LinearMappingError('Linear mapping file is malformed', 'MALFORMED');
|
|
138
|
+
}
|
|
139
|
+
document = readMappingDocument(parsed);
|
|
140
|
+
}
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (error instanceof LinearMappingError) {
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
throw new LinearMappingError('Linear mapping file is malformed', 'MALFORMED');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const next = {
|
|
149
|
+
defaultProjectPath: readTrimmedString(input.defaultProjectPath) || null,
|
|
150
|
+
teamProjectPaths: readTeamProjectPaths(input.teamProjectPaths),
|
|
151
|
+
};
|
|
152
|
+
document.workspaces[mappingOrgKey()] = next;
|
|
153
|
+
writeJsonFile(filePath, document);
|
|
154
|
+
return next;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function mergeLinearMappingView(stored, teams) {
|
|
158
|
+
const mapping = stored || emptyMapping();
|
|
159
|
+
const nodes = Array.isArray(teams) ? teams : [];
|
|
160
|
+
return {
|
|
161
|
+
defaultProjectPath: mapping.defaultProjectPath,
|
|
162
|
+
teams: nodes.map((team) => ({
|
|
163
|
+
id: team.id,
|
|
164
|
+
key: team.key,
|
|
165
|
+
name: team.name,
|
|
166
|
+
projectPath: mapping.teamProjectPaths[team.id] || null,
|
|
167
|
+
})),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function resolveMappedProjectPath(view, team) {
|
|
172
|
+
const teams = Array.isArray(view?.teams) ? view.teams : [];
|
|
173
|
+
const teamId = team ? readTrimmedString(team.id) : '';
|
|
174
|
+
if (teamId) {
|
|
175
|
+
const row = teams.find((entry) => entry.id === teamId);
|
|
176
|
+
if (row?.projectPath) {
|
|
177
|
+
return row.projectPath;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const teamKey = team ? readTrimmedString(team.key) : '';
|
|
181
|
+
if (teamKey) {
|
|
182
|
+
const row = teams.find((entry) => entry.key === teamKey);
|
|
183
|
+
if (row?.projectPath) {
|
|
184
|
+
return row.projectPath;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return view?.defaultProjectPath || null;
|
|
188
|
+
}
|