lycheedev 1.0.6 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lycheedev.js +257 -38
- package/package.json +1 -1
- package/src/addon.js +1 -1
- package/src/doctor.js +2 -1
- package/src/install.js +12 -4
- package/src/py/instances.py +50 -5
- package/src/wow.js +278 -24
- package/vendor/addon/Core/Clients/Forever.lua +9 -0
- package/vendor/addon/Core/Locale.lua +6 -2
- package/vendor/addon/Core/Locale_enUS.lua +6 -2
- package/vendor/addon/Lychee Dev_Forever.toc +43 -0
- package/vendor/addon/Lychee Dev_Mainline.toc +1 -1
- package/vendor/addon/Lychee Dev_Mists.toc +1 -1
- package/vendor/addon/Lychee Dev_Wrath.toc +1 -1
- package/vendor/addon/Modules/Automation/Controller.lua +130 -3
- package/vendor/addon/Modules/Events/CatalogData_Forever.lua +1809 -0
- package/vendor/addon/UI/AutomationOverlay.lua +83 -13
- package/vendor/addon/UI/Pages/About.lua +4 -1
- package/vendor/skill/SKILL.md +23 -97
- package/vendor/skill/agents/openai.yaml +3 -3
- package/vendor/skill/references/automation.md +85 -284
- package/vendor/skill/references/clients.md +28 -112
- package/vendor/skill/references/runtime-investigations.md +7 -0
- package/vendor/skill/scripts/automation/windows.py +269 -50
- package/vendor/skill/scripts/automation.py +194 -25
- package/vendor/skill/scripts/selftest_offline.py +153 -73
- package/vendor/skill/scripts/test_input_safety.py +132 -0
|
@@ -47,7 +47,17 @@ from automation.saved_variables import SavedVariablesError # noqa: E402
|
|
|
47
47
|
|
|
48
48
|
NOTICE_MAX_BYTES = 512
|
|
49
49
|
BUG_TASK_ID = "bug"
|
|
50
|
-
|
|
50
|
+
# Client -> candidate install folders, in the order to try. A folder name is a
|
|
51
|
+
# location rather than an identity: the launcher reuses a test folder for
|
|
52
|
+
# whatever is on the test track, so WoW: Forever currently lives in
|
|
53
|
+
# `_classic_beta_` while a dedicated `_forever_` folder is also accepted. The
|
|
54
|
+
# right folder is decided by what exists under the WoW root, not by the name.
|
|
55
|
+
CLIENT_FOLDERS = {
|
|
56
|
+
"retail": ("_retail_",),
|
|
57
|
+
"classic": ("_classic_",),
|
|
58
|
+
"titan": ("_classic_titan_",),
|
|
59
|
+
"forever": ("_classic_beta_", "_forever_"),
|
|
60
|
+
}
|
|
51
61
|
DEFAULT_TIMEOUT = 120.0
|
|
52
62
|
DEFAULT_INTERVAL = 0.1
|
|
53
63
|
SV_READ_RETRIES = 3
|
|
@@ -173,9 +183,13 @@ def cmd_profile(args) -> int:
|
|
|
173
183
|
raise CliError(f"addon directory not found: {args.addon_dir}")
|
|
174
184
|
if not os.path.isdir(args.wow_root):
|
|
175
185
|
raise CliError(f"WoW root directory not found: {args.wow_root}")
|
|
186
|
+
folders = CLIENT_FOLDERS[args.client]
|
|
176
187
|
profile = {
|
|
177
188
|
"client": args.client,
|
|
178
|
-
|
|
189
|
+
# The first entry is the default; clientFolders keeps every accepted
|
|
190
|
+
# location so a client that moved folders still resolves.
|
|
191
|
+
"clientFolder": folders[0],
|
|
192
|
+
"clientFolders": list(folders),
|
|
179
193
|
"wow_root": os.path.abspath(args.wow_root),
|
|
180
194
|
"addon_dir": os.path.abspath(args.addon_dir),
|
|
181
195
|
"sv_path": os.path.abspath(args.sv_path) if args.sv_path else None,
|
|
@@ -192,15 +206,25 @@ def resolve_client_root(profile: dict) -> str:
|
|
|
192
206
|
"""Resolve the client folder (`_retail_`, ...) under the configured WoW root.
|
|
193
207
|
|
|
194
208
|
A profile may point either at the WoW root that contains ``_retail_`` or at
|
|
195
|
-
the client folder itself; the account tree decides which one is right.
|
|
209
|
+
the client folder itself; the account tree decides which one is right. Every
|
|
210
|
+
accepted folder for the client is tried, so a build that moved folders still
|
|
211
|
+
resolves without rewriting the profile.
|
|
196
212
|
"""
|
|
197
213
|
|
|
198
214
|
root = os.path.abspath(profile.get("wow_root") or "")
|
|
199
|
-
|
|
215
|
+
recorded = profile.get("clientFolders")
|
|
216
|
+
if not recorded:
|
|
217
|
+
recorded = [profile.get("clientFolder")] if profile.get("clientFolder") else []
|
|
218
|
+
folders = list(recorded) + list(CLIENT_FOLDERS.get(profile.get("client"), ()))
|
|
200
219
|
candidates = []
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
220
|
+
for folder in folders:
|
|
221
|
+
if not folder:
|
|
222
|
+
continue
|
|
223
|
+
path = os.path.join(root, folder)
|
|
224
|
+
if path not in candidates:
|
|
225
|
+
candidates.append(path)
|
|
226
|
+
if root not in candidates:
|
|
227
|
+
candidates.append(root)
|
|
204
228
|
for candidate in candidates:
|
|
205
229
|
if os.path.isdir(os.path.join(candidate, "WTF", "Account")):
|
|
206
230
|
return candidate
|
|
@@ -362,8 +386,8 @@ def _window_module():
|
|
|
362
386
|
def _deliver(session: session_mod.Session, windows, args, text: str) -> None:
|
|
363
387
|
"""Log the intent, then send exactly one command (design section 6.2)."""
|
|
364
388
|
|
|
365
|
-
mode = getattr(args, "mode", "
|
|
366
|
-
session.log_event("
|
|
389
|
+
mode = getattr(args, "mode", "messages")
|
|
390
|
+
session.log_event("command_prepared", hwnd=args.hwnd, text=text, mode=mode)
|
|
367
391
|
try:
|
|
368
392
|
windows.send_command(args.hwnd, text, pid=getattr(args, "pid", None),
|
|
369
393
|
exe_path=getattr(args, "exe_path", None),
|
|
@@ -372,6 +396,7 @@ def _deliver(session: session_mod.Session, windows, args, text: str) -> None:
|
|
|
372
396
|
session.log_event("command_failed", hwnd=args.hwnd, text=text,
|
|
373
397
|
mode=mode, reason=str(error))
|
|
374
398
|
raise CliError(f"command delivery failed: {error}", code=EXIT_INPUT)
|
|
399
|
+
session.log_event("command_submitted", hwnd=args.hwnd, text=text, mode=mode)
|
|
375
400
|
|
|
376
401
|
|
|
377
402
|
def cmd_send(args) -> int:
|
|
@@ -386,11 +411,11 @@ def cmd_send(args) -> int:
|
|
|
386
411
|
f"reload for {args.ticket} was already requested; check the saved "
|
|
387
412
|
"variables file before repeating it")
|
|
388
413
|
_deliver(session, windows, args, args.text)
|
|
389
|
-
print("
|
|
414
|
+
print("submitted; game execution is not yet confirmed")
|
|
390
415
|
return 0
|
|
391
416
|
|
|
392
417
|
|
|
393
|
-
def ack_command(ticket: str, outcome: str) -> str:
|
|
418
|
+
def ack_command(ticket: str, outcome: str, nonce: str | None = None) -> str:
|
|
394
419
|
"""Build the in-game command that reports a ticket's read outcome.
|
|
395
420
|
|
|
396
421
|
The plugin cannot see whether the host read a result, so the host says so
|
|
@@ -399,7 +424,11 @@ def ack_command(ticket: str, outcome: str) -> str:
|
|
|
399
424
|
|
|
400
425
|
if outcome not in ("received", "failed"):
|
|
401
426
|
raise CliError("ack status must be 'received' or 'failed'")
|
|
402
|
-
|
|
427
|
+
if not svlib.TICKET_PATTERN.fullmatch(ticket) or len(ticket) > 64:
|
|
428
|
+
raise CliError("invalid acknowledgement ticket")
|
|
429
|
+
if nonce is not None and not registry.REQUEST_ID_PATTERN.fullmatch(nonce):
|
|
430
|
+
raise CliError("invalid acknowledgement nonce")
|
|
431
|
+
return f"/dev auto ack {ticket} {outcome}" + (f" {nonce}" if nonce else "")
|
|
403
432
|
|
|
404
433
|
|
|
405
434
|
def cmd_ack(args) -> int:
|
|
@@ -408,13 +437,55 @@ def cmd_ack(args) -> int:
|
|
|
408
437
|
windows = _window_module()
|
|
409
438
|
session = session_mod.Session(data_dir=args.data_dir,
|
|
410
439
|
installation=args.installation)
|
|
411
|
-
|
|
440
|
+
nonce = new_request_id()
|
|
441
|
+
text = ack_command(args.ticket, args.status, nonce)
|
|
412
442
|
_deliver(session, windows, args, text)
|
|
413
|
-
session.log_event("
|
|
414
|
-
|
|
443
|
+
session.log_event("ticket_ack_submitted", ticket=args.ticket, status=args.status)
|
|
444
|
+
notice = poll_notice(windows, session, args, expected_task="ack", expected_run=nonce,
|
|
445
|
+
expected_ticket=args.ticket, expected_status=args.status)
|
|
446
|
+
if notice is None:
|
|
447
|
+
session.log_event("ticket_ack_unresolved", ticket=args.ticket, nonce=nonce)
|
|
448
|
+
raise CliError("ack was submitted but no matching game receipt arrived",
|
|
449
|
+
code=EXIT_NOTICE_TIMEOUT)
|
|
450
|
+
session.log_event("ticket_ack_confirmed", ticket=args.ticket, status=args.status, nonce=nonce)
|
|
451
|
+
_deliver(session, windows, args, f"/dev auto unidentify {nonce}")
|
|
452
|
+
if not wait_ack_cleared(windows, args, nonce):
|
|
453
|
+
session.log_event("ticket_ack_cleanup_unresolved", ticket=args.ticket, nonce=nonce)
|
|
454
|
+
raise CliError("ack confirmed, but its marker cleanup was not observed",
|
|
455
|
+
code=EXIT_NOTICE_TIMEOUT)
|
|
456
|
+
session.log_event("ticket_ack_cleared", ticket=args.ticket, nonce=nonce)
|
|
457
|
+
print(f"ack confirmed: {args.ticket} {args.status}")
|
|
415
458
|
return 0
|
|
416
459
|
|
|
417
460
|
|
|
461
|
+
def wait_ack_cleared(windows, args, nonce: str) -> bool:
|
|
462
|
+
"""Observe removal of this receipt; never dismiss a newer marker by nonce."""
|
|
463
|
+
interval = getattr(args, "interval", None) or DEFAULT_INTERVAL
|
|
464
|
+
deadline = time.monotonic() + min(args.timeout, 5.0)
|
|
465
|
+
absent = 0
|
|
466
|
+
with windows.open_notice_capture(args.hwnd, pid=getattr(args, "pid", None),
|
|
467
|
+
exe_path=getattr(args, "exe_path", None),
|
|
468
|
+
interval=interval) as capture:
|
|
469
|
+
while time.monotonic() < deadline:
|
|
470
|
+
if capture.window_closed:
|
|
471
|
+
return False
|
|
472
|
+
roi = capture.latest_roi()
|
|
473
|
+
if roi is not None:
|
|
474
|
+
visible = False
|
|
475
|
+
for payload in windows.decode_qr(roi):
|
|
476
|
+
try:
|
|
477
|
+
marker = json.loads(payload)
|
|
478
|
+
except (ValueError, TypeError):
|
|
479
|
+
continue
|
|
480
|
+
if isinstance(marker, dict) and marker.get("task") == "ack" and marker.get("run") == nonce:
|
|
481
|
+
visible = True
|
|
482
|
+
absent = 0 if visible else absent + 1
|
|
483
|
+
if absent >= 2:
|
|
484
|
+
return True
|
|
485
|
+
time.sleep(interval)
|
|
486
|
+
return False
|
|
487
|
+
|
|
488
|
+
|
|
418
489
|
def validate_notice(json_text: str) -> dict:
|
|
419
490
|
if not isinstance(json_text, str) or not json_text:
|
|
420
491
|
raise SavedVariablesError("notice payload is empty")
|
|
@@ -464,7 +535,9 @@ def notice_identity_problems(notice: dict, *, expected_task: str | None,
|
|
|
464
535
|
|
|
465
536
|
def poll_notice(windows, session: session_mod.Session, args, *,
|
|
466
537
|
expected_task: str | None = None,
|
|
467
|
-
expected_run: str | None = None
|
|
538
|
+
expected_run: str | None = None,
|
|
539
|
+
expected_ticket: str | None = None,
|
|
540
|
+
expected_status: str | None = None) -> dict | None:
|
|
468
541
|
"""Keep one WGC session open and poll until a matching notice or the deadline.
|
|
469
542
|
|
|
470
543
|
The session outlives a single frame because a task can run far longer than
|
|
@@ -492,6 +565,10 @@ def poll_notice(windows, session: session_mod.Session, args, *,
|
|
|
492
565
|
problems = notice_identity_problems(
|
|
493
566
|
notice, expected_task=expected_task,
|
|
494
567
|
expected_run=expected_run)
|
|
568
|
+
if expected_ticket is not None and notice["ticket"] != expected_ticket:
|
|
569
|
+
problems.append("receipt ticket mismatch")
|
|
570
|
+
if expected_status is not None and notice.get("status") != expected_status:
|
|
571
|
+
problems.append("receipt status mismatch")
|
|
495
572
|
if problems:
|
|
496
573
|
session.log_event("notice_identity_mismatch",
|
|
497
574
|
ticket=notice["ticket"],
|
|
@@ -520,6 +597,73 @@ def cmd_capture(args) -> int:
|
|
|
520
597
|
return 0
|
|
521
598
|
|
|
522
599
|
|
|
600
|
+
def cmd_identify(args) -> int:
|
|
601
|
+
"""Read the in-game identity marker from one or more game windows.
|
|
602
|
+
|
|
603
|
+
Nothing observable from outside the game says which character sits behind
|
|
604
|
+
which window, so with several windows open a slash command cannot be aimed
|
|
605
|
+
without guessing. The addon can display a marker on request
|
|
606
|
+
(``/dev auto identify``); this reads it out of each window so the caller can
|
|
607
|
+
offer the user a character-based choice instead of an arbitrary index.
|
|
608
|
+
|
|
609
|
+
Capture does not need the foreground, so this is safe before any input is
|
|
610
|
+
sent. A window with no visible marker is reported with ``identity: null``
|
|
611
|
+
rather than treated as an error: that is the normal state until the user
|
|
612
|
+
asks the game to show one.
|
|
613
|
+
"""
|
|
614
|
+
|
|
615
|
+
windows = _window_module()
|
|
616
|
+
targets = _identify_targets(args)
|
|
617
|
+
if not targets:
|
|
618
|
+
raise CliError("identify needs at least one window: pass --hwnd, or "
|
|
619
|
+
"--windows-json with the instances list")
|
|
620
|
+
|
|
621
|
+
# Only forward an explicit timeout: passing None would override the helper's
|
|
622
|
+
# own measured default rather than selecting it.
|
|
623
|
+
options = {"interval": args.interval}
|
|
624
|
+
if args.timeout is not None:
|
|
625
|
+
options["timeout"] = args.timeout
|
|
626
|
+
results = windows.read_identities(targets, **options)
|
|
627
|
+
print(json.dumps(results, ensure_ascii=False, sort_keys=True))
|
|
628
|
+
# Every window unreadable is a real failure; a partly readable set is not.
|
|
629
|
+
if results and all(entry["identity"] is None and entry["error"] for entry in results):
|
|
630
|
+
return EXIT_NOTICE_TIMEOUT
|
|
631
|
+
return 0
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
def _identify_targets(args) -> list[dict]:
|
|
635
|
+
"""Build the probe list from repeated --hwnd flags or a windows JSON file."""
|
|
636
|
+
|
|
637
|
+
targets: list[dict] = []
|
|
638
|
+
if args.windows_json:
|
|
639
|
+
try:
|
|
640
|
+
with open(args.windows_json, encoding="utf-8") as handle:
|
|
641
|
+
loaded = json.load(handle)
|
|
642
|
+
except OSError as error:
|
|
643
|
+
raise CliError(f"could not read --windows-json: {error}") from error
|
|
644
|
+
except ValueError as error:
|
|
645
|
+
raise CliError(f"--windows-json is not valid JSON: {error}") from error
|
|
646
|
+
if not isinstance(loaded, list):
|
|
647
|
+
raise CliError("--windows-json must contain a JSON array of windows")
|
|
648
|
+
for entry in loaded:
|
|
649
|
+
if not isinstance(entry, dict) or entry.get("hwnd") is None:
|
|
650
|
+
raise CliError("every --windows-json entry needs an 'hwnd'")
|
|
651
|
+
targets.append({
|
|
652
|
+
"hwnd": entry.get("hwnd"),
|
|
653
|
+
"pid": entry.get("pid"),
|
|
654
|
+
"exePath": entry.get("exePath"),
|
|
655
|
+
"flavorFolder": entry.get("flavorFolder"),
|
|
656
|
+
"flavorId": entry.get("flavorId"),
|
|
657
|
+
"flavorLabel": entry.get("flavorLabel"),
|
|
658
|
+
})
|
|
659
|
+
return targets
|
|
660
|
+
|
|
661
|
+
for hwnd in args.hwnd or ():
|
|
662
|
+
targets.append({"hwnd": hwnd, "pid": args.pid, "exePath": args.exe_path,
|
|
663
|
+
"flavorFolder": None, "flavorId": None, "flavorLabel": None})
|
|
664
|
+
return targets
|
|
665
|
+
|
|
666
|
+
|
|
523
667
|
# --- orchestrated flows ---------------------------------------------------------
|
|
524
668
|
|
|
525
669
|
def _notice_to_sv(session: session_mod.Session, windows, notice: dict, args,
|
|
@@ -577,6 +721,11 @@ def cmd_run(args) -> int:
|
|
|
577
721
|
expected_request_id = args.request_id or definition["requestId"]
|
|
578
722
|
revision = args.revision or definition["revision"]
|
|
579
723
|
|
|
724
|
+
if not registry.TASK_ID_PATTERN.fullmatch(args.task):
|
|
725
|
+
raise CliError("invalid task id")
|
|
726
|
+
if not expected_request_id or not registry.REQUEST_ID_PATTERN.fullmatch(expected_request_id):
|
|
727
|
+
raise CliError("run requires an installed task block or an explicit --request-id")
|
|
728
|
+
|
|
580
729
|
session.log_event("run_started", task=args.task,
|
|
581
730
|
requestId=expected_request_id, revision=revision)
|
|
582
731
|
_deliver(session, windows, args, f"/dev auto run {args.task}")
|
|
@@ -598,8 +747,11 @@ def cmd_bugs(args) -> int:
|
|
|
598
747
|
raise CliError("--count must be an integer between 1 and 100")
|
|
599
748
|
session = session_mod.Session(data_dir=args.data_dir,
|
|
600
749
|
installation=args.installation)
|
|
601
|
-
|
|
602
|
-
|
|
750
|
+
args.request_id = args.request_id or new_request_id()
|
|
751
|
+
if not registry.REQUEST_ID_PATTERN.fullmatch(args.request_id):
|
|
752
|
+
raise CliError("invalid bug request id")
|
|
753
|
+
session.log_event("bugs_started", count=args.count, requestId=args.request_id)
|
|
754
|
+
_deliver(session, windows, args, f"/dev auto bug {args.count} {args.request_id}")
|
|
603
755
|
notice = poll_notice(windows, session, args, expected_task=BUG_TASK_ID,
|
|
604
756
|
expected_run=args.request_id)
|
|
605
757
|
if notice is None:
|
|
@@ -696,7 +848,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
696
848
|
profile.add_argument("profile_command", choices=["set", "show"])
|
|
697
849
|
profile.add_argument("--name", required=True, help="profile name")
|
|
698
850
|
profile.add_argument("--client", choices=sorted(CLIENT_FOLDERS),
|
|
699
|
-
help="client type: retail, classic or
|
|
851
|
+
help="client type: retail, classic, titan or forever; the "
|
|
852
|
+
"client folder is resolved from the WoW root")
|
|
700
853
|
profile.add_argument("--wow-root", help="WoW root that contains the client folder")
|
|
701
854
|
profile.add_argument("--addon-dir", help="installed addon directory")
|
|
702
855
|
profile.add_argument("--sv-path", help="exact 'Lychee Dev.lua' path to read")
|
|
@@ -727,11 +880,9 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
727
880
|
window.add_argument("--pid", type=int, help="expected process id")
|
|
728
881
|
window.add_argument("--exe-path", help="expected executable path")
|
|
729
882
|
window.add_argument(
|
|
730
|
-
"--mode", choices=("foreground", "messages"), default="
|
|
731
|
-
help="
|
|
732
|
-
"
|
|
733
|
-
"no foreground but requires the chat box to be open already "
|
|
734
|
-
"(default: foreground)")
|
|
883
|
+
"--mode", choices=("foreground", "messages"), default="messages",
|
|
884
|
+
help="foreground uses clipboard readback; messages posts input to the "
|
|
885
|
+
"target HWND without changing foreground (execution needs a receipt)")
|
|
735
886
|
|
|
736
887
|
polling = argparse.ArgumentParser(add_help=False)
|
|
737
888
|
polling.add_argument("--timeout", type=float, default=DEFAULT_TIMEOUT,
|
|
@@ -749,7 +900,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
749
900
|
send.add_argument("--ticket", help="ticket used to dedup a '/reload' command")
|
|
750
901
|
send.set_defaults(func=cmd_send)
|
|
751
902
|
|
|
752
|
-
ack = sub.add_parser("ack", parents=[window],
|
|
903
|
+
ack = sub.add_parser("ack", parents=[window, polling],
|
|
753
904
|
help="report a ticket's read outcome to the running game")
|
|
754
905
|
ack.add_argument("--ticket", required=True, help="exact ticket that was read")
|
|
755
906
|
ack.add_argument("--status", required=True, choices=("received", "failed"),
|
|
@@ -760,6 +911,24 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
760
911
|
help="poll the window and decode the notice QR")
|
|
761
912
|
capture.set_defaults(func=cmd_capture)
|
|
762
913
|
|
|
914
|
+
identify = sub.add_parser(
|
|
915
|
+
"identify",
|
|
916
|
+
help="read the character/build identity marker from game windows")
|
|
917
|
+
identify.add_argument("--hwnd", type=lambda value: int(value, 0), action="append",
|
|
918
|
+
help="a window to probe; repeat for several windows")
|
|
919
|
+
identify.add_argument("--windows-json",
|
|
920
|
+
help="JSON file with the instance list to probe instead "
|
|
921
|
+
"of --hwnd (the shape 'lycheedev instances' prints)")
|
|
922
|
+
identify.add_argument("--pid", type=int, help="expected process id")
|
|
923
|
+
identify.add_argument("--exe-path", help="expected executable path")
|
|
924
|
+
identify.add_argument("--timeout", type=float, default=None,
|
|
925
|
+
help="seconds to wait per window for its marker "
|
|
926
|
+
"(default: the helper's measured budget)")
|
|
927
|
+
identify.add_argument("--interval", type=float, default=DEFAULT_INTERVAL,
|
|
928
|
+
help=f"seconds between polls per window "
|
|
929
|
+
f"(default: {DEFAULT_INTERVAL})")
|
|
930
|
+
identify.set_defaults(func=cmd_identify)
|
|
931
|
+
|
|
763
932
|
run = sub.add_parser("run", parents=[window, polling],
|
|
764
933
|
help="deliver and resolve one task run")
|
|
765
934
|
run.add_argument("--task", required=True, help="task id to run")
|
|
@@ -478,11 +478,7 @@ else:
|
|
|
478
478
|
cli._window_module = real_window_module
|
|
479
479
|
print("CLI window/input exit codes (4 for window/dependency, 1 otherwise) OK")
|
|
480
480
|
|
|
481
|
-
# ---
|
|
482
|
-
#
|
|
483
|
-
# Regression: the sequence used to paste BEFORE opening the chat box, so the
|
|
484
|
-
# client opened an empty chat and no command ran. Reference behaviour is
|
|
485
|
-
# Return -> Ctrl+V -> Return.
|
|
481
|
+
# --- input transaction regressions (no live game access) ----------------------
|
|
486
482
|
|
|
487
483
|
try:
|
|
488
484
|
from automation import windows as winmod
|
|
@@ -492,69 +488,10 @@ except Exception: # pragma: no cover - non-Windows hosts
|
|
|
492
488
|
if winmod is None: # pragma: no cover - non-Windows hosts
|
|
493
489
|
print("command delivery order (skipped: no windows module)")
|
|
494
490
|
else:
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
def read_text(self):
|
|
501
|
-
return self.value
|
|
502
|
-
|
|
503
|
-
def copy_text(self, text):
|
|
504
|
-
self.value = text
|
|
505
|
-
self.writes.append(text)
|
|
506
|
-
|
|
507
|
-
def clear(self):
|
|
508
|
-
self.value = None
|
|
509
|
-
|
|
510
|
-
pressed = []
|
|
511
|
-
real_send_key = winmod._send_key
|
|
512
|
-
real_set_fg = winmod.user32.SetForegroundWindow
|
|
513
|
-
real_is_foreground = winmod.is_foreground
|
|
514
|
-
real_confirm = winmod.confirm_window
|
|
515
|
-
real_sleep = winmod.time.sleep
|
|
516
|
-
try:
|
|
517
|
-
def fake_send_key(vk, *, ctrl=False):
|
|
518
|
-
pressed.append(("ctrl+v" if ctrl else "key") + ":%#x" % vk)
|
|
519
|
-
|
|
520
|
-
winmod._send_key = fake_send_key
|
|
521
|
-
winmod.user32.SetForegroundWindow = lambda _hwnd: 1
|
|
522
|
-
winmod.is_foreground = lambda _hwnd: True
|
|
523
|
-
winmod.confirm_window = lambda *a, **k: None
|
|
524
|
-
winmod.time.sleep = lambda _seconds: None
|
|
525
|
-
|
|
526
|
-
delivery_clipboard = _RecordingClipboard()
|
|
527
|
-
winmod.send_command(1, "/reload", clipboard=delivery_clipboard)
|
|
528
|
-
expected = ["key:0xd", "ctrl+v:0x56", "key:0xd"]
|
|
529
|
-
assert pressed == expected, f"delivery order was {pressed}, expected {expected}"
|
|
530
|
-
assert delivery_clipboard.writes[0] == "/reload", delivery_clipboard.writes
|
|
531
|
-
finally:
|
|
532
|
-
winmod._send_key = real_send_key
|
|
533
|
-
winmod.user32.SetForegroundWindow = real_set_fg
|
|
534
|
-
winmod.is_foreground = real_is_foreground
|
|
535
|
-
winmod.confirm_window = real_confirm
|
|
536
|
-
winmod.time.sleep = real_sleep
|
|
537
|
-
print("command delivery order (Return, Ctrl+V, Return) OK")
|
|
538
|
-
|
|
539
|
-
posted = []
|
|
540
|
-
real_post = winmod.user32.PostMessageW
|
|
541
|
-
real_sleep_messages = winmod.time.sleep
|
|
542
|
-
try:
|
|
543
|
-
winmod.user32.PostMessageW = (
|
|
544
|
-
lambda hwnd, msg, wparam, lparam: posted.append((msg, wparam)) or 1)
|
|
545
|
-
winmod.time.sleep = lambda _seconds: None
|
|
546
|
-
winmod.send_command_messages(1, "/reload")
|
|
547
|
-
finally:
|
|
548
|
-
winmod.user32.PostMessageW = real_post
|
|
549
|
-
winmod.time.sleep = real_sleep_messages
|
|
550
|
-
|
|
551
|
-
chars = "".join(chr(w) for m, w in posted if m == winmod.WM_CHAR)
|
|
552
|
-
assert chars == "/reload", chars
|
|
553
|
-
down = [w for m, w in posted if m == winmod.WM_KEYDOWN]
|
|
554
|
-
assert down == [winmod.VK_RETURN], down
|
|
555
|
-
assert all(m in (winmod.WM_CHAR, winmod.WM_KEYDOWN, winmod.WM_KEYUP)
|
|
556
|
-
for m, _w in posted), posted
|
|
557
|
-
print("command delivery via posted messages (no foreground) OK")
|
|
491
|
+
import unittest
|
|
492
|
+
from test_input_safety import InputSafetyTests
|
|
493
|
+
result = unittest.TextTestRunner().run(unittest.defaultTestLoader.loadTestsFromTestCase(InputSafetyTests))
|
|
494
|
+
assert result.wasSuccessful(), "input transaction regressions failed"
|
|
558
495
|
|
|
559
496
|
# The notice is drawn at the top-left corner of the game window, so the scan
|
|
560
497
|
# area must cover that corner. A ROI that drifts back to another corner makes
|
|
@@ -574,6 +511,47 @@ else:
|
|
|
574
511
|
"the Lua notice still anchors to TOPRIGHT while the ROI scans TOPLEFT"
|
|
575
512
|
print("Lua notice anchor and Python ROI agree on the top-left corner OK")
|
|
576
513
|
|
|
514
|
+
# The identity probe reads a marker from every running window so the caller
|
|
515
|
+
# can name the window before typing into it. Probing must keep the input
|
|
516
|
+
# order, isolate one bad window, and treat "no marker" as ordinary rather
|
|
517
|
+
# than as an error.
|
|
518
|
+
probe_delay = 0.3
|
|
519
|
+
|
|
520
|
+
def fake_identity_reader(hwnd, **_kwargs):
|
|
521
|
+
time.sleep(probe_delay)
|
|
522
|
+
if hwnd == 3:
|
|
523
|
+
raise winmod.WindowIdentityError("stale window")
|
|
524
|
+
if hwnd == 4:
|
|
525
|
+
return None
|
|
526
|
+
return {"v": 1, "id": f"char{hwnd}", "realm": "realm", "client": "retail"}
|
|
527
|
+
|
|
528
|
+
probe_windows = [{"hwnd": 1, "pid": 11}, {"hwnd": 2, "pid": 22},
|
|
529
|
+
{"hwnd": 3, "pid": 33}, {"hwnd": 4, "pid": 44}]
|
|
530
|
+
probe_start = time.monotonic()
|
|
531
|
+
probe_results = winmod.read_identities(probe_windows, reader=fake_identity_reader)
|
|
532
|
+
probe_elapsed = time.monotonic() - probe_start
|
|
533
|
+
|
|
534
|
+
assert [entry["hwnd"] for entry in probe_results] == [1, 2, 3, 4], probe_results
|
|
535
|
+
assert probe_results[0]["identity"]["id"] == "char1", probe_results[0]
|
|
536
|
+
assert probe_results[1]["identity"]["id"] == "char2", probe_results[1]
|
|
537
|
+
assert probe_results[2]["error"] == "stale window", probe_results[2]
|
|
538
|
+
assert probe_results[2]["identity"] is None, probe_results[2]
|
|
539
|
+
assert probe_results[3]["identity"] is None and probe_results[3]["error"] is None, \
|
|
540
|
+
probe_results[3]
|
|
541
|
+
# Windows are probed concurrently, so four delayed probes must cost far less
|
|
542
|
+
# than four sequential waits.
|
|
543
|
+
assert probe_elapsed < probe_delay * 2, probe_elapsed
|
|
544
|
+
assert winmod.read_identities([]) == []
|
|
545
|
+
# A found marker must return at once instead of waiting out the grace period.
|
|
546
|
+
instant_start = time.monotonic()
|
|
547
|
+
winmod.read_identities(probe_windows[:1],
|
|
548
|
+
reader=lambda _hwnd, **_kw: {"v": 1, "id": "fast"})
|
|
549
|
+
assert time.monotonic() - instant_start < probe_delay, "a found marker waited"
|
|
550
|
+
# The waiting budget must stay small: it is paid per window on every probe.
|
|
551
|
+
assert 0 < winmod.IDENTITY_FIRST_FRAME_GRACE <= 1.0, winmod.IDENTITY_FIRST_FRAME_GRACE
|
|
552
|
+
assert 0 < winmod.IDENTITY_TIMEOUT <= 5.0, winmod.IDENTITY_TIMEOUT
|
|
553
|
+
print("identity probe order, isolation and concurrency OK")
|
|
554
|
+
|
|
577
555
|
# --- host read acknowledgement ------------------------------------------------
|
|
578
556
|
#
|
|
579
557
|
# The plugin cannot see whether the host read a result, so the host says so with
|
|
@@ -683,6 +661,20 @@ timeout_events = [r["event"] for r in timeout_session.read_events()]
|
|
|
683
661
|
assert "notice_seen" not in timeout_events
|
|
684
662
|
print("poll_notice: stale notice rejected, fresh accepted, timeout bounded OK")
|
|
685
663
|
|
|
664
|
+
# Acknowledgement receipts must match Ticket, nonce, task and outcome together.
|
|
665
|
+
ack_good = notice_json(task="ack", run="ack-nonce", status="received")
|
|
666
|
+
ack_stale = notice_json(task="ack", run="old-nonce", status="received")
|
|
667
|
+
ack_wrong_ticket = notice_json(task="ack", run="ack-nonce", ticket="LYCHEE-other", status="received")
|
|
668
|
+
ack_wrong_status = notice_json(task="ack", run="ack-nonce", status="failed")
|
|
669
|
+
ack_resolved = cli.poll_notice(
|
|
670
|
+
_FakeWindows([[ack_stale, ack_wrong_ticket, ack_wrong_status], [ack_good]]),
|
|
671
|
+
fake_session, poll_args, expected_task="ack", expected_run="ack-nonce",
|
|
672
|
+
expected_ticket=ticket, expected_status="received")
|
|
673
|
+
assert ack_resolved and ack_resolved["status"] == "received"
|
|
674
|
+
for bad_ticket in ("LYCHEE-1\n/reload", "LYCHEE-1 received", "bad"):
|
|
675
|
+
expect_failure("ack ticket validation", lambda t=bad_ticket: cli.ack_command(t, "received"), cli.CliError)
|
|
676
|
+
print("ack receipt exact identity and command validation OK")
|
|
677
|
+
|
|
686
678
|
# --- registry: schema/kind rejection, hash, region preservation ---------------
|
|
687
679
|
|
|
688
680
|
def registry_text(*blocks):
|
|
@@ -838,10 +830,58 @@ with contextlib.redirect_stdout(out):
|
|
|
838
830
|
"--client", "retail",
|
|
839
831
|
"--wow-root", os.path.join(wow_root, "_retail_"),
|
|
840
832
|
"--addon-dir", addon_install]) == 0
|
|
833
|
+
out = io.StringIO()
|
|
841
834
|
with contextlib.redirect_stdout(out):
|
|
842
835
|
assert cli.main(["--data-dir", profile_data, "sv", "find", "--profile", "direct"]) == 0
|
|
843
|
-
assert expected_sv
|
|
836
|
+
assert out.getvalue().strip() == expected_sv, out.getvalue()
|
|
844
837
|
assert cli.main(["--data-dir", profile_data, "sv", "find", "--profile", "missing"]) == 1
|
|
838
|
+
|
|
839
|
+
# WoW: Forever lives in a reused test folder on the test track, so a profile for
|
|
840
|
+
# it must resolve whichever accepted folder actually holds the account tree.
|
|
841
|
+
assert cli.CLIENT_FOLDERS["forever"] == ("_classic_beta_", "_forever_"), \
|
|
842
|
+
cli.CLIENT_FOLDERS["forever"]
|
|
843
|
+
forever_account = os.path.join(wow_root, "_classic_beta_", "WTF", "Account",
|
|
844
|
+
"TESTACCOUNT", "SavedVariables")
|
|
845
|
+
os.makedirs(forever_account, exist_ok=True)
|
|
846
|
+
forever_sv = os.path.join(forever_account, "Lychee Dev.lua")
|
|
847
|
+
with open(forever_sv, "wb") as handle:
|
|
848
|
+
handle.write(b"LycheeDevDB = {}\n")
|
|
849
|
+
assert cli.main(["--data-dir", profile_data, "profile", "set", "--name", "forever-main",
|
|
850
|
+
"--client", "forever", "--wow-root", wow_root,
|
|
851
|
+
"--addon-dir", addon_install]) == 0
|
|
852
|
+
out = io.StringIO()
|
|
853
|
+
with contextlib.redirect_stdout(out):
|
|
854
|
+
assert cli.main(["--data-dir", profile_data, "sv", "find",
|
|
855
|
+
"--profile", "forever-main"]) == 0
|
|
856
|
+
assert out.getvalue().strip() == forever_sv, out.getvalue()
|
|
857
|
+
|
|
858
|
+
# The same profile must still resolve after the client moves to its own folder,
|
|
859
|
+
# without rewriting the profile: the recorded folder is a hint, not the answer.
|
|
860
|
+
os.rename(os.path.join(wow_root, "_classic_beta_"), os.path.join(wow_root, "_forever_"))
|
|
861
|
+
out = io.StringIO()
|
|
862
|
+
with contextlib.redirect_stdout(out):
|
|
863
|
+
assert cli.main(["--data-dir", profile_data, "sv", "find",
|
|
864
|
+
"--profile", "forever-main"]) == 0
|
|
865
|
+
assert out.getvalue().strip() == os.path.join(
|
|
866
|
+
wow_root, "_forever_", "WTF", "Account", "TESTACCOUNT", "SavedVariables",
|
|
867
|
+
"Lychee Dev.lua"), out.getvalue()
|
|
868
|
+
|
|
869
|
+
# The old bug: a profile that recorded `_classic_arena_` (which does not exist)
|
|
870
|
+
# must still fall back to the client's real folders.
|
|
871
|
+
stale = os.path.join(profile_data, "profiles.json")
|
|
872
|
+
with open(stale, encoding="utf-8") as handle:
|
|
873
|
+
stored = json.load(handle)
|
|
874
|
+
stored["forever-main"]["clientFolder"] = "_classic_arena_"
|
|
875
|
+
stored["forever-main"]["clientFolders"] = ["_classic_arena_"]
|
|
876
|
+
with open(stale, "w", encoding="utf-8") as handle:
|
|
877
|
+
json.dump(stored, handle)
|
|
878
|
+
out = io.StringIO()
|
|
879
|
+
with contextlib.redirect_stdout(out):
|
|
880
|
+
assert cli.main(["--data-dir", profile_data, "sv", "find",
|
|
881
|
+
"--profile", "forever-main"]) == 0, out.getvalue()
|
|
882
|
+
assert out.getvalue().strip() == os.path.join(
|
|
883
|
+
wow_root, "_forever_", "WTF", "Account", "TESTACCOUNT", "SavedVariables",
|
|
884
|
+
"Lychee Dev.lua"), out.getvalue()
|
|
845
885
|
print("profile set + sv find resolve the client folder OK")
|
|
846
886
|
|
|
847
887
|
# --- send: host log first, reload dedup, explicit input failure ---------------
|
|
@@ -890,14 +930,14 @@ try:
|
|
|
890
930
|
scoped = [r["event"] for r in
|
|
891
931
|
ses.Session(data_dir=send_data, installation="send-scope").read_events()]
|
|
892
932
|
assert scoped.count("reload_requested") == 1, scoped
|
|
893
|
-
assert scoped.count("
|
|
933
|
+
assert scoped.count("command_submitted") == 1, scoped
|
|
894
934
|
every = ses.Session(data_dir=send_data).read_events(
|
|
895
935
|
installation=ses.ALL_INSTALLATIONS)
|
|
896
|
-
assert [r["event"] for r in every].count("
|
|
936
|
+
assert [r["event"] for r in every].count("command_submitted") == 2
|
|
897
937
|
assert _FakeSendWindows.sent == [(1, "/reload"), (1, "/dev auto status x")]
|
|
898
|
-
assert _FakeSendWindows.modes == ["
|
|
938
|
+
assert _FakeSendWindows.modes == ["messages", "messages"], _FakeSendWindows.modes
|
|
899
939
|
assert cli.main(["--data-dir", send_data, "send", "--hwnd", "0x1",
|
|
900
|
-
"--mode", "messages", "--text", "
|
|
940
|
+
"--mode", "messages", "--text", "/dev"]) == 0
|
|
901
941
|
assert _FakeSendWindows.modes[-1] == "messages", _FakeSendWindows.modes
|
|
902
942
|
|
|
903
943
|
cli._window_module = lambda: _FailingSendWindows
|
|
@@ -910,6 +950,46 @@ finally:
|
|
|
910
950
|
cli._window_module = original_window_module
|
|
911
951
|
print("send host log + reload dedup + input failure exit OK")
|
|
912
952
|
|
|
953
|
+
# Drive the actual CLI acknowledgement flow: submission alone is unresolved.
|
|
954
|
+
from unittest.mock import patch
|
|
955
|
+
ack_data = os.path.join(tmp, "ack-flow")
|
|
956
|
+
ack_args = ["--data-dir", ack_data, "ack", "--hwnd", "1", "--ticket", "LYCHEE-1",
|
|
957
|
+
"--status", "received", "--timeout", "0.1"]
|
|
958
|
+
with patch.object(cli, "_window_module", return_value=_FakeSendWindows), \
|
|
959
|
+
patch.object(cli, "poll_notice", return_value=None):
|
|
960
|
+
assert cli.main(ack_args) == 5
|
|
961
|
+
ack_events = [r["event"] for r in ses.Session(data_dir=ack_data).read_events()]
|
|
962
|
+
assert "ticket_ack_unresolved" in ack_events and "ticket_ack_confirmed" not in ack_events
|
|
963
|
+
with patch.object(cli, "_window_module", return_value=_FakeSendWindows), \
|
|
964
|
+
patch.object(cli, "poll_notice", return_value={"status": "received"}) as poll, \
|
|
965
|
+
patch.object(cli, "wait_ack_cleared", return_value=True):
|
|
966
|
+
assert cli.main(ack_args) == 0
|
|
967
|
+
sent_nonce = _FakeSendWindows.sent[-2][1].split()[-1]
|
|
968
|
+
assert _FakeSendWindows.sent[-1][1] == f"/dev auto unidentify {sent_nonce}"
|
|
969
|
+
assert poll.call_args.kwargs["expected_run"] == sent_nonce
|
|
970
|
+
assert poll.call_args.kwargs["expected_ticket"] == "LYCHEE-1"
|
|
971
|
+
assert poll.call_args.kwargs["expected_status"] == "received"
|
|
972
|
+
with patch.object(cli, "_window_module", return_value=_FakeSendWindows), \
|
|
973
|
+
patch.object(cli, "poll_notice", return_value={}) as poll, \
|
|
974
|
+
patch.object(cli, "_notice_to_sv", return_value=0):
|
|
975
|
+
assert cli.main(["--data-dir", ack_data, "bugs", "--hwnd", "1", "--count", "2",
|
|
976
|
+
"--sv", "unused", "--request-id", "bug-proof-1"]) == 0
|
|
977
|
+
assert _FakeSendWindows.sent[-1][1] == "/dev auto bug 2 bug-proof-1"
|
|
978
|
+
assert poll.call_args.kwargs["expected_run"] == "bug-proof-1"
|
|
979
|
+
# Cleanup requires observed frames, and a still-visible receipt must time out.
|
|
980
|
+
cleanup_args = argparse.Namespace(hwnd=1, pid=None, exe_path=None, timeout=0.03, interval=0.001)
|
|
981
|
+
assert cli.wait_ack_cleared(_FakeWindows([[], []]), cleanup_args, "cleanup-nonce")
|
|
982
|
+
visible_receipt = notice_json(task="ack", run="cleanup-nonce", status="received")
|
|
983
|
+
assert not cli.wait_ack_cleared(_FakeWindows([[visible_receipt], [visible_receipt]]),
|
|
984
|
+
cleanup_args, "cleanup-nonce")
|
|
985
|
+
class _NoFrameCapture(_FakeCapture):
|
|
986
|
+
def latest_roi(self): return None
|
|
987
|
+
no_frames = _FakeWindows([])
|
|
988
|
+
no_frames.open_notice_capture = lambda *a, **k: _NoFrameCapture()
|
|
989
|
+
assert not cli.wait_ack_cleared(no_frames, cleanup_args, "cleanup-nonce")
|
|
990
|
+
print("ack CLI unresolved/confirmed lifecycle and bug request delivery OK")
|
|
991
|
+
|
|
992
|
+
|
|
913
993
|
# --- packaging metadata -------------------------------------------------------
|
|
914
994
|
|
|
915
995
|
requirements = os.path.join(HERE, "requirements.txt")
|