diff options
| author | tanaka takashi <isazaka@gmail.com> | 2026-09-01 20:10:20 +0900 |
|---|---|---|
| committer | tanaka takashi <isazaka@gmail.com> | 2026-09-01 20:10:20 +0900 |
| commit | 55e581bab9b600e7c070ec596d3109fc897d2d86 (patch) | |
| tree | 15ca196a1858696c216946dc9608fae613ad6e5f /doc/Testing-Results.md | |
feat: Firefox selection translation extension with local Ollama (initial version)
Implement the complete initial version of a Firefox WebExtension (Manifest V3)
that translates selected text on web pages using a local Ollama LLM and shows
the result in a small popover near the selection.
Specification alignment (Phase 0)
- Unified Specifications.md / Design.md / Security.md on the same approach:
Ollama REST API + Fetch API + NDJSON streaming (no ollama-js SDK dependency)
- Fixed host_permissions to http://localhost/* and http://127.0.0.1/* because
Firefox match patterns do not support port numbers (bug 1362809/1468162);
the actual connection target is restricted to localhost/127.0.0.1 + any port
by application-side validation (defense in depth, OLL-09)
- Clipboard: use navigator.clipboard.writeText() only inside the copy button
click (user activation); no deprecated execCommand fallback
Implementation (zero dependencies, vanilla JS, no npm/Node required)
- manifest.json: MV3, background.scripts + type:module (event page, no
service_worker), action popup, options_ui, content_scripts for http/https,
permissions: storage + localhost host permissions only
- src/shared: constants (ports, limits, presets, error codes), message
validation, settings schema (defaults / merge / sanitize / buildOptions /
toApiThinking), system prompt builder (fixed prompt first + user prompt)
- src/background: message-router (runtime.Port streaming + runtime.onMessage
for model list), translation-session (single active request, abort previous
on new request, stale chunk suppression), ollama-client (fetch against
/api/tags and /api/chat with buffering NDJSON line parser tolerant to chunk
boundaries inside JSON objects, AbortController, host re-validation before
every request, HTTP status to error-code mapping), settings-service
(storage.local load/save with validation and fallback to defaults)
- src/content/content.js: single classic script (Firefox does not support ES
modules in content scripts) with selection detection (selectionchange +
mouseup + keyup, debounced), Shadow DOM action button, Shadow DOM popover
with HIDDEN/LOADING/STREAMING/COMPLETED/ERROR state machine, port client
with requestId-based stale chunk filtering, enabled-state sync via
storage.onChanged; all dynamic text rendered via textContent only
- src/popup + src/options: full settings UI (enable toggle, Ollama host,
model list from Ollama with saved-model warning, target language, thinking
mode, temperature slider 0.0-2.0 step 0.1, context length presets
4k/8k/16k/32k/128k/256k, seed random/fixed with integer value, user system
prompt, advanced numeric options with steppers, stop sequences textarea)
- icons generated by tools/make-icons.ps1 (System.Drawing, no external tools)
- build.ps1 packages manifest.json + icons/ + src/ into dist zip, excluding
tests/, doc/, ollama-js/ and tools/
Tests (71 passed, 0 failed)
- In-browser test runner (tests/test.html) with custom describe/it/assert
framework; no npm, no Node.js
- Unit: constants sync between content mirror and shared module, Ollama host
validation (localhost/127.0.0.1 + any port only; rejects external hosts,
LAN IPs, https, credentials, paths), settings schema defaults and fallback,
temperature 0.1-step validation, context length presets, seed modes,
advanced option types, buildOptions omission of unset values and absence of
tfs_z/mirostat fields, system prompt composition order, message validation
with selection length boundary values
- Integration: NDJSON streaming across awkward byte boundaries, thinking
chunk forwarding, malformed line tolerance, error payload mapping, think/
options inclusion rules, model list, TranslationSession abort semantics,
settings round-trip with storage.onChanged cache refresh, full port flow
(started/chunk/completed), newer request aborts older with stale chunk
discard, malformed message rejection, OLLAMA_UNAVAILABLE and
INVALID_SETTINGS error paths, untrusted sender rejection
Security audit (Design.md section 24 checklist: all pass)
- No innerHTML/outerHTML/document.write/eval/new Function/localStorage
- No remote JS/CSS/fonts/CDN resources; no inline scripts in extension pages
- Ollama access limited to background; content scripts never fetch Ollama
- Background validates message type/length/requestId; single concurrent
translation enforced
- Clipboard API only (no execCommand fallback)
- Minimal permissions: storage + localhost host permissions
Docs
- README.md with build/load/usage instructions, API list, permission rationale
- doc/Testing-Results.md with automated test results, security audit results,
and a 14-item manual Firefox verification checklist (to be executed on a
real Firefox + Ollama environment)
Diffstat (limited to 'doc/Testing-Results.md')
| -rw-r--r-- | doc/Testing-Results.md | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/doc/Testing-Results.md b/doc/Testing-Results.md new file mode 100644 index 0000000..b2cf153 --- /dev/null +++ b/doc/Testing-Results.md @@ -0,0 +1,87 @@ +# テスト実行結果 + +実施日: 2026-09-01 + +## 1. 単体・結合テスト(自動) + +実行環境: Firefox系ブラウザ(Geckoエンジン)で `tests/test.html` を実行。npm / Node.js 不使用の自作ランナー。 + +**結果: 71 passed, 0 failed** + +### カバレッジ + +| 領域 | テスト数 | 内容 | +|---|---:|---| +| constants sync (content mirror) | 4 | Content Script複製定数とshared定数の同期担保 | +| ollama host validation | 9 | localhost/127.0.0.1+任意port許可、外部host/LAN/https/credentials拒否 | +| settings schema defaults | 4 | 既定値、不正値のフォールバック、ユーザープロンプト長制限 | +| temperature validation | 4 | 0.1刻み、範囲外・中間値拒否 | +| context length validation | 1 | プリセット6値のみ許可 | +| seed validation | 3 | random/fixed、非整数seed破棄 | +| advanced options validation | 4 | null許容、整数/浮動小数チェック、stop配列 | +| buildOptions | 5 | 未設定除外、seedモード反映、API名マップ、mirostat系不使用 | +| toApiThinking | 3 | off→省略、on→true、low/high→文字列 | +| system prompt builder | 4 | 固定プロンプト先頭、言語指定、ユーザープロンプト結合順序 | +| message validation | 6 | translate/cancel検証、長さ上限境界値、requestId生成 | +| ollama client: listModels | 4 | 正常系、404写像、host拒否(fetch前)、ネットワークエラー写像 | +| ollama client: chatStream | 6 | **JSON境界分断チャンク耐性**、thinking分離、不正行スキップ、エラーペイロード写像、think/options条件付き送信、400/404写像 | +| toExtensionError | 2 | AbortError→REQUEST_ABORTED、デフォルトコード | +| TranslationSession | 2 | 新規要求で旧要求Abort+旧portへの通知、isActive/clear | +| settings service | 3 | 保存/復元ラウンドトリップ、不正値フォールバック、onChangedキャッシュ更新 | +| message router: port flow | 5 | started/chunk/completed伝送、**A→B新規要求でAがabort+stale chunk廃棄**、不正メッセージ破棄、OLLAMA_UNAVAILABLE、INVALID_SETTINGS | +| message router: listModels | 2 | 正常系、非信頼sender拒否 | + +## 2. Firefox実機動作確認 + +以下は `about:debugging` から一時アドオンとしてロードし、実Ollama環境で確認する項目です。 + +| # | 確認項目 | 結果 | +|---|---|---| +| 1 | 通常HTMLページで文字列選択後、翻訳アイコンが表示される | ☐ 未実施 | +| 2 | アイコン押下までOllama requestが発生しない | ☐ 未実施 | +| 3 | アイコン押下で翻訳ポップオーバーが表示される | ☐ 未実施 | +| 4 | streaming結果が逐次表示される | ☐ 未実施 | +| 5 | コピーが動作する | ☐ 未実施 | +| 6 | 再生成が動作する | ☐ 未実施 | +| 7 | 閉じる操作が動作する | ☐ 未実施 | +| 8 | 新規翻訳で旧streamがキャンセルされる | ☐ 未実施 | +| 9 | 拡張無効時は翻訳アイコンが出ない | ☐ 未実施 | +| 10 | 設定変更後の値が次回翻訳に反映される | ☐ 未実施 | +| 11 | Firefox再起動後も設定が保持される | ☐ 未実施 | +| 12 | Ollama停止時に適切なエラーとなる | ☐ 未実施 | +| 13 | ページ内のHTMLらしき文字列やscript文字列を選択してもDOM実行されない | ☐ 未実施 | +| 14 | LLM出力にHTML文字列が含まれてもHTMLとして解釈されない | ☐ 未実施 | + +## 3. セキュリティチェック + +| 項目 | 結果 | +|---|---| +| `innerHTML` / `outerHTML` / `document.write` 不使用 | ✅ 全ソースでgrep確認済み | +| `eval` / `new Function` / 文字列setTimeout不使用 | ✅ 全ソースでgrep確認済み | +| リモートJS/CSS/フォント/CDN不使用 | ✅ 外部資源参照なし | +| inline script不使用(popup/options/options HTML) | ✅ 外部script fileのみ | +| LLM出力・選択文字列の`textContent`描画 | ✅ popover body / status すべてtextContent | +| Content ScriptからのOllama fetchなし | ✅ Ollama clientはbackgroundのみ | +| message validation(型・長さ・requestId) | ✅ shared/messages.js で実施、テストで担保 | +| host制限(localhost/127.0.0.1+portのみ) | ✅ schema validator + client assertAllowedHost の二重防御、テストで担保 | +| `execCommand('copy')` 等deprecated API不使用 | ✅ Clipboard APIのみ(失敗時はメッセージ表示) | +| 不要権限なし(tabs/scripting/cookies/webRequest等) | ✅ manifest.jsonで確認 | + +## 4. Firefox API監査チェックリスト(Design §24) + +- [x] Manifest V3 +- [x] `action` 使用 +- [x] `background.scripts` 使用(`type: module`) +- [x] `background.service_worker` 不使用 +- [x] `browser_action` 不使用 +- [x] `tabs.executeScript()` 不使用 +- [x] `runtime.getBackgroundPage()` 不使用 +- [x] `window.localStorage` 不使用 +- [x] `storage.local` 使用 +- [x] `runtime.Port` streaming通信 +- [x] Content ScriptからOllama fetchなし +- [x] `eval` / `new Function`なし +- [x] Remote JSなし +- [x] LLM出力への`innerHTML`なし +- [x] 不要permissionsなし +- [x] iframe初期対応なし
\ No newline at end of file |
