@openchamber/web 1.21.0 → 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/bin/cli.test.js +35 -0
- package/bin/lib/DOCUMENTATION.md +12 -0
- package/bin/lib/cli-settings-accessors.js +111 -0
- package/bin/lib/cli-settings-accessors.test.js +189 -0
- package/bin/lib/cli-startup.js +29 -9
- package/bin/lib/commands-connect-url.js +12 -14
- package/dist/assets/{CodeMirrorCommentWidgets-C2BopIs3.js → CodeMirrorCommentWidgets-CPvfxh0N.js} +1 -1
- package/dist/assets/CommitSection-CC5mFzO2.js +1 -0
- 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-osju7J70.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-Dan3mADn.js → PatchDiff-BGPl1s-U.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CGoI2v0q.js → PierreDiffViewer-Cvz9Z-io.js} +2 -2
- package/dist/assets/PlanView-BFMsnHk3.js +5 -0
- package/dist/assets/SettingsView-_Gtn5SdT.js +28 -0
- package/dist/assets/{SettingsWindow-DXF-MTHG.js → SettingsWindow-C1Qa09YO.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DrCa1JRk.js → ToolOutputDialog-DzQlzMF4.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-B_tfvlNF.js → ToolPartDiffPreview-DfVOfwHy.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-CN_BctrR.js → VirtualizedFileDiff-DT5MDv-u.js} +1 -1
- package/dist/assets/WalkthroughView-D8sLH_M8.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-Gi1d5eU1.js → computeVirtualFileMetrics-DmpLWhll.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-CpzVNWAv.js → contextPanelEmbeddedChat-BK78t3M_.js} +1 -1
- package/dist/assets/de-C3luvSd_.js +9 -0
- package/dist/assets/es-CmU4HLv9.js +15 -0
- package/dist/assets/fr-Bgyni40l.js +13 -0
- package/dist/assets/index-C57jT0Sa.css +1 -0
- package/dist/assets/{index-Brm3X9rs.js → index-CWYs7sMK.js} +1 -1
- package/dist/assets/index-b0zDkWyg.js +7 -0
- package/dist/assets/{isDiffPlainText-pH9kAJQH.js → isDiffPlainText-BO_q5ezD.js} +1 -1
- package/dist/assets/{isFilePlainText-CVKy_dgB.js → isFilePlainText-D8qPqUAf.js} +1 -1
- package/dist/assets/ja-C1ImKinT.js +15 -0
- package/dist/assets/ko-CP7OdxYH.js +15 -0
- package/dist/assets/main-D4rd8Hy5.js +928 -0
- package/dist/assets/{main-vUCh0VB0.js → main-D7fwjW2z.js} +2 -2
- package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
- package/dist/assets/markdownCore-BcmkWZPO.js +3 -0
- package/dist/assets/{miniChat-BlzGEYgE.js → miniChat-D5rraz-g.js} +2 -2
- package/dist/assets/{mobile-CkX6H-IT.js → mobile-Cg_DE3KL.js} +2 -2
- package/dist/assets/{patchFileDiff-BCTsE43U.js → patchFileDiff-Bpql0QGw.js} +3 -3
- package/dist/assets/pl-DQYSiGYX.js +15 -0
- package/dist/assets/pt-BR-DytpsW4M.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-CJYe_KOL.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-BgTPSITe.js → shikiHighlight-CFAVs_lu.js} +1 -1
- package/dist/assets/tr-aizaUvft.js +6 -0
- package/dist/assets/uk-DwnRxJZd.js +15 -0
- package/dist/assets/useAppFontEffects-DWXGRUPZ.js +7310 -0
- package/dist/assets/{useInlineCommentController-DFFv0hae.js → useInlineCommentController-Cc0OCXr0.js} +2 -2
- package/dist/assets/useRootScrollLock-BFZtfciC.js +1 -0
- package/dist/assets/{vendor-base-ui-_6j2xOWl.js → vendor-base-ui-BeMD8X_w.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-DkQX2EBa.js → vendor-codemirror-language-data-BGFszm8n.js} +2 -2
- package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
- package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
- package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
- package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
- package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
- package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
- package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
- package/dist/assets/{web-components-DLnGY4fs.js → web-components-CD-GFayc.js} +4 -4
- package/dist/assets/zh-CN-UDNMxm7r.js +15 -0
- package/dist/assets/zh-TW-BsswdYL-.js +15 -0
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/dist/site.webmanifest +1 -1
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/public/site.webmanifest +1 -1
- package/server/index.js +6 -2
- package/server/lib/cloudflare-tunnel.js +1 -1
- 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 +5 -0
- package/server/lib/fs/routes.js +150 -0
- package/server/lib/fs/routes.test.js +308 -3
- package/server/lib/git/DOCUMENTATION.md +4 -3
- package/server/lib/git/service.js +128 -6
- package/server/lib/git/service.test.js +191 -1
- 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/markdown-image-grants/DOCUMENTATION.md +4 -0
- package/server/lib/markdown-image-grants/routes.js +3 -1
- package/server/lib/markdown-image-grants/routes.test.js +14 -0
- package/server/lib/openchamber-sessions/routes.js +4 -1
- package/server/lib/openchamber-sessions/routes.test.js +23 -0
- package/server/lib/opencode/env-runtime.js +17 -1
- package/server/lib/opencode/env-runtime.test.js +56 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/lifecycle.js +48 -9
- package/server/lib/opencode/lifecycle.test.js +125 -1
- package/server/lib/opencode/managed-process-registry.d.ts +13 -0
- package/server/lib/opencode/managed-process-registry.js +213 -163
- package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
- package/server/lib/opencode/project-directory-runtime.js +16 -11
- package/server/lib/opencode/project-directory-runtime.test.js +32 -12
- package/server/lib/opencode/pwa-manifest-routes.js +1 -1
- package/server/lib/opencode/routes-upgrade.test.js +96 -12
- package/server/lib/opencode/routes.js +53 -5
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +10 -0
- package/server/lib/opencode/static-routes-runtime.js +3 -3
- package/server/lib/opencode/theme-runtime.js +1 -1
- package/server/lib/opencode/theme-runtime.test.js +129 -0
- 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 +19 -0
- package/server/lib/quota/providers/copilot.js +26 -10
- package/server/lib/quota/providers/copilot.test.js +78 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
- package/server/lib/small-model/DOCUMENTATION.md +11 -5
- package/server/lib/small-model/call.js +64 -20
- package/server/lib/small-model/call.test.js +184 -2
- 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/tunnels/install-help.js +2 -2
- package/server/lib/tunnels/install-help.test.js +9 -0
- package/server/lib/walkthrough/languages.js +1 -0
- package/dist/assets/CommitSection-HJeMUAWb.js +0 -1
- package/dist/assets/DiffView-D5cvbEPb.js +0 -4
- package/dist/assets/FilesView-DPU8aNPL.js +0 -17
- package/dist/assets/GitView-Ct6xWrVH.js +0 -6
- package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +0 -12
- package/dist/assets/OnboardingScreen-w2VG4fWY.js +0 -1
- package/dist/assets/PlanView-Dgg-WTEc.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +0 -1
- package/dist/assets/SettingsView-D9yRuFZw.js +0 -28
- package/dist/assets/WalkthroughView-D9Q4lr5x.js +0 -4
- package/dist/assets/de-B_LdJwEM.js +0 -9
- package/dist/assets/es-CubfsAYV.js +0 -15
- package/dist/assets/fr-5qJM0nFS.js +0 -13
- package/dist/assets/index-BW82eK5v.css +0 -1
- package/dist/assets/index-rlLjZUM5.js +0 -7
- package/dist/assets/ja-DJYIBUlH.js +0 -15
- package/dist/assets/ko-DcUBkB7y.js +0 -15
- package/dist/assets/main-DLBxKIoX.js +0 -926
- package/dist/assets/markdownCore-DG6GHLF4.js +0 -3
- package/dist/assets/pl-rB6BLcio.js +0 -15
- package/dist/assets/pt-BR-DcwtlO-o.js +0 -15
- package/dist/assets/renderMobileApp-hQJTnr8B.js +0 -25
- package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +0 -15
- package/dist/assets/scheduledTasksApi-CAGPh_gZ.js +0 -1
- package/dist/assets/uk-INZlFD9A.js +0 -15
- package/dist/assets/useAppFontEffects-Cll4gnsh.js +0 -7268
- package/dist/assets/zh-CN-Dzda8xa1.js +0 -15
- package/dist/assets/zh-TW-Cwn3rNYZ.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
|
+
});
|
|
@@ -34,3 +34,7 @@ server implementation. VS Code does not call this route for workspace images;
|
|
|
34
34
|
those use its local filesystem bridge. If called, the grant route returns an
|
|
35
35
|
explicit unsupported response because OpenCode temporary images are not
|
|
36
36
|
supported there.
|
|
37
|
+
|
|
38
|
+
Requests to OpenCode carry the directory in a percent-encoded
|
|
39
|
+
`x-opencode-directory` header, matching the SDK wire format; OpenCode rejects
|
|
40
|
+
raw non-ASCII header values.
|
|
@@ -200,7 +200,9 @@ const fetchMessage = async ({ sessionId, messageId, directory, buildOpenCodeUrl,
|
|
|
200
200
|
const response = await fetch(url, {
|
|
201
201
|
headers: {
|
|
202
202
|
accept: 'application/json',
|
|
203
|
-
|
|
203
|
+
// Percent-encoded to match the SDK wire format; raw non-ASCII values
|
|
204
|
+
// are rejected by OpenCode.
|
|
205
|
+
'x-opencode-directory': encodeURIComponent(directory),
|
|
204
206
|
...getOpenCodeAuthHeaders(),
|
|
205
207
|
},
|
|
206
208
|
signal: AbortSignal.timeout(10_000),
|
|
@@ -74,6 +74,20 @@ const prepare = (app, directory, sources) => request(app)
|
|
|
74
74
|
.expect(200);
|
|
75
75
|
|
|
76
76
|
describe('session image assets', () => {
|
|
77
|
+
it('percent-encodes the directory header on the message fetch', async () => {
|
|
78
|
+
const fixture = await createFixture();
|
|
79
|
+
await prepare(fixture.app, fixture.directory, ['image.png']);
|
|
80
|
+
|
|
81
|
+
expect(fixture.fetchMock).toHaveBeenCalledWith(
|
|
82
|
+
expect.any(URL),
|
|
83
|
+
expect.objectContaining({
|
|
84
|
+
headers: expect.objectContaining({
|
|
85
|
+
'x-opencode-directory': encodeURIComponent(fixture.directory),
|
|
86
|
+
}),
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
77
91
|
it('prepares workspace and OpenCode temporary images with one message fetch', async () => {
|
|
78
92
|
const fixture = await createFixture({ sources: ['workspace.png'] });
|
|
79
93
|
await fs.writeFile(path.join(fixture.directory, 'workspace.png'), PNG);
|
|
@@ -83,7 +83,10 @@ const resolveVariant = (providers, providerID, modelID, variant) => {
|
|
|
83
83
|
const parseConfigModel = (value) => splitModel(value);
|
|
84
84
|
|
|
85
85
|
const buildDirectoryHeaders = (directory) => ({
|
|
86
|
-
|
|
86
|
+
// OpenCode rejects non-ASCII header values; the official SDK sends this
|
|
87
|
+
// header percent-encoded, so match that wire format (non-ASCII checkout
|
|
88
|
+
// paths such as "Masaüstü" otherwise fail every dispatched prompt).
|
|
89
|
+
...(directory ? { 'x-opencode-directory': encodeURIComponent(directory) } : {}),
|
|
87
90
|
});
|
|
88
91
|
|
|
89
92
|
const fetchJson = async (url, authHeaders, fallback, directory) => {
|
|
@@ -161,6 +161,29 @@ describe('openchamber session routes', () => {
|
|
|
161
161
|
}
|
|
162
162
|
});
|
|
163
163
|
|
|
164
|
+
it('percent-encodes the directory header for non-ASCII checkout paths', async () => {
|
|
165
|
+
const originalFetch = globalThis.fetch;
|
|
166
|
+
globalThis.fetch = vi.fn(async () => ({ ok: true, json: async () => ({ id: 'ses_123' }) }));
|
|
167
|
+
try {
|
|
168
|
+
const { app } = createApp();
|
|
169
|
+
await request(app)
|
|
170
|
+
.post('/api/openchamber/sessions')
|
|
171
|
+
.send({ directory: '/home/user/Masaüstü/projeler', title: 'Side task' })
|
|
172
|
+
.expect(200);
|
|
173
|
+
|
|
174
|
+
expect(globalThis.fetch).toHaveBeenCalledWith(
|
|
175
|
+
expect.any(String),
|
|
176
|
+
expect.objectContaining({
|
|
177
|
+
headers: expect.objectContaining({
|
|
178
|
+
'x-opencode-directory': encodeURIComponent('/home/user/Masaüstü/projeler'),
|
|
179
|
+
}),
|
|
180
|
+
}),
|
|
181
|
+
);
|
|
182
|
+
} finally {
|
|
183
|
+
globalThis.fetch = originalFetch;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
164
187
|
it('parses JSON body without global middleware', async () => {
|
|
165
188
|
const originalFetch = globalThis.fetch;
|
|
166
189
|
globalThis.fetch = vi.fn(async () => ({ ok: true, json: async () => ({ id: 'ses_123' }) }));
|
|
@@ -5,6 +5,12 @@ import path from 'node:path';
|
|
|
5
5
|
import { clearAppImageArgv0FromProcessEnv } from '../inherited-env.js';
|
|
6
6
|
import { mergePathValues } from './path-utils.js';
|
|
7
7
|
|
|
8
|
+
// Login-shell probes source the user's rc files. A slow or interactive rc
|
|
9
|
+
// (nvm, pyenv, a prompt waiting for input) must not hold server startup
|
|
10
|
+
// hostage: a probe that overruns is abandoned and resolution falls through
|
|
11
|
+
// to the next candidate. Electron's own login-shell probe uses the same bound.
|
|
12
|
+
const SHELL_PROBE_TIMEOUT_MS = 5_000;
|
|
13
|
+
|
|
8
14
|
export const createOpenCodeEnvRuntime = (deps) => {
|
|
9
15
|
const {
|
|
10
16
|
state,
|
|
@@ -208,6 +214,7 @@ export const createOpenCodeEnvRuntime = (deps) => {
|
|
|
208
214
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
209
215
|
maxBuffer: 10 * 1024 * 1024,
|
|
210
216
|
windowsHide: true,
|
|
217
|
+
timeout: SHELL_PROBE_TIMEOUT_MS,
|
|
211
218
|
});
|
|
212
219
|
|
|
213
220
|
if (result.status !== 0) {
|
|
@@ -460,6 +467,7 @@ export const createOpenCodeEnvRuntime = (deps) => {
|
|
|
460
467
|
encoding: 'utf8',
|
|
461
468
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
462
469
|
windowsHide: true,
|
|
470
|
+
timeout: SHELL_PROBE_TIMEOUT_MS,
|
|
463
471
|
});
|
|
464
472
|
if (result.status === 0) {
|
|
465
473
|
const found = (result.stdout || '').trim().split(/\s+/).pop() || '';
|
|
@@ -527,6 +535,7 @@ export const createOpenCodeEnvRuntime = (deps) => {
|
|
|
527
535
|
encoding: 'utf8',
|
|
528
536
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
529
537
|
windowsHide: true,
|
|
538
|
+
timeout: SHELL_PROBE_TIMEOUT_MS,
|
|
530
539
|
});
|
|
531
540
|
if (result.status === 0) {
|
|
532
541
|
const found = (result.stdout || '').trim().split(/\s+/).pop() || '';
|
|
@@ -608,6 +617,7 @@ export const createOpenCodeEnvRuntime = (deps) => {
|
|
|
608
617
|
encoding: 'utf8',
|
|
609
618
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
610
619
|
windowsHide: true,
|
|
620
|
+
timeout: SHELL_PROBE_TIMEOUT_MS,
|
|
611
621
|
});
|
|
612
622
|
if (result.status === 0) {
|
|
613
623
|
const found = (result.stdout || '').trim().split(/\s+/).pop() || '';
|
|
@@ -1011,7 +1021,13 @@ export const createOpenCodeEnvRuntime = (deps) => {
|
|
|
1011
1021
|
const normalized = normalizeOpencodeBinarySetting(settings.opencodeBinary);
|
|
1012
1022
|
|
|
1013
1023
|
if (normalized === '') {
|
|
1014
|
-
|
|
1024
|
+
// The empty-string sentinel drops a previously APPLIED settings
|
|
1025
|
+
// override (source === 'settings'). An OPENCODE_BINARY provided by
|
|
1026
|
+
// the user's own environment is explicit configuration and must not
|
|
1027
|
+
// be destroyed by an empty setting.
|
|
1028
|
+
if (state.resolvedOpencodeBinarySource === 'settings') {
|
|
1029
|
+
delete process.env.OPENCODE_BINARY;
|
|
1030
|
+
}
|
|
1015
1031
|
state.resolvedOpencodeBinary = null;
|
|
1016
1032
|
state.resolvedOpencodeBinarySource = null;
|
|
1017
1033
|
clearWslOpencodeResolution();
|
|
@@ -200,6 +200,39 @@ describe('OpenCode env runtime', () => {
|
|
|
200
200
|
expect(state.resolvedOpencodeBinarySource).toBe('settings');
|
|
201
201
|
});
|
|
202
202
|
|
|
203
|
+
it('keeps an env-provided OPENCODE_BINARY when the setting is an empty-string sentinel', async () => {
|
|
204
|
+
const dir = createTempDir('openchamber-env-opencode-');
|
|
205
|
+
const binary = path.join(dir, 'opencode');
|
|
206
|
+
fs.writeFileSync(binary, '#!/bin/sh\nexit 0\n');
|
|
207
|
+
if (process.platform !== 'win32') fs.chmodSync(binary, 0o755);
|
|
208
|
+
process.env.OPENCODE_BINARY = binary;
|
|
209
|
+
const { runtime, state } = createRuntime({ opencodeBinary: '' });
|
|
210
|
+
|
|
211
|
+
await expect(runtime.applyOpencodeBinaryFromSettings()).resolves.toBeNull();
|
|
212
|
+
expect(process.env.OPENCODE_BINARY).toBe(binary);
|
|
213
|
+
expect(state.resolvedOpencodeBinary).toBeNull();
|
|
214
|
+
expect(state.resolvedOpencodeBinarySource).toBeNull();
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('drops a previously applied settings override when the setting is cleared to an empty string', async () => {
|
|
218
|
+
const dir = createTempDir('openchamber-settings-opencode-');
|
|
219
|
+
const binary = path.join(dir, 'opencode');
|
|
220
|
+
fs.writeFileSync(binary, '#!/bin/sh\nexit 0\n');
|
|
221
|
+
if (process.platform !== 'win32') fs.chmodSync(binary, 0o755);
|
|
222
|
+
const settings = { opencodeBinary: binary };
|
|
223
|
+
const { runtime, state } = createRuntime(settings);
|
|
224
|
+
|
|
225
|
+
await expect(runtime.applyOpencodeBinaryFromSettings()).resolves.toBe(binary);
|
|
226
|
+
expect(process.env.OPENCODE_BINARY).toBe(binary);
|
|
227
|
+
expect(state.resolvedOpencodeBinarySource).toBe('settings');
|
|
228
|
+
|
|
229
|
+
settings.opencodeBinary = '';
|
|
230
|
+
await expect(runtime.applyOpencodeBinaryFromSettings()).resolves.toBeNull();
|
|
231
|
+
expect(process.env.OPENCODE_BINARY).toBeUndefined();
|
|
232
|
+
expect(state.resolvedOpencodeBinary).toBeNull();
|
|
233
|
+
expect(state.resolvedOpencodeBinarySource).toBeNull();
|
|
234
|
+
});
|
|
235
|
+
|
|
203
236
|
it('prefers the bundled CLI over a user-installed OpenCode from PATH', () => {
|
|
204
237
|
const bundledDir = createTempDir('openchamber-bundled-opencode-');
|
|
205
238
|
const bundledBinary = path.join(bundledDir, process.platform === 'win32' ? 'opencode.exe' : 'opencode');
|
|
@@ -301,6 +334,29 @@ describe('OpenCode env runtime', () => {
|
|
|
301
334
|
});
|
|
302
335
|
});
|
|
303
336
|
|
|
337
|
+
it('bounds every login-shell probe and falls through when one overruns', () => {
|
|
338
|
+
setPlatform('darwin');
|
|
339
|
+
process.env.PATH = createTempDir('openchamber-empty-path-');
|
|
340
|
+
process.env.SHELL = '/bin/zsh';
|
|
341
|
+
delete process.env.OPENCODE_BINARY;
|
|
342
|
+
const shellCalls = [];
|
|
343
|
+
const { runtime } = createRuntime({}, {
|
|
344
|
+
homedir: () => createTempDir('openchamber-empty-home-'),
|
|
345
|
+
spawnSync: (command, args, options) => {
|
|
346
|
+
shellCalls.push({ command, args, options });
|
|
347
|
+
// What spawnSync reports when `timeout` fires: no status, an error.
|
|
348
|
+
return { status: null, signal: 'SIGTERM', error: new Error('spawnSync ETIMEDOUT'), stdout: '', stderr: '' };
|
|
349
|
+
},
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
expect(runtime.resolveOpencodeCliPath()).toBeNull();
|
|
353
|
+
expect(shellCalls.length).toBeGreaterThan(0);
|
|
354
|
+
for (const call of shellCalls) {
|
|
355
|
+
expect(call.args).toContain('-lic');
|
|
356
|
+
expect(call.options.timeout).toBe(5_000);
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
|
|
304
360
|
it('does not auto-detect the Windows OpenCode desktop app as a CLI', () => {
|
|
305
361
|
setPlatform('win32');
|
|
306
362
|
const localAppData = createTempDir('openchamber-localappdata-');
|
|
@@ -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, {
|