From 09f6d479576eeb1209e390a57459aee0cb3d0b8c Mon Sep 17 00:00:00 2001 From: Aleksei Khoroshilov <5928869+goodov@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:24:42 +0700 Subject: [PATCH] Use json5 for studies storage (#1227) Replace `JSON.parse/stringify` with `JSON5.parser/stringify`, also remove prefix `PLATFORM_` from platforms. --- .prettierrc.js | 8 ++ package-lock.json | 136 +++++++++++++++++- package.json | 2 + src/seed_tools/commands/create.test.ts | 3 + src/seed_tools/commands/lint.test.ts | 7 +- src/seed_tools/commands/split_seed_json.ts | 2 +- src/seed_tools/utils/study_json_utils.test.ts | 35 +++-- src/seed_tools/utils/study_json_utils.ts | 20 ++- .../test1/studies/AnotherTestStudy.json | 26 ---- .../test1/studies/AnotherTestStudy.json5 | 26 ++++ .../test1/studies/TestStudy.json | 36 ----- .../test1/studies/TestStudy.json5 | 36 +++++ .../test2/studies/AnotherTestStudy.json | 26 ---- .../test2/studies/AnotherTestStudy.json5 | 26 ++++ .../test2/studies/TestStudy.json | 37 ----- .../test2/studies/TestStudy.json5 | 37 +++++ .../test2/studies/ThirdStudy.json | 34 ----- .../test2/studies/ThirdStudy.json5 | 34 +++++ .../test1/studies/TestStudy.json | 28 ---- .../test1/studies/TestStudy.json5 | 28 ++++ .../test2/studies/TestStudy.json | 24 ---- .../test2/studies/TestStudy.json5 | 24 ++++ .../test3/studies/TestStudy.json | 21 --- .../test3/studies/TestStudy.json5 | 21 +++ .../set_seed_version/studies/TestStudy.json | 43 ------ .../set_seed_version/studies/TestStudy.json5 | 43 ++++++ .../test1/expected_output.txt | 50 +++---- .../test1/studies/TestStudy.json | 43 ------ .../test1/studies/TestStudy.json5 | 43 ++++++ .../valid_seeds/test1/studies/TestStudy.json | 43 ------ .../valid_seeds/test1/studies/TestStudy.json5 | 43 ++++++ .../test2/studies/AnotherTestStudy.json | 38 ----- .../test2/studies/AnotherTestStudy.json5 | 38 +++++ .../valid_seeds/test2/studies/TestStudy.json | 43 ------ .../valid_seeds/test2/studies/TestStudy.json5 | 43 ++++++ .../test3/studies/AnotherTestStudy.json | 74 ---------- .../test3/studies/AnotherTestStudy.json5 | 74 ++++++++++ .../valid_seeds/test3/studies/TestStudy.json | 43 ------ .../valid_seeds/test3/studies/TestStudy.json5 | 43 ++++++ 39 files changed, 774 insertions(+), 607 deletions(-) delete mode 100644 src/test/data/invalid_seeds/test1/studies/AnotherTestStudy.json create mode 100644 src/test/data/invalid_seeds/test1/studies/AnotherTestStudy.json5 delete mode 100644 src/test/data/invalid_seeds/test1/studies/TestStudy.json create mode 100644 src/test/data/invalid_seeds/test1/studies/TestStudy.json5 delete mode 100644 src/test/data/invalid_seeds/test2/studies/AnotherTestStudy.json create mode 100644 src/test/data/invalid_seeds/test2/studies/AnotherTestStudy.json5 delete mode 100644 src/test/data/invalid_seeds/test2/studies/TestStudy.json create mode 100644 src/test/data/invalid_seeds/test2/studies/TestStudy.json5 delete mode 100644 src/test/data/invalid_seeds/test2/studies/ThirdStudy.json create mode 100644 src/test/data/invalid_seeds/test2/studies/ThirdStudy.json5 delete mode 100644 src/test/data/invalid_studies/test1/studies/TestStudy.json create mode 100644 src/test/data/invalid_studies/test1/studies/TestStudy.json5 delete mode 100644 src/test/data/invalid_studies/test2/studies/TestStudy.json create mode 100644 src/test/data/invalid_studies/test2/studies/TestStudy.json5 delete mode 100644 src/test/data/invalid_studies/test3/studies/TestStudy.json create mode 100644 src/test/data/invalid_studies/test3/studies/TestStudy.json5 delete mode 100644 src/test/data/set_seed_version/studies/TestStudy.json create mode 100644 src/test/data/set_seed_version/studies/TestStudy.json5 delete mode 100644 src/test/data/unformatted_studies/test1/studies/TestStudy.json create mode 100644 src/test/data/unformatted_studies/test1/studies/TestStudy.json5 delete mode 100644 src/test/data/valid_seeds/test1/studies/TestStudy.json create mode 100644 src/test/data/valid_seeds/test1/studies/TestStudy.json5 delete mode 100644 src/test/data/valid_seeds/test2/studies/AnotherTestStudy.json create mode 100644 src/test/data/valid_seeds/test2/studies/AnotherTestStudy.json5 delete mode 100644 src/test/data/valid_seeds/test2/studies/TestStudy.json create mode 100644 src/test/data/valid_seeds/test2/studies/TestStudy.json5 delete mode 100644 src/test/data/valid_seeds/test3/studies/AnotherTestStudy.json create mode 100644 src/test/data/valid_seeds/test3/studies/AnotherTestStudy.json5 delete mode 100644 src/test/data/valid_seeds/test3/studies/TestStudy.json create mode 100644 src/test/data/valid_seeds/test3/studies/TestStudy.json5 diff --git a/.prettierrc.js b/.prettierrc.js index d4742643..93ee66ef 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -19,5 +19,13 @@ module.exports = { parser: 'json-stringify', }, }, + { + files: '*.json5', + options: { + // Sync with JSON5.stringify logic. + plugins: ['prettier-plugin-multiline-arrays'], + trailingComma: 'all', + }, + }, ], }; diff --git a/package-lock.json b/package-lock.json index a043e15b..d6bc2324 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "license": "MPL-2.0", "dependencies": { "@protobuf-ts/runtime": "2.9.4", + "json5": "2.2.3", "react": "18.3.1", "react-dom": "18.3.1", "react-router": "6.27.0", @@ -36,6 +37,7 @@ "jest": "29.7.0", "lint-staged": "15.2.10", "prettier": "3.3.3", + "prettier-plugin-multiline-arrays": "3.0.6", "prettier-plugin-organize-imports": "3.2.4", "protobufjs": "7.4.0", "protobufjs-cli": "1.1.3", @@ -64,6 +66,31 @@ "node": ">=6.0.0" } }, + "node_modules/@augment-vir/common": { + "version": "28.2.4", + "resolved": "https://registry.npmjs.org/@augment-vir/common/-/common-28.2.4.tgz", + "integrity": "sha512-5Ib0OX7YlxAuFrG+MAoTsz6RlKMcbdMdoNGcEEKH/ezc/ZKMy/IHZ9Z/ZcCHYopZ4ocGXzVY4KUOiJ8+CXXvTA==", + "dev": true, + "license": "MIT", + "dependencies": { + "browser-or-node": "^3.0.0", + "run-time-assertions": "^1.5.1", + "type-fest": "^4.20.1" + } + }, + "node_modules/@augment-vir/common/node_modules/type-fest": { + "version": "4.26.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.26.1.tgz", + "integrity": "sha512-yOGpmOAL7CkKe/91I5O3gPICmJNLJ1G4zFYVAsRHg7M64biSnPtRj0WNQt++bRkjYOqjWXrhnUw1utzmVErAdg==", + "dev": true, + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@babel/code-frame": { "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", @@ -3398,6 +3425,13 @@ "node": ">=8" } }, + "node_modules/browser-or-node": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/browser-or-node/-/browser-or-node-3.0.0.tgz", + "integrity": "sha512-iczIdVJzGEYhP5DqQxYM9Hh7Ztpqqi+CXZpSmX8ALFs9ecXkQIeqRyM6TfxEfMVpwhl3dSuDvxdzzo9sUOIVBQ==", + "dev": true, + "license": "MIT" + }, "node_modules/browserslist": { "version": "4.23.3", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.23.3.tgz", @@ -5090,6 +5124,13 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/expect-type": { + "version": "0.15.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-0.15.0.tgz", + "integrity": "sha512-yWnriYB4e8G54M5/fAFj7rCIBiKs1HAACaY13kCz6Ku0dezjS9aMcfcdVK2X8Tv2tEV1BPz/wKfQ7WA4S/d8aA==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/express": { "version": "4.21.1", "resolved": "https://registry.npmjs.org/express/-/express-4.21.1.tgz", @@ -7519,7 +7560,6 @@ "version": "2.2.3", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", - "dev": true, "license": "MIT", "bin": { "json5": "lib/cli.js" @@ -9021,6 +9061,20 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/prettier-plugin-multiline-arrays": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/prettier-plugin-multiline-arrays/-/prettier-plugin-multiline-arrays-3.0.6.tgz", + "integrity": "sha512-FrWVa7MoDQo9b5XoLPrqIDClb0k+O8wOIsIr1DutRXhcerLY8PfIe/yYeTVD/vpRISkSXCBEYmj5Voe0wb5dEQ==", + "dev": true, + "license": "(MIT or CC0 1.0)", + "dependencies": { + "@augment-vir/common": "^28.1.0", + "proxy-vir": "^1.0.0" + }, + "peerDependencies": { + "prettier": ">=3.0.0" + } + }, "node_modules/prettier-plugin-organize-imports": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/prettier-plugin-organize-imports/-/prettier-plugin-organize-imports-3.2.4.tgz", @@ -9222,6 +9276,48 @@ "node": ">= 0.10" } }, + "node_modules/proxy-vir": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/proxy-vir/-/proxy-vir-1.0.0.tgz", + "integrity": "sha512-WV1gkBxUOwLSz0Bn09tisIqLK7leAqtFm/474t3L0hQKJw7/gdrkGcWw0/OT1PhSy+TDS6swfq7Niuoq3XJhkQ==", + "dev": true, + "license": "(MIT or CC0 1.0)", + "dependencies": { + "@augment-vir/common": "^23.3.4" + } + }, + "node_modules/proxy-vir/node_modules/@augment-vir/common": { + "version": "23.4.0", + "resolved": "https://registry.npmjs.org/@augment-vir/common/-/common-23.4.0.tgz", + "integrity": "sha512-QIrJ1doD00TNbOzeVrk9KgPTzRlIjayxERnhtbQjK/AFPj5yElcB03GbnGdQZPzws/R+5gfMM5cZiH7QyBP+Kg==", + "dev": true, + "license": "MIT", + "dependencies": { + "browser-or-node": "^2.1.1", + "run-time-assertions": "^1.0.0", + "type-fest": "^4.10.2" + } + }, + "node_modules/proxy-vir/node_modules/browser-or-node": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/browser-or-node/-/browser-or-node-2.1.1.tgz", + "integrity": "sha512-8CVjaLJGuSKMVTxJ2DpBl5XnlNDiT4cQFeuCJJrvJmts9YrTZDizTX7PjC2s6W4x+MBGZeEY6dGMrF04/6Hgqg==", + "dev": true, + "license": "MIT" + }, + "node_modules/proxy-vir/node_modules/type-fest": { + "version": "4.26.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.26.1.tgz", + "integrity": "sha512-yOGpmOAL7CkKe/91I5O3gPICmJNLJ1G4zFYVAsRHg7M64biSnPtRj0WNQt++bRkjYOqjWXrhnUw1utzmVErAdg==", + "dev": true, + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -9726,6 +9822,44 @@ "queue-microtask": "^1.2.2" } }, + "node_modules/run-time-assertions": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/run-time-assertions/-/run-time-assertions-1.5.2.tgz", + "integrity": "sha512-ccfwvjGuNU14cSSXLlmPRiqEgMfA7w3J2TViO79zMnzXGvE6FJ0dxnhIQGwe5r/vwySOJ4sqZksexo9wyAlA8g==", + "deprecated": "Use @augment-vir/assert instead.", + "dev": true, + "license": "(MIT or CC0 1.0)", + "dependencies": { + "@augment-vir/common": "^29.3.0", + "expect-type": "~0.15.0", + "type-fest": "^4.22.0" + } + }, + "node_modules/run-time-assertions/node_modules/@augment-vir/common": { + "version": "29.3.0", + "resolved": "https://registry.npmjs.org/@augment-vir/common/-/common-29.3.0.tgz", + "integrity": "sha512-k3OX35/576thmGUzQUBcCKGarb7ONBfiu07+iV2vxmjl7VoB1rOB0vu8WqgB1ceJq2EMLDPXY18hHpJ9WeTHXQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "browser-or-node": "^3.0.0", + "run-time-assertions": "^1.5.1", + "type-fest": "^4.21.0" + } + }, + "node_modules/run-time-assertions/node_modules/type-fest": { + "version": "4.26.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.26.1.tgz", + "integrity": "sha512-yOGpmOAL7CkKe/91I5O3gPICmJNLJ1G4zFYVAsRHg7M64biSnPtRj0WNQt++bRkjYOqjWXrhnUw1utzmVErAdg==", + "dev": true, + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/safe-array-concat": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/safe-array-concat/-/safe-array-concat-1.1.2.tgz", diff --git a/package.json b/package.json index 96fb7e40..4bad09a3 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "jest": "29.7.0", "lint-staged": "15.2.10", "prettier": "3.3.3", + "prettier-plugin-multiline-arrays": "3.0.6", "prettier-plugin-organize-imports": "3.2.4", "protobufjs": "7.4.0", "protobufjs-cli": "1.1.3", @@ -54,6 +55,7 @@ "moduleResolution": "node", "dependencies": { "@protobuf-ts/runtime": "2.9.4", + "json5": "2.2.3", "react": "18.3.1", "react-dom": "18.3.1", "react-router": "6.27.0", diff --git a/src/seed_tools/commands/create.test.ts b/src/seed_tools/commands/create.test.ts index 29fdca85..93bcac97 100644 --- a/src/seed_tools/commands/create.test.ts +++ b/src/seed_tools/commands/create.test.ts @@ -15,6 +15,7 @@ describe('create command', () => { const testDataDir = wsPath('//src/test/data'); let tempDir: string; + let logMock: jest.SpyInstance; let exitMock: jest.SpyInstance; let errorMock: jest.SpyInstance; @@ -23,11 +24,13 @@ describe('create command', () => { exitMock = jest.spyOn(process, 'exit').mockImplementation((code) => { throw new Error(`process.exit(${code})`); }); + logMock = jest.spyOn(console, 'log').mockImplementation(); errorMock = jest.spyOn(console, 'error').mockImplementation(); }); afterEach(async () => { await fs.rm(tempDir, { recursive: true, force: true }); + logMock.mockRestore(); exitMock.mockRestore(); errorMock.mockRestore(); }); diff --git a/src/seed_tools/commands/lint.test.ts b/src/seed_tools/commands/lint.test.ts index e56446d3..6f32bbec 100644 --- a/src/seed_tools/commands/lint.test.ts +++ b/src/seed_tools/commands/lint.test.ts @@ -16,6 +16,7 @@ describe('lint command', () => { let tempDir: string; let exitMock: jest.SpyInstance; + let logMock: jest.SpyInstance; let errorMock: jest.SpyInstance; beforeEach(async () => { @@ -23,11 +24,13 @@ describe('lint command', () => { exitMock = jest.spyOn(process, 'exit').mockImplementation((code) => { throw new Error(`process.exit(${code})`); }); + logMock = jest.spyOn(console, 'log').mockImplementation(); errorMock = jest.spyOn(console, 'error').mockImplementation(); }); afterEach(async () => { await fs.rm(tempDir, { recursive: true, force: true }); + logMock.mockRestore(); exitMock.mockRestore(); errorMock.mockRestore(); }); @@ -86,8 +89,8 @@ describe('lint command', () => { // copy the unformatted studies to a temp dir await fs.mkdir(tempStudiesDir); await fs.copyFile( - path.join(studiesDir, 'TestStudy.json'), - path.join(tempStudiesDir, 'TestStudy.json'), + path.join(studiesDir, 'TestStudy.json5'), + path.join(tempStudiesDir, 'TestStudy.json5'), ); // lint should fail. diff --git a/src/seed_tools/commands/split_seed_json.ts b/src/seed_tools/commands/split_seed_json.ts index d93b293f..c4ef357a 100644 --- a/src/seed_tools/commands/split_seed_json.ts +++ b/src/seed_tools/commands/split_seed_json.ts @@ -48,7 +48,7 @@ async function main(seedPath: string, outputDir: string) { for (const study of studies) { const studyName = study[0]; const studyArray = study[1]; - const studyFile = `${outputDir}/${studyName}.json`; + const studyFile = `${outputDir}/${studyName}.json5`; await study_json_utils.writeStudyFile(studyArray, studyFile); } } diff --git a/src/seed_tools/utils/study_json_utils.test.ts b/src/seed_tools/utils/study_json_utils.test.ts index 610d6aad..9c29d313 100644 --- a/src/seed_tools/utils/study_json_utils.test.ts +++ b/src/seed_tools/utils/study_json_utils.test.ts @@ -3,6 +3,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can obtain one at https://mozilla.org/MPL/2.0/. +import JSON5 from 'json5'; import { Study, Study_Channel, @@ -26,7 +27,7 @@ describe('stringifyStudies', () => { ); const stringifiedStudyArray = stringifyStudies([study]); - expect(JSON.parse(stringifiedStudyArray)).toEqual([ + expect(JSON5.parse(stringifiedStudyArray)).toEqual([ { name: 'study', filter: { @@ -37,23 +38,25 @@ describe('stringifyStudies', () => { ]); }); - it('should convert channel values', () => { + it('should convert channel, platform values', () => { const study = Study.fromJson( { name: 'study', filter: { channel: ['CANARY', 'BETA', 'STABLE'], + platform: ['PLATFORM_LINUX', 'PLATFORM_MAC'], }, }, { ignoreUnknownFields: false }, ); const stringifiedStudyArray = stringifyStudies([study]); - expect(JSON.parse(stringifiedStudyArray)).toEqual([ + expect(JSON5.parse(stringifiedStudyArray)).toEqual([ { name: 'study', filter: { channel: ['NIGHTLY', 'BETA', 'RELEASE'], + platform: ['LINUX', 'MAC'], }, }, ]); @@ -73,7 +76,7 @@ describe('stringifyStudies', () => { }, ], filter: { - platform: ['PLATFORM_WINDOWS', 'PLATFORM_MAC'], + platform: ['WINDOWS', 'MAC'], channel: ['CANARY', 'BETA', 'STABLE'], }, }, @@ -81,7 +84,7 @@ describe('stringifyStudies', () => { ); const stringifiedStudyArray = stringifyStudies([study]); - expect(JSON.parse(stringifiedStudyArray)).toEqual([ + expect(JSON5.parse(stringifiedStudyArray)).toEqual([ { name: 'BraveHorizontalTabsUpdateEnabledStudy', experiment: [ @@ -95,13 +98,13 @@ describe('stringifyStudies', () => { ], filter: { channel: ['NIGHTLY', 'BETA', 'RELEASE'], - platform: ['PLATFORM_WINDOWS', 'PLATFORM_MAC'], + platform: ['WINDOWS', 'MAC'], }, }, ]); }); - it('chromium mode should keep channel values', () => { + it('chromium mode should not modify channel, platform values', () => { const startDate = new Date('2022-01-01T00:00:00Z'); const study = Study.fromJson( { @@ -109,6 +112,7 @@ describe('stringifyStudies', () => { filter: { start_date: Math.floor(startDate.getTime() / 1000), channel: ['CANARY', 'BETA', 'STABLE'], + platform: ['PLATFORM_LINUX', 'PLATFORM_MAC'], }, }, { ignoreUnknownFields: false }, @@ -117,12 +121,13 @@ describe('stringifyStudies', () => { const stringifiedStudyArray = stringifyStudies([study], { isChromium: true, }); - expect(JSON.parse(stringifiedStudyArray)).toEqual([ + expect(JSON5.parse(stringifiedStudyArray)).toEqual([ { name: 'study', filter: { start_date: startDate.toISOString(), channel: ['CANARY', 'BETA', 'STABLE'], + platform: ['PLATFORM_LINUX', 'PLATFORM_MAC'], }, }, ]); @@ -134,7 +139,7 @@ describe('parseStudies', () => { const startDate = '2022-01-01T00:00:00.000Z'; const endDate = '2022-12-31T23:59:59.999Z'; - const study = JSON.stringify([ + const study = JSON5.stringify([ { name: 'study', filter: { @@ -156,7 +161,7 @@ describe('parseStudies', () => { it('should throw an error for invalid start_date or end_date format', () => { const parseStudyWithFilter = (filter: any) => { return parseStudies( - JSON.stringify([ + JSON5.stringify([ { name: 'study', filter, @@ -177,7 +182,7 @@ describe('parseStudies', () => { }); it('should convert channel values from NIGHTLY to CANARY and RELEASE to STABLE', () => { - const study = JSON.stringify([ + const study = JSON5.stringify([ { name: 'study', filter: { @@ -195,12 +200,12 @@ describe('parseStudies', () => { }); it('should not modify other keys', () => { - const study = JSON.stringify([ + const study = JSON5.stringify([ { name: 'study', filter: { channel: ['RELEASE', 'BETA', 'NIGHTLY'], - platform: ['PLATFORM_WINDOWS', 'PLATFORM_MAC'], + platform: ['WINDOWS', 'MAC'], }, }, ]); @@ -240,7 +245,7 @@ describe('parseStudies', () => { const invalidStudyArrayString = 'invalid'; expect(() => parseStudies(invalidStudyArrayString)).toThrowError( - 'Unexpected token', + 'invalid character', ); }); @@ -270,7 +275,7 @@ describe('parseStudies', () => { }); it('chromium mode should keep channel values', () => { - const study = JSON.stringify([ + const study = JSON5.stringify([ { name: 'study', filter: { diff --git a/src/seed_tools/utils/study_json_utils.ts b/src/seed_tools/utils/study_json_utils.ts index 914b434c..15f567ba 100644 --- a/src/seed_tools/utils/study_json_utils.ts +++ b/src/seed_tools/utils/study_json_utils.ts @@ -4,6 +4,7 @@ // You can obtain one at https://mozilla.org/MPL/2.0/. import { promises as fs } from 'fs'; +import JSON5 from 'json5'; import { Study } from '../../proto/generated/study'; export interface Options { @@ -46,7 +47,7 @@ export function parseStudies( studyArrayString: string, options?: Options, ): Study[] { - const jsonStudies = JSON.parse( + const jsonStudies = JSON5.parse( studyArrayString, jsonStudyReviever.bind(null, options), ); @@ -79,7 +80,8 @@ export function stringifyStudies(studies: Study[], options?: Options): string { // Use 2 spaces for indentation and add a newline at the end to match Prettier // `json-stringify` behaviour. return ( - JSON.stringify(jsonStudies, jsonStudyReplacer.bind(null, options), 2) + '\n' + JSON5.stringify(jsonStudies, jsonStudyReplacer.bind(null, options), 2) + + '\n' ); } @@ -106,6 +108,13 @@ function jsonStudyReplacer( } return value; }); + case 'platform': + if (options?.isChromium === true) { + return value; + } + return value.map((value: string): string => { + return value.replace(/^PLATFORM_/, ''); + }); default: return value; } @@ -142,6 +151,13 @@ function jsonStudyReviever( } return value; }); + case 'platform': + if (options?.isChromium === true) { + return value; + } + return value.map((value: string): string => { + return `PLATFORM_${value}`; + }); default: return value; } diff --git a/src/test/data/invalid_seeds/test1/studies/AnotherTestStudy.json b/src/test/data/invalid_seeds/test1/studies/AnotherTestStudy.json deleted file mode 100644 index 6adad4a9..00000000 --- a/src/test/data/invalid_seeds/test1/studies/AnotherTestStudy.json +++ /dev/null @@ -1,26 +0,0 @@ -[ - { - "name": "AnotherTestStudy", - "experiment": [ - { - "name": "Disabled", - "probability_weight": 100, - "feature_association": { - "disable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Default", - "probability_weight": 0 - } - ], - "filter": { - "min_version": "120.*", - "platform": [ - "PLATFORM_WINDOWS" - ] - } - } -] diff --git a/src/test/data/invalid_seeds/test1/studies/AnotherTestStudy.json5 b/src/test/data/invalid_seeds/test1/studies/AnotherTestStudy.json5 new file mode 100644 index 00000000..9f1a3354 --- /dev/null +++ b/src/test/data/invalid_seeds/test1/studies/AnotherTestStudy.json5 @@ -0,0 +1,26 @@ +[ + { + name: 'AnotherTestStudy', + experiment: [ + { + name: 'Disabled', + probability_weight: 100, + feature_association: { + disable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Default', + probability_weight: 0, + }, + ], + filter: { + min_version: '120.*', + platform: [ + 'WINDOWS', + ], + }, + }, +] diff --git a/src/test/data/invalid_seeds/test1/studies/TestStudy.json b/src/test/data/invalid_seeds/test1/studies/TestStudy.json deleted file mode 100644 index fea8b66f..00000000 --- a/src/test/data/invalid_seeds/test1/studies/TestStudy.json +++ /dev/null @@ -1,36 +0,0 @@ -[ - { - "name": "TestStudy", - "experiment": [ - { - "name": "Enabled", - "probability_weight": 100, - "feature_association": { - "enable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Disabled", - "probability_weight": 0, - "feature_association": { - "disable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Default", - "probability_weight": 0 - } - ], - "filter": { - "max_version": "120.0.0.1", - "platform": [ - "PLATFORM_MAC", - "PLATFORM_WINDOWS" - ] - } - } -] diff --git a/src/test/data/invalid_seeds/test1/studies/TestStudy.json5 b/src/test/data/invalid_seeds/test1/studies/TestStudy.json5 new file mode 100644 index 00000000..dacfc3b4 --- /dev/null +++ b/src/test/data/invalid_seeds/test1/studies/TestStudy.json5 @@ -0,0 +1,36 @@ +[ + { + name: 'TestStudy', + experiment: [ + { + name: 'Enabled', + probability_weight: 100, + feature_association: { + enable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Disabled', + probability_weight: 0, + feature_association: { + disable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Default', + probability_weight: 0, + }, + ], + filter: { + max_version: '120.0.0.1', + platform: [ + 'MAC', + 'WINDOWS', + ], + }, + }, +] diff --git a/src/test/data/invalid_seeds/test2/studies/AnotherTestStudy.json b/src/test/data/invalid_seeds/test2/studies/AnotherTestStudy.json deleted file mode 100644 index 6adad4a9..00000000 --- a/src/test/data/invalid_seeds/test2/studies/AnotherTestStudy.json +++ /dev/null @@ -1,26 +0,0 @@ -[ - { - "name": "AnotherTestStudy", - "experiment": [ - { - "name": "Disabled", - "probability_weight": 100, - "feature_association": { - "disable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Default", - "probability_weight": 0 - } - ], - "filter": { - "min_version": "120.*", - "platform": [ - "PLATFORM_WINDOWS" - ] - } - } -] diff --git a/src/test/data/invalid_seeds/test2/studies/AnotherTestStudy.json5 b/src/test/data/invalid_seeds/test2/studies/AnotherTestStudy.json5 new file mode 100644 index 00000000..9f1a3354 --- /dev/null +++ b/src/test/data/invalid_seeds/test2/studies/AnotherTestStudy.json5 @@ -0,0 +1,26 @@ +[ + { + name: 'AnotherTestStudy', + experiment: [ + { + name: 'Disabled', + probability_weight: 100, + feature_association: { + disable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Default', + probability_weight: 0, + }, + ], + filter: { + min_version: '120.*', + platform: [ + 'WINDOWS', + ], + }, + }, +] diff --git a/src/test/data/invalid_seeds/test2/studies/TestStudy.json b/src/test/data/invalid_seeds/test2/studies/TestStudy.json deleted file mode 100644 index 2cb2e9d4..00000000 --- a/src/test/data/invalid_seeds/test2/studies/TestStudy.json +++ /dev/null @@ -1,37 +0,0 @@ -[ - { - "name": "TestStudy", - "experiment": [ - { - "name": "Enabled", - "probability_weight": 100, - "feature_association": { - "enable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Disabled", - "probability_weight": 0, - "feature_association": { - "disable_feature": [ - "TestFeature", - "AnotherFeature" - ] - } - }, - { - "name": "Default", - "probability_weight": 0 - } - ], - "filter": { - "max_version": "119.0.0.1", - "platform": [ - "PLATFORM_MAC", - "PLATFORM_WINDOWS" - ] - } - } -] diff --git a/src/test/data/invalid_seeds/test2/studies/TestStudy.json5 b/src/test/data/invalid_seeds/test2/studies/TestStudy.json5 new file mode 100644 index 00000000..c4224920 --- /dev/null +++ b/src/test/data/invalid_seeds/test2/studies/TestStudy.json5 @@ -0,0 +1,37 @@ +[ + { + name: 'TestStudy', + experiment: [ + { + name: 'Enabled', + probability_weight: 100, + feature_association: { + enable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Disabled', + probability_weight: 0, + feature_association: { + disable_feature: [ + 'TestFeature', + 'AnotherFeature', + ], + }, + }, + { + name: 'Default', + probability_weight: 0, + }, + ], + filter: { + max_version: '119.0.0.1', + platform: [ + 'MAC', + 'WINDOWS', + ], + }, + }, +] diff --git a/src/test/data/invalid_seeds/test2/studies/ThirdStudy.json b/src/test/data/invalid_seeds/test2/studies/ThirdStudy.json deleted file mode 100644 index aa857d97..00000000 --- a/src/test/data/invalid_seeds/test2/studies/ThirdStudy.json +++ /dev/null @@ -1,34 +0,0 @@ -[ - { - "name": "ThirdStudy", - "experiment": [ - { - "name": "Enabled", - "probability_weight": 100, - "feature_association": { - "enable_feature": [ - "AnotherFeature" - ] - } - }, - { - "name": "Disabled", - "probability_weight": 0, - "feature_association": { - "disable_feature": [ - "AnotherFeature" - ] - } - }, - { - "name": "Default", - "probability_weight": 0 - } - ], - "filter": { - "platform": [ - "PLATFORM_MAC" - ] - } - } -] diff --git a/src/test/data/invalid_seeds/test2/studies/ThirdStudy.json5 b/src/test/data/invalid_seeds/test2/studies/ThirdStudy.json5 new file mode 100644 index 00000000..5e4dcda3 --- /dev/null +++ b/src/test/data/invalid_seeds/test2/studies/ThirdStudy.json5 @@ -0,0 +1,34 @@ +[ + { + name: 'ThirdStudy', + experiment: [ + { + name: 'Enabled', + probability_weight: 100, + feature_association: { + enable_feature: [ + 'AnotherFeature', + ], + }, + }, + { + name: 'Disabled', + probability_weight: 0, + feature_association: { + disable_feature: [ + 'AnotherFeature', + ], + }, + }, + { + name: 'Default', + probability_weight: 0, + }, + ], + filter: { + platform: [ + 'MAC', + ], + }, + }, +] diff --git a/src/test/data/invalid_studies/test1/studies/TestStudy.json b/src/test/data/invalid_studies/test1/studies/TestStudy.json deleted file mode 100644 index 30d6248c..00000000 --- a/src/test/data/invalid_studies/test1/studies/TestStudy.json +++ /dev/null @@ -1,28 +0,0 @@ -[ - { - "name": "TestStudy", - "experiment": [ - { - "name": "Enabled", - "feature_association": { - "enable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Disabled", - "probability_weight": 100, - "feature_association": { - "disable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Default", - "probability_weight": 0 - } - ] - } -] diff --git a/src/test/data/invalid_studies/test1/studies/TestStudy.json5 b/src/test/data/invalid_studies/test1/studies/TestStudy.json5 new file mode 100644 index 00000000..67c2b20b --- /dev/null +++ b/src/test/data/invalid_studies/test1/studies/TestStudy.json5 @@ -0,0 +1,28 @@ +[ + { + name: 'TestStudy', + experiment: [ + { + name: 'Enabled', + feature_association: { + enable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Disabled', + probability_weight: 100, + feature_association: { + disable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Default', + probability_weight: 0, + }, + ], + }, +] diff --git a/src/test/data/invalid_studies/test2/studies/TestStudy.json b/src/test/data/invalid_studies/test2/studies/TestStudy.json deleted file mode 100644 index 305ef892..00000000 --- a/src/test/data/invalid_studies/test2/studies/TestStudy.json +++ /dev/null @@ -1,24 +0,0 @@ -[ - { - "name": "TestStudy", - "experiment": [ - { - "name": "Enabled", - "probability_weight": 100, - "feature_association": { - "enable_feature": [ - "TestFeature" - ] - } - } - ], - "filter": { - "locale": [ - "en" - ], - "exclude_locale": [ - "en-US" - ] - } - } -] diff --git a/src/test/data/invalid_studies/test2/studies/TestStudy.json5 b/src/test/data/invalid_studies/test2/studies/TestStudy.json5 new file mode 100644 index 00000000..5715c92d --- /dev/null +++ b/src/test/data/invalid_studies/test2/studies/TestStudy.json5 @@ -0,0 +1,24 @@ +[ + { + name: 'TestStudy', + experiment: [ + { + name: 'Enabled', + probability_weight: 100, + feature_association: { + enable_feature: [ + 'TestFeature', + ], + }, + }, + ], + filter: { + locale: [ + 'en', + ], + exclude_locale: [ + 'en-US', + ], + }, + }, +] diff --git a/src/test/data/invalid_studies/test3/studies/TestStudy.json b/src/test/data/invalid_studies/test3/studies/TestStudy.json deleted file mode 100644 index 16db8b2c..00000000 --- a/src/test/data/invalid_studies/test3/studies/TestStudy.json +++ /dev/null @@ -1,21 +0,0 @@ -[ - { - "name": "TestStudy", - "experiment": [ - { - "name": "Enabled", - "probability_weight": 100, - "feature_association": { - "enable_feature": [ - "TestFeature" - ] - } - } - ], - "filter": { - "platform": [ - "PLATFORM_MACOS" - ] - } - } -] diff --git a/src/test/data/invalid_studies/test3/studies/TestStudy.json5 b/src/test/data/invalid_studies/test3/studies/TestStudy.json5 new file mode 100644 index 00000000..b4ec560e --- /dev/null +++ b/src/test/data/invalid_studies/test3/studies/TestStudy.json5 @@ -0,0 +1,21 @@ +[ + { + name: 'TestStudy', + experiment: [ + { + name: 'Enabled', + probability_weight: 100, + feature_association: { + enable_feature: [ + 'TestFeature', + ], + }, + }, + ], + filter: { + platform: [ + 'MACOS', + ], + }, + }, +] diff --git a/src/test/data/set_seed_version/studies/TestStudy.json b/src/test/data/set_seed_version/studies/TestStudy.json deleted file mode 100644 index ad5694dc..00000000 --- a/src/test/data/set_seed_version/studies/TestStudy.json +++ /dev/null @@ -1,43 +0,0 @@ -[ - { - "name": "TestStudy", - "experiment": [ - { - "name": "Enabled", - "probability_weight": 100, - "feature_association": { - "enable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Disabled", - "probability_weight": 0, - "feature_association": { - "disable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Default", - "probability_weight": 0 - } - ], - "filter": { - "min_version": "92.1.30.57", - "channel": [ - "NIGHTLY", - "BETA", - "RELEASE" - ], - "platform": [ - "PLATFORM_WINDOWS", - "PLATFORM_MAC", - "PLATFORM_LINUX", - "PLATFORM_ANDROID" - ] - } - } -] diff --git a/src/test/data/set_seed_version/studies/TestStudy.json5 b/src/test/data/set_seed_version/studies/TestStudy.json5 new file mode 100644 index 00000000..771ada3f --- /dev/null +++ b/src/test/data/set_seed_version/studies/TestStudy.json5 @@ -0,0 +1,43 @@ +[ + { + name: 'TestStudy', + experiment: [ + { + name: 'Enabled', + probability_weight: 100, + feature_association: { + enable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Disabled', + probability_weight: 0, + feature_association: { + disable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Default', + probability_weight: 0, + }, + ], + filter: { + min_version: '92.1.30.57', + channel: [ + 'NIGHTLY', + 'BETA', + 'RELEASE', + ], + platform: [ + 'WINDOWS', + 'MAC', + 'LINUX', + 'ANDROID', + ], + }, + }, +] diff --git a/src/test/data/unformatted_studies/test1/expected_output.txt b/src/test/data/unformatted_studies/test1/expected_output.txt index 42cf9421..3c1690a3 100644 --- a/src/test/data/unformatted_studies/test1/expected_output.txt +++ b/src/test/data/unformatted_studies/test1/expected_output.txt @@ -1,33 +1,29 @@ @@ -7,7 +7,7 @@ - "probability_weight": 100, - "feature_association": { - "enable_feature": [ -- "TestFeature" -+ "TestFeature" - ] - } + probability_weight: 100, + feature_association: { + enable_feature: [ +- 'TestFeature', ++ 'TestFeature', + ], + }, }, -@@ -21,19 +21,19 @@ - } +@@ -21,17 +21,17 @@ + }, }, { -- "probability_weight": 0, -- "name": "Default" -+ "name": "Default", -+ "probability_weight": 0 - } +- probability_weight: 0, + name: 'Default', ++ probability_weight: 0, + }, ], - "filter": { -+ "min_version": "92.1.30.57", - "channel": [ - "NIGHTLY", - "BETA", - "RELEASE" + filter: { ++ min_version: '92.1.30.57', + channel: [ + 'NIGHTLY', + 'BETA', + 'RELEASE', ], -- "min_version": "92.1.30.57", - "platform": [ -- "WINDOWS", -+ "PLATFORM_WINDOWS", - "PLATFORM_MAC", - "PLATFORM_LINUX", - "PLATFORM_ANDROID" +- min_version: '92.1.30.57', + platform: [ + 'WINDOWS', + 'MAC', diff --git a/src/test/data/unformatted_studies/test1/studies/TestStudy.json b/src/test/data/unformatted_studies/test1/studies/TestStudy.json deleted file mode 100644 index 26971c83..00000000 --- a/src/test/data/unformatted_studies/test1/studies/TestStudy.json +++ /dev/null @@ -1,43 +0,0 @@ -[ - { - "name": "TestStudy", - "experiment": [ - { - "name": "Enabled", - "probability_weight": 100, - "feature_association": { - "enable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Disabled", - "probability_weight": 0, - "feature_association": { - "disable_feature": [ - "TestFeature" - ] - } - }, - { - "probability_weight": 0, - "name": "Default" - } - ], - "filter": { - "channel": [ - "NIGHTLY", - "BETA", - "RELEASE" - ], - "min_version": "92.1.30.57", - "platform": [ - "WINDOWS", - "PLATFORM_MAC", - "PLATFORM_LINUX", - "PLATFORM_ANDROID" - ] - } - } -] diff --git a/src/test/data/unformatted_studies/test1/studies/TestStudy.json5 b/src/test/data/unformatted_studies/test1/studies/TestStudy.json5 new file mode 100644 index 00000000..863734ab --- /dev/null +++ b/src/test/data/unformatted_studies/test1/studies/TestStudy.json5 @@ -0,0 +1,43 @@ +[ + { + name: 'TestStudy', + experiment: [ + { + name: 'Enabled', + probability_weight: 100, + feature_association: { + enable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Disabled', + probability_weight: 0, + feature_association: { + disable_feature: [ + 'TestFeature', + ], + }, + }, + { + probability_weight: 0, + name: 'Default', + }, + ], + filter: { + channel: [ + 'NIGHTLY', + 'BETA', + 'RELEASE', + ], + min_version: '92.1.30.57', + platform: [ + 'WINDOWS', + 'MAC', + 'LINUX', + 'ANDROID', + ], + }, + }, +] diff --git a/src/test/data/valid_seeds/test1/studies/TestStudy.json b/src/test/data/valid_seeds/test1/studies/TestStudy.json deleted file mode 100644 index ad5694dc..00000000 --- a/src/test/data/valid_seeds/test1/studies/TestStudy.json +++ /dev/null @@ -1,43 +0,0 @@ -[ - { - "name": "TestStudy", - "experiment": [ - { - "name": "Enabled", - "probability_weight": 100, - "feature_association": { - "enable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Disabled", - "probability_weight": 0, - "feature_association": { - "disable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Default", - "probability_weight": 0 - } - ], - "filter": { - "min_version": "92.1.30.57", - "channel": [ - "NIGHTLY", - "BETA", - "RELEASE" - ], - "platform": [ - "PLATFORM_WINDOWS", - "PLATFORM_MAC", - "PLATFORM_LINUX", - "PLATFORM_ANDROID" - ] - } - } -] diff --git a/src/test/data/valid_seeds/test1/studies/TestStudy.json5 b/src/test/data/valid_seeds/test1/studies/TestStudy.json5 new file mode 100644 index 00000000..771ada3f --- /dev/null +++ b/src/test/data/valid_seeds/test1/studies/TestStudy.json5 @@ -0,0 +1,43 @@ +[ + { + name: 'TestStudy', + experiment: [ + { + name: 'Enabled', + probability_weight: 100, + feature_association: { + enable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Disabled', + probability_weight: 0, + feature_association: { + disable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Default', + probability_weight: 0, + }, + ], + filter: { + min_version: '92.1.30.57', + channel: [ + 'NIGHTLY', + 'BETA', + 'RELEASE', + ], + platform: [ + 'WINDOWS', + 'MAC', + 'LINUX', + 'ANDROID', + ], + }, + }, +] diff --git a/src/test/data/valid_seeds/test2/studies/AnotherTestStudy.json b/src/test/data/valid_seeds/test2/studies/AnotherTestStudy.json deleted file mode 100644 index d5ca3bce..00000000 --- a/src/test/data/valid_seeds/test2/studies/AnotherTestStudy.json +++ /dev/null @@ -1,38 +0,0 @@ -[ - { - "name": "AnotherTestStudy", - "experiment": [ - { - "name": "Enabled_Group", - "probability_weight": 0, - "feature_association": { - "enable_feature": [ - "AnotherTestFeature" - ] - } - }, - { - "name": "Disabled_Group", - "probability_weight": 100, - "feature_association": { - "disable_feature": [ - "AnotherTestFeature" - ] - } - }, - { - "name": "Default_Group", - "probability_weight": 0 - } - ], - "filter": { - "min_version": "120.*", - "channel": [ - "RELEASE" - ], - "platform": [ - "PLATFORM_MAC" - ] - } - } -] diff --git a/src/test/data/valid_seeds/test2/studies/AnotherTestStudy.json5 b/src/test/data/valid_seeds/test2/studies/AnotherTestStudy.json5 new file mode 100644 index 00000000..846db38e --- /dev/null +++ b/src/test/data/valid_seeds/test2/studies/AnotherTestStudy.json5 @@ -0,0 +1,38 @@ +[ + { + name: 'AnotherTestStudy', + experiment: [ + { + name: 'Enabled_Group', + probability_weight: 0, + feature_association: { + enable_feature: [ + 'AnotherTestFeature', + ], + }, + }, + { + name: 'Disabled_Group', + probability_weight: 100, + feature_association: { + disable_feature: [ + 'AnotherTestFeature', + ], + }, + }, + { + name: 'Default_Group', + probability_weight: 0, + }, + ], + filter: { + min_version: '120.*', + channel: [ + 'RELEASE', + ], + platform: [ + 'MAC', + ], + }, + }, +] diff --git a/src/test/data/valid_seeds/test2/studies/TestStudy.json b/src/test/data/valid_seeds/test2/studies/TestStudy.json deleted file mode 100644 index ad5694dc..00000000 --- a/src/test/data/valid_seeds/test2/studies/TestStudy.json +++ /dev/null @@ -1,43 +0,0 @@ -[ - { - "name": "TestStudy", - "experiment": [ - { - "name": "Enabled", - "probability_weight": 100, - "feature_association": { - "enable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Disabled", - "probability_weight": 0, - "feature_association": { - "disable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Default", - "probability_weight": 0 - } - ], - "filter": { - "min_version": "92.1.30.57", - "channel": [ - "NIGHTLY", - "BETA", - "RELEASE" - ], - "platform": [ - "PLATFORM_WINDOWS", - "PLATFORM_MAC", - "PLATFORM_LINUX", - "PLATFORM_ANDROID" - ] - } - } -] diff --git a/src/test/data/valid_seeds/test2/studies/TestStudy.json5 b/src/test/data/valid_seeds/test2/studies/TestStudy.json5 new file mode 100644 index 00000000..771ada3f --- /dev/null +++ b/src/test/data/valid_seeds/test2/studies/TestStudy.json5 @@ -0,0 +1,43 @@ +[ + { + name: 'TestStudy', + experiment: [ + { + name: 'Enabled', + probability_weight: 100, + feature_association: { + enable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Disabled', + probability_weight: 0, + feature_association: { + disable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Default', + probability_weight: 0, + }, + ], + filter: { + min_version: '92.1.30.57', + channel: [ + 'NIGHTLY', + 'BETA', + 'RELEASE', + ], + platform: [ + 'WINDOWS', + 'MAC', + 'LINUX', + 'ANDROID', + ], + }, + }, +] diff --git a/src/test/data/valid_seeds/test3/studies/AnotherTestStudy.json b/src/test/data/valid_seeds/test3/studies/AnotherTestStudy.json deleted file mode 100644 index 359599c4..00000000 --- a/src/test/data/valid_seeds/test3/studies/AnotherTestStudy.json +++ /dev/null @@ -1,74 +0,0 @@ -[ - { - "name": "AnotherTestStudy", - "experiment": [ - { - "name": "Enabled_Group", - "probability_weight": 0, - "feature_association": { - "enable_feature": [ - "AnotherTestFeature" - ] - } - }, - { - "name": "Disabled_Group", - "probability_weight": 100, - "feature_association": { - "disable_feature": [ - "AnotherTestFeature" - ] - } - }, - { - "name": "Default_Group", - "probability_weight": 0 - } - ], - "filter": { - "min_version": "120.*", - "channel": [ - "RELEASE" - ], - "platform": [ - "PLATFORM_MAC" - ] - } - }, - { - "name": "AnotherTestStudy", - "experiment": [ - { - "name": "Enabled_Group", - "probability_weight": 50, - "feature_association": { - "enable_feature": [ - "AnotherTestFeature" - ] - } - }, - { - "name": "Disabled_Group", - "probability_weight": 50, - "feature_association": { - "disable_feature": [ - "AnotherTestFeature" - ] - } - }, - { - "name": "Default_Group", - "probability_weight": 0 - } - ], - "filter": { - "min_version": "120.*", - "channel": [ - "BETA" - ], - "platform": [ - "PLATFORM_MAC" - ] - } - } -] diff --git a/src/test/data/valid_seeds/test3/studies/AnotherTestStudy.json5 b/src/test/data/valid_seeds/test3/studies/AnotherTestStudy.json5 new file mode 100644 index 00000000..37b4577e --- /dev/null +++ b/src/test/data/valid_seeds/test3/studies/AnotherTestStudy.json5 @@ -0,0 +1,74 @@ +[ + { + name: 'AnotherTestStudy', + experiment: [ + { + name: 'Enabled_Group', + probability_weight: 0, + feature_association: { + enable_feature: [ + 'AnotherTestFeature', + ], + }, + }, + { + name: 'Disabled_Group', + probability_weight: 100, + feature_association: { + disable_feature: [ + 'AnotherTestFeature', + ], + }, + }, + { + name: 'Default_Group', + probability_weight: 0, + }, + ], + filter: { + min_version: '120.*', + channel: [ + 'RELEASE', + ], + platform: [ + 'MAC', + ], + }, + }, + { + name: 'AnotherTestStudy', + experiment: [ + { + name: 'Enabled_Group', + probability_weight: 50, + feature_association: { + enable_feature: [ + 'AnotherTestFeature', + ], + }, + }, + { + name: 'Disabled_Group', + probability_weight: 50, + feature_association: { + disable_feature: [ + 'AnotherTestFeature', + ], + }, + }, + { + name: 'Default_Group', + probability_weight: 0, + }, + ], + filter: { + min_version: '120.*', + channel: [ + 'BETA', + ], + platform: [ + 'MAC', + ], + }, + }, +] diff --git a/src/test/data/valid_seeds/test3/studies/TestStudy.json b/src/test/data/valid_seeds/test3/studies/TestStudy.json deleted file mode 100644 index ad5694dc..00000000 --- a/src/test/data/valid_seeds/test3/studies/TestStudy.json +++ /dev/null @@ -1,43 +0,0 @@ -[ - { - "name": "TestStudy", - "experiment": [ - { - "name": "Enabled", - "probability_weight": 100, - "feature_association": { - "enable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Disabled", - "probability_weight": 0, - "feature_association": { - "disable_feature": [ - "TestFeature" - ] - } - }, - { - "name": "Default", - "probability_weight": 0 - } - ], - "filter": { - "min_version": "92.1.30.57", - "channel": [ - "NIGHTLY", - "BETA", - "RELEASE" - ], - "platform": [ - "PLATFORM_WINDOWS", - "PLATFORM_MAC", - "PLATFORM_LINUX", - "PLATFORM_ANDROID" - ] - } - } -] diff --git a/src/test/data/valid_seeds/test3/studies/TestStudy.json5 b/src/test/data/valid_seeds/test3/studies/TestStudy.json5 new file mode 100644 index 00000000..771ada3f --- /dev/null +++ b/src/test/data/valid_seeds/test3/studies/TestStudy.json5 @@ -0,0 +1,43 @@ +[ + { + name: 'TestStudy', + experiment: [ + { + name: 'Enabled', + probability_weight: 100, + feature_association: { + enable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Disabled', + probability_weight: 0, + feature_association: { + disable_feature: [ + 'TestFeature', + ], + }, + }, + { + name: 'Default', + probability_weight: 0, + }, + ], + filter: { + min_version: '92.1.30.57', + channel: [ + 'NIGHTLY', + 'BETA', + 'RELEASE', + ], + platform: [ + 'WINDOWS', + 'MAC', + 'LINUX', + 'ANDROID', + ], + }, + }, +]