sdtk-code-kit 0.4.4 → 0.6.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 +139 -14
- package/assets/manifest/toolkit-bundle.sha256.txt +33 -8
- package/assets/toolkit/toolkit/AGENTS.md +2 -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 +7 -2
- package/assets/toolkit/toolkit/skills/code-issue/SKILL.md +75 -0
- package/assets/toolkit/toolkit/skills/code-issue/references/MODE_FIX.md +31 -0
- package/assets/toolkit/toolkit/skills/code-issue/references/MODE_PICK.md +19 -0
- package/assets/toolkit/toolkit/skills/code-issue/references/MODE_PLAN.md +23 -0
- package/assets/toolkit/toolkit/skills/code-issue/references/MODE_REVIEW.md +21 -0
- package/assets/toolkit/toolkit/skills/code-issue/references/PROFILE_TEMPLATE.md +53 -0
- package/assets/toolkit/toolkit/skills/code-issue/references/RECORDS.md +39 -0
- package/assets/toolkit/toolkit/skills/code-issue/scripts/test_tracker.py +283 -0
- package/assets/toolkit/toolkit/skills/code-issue/scripts/tracker.py +465 -0
- package/assets/toolkit/toolkit/skills/code-review/SKILL.md +2 -1
- package/assets/toolkit/toolkit/skills/code-review/references/lead-review-lessons.md +30 -0
- package/assets/toolkit/toolkit/skills/code-review/references/lead-review.md +120 -0
- 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 +2 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""app_profile — python -m unittest test_app_profile (from this folder). Uses its own registry key
|
|
3
|
+
(HKCU\\Software\\sdtk-code-ui-e2e-unittest) and temp folders; the app's real key and data folder are never touched."""
|
|
4
|
+
import os
|
|
5
|
+
import subprocess
|
|
6
|
+
import tempfile
|
|
7
|
+
import sys
|
|
8
|
+
import unittest
|
|
9
|
+
|
|
10
|
+
if sys.platform != "win32":
|
|
11
|
+
raise unittest.SkipTest("app_profile parks the app's registry key and data folder: Windows only")
|
|
12
|
+
|
|
13
|
+
import winreg # noqa: E402
|
|
14
|
+
|
|
15
|
+
import app_profile # noqa: E402
|
|
16
|
+
|
|
17
|
+
KEY = r"Software\sdtk-code-ui-e2e-unittest"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def values():
|
|
21
|
+
out, i = {}, 0
|
|
22
|
+
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, KEY) as k:
|
|
23
|
+
while True:
|
|
24
|
+
try:
|
|
25
|
+
name, value, _ = winreg.EnumValue(k, i)
|
|
26
|
+
except OSError:
|
|
27
|
+
return out
|
|
28
|
+
out[name] = value
|
|
29
|
+
i += 1
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class AppProfileTests(unittest.TestCase):
|
|
33
|
+
def setUp(self):
|
|
34
|
+
self.tmp = tempfile.TemporaryDirectory()
|
|
35
|
+
self.data = os.path.join(self.tmp.name, "data")
|
|
36
|
+
os.makedirs(self.data)
|
|
37
|
+
open(os.path.join(self.data, "app.db"), "w").write("owner")
|
|
38
|
+
self.cfg = {"generations": [{"exe_name": "Old.exe", "data_dir": "%TEMP%\\old", "registry_key": "Software\\Old"},
|
|
39
|
+
{"exe_name": "App.exe", "data_dir": self.data, "registry_key": KEY,
|
|
40
|
+
"data_files": ["app.db"]}],
|
|
41
|
+
"profile_values": {"BaseFolderPath": "{work}\\{label}"}, "clear_values": ["Session"]}
|
|
42
|
+
with winreg.CreateKey(winreg.HKEY_CURRENT_USER, KEY) as k:
|
|
43
|
+
winreg.SetValueEx(k, "Session", 0, winreg.REG_SZ, "owner session")
|
|
44
|
+
winreg.SetValueEx(k, "BaseFolderPath", 0, winreg.REG_SZ, "C:\\owner")
|
|
45
|
+
self.ident = app_profile.identity(self.cfg, r"C:\build\APP.EXE")
|
|
46
|
+
self.state = app_profile.OwnerState(self.ident, self.cfg, os.path.join(self.tmp.name, "state"),
|
|
47
|
+
os.path.join(self.tmp.name, "work"), running=lambda exe: False)
|
|
48
|
+
|
|
49
|
+
def tearDown(self):
|
|
50
|
+
subprocess.run(["reg", "delete", "HKCU\\" + KEY, "/f"], capture_output=True)
|
|
51
|
+
self.tmp.cleanup()
|
|
52
|
+
|
|
53
|
+
def test_identity_follows_the_exe(self):
|
|
54
|
+
self.assertEqual(self.ident.registry_key, KEY)
|
|
55
|
+
self.assertEqual(app_profile.identity(self.cfg, None).exe_name, "Old.exe")
|
|
56
|
+
|
|
57
|
+
def test_park_switch_restore_round_trip(self):
|
|
58
|
+
self.state.park()
|
|
59
|
+
self.assertFalse(os.path.exists(os.path.join(self.data, "app.db")))
|
|
60
|
+
self.state.switch_to("TK-1")
|
|
61
|
+
v = values()
|
|
62
|
+
self.assertEqual(v["BaseFolderPath"], os.path.join(self.tmp.name, "work", "TK-1"))
|
|
63
|
+
self.assertNotIn("Session", v)
|
|
64
|
+
open(os.path.join(self.data, "app.db"), "w").write("tk1")
|
|
65
|
+
self.state.restore()
|
|
66
|
+
self.assertEqual(open(os.path.join(self.data, "app.db")).read(), "owner")
|
|
67
|
+
self.assertEqual(values()["Session"], "owner session")
|
|
68
|
+
self.assertEqual(open(os.path.join(self.tmp.name, "state", "TK-1", "app.db")).read(), "tk1")
|
|
69
|
+
|
|
70
|
+
def test_refuses_while_the_app_runs(self):
|
|
71
|
+
state = app_profile.OwnerState(self.ident, self.cfg, os.path.join(self.tmp.name, "s2"), self.tmp.name,
|
|
72
|
+
running=lambda exe: True)
|
|
73
|
+
with self.assertRaisesRegex(RuntimeError, "is running"):
|
|
74
|
+
state.park()
|
|
75
|
+
self.assertTrue(os.path.exists(os.path.join(self.data, "app.db")))
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
unittest.main()
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
"""Tests for fault_proxy.py - run with: python -m unittest test_fault_proxy (from this folder)
|
|
2
|
+
|
|
3
|
+
Stdlib only. A stand-in origin server is started, the proxy is put in front of it, and each mode is driven the way the
|
|
4
|
+
app (or a script) would drive it: through the proxy's own /__fault/mode path, then a request through the proxy.
|
|
5
|
+
"""
|
|
6
|
+
import http.client
|
|
7
|
+
import http.server
|
|
8
|
+
import os
|
|
9
|
+
import socket
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
import threading
|
|
13
|
+
import time
|
|
14
|
+
import unittest
|
|
15
|
+
|
|
16
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
17
|
+
import fault_proxy as fp # noqa: E402
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Origin(http.server.BaseHTTPRequestHandler):
|
|
21
|
+
def do_GET(self):
|
|
22
|
+
body = b"origin-ok"
|
|
23
|
+
self.send_response(200)
|
|
24
|
+
self.send_header("Content-Length", str(len(body)))
|
|
25
|
+
self.end_headers()
|
|
26
|
+
self.wfile.write(body)
|
|
27
|
+
|
|
28
|
+
def do_POST(self):
|
|
29
|
+
data = self.rfile.read(int(self.headers.get("Content-Length", 0)))
|
|
30
|
+
self.send_response(200)
|
|
31
|
+
self.send_header("Content-Length", str(len(data)))
|
|
32
|
+
self.end_headers()
|
|
33
|
+
self.wfile.write(data)
|
|
34
|
+
|
|
35
|
+
def log_message(self, *args):
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
_origin = None
|
|
40
|
+
_proxy_port = 0
|
|
41
|
+
_origin_port = 0
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def setUpModule():
|
|
45
|
+
global _origin, _proxy_port, _origin_port
|
|
46
|
+
_origin = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Origin)
|
|
47
|
+
_origin_port = _origin.server_address[1]
|
|
48
|
+
threading.Thread(target=_origin.serve_forever, daemon=True).start()
|
|
49
|
+
server = fp.listen(0)
|
|
50
|
+
_proxy_port = server.getsockname()[1]
|
|
51
|
+
threading.Thread(target=fp.serve, args=(server,), daemon=True).start()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def tearDownModule():
|
|
55
|
+
_origin.shutdown()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def set_mode_by_request(key):
|
|
59
|
+
c = http.client.HTTPConnection("127.0.0.1", _proxy_port, timeout=3)
|
|
60
|
+
c.request("GET", f"/__fault/mode/{key}")
|
|
61
|
+
r = c.getresponse()
|
|
62
|
+
return r.status, r.read().decode()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def via_proxy(method="GET", body=None, timeout=3):
|
|
66
|
+
c = http.client.HTTPConnection("127.0.0.1", _proxy_port, timeout=timeout)
|
|
67
|
+
c.request(method, f"http://127.0.0.1:{_origin_port}/x?y=1", body=body)
|
|
68
|
+
r = c.getresponse()
|
|
69
|
+
return r, r.read()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class ControlPath(unittest.TestCase):
|
|
73
|
+
def test_setting_a_mode_answers_with_it_and_changes_it(self):
|
|
74
|
+
self.assertEqual((200, "mode=5"), set_mode_by_request("5"))
|
|
75
|
+
self.assertEqual("5", fp.MODE)
|
|
76
|
+
|
|
77
|
+
def test_asking_for_the_mode_reports_it_without_changing_it(self):
|
|
78
|
+
set_mode_by_request("7")
|
|
79
|
+
c = http.client.HTTPConnection("127.0.0.1", _proxy_port, timeout=3)
|
|
80
|
+
c.request("GET", "/__fault/mode")
|
|
81
|
+
r = c.getresponse()
|
|
82
|
+
self.assertEqual((200, "mode=7"), (r.status, r.read().decode()))
|
|
83
|
+
self.assertEqual("7", fp.MODE)
|
|
84
|
+
|
|
85
|
+
def test_an_unknown_mode_is_refused_and_changes_nothing(self):
|
|
86
|
+
set_mode_by_request("p")
|
|
87
|
+
status, _ = set_mode_by_request("z")
|
|
88
|
+
self.assertEqual(400, status)
|
|
89
|
+
self.assertEqual("p", fp.MODE)
|
|
90
|
+
|
|
91
|
+
def test_the_control_request_is_answered_not_forwarded(self):
|
|
92
|
+
set_mode_by_request("p")
|
|
93
|
+
c = http.client.HTTPConnection("127.0.0.1", _proxy_port, timeout=3)
|
|
94
|
+
c.request("GET", f"http://127.0.0.1:{_origin_port}/__fault/mode") # absolute form, as a proxy client sends
|
|
95
|
+
r = c.getresponse()
|
|
96
|
+
self.assertEqual("mode=p", r.read().decode()) # the origin would have said origin-ok
|
|
97
|
+
|
|
98
|
+
def test_it_still_works_while_the_proxy_is_hanging_or_dropping(self):
|
|
99
|
+
for stuck in ("h", "d"):
|
|
100
|
+
fp.set_mode(stuck)
|
|
101
|
+
self.assertEqual((200, "mode=p"), set_mode_by_request("p"))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class Modes(unittest.TestCase):
|
|
105
|
+
def setUp(self):
|
|
106
|
+
set_mode_by_request("p")
|
|
107
|
+
|
|
108
|
+
def test_pass_forwards_a_get(self):
|
|
109
|
+
r, body = via_proxy()
|
|
110
|
+
self.assertEqual((200, b"origin-ok"), (r.status, body))
|
|
111
|
+
|
|
112
|
+
def test_pass_forwards_a_post_body(self):
|
|
113
|
+
r, body = via_proxy("POST", body=b"hello-body")
|
|
114
|
+
self.assertEqual((200, b"hello-body"), (r.status, body))
|
|
115
|
+
|
|
116
|
+
def test_5_answers_503(self):
|
|
117
|
+
set_mode_by_request("5")
|
|
118
|
+
r, _ = via_proxy()
|
|
119
|
+
self.assertEqual(503, r.status)
|
|
120
|
+
|
|
121
|
+
def test_7_answers_407_with_a_challenge(self):
|
|
122
|
+
set_mode_by_request("7")
|
|
123
|
+
r, _ = via_proxy()
|
|
124
|
+
self.assertEqual(407, r.status)
|
|
125
|
+
self.assertTrue(r.getheader("Proxy-Authenticate"))
|
|
126
|
+
|
|
127
|
+
def test_r_answers_302_with_a_location(self):
|
|
128
|
+
set_mode_by_request("r")
|
|
129
|
+
r, _ = via_proxy()
|
|
130
|
+
self.assertEqual(302, r.status)
|
|
131
|
+
self.assertTrue(r.getheader("Location"))
|
|
132
|
+
|
|
133
|
+
def test_d_cuts_the_connection(self):
|
|
134
|
+
set_mode_by_request("d")
|
|
135
|
+
with self.assertRaises((ConnectionError, http.client.RemoteDisconnected, OSError)):
|
|
136
|
+
via_proxy()
|
|
137
|
+
|
|
138
|
+
def test_h_never_answers(self):
|
|
139
|
+
set_mode_by_request("h")
|
|
140
|
+
started = time.time()
|
|
141
|
+
with self.assertRaises((socket.timeout, TimeoutError)):
|
|
142
|
+
via_proxy(timeout=2)
|
|
143
|
+
self.assertGreaterEqual(time.time() - started, 1.5)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class Connect(unittest.TestCase):
|
|
147
|
+
def connect(self):
|
|
148
|
+
s = socket.create_connection(("127.0.0.1", _proxy_port), timeout=3)
|
|
149
|
+
s.sendall(f"CONNECT 127.0.0.1:{_origin_port} HTTP/1.1\r\nHost: 127.0.0.1:{_origin_port}\r\n\r\n".encode())
|
|
150
|
+
return s, s.recv(4096)
|
|
151
|
+
|
|
152
|
+
def test_pass_tunnels_to_the_origin(self):
|
|
153
|
+
set_mode_by_request("p")
|
|
154
|
+
s, established = self.connect()
|
|
155
|
+
self.assertTrue(established.startswith(b"HTTP/1.1 200"))
|
|
156
|
+
s.sendall(b"GET /t HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n")
|
|
157
|
+
time.sleep(0.3)
|
|
158
|
+
self.assertIn(b"origin-ok", s.recv(4096))
|
|
159
|
+
s.close()
|
|
160
|
+
|
|
161
|
+
def test_5_answers_503_on_the_connect_itself(self):
|
|
162
|
+
set_mode_by_request("5")
|
|
163
|
+
s, answer = self.connect()
|
|
164
|
+
self.assertTrue(answer.startswith(b"HTTP/1.1 503"))
|
|
165
|
+
s.close()
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class StartupFlag(unittest.TestCase):
|
|
169
|
+
def test_mode_flag_starts_the_proxy_in_that_mode(self):
|
|
170
|
+
with socket.socket() as probe:
|
|
171
|
+
probe.bind(("127.0.0.1", 0))
|
|
172
|
+
port = probe.getsockname()[1]
|
|
173
|
+
proc = subprocess.Popen(
|
|
174
|
+
[sys.executable, os.path.join(os.path.dirname(os.path.abspath(__file__)), "fault_proxy.py"),
|
|
175
|
+
"--port", str(port), "--mode", "5"],
|
|
176
|
+
stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
177
|
+
try:
|
|
178
|
+
deadline = time.time() + 5
|
|
179
|
+
while True:
|
|
180
|
+
try:
|
|
181
|
+
c = http.client.HTTPConnection("127.0.0.1", port, timeout=2)
|
|
182
|
+
c.request("GET", f"http://127.0.0.1:{_origin_port}/x")
|
|
183
|
+
self.assertEqual(503, c.getresponse().status)
|
|
184
|
+
break
|
|
185
|
+
except ConnectionRefusedError:
|
|
186
|
+
if time.time() > deadline:
|
|
187
|
+
raise
|
|
188
|
+
time.sleep(0.1)
|
|
189
|
+
finally:
|
|
190
|
+
proc.kill()
|
|
191
|
+
proc.wait()
|
|
192
|
+
proc.stdin.close()
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
class VersionBodyTests(unittest.TestCase):
|
|
196
|
+
"""The version check can be answered by the proxy itself (mode p only), set through /__fault/versionbody/<body>."""
|
|
197
|
+
|
|
198
|
+
def setUp(self):
|
|
199
|
+
fp.MODE = "p" # an earlier test may have left the proxy in another mode
|
|
200
|
+
|
|
201
|
+
def tearDown(self):
|
|
202
|
+
fp.VERSION_BODY = None
|
|
203
|
+
|
|
204
|
+
def _post(self, path="/api/user-manager/system-limit-version"):
|
|
205
|
+
conn = http.client.HTTPConnection("127.0.0.1", _proxy_port, timeout=5)
|
|
206
|
+
conn.request("POST", f"http://127.0.0.1:{_origin_port}{path}", body=b'{"data":{"key":"k"}}', headers={"Content-Type": "application/json"})
|
|
207
|
+
r = conn.getresponse()
|
|
208
|
+
return r.status, r.read()
|
|
209
|
+
|
|
210
|
+
def _control(self, tail):
|
|
211
|
+
conn = http.client.HTTPConnection("127.0.0.1", _proxy_port, timeout=5)
|
|
212
|
+
conn.request("GET", f"/__fault/versionbody/{tail}")
|
|
213
|
+
r = conn.getresponse()
|
|
214
|
+
return r.status, r.read()
|
|
215
|
+
|
|
216
|
+
def test_the_version_check_gets_the_body_that_was_set(self):
|
|
217
|
+
self.assertEqual(self._control('{"status":0,"data":{"limit_version":2000000}}')[0], 200)
|
|
218
|
+
status, body = self._post()
|
|
219
|
+
self.assertEqual((status, body), (200, b'{"status":0,"data":{"limit_version":2000000}}'))
|
|
220
|
+
|
|
221
|
+
def test_an_empty_body_can_be_set(self):
|
|
222
|
+
self._control("__empty__")
|
|
223
|
+
self.assertEqual(self._post(), (200, b""))
|
|
224
|
+
|
|
225
|
+
def test_other_requests_are_still_forwarded(self):
|
|
226
|
+
self._control('{"status":0}')
|
|
227
|
+
status, body = self._post("/api/other")
|
|
228
|
+
self.assertEqual(body, b'{"data":{"key":"k"}}')
|
|
229
|
+
|
|
230
|
+
def test_a_dash_puts_the_real_answer_back(self):
|
|
231
|
+
self._control("x")
|
|
232
|
+
self._control("-")
|
|
233
|
+
self.assertEqual(self._post()[1], b'{"data":{"key":"k"}}')
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
class InFlightTests(unittest.TestCase):
|
|
237
|
+
"""Switching to a fault mode also cuts an exchange that is already being relayed (an upload under way)."""
|
|
238
|
+
|
|
239
|
+
def test_a_fault_mode_cuts_an_exchange_in_flight(self):
|
|
240
|
+
fp.MODE = "p"
|
|
241
|
+
a, b = socket.socketpair()
|
|
242
|
+
c, d = socket.socketpair()
|
|
243
|
+
t = threading.Thread(target=fp.relay, args=(a, c), daemon=True)
|
|
244
|
+
t.start()
|
|
245
|
+
time.sleep(0.3)
|
|
246
|
+
self.assertEqual(2, len(fp.ACTIVE))
|
|
247
|
+
fp.set_mode("d")
|
|
248
|
+
t.join(timeout=5)
|
|
249
|
+
self.assertFalse(t.is_alive())
|
|
250
|
+
self.assertEqual(0, len(fp.ACTIVE))
|
|
251
|
+
fp.set_mode("p")
|
|
252
|
+
for sk in (b, d):
|
|
253
|
+
sk.close()
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class RuleTests(unittest.TestCase):
|
|
257
|
+
"""An API request can be answered by the proxy with a chosen status (mode p), a limited number of times."""
|
|
258
|
+
|
|
259
|
+
def setUp(self):
|
|
260
|
+
fp.MODE = "p"
|
|
261
|
+
fp.RULES.clear()
|
|
262
|
+
|
|
263
|
+
def tearDown(self):
|
|
264
|
+
fp.RULES.clear()
|
|
265
|
+
|
|
266
|
+
def _rule(self, tail):
|
|
267
|
+
import urllib.parse
|
|
268
|
+
conn = http.client.HTTPConnection("127.0.0.1", _proxy_port, timeout=5)
|
|
269
|
+
conn.request("GET", "/__fault/rule/" + urllib.parse.quote(tail, safe=""))
|
|
270
|
+
r = conn.getresponse()
|
|
271
|
+
return r.status, r.read()
|
|
272
|
+
|
|
273
|
+
def _post(self, path):
|
|
274
|
+
conn = http.client.HTTPConnection("127.0.0.1", _proxy_port, timeout=5)
|
|
275
|
+
conn.request("POST", f"http://127.0.0.1:{_origin_port}{path}", body=b"{}")
|
|
276
|
+
r = conn.getresponse()
|
|
277
|
+
return r.status, r.read()
|
|
278
|
+
|
|
279
|
+
def test_a_rule_answers_with_its_status_and_body(self):
|
|
280
|
+
self._rule('{"match": "/items/search", "status": 409, "body": "{}"}')
|
|
281
|
+
self.assertEqual((409, b"{}"), self._post("/api/items/search/x"))
|
|
282
|
+
|
|
283
|
+
def test_other_paths_are_forwarded(self):
|
|
284
|
+
self._rule('{"match": "/items/search", "status": 409}')
|
|
285
|
+
self.assertEqual(200, self._post("/api/other")[0])
|
|
286
|
+
|
|
287
|
+
def test_times_limits_the_rule(self):
|
|
288
|
+
self._rule('{"match": "/api/", "status": 401, "times": 1}')
|
|
289
|
+
self.assertEqual(401, self._post("/api/a")[0])
|
|
290
|
+
self.assertEqual(200, self._post("/api/a")[0])
|
|
291
|
+
|
|
292
|
+
def test_not_match_excludes_a_path(self):
|
|
293
|
+
self._rule('{"match": "/api/", "not_match": "/user-manager/", "status": 401}')
|
|
294
|
+
self.assertEqual(200, self._post("/api/user-manager/login")[0])
|
|
295
|
+
self.assertEqual(401, self._post("/api/files")[0])
|
|
296
|
+
|
|
297
|
+
def test_a_dash_removes_the_rules(self):
|
|
298
|
+
self._rule('{"match": "/api/", "status": 401}')
|
|
299
|
+
self._rule("-")
|
|
300
|
+
self.assertEqual(200, self._post("/api/a")[0])
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
if __name__ == "__main__":
|
|
304
|
+
unittest.main()
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
class RuleMatching(unittest.TestCase):
|
|
308
|
+
"""rule_matches: which requests a rule answers (path rules, WebSocket-only rules, CONNECT rules)."""
|
|
309
|
+
|
|
310
|
+
WS = ["GET http://h/ws/signal HTTP/1.1", "Host: h", "Upgrade: websocket", "Connection: Upgrade"]
|
|
311
|
+
API = ["GET http://h/api/x HTTP/1.1", "Host: h"]
|
|
312
|
+
|
|
313
|
+
def test_path_rule_matches_ordinary_requests_not_a_connect(self):
|
|
314
|
+
rule = {"match": "/api/", "status": 503}
|
|
315
|
+
self.assertTrue(fp.rule_matches(rule, "GET", "http://h/api/x", self.API))
|
|
316
|
+
self.assertFalse(fp.rule_matches(rule, "CONNECT", "h:443", ["CONNECT h:443 HTTP/1.1"]))
|
|
317
|
+
|
|
318
|
+
def test_websocket_rule_matches_only_the_handshake(self):
|
|
319
|
+
rule = {"match": "", "websocket": True, "status": 503}
|
|
320
|
+
self.assertTrue(fp.rule_matches(rule, "GET", "http://h/ws/signal", self.WS))
|
|
321
|
+
self.assertFalse(fp.rule_matches(rule, "GET", "http://h/api/x", self.API))
|
|
322
|
+
|
|
323
|
+
def test_connect_rule_matches_only_a_connect_to_that_host(self):
|
|
324
|
+
rule = {"connect": "realtime.example:443", "status": 503}
|
|
325
|
+
self.assertTrue(fp.rule_matches(rule, "CONNECT", "realtime.example:443", ["CONNECT x HTTP/1.1"]))
|
|
326
|
+
self.assertFalse(fp.rule_matches(rule, "CONNECT", "s3.example:443", ["CONNECT x HTTP/1.1"]))
|
|
327
|
+
self.assertFalse(fp.rule_matches(rule, "GET", "http://realtime.example:443/x", self.API))
|
|
@@ -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
package/src/lib/scope.js
CHANGED
|
@@ -45,11 +45,13 @@ const MANAGED_CLAUDE_SKILLS = [
|
|
|
45
45
|
"code-discover",
|
|
46
46
|
"code-execute",
|
|
47
47
|
"code-finish",
|
|
48
|
+
"code-issue",
|
|
48
49
|
"code-parallel",
|
|
49
50
|
"code-plan",
|
|
50
51
|
"code-review",
|
|
51
52
|
"code-ship",
|
|
52
53
|
"code-tdd",
|
|
54
|
+
"code-ui-e2e",
|
|
53
55
|
"code-verify",
|
|
54
56
|
"code-worktree",
|
|
55
57
|
];
|