forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_test_cmds.py
More file actions
73 lines (67 loc) · 3.82 KB
/
Copy pathadd_test_cmds.py
File metadata and controls
73 lines (67 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""Select 10 best diverse tasks and add test commands from lesson content."""
import json, re
from pathlib import Path
REPO = Path("/mnt/c/Users/hp/MisakaNet")
TASKS_DIR = REPO / "tasks"
LESSONS_DIR = REPO / "lessons"
# Pick the 10 most diverse, highest-quality tasks
# Strategy: one per domain, prioritizing those with code blocks
selected = {
"lesson-github-actions-code-injection": {
"reason": "Has explicit YAML examples showing safe/unsafe patterns",
"test_cmd": "python3 -c \"import yaml,sys;yaml.safe_load(open('lessons/github-actions-code-injection.md').read().split('```yaml')[1].split('```')[0]);print('YAML valid')\"",
},
"lesson-slugify-path-traversal-deep-coverage": {
"reason": "Has Python/pytest code for slugify function",
"test_cmd": "python3 -c \"import re;p=r'^[a-z0-9]+(-[a-z0-9]+)*$';assert re.match(p,'hello-world');assert not re.match(p,'../etc');print('slugify pattern OK')\"",
},
"lesson-chrome-relay-browser-automation": {
"reason": "Has CDP/WebSocket code block for browser automation",
"test_cmd": "python3 -c \"import json;obj={'method':'Target.createTarget','params':{'url':'about:blank'}};assert json.dumps(obj);print('CDP message OK')\"",
},
"lesson-auto-merge-ci-pipeline": {
"reason": "Has YAML workflow config that can be validated",
"test_cmd": "python3 -c \"import yaml;c=open('.github/workflows/pr-checks.yml').read();d=yaml.safe_load(c);assert 'jobs' in d;print(f'Workflow OK: {len(d[\"jobs\"])} jobs')\"",
},
"lesson-cronjob-one-shot-race-condition-duplicat": {
"reason": "Has distributed lock logic",
"test_cmd": "python3 -c \"import json;lock={'key':'cron_123','expires':9999999999};assert lock['key'];print('Distributed lock key OK')\"",
},
"lesson-feishu-markdown-table-not-rendered": {
"reason": "Has Feishu API message format examples",
"test_cmd": "python3 -c \"import json;msg={'msg_type':'post','content':json.dumps({'zh_cn':{'title':'test','content':[[{'tag':'text','text':'test'}]]}})};assert msg['msg_type']=='post';print('Feishu message OK')\"",
},
"lesson-git-credential-helper-gh-path-mismatch": {
"reason": "Has git credential config example",
"test_cmd": "git config --global --list 2>/dev/null | grep -q credential.helper; echo $?",
},
"lesson-oss-refactor-lessons": {
"reason": "Has lessons about architecture refactoring",
"test_cmd": "python3 -c \"import json;d=json.load(open('data/quality_scores.json'));print(f'{len(d[\"scores\"])} lessons scored, avg: {d[\"summary\"][\"average\"]}')\"",
},
"lesson-dco-auto-fix-workflow": {
"reason": "DCO check logic can be tested with regex",
"test_cmd": "python3 -c \"import re;p=re.compile(r'^Signed-off-by: .+<.+>',re.MULTILINE);assert p.search('Signed-off-by: Test <test@test.com>');assert not p.search('no signoff');print('DCO regex OK')\"",
},
"lesson-registration-chain-worker-fallback": {
"reason": "Has Worker registration flow logic",
"test_cmd": "python3 -c \"import json,sys;r=json.load(open('misaka-protocol.json'));assert 'nodes' in r and 'ecosystem' in r;print(f'Config OK: {r[\"nodes\"][\"current_count\"]} nodes')\"",
},
}
for tid, info in selected.items():
task_path = TASKS_DIR / f"{tid}.json"
if not task_path.exists():
print(f"❌ Task not found: {tid}")
continue
task = json.loads(task_path.read_text())
old_cmd = task.get("test_cmd", "")
task["test_cmd"] = info["test_cmd"]
json.dump(task, open(task_path, "w"), ensure_ascii=False, indent=2)
print(f"✅ {tid}: {info['reason']}")
if old_cmd:
print(f" replaced: {old_cmd[:60]}")
print(f" test_cmd: {info['test_cmd'][:70]}...")
print()
print(f"\n{'='*40}")
print("10 tasks updated with test commands")