sdtk-code-kit 0.4.4 → 0.5.0
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/README.md +1 -1
- package/assets/manifest/toolkit-bundle.manifest.json +82 -12
- package/assets/manifest/toolkit-bundle.sha256.txt +21 -7
- package/assets/toolkit/toolkit/AGENTS.md +1 -1
- package/assets/toolkit/toolkit/SDTKCODE_TOOLKIT.md +2 -2
- package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +4 -4
- package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +4 -4
- package/assets/toolkit/toolkit/scripts/uninstall-claude-skills.ps1 +2 -2
- package/assets/toolkit/toolkit/scripts/uninstall-codex-skills.ps1 +2 -2
- package/assets/toolkit/toolkit/skills/code-discover/SKILL.md +3 -1
- package/assets/toolkit/toolkit/skills/code-ui-e2e/SKILL.md +97 -0
- package/assets/toolkit/toolkit/skills/code-ui-e2e/references/PROFILE_TEMPLATE.md +30 -0
- package/assets/toolkit/toolkit/skills/code-ui-e2e/references/SAFETY.md +17 -0
- package/assets/toolkit/toolkit/skills/code-ui-e2e/references/TEST_HOOKS.md +32 -0
- package/assets/toolkit/toolkit/skills/code-ui-e2e/scripts/app_profile.py +118 -0
- package/assets/toolkit/toolkit/skills/code-ui-e2e/scripts/build_test_app.py +140 -0
- package/assets/toolkit/toolkit/skills/code-ui-e2e/scripts/cli.py +46 -0
- package/assets/toolkit/toolkit/skills/code-ui-e2e/scripts/fault_proxy.py +381 -0
- package/assets/toolkit/toolkit/skills/code-ui-e2e/scripts/run_smoke.py +242 -0
- package/assets/toolkit/toolkit/skills/code-ui-e2e/scripts/test_app_profile.py +79 -0
- package/assets/toolkit/toolkit/skills/code-ui-e2e/scripts/test_fault_proxy.py +327 -0
- package/assets/toolkit/toolkit/skills/code-ui-e2e/scripts/test_run_smoke.py +79 -0
- package/assets/toolkit/toolkit/skills/code-ui-e2e/scripts/uia_base.py +127 -0
- package/assets/toolkit/toolkit/skills/code-ui-e2e/scripts/waits.py +40 -0
- package/package.json +1 -1
- package/src/lib/scope.js +1 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""run_smoke with a fake suite and a fake markdown (no app) — python -m unittest test_run_smoke (from this folder)"""
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import tempfile
|
|
6
|
+
import textwrap
|
|
7
|
+
import unittest
|
|
8
|
+
|
|
9
|
+
import run_smoke
|
|
10
|
+
|
|
11
|
+
MARKDOWN = textwrap.dedent("""\
|
|
12
|
+
## 4.1 UI
|
|
13
|
+
| ID | Mức | Tiền điều kiện | Bước | Kỳ vọng | Spec | KQ | Ghi chú |
|
|
14
|
+
|---|---|---|---|---|---|---|---|
|
|
15
|
+
| **TST-UI-01** | | — | a | b | m1 | ☐ | |
|
|
16
|
+
| **TST-FN-01** | 🔴 | — | a | b | m1 | ☐ | |
|
|
17
|
+
| TST-FN-02 | 🟡 | — | a | b | m1 | ☐ | |
|
|
18
|
+
| **TST-ER-01** | | — | a | b | m1 | ☐ | |
|
|
19
|
+
| **TST-BV-01** | | — | a | b | m1 | ☐ | |
|
|
20
|
+
| **TST-RG-01** | | — | a | b | m1 | ☐ | |
|
|
21
|
+
Text mentioning TST-FN-01 again is not a row.
|
|
22
|
+
## 5. Ma trận
|
|
23
|
+
| **TST-FN-01** | m1 |
|
|
24
|
+
""")
|
|
25
|
+
|
|
26
|
+
SUITE = textwrap.dedent("""\
|
|
27
|
+
SOURCE = {source!r}
|
|
28
|
+
def ok(ctx): ctx.check(True, "fine")
|
|
29
|
+
def ng(ctx): ctx.check(False, "folder B unchanged")
|
|
30
|
+
def boom(ctx): raise RuntimeError("no window")
|
|
31
|
+
def held(ctx): ctx.hold("CB-3 not ready")
|
|
32
|
+
def look(ctx): ctx.check(True, "x"); ctx.visual("chip shows リアルタイム")
|
|
33
|
+
CASES = {{"TST-UI-01": ok, "TST-FN-01": ng, "TST-FN-02": boom, "TST-ER-01": held, "TST-BV-01": look}}
|
|
34
|
+
MANUAL = {{"TST-RG-01": "install over the old build"}}
|
|
35
|
+
def setup(ctx): ctx.state["setup"] = True
|
|
36
|
+
def teardown(ctx): open({marker!r}, "w").write(str(ctx.state.get("setup")))
|
|
37
|
+
""")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class RunSmokeTests(unittest.TestCase):
|
|
41
|
+
def setUp(self):
|
|
42
|
+
self.tmp = tempfile.TemporaryDirectory()
|
|
43
|
+
self.md = os.path.join(self.tmp.name, "SMOKE_TEST_X_VI.md")
|
|
44
|
+
open(self.md, "w", encoding="utf-8").write(MARKDOWN)
|
|
45
|
+
self.marker = os.path.join(self.tmp.name, "teardown.txt")
|
|
46
|
+
self.suite = os.path.join(self.tmp.name, "tst.py")
|
|
47
|
+
open(self.suite, "w", encoding="utf-8").write(SUITE.format(source=self.md, marker=self.marker))
|
|
48
|
+
|
|
49
|
+
def tearDown(self):
|
|
50
|
+
self.tmp.cleanup()
|
|
51
|
+
|
|
52
|
+
def test_markdown_ids_are_table_rows_in_order(self):
|
|
53
|
+
self.assertEqual(run_smoke.markdown_ids(self.md),
|
|
54
|
+
["TST-UI-01", "TST-FN-01", "TST-FN-02", "TST-ER-01", "TST-BV-01", "TST-RG-01"])
|
|
55
|
+
|
|
56
|
+
def test_statuses_report_and_teardown(self):
|
|
57
|
+
out, results = run_smoke.run(self.suite, env={}, results_root=self.tmp.name)
|
|
58
|
+
status = {r["id"]: r["status"] for r in results}
|
|
59
|
+
self.assertEqual(status, {"TST-UI-01": "OK", "TST-FN-01": "NG", "TST-FN-02": "NG",
|
|
60
|
+
"TST-ER-01": "保留", "TST-BV-01": "要目視"})
|
|
61
|
+
self.assertEqual(open(self.marker).read(), "True")
|
|
62
|
+
report = open(os.path.join(out, "report.md"), encoding="utf-8").read()
|
|
63
|
+
self.assertIn("| TST-RG-01 | 手動 | install over the old build |", report)
|
|
64
|
+
self.assertIn("✗ folder B unchanged", report)
|
|
65
|
+
data = json.load(open(os.path.join(out, "results.json"), encoding="utf-8"))
|
|
66
|
+
self.assertEqual(data["coverage"]["TST-RG-01"], "手動: install over the old build")
|
|
67
|
+
|
|
68
|
+
def test_only(self):
|
|
69
|
+
_, results = run_smoke.run(self.suite, only={"TST-UI-01"}, env={}, results_root=self.tmp.name)
|
|
70
|
+
self.assertEqual([r["id"] for r in results], ["TST-UI-01"])
|
|
71
|
+
|
|
72
|
+
def test_unknown_id_is_refused(self):
|
|
73
|
+
open(self.suite, "a", encoding="utf-8").write('CASES["TST-FN-99"] = ok\n')
|
|
74
|
+
with self.assertRaises(SystemExit):
|
|
75
|
+
run_smoke.run(self.suite, env={}, results_root=self.tmp.name)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
unittest.main()
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Building blocks for a Windows desktop-app driver on UI Automation (pywinauto, UIA backend). A project's driver
|
|
3
|
+
(its pages, buttons, dialogs) builds on these; nothing here knows any product.
|
|
4
|
+
|
|
5
|
+
Import this module BEFORE pywinauto anywhere else: it makes the process per-monitor DPI aware first. With monitors at
|
|
6
|
+
different scales a system-aware process gets scaled coordinates for a window on the other monitor, and a click lands
|
|
7
|
+
somewhere else (the title bar's minimize button, in practice).
|
|
8
|
+
"""
|
|
9
|
+
import ctypes
|
|
10
|
+
import re
|
|
11
|
+
import time
|
|
12
|
+
|
|
13
|
+
ctypes.windll.user32.SetProcessDpiAwarenessContext(ctypes.c_void_p(-4)) # PER_MONITOR_AWARE_V2
|
|
14
|
+
|
|
15
|
+
from pywinauto import Desktop # noqa: E402
|
|
16
|
+
from pywinauto.findwindows import ElementNotFoundError # noqa: E402
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class DriverError(Exception):
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Fatal(DriverError):
|
|
24
|
+
"""Raise inside a wait_until predicate to stop waiting at once (what is waited for will never come)."""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def wait_until(predicate, timeout, interval=0.5, what="condition"):
|
|
28
|
+
end = time.time() + timeout
|
|
29
|
+
last_error = None
|
|
30
|
+
while time.time() < end:
|
|
31
|
+
try:
|
|
32
|
+
value = predicate()
|
|
33
|
+
if value:
|
|
34
|
+
return value
|
|
35
|
+
except Fatal:
|
|
36
|
+
raise
|
|
37
|
+
except Exception as e: # noqa: BLE001 - the window may be rebuilding its controls
|
|
38
|
+
last_error = e
|
|
39
|
+
time.sleep(interval)
|
|
40
|
+
raise DriverError(f"timeout ({timeout}s) waiting for {what}" + (f": {last_error}" if last_error else ""))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def find_control(parent, title=None, title_re=None, control_type=None, found_index=0):
|
|
44
|
+
"""The found_index-th descendant with exactly that name (or name pattern) and control type. Exact match on
|
|
45
|
+
purpose: matching a prefix clicked the wrong checkbox when two labels started alike."""
|
|
46
|
+
found = [c for c in parent.descendants(control_type=control_type)
|
|
47
|
+
if (title is None or c.element_info.name == title)
|
|
48
|
+
and (title_re is None or re.fullmatch(title_re, c.element_info.name))]
|
|
49
|
+
if len(found) <= found_index:
|
|
50
|
+
raise ElementNotFoundError(f"{control_type} {title or title_re!r} not found")
|
|
51
|
+
return found[found_index]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def process_windows(pid):
|
|
55
|
+
return list(Desktop(backend="uia").windows(process=pid))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def press(button):
|
|
59
|
+
"""Invoke through UI Automation first (works when a toast covers the button), then fall back to a click."""
|
|
60
|
+
try:
|
|
61
|
+
button.invoke()
|
|
62
|
+
except Exception: # noqa: BLE001
|
|
63
|
+
button.click_input()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def foreground_pid():
|
|
67
|
+
pid = ctypes.c_ulong()
|
|
68
|
+
ctypes.windll.user32.GetWindowThreadProcessId(ctypes.windll.user32.GetForegroundWindow(), ctypes.byref(pid))
|
|
69
|
+
return pid.value
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def ensure_foreground(window, pid, what="the app window"):
|
|
73
|
+
"""Before any keystroke or coordinate click: the app must own the foreground window. Typing into whatever else
|
|
74
|
+
is in front (a browser, an editor) has sent a password to the wrong window."""
|
|
75
|
+
window.set_focus()
|
|
76
|
+
time.sleep(0.3)
|
|
77
|
+
if foreground_pid() != pid:
|
|
78
|
+
raise DriverError(f"{what} is not in the foreground: stopped before typing or clicking")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def dpi_scale(window) -> float:
|
|
82
|
+
handle = getattr(window, "handle", None)
|
|
83
|
+
return ctypes.windll.user32.GetDpiForWindow(handle) / 96 if handle else 1.0
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def dialog_buttons(dialog, exclude=("Minimize", "Maximize", "Restore", "Close")):
|
|
87
|
+
return [b for b in dialog.descendants(control_type="Button") if b.element_info.name not in exclude]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def press_first(dialog, names):
|
|
91
|
+
"""Presses the first button whose name is in `names` (e.g. ("OK", "閉じる") across product versions)."""
|
|
92
|
+
buttons = dialog_buttons(dialog)
|
|
93
|
+
for name in names:
|
|
94
|
+
for b in buttons:
|
|
95
|
+
if b.element_info.name == name:
|
|
96
|
+
press(b)
|
|
97
|
+
return name
|
|
98
|
+
raise DriverError(f"none of {names} in the dialog: {[b.element_info.name for b in buttons]}")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def folder_dialog_box(picker):
|
|
102
|
+
"""The folder field of the Windows common folder dialog: an Edit with automation id 1152 (or under a
|
|
103
|
+
「フォルダー」 / "Folder" combo box). Lists the dialog's fields when not found, so the next fix is not a guess."""
|
|
104
|
+
for e in picker.descendants(control_type="Edit"):
|
|
105
|
+
parent = e.parent()
|
|
106
|
+
names = (e.element_info.name, parent.element_info.name if parent else "")
|
|
107
|
+
if e.element_info.automation_id == "1152" or any(n.startswith(("フォルダー", "Folder")) for n in names):
|
|
108
|
+
return e
|
|
109
|
+
fields = [f"{e.element_info.control_type}:{e.element_info.name!r}:{e.element_info.automation_id}"
|
|
110
|
+
for e in picker.descendants() if e.element_info.control_type in ("Edit", "ComboBox", "Button")]
|
|
111
|
+
raise DriverError(f"no folder field in the folder dialog: {fields}")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def screenshot(window, path, inset=0, mark=None):
|
|
115
|
+
"""The window's rectangle as it is on screen (toasts and menus over it included). `inset` trims rounded corners
|
|
116
|
+
where the desktop shows through (about 8 px for dialogs); `mark` = a control to frame in red, as a person
|
|
117
|
+
marking 'press this' on a manual screenshot would."""
|
|
118
|
+
from PIL import ImageDraw, ImageGrab
|
|
119
|
+
r = window.rectangle()
|
|
120
|
+
left, top, right, bottom = r.left + inset, r.top + inset, r.right - inset, r.bottom - inset
|
|
121
|
+
img = ImageGrab.grab(bbox=(left, top, right, bottom), all_screens=True)
|
|
122
|
+
if mark is not None:
|
|
123
|
+
m = mark.rectangle()
|
|
124
|
+
ImageDraw.Draw(img).rectangle((m.left - left - 3, m.top - top - 3, m.right - left + 3, m.bottom - top + 3),
|
|
125
|
+
outline=(230, 0, 0), width=4)
|
|
126
|
+
img.save(path)
|
|
127
|
+
return path
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Waiting for things that happen on the app's own clock: a periodic background cycle (sync, polling, scheduled
|
|
3
|
+
work), a file or folder that appears, a history row. Every wait has a timeout and prints what it waits for, so a long
|
|
4
|
+
run shows where it is. Set SYNC_CYCLE_SECONDS to the app's cycle (from the project's e2e profile)."""
|
|
5
|
+
import os
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
SYNC_CYCLE_SECONDS = 5 * 60 # the app's background cycle; override from the e2e profile
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class WaitTimeout(RuntimeError):
|
|
12
|
+
pass
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def until(predicate, timeout: float, interval: float = 5, what: str = "condition", clock=time):
|
|
16
|
+
"""Polls `predicate` until it returns something truthy (returned) or `timeout` seconds pass (WaitTimeout)."""
|
|
17
|
+
end = clock.time() + timeout
|
|
18
|
+
print(f" waiting up to {timeout:.0f}s for {what}", flush=True)
|
|
19
|
+
while True:
|
|
20
|
+
value = predicate()
|
|
21
|
+
if value:
|
|
22
|
+
return value
|
|
23
|
+
if clock.time() >= end:
|
|
24
|
+
raise WaitTimeout(f"{what}: not within {timeout:.0f}s")
|
|
25
|
+
clock.sleep(interval)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def cycles(n: float, what: str = "", clock=time):
|
|
29
|
+
"""Sleeps n sync cycles (a case that must show something did NOT happen in that time)."""
|
|
30
|
+
seconds = n * SYNC_CYCLE_SECONDS
|
|
31
|
+
print(f" sleeping {n} cycle(s) = {seconds:.0f}s" + (f" ({what})" if what else ""), flush=True)
|
|
32
|
+
clock.sleep(seconds)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def path_exists(path: str, timeout: float, what: str | None = None, clock=time) -> str:
|
|
36
|
+
return until(lambda: os.path.exists(path) and path, timeout, interval=2, what=what or f"{path} to exist", clock=clock)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def path_gone(path: str, timeout: float, what: str | None = None, clock=time) -> bool:
|
|
40
|
+
return until(lambda: not os.path.exists(path), timeout, interval=2, what=what or f"{path} to disappear", clock=clock)
|
package/package.json
CHANGED