Skip to content

Commit ee4a2ea

Browse files
committed
Fix experiment lookup
1 parent 42a0f56 commit ee4a2ea

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

chat-lib/test/nesProvider.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ import { CopilotToken } from '../src/_internal/platform/authentication/common/co
2727

2828

2929
class TestFetcher implements IFetcher {
30+
31+
requests: { url: string; options: FetchOptions }[] = [];
32+
3033
constructor(private readonly responses: Record<string, string>) { }
3134

3235
getUserAgentLibrary(): string {
3336
return 'test-fetcher';
3437
}
3538

3639
async fetch(url: string, options: FetchOptions): Promise<Response> {
40+
this.requests.push({ url, options });
3741
const uri = URI.parse(url);
3842
const responseText = this.responses[uri.path];
3943

@@ -132,18 +136,25 @@ describe('NESProvider Facade', () => {
132136
doc.setSelection([new OffsetRange(1, 1)], undefined);
133137
const telemetrySender = new TestTelemetrySender();
134138
const logTarget = new TestLogTarget();
139+
const fetcher = new TestFetcher({ '/chat/completions': await fs.readFile(path.join(__dirname, 'nesProvider.reply.txt'), 'utf8') });
135140
const nextEditProvider = createNESProvider({
136141
workspace,
137-
fetcher: new TestFetcher({ '/chat/completions': await fs.readFile(path.join(__dirname, 'nesProvider.reply.txt'), 'utf8') }),
142+
fetcher,
138143
copilotTokenManager: new TestCopilotTokenManager(),
139144
telemetrySender,
140145
logTarget,
141146
});
147+
nextEditProvider.updateTreatmentVariables({
148+
'config.github.copilot.chat.advanced.inlineEdits.xtabProvider.defaultModelConfigurationString': '{ "modelName": "xtab-test" }',
149+
});
142150

143151
doc.applyEdit(StringEdit.insert(11, '3D'));
144152

145153
const result = await nextEditProvider.getNextEdit(doc.id.toUri(), CancellationToken.None);
146154

155+
assert.strictEqual(fetcher.requests.length, 1);
156+
assert.strictEqual(fetcher.requests[0].options.json?.model, 'xtab-test');
157+
147158
assert(result.result);
148159

149160
const { range, newText } = result.result;

src/platform/configuration/common/defaultsOnlyConfigurationService.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@ export class DefaultsOnlyConfigurationService extends AbstractConfigurationServi
3030
}
3131

3232
override getExperimentBasedConfig<T extends ExperimentBasedConfigType>(key: ExperimentBasedConfig<T>, experimentationService: IExperimentationService, scope?: ConfigurationScope): T {
33+
if (key.experimentName) {
34+
const expValue = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(key.experimentName);
35+
if (expValue !== undefined) {
36+
return expValue;
37+
}
38+
}
39+
40+
// This is the pattern we've been using for a while now. We need to maintain it for older experiments.
41+
const expValue = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(`copilotchat.config.${key.id}`);
42+
if (expValue !== undefined) {
43+
return expValue;
44+
}
45+
46+
// This is the pattern vscode uses for settings using the `onExp` tag. But vscode only supports it for
47+
// settings defined in package.json, so this is why we're also reading the value from exp here.
48+
const expValue2 = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(`config.${key.fullyQualifiedId}`);
49+
if (expValue2 !== undefined) {
50+
return expValue2;
51+
}
52+
3353
return this.getDefaultValue(key);
3454
}
3555

0 commit comments

Comments
 (0)