提交 b76d3f01 编写于 作者: C Connor Peet

experiments: rename to action2 for new experiments

上级 4c59cdd2
......@@ -93,7 +93,7 @@ interface IExperimentStorageState {
* be incremented when adding a condition, otherwise experiments might activate
* on older versions of VS Code where not intended.
*/
export const currentSchemaVersion = 2;
export const currentSchemaVersion = 3;
interface IRawExperiment {
id: string;
......@@ -128,6 +128,7 @@ interface IRawExperiment {
userProbability?: number;
};
action?: IExperimentAction;
action2?: IExperimentAction;
}
interface IActivationEventRecord {
......@@ -310,10 +311,11 @@ export class ExperimentService extends Disposable implements IExperimentService
state: !!experiment.enabled ? ExperimentState.Evaluating : ExperimentState.NoRun
};
if (experiment.action) {
const action = experiment.action2 || experiment.action;
if (action) {
processedExperiment.action = {
type: ExperimentActionType[experiment.action.type] || ExperimentActionType.Custom,
properties: experiment.action.properties
type: ExperimentActionType[action.type] || ExperimentActionType.Custom,
properties: action.properties
};
if (processedExperiment.action.type === ExperimentActionType.Prompt) {
((<IExperimentActionPromptProperties>processedExperiment.action.properties).commands || []).forEach(x => {
......@@ -557,7 +559,7 @@ export class ExperimentService extends Disposable implements IExperimentService
if (typeof latestExperimentState.editCount === 'number' && latestExperimentState.editCount >= fileEdits.minEditCount) {
processedExperiment.state = latestExperimentState.state = (typeof condition.userProbability === 'number' && Math.random() < condition.userProbability && this.checkExperimentDependencies(experiment)) ? ExperimentState.Run : ExperimentState.NoRun;
this.storageService.store(storageKey, JSON.stringify(latestExperimentState), StorageScope.GLOBAL);
if (latestExperimentState.state === ExperimentState.Run && experiment.action && ExperimentActionType[experiment.action.type] === ExperimentActionType.Prompt) {
if (latestExperimentState.state === ExperimentState.Run && processedExperiment.action && ExperimentActionType[processedExperiment.action.type] === ExperimentActionType.Prompt) {
this.fireRunExperiment(processedExperiment);
}
}
......
......@@ -768,6 +768,7 @@ suite('Experiment Service', () => {
testObject = instantiationService.createInstance(TestExperimentService);
return testObject.getExperimentById('experiment1').then(result => {
assert.equal(result.enabled, false);
assert.equal(result.action?.type, 'Prompt');
assert.equal(result.state, ExperimentState.NoRun);
return testObject.getCuratedExtensionsList(curatedExtensionsKey).then(curatedList => {
assert.equal(curatedList.length, 0);
......@@ -775,6 +776,29 @@ suite('Experiment Service', () => {
});
});
test('Maps action2 to action.', () => {
experimentData = {
experiments: [
{
id: 'experiment1',
enabled: false,
action2: {
type: 'Prompt',
properties: {
promptText: 'Hello world',
commands: []
}
}
}
]
};
testObject = instantiationService.createInstance(TestExperimentService);
return testObject.getExperimentById('experiment1').then(result => {
assert.equal(result.action?.type, 'Prompt');
});
});
test('Experiment that is disabled or deleted should be removed from storage', () => {
experimentData = {
experiments: [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册