-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
84 changed files
with
3,257 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// 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 { Command } from '@commander-js/extra-typings'; | ||
import { execSync } from 'child_process'; | ||
import { assert } from 'console'; | ||
import { existsSync, promises as fs } from 'fs'; | ||
import * as os from 'os'; | ||
import * as path from 'path'; | ||
|
||
export default function createCommand() { | ||
return new Command('compare_python_gen') | ||
.description( | ||
'Run python and typescript seed generators and compare results', | ||
) | ||
.option('--python <value>', 'Path to python executable', 'python3') | ||
.action(main); | ||
} | ||
|
||
interface Options { | ||
python: string; | ||
} | ||
|
||
async function main(options: Options) { | ||
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'seed-compare-')); | ||
const mockSerialNumber = 'mock_serial_number'; | ||
|
||
try { | ||
const pythonSeedFilePath = path.join(tempDir, 'python_seed.bin'); | ||
const typescriptSeedFilePath = path.join(tempDir, 'typescript_seed.bin'); | ||
const pythonSeedSerialNumberFilePath = path.join( | ||
tempDir, | ||
'python_serialnumber', | ||
); | ||
const typescriptSeedSerialNumberFilePath = path.join( | ||
tempDir, | ||
'typescript_serialnumber', | ||
); | ||
|
||
// Run Python seed generator | ||
execSync( | ||
`${options.python} ./seed/serialize.py ./seed/seed.json --mock_serial_number ${mockSerialNumber}`, | ||
{ | ||
stdio: 'inherit', | ||
}, | ||
); | ||
// Move generated seed.bin and serialnumber to temporary directory. | ||
await moveFile('./seed.bin', pythonSeedFilePath); | ||
await moveFile('./serialnumber', pythonSeedSerialNumberFilePath); | ||
|
||
// Run TypeScript seed generator | ||
execSync( | ||
`npm run seed_tools create ./studies ${typescriptSeedFilePath} -- --mock_serial_number ${mockSerialNumber} --output_serial_number_file ${typescriptSeedSerialNumberFilePath}`, | ||
{ stdio: 'inherit' }, | ||
); | ||
|
||
// Run seed comparator | ||
execSync( | ||
`npm run seed_tools compare_seeds ${pythonSeedFilePath} ${typescriptSeedFilePath} ${pythonSeedSerialNumberFilePath} ${typescriptSeedSerialNumberFilePath}`, | ||
{ stdio: 'inherit' }, | ||
); | ||
} finally { | ||
// Clean up temporary directory | ||
await fs.rm(tempDir, { recursive: true, force: true }); | ||
} | ||
} | ||
|
||
async function moveFile(src: string, dest: string) { | ||
await fs.copyFile(src, dest); | ||
await fs.unlink(src); | ||
assert(!existsSync(src)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[ | ||
{ | ||
name: 'AllowCertainClientHintsStudy', | ||
experiment: [ | ||
{ | ||
name: 'Enabled', | ||
probability_weight: 100, | ||
feature_association: { | ||
enable_feature: [ | ||
'AllowCertainClientHints', | ||
], | ||
}, | ||
}, | ||
{ | ||
name: 'Default', | ||
probability_weight: 0, | ||
}, | ||
], | ||
filter: { | ||
min_version: '104.1.44.59', | ||
channel: [ | ||
'RELEASE', | ||
'BETA', | ||
'NIGHTLY', | ||
], | ||
platform: [ | ||
'WINDOWS', | ||
'MAC', | ||
'LINUX', | ||
'ANDROID', | ||
], | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[ | ||
{ | ||
name: 'BraveAIChatEnabledStudy', | ||
experiment: [ | ||
{ | ||
name: 'Enabled', | ||
probability_weight: 100, | ||
feature_association: { | ||
enable_feature: [ | ||
'AIChat', | ||
], | ||
}, | ||
}, | ||
{ | ||
name: 'Default', | ||
probability_weight: 0, | ||
}, | ||
], | ||
filter: { | ||
min_version: '119.1.60.0', | ||
channel: [ | ||
'RELEASE', | ||
], | ||
platform: [ | ||
'WINDOWS', | ||
'MAC', | ||
'LINUX', | ||
], | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[ | ||
{ | ||
name: 'BraveAdblockExperimentalListDefaultStudy', | ||
experiment: [ | ||
{ | ||
name: 'Enabled', | ||
probability_weight: 100, | ||
feature_association: { | ||
enable_feature: [ | ||
'BraveAdblockExperimentalListDefault', | ||
], | ||
}, | ||
}, | ||
{ | ||
name: 'Default', | ||
probability_weight: 0, | ||
}, | ||
], | ||
filter: { | ||
min_version: '123.1.66.53', | ||
channel: [ | ||
'BETA', | ||
'NIGHTLY', | ||
], | ||
platform: [ | ||
'WINDOWS', | ||
'MAC', | ||
'LINUX', | ||
'ANDROID', | ||
], | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[ | ||
{ | ||
name: 'BraveAdblockMobileNotificationsListDefault', | ||
experiment: [ | ||
{ | ||
name: 'Enabled', | ||
probability_weight: 100, | ||
feature_association: { | ||
enable_feature: [ | ||
'BraveAdblockMobileNotificationsListDefault', | ||
], | ||
}, | ||
}, | ||
{ | ||
name: 'Default', | ||
probability_weight: 0, | ||
}, | ||
], | ||
filter: { | ||
channel: [ | ||
'RELEASE', | ||
'BETA', | ||
'NIGHTLY', | ||
], | ||
platform: [ | ||
'WINDOWS', | ||
'MAC', | ||
'LINUX', | ||
'ANDROID', | ||
], | ||
}, | ||
}, | ||
] |
Oops, something went wrong.