Skip to content

Commit fcda971

Browse files
authored
test framework traits for Chat (#13285)
* add test frameworks traits to VSCode Copilot Chat * add test framework traits for #cpp * update prompt * drop unnecessary `?.`, and use sensible names for test framework in tests.
1 parent 669e830 commit fcda971

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ export interface ChatContextResult {
554554
compiler: string;
555555
targetPlatform: string;
556556
targetArchitecture: string;
557+
usedTestFrameworks: string[];
557558
}
558559

559560
interface FolderFilesEncodingChanged {

Extension/src/LanguageServer/lmTool.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ export class CppConfigurationLanguageModelTool implements vscode.LanguageModelTo
168168
contextString += `The project targets the ${chatContext.targetArchitecture} architecture. `;
169169
telemetryProperties["targetArchitecture"] = chatContext.targetArchitecture;
170170
}
171-
171+
if (chatContext.usedTestFrameworks.length > 0) {
172+
contextString += `The project uses the following C++ test frameworks: ${chatContext.usedTestFrameworks.join(', ')}. `;
173+
telemetryProperties["testFrameworks"] = chatContext.usedTestFrameworks.join(', ');
174+
}
172175
return contextString;
173176
}
174177
catch {

Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ describe('CppConfigurationLanguageModelTool Tests', () => {
130130
});
131131

132132
const arrangeChatContextFromCppTools = ({ chatContextFromCppTools, isCpp, isHeaderFile }:
133-
{ chatContextFromCppTools?: ChatContextResult; isCpp?: boolean; isHeaderFile?: boolean } =
134-
{ chatContextFromCppTools: undefined, isCpp: undefined, isHeaderFile: false }
133+
{ chatContextFromCppTools?: ChatContextResult; isCpp?: boolean; isHeaderFile?: boolean } =
134+
{ chatContextFromCppTools: undefined, isCpp: undefined, isHeaderFile: false }
135135
) => {
136136
activeClientStub.getChatContext.resolves(chatContextFromCppTools);
137137
sinon.stub(util, 'isCpp').returns(isCpp ?? true);
@@ -145,7 +145,8 @@ describe('CppConfigurationLanguageModelTool Tests', () => {
145145
standardVersion: 'c++20',
146146
compiler: 'msvc',
147147
targetPlatform: 'windows',
148-
targetArchitecture: 'x64'
148+
targetArchitecture: 'x64',
149+
usedTestFrameworks: ['GTest', 'Catch2']
149150
}
150151
});
151152

@@ -157,12 +158,14 @@ describe('CppConfigurationLanguageModelTool Tests', () => {
157158
"compiler": 'MSVC',
158159
"standardVersion": 'C++20',
159160
"targetPlatform": 'Windows',
160-
"targetArchitecture": 'x64'
161+
"targetArchitecture": 'x64',
162+
'testFrameworks': 'GTest, Catch2'
161163
})));
162164
ok(result, 'result should not be undefined');
163165
const text = result.content[0] as vscode.LanguageModelTextPart;
164166
ok(text, 'result should contain a text part');
165-
ok(text.value === 'The user is working on a C++ project. The project uses language version C++20. The project compiles using the MSVC compiler. The project targets the Windows platform. The project targets the x64 architecture. ');
167+
const traits_text = `The user is working on a C++ project. The project uses language version C++20. The project compiles using the MSVC compiler. The project targets the Windows platform. The project targets the x64 architecture. The project uses the following C++ test frameworks: GTest, Catch2. `;
168+
ok(text.value === traits_text);
166169
});
167170

168171
const testGetProjectContext = async ({
@@ -184,7 +187,8 @@ describe('CppConfigurationLanguageModelTool Tests', () => {
184187
standardVersion: 'c++20',
185188
compiler: compiler,
186189
targetPlatform: 'windows',
187-
targetArchitecture: 'x64'
190+
targetArchitecture: 'x64',
191+
usedTestFrameworks: []
188192
}
189193
});
190194

@@ -225,7 +229,8 @@ describe('CppConfigurationLanguageModelTool Tests', () => {
225229
standardVersion: 'gnu++17',
226230
compiler: 'javac',
227231
targetPlatform: 'arduino',
228-
targetArchitecture: 'bar'
232+
targetArchitecture: 'bar',
233+
usedTestFrameworks: []
229234
}
230235
});
231236
const telemetryProperties: Record<string, string> = {};

0 commit comments

Comments
 (0)