Skip to content

Commit

Permalink
Support iOS in finch tracker & griffin.brave.com
Browse files Browse the repository at this point in the history
  • Loading branch information
atuchin-m committed Oct 25, 2023
1 parent 3e43b3e commit 2986f7c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/core/base_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ export class ProcessingOptions {
// taken from API.
// Studies that target to older versions are considered as outdated.
minMajorVersion: number;

// True if study is originated from Brave (Griffin), false for upstream.
isBraveSeed: boolean;
}
19 changes: 13 additions & 6 deletions src/core/study_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import { variations as proto } from '../proto/generated/proto_bundle';
import { type ProcessingOptions } from './base_types';
import { matchesMaxVersion, parseVersionPattern } from './version';

const SUPPORTED_PLATFORMS: readonly proto.Study.Platform[] = [
const UPSTREAM_SUPPORTED_PLATFORMS: readonly proto.Study.Platform[] = [
proto.Study.Platform.PLATFORM_ANDROID,
proto.Study.Platform.PLATFORM_LINUX,
proto.Study.Platform.PLATFORM_MAC,
proto.Study.Platform.PLATFORM_WINDOWS,
];

const BRAVE_SUPPORTED_PLATFORMS: readonly proto.Study.Platform[] =
UPSTREAM_SUPPORTED_PLATFORMS.concat([proto.Study.Platform.PLATFORM_IOS]);

export enum StudyChannelTarget {
// filter.channel includes DEV or CANNERY, doesn't include STABLE or BETA.
DEV_OR_CANARY,
Expand Down Expand Up @@ -88,7 +91,7 @@ export class ProcessedStudy {
this.study = study;
this.studyDetails = new StudyDetails(study, options);
this.affectedFeatures = getAffectedFeatures(study);
this.postProcessStudy();
this.postProcessStudy(options);
}

getPriority(): StudyPriority {
Expand All @@ -111,14 +114,14 @@ export class ProcessedStudy {
details.maxNonDefaultIndex = 0;
}

postProcessStudy(): void {
postProcessStudy(options: ProcessingOptions): void {
this.study.filter?.channel?.sort();
this.study.filter?.platform?.sort();
this.study.filter?.country?.sort();
this.study.filter?.locale?.sort();
const filter = this.study.filter;
if (filter != null) {
filter.platform = filterPlatforms(filter);
filter.platform = filterPlatforms(filter, options.isBraveSeed);
}
}

Expand Down Expand Up @@ -228,7 +231,7 @@ export class StudyDetails {
e.feature_association?.enable_feature.length === 0;
}

const filteredPlatforms = filterPlatforms(filter);
const filteredPlatforms = filterPlatforms(filter, options.isBraveSeed);
if (filteredPlatforms === undefined || filteredPlatforms.length === 0) {
this.hasNoSupportedPlatform = true;
}
Expand Down Expand Up @@ -309,10 +312,14 @@ function areFeaturesInDefaultStates(e: proto.Study.IExperiment): boolean {

function filterPlatforms(
f: proto.Study.IFilter | undefined | null,
isBraveSeed: boolean,
): proto.Study.Platform[] | undefined {
const platform = f?.platform;
if (platform == null) return undefined;
return platform.filter((p) => SUPPORTED_PLATFORMS.includes(p));
const supportedPlatforms = isBraveSeed
? BRAVE_SUPPORTED_PLATFORMS
: UPSTREAM_SUPPORTED_PLATFORMS;
return platform.filter((p) => supportedPlatforms.includes(p));
}

// Processes a list of studies and groups it according to study.name.
Expand Down
1 change: 1 addition & 0 deletions src/finch_tracker/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async function main(): Promise<void> {

const options: ProcessingOptions = {
minMajorVersion,
isBraveSeed: false,
};

const outputFile = program.opts().output;
Expand Down
7 changes: 5 additions & 2 deletions src/finch_tracker/tracker_lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ function serialize(json: Record<string, any>) {

test('seed serialization', () => {
const data = fs.readFileSync('test/data/seed1.bin');
const map = serializeStudies(data, { minMajorVersion: 116 });
const map = serializeStudies(data, {
minMajorVersion: 116,
isBraveSeed: true,
});
const serializedOutput = serialize(map);

const serializedExpectations = fs
Expand Down Expand Up @@ -87,7 +90,7 @@ describe('summary', () => {
const summary = makeSummary(
oldSeed,
newSeed,
{ minMajorVersion: 116 },
{ minMajorVersion: 116, isBraveSeed: true },
StudyPriority.STABLE_MIN,
);

Expand Down
7 changes: 4 additions & 3 deletions src/web/app/seed_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ async function loadSeedFromUrl(url: string, type: SeedType) {
const data = await loadFile(url, 'arraybuffer');
const seedBytes = new Uint8Array(data);
const seed = proto.VariationsSeed.decode(seedBytes);
const isBrave = type !== SeedType.UPSTREAM;
const isBraveSeed = type !== SeedType.UPSTREAM;

// Desktop/Android could use a different major chrome version.
// Use -1 version for Brave studies to make sure that we don't cut
// anything important.
const minMajorVersion = (await getCurrentMajorVersion) - (isBrave ? 1 : 0);
const options: ProcessingOptions = { minMajorVersion };
const minMajorVersion =
(await getCurrentMajorVersion) - (isBraveSeed ? 1 : 0);
const options: ProcessingOptions = { minMajorVersion, isBraveSeed };
const studies: StudyModel[] = [];
seed.study.forEach((study, index) => {
const processed = new ProcessedStudy(study, options);
Expand Down
12 changes: 9 additions & 3 deletions src/web/app/study_model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { SeedType } from '../../core/base_types';

function makeStudyModel(properties: proto.IStudy) {
const study = new proto.Study(properties);
const processed = new ProcessedStudy(study, { minMajorVersion: 116 });
const processed = new ProcessedStudy(study, {
minMajorVersion: 116,
isBraveSeed: true,
});
const randomID = Math.floor(Math.random() * 1000000);
return new StudyModel(processed, SeedType.PRODUCTION, randomID);
}
Expand Down Expand Up @@ -43,7 +46,10 @@ describe('models', () => {
],
filter: {
channel: [proto.Study.Channel.STABLE, proto.Study.Channel.CANARY],
platform: [proto.Study.Platform.PLATFORM_WINDOWS],
platform: [
proto.Study.Platform.PLATFORM_WINDOWS,
proto.Study.Platform.PLATFORM_IOS,
],
},
});

Expand Down Expand Up @@ -82,7 +88,7 @@ describe('models', () => {
expect(studyList.filterStudies(filter).length).toBe(1);

expect(study1.channels()).toStrictEqual(['NIGHTLY', 'RELEASE']);
expect(study1.platforms()).toStrictEqual(['WINDOWS']);
expect(study1.platforms()).toStrictEqual(['WINDOWS', 'IOS']);
const experiments = study1.filterExperiments(filter);
expect(experiments.length).toBe(2);
expect(experiments[0].name()).toBe('Enabled');
Expand Down

0 comments on commit 2986f7c

Please sign in to comment.