M7: corpus manifest loader/validation, chrF/BLEU/token/numeric metrics, raw-output and report.md/report.json writer, and sprachmittler-cli languages/detect/eval. A synthetic 4-segment run with the 7B validated the harness; the private-corpus and 1.8B evaluation and the default-model ADR remain open. M8: privacy-check root fixture + seeded self-test wired into make verify; English/German localisation for the app shell; end-user USER_GUIDE; release.sh (unsigned archive, Developer ID sign, notarise/staple, DMG, --dry-run); idle CPU/memory and warm 7B measurements in PERFORMANCE. Docs: PROGRESS M7–M8, MODEL_EVALUATION results log/gate status, PERFORMANCE measurements, TESTING evaluation cases, ADR-008 status. Compatibility/VoiceOver/notarisation gates remain manual. Verified: make verify green (format, strict lint, privacy self-test, Debug+Release signatures, 227 package tests); CLI languages/detect/eval run; release dry-run.
83 lines
6.9 KiB
Markdown
83 lines
6.9 KiB
Markdown
# Testing strategy
|
|
|
|
Framework: **Swift Testing** (`import Testing`, `@Test`, `#expect`) for all package tests. XCTest only where Swift Testing lacks support, e.g. performance `measure`.
|
|
|
|
## Layers
|
|
|
|
| Layer | Scope | Where | Runs in `make verify` |
|
|
|---|---|---|---|
|
|
| Unit | Pure logic: language mapping, chunking, token scanning, prompt building, option mapping, validation, settings, chrF/BLEU | `Packages/SprachmittlerKit/Tests/*Tests` | yes |
|
|
| Contract | Ollama client against recorded fixtures through `URLProtocol` stubs; request encoding | `SprachmittlerOllamaTests`, `SprachmittlerEnginesTests` | yes |
|
|
| Component | `TranslationSession` + `DoubleCopyDetector` + `InsertionCoordinator` with fakes, a manual clock and a fake pasteboard | `SprachmittlerCoreTests`, `SprachmittlerCaptureTests` | yes |
|
|
| Live integration | Real Ollama on localhost, opt-in via `SPRACHMITTLER_LIVE=1` | `SprachmittlerLiveTests` | no; `make live-test` |
|
|
| Evaluation | Model comparison on the private corpus | `sprachmittler-cli eval` | no; `/evaluate` |
|
|
| Manual | Double copy, panel focus, Accessibility replacement, clipboard restoration, Services, VoiceOver, real translation quality | checklist below | no |
|
|
|
|
## Rules
|
|
|
|
- Every bug fix starts with a failing test, unless it is only reproducible manually. In that case, add a manual checklist item.
|
|
- No test may depend on the network or a real model unless it is in `SprachmittlerLiveTests`.
|
|
- Time-dependent logic (double-copy window, timeouts) takes an injected clock. Tests use a manual clock; never `Task.sleep` with real time.
|
|
- HTTP contract tests use a serialized `URLProtocol` stub; timeout tests use `ManualSleeper` and never real time.
|
|
- Fakes live in `SprachmittlerTestSupport`: `FakePasteboard`, `FakeClock`, `FakeOllamaHTTPTransport`, `FakeOllamaCatalog`, `FakeOllamaChat`, `ManualSleeper`, `FakeTextInserter`, `FakeAccessibility`, `FakeSettingsStore`, `TemporaryDirectory`.
|
|
- Fixtures live inside their test target (SwiftPM resources must sit within the target) and are loaded with `Bundle.module`. All fixtures are **synthetic**; never add private text.
|
|
- Golden files for prompts, Markdown and JSON output live next to the tests (`Fixtures/`); update them only with an explanation in the commit message.
|
|
|
|
## Required test cases (minimum)
|
|
|
|
Text:
|
|
- `Chunker` splits a 9000-character Latin text into paragraphs, never inside a grapheme; CJK text uses the 2000-character limit; join round-trips exactly.
|
|
- `ProtectedTokenScanner` finds URLs (with query and fragment), e-mails, `{{var}}`, `${var}`, `%s`, `%d`, `%1$@`, Markdown code spans, fenced blocks and HTML tags; does not flag ordinary punctuation.
|
|
- `LanguageDetector` identifies a German paragraph and an English paragraph; short/mixed text reports low confidence.
|
|
- `OutputValidator` flags a missing URL, a preamble, `done_reason: "length"`, a repetition loop and an empty output; clean output has no warnings.
|
|
|
|
Ollama client:
|
|
- NDJSON line split across chunks is decoded; `done_reason: "length"` reaches the caller; cancel mid-stream cancels the URL task; idle timeout fires with the manual clock; 404 missing model → `modelNotInstalled`; redirect is refused; `num_ctx` and option names are encoded exactly.
|
|
|
|
Engines:
|
|
- The default prompt equals the documented string byte for byte, including the blank line and the bold markers.
|
|
- The prompt prefix is identical for the same target language and differs only in the source text.
|
|
- `German`, `Chinese`, `Traditional Chinese`, `Portuguese`, `Norwegian`, `Norwegian Nynorsk`, `Arabic Kazakh` and `Cyrillic Kazakh` map correctly.
|
|
- Sampling merge: publisher values override model defaults; no unknown keys are sent.
|
|
- Structured Data 1 and Delimiters prompts are byte-exact fallbacks; no free-form prompt can be constructed.
|
|
|
|
Session and insertion:
|
|
- One translation in flight; a new trigger cancels the old task; late deltas from the old epoch are dropped.
|
|
- A blocking warning disables Replace; Copy stays enabled; a clean result enables Replace.
|
|
- Replace aborts when the source app changed, when the selected text changed, or when Accessibility is denied.
|
|
- AX direct replacement is preferred; paste fallback is used when AX fails; the clipboard snapshot is restored; own writes are suppressed.
|
|
- The double-copy detector requires identical text within the window and ignores empty/whitespace-only text.
|
|
|
|
Evaluation:
|
|
- chrF and BLEU match hand-computed values on a tiny pair.
|
|
- Protected-token retention is 1.0 for a clean pair and 0.0 for a lost URL.
|
|
- Numeric normalisation treats `1,5`, `1.5` and `1 5` as the same value only where documented.
|
|
- Manifest validation rejects duplicate IDs, bad paths, bad languages and unknown reference kinds.
|
|
- `report.md`/`report.json` contain the environment block and per-category tables.
|
|
- `scripts/privacy-self-test.sh` seeds and detects one violation for every major SP rule.
|
|
|
|
## Manual release checklist
|
|
|
|
- [ ] First launch: onboarding shows correct states with Ollama stopped, model missing, Accessibility denied.
|
|
- [ ] Select a paragraph in Safari, Mail, TextEdit, Notes, Word, Pages, Slack, VS Code, Obsidian and Terminal; press ⌘C twice; the panel appears without stealing focus.
|
|
- [ ] Copy the translation; paste it into the source app; the source text is unchanged.
|
|
- [ ] Click Replace in TextEdit, Notes, Safari and Mail; the selection is replaced; ⌘Z restores it.
|
|
- [ ] Deny Accessibility: Copy and Services work; Replace explains what to enable and offers the right System Settings page.
|
|
- [ ] Replace with a rich-text or image clipboard: after the paste fallback, the previous clipboard is back.
|
|
- [ ] Copy two different things quickly: no translation is triggered.
|
|
- [ ] Copy the same text twice slowly: no translation is triggered. Change the window in Settings and repeat.
|
|
- [ ] Translate a long multi-paragraph text: chunks are joined with the original paragraph breaks; a failed chunk is visible.
|
|
- [ ] Translate text with a URL, an e-mail and `{{placeholder}}`: all survive or a warning appears.
|
|
- [ ] Translate Markdown and JSON: keys/formatting survive.
|
|
- [ ] Change the target language while streaming: the old request is cancelled and the new one starts.
|
|
- [ ] Services ▸ Translate with Sprachmittler works without Accessibility.
|
|
- [ ] Settings: an invalid remote `http://` endpoint is blocked; reset restores defaults; model/digest/licence are shown.
|
|
- [ ] Onboarding reopens from the menu; Ollama stopped, model missing and Accessibility denied each show a fix action.
|
|
- [ ] Launch at login follows `SMAppService`; Diagnostics shows versions, digests, timings and error kinds but no text.
|
|
- [ ] VoiceOver can operate the panel and Settings; every action has a keyboard path.
|
|
- [ ] Console.app shows no selected text, translation, pasteboard content, app name or path.
|
|
- [ ] Quit during a translation: no orphaned request; `ollama ps` shows no hanging request.
|
|
- [ ] Reinstall the app and re-grant Accessibility if macOS requires it.
|
|
- [ ] Remote endpoint: `http://` remote refused; `https://` accepted only with the toggle.
|
|
- [ ] Launch at login mirrors the system setting.
|