Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion chat-lib/test/nesProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ import { CopilotToken } from '../src/_internal/platform/authentication/common/co


class TestFetcher implements IFetcher {

requests: { url: string; options: FetchOptions }[] = [];

constructor(private readonly responses: Record<string, string>) { }

getUserAgentLibrary(): string {
return 'test-fetcher';
}

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

Expand Down Expand Up @@ -132,18 +136,25 @@ describe('NESProvider Facade', () => {
doc.setSelection([new OffsetRange(1, 1)], undefined);
const telemetrySender = new TestTelemetrySender();
const logTarget = new TestLogTarget();
const fetcher = new TestFetcher({ '/chat/completions': await fs.readFile(path.join(__dirname, 'nesProvider.reply.txt'), 'utf8') });
const nextEditProvider = createNESProvider({
workspace,
fetcher: new TestFetcher({ '/chat/completions': await fs.readFile(path.join(__dirname, 'nesProvider.reply.txt'), 'utf8') }),
fetcher,
copilotTokenManager: new TestCopilotTokenManager(),
telemetrySender,
logTarget,
});
nextEditProvider.updateTreatmentVariables({
'config.github.copilot.chat.advanced.inlineEdits.xtabProvider.defaultModelConfigurationString': '{ "modelName": "xtab-test" }',
});

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

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

assert.strictEqual(fetcher.requests.length, 1);
assert.strictEqual(fetcher.requests[0].options.json?.model, 'xtab-test');

assert(result.result);

const { range, newText } = result.result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ export class DefaultsOnlyConfigurationService extends AbstractConfigurationServi
}

override getExperimentBasedConfig<T extends ExperimentBasedConfigType>(key: ExperimentBasedConfig<T>, experimentationService: IExperimentationService, scope?: ConfigurationScope): T {
if (key.experimentName) {
const expValue = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(key.experimentName);
if (expValue !== undefined) {
return expValue;
}
}

// This is the pattern we've been using for a while now. We need to maintain it for older experiments.
const expValue = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(`copilotchat.config.${key.id}`);
if (expValue !== undefined) {
return expValue;
}

// This is the pattern vscode uses for settings using the `onExp` tag. But vscode only supports it for
// settings defined in package.json, so this is why we're also reading the value from exp here.
const expValue2 = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(`config.${key.fullyQualifiedId}`);
if (expValue2 !== undefined) {
return expValue2;
}

return this.getDefaultValue(key);
}

Expand Down
Loading