summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authortanaka takashi <isazaka@gmail.com>2026-09-01 20:38:17 +0900
committertanaka takashi <isazaka@gmail.com>2026-09-01 20:38:17 +0900
commitbb06e0e58dcb90eceede6f0b05743fdccc8f51af (patch)
treeaa239db6e1a1d695c651c363702182c24b57c4cd /src/shared
parent55e581bab9b600e7c070ec596d3109fc897d2d86 (diff)
fix: options page never ran due to missing export; unify settings handling
Root cause of the broken options page (audit finding): - options.js imported CONTEXT_PRESETS from settings-schema.js, but that module never exported it. A named-import mismatch in ES modules is a SyntaxError, so the entire options page script silently never executed. This is why the settings page rendered its static HTML but was dead: no language options, no model list, no save handler. Fixes - options.js: import CONTEXT_PRESETS from shared/constants.js (where it is defined) instead of settings-schema.js - options.js: save flow now merges the validated form over the stored settings (sanitize again) so fields saved by the popup in the meantime are preserved instead of being dropped - popup.js: populate language options inside loadSettings and sanitize settings before every save, matching the options page behavior - settings-schema.js: add normalizeOllamaHost() and use it in sanitizeSettings so trailing-slash variants are stored identically - content.js: consolidate popover state - remove the duplicate outer lastSourceText and keep regenerate source inside the popover module; regenerate now calls portClient.translate directly Test hardening (would have caught the original bug) - tests/ui-smoke-tests.js: new smoke tests that install a fake browser API, run the real popup.js / options.js page scripts as ES modules against representative markup, and assert that language options are populated, the model select is filled from the mocked model list, and the stored host is reflected. The runner result elements are preserved across the sandboxed DOM swap - test.html: include the smoke test module Results: 73 passed, 0 failed (71 existing + 2 smoke). dist rebuilt.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/settings-schema.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/shared/settings-schema.js b/src/shared/settings-schema.js
index fad7a5f..057812d 100644
--- a/src/shared/settings-schema.js
+++ b/src/shared/settings-schema.js
@@ -33,6 +33,7 @@ export function isValidOllamaHost(value) {
}
if (url.protocol !== 'http:') return false;
if (url.hostname !== 'localhost' && url.hostname !== '127.0.0.1') return false;
+ // Only the root path ("http://host/" or "http://host") is allowed.
if (url.pathname !== '/' && url.pathname !== '') return false;
if (url.search !== '' || url.hash !== '') return false;
if (url.username !== '' || url.password !== '') return false;
@@ -45,6 +46,17 @@ export function isValidOllamaHost(value) {
}
/**
+ * Normalize a validated host for storage: strip the trailing slash so
+ * "http://localhost:11434/" and "http://localhost:11434" are stored
+ * identically.
+ * @param {string} host already validated host
+ * @returns {string}
+ */
+export function normalizeOllamaHost(host) {
+ return host.replace(/\/+$/, '') || 'http://localhost';
+}
+
+/**
* @param {*} value
* @returns {boolean}
*/
@@ -189,7 +201,7 @@ export function sanitizeSettings(stored) {
if (isValidOllamaHost(stored.ollamaHost)) {
// Normalize: strip trailing slash.
- result.ollamaHost = stored.ollamaHost.replace(/\/+$/, '') || DEFAULT_OLLAMA_HOST;
+ result.ollamaHost = normalizeOllamaHost(stored.ollamaHost) || DEFAULT_OLLAMA_HOST;
}
if (typeof stored.model === 'string' && stored.model.length <= 256) {