Files
Sprachmittler/Packages/SprachmittlerKit/Tests/SprachmittlerCoreTests/CapturePolicyTests.swift
T
schihei 2a601058f4 feat(capture): translate long selections in parts
The capture gate and the chunk size were the same number, so a selection above one chunk was rejected before the pipeline could split it; the Settings sliders moved both thresholds together. Add maximumPartsPerSelection (1-8, default 1, so existing behaviour is unchanged). The capture limit is now part size x parts and travels on TranslationSessionRequest, so the watcher, CapturePolicy and TranslationSession agree for that capture. TranslationStreaming gained an optional per-part callback; the session emits chunkStarted and the panel shows 'Part 2 of 4' while streaming and '2 parts' when finished. textTooLong now points at Settings and offers an Open Settings button. Lower the dense-script part-size maximum to 4000 because 5000 dense characters plus a 4096-token output can overflow the 8192-token context. Tests cover capture limits, watcher limits, pipeline part callbacks, session events and limits, panel progress, settings clamping and migration. Docs updated: ADR-011, TRANSLATION_OUTPUT, SELECTION_AND_CLIPBOARD, ARCHITECTURE, LANGUAGES and README. Verified: make verify green; live 4355-character German text showed Part 1 of 2, Part 2 of 2 and '2 parts'; with one part the panel showed the too-long message and Open Settings.
2026-11-27 20:21:30 +01:00

55 lines
2.0 KiB
Swift

import SprachmittlerCore
import SprachmittlerText
import Testing
@Suite("Capture policy")
struct CapturePolicyTests {
@Test func emptyAndWhitespaceTextAreRejected() {
#expect(CapturePolicy.validate("") == .empty)
#expect(CapturePolicy.validate(" \n\t") == .empty)
}
@Test func latinLimitIs4000() {
#expect(CapturePolicy.validate(String(repeating: "a", count: 4000)) == .valid)
#expect(
CapturePolicy.validate(String(repeating: "a", count: 4001))
== .textTooLong(characters: 4001, limit: 4000)
)
}
@Test func denseScriptLimitIs2000() {
let valid = String(repeating: "你", count: 2000)
let tooLong = String(repeating: "你", count: 2001)
#expect(CapturePolicy.validate(valid) == .valid)
#expect(
CapturePolicy.validate(tooLong)
== .textTooLong(characters: 2001, limit: 2000)
)
}
@Test func partsRaiseTheCaptureLimit() {
let limits = CaptureLimits(maximumParts: 3)
#expect(CapturePolicy.validate(String(repeating: "a", count: 12000), limits: limits) == .valid)
#expect(
CapturePolicy.validate(String(repeating: "a", count: 12001), limits: limits)
== .textTooLong(characters: 12001, limit: 12000)
)
#expect(CapturePolicy.validate(String(repeating: "你", count: 6000), limits: limits) == .valid)
#expect(
CapturePolicy.validate(String(repeating: "你", count: 6001), limits: limits)
== .textTooLong(characters: 6001, limit: 6000)
)
}
@Test func maximumPartsIsAtLeastOne() {
#expect(CaptureLimits(maximumParts: 0).maximumParts == 1)
#expect(CaptureLimits(maximumParts: 0).captureLimit(for: "a") == 4000)
}
@Test func chunkerStillSplitsTheAcceptedText() {
let limits = CaptureLimits(maximumParts: 3)
let text = String(repeating: "a", count: 12000)
#expect(limits.chunker.chunks(for: text).count == 3)
}
}