chore: Implement settings dump schema to update firefox remote servic…, p=#11579

* chore: Implement settings dump schema to update firefox remote services data, b=no-bug, c=configs, scripts

* feat: Also update with timestamps, b=no-bug, c=configs, scripts

* chore: Move JSON with comments to a new module, b=no-bug, c=scripts, tests

---------

Signed-off-by: mr. m <91018726+mr-cheffy@users.noreply.github.com>
This commit is contained in:
mr. m
2025-12-11 13:26:28 +01:00
committed by GitHub
parent bcf4c4d1a3
commit 0c0c982bc2
6 changed files with 103 additions and 10 deletions

View File

@@ -0,0 +1,20 @@
// 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 http://mozilla.org/MPL/2.0/.
{
"remove": {
"identifiers": [
// Firefox adds Perplexity by default, we don't want it as
// its not very privacy focused.
"perplexity",
// These are not search engines, Firefox adds them by default
// but we don't want them.
"wikipedia",
"wikipedia-*",
"ebay",
"ebay-*"
]
},
"timestamp": 1765455207275
}

View File

@@ -10,7 +10,8 @@
"build": "surfer build",
"build:ui": "surfer build --ui",
"start": "cd engine && python3 ./mach run --noprofile",
"import": "npm run ffprefs && surfer import",
"import": "npm run ffprefs && npm run import:dumps && surfer import",
"import:dumps": "python3 scripts/update_service_dumps.py",
"export": "surfer export",
"init": "npm run download && npm run import && npm run bootstrap",
"download": "surfer download",

View File

@@ -20,3 +20,6 @@
- name: browser.ml.chat.menu
value: false
- name: browser.ml.linkPreview.enabled
value: false

View File

@@ -0,0 +1,14 @@
# 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 http://mozilla.org/MPL/2.0/.
import json
class JSONWithCommentsDecoder(json.JSONDecoder):
def __init__(self, **kw):
super().__init__(**kw)
def decode(self, s: str) -> Any:
s = '\n'.join(l for l in s.split('\n') if not l.lstrip(' ').startswith('//'))
return super().decode(s)

View File

@@ -7,6 +7,7 @@ import sys
import json
from pathlib import Path
from typing import Any
from json_with_comments import JSONWithCommentsDecoder
IGNORE_PREFS_FILE_IN = os.path.join(
'src', 'zen', 'tests', 'ignorePrefs.json'
@@ -16,15 +17,6 @@ IGNORE_PREFS_FILE_OUT = os.path.join(
)
class JSONWithCommentsDecoder(json.JSONDecoder):
def __init__(self, **kw):
super().__init__(**kw)
def decode(self, s: str) -> Any:
s = '\n'.join(l for l in s.split('\n') if not l.lstrip(' ').startswith('//'))
return super().decode(s)
def copy_ignore_prefs():
print("Copying ignorePrefs.json from src/zen/tests to engine/testing/mochitest...")
# if there are prefs that dont exist on output file, copy them from input file

View File

@@ -0,0 +1,63 @@
# 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 http://mozilla.org/MPL/2.0/.
import os
import json
from json_with_comments import JSONWithCommentsDecoder
DUMPS_FOLDER = os.path.join(
'configs', 'dumps'
)
ENGINE_DUMPS_FOLDER = os.path.join(
'engine', 'services', 'settings', 'dumps', 'main'
)
def merge_dumps(original, updates):
"""Filters entries from the original dump, removing those whose identifiers are specified in the updates removal list."""
remove_ids = updates.get('remove', {"identifiers": []}).get('identifiers', [])
# Filter out entries in original that are in remove_ids.
#  We may find example-* patterns, so we need to handle that as well.
merged_data = [
entry for entry in original.get('data', [])
if not any(
entry.get('identifier', '') == rid or
(rid.endswith('*') and entry.get('identifier', '').startswith(rid[:-1]))
for rid in remove_ids
)
]
return {
'data': merged_data,
**{k: v for k, v in original.items() if k != 'data'},
'timestamp': updates.get('timestamp', original.get('timestamp'))
}
def main():
for filename in os.listdir(DUMPS_FOLDER):
if filename.endswith('.json'):
#  parse json with comments
with open(os.path.join(DUMPS_FOLDER, filename), 'r') as f:
data = json.load(f, cls=JSONWithCommentsDecoder)
original_path = os.path.join(ENGINE_DUMPS_FOLDER, filename)
if os.path.exists(original_path):
with open(original_path, 'r', encoding='utf-8') as f:
original_content = f.read()
original_content = '\n'.join(
line for line in original_content.split('\n') if not line.lstrip(' ').startswith('//')
)
original_data = json.loads(original_content)
merged_data = merge_dumps(original_data, data)
with open(original_path, 'w', encoding='utf-8') as f:
json.dump(merged_data, f, indent=2, ensure_ascii=False)
print(f"Updated dump: {filename}")
else:
print(f"Original dump file not found: {original_path}")
exit(1)
if __name__ == "__main__":
main()