Skip to content

Commit b76d3f0

Browse files
committed
experiments: rename to action2 for new experiments
1 parent 4c59cdd commit b76d3f0

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

src/vs/workbench/contrib/experiments/common/experimentService.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ interface IExperimentStorageState {
9393
* be incremented when adding a condition, otherwise experiments might activate
9494
* on older versions of VS Code where not intended.
9595
*/
96-
export const currentSchemaVersion = 2;
96+
export const currentSchemaVersion = 3;
9797

9898
interface IRawExperiment {
9999
id: string;
@@ -128,6 +128,7 @@ interface IRawExperiment {
128128
userProbability?: number;
129129
};
130130
action?: IExperimentAction;
131+
action2?: IExperimentAction;
131132
}
132133

133134
interface IActivationEventRecord {
@@ -310,10 +311,11 @@ export class ExperimentService extends Disposable implements IExperimentService
310311
state: !!experiment.enabled ? ExperimentState.Evaluating : ExperimentState.NoRun
311312
};
312313

313-
if (experiment.action) {
314+
const action = experiment.action2 || experiment.action;
315+
if (action) {
314316
processedExperiment.action = {
315-
type: ExperimentActionType[experiment.action.type] || ExperimentActionType.Custom,
316-
properties: experiment.action.properties
317+
type: ExperimentActionType[action.type] || ExperimentActionType.Custom,
318+
properties: action.properties
317319
};
318320
if (processedExperiment.action.type === ExperimentActionType.Prompt) {
319321
((<IExperimentActionPromptProperties>processedExperiment.action.properties).commands || []).forEach(x => {
@@ -557,7 +559,7 @@ export class ExperimentService extends Disposable implements IExperimentService
557559
if (typeof latestExperimentState.editCount === 'number' && latestExperimentState.editCount >= fileEdits.minEditCount) {
558560
processedExperiment.state = latestExperimentState.state = (typeof condition.userProbability === 'number' && Math.random() < condition.userProbability && this.checkExperimentDependencies(experiment)) ? ExperimentState.Run : ExperimentState.NoRun;
559561
this.storageService.store(storageKey, JSON.stringify(latestExperimentState), StorageScope.GLOBAL);
560-
if (latestExperimentState.state === ExperimentState.Run && experiment.action && ExperimentActionType[experiment.action.type] === ExperimentActionType.Prompt) {
562+
if (latestExperimentState.state === ExperimentState.Run && processedExperiment.action && ExperimentActionType[processedExperiment.action.type] === ExperimentActionType.Prompt) {
561563
this.fireRunExperiment(processedExperiment);
562564
}
563565
}

src/vs/workbench/contrib/experiments/test/electron-browser/experimentService.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,13 +768,37 @@ suite('Experiment Service', () => {
768768
testObject = instantiationService.createInstance(TestExperimentService);
769769
return testObject.getExperimentById('experiment1').then(result => {
770770
assert.equal(result.enabled, false);
771+
assert.equal(result.action?.type, 'Prompt');
771772
assert.equal(result.state, ExperimentState.NoRun);
772773
return testObject.getCuratedExtensionsList(curatedExtensionsKey).then(curatedList => {
773774
assert.equal(curatedList.length, 0);
774775
});
775776
});
776777
});
777778

779+
test('Maps action2 to action.', () => {
780+
experimentData = {
781+
experiments: [
782+
{
783+
id: 'experiment1',
784+
enabled: false,
785+
action2: {
786+
type: 'Prompt',
787+
properties: {
788+
promptText: 'Hello world',
789+
commands: []
790+
}
791+
}
792+
}
793+
]
794+
};
795+
796+
testObject = instantiationService.createInstance(TestExperimentService);
797+
return testObject.getExperimentById('experiment1').then(result => {
798+
assert.equal(result.action?.type, 'Prompt');
799+
});
800+
});
801+
778802
test('Experiment that is disabled or deleted should be removed from storage', () => {
779803
experimentData = {
780804
experiments: [

0 commit comments

Comments
 (0)