* feat(plugin,host,ui): add agent session takeover, protected-phase confirmation, and autoinstall host foundation * feat(macos,ui,cli): add offline REIMSPROV first-boot provisioning to skip Setup Assistant (#129) Builds a per-VM read-only REIMSPROV disk image containing a pure-Go XAR Distribution flat package (provision.pkg) and an offline Recovery fallback script (provision-offline.sh). Passwords are hashed in memory to Apple SALTED-SHA512-PBKDF2 bplist00 ShadowHashData (never persisted in plaintext, no auto-login or NOPASSWD sudo). Uses native OpenDirectory.framework (JXA NSData) + dseditgroup under SIP-enabled live bootinstalld and dslocal plist + PlistBuddy under offline Recovery, skips Setup Assistant and Keyboard Setup Assistant, pre-stages Guest Tools, integrates with CreateWizard / VMPage / vm provision CLI / StartAutoInstall, and zero-wipes on finish_install, normal cold start, or DeleteVM. * feat(autoinstall,host,ui): add input-locked session shield, recovery-only mode, and restart grace cap Adds the real-machine end-to-end verified baseline for automatic macOS installation: (1) takeover_policy 'lock' with transparent Win32 VM client-area input shield, low-level key/mouse lock preserving host escape shortcuts (Alt+Tab/Alt+Esc/Win), HUD & UI Pause/Resume controls, and write guards while paused; (2) decoupled recovery_only vs full (REIMSPROV) modes in StartAutoInstall, CreateWizard, and VMAutoInstallPanel; (3) graceful_timeout_sec cap (default 10s) on automated built-in macOS host/vm.restart so Setup Assistant/Login Window restarts do not stall 90s on ACPI; (4) additional modifier aliases in console manager and agent-session/telemetry cleanup on VM deletion. * feat(autoinstall,overlay,plugin): add built-in macOS auto-install plugin, dynamic island overlay, and review fixes * fix(app,host,macos,ui): address PR #134 automated review findings - Frontend & i18n: - Fix UTF-8/GBK mojibake in VMPage.tsx. - Emit reims:confirm-resolved on timeout/cancel/resolve so frontend modals auto-close and surface errors cleanly; stop submitCreate from continuing after PrepareVMProvision failure. - Gate AutoInstallPanel RapidOCR download button on preflight can_download_ocr when pinned default assets are unavailable. - App / Sessions / Confirm / Lifecycle: - Add 30s denial cooldown for protected-phase confirmation prompts and revoke (pluginID, vmKey) grants on non-completed session exits. - Fix sessionOverlay / activeAgentSessions data race, remove duplicate permission-denied invocation, guard against clobbering other sessions or completed overlays, and unify VM key normalization. - Grant protected-phase confirmation and attach lock-mode session + watcher when resuming auto-install without an active session. - Unify FinishInstall and host/vm.finishInstall result handling and persist .reims-go-provision-ready across restarts. - Preserve non-timeout stop errors in restartMacOSVMLocked instead of force-killing. - Host Takeover Hooks: - Require both keyboard and mouse WH_*_LL hooks (rolling back partial installs), initialize thread message queue before ready, reset started state on error/exit for retry, and report hook failures. - macOS Provisioning & Autoinstall Engine: - Track REIMSPROV staged/wipe-pending/ready lifecycle markers, exclude "restore" recovery marker from re-attaching REIMSPROV, fail explicitly on offline admin plist creation failure, and report wipe failures. - Serialize per-VM Start/Stop/Resume with stop generation tokens, guard ROI fast-path against maxDim overflow, switch hostclient early-event buffer to FIFO eviction, fix untyped nil Engine return, tighten negation & high-risk fuzzy matching, preserve ackedQemuErrors across RebootWindow resets, and re-orient/expire stale inherited running checkpoints. - Document verified Windows SDK IDL vtable slots for WinOCR (live-tested on Windows) and add regression tests across app, host, macosdriver, startprep, installer, and autoinstall packages. * fix(app,cli,host,macos,ui): address PR #134 second automated review findings - CLI & Desktop Control Channel: - Add __reims_host__ / autoinstall desktop control channel with data_root verification so CLI status, resume, and stop talk directly to the live desktop runner instead of splitting checkpoint state or launching doomed short-lived CLI runners. - Merge live runners with on-disk checkpoints when listing status without a VM argument. - App Sessions, Confirmations, Downloads & Telemetry: - Scope single-VM not_authorized errors to the target VM in handleSessionBegin and resolveComputerUseVM so active sessions on other VMs are not aborted. - Exclude stopped and suspended VMs from hasUnboundAgentSession fast-polling. - Revoke protected-phase grants when a VM disappears from poll results. - Require manifest Secret:true validation before storing auto-install passwords and remove the unsafe default account_password fallback. - Reject userinfo URLs in allow_custom_mirror, gate custom-mirror exemption strictly on plugin.ErrNetOriginNotDeclared, and keep redirect SSRF checks enabled on loopback custom mirrors. - Preserve VM telemetry milestones across suspend-resume and Win10 cold-reboot restarts while still resetting on fresh cold boots. - Log a warning when Guest Tools bridge is unavailable while preparing REIMSPROV. - Clarify CallHostAPI authorization/audit contract and add regression test proving built-in plugins enforce catalog permissions and audit logging. - Host Takeover & Guest Tools: - Track locked mouse button presses via a 5-button bitmask so ButtonUp events from drags started outside the VM window are never swallowed. - Align active-window-reporter.js permissions to 0o100755 across ToolsDiskFiles, ToolsProvisionFiles, and postinstall. - macOS Provisioning & Autoinstall Engine (OCR / Vision / Rules / Runner): - Never delete an unwiped REIMSPROV image on OpenFile/Write/Sync failure; persist wipe-pending marker and return error for retry. - Harden live postinstall preference writes with chmod 600, plutil -lint, chown, and cfprefsd flush. - Rewrite Windows RapidOCR C ABI structs and result extraction to match RapidAI/RapidOcrOnnx@675e73fe4c include/OcrLiteCApi.h:27-70 and src/OcrLiteCApi.cpp:12-160 (5-arg OcrInit verified). - Inspect PE32/PE32+ IMAGE_DIRECTORY_ENTRY_IMPORT directly to require onnxruntime.dll only for dynamically linked RapidOcrOnnx.dll builds. - Validate cfg.VM and use collision-free SHA-256-suffixed checkpoint paths with read fallback; redact PII/paths/UUIDs/MACs/IPs/tokens in diagnostic summaries; snapshot checkpoints before releasing r.mu for serialized disk I/O. - Add contrast/border/focus-ring ok return to DetectInputFieldNearLabel, enforce mask-dots verification in fillAccountForm and login screens, refuse blind password typing on clock-only lock screens, confirm shell readiness before typing install.sh, and prefer isolated button lines over modal prose in FindHit. - Frontend: - Require explicit Apple SLA confirmation in both recovery_only and full modes across AutoInstallPanel and CreateWizard, with unit tests in frontend/scripts/test-autoinstall.mjs. * fix(app,cli,host,macos,ui): address PR #134 third automated review findings Addresses all confirmed findings from Review #6204465334 (commit d516350) with targeted regression tests and hardens verified COM vtable bindings: - App & Session Lifecycle: - Track hostPaused separately in agentSession so plugin host/session.update (paused_for_user=false) cannot clear physical user takeover or explicit PauseAgentSession holds; only host ResumeAgentSession or timed takeover expiry clears them. - Give each auto-install session watcher a monotonic watchGen + cancelable child context so restarting/resuming auto-install on the same VM cancels any superseded watcher and prevents stale timeout or secret cleanup. - Bound fast 500ms unbound-PID discovery for running VMs to sessionDiscoverGraceWindow via unboundSince (refreshed on restart/rebind). - Keep non-blocking buffered confirm resolution send inside confirmMu for clear mutual exclusion with cancelPendingConfirmations. - Clear cold-reboot telemetry preserveNextBoot via defer on all early-return and StartVM-failure paths in watchColdReboot. - Rebuild REIMSPROV with current StartAutoInstall credentials (preserving install_guest_tools) whenever VM is stopped instead of reusing stale images. - CLI & macOS Provisioning / StartPrep: - Refuse `vm provision --clear` and overwriting existing REIMSPROV while the VM is running or paused. - Guard live "/" root in postinstall against macOS Recovery/Installer (/System/Installation/CDIS), forbid "/" in provision-offline.sh, and scope chmod 644 strictly to com.apple.keyboardtype.plist. - Reject unknown -* options in REIMSHELP/install.sh (including after --erase). - Defer clearing the one-shot REIMSPROV staged marker until after setExtraArgs (startprep) and StartWithCompat (macosdriver) succeed. - Preserve pending RestartFrom guards in AdvancePostInstallHandoff when checkpoint is already at StepDesktop. - Host Input & Session Overlay: - Filter injected keyboard events (LLKHF_INJECTED / LLKHF_LOWER_IL_INJECTED) in locked-input mode consistently with the mouse hook. - Clean up exited overlay entries in entry.run() and recreate dead entries on Manager.Upsert when CreateWindowExW fails or exits early. - Cache the static island base surface (shell + icons + DirectWrite text) and measured text metrics across breathing frames, raising timerBreathMs to 100ms. - Replace magic Direct2D/DirectWrite vtable indices with named d2d1.h / dwrite.h constants, check EndDraw HRESULT, and add a live Windows DirectWrite rendering smoke test. - Autoinstall OCR, Rules, Watchdog & Runner: - Persist and verify a per-file SHA-256 manifest.json in <dataDir>/ocr/ before loading RapidOcrOnnx.dll / onnxruntime.dll; reject duplicate whitelisted basenames in offline zip imports. - Signal WinOCREngine.Close() before acquiring e.mu and add bounded wait + channel wakeup in Recognize so Close() immediately cancels in-flight OCR. - Fall back to installed RapidOCR when WinOCR initialization fails in Open(), and distinguish needs_rapidocr_import from needs_rapidocr_download in Probe. - Pause instead of pressing Return when post-TypeSecret login screenshot fails. - Re-baseline ColdRebootCount in Watchdog.ResetRebootWindow / ResetAfterResume. - Tighten recovery.main specificity (drop bare "Disk Utility"), guard 4-5 char pure-ASCII needles from sliding-window fuzzy collisions, use Unicode word boundaries for short names (<4 runes) in RedactDiagnosticText, and honor rule verify.wait_change_ms with early exit on visual frame diff. * fix(autoinstall): handle CJK short-name redaction, sh-3.2 prompt bound, and OCR re-import pruning
347 lines
13 KiB
Go
347 lines
13 KiB
Go
package rules
|
|
|
|
import (
|
|
"image"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/Nwflower/reims-go/internal/macos/autoinstall/ocr"
|
|
)
|
|
|
|
func TestNormalizeAndFuzzyMatch(t *testing.T) {
|
|
if got := NormalizeText(" 实 用 工 具… "); got != "实用工具" {
|
|
t.Fatalf("NormalizeText = %q, want 实用工具", got)
|
|
}
|
|
if !MatchPhrase("悄 后 设 置", "稍后设置", true) {
|
|
t.Fatal("fuzzy match should tolerate single CJK OCR error (悄后设置 ~ 稍后设置)")
|
|
}
|
|
if !MatchPhrase("ContInue", "Continue", true) {
|
|
t.Fatal("case-insensitive match should match ContInue")
|
|
}
|
|
// Negation guard must never allow "不使用" to match positive "使用",
|
|
// including fuzzy substitution/insertion windows at start=0.
|
|
if MatchPhrase("确定不使用定位服务", "使用定位服务", true) {
|
|
t.Fatal("negation collision guard failed")
|
|
}
|
|
if MatchPhrase("不同意します", "同意します", true) {
|
|
t.Fatal("negated Japanese phrase must not fuzzy-match positive needle")
|
|
}
|
|
if MatchPhrase("不使用定位", "请使用定位", true) {
|
|
t.Fatal("negated-prefix substitution window must not fuzzy-match positive needle")
|
|
}
|
|
}
|
|
|
|
func TestLoadEngineAndOverlayAndHighRisk(t *testing.T) {
|
|
dataDir := t.TempDir()
|
|
rulesDir := filepath.Join(dataDir, "rules")
|
|
if err := os.MkdirAll(rulesDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
patch := `{
|
|
"version": 1,
|
|
"rules": [
|
|
{
|
|
"id": "setup.custom_macos27",
|
|
"stage": "setup_assistant",
|
|
"priority": 95,
|
|
"match": { "roi": "title_band", "any_of": ["Future macOS 27 Page"] },
|
|
"actions": [{ "op": "key", "key": "ret" }]
|
|
}
|
|
]
|
|
}`
|
|
if err := os.WriteFile(filepath.Join(rulesDir, "patch.json"), []byte(patch), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
eng, err := LoadEngine(dataDir)
|
|
if err != nil {
|
|
t.Fatalf("LoadEngine: %v", err)
|
|
}
|
|
// Built-in online Setup Assistant rule matches.
|
|
r, ok := eng.MatchScreen("setup_assistant", map[string]string{
|
|
"title_band": "Sign In with Your Apple Account",
|
|
})
|
|
if !ok || r.ID != "setup.apple_account" {
|
|
t.Fatalf("expected setup.apple_account, got %+v %v", r.ID, ok)
|
|
}
|
|
// Modal rule has higher priority than underlying title_band rule.
|
|
rModal, ok := eng.MatchScreen("setup_assistant", map[string]string{
|
|
"title_band": "Sign In with Your Apple Account",
|
|
"modal": "Are you sure you want to skip signing in?",
|
|
})
|
|
if !ok || rModal.ID != "setup.apple_account_skip_modal" {
|
|
t.Fatalf("expected skip modal priority override, got %+v %v", rModal.ID, ok)
|
|
}
|
|
// User overlay JSON rule matches.
|
|
rPatch, ok := eng.MatchScreen("setup_assistant", map[string]string{
|
|
"title_band": "Future macOS 27 Page",
|
|
})
|
|
if !ok || rPatch.ID != "setup.custom_macos27" {
|
|
t.Fatalf("expected overlay patch rule, got %+v %v", rPatch.ID, ok)
|
|
}
|
|
// High-risk keyword detection catches non-empty disk refusal, recovery key screens,
|
|
// and single-char OCR typos without false-positiving on benign words like "Please" or "Ease".
|
|
for _, sample := range []string{
|
|
"Refusing to erase non-empty disk /dev/disk0",
|
|
"Save your Recovery Key before continuing",
|
|
"Multiple eligible disks found [y/N]",
|
|
"Are you sure you want to erasc Macintosh HD?",
|
|
"Save your recovery kev now",
|
|
"Installatlon failed unexpectedly",
|
|
} {
|
|
if _, hit := DetectHighRiskKeyword(sample); !hit {
|
|
t.Fatalf("expected high-risk detection for %q", sample)
|
|
}
|
|
}
|
|
for _, safe := range []string{
|
|
"Please select your country or region",
|
|
"Ease of access settings",
|
|
"Do not erasc existing files",
|
|
} {
|
|
if kw, hit := DetectHighRiskKeyword(safe); hit {
|
|
t.Fatalf("benign text %q falsely triggered high-risk keyword %q", safe, kw)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFindHitLocatesExactCJKMenuItem(t *testing.T) {
|
|
// Simulates Windows.Media.Ocr emitting per-character CJK words on one Recovery menu bar line.
|
|
lines := []ocr.Line{{
|
|
Text: "恢 复 文 件 编 辑 实 用 工 具 窗 口",
|
|
Rect: image.Rect(40, 4, 340, 22),
|
|
Words: []ocr.Word{
|
|
{Text: "恢", Rect: image.Rect(40, 4, 58, 22)},
|
|
{Text: "复", Rect: image.Rect(58, 4, 76, 22)},
|
|
{Text: "文", Rect: image.Rect(92, 4, 110, 22)},
|
|
{Text: "件", Rect: image.Rect(110, 4, 128, 22)},
|
|
{Text: "编", Rect: image.Rect(144, 4, 162, 22)},
|
|
{Text: "辑", Rect: image.Rect(162, 4, 180, 22)},
|
|
{Text: "实", Rect: image.Rect(196, 4, 214, 22)},
|
|
{Text: "用", Rect: image.Rect(214, 4, 232, 22)},
|
|
{Text: "工", Rect: image.Rect(232, 4, 250, 22)},
|
|
{Text: "具", Rect: image.Rect(250, 4, 268, 22)},
|
|
{Text: "窗", Rect: image.Rect(284, 4, 302, 22)},
|
|
{Text: "口", Rect: image.Rect(302, 4, 320, 22)},
|
|
},
|
|
}}
|
|
_, pt, ok := FindHit(lines, []string{"Utilities", "实用工具"}, true)
|
|
if !ok {
|
|
t.Fatal("expected to locate 实用工具")
|
|
}
|
|
if pt.X < 196 || pt.X > 268 {
|
|
t.Fatalf("clicked X=%d outside 实用工具 bounds [196,268] (regression: hit 文/件/编辑)", pt.X)
|
|
}
|
|
}
|
|
|
|
func TestTerminalHighRiskAllowsBlankDiskErase(t *testing.T) {
|
|
normal := `No writable volume found; detected blank VM disk: /dev/disk0 (68.7 GB, QEMU NVMe Ctrl)
|
|
Formatting /dev/disk0 as APFS (Macintosh HD, GPT)...
|
|
Started erase on disk0
|
|
Finished erase on disk0
|
|
Using target volume: /Volumes/Macintosh HD
|
|
Copying InstallAssistant.pkg as SharedSupport.dmg`
|
|
if kw, bad := DetectTerminalHighRiskKeyword(normal); bad {
|
|
t.Fatalf("normal blank-disk install.sh output must not trigger terminal high-risk stop, matched %q", kw)
|
|
}
|
|
for _, danger := range []string{
|
|
"Found 1 disk >= 30 GB that already has partitions: /dev/disk0",
|
|
"Erase /dev/disk0 as APFS? All data on it will be lost! [y/N]:",
|
|
"Refusing to erase a non-blank disk non-interactively.",
|
|
"No writable target volume found under /Volumes.",
|
|
} {
|
|
if _, bad := DetectTerminalHighRiskKeyword(danger); !bad {
|
|
t.Fatalf("expected terminal high-risk stop for %q", danger)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestMatchScreenFallsBackToFullWhenROIHoldsOnlyNoise(t *testing.T) {
|
|
eng, err := LoadEngine(t.TempDir())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Single-symbol back button "<" in title_band must not block falling back to full text.
|
|
r, ok := eng.MatchScreen("setup_assistant", map[string]string{
|
|
"title_band": "<",
|
|
"body": "选择国家或地区\n阿尔巴尼亚",
|
|
"full": "<\n选择国家或地区\n阿尔巴尼亚",
|
|
})
|
|
if !ok || r.ID != "setup.region" {
|
|
t.Fatalf("expected setup.region via full fallback when title_band is noise, got ok=%v id=%q", ok, r.ID)
|
|
}
|
|
// Meaningful heading text in title_band stays scoped to title_band.
|
|
r2, ok := eng.MatchScreen("setup_assistant", map[string]string{
|
|
"title_band": "Data & Privacy",
|
|
"body": "Accessibility information",
|
|
"full": "Data & Privacy\nAccessibility information",
|
|
})
|
|
if !ok || r2.ID != "setup.privacy" {
|
|
t.Fatalf("expected setup.privacy from title_band, got ok=%v id=%q", ok, r2.ID)
|
|
}
|
|
}
|
|
|
|
func TestDisagreeAndNegatedButtonsNeverFalseMatchAgree(t *testing.T) {
|
|
if MatchPhrase("Disagree", "Agree", true) {
|
|
t.Fatal("Disagree must never match Agree")
|
|
}
|
|
if MatchPhrase("不同意", "同意", true) {
|
|
t.Fatal("不同意 must never match 同意")
|
|
}
|
|
// Action bar containing both "Disagree" and "Agree" must click "Agree".
|
|
enLines := []ocr.Line{{
|
|
Text: "Disagree Agree",
|
|
Rect: image.Rect(700, 620, 1080, 660),
|
|
Words: []ocr.Word{
|
|
{Text: "Disagree", Rect: image.Rect(700, 620, 860, 660)},
|
|
{Text: "Agree", Rect: image.Rect(920, 620, 1080, 660)},
|
|
},
|
|
}}
|
|
_, enPt, ok := FindHit(enLines, []string{"Agree", "同意"}, true)
|
|
if !ok || enPt.X < 920 || enPt.X > 1080 {
|
|
t.Fatalf("expected click on Agree [920,1080], got ok=%v pt=%v", ok, enPt)
|
|
}
|
|
|
|
// Chinese action bar containing "上一步 不同意 同意" with single-char CJK WinOCR words must click "同意".
|
|
zhLines := []ocr.Line{{
|
|
Text: "上 一 步 不 同 意 同 意",
|
|
Rect: image.Rect(600, 620, 1080, 660),
|
|
Words: []ocr.Word{
|
|
{Text: "上", Rect: image.Rect(600, 620, 620, 660)},
|
|
{Text: "一", Rect: image.Rect(620, 620, 640, 660)},
|
|
{Text: "步", Rect: image.Rect(640, 620, 660, 660)},
|
|
{Text: "不", Rect: image.Rect(760, 620, 780, 660)},
|
|
{Text: "同", Rect: image.Rect(780, 620, 800, 660)},
|
|
{Text: "意", Rect: image.Rect(800, 620, 820, 660)},
|
|
{Text: "同", Rect: image.Rect(960, 620, 980, 660)},
|
|
{Text: "意", Rect: image.Rect(980, 620, 1000, 660)},
|
|
},
|
|
}}
|
|
_, zhPt, ok := FindHit(zhLines, []string{"Agree", "同意"}, true)
|
|
if !ok || zhPt.X < 960 || zhPt.X > 1000 {
|
|
t.Fatalf("expected click on 同意 [960,1000], got ok=%v pt=%v", ok, zhPt)
|
|
}
|
|
|
|
// Setup Hello priority must not hijack specific title_band pages whose body contains "hello"/"你好".
|
|
eng, err := LoadEngine(t.TempDir())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
rule, ok := eng.MatchScreen("setup_assistant", map[string]string{
|
|
"title_band": "Create a Computer Account",
|
|
"body": "Full Name: Hello User",
|
|
"full": "Create a Computer Account\nFull Name: Hello User",
|
|
})
|
|
if !ok || rule.ID != "setup.create_account" {
|
|
t.Fatalf("expected setup.create_account over setup.hello, got ok=%v id=%q", ok, rule.ID)
|
|
}
|
|
}
|
|
|
|
func TestFindHitPrefersStandaloneButtonOverBodyProse(t *testing.T) {
|
|
// 1. Apple Account skip confirmation modal: prose sentence contains "skip"
|
|
// above the standalone "Skip" button. FindHit MUST click the button at Y=420.
|
|
modalLines := []ocr.Line{
|
|
{
|
|
Text: "Are you sure you want to skip setting up an Apple Account?",
|
|
Rect: image.Rect(300, 260, 960, 290),
|
|
Words: []ocr.Word{
|
|
{Text: "Are", Rect: image.Rect(300, 260, 340, 290)},
|
|
{Text: "you", Rect: image.Rect(345, 260, 385, 290)},
|
|
{Text: "sure", Rect: image.Rect(390, 260, 440, 290)},
|
|
{Text: "you", Rect: image.Rect(445, 260, 485, 290)},
|
|
{Text: "want", Rect: image.Rect(490, 260, 540, 290)},
|
|
{Text: "to", Rect: image.Rect(545, 260, 570, 290)},
|
|
{Text: "skip", Rect: image.Rect(575, 260, 625, 290)},
|
|
{Text: "setting", Rect: image.Rect(630, 260, 700, 290)},
|
|
{Text: "up", Rect: image.Rect(705, 260, 735, 290)},
|
|
},
|
|
},
|
|
{
|
|
Text: "Skip",
|
|
Rect: image.Rect(740, 410, 820, 445),
|
|
Words: []ocr.Word{{Text: "Skip", Rect: image.Rect(740, 410, 820, 445)}},
|
|
},
|
|
}
|
|
_, pt, ok := FindHit(modalLines, []string{"Skip", "跳过", "略過"}, true)
|
|
if !ok || pt.Y < 410 || pt.Y > 445 {
|
|
t.Fatalf("expected click on Skip button at Y=[410,445], got ok=%v pt=%v", ok, pt)
|
|
}
|
|
|
|
// 2. Two-button row ("Cancel Skip") at Y=410 still beats long prose at Y=260.
|
|
modalTwoBtn := []ocr.Line{
|
|
modalLines[0],
|
|
{
|
|
Text: "Cancel Skip",
|
|
Rect: image.Rect(600, 410, 820, 445),
|
|
Words: []ocr.Word{
|
|
{Text: "Cancel", Rect: image.Rect(600, 410, 690, 445)},
|
|
{Text: "Skip", Rect: image.Rect(740, 410, 820, 445)},
|
|
},
|
|
},
|
|
}
|
|
_, pt2, ok := FindHit(modalTwoBtn, []string{"Skip", "跳过"}, true)
|
|
if !ok || pt2.Y < 410 || pt2.X < 740 {
|
|
t.Fatalf("expected click on Skip button [740..820, 410..445], got ok=%v pt=%v", ok, pt2)
|
|
}
|
|
|
|
// 3. Multi-word modal button "Don't Use" beats body sentence containing "don't want to use".
|
|
locModal := []ocr.Line{
|
|
{
|
|
Text: "Are you sure you don't use Location Services?",
|
|
Rect: image.Rect(300, 260, 920, 290),
|
|
Words: []ocr.Word{
|
|
{Text: "Are", Rect: image.Rect(300, 260, 340, 290)},
|
|
{Text: "you", Rect: image.Rect(345, 260, 385, 290)},
|
|
{Text: "sure", Rect: image.Rect(390, 260, 440, 290)},
|
|
{Text: "you", Rect: image.Rect(445, 260, 485, 290)},
|
|
{Text: "don't", Rect: image.Rect(490, 260, 550, 290)},
|
|
{Text: "use", Rect: image.Rect(555, 260, 595, 290)},
|
|
{Text: "Location", Rect: image.Rect(600, 260, 690, 290)},
|
|
},
|
|
},
|
|
{
|
|
Text: "Don't Use",
|
|
Rect: image.Rect(710, 415, 830, 448),
|
|
Words: []ocr.Word{
|
|
{Text: "Don't", Rect: image.Rect(710, 415, 770, 448)},
|
|
{Text: "Use", Rect: image.Rect(775, 415, 830, 448)},
|
|
},
|
|
},
|
|
}
|
|
_, pt3, ok := FindHit(locModal, []string{"Don't Use", "不使用"}, true)
|
|
if !ok || pt3.Y < 415 {
|
|
t.Fatalf("expected click on Don't Use button at Y=[415,448], got ok=%v pt=%v", ok, pt3)
|
|
}
|
|
}
|
|
|
|
func TestShortASCIIFuzzyGuardAndRecoveryMainSpecificity(t *testing.T) {
|
|
// 4-5 char pure-ASCII needles must not fuzzy-match unrelated 3-5 char substrings.
|
|
for _, sample := range []string{"desire", "Sir", "Air", "Skipper's ship", "Site Settings"} {
|
|
if MatchPhrase(sample, "Siri", true) {
|
|
t.Fatalf("short ASCII fuzzy match falsely matched %q against Siri", sample)
|
|
}
|
|
}
|
|
if !MatchPhrase("Ask Siri", "Siri", true) {
|
|
t.Fatal("exact normalized match for Siri must still work")
|
|
}
|
|
|
|
eng, err := LoadEngine(t.TempDir())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Bare "Disk Utility" text (e.g. in Terminal help output) must not match recovery.main.
|
|
if r, ok := eng.MatchScreen("recovery", map[string]string{
|
|
"body": "Open Disk Utility to erase your disk",
|
|
"full": "Open Disk Utility to erase your disk",
|
|
}); ok && r.ID == "recovery.main" {
|
|
t.Fatalf("bare Disk Utility text must not trigger recovery.main: %+v", r)
|
|
}
|
|
// Explicit Reinstall macOS still matches recovery.main.
|
|
if r, ok := eng.MatchScreen("recovery", map[string]string{
|
|
"body": "Reinstall macOS Sequoia",
|
|
"full": "Reinstall macOS Sequoia",
|
|
}); !ok || r.ID != "recovery.main" {
|
|
t.Fatalf("expected recovery.main for Reinstall macOS, got ok=%v id=%q", ok, r.ID)
|
|
}
|
|
}
|