Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/chronicle/common/test/standupPrompt.spec.ts
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { describe, expect, it } from 'vitest';
7
import { extractFilePath, extractRefsFromMcpTool, extractRefsFromTerminal, extractRepoFromMcpTool, isGitHubMcpTool } from '../sessionStoreTracking';
8
import { type AnnotatedRef, type AnnotatedSession, buildRefsQuery, buildStandupPrompt } from '../standupPrompt';
9
10
describe('buildStandupPrompt', () => {
11
it('returns no-activity message when no sessions', () => {
12
const result = buildStandupPrompt([], [], [], []);
13
expect(result).toContain('no sessions were found');
14
});
15
16
it('includes session data in prompt', () => {
17
const sessions: AnnotatedSession[] = [
18
{ id: 'sess-1', branch: 'feature/auth', repository: 'owner/repo', summary: 'Added OAuth', updated_at: '2026-04-06T10:00:00Z', source: 'cloud' },
19
];
20
const result = buildStandupPrompt(sessions, [], [], []);
21
expect(result).toContain('sess-1');
22
expect(result).toContain('feature/auth');
23
expect(result).toContain('owner/repo');
24
expect(result).toContain('Added OAuth');
25
});
26
27
it('includes refs in prompt', () => {
28
const sessions: AnnotatedSession[] = [
29
{ id: 'sess-1', branch: 'main', summary: 'Fix', source: 'cloud' },
30
];
31
const refs: AnnotatedRef[] = [
32
{ session_id: 'sess-1', ref_type: 'pr', ref_value: '42', source: 'cloud' },
33
{ session_id: 'sess-1', ref_type: 'commit', ref_value: 'abc123', source: 'cloud' },
34
];
35
const result = buildStandupPrompt(sessions, refs, [], []);
36
expect(result).toContain('commit: abc123');
37
});
38
39
it('shows "No references found" when refs empty', () => {
40
const sessions: AnnotatedSession[] = [{ id: 'sess-1', branch: 'main', summary: 'Fix', source: 'cloud' }];
41
const result = buildStandupPrompt(sessions, [], [], []);
42
expect(result).toContain('No references found.');
43
});
44
45
it('includes extra context when provided', () => {
46
const sessions: AnnotatedSession[] = [{ id: 'sess-1', summary: 'Work', source: 'cloud' }];
47
const result = buildStandupPrompt(sessions, [], [], [], 'Focus on backend changes');
48
expect(result).toContain('Additional context: Focus on backend changes');
49
});
50
51
it('shows "unknown" for missing branch and repo', () => {
52
const sessions: AnnotatedSession[] = [{ id: 'sess-1', summary: 'Work', source: 'cloud' }];
53
const result = buildStandupPrompt(sessions, [], [], []);
54
expect(result).toContain('unknown (unknown)');
55
});
56
57
it('handles multiple sessions from different branches', () => {
58
const sessions: AnnotatedSession[] = [
59
{ id: 'sess-1', branch: 'feature/a', repository: 'org/repo', summary: 'Feature A', source: 'cloud' },
60
{ id: 'sess-2', branch: 'feature/b', repository: 'org/repo', summary: 'Feature B', source: 'cloud' },
61
];
62
const result = buildStandupPrompt(sessions, [], [], []);
63
expect(result).toContain('feature/a');
64
expect(result).toContain('feature/b');
65
});
66
67
it('shows source tags for cloud sessions', () => {
68
const sessions: AnnotatedSession[] = [
69
{ id: 'cloud-1', branch: 'main', summary: 'Cloud work 1', source: 'cloud' },
70
{ id: 'cloud-2', branch: 'feature/x', summary: 'Cloud work 2', source: 'cloud' },
71
];
72
const refs: AnnotatedRef[] = [
73
{ session_id: 'cloud-2', ref_type: 'pr', ref_value: '99', source: 'cloud' },
74
];
75
const result = buildStandupPrompt(sessions, refs, [], []);
76
expect(result).toContain('cloud-2 | pr: 99');
77
});
78
});
79
80
describe('buildRefsQuery', () => {
81
it('builds IN clause with escaped IDs', () => {
82
const query = buildRefsQuery(['sess-1', 'sess-2']);
83
expect(query).toContain('\'sess-1\'');
84
expect(query).toContain('\'sess-2\'');
85
expect(query).toContain('session_refs');
86
});
87
88
it('escapes single quotes in session IDs', () => {
89
const query = buildRefsQuery(['it\'s']);
90
expect(query).toContain('\'it\'\'s\'');
91
});
92
});
93
94
describe('extractFilePath', () => {
95
it('extracts filePath from apply_patch args', () => {
96
expect(extractFilePath('apply_patch', { filePath: '/src/index.ts' })).toBe('/src/index.ts');
97
});
98
99
it('extracts path from create tool args', () => {
100
expect(extractFilePath('create', { path: '/src/new.ts' })).toBe('/src/new.ts');
101
});
102
103
it('extracts filePath from read_file args', () => {
104
expect(extractFilePath('read_file', { filePath: '/src/index.ts' })).toBe('/src/index.ts');
105
});
106
107
it('returns undefined for null args', () => {
108
expect(extractFilePath('apply_patch', null)).toBeUndefined();
109
});
110
111
it('returns undefined when no path field exists', () => {
112
expect(extractFilePath('apply_patch', { content: 'hello' })).toBeUndefined();
113
});
114
});
115
116
describe('extractRefsFromMcpTool', () => {
117
it('extracts PR number from pull_request tool', () => {
118
const refs = extractRefsFromMcpTool('github-mcp-server-pull_request_read', { pullNumber: 42 });
119
expect(refs).toEqual([{ ref_type: 'pr', ref_value: '42' }]);
120
});
121
122
it('extracts issue number from issue tool', () => {
123
const refs = extractRefsFromMcpTool('github-mcp-server-issue_read', { issue_number: 99 });
124
expect(refs).toEqual([{ ref_type: 'issue', ref_value: '99' }]);
125
});
126
127
it('extracts commit SHA from commit tool', () => {
128
const refs = extractRefsFromMcpTool('github-mcp-server-get_commit', { sha: 'abc123' });
129
expect(refs).toEqual([{ ref_type: 'commit', ref_value: 'abc123' }]);
130
});
131
132
it('returns empty for unrecognized tool', () => {
133
expect(extractRefsFromMcpTool('github-mcp-server-list_repos', {})).toEqual([]);
134
});
135
});
136
137
describe('extractRefsFromTerminal', () => {
138
it('extracts PR URL from gh pr create output', () => {
139
const refs = extractRefsFromTerminal(
140
{ command: 'gh pr create --title "feat"' },
141
'https://github.com/owner/repo/pull/123'
142
);
143
expect(refs).toEqual([{ ref_type: 'pr', ref_value: '123' }]);
144
});
145
146
it('extracts issue URL from gh issue create output', () => {
147
const refs = extractRefsFromTerminal(
148
{ command: 'gh issue create --title "bug"' },
149
'https://github.com/owner/repo/issues/456'
150
);
151
expect(refs).toEqual([{ ref_type: 'issue', ref_value: '456' }]);
152
});
153
154
it('extracts commit SHA from git commit output', () => {
155
const refs = extractRefsFromTerminal(
156
{ command: 'git commit -m "fix"' },
157
'[main abc1234] fix'
158
);
159
expect(refs).toEqual([{ ref_type: 'commit', ref_value: 'abc1234' }]);
160
});
161
162
it('returns empty for missing command', () => {
163
expect(extractRefsFromTerminal({}, undefined)).toEqual([]);
164
});
165
166
it('returns empty for unrecognized command', () => {
167
expect(extractRefsFromTerminal({ command: 'npm install' }, 'done')).toEqual([]);
168
});
169
});
170
171
describe('extractRepoFromMcpTool', () => {
172
it('extracts owner/repo', () => {
173
expect(extractRepoFromMcpTool({ owner: 'microsoft', repo: 'vscode' })).toBe('microsoft/vscode');
174
});
175
176
it('returns undefined when owner missing', () => {
177
expect(extractRepoFromMcpTool({ repo: 'vscode' })).toBeUndefined();
178
});
179
180
it('returns undefined when repo missing', () => {
181
expect(extractRepoFromMcpTool({ owner: 'microsoft' })).toBeUndefined();
182
});
183
});
184
185
describe('isGitHubMcpTool', () => {
186
it('returns true for github-mcp-server-* tools', () => {
187
expect(isGitHubMcpTool('github-mcp-server-pull_request_read')).toBe(true);
188
});
189
190
it('returns false for other tools', () => {
191
expect(isGitHubMcpTool('apply_patch')).toBe(false);
192
});
193
});
194
195