@openchamber/web 1.21.1 → 1.22.0
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-CPvfxh0N.js} +1 -1
- package/dist/assets/{CommitSection-DwGiXyjf.js → CommitSection-CC5mFzO2.js} +1 -1
- package/dist/assets/DiffView-6xGdyI0n.js +4 -0
- package/dist/assets/FilesView-Bm3vT63N.js +17 -0
- package/dist/assets/GitView-B6y1Y69c.js +6 -0
- package/dist/assets/{JsonTreeView-CggOsLot.js → JsonTreeView-rwHz84MX.js} +1 -1
- package/dist/assets/LinearIssuesView-B0UM_Rkx.js +1 -0
- package/dist/assets/MarkdownImageGallery-sGilV9Hs.js +1 -0
- package/dist/assets/MarkdownRendererImpl--4sRsKBn.js +12 -0
- package/dist/assets/OnboardingScreen-CECL_Cms.js +1 -0
- package/dist/assets/{PatchDiff-DJYMUiXA.js → PatchDiff-BGPl1s-U.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CY2bx_SB.js → PierreDiffViewer-Cvz9Z-io.js} +3 -3
- package/dist/assets/{PlanView-PkiOY_9H.js → PlanView-BFMsnHk3.js} +4 -4
- package/dist/assets/SettingsView-_Gtn5SdT.js +28 -0
- package/dist/assets/{SettingsWindow-oyOm2fHR.js → SettingsWindow-C1Qa09YO.js} +1 -1
- package/dist/assets/{ToolOutputDialog-lKyeQTPL.js → ToolOutputDialog-DzQlzMF4.js} +5 -5
- package/dist/assets/{ToolPartDiffPreview-C7kBQNAA.js → ToolPartDiffPreview-DfVOfwHy.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-BP7ebDFF.js → VirtualizedFileDiff-DT5MDv-u.js} +1 -1
- package/dist/assets/WalkthroughView-D8sLH_M8.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-CZ0xPeaT.js → computeVirtualFileMetrics-DmpLWhll.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-C9abMBTb.js → contextPanelEmbeddedChat-BK78t3M_.js} +1 -1
- package/dist/assets/{de-CEoCz3j6.js → de-C3luvSd_.js} +4 -4
- package/dist/assets/{es-DwyXCqaL.js → es-CmU4HLv9.js} +3 -3
- package/dist/assets/{fr-CS7Csln9.js → fr-Bgyni40l.js} +4 -4
- package/dist/assets/index-C57jT0Sa.css +1 -0
- package/dist/assets/{index-CaPAjwXQ.js → index-CWYs7sMK.js} +1 -1
- package/dist/assets/index-b0zDkWyg.js +7 -0
- package/dist/assets/{isDiffPlainText-ZBvDxhVB.js → isDiffPlainText-BO_q5ezD.js} +1 -1
- package/dist/assets/{isFilePlainText-DiLRrkJr.js → isFilePlainText-D8qPqUAf.js} +1 -1
- package/dist/assets/{ja-vnwqLcx6.js → ja-C1ImKinT.js} +4 -4
- package/dist/assets/{ko-CXuSfZv5.js → ko-CP7OdxYH.js} +4 -4
- package/dist/assets/main-D4rd8Hy5.js +928 -0
- package/dist/assets/{main-D5RWr6sJ.js → main-D7fwjW2z.js} +2 -2
- package/dist/assets/markdownCore-BcmkWZPO.js +3 -0
- package/dist/assets/{miniChat-CqR3icsk.js → miniChat-D5rraz-g.js} +2 -2
- package/dist/assets/{mobile-RN_UTTlB.js → mobile-Cg_DE3KL.js} +2 -2
- package/dist/assets/{patchFileDiff-CjRR5ESs.js → patchFileDiff-Bpql0QGw.js} +3 -3
- package/dist/assets/{pl-BJxry0Mi.js → pl-DQYSiGYX.js} +4 -4
- package/dist/assets/{pt-BR-DxLmkhdv.js → pt-BR-DytpsW4M.js} +3 -3
- package/dist/assets/{renderElectronMiniChatApp-1wC94fQK.js → renderElectronMiniChatApp-B_Bn7BbN.js} +2 -2
- package/dist/assets/renderMobileApp-DLfxMzGJ.js +25 -0
- package/dist/assets/runtimeEndpointReset-HlRmXFGW.js +16 -0
- package/dist/assets/scheduledTasksApi-BPvxrynl.js +1 -0
- package/dist/assets/{shikiHighlight-fGmFkxAM.js → shikiHighlight-CFAVs_lu.js} +1 -1
- package/dist/assets/tr-aizaUvft.js +6 -0
- package/dist/assets/{uk-ClgQjmlw.js → uk-DwnRxJZd.js} +3 -3
- package/dist/assets/{useAppFontEffects-KP8_yiGW.js → useAppFontEffects-DWXGRUPZ.js} +191 -151
- package/dist/assets/useInlineCommentController-Cc0OCXr0.js +2 -0
- package/dist/assets/useRootScrollLock-BFZtfciC.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-DrTPkHl4.js → vendor-codemirror-language-data-BGFszm8n.js} +2 -2
- package/dist/assets/{web-components-DOXvU-tB.js → web-components-CD-GFayc.js} +4 -4
- package/dist/assets/{zh-CN-Ba6y8H-i.js → zh-CN-UDNMxm7r.js} +3 -3
- package/dist/assets/zh-TW-BsswdYL-.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/index.js +4 -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/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/opencode/feature-routes-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/scheduled-tasks/DOCUMENTATION.md +7 -0
- 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/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/WalkthroughView-MuJodAHD.js +0 -4
- 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/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/useInlineCommentController-HIjtuhxD.js +0 -2
- package/dist/assets/useRootScrollLock-BSiQ5F75.js +0 -1
- package/dist/assets/zh-TW-Dv8yyhN1.js +0 -15
|
@@ -0,0 +1,271 @@
|
|
|
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, setLinearSessionCommentsEnabled } from './auth.js';
|
|
6
|
+
import {
|
|
7
|
+
buildLinearSessionOpenUrl,
|
|
8
|
+
buildLinearSessionStatusComment,
|
|
9
|
+
isPublicSessionOrigin,
|
|
10
|
+
postLinearSessionStatus,
|
|
11
|
+
pruneSessionStatusRecords,
|
|
12
|
+
readSessionOrigin,
|
|
13
|
+
} from './status.js';
|
|
14
|
+
|
|
15
|
+
const makeTempDir = () => fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-linear-status-'));
|
|
16
|
+
|
|
17
|
+
const jsonResponse = (payload, status = 200) => new Response(JSON.stringify(payload), {
|
|
18
|
+
status,
|
|
19
|
+
headers: { 'Content-Type': 'application/json' },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const issueNode = {
|
|
23
|
+
id: 'issue-uuid-1',
|
|
24
|
+
identifier: 'ENG-12',
|
|
25
|
+
title: 'Broken login',
|
|
26
|
+
url: 'https://linear.app/openchamber/issue/ENG-12',
|
|
27
|
+
state: { name: 'In Progress', type: 'started' },
|
|
28
|
+
assignee: null,
|
|
29
|
+
team: { id: 'team-eng', key: 'ENG', name: 'Engineering' },
|
|
30
|
+
description: null,
|
|
31
|
+
comments: { nodes: [] },
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function stubLinearGraphql({ commentId = 'comment-1' } = {}) {
|
|
35
|
+
return vi.fn(async (_url, options) => {
|
|
36
|
+
const body = JSON.parse(options.body);
|
|
37
|
+
if (body.query.includes('query GetLinearIssue')) {
|
|
38
|
+
return jsonResponse({ data: { issue: issueNode } });
|
|
39
|
+
}
|
|
40
|
+
if (body.query.includes('mutation CommentCreate')) {
|
|
41
|
+
expect(body.variables.input.issueId).toBe('issue-uuid-1');
|
|
42
|
+
expect(body.variables.input.body).toContain('/?session=ses_1');
|
|
43
|
+
return jsonResponse({
|
|
44
|
+
data: {
|
|
45
|
+
commentCreate: {
|
|
46
|
+
success: true,
|
|
47
|
+
comment: { id: commentId },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
throw new Error(`unexpected query: ${body.query}`);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe('Linear session status comments', () => {
|
|
57
|
+
let dataDir;
|
|
58
|
+
let previousDataDir;
|
|
59
|
+
let previousPort;
|
|
60
|
+
|
|
61
|
+
beforeEach(() => {
|
|
62
|
+
previousDataDir = process.env.OPENCHAMBER_DATA_DIR;
|
|
63
|
+
previousPort = process.env.OPENCHAMBER_PORT;
|
|
64
|
+
dataDir = makeTempDir();
|
|
65
|
+
process.env.OPENCHAMBER_DATA_DIR = dataDir;
|
|
66
|
+
process.env.OPENCHAMBER_PORT = '3001';
|
|
67
|
+
setLinearAuth({
|
|
68
|
+
accessToken: 'access-1',
|
|
69
|
+
refreshToken: 'refresh-1',
|
|
70
|
+
tokenType: 'Bearer',
|
|
71
|
+
expiresAt: Date.now() + 86_400_000,
|
|
72
|
+
scope: 'read,write,comments:create',
|
|
73
|
+
});
|
|
74
|
+
setLinearSessionCommentsEnabled(true);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
afterEach(() => {
|
|
78
|
+
vi.unstubAllGlobals();
|
|
79
|
+
clearLinearAuth();
|
|
80
|
+
if (previousDataDir === undefined) {
|
|
81
|
+
delete process.env.OPENCHAMBER_DATA_DIR;
|
|
82
|
+
} else {
|
|
83
|
+
process.env.OPENCHAMBER_DATA_DIR = previousDataDir;
|
|
84
|
+
}
|
|
85
|
+
if (previousPort === undefined) {
|
|
86
|
+
delete process.env.OPENCHAMBER_PORT;
|
|
87
|
+
} else {
|
|
88
|
+
process.env.OPENCHAMBER_PORT = previousPort;
|
|
89
|
+
}
|
|
90
|
+
fs.rmSync(dataDir, { recursive: true, force: true });
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('reads http(s) origins and rejects other URLs', () => {
|
|
94
|
+
expect(readSessionOrigin('https://app.example.com')).toBe('https://app.example.com');
|
|
95
|
+
expect(readSessionOrigin('http://127.0.0.1:3001/')).toBe('http://127.0.0.1:3001');
|
|
96
|
+
expect(readSessionOrigin('javascript:alert(1)')).toBe('');
|
|
97
|
+
expect(readSessionOrigin('https://app.example.com/secret')).toBe('');
|
|
98
|
+
expect(readSessionOrigin('openchamber:')).toBe('');
|
|
99
|
+
expect(buildLinearSessionOpenUrl('ses_1', 'https://app.example.com'))
|
|
100
|
+
.toBe('https://app.example.com/?session=ses_1');
|
|
101
|
+
expect(buildLinearSessionOpenUrl('ses_1', '')).toBe('');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('treats only externally reachable origins as public', () => {
|
|
105
|
+
expect(isPublicSessionOrigin('https://chamber.example.com')).toBe(true);
|
|
106
|
+
expect(isPublicSessionOrigin('http://chamber.example.com:8080')).toBe(true);
|
|
107
|
+
expect(isPublicSessionOrigin('https://203.0.113.10')).toBe(true);
|
|
108
|
+
|
|
109
|
+
expect(isPublicSessionOrigin('http://localhost:3001')).toBe(false);
|
|
110
|
+
expect(isPublicSessionOrigin('http://127.0.0.1:3001')).toBe(false);
|
|
111
|
+
expect(isPublicSessionOrigin('http://[::1]:3001')).toBe(false);
|
|
112
|
+
expect(isPublicSessionOrigin('http://192.168.1.20:3001')).toBe(false);
|
|
113
|
+
expect(isPublicSessionOrigin('http://10.0.0.5:3001')).toBe(false);
|
|
114
|
+
expect(isPublicSessionOrigin('http://172.20.1.4:3001')).toBe(false);
|
|
115
|
+
expect(isPublicSessionOrigin('http://169.254.10.1:3001')).toBe(false);
|
|
116
|
+
expect(isPublicSessionOrigin('http://100.101.102.103:3001')).toBe(false);
|
|
117
|
+
expect(isPublicSessionOrigin('http://macbook.local:3001')).toBe(false);
|
|
118
|
+
expect(isPublicSessionOrigin('http://macbook:3001')).toBe(false);
|
|
119
|
+
expect(isPublicSessionOrigin('http://[fd00::1]:3001')).toBe(false);
|
|
120
|
+
expect(isPublicSessionOrigin('openchamber:')).toBe(false);
|
|
121
|
+
expect(isPublicSessionOrigin('')).toBe(false);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('posts nothing while session comments are turned off', async () => {
|
|
125
|
+
setLinearSessionCommentsEnabled(false);
|
|
126
|
+
const graphql = vi.fn();
|
|
127
|
+
vi.stubGlobal('fetch', graphql);
|
|
128
|
+
await expect(postLinearSessionStatus({
|
|
129
|
+
kind: 'started',
|
|
130
|
+
sessionId: 'ses_1',
|
|
131
|
+
issueIdentifier: 'ENG-12',
|
|
132
|
+
sessionOrigin: 'https://app.example.com',
|
|
133
|
+
})).resolves.toEqual({ connected: true, posted: false, skipped: 'disabled' });
|
|
134
|
+
expect(graphql).not.toHaveBeenCalled();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('posts nothing when the session origin only the author can reach', async () => {
|
|
138
|
+
const graphql = vi.fn();
|
|
139
|
+
vi.stubGlobal('fetch', graphql);
|
|
140
|
+
await expect(postLinearSessionStatus({
|
|
141
|
+
kind: 'started',
|
|
142
|
+
sessionId: 'ses_1',
|
|
143
|
+
issueIdentifier: 'ENG-12',
|
|
144
|
+
sessionOrigin: 'http://127.0.0.1:3001',
|
|
145
|
+
})).resolves.toEqual({ connected: true, posted: false, skipped: 'origin-not-public' });
|
|
146
|
+
await expect(postLinearSessionStatus({
|
|
147
|
+
kind: 'started',
|
|
148
|
+
sessionId: 'ses_2',
|
|
149
|
+
issueIdentifier: 'ENG-12',
|
|
150
|
+
})).resolves.toEqual({ connected: true, posted: false, skipped: 'origin-not-public' });
|
|
151
|
+
expect(graphql).not.toHaveBeenCalled();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('keeps the newest dedupe records and drops the oldest', () => {
|
|
155
|
+
const records = {};
|
|
156
|
+
for (let index = 0; index < 5; index += 1) {
|
|
157
|
+
records[`ses_${index}`] = { issueIdentifier: 'ENG-12', started: true };
|
|
158
|
+
}
|
|
159
|
+
expect(Object.keys(pruneSessionStatusRecords(records, 3))).toEqual(['ses_2', 'ses_3', 'ses_4']);
|
|
160
|
+
expect(Object.keys(pruneSessionStatusRecords(records, 10))).toHaveLength(5);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('makes the whole status line one link and carries no title', () => {
|
|
164
|
+
expect(buildLinearSessionStatusComment({
|
|
165
|
+
kind: 'started',
|
|
166
|
+
sessionUrl: 'https://app.example.com/?session=ses_1',
|
|
167
|
+
})).toBe('[OpenChamber session started](https://app.example.com/?session=ses_1)');
|
|
168
|
+
expect(buildLinearSessionStatusComment({
|
|
169
|
+
kind: 'completed',
|
|
170
|
+
sessionUrl: 'https://app.example.com/?session=ses_1',
|
|
171
|
+
})).toBe('[OpenChamber session completed](https://app.example.com/?session=ses_1)');
|
|
172
|
+
expect(buildLinearSessionStatusComment({
|
|
173
|
+
kind: 'failure',
|
|
174
|
+
sessionUrl: 'https://app.example.com/?session=ses_1',
|
|
175
|
+
})).toBe('[OpenChamber session failed](https://app.example.com/?session=ses_1)');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('cannot be broken by brackets in the issue title', async () => {
|
|
179
|
+
const graphql = stubLinearGraphql();
|
|
180
|
+
vi.stubGlobal('fetch', graphql);
|
|
181
|
+
await postLinearSessionStatus({
|
|
182
|
+
kind: 'started',
|
|
183
|
+
sessionId: 'ses_1',
|
|
184
|
+
issueIdentifier: 'ENG-12',
|
|
185
|
+
sessionOrigin: 'https://app.example.com',
|
|
186
|
+
});
|
|
187
|
+
const commentCalls = graphql.mock.calls.filter(([, options]) => {
|
|
188
|
+
return JSON.parse(options.body).query.includes('mutation CommentCreate');
|
|
189
|
+
});
|
|
190
|
+
const body = JSON.parse(commentCalls[0][1].body).variables.input.body;
|
|
191
|
+
// One balanced pair of brackets, so a title like "[Bug] …" can never leak in
|
|
192
|
+
// and split the link across the renderer.
|
|
193
|
+
expect(body.match(/\[/g)).toHaveLength(1);
|
|
194
|
+
expect(body.match(/\]/g)).toHaveLength(1);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('returns disconnected without calling Linear when there is no auth', async () => {
|
|
198
|
+
clearLinearAuth();
|
|
199
|
+
const graphql = vi.fn();
|
|
200
|
+
vi.stubGlobal('fetch', graphql);
|
|
201
|
+
await expect(postLinearSessionStatus({
|
|
202
|
+
kind: 'started',
|
|
203
|
+
sessionId: 'ses_1',
|
|
204
|
+
issueIdentifier: 'ENG-12',
|
|
205
|
+
})).resolves.toEqual({ connected: false });
|
|
206
|
+
expect(graphql).not.toHaveBeenCalled();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('posts a started comment once and skips repeats', async () => {
|
|
210
|
+
const graphql = stubLinearGraphql();
|
|
211
|
+
vi.stubGlobal('fetch', graphql);
|
|
212
|
+
|
|
213
|
+
const first = await postLinearSessionStatus({
|
|
214
|
+
kind: 'started',
|
|
215
|
+
sessionId: 'ses_1',
|
|
216
|
+
issueIdentifier: 'ENG-12',
|
|
217
|
+
sessionOrigin: 'https://app.example.com',
|
|
218
|
+
});
|
|
219
|
+
expect(first).toEqual({ connected: true, posted: true, commentId: 'comment-1' });
|
|
220
|
+
|
|
221
|
+
const second = await postLinearSessionStatus({
|
|
222
|
+
kind: 'started',
|
|
223
|
+
sessionId: 'ses_1',
|
|
224
|
+
issueIdentifier: 'ENG-12',
|
|
225
|
+
sessionOrigin: 'https://app.example.com',
|
|
226
|
+
});
|
|
227
|
+
expect(second).toEqual({ connected: true, posted: false, skipped: 'already-posted' });
|
|
228
|
+
|
|
229
|
+
const commentCalls = graphql.mock.calls.filter(([, options]) => {
|
|
230
|
+
return JSON.parse(options.body).query.includes('mutation CommentCreate');
|
|
231
|
+
});
|
|
232
|
+
expect(commentCalls).toHaveLength(1);
|
|
233
|
+
const body = JSON.parse(commentCalls[0][1].body).variables.input.body;
|
|
234
|
+
expect(body).toBe('[OpenChamber session started](https://app.example.com/?session=ses_1)');
|
|
235
|
+
expect(JSON.stringify(first)).not.toContain('access-1');
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('skips completed until started has been posted', async () => {
|
|
239
|
+
const graphql = stubLinearGraphql();
|
|
240
|
+
vi.stubGlobal('fetch', graphql);
|
|
241
|
+
await expect(postLinearSessionStatus({
|
|
242
|
+
kind: 'completed',
|
|
243
|
+
sessionId: 'ses_1',
|
|
244
|
+
})).resolves.toEqual({ connected: true, posted: false, skipped: 'not-started' });
|
|
245
|
+
expect(graphql).not.toHaveBeenCalled();
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('posts completed once after started, reusing the stored open URL', async () => {
|
|
249
|
+
vi.stubGlobal('fetch', stubLinearGraphql({ commentId: 'comment-started' }));
|
|
250
|
+
await postLinearSessionStatus({
|
|
251
|
+
kind: 'started',
|
|
252
|
+
sessionId: 'ses_1',
|
|
253
|
+
issueIdentifier: 'ENG-12',
|
|
254
|
+
sessionOrigin: 'https://app.example.com',
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const graphql = stubLinearGraphql({ commentId: 'comment-done' });
|
|
258
|
+
vi.stubGlobal('fetch', graphql);
|
|
259
|
+
const first = await postLinearSessionStatus({ kind: 'completed', sessionId: 'ses_1' });
|
|
260
|
+
expect(first).toEqual({ connected: true, posted: true, commentId: 'comment-done' });
|
|
261
|
+
const second = await postLinearSessionStatus({ kind: 'completed', sessionId: 'ses_1' });
|
|
262
|
+
expect(second).toEqual({ connected: true, posted: false, skipped: 'already-posted' });
|
|
263
|
+
|
|
264
|
+
const commentCalls = graphql.mock.calls.filter(([, options]) => {
|
|
265
|
+
return JSON.parse(options.body).query.includes('mutation CommentCreate');
|
|
266
|
+
});
|
|
267
|
+
expect(commentCalls).toHaveLength(1);
|
|
268
|
+
const body = JSON.parse(commentCalls[0][1].body).variables.input.body;
|
|
269
|
+
expect(body).toBe('[OpenChamber session completed](https://app.example.com/?session=ses_1)');
|
|
270
|
+
});
|
|
271
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { clearLinearAuth, getLinearAuth } from './auth.js';
|
|
2
|
+
import { fetchLinearGraphql, getValidLinearAccessToken } from './client.js';
|
|
3
|
+
import { isPlainObject, readTrimmedString } from './parse.js';
|
|
4
|
+
|
|
5
|
+
const TEAMS_QUERY = `
|
|
6
|
+
query ListLinearTeams($first: Int!, $after: String) {
|
|
7
|
+
teams(first: $first, after: $after) {
|
|
8
|
+
nodes { id key name }
|
|
9
|
+
pageInfo { hasNextPage endCursor }
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
const PAGE_SIZE = 50;
|
|
14
|
+
const MAX_PAGES = 20;
|
|
15
|
+
|
|
16
|
+
function readTeam(node) {
|
|
17
|
+
if (!isPlainObject(node)) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const id = readTrimmedString(node.id);
|
|
21
|
+
const key = readTrimmedString(node.key);
|
|
22
|
+
const name = readTrimmedString(node.name);
|
|
23
|
+
if (!id || !key || !name) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return { id, key, name };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function listLinearTeams() {
|
|
30
|
+
try {
|
|
31
|
+
const token = await getValidLinearAccessToken();
|
|
32
|
+
if (!token) {
|
|
33
|
+
return { connected: false };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const teams = [];
|
|
37
|
+
let after = null;
|
|
38
|
+
for (let page = 0; page < MAX_PAGES; page += 1) {
|
|
39
|
+
const variables = { first: PAGE_SIZE };
|
|
40
|
+
if (after) {
|
|
41
|
+
variables.after = after;
|
|
42
|
+
}
|
|
43
|
+
const data = await fetchLinearGraphql(token, TEAMS_QUERY, variables);
|
|
44
|
+
const connection = isPlainObject(data.teams) ? data.teams : null;
|
|
45
|
+
const nodes = isPlainObject(connection) && Array.isArray(connection.nodes)
|
|
46
|
+
? connection.nodes
|
|
47
|
+
: [];
|
|
48
|
+
for (const node of nodes) {
|
|
49
|
+
const team = readTeam(node);
|
|
50
|
+
if (team) {
|
|
51
|
+
teams.push(team);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const pageInfo = isPlainObject(connection) ? connection.pageInfo : null;
|
|
55
|
+
if (!isPlainObject(pageInfo) || pageInfo.hasNextPage !== true) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
after = readTrimmedString(pageInfo.endCursor);
|
|
59
|
+
if (!after) {
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return { connected: true, teams };
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (error?.status === 401) {
|
|
67
|
+
clearLinearAuth(getLinearAuth()?.workspaceId);
|
|
68
|
+
return { connected: false };
|
|
69
|
+
}
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
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 { clearLinearAuth, setLinearAuth } from './auth.js';
|
|
6
|
+
import { listLinearTeams } from './teams.js';
|
|
7
|
+
|
|
8
|
+
const makeTempDir = () => fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-linear-teams-'));
|
|
9
|
+
|
|
10
|
+
const jsonResponse = (payload, status = 200) => new Response(JSON.stringify(payload), {
|
|
11
|
+
status,
|
|
12
|
+
headers: { 'Content-Type': 'application/json' },
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('Linear teams list', () => {
|
|
16
|
+
let dataDir;
|
|
17
|
+
let previousDataDir;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
previousDataDir = process.env.OPENCHAMBER_DATA_DIR;
|
|
21
|
+
dataDir = makeTempDir();
|
|
22
|
+
process.env.OPENCHAMBER_DATA_DIR = dataDir;
|
|
23
|
+
setLinearAuth({
|
|
24
|
+
accessToken: 'access-1',
|
|
25
|
+
refreshToken: 'refresh-1',
|
|
26
|
+
tokenType: 'Bearer',
|
|
27
|
+
expiresAt: Date.now() + 86_400_000,
|
|
28
|
+
scope: 'read,write,comments:create',
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
vi.unstubAllGlobals();
|
|
34
|
+
clearLinearAuth();
|
|
35
|
+
if (previousDataDir === undefined) {
|
|
36
|
+
delete process.env.OPENCHAMBER_DATA_DIR;
|
|
37
|
+
} else {
|
|
38
|
+
process.env.OPENCHAMBER_DATA_DIR = previousDataDir;
|
|
39
|
+
}
|
|
40
|
+
fs.rmSync(dataDir, { recursive: true, force: true });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('returns disconnected without calling Linear when there is no auth', async () => {
|
|
44
|
+
clearLinearAuth();
|
|
45
|
+
const graphql = vi.fn();
|
|
46
|
+
vi.stubGlobal('fetch', graphql);
|
|
47
|
+
await expect(listLinearTeams()).resolves.toEqual({ connected: false });
|
|
48
|
+
expect(graphql).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('lists teams across pages and never returns the token', async () => {
|
|
52
|
+
const graphql = vi.fn(async (_url, options) => {
|
|
53
|
+
const body = JSON.parse(options.body);
|
|
54
|
+
expect(body.query).toContain('query ListLinearTeams');
|
|
55
|
+
expect(options.headers.Authorization).toBe('Bearer access-1');
|
|
56
|
+
if (!body.variables.after) {
|
|
57
|
+
return jsonResponse({
|
|
58
|
+
data: {
|
|
59
|
+
teams: {
|
|
60
|
+
nodes: [{ id: 'team-eng', key: 'ENG', name: 'Engineering' }],
|
|
61
|
+
pageInfo: { hasNextPage: true, endCursor: 'cursor-2' },
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
expect(body.variables.after).toBe('cursor-2');
|
|
67
|
+
return jsonResponse({
|
|
68
|
+
data: {
|
|
69
|
+
teams: {
|
|
70
|
+
nodes: [{ id: 'team-des', key: 'DES', name: 'Design' }],
|
|
71
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
vi.stubGlobal('fetch', graphql);
|
|
77
|
+
|
|
78
|
+
const result = await listLinearTeams();
|
|
79
|
+
expect(result).toEqual({
|
|
80
|
+
connected: true,
|
|
81
|
+
teams: [
|
|
82
|
+
{ id: 'team-eng', key: 'ENG', name: 'Engineering' },
|
|
83
|
+
{ id: 'team-des', key: 'DES', name: 'Design' },
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
expect(JSON.stringify(result)).not.toContain('access-1');
|
|
87
|
+
expect(graphql).toHaveBeenCalledTimes(2);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('clears auth and reports disconnected after a GraphQL 401', async () => {
|
|
91
|
+
vi.stubGlobal('fetch', vi.fn(async () => jsonResponse({ errors: [{ message: 'Unauthorized' }] }, 401)));
|
|
92
|
+
await expect(listLinearTeams()).resolves.toEqual({ connected: false });
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -4,6 +4,7 @@ import { registerSmallModelRoutes } from '../small-model/routes.js';
|
|
|
4
4
|
import { registerWalkthroughRoutes } from '../walkthrough/routes.js';
|
|
5
5
|
import { registerSessionGoalRoutes } from '../session-goal/routes.js';
|
|
6
6
|
import { registerGitHubRoutes } from '../github/routes.js';
|
|
7
|
+
import { registerLinearRoutes } from '../linear/routes.js';
|
|
7
8
|
import { registerGitRoutes } from '../git/routes.js';
|
|
8
9
|
import { registerDevServerRoutes } from '../dev-servers/routes.js';
|
|
9
10
|
import { registerMagicPromptRoutes } from '../magic-prompts/routes.js';
|
|
@@ -300,6 +301,7 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
300
301
|
registerWalkthroughRoutes(app, { getWalkthroughService });
|
|
301
302
|
registerSessionGoalRoutes(app);
|
|
302
303
|
registerGitHubRoutes(app);
|
|
304
|
+
registerLinearRoutes(app);
|
|
303
305
|
registerGitRoutes(app);
|
|
304
306
|
registerDevServerRoutes(app, { scanner: devServerScanner, getOwnPorts });
|
|
305
307
|
registerMagicPromptRoutes(app, {
|
|
@@ -47,20 +47,20 @@ export const createStaticRoutesRuntime = (dependencies) => {
|
|
|
47
47
|
normalizePwaOrientation,
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
app.get(/^(?!\/api|.*\.(js|css|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|map)).*$/, (_req, res) => {
|
|
50
|
+
app.get(/^(?!\/api|\/linear|.*\.(js|css|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|map)).*$/, (_req, res) => {
|
|
51
51
|
res.sendFile(path.join(distPath, 'index.html'));
|
|
52
52
|
});
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
console.warn(`Warning: ${distPath} not found, static files will not be served`);
|
|
57
|
-
app.get(/^(?!\/api|.*\.(js|css|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|map)).*$/, (_req, res) => {
|
|
57
|
+
app.get(/^(?!\/api|\/linear|.*\.(js|css|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|map)).*$/, (_req, res) => {
|
|
58
58
|
res.status(404).send('Static files not found. Please build the application first.');
|
|
59
59
|
});
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
const registerApiOnlyFallbackRoutes = (app) => {
|
|
63
|
-
app.get(/^(?!\/api|\/auth|\/health|.*\.(js|css|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|map)).*$/, (req, res) => {
|
|
63
|
+
app.get(/^(?!\/api|\/auth|\/health|\/linear|.*\.(js|css|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|map)).*$/, (req, res) => {
|
|
64
64
|
const command = 'openchamber connect-url --help';
|
|
65
65
|
res.status(200).format({
|
|
66
66
|
html: () => {
|
|
@@ -499,11 +499,20 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
499
499
|
}
|
|
500
500
|
};
|
|
501
501
|
|
|
502
|
+
// Normalized tasks for reading, plus the raw on-disk record of each one for
|
|
503
|
+
// writing back. Normalization only keeps the fields THIS build knows, so a
|
|
504
|
+
// write that re-serialized normalized tasks would strip every field added
|
|
505
|
+
// by a newer build (or a newer UI) the moment an older server touched the
|
|
506
|
+
// file — a goal or auto-accept setting silently lost after a task ran.
|
|
507
|
+
// Writers therefore persist untouched tasks from `rawTasksByID` verbatim and
|
|
508
|
+
// only serialize a normalized task where the task itself was deliberately
|
|
509
|
+
// replaced.
|
|
502
510
|
const readProjectConfigFromDisk = async (projectID) => {
|
|
503
511
|
const parsed = await readRawProjectConfigFromDisk(projectID);
|
|
504
512
|
const tasksRaw = Array.isArray(parsed.scheduledTasks) ? parsed.scheduledTasks : [];
|
|
505
513
|
const now = Date.now();
|
|
506
514
|
const scheduledTasks = [];
|
|
515
|
+
const rawTasksByID = new Map();
|
|
507
516
|
for (const task of tasksRaw) {
|
|
508
517
|
try {
|
|
509
518
|
const normalized = normalizeTaskForStorage(task, {
|
|
@@ -514,15 +523,31 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
514
523
|
refreshUpdatedAt: false,
|
|
515
524
|
});
|
|
516
525
|
scheduledTasks.push(normalized);
|
|
526
|
+
rawTasksByID.set(normalized.id, task);
|
|
517
527
|
} catch {
|
|
518
528
|
}
|
|
519
529
|
}
|
|
520
530
|
return {
|
|
521
531
|
version: PROJECT_CONFIG_VERSION,
|
|
522
532
|
scheduledTasks,
|
|
533
|
+
rawTasksByID,
|
|
523
534
|
};
|
|
524
535
|
};
|
|
525
536
|
|
|
537
|
+
// The list to write: tasks this write replaced go out normalized; every
|
|
538
|
+
// other task goes out exactly as stored, fields unknown to this build
|
|
539
|
+
// included. A state-only update counts as untouched — only its `state` is
|
|
540
|
+
// swapped onto the stored record. Callers keep working with (and returning)
|
|
541
|
+
// the normalized tasks; only the bytes on disk differ.
|
|
542
|
+
const toStoredTasks = (config, tasks, { replacedIDs = new Set(), stateUpdatedID = null } = {}) => (
|
|
543
|
+
tasks.map((task) => {
|
|
544
|
+
if (replacedIDs.has(task.id)) return task;
|
|
545
|
+
const stored = config.rawTasksByID.get(task.id);
|
|
546
|
+
if (!stored) return task;
|
|
547
|
+
return task.id === stateUpdatedID ? { ...stored, state: task.state } : stored;
|
|
548
|
+
})
|
|
549
|
+
);
|
|
550
|
+
|
|
526
551
|
const writeProjectConfigToDisk = async (projectID, config) => {
|
|
527
552
|
const filePath = resolveProjectConfigPath(projectID);
|
|
528
553
|
const parentDirectory = path.dirname(filePath);
|
|
@@ -607,7 +632,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
607
632
|
|
|
608
633
|
const nextConfig = {
|
|
609
634
|
version: PROJECT_CONFIG_VERSION,
|
|
610
|
-
scheduledTasks: nextTasks,
|
|
635
|
+
scheduledTasks: toStoredTasks(current, nextTasks, { replacedIDs: new Set([normalizedTask.id]) }),
|
|
611
636
|
};
|
|
612
637
|
await writeProjectConfigToDisk(projectID, nextConfig);
|
|
613
638
|
|
|
@@ -633,7 +658,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
633
658
|
if (deleted) {
|
|
634
659
|
await writeProjectConfigToDisk(projectID, {
|
|
635
660
|
version: PROJECT_CONFIG_VERSION,
|
|
636
|
-
scheduledTasks: nextTasks,
|
|
661
|
+
scheduledTasks: toStoredTasks(current, nextTasks),
|
|
637
662
|
});
|
|
638
663
|
}
|
|
639
664
|
|
|
@@ -676,7 +701,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
676
701
|
|
|
677
702
|
await writeProjectConfigToDisk(projectID, {
|
|
678
703
|
version: PROJECT_CONFIG_VERSION,
|
|
679
|
-
scheduledTasks: nextTasks,
|
|
704
|
+
scheduledTasks: toStoredTasks(current, nextTasks, { stateUpdatedID: nextTask.id }),
|
|
680
705
|
});
|
|
681
706
|
|
|
682
707
|
return {
|
|
@@ -737,7 +762,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
737
762
|
|
|
738
763
|
await writeProjectConfigToDisk(projectID, {
|
|
739
764
|
version: PROJECT_CONFIG_VERSION,
|
|
740
|
-
scheduledTasks: nextTasks,
|
|
765
|
+
scheduledTasks: toStoredTasks(current, nextTasks, { stateUpdatedID: nextTask.id }),
|
|
741
766
|
});
|
|
742
767
|
|
|
743
768
|
return {
|
|
@@ -797,6 +822,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
797
822
|
|
|
798
823
|
const consumedLoopPaths = new Set();
|
|
799
824
|
const nextTasks = [];
|
|
825
|
+
const replacedIDs = new Set();
|
|
800
826
|
for (const task of tasks) {
|
|
801
827
|
if (task.loopFile && !activeLoopFilePaths.has(task.loopFile)) {
|
|
802
828
|
// The driving loop file was removed (or renamed) — unschedule.
|
|
@@ -828,6 +854,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
828
854
|
},
|
|
829
855
|
);
|
|
830
856
|
nextTasks.push(adopted);
|
|
857
|
+
replacedIDs.add(adopted.id);
|
|
831
858
|
pendingLoops.delete(loop.definition.name);
|
|
832
859
|
if (task.loopFile) {
|
|
833
860
|
consumedLoopPaths.add(task.loopFile);
|
|
@@ -863,6 +890,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
863
890
|
},
|
|
864
891
|
);
|
|
865
892
|
nextTasks.push(created);
|
|
893
|
+
replacedIDs.add(created.id);
|
|
866
894
|
} catch (error) {
|
|
867
895
|
console.warn(`[scheduled-tasks] skipped loop ${loop.filePath}:`, error?.message ?? error);
|
|
868
896
|
}
|
|
@@ -870,7 +898,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
870
898
|
|
|
871
899
|
await writeProjectConfigToDisk(projectID, {
|
|
872
900
|
version: PROJECT_CONFIG_VERSION,
|
|
873
|
-
scheduledTasks: nextTasks,
|
|
901
|
+
scheduledTasks: toStoredTasks(current, nextTasks, { replacedIDs }),
|
|
874
902
|
});
|
|
875
903
|
|
|
876
904
|
return nextTasks;
|