Self-hosted AI workspace.
Python
Ignore censor preference storage errors (#1652)
red person1c63569c82b0
diff --git a/static/js/censor.js b/static/js/censor.jsindex ecb5f2fcf..099e27441 100644--- a/static/js/censor.js+++ b/static/js/censor.js@@ -8,7 +8,13 @@let _enabled = true;let _observer = null;const PREF_KEY = 'odysseus-sensitive-blur';-const _prefEnabled = () => localStorage.getItem(PREF_KEY) === 'on';+export const _prefEnabled = () => {+ try {+ return localStorage.getItem(PREF_KEY) === 'on';+ } catch (_) {+ return false;+ }+};// Patterns that indicate sensitive dataconst PATTERNS = [diff --git a/tests/test_censor_pref_js.py b/tests/test_censor_pref_js.pynew file mode 100644index 000000000..adef2592c--- /dev/null+++ b/tests/test_censor_pref_js.py@@ -0,0 +1,49 @@+import json+import shutil+import subprocess+from pathlib import Path++import pytest+++ROOT = Path(__file__).resolve().parents[1]+pytestmark = pytest.mark.skipif(not shutil.which("node"), reason="node binary not on PATH")+++def _node_eval(source: str):+ result = subprocess.run(+ ["node", "--input-type=module", "-e", source],+ cwd=ROOT,+ check=True,+ capture_output=True,+ text=True,+ )+ return json.loads(result.stdout)+++def test_censor_pref_falls_back_when_storage_throws():+ values = _node_eval(+ """+ globalThis.localStorage = {+ getItem() { throw new Error('blocked'); }+ };+ const { _prefEnabled } = await import('./static/js/censor.js');+ console.log(JSON.stringify({ enabled: _prefEnabled() }));+ """+ )++ assert values == {"enabled": False}+++def test_censor_pref_reads_enabled_flag():+ values = _node_eval(+ """+ globalThis.localStorage = {+ getItem(key) { return key === 'odysseus-sensitive-blur' ? 'on' : null; }+ };+ const { _prefEnabled } = await import('./static/js/censor.js');+ console.log(JSON.stringify({ enabled: _prefEnabled() }));+ """+ )++ assert values == {"enabled": True}