-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·4646 lines (4205 loc) · 174 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·4646 lines (4205 loc) · 174 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# test.sh — Self-tests for quick-question repo
# Run: ./test.sh
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Python compatibility (Windows Git Bash has python, not python3)
# Note: Windows Store has a python3 alias that exists but doesn't work,
# so we verify with --version, not just command -v.
QQ_PY="python3"
python3 --version >/dev/null 2>&1 || QQ_PY="python"
export QQ_PY
# Force core.autocrlf=false for all git operations in test fixtures so Windows
# checkouts don't appear "modified" relative to the index right after commit.
# Without this, the worktree closeout test sees its own committed files as dirty.
export GIT_CONFIG_PARAMETERS="'core.autocrlf=false'"
# OS detection — used to gate a small set of test fixtures that create fake
# bare-name executables (no .cmd / .exe extension) which Linux/macOS can run
# via shebang but Windows cannot exec via PATHEXT.
IS_WINDOWS=false
case "$(uname -s)" in
MINGW*|MSYS*|CYGWIN*) IS_WINDOWS=true ;;
esac
PASS=0
FAIL=0
SKIP=0
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
NC='\033[0m'
pass() { PASS=$((PASS + 1)); echo -e " ${GREEN}✓${NC} $1"; }
fail() { FAIL=$((FAIL + 1)); echo -e " ${RED}✗${NC} $1"; }
skip() { SKIP=$((SKIP + 1)); echo -e " ${YELLOW}∅${NC} $1 (skipped: $2)"; }
# ── 1. ShellCheck ──
echo -e "${CYAN}[1/10] ShellCheck${NC}"
if command -v shellcheck &>/dev/null; then
SHELL_FILES=$(find "$SCRIPT_DIR/scripts" -name "*.sh" -not -type l)
SHELL_FILES="$SHELL_FILES $SCRIPT_DIR/install.sh $SCRIPT_DIR/test.sh $SCRIPT_DIR/.devcontainer/postCreate.sh $SCRIPT_DIR/scripts/docker-dev.sh"
SC_FAIL=0
for f in $SHELL_FILES; do
if shellcheck -S error "$f" >/dev/null 2>&1; then
pass "$(basename "$f")"
else
fail "$(basename "$f")"
shellcheck -S error "$f" 2>&1 | head -20
SC_FAIL=1
fi
done
[ "$SC_FAIL" -eq 0 ] || echo ""
else
echo -e " ${CYAN}shellcheck not installed — skipping (brew install shellcheck)${NC}"
fi
# ── 2. Python compilation ──
echo -e "${CYAN}[2/10] Python compilation${NC}"
PY_FILES=$(find "$SCRIPT_DIR/scripts" -name "*.py" -not -type l)
for py_file in $PY_FILES; do
if $QQ_PY -m py_compile "$py_file" >/dev/null 2>&1; then
pass "$(basename "$py_file")"
else
fail "$(basename "$py_file")"
fi
done
# ── 3. JSON validity ──
echo -e "${CYAN}[3/10] JSON validity${NC}"
for json_file in scripts/qq-capabilities.json scripts/tykit_capabilities.json scripts/godot_capabilities.json scripts/unreal_capabilities.json scripts/sbox_capabilities.json hooks/hooks.json .claude-plugin/plugin.json .claude-plugin/marketplace.json docs/evals/foundation-smoke.json docs/evals/unity-local.json docs/evals/collaboration-multi-actor.json docs/evals/qq-bench-foundation.json docs/evals/qq-bench-core-v0.json docs/evals/qq-bench-core-v1.json docs/evals/qq-bench-core-solver-v0.json .devcontainer/devcontainer.json; do
if [ -f "$SCRIPT_DIR/$json_file" ]; then
if $QQ_PY -m json.tool "$SCRIPT_DIR/$json_file" >/dev/null 2>&1; then
pass "$json_file"
else
fail "$json_file — invalid JSON"
fi
else
fail "$json_file — file not found"
fi
done
# ── 4. Structural checks ──
echo -e "${CYAN}[4/10] Structural checks${NC}"
# Every skill directory has a SKILL.md
SKILL_DIRS=$(find "$SCRIPT_DIR/skills" -mindepth 1 -maxdepth 1 -type d)
for dir in $SKILL_DIRS; do
name=$(basename "$dir")
if [ -f "$dir/SKILL.md" ]; then
pass "skills/$name/SKILL.md exists"
else
fail "skills/$name/SKILL.md missing"
fi
done
# Hook scripts referenced in hooks.json actually exist
HOOK_SCRIPTS=$(grep -oE 'scripts/[a-z/._-]+\.sh' "$SCRIPT_DIR/hooks/hooks.json" || true)
for script in $HOOK_SCRIPTS; do
if [ -f "$SCRIPT_DIR/$script" ]; then
pass "hooks.json → $script exists"
else
fail "hooks.json → $script NOT FOUND"
fi
done
# Platform helper scripts exist
for pf in detect.sh macos.sh windows.sh; do
if [ -f "$SCRIPT_DIR/scripts/platform/$pf" ]; then
pass "scripts/platform/$pf exists"
else
fail "scripts/platform/$pf NOT FOUND"
fi
done
# Dev container files exist
for dc in .devcontainer/devcontainer.json .devcontainer/Dockerfile .devcontainer/postCreate.sh docs/dev/developer-workflow.md docs/dev/containerization.md scripts/docker-dev.sh; do
if [ -f "$SCRIPT_DIR/$dc" ]; then
pass "$dc exists"
else
fail "$dc NOT FOUND"
fi
done
# install.sh resolves hook/runtime modules instead of blindly copying the whole hooks tree
if grep -q 'hooks-auto-compile' "$SCRIPT_DIR/scripts/qq_internal_install.py" && grep -q 'qq_internal_install.py' "$SCRIPT_DIR/install.sh"; then
pass "install.sh resolves hook modules through qq_internal_install.py"
else
fail "install.sh missing modular hook install support"
fi
if grep -q 'updated existing dependency to tested release' "$SCRIPT_DIR/install.sh"; then
pass "install.sh repins existing tykit dependency"
else
fail "install.sh does not repin existing tykit dependency"
fi
# Symlinks in tykit Scripts~/ point to valid targets
TYKIT_SCRIPTS="$SCRIPT_DIR/packages/com.tyk.tykit/Scripts~"
if [ -d "$TYKIT_SCRIPTS" ]; then
for link in "$TYKIT_SCRIPTS"/*.sh; do
if [ -L "$link" ]; then
if [ -e "$link" ]; then
pass "symlink $(basename "$link") → valid"
else
fail "symlink $(basename "$link") → BROKEN"
fi
fi
done
fi
# tykit command coverage ratchet — enforce that the uncovered command count
# does not grow. As new tests land in v1.17.x, lower TYKIT_MAX_UNCOVERED.
# Run `python scripts/qq-tykit-coverage.py` standalone for the full report.
TYKIT_MAX_UNCOVERED=78
if [ -d "$SCRIPT_DIR/packages/com.tyk.tykit/Editor/Commands" ]; then
TYKIT_AUDIT_OUT=$("$QQ_PY" "$SCRIPT_DIR/scripts/qq-tykit-coverage.py" \
--project "$SCRIPT_DIR" --max-uncovered "$TYKIT_MAX_UNCOVERED" 2>&1)
TYKIT_AUDIT_EXIT=$?
TYKIT_UNCOVERED=$(printf '%s\n' "$TYKIT_AUDIT_OUT" | grep -oE 'uncovered: [0-9]+' | head -1 | awk '{print $2}')
if [ "$TYKIT_AUDIT_EXIT" -eq 0 ]; then
pass "tykit command coverage: ${TYKIT_UNCOVERED:-?} uncovered (max ${TYKIT_MAX_UNCOVERED})"
else
fail "tykit command coverage ratchet exceeded — ${TYKIT_UNCOVERED:-?} uncovered > max ${TYKIT_MAX_UNCOVERED}"
printf '%s\n' "$TYKIT_AUDIT_OUT" | sed 's/^/ /'
fi
fi
# Root README Chinese-half drift check — docs/zh-CN/README.md is the canonical
# Chinese source; root README's Chinese half is auto-generated by
# qq-sync-readme-zh.py. Run `python scripts/qq-sync-readme-zh.py --write` to fix.
if [ -f "$SCRIPT_DIR/scripts/qq-sync-readme-zh.py" ] && [ -f "$SCRIPT_DIR/docs/zh-CN/README.md" ]; then
if "$QQ_PY" "$SCRIPT_DIR/scripts/qq-sync-readme-zh.py" \
--check --project "$SCRIPT_DIR" >/dev/null 2>&1; then
pass "root README Chinese half in sync with docs/zh-CN/README.md"
else
fail "root README Chinese half drifts from docs/zh-CN/README.md (run: python scripts/qq-sync-readme-zh.py --write)"
fi
fi
# ── 5. README consistency ──
echo -e "${CYAN}[5/10] README consistency${NC}"
ACTUAL_SKILL_COUNT=$(find "$SCRIPT_DIR/skills" -mindepth 1 -maxdepth 1 -type d | wc -l | tr -d ' ')
if grep -qE "${ACTUAL_SKILL_COUNT} (skill|slash|Slash)" "$SCRIPT_DIR/README.md"; then
pass "README skill count ($ACTUAL_SKILL_COUNT) matches actual"
else
fail "README skill count does not match actual ($ACTUAL_SKILL_COUNT skills)"
fi
for dir in $SKILL_DIRS; do
name=$(basename "$dir")
if grep -q "/qq:${name}" "$SCRIPT_DIR/README.md"; then
pass "skill $name in README"
else
fail "skill $name NOT in README"
fi
done
# 5b: skill count consistency across language READMEs (Chinese 个, Japanese 個, Korean 개)
for lang_readme in "$SCRIPT_DIR/docs/zh-CN/README.md" "$SCRIPT_DIR/docs/ja/README.md" "$SCRIPT_DIR/docs/ko/README.md"; do
if [ -f "$lang_readme" ]; then
rel_path="${lang_readme#"$SCRIPT_DIR/"}"
if grep -qE "${ACTUAL_SKILL_COUNT} ?(skill|slash|个|個|개)" "$lang_readme"; then
pass "$rel_path mentions $ACTUAL_SKILL_COUNT (skill count consistent)"
else
fail "$rel_path does NOT mention $ACTUAL_SKILL_COUNT (skill count drift)"
fi
fi
done
# 5c: README version badge matches plugin.json
PLUGIN_VERSION=$($QQ_PY -c "import json,sys; print(json.load(open(sys.argv[1]))['version'])" "$SCRIPT_DIR/.claude-plugin/plugin.json" 2>/dev/null || printf 'unknown')
if [ "$PLUGIN_VERSION" != "unknown" ] && grep -q "version-v${PLUGIN_VERSION}" "$SCRIPT_DIR/README.md"; then
pass "README version badge matches plugin.json (v$PLUGIN_VERSION)"
else
fail "README version badge does NOT match plugin.json (v$PLUGIN_VERSION)"
fi
# 5d: no legacy review-gate-{check,set,count,stop}.sh references in docs/ or templates/
LEGACY_GATE_FILES=$(grep -rEl 'review-gate-(check|set|count|stop)\.sh' "$SCRIPT_DIR/docs" "$SCRIPT_DIR/templates" 2>/dev/null || true)
if [ -z "$LEGACY_GATE_FILES" ]; then
pass "no legacy review-gate-{check,set,count,stop}.sh refs in docs/ or templates/"
else
fail "legacy review-gate-*.sh refs found in:"
printf ' %s\n' $LEGACY_GATE_FILES
fi
# 5e: cross-doc link rot — verify every relative markdown link in tracked
# docs resolves to a file or directory that exists. Catches the class of
# drift where a doc gets renamed/moved without updating the things linking
# to it.
LINK_ROT_STATUS=0
LINK_ROT_OUTPUT="$($QQ_PY - "$SCRIPT_DIR" <<'PY' 2>&1
import re
import sys
from pathlib import Path
repo = Path(sys.argv[1])
# Inline markdown link: [text](url). Reference-style links and HTML <a> are
# intentionally out of scope — they're rare in this corpus and would add false
# positives. URL captures everything up to the next ')'.
link_re = re.compile(r'\[[^\]]*\]\(([^)\s]+)\)')
broken: list[str] = []
# Top-level docs at repo root.
candidates: list[Path] = []
for name in ('README.md', 'AGENTS.md', 'CLAUDE.md', 'CONTRIBUTING.md',
'SECURITY.md', 'CODE_OF_CONDUCT.md', 'CHANGELOG.md'):
p = repo / name
if p.is_file():
candidates.append(p)
# Recurse into docs/ and templates/, but skip:
# - docs/superpowers/ — historical spec/plan files for completed work
# that intentionally reference files since deleted (Context Capsule, etc.)
# - docs/main/ — codex review log dumps with absolute paths
# - any *_review.md — review output dumps, not maintained docs
SKIPPED_PARTS = {'superpowers', 'main'}
for sub in ('docs', 'templates'):
base = repo / sub
if not base.is_dir():
continue
for path in base.rglob('*.md'):
if any(part in SKIPPED_PARTS for part in path.parts):
continue
if path.name.endswith('_review.md'):
continue
candidates.append(path)
for path in candidates:
try:
text = path.read_text(encoding='utf-8')
except (OSError, UnicodeDecodeError):
continue
in_fence = False
fence_marker = chr(96) * 3 # avoid triple-backtick literal — bash $() parser
for lineno, line in enumerate(text.splitlines(), 1):
# Skip fenced code blocks (lines starting with three backticks).
if line.lstrip().startswith(fence_marker):
in_fence = not in_fence
continue
if in_fence:
continue
for m in link_re.finditer(line):
url = m.group(1).strip()
# Skip external URLs, in-page anchors, and non-file schemes.
if url.startswith(('http://', 'https://', 'mailto:', 'ftp://',
'tel:', 'data:', 'javascript:', '#')):
continue
# Drop fragment / query — we only check the file part.
url_path = url.split('#', 1)[0].split('?', 1)[0]
if not url_path:
continue
target = (path.parent / url_path).resolve()
if not target.exists():
rel = path.relative_to(repo).as_posix()
broken.append(f'{rel}:{lineno} -> {url}')
if broken:
print('\n'.join(broken))
sys.exit(1)
PY
)" || LINK_ROT_STATUS=$?
if [ "$LINK_ROT_STATUS" -eq 0 ]; then
pass "no broken relative markdown links in tracked docs"
else
BROKEN_COUNT=$(printf '%s' "$LINK_ROT_OUTPUT" | awk '/->/{c++} END{print c+0}')
fail "broken relative markdown links found ($BROKEN_COUNT)"
printf '%s\n' "$LINK_ROT_OUTPUT" | head -20 | sed 's/^/ /'
if [ "$BROKEN_COUNT" -gt 20 ]; then
printf ' ... %s more\n' "$((BROKEN_COUNT - 20))"
fi
fi
# 5f: cross-language link discipline — when a doc inside docs/<lang>/ links
# to a sibling in another language (e.g. docs/zh-CN/foo.md -> ../en/bar.md),
# verify that docs/<lang>/bar.md does NOT exist. If it does, the link should
# have been to the same-language sibling. Catches the v1.16.22 class of bug
# where zh-CN README's tykit-mcp / tykit-api / worktrees links pointed to
# ../en/ even though docs/zh-CN/ had identical filenames.
CROSS_LANG_STATUS=0
CROSS_LANG_OUTPUT="$($QQ_PY - "$SCRIPT_DIR" <<'PY' 2>&1
import re
import sys
from pathlib import Path
repo = Path(sys.argv[1])
docs = repo / 'docs'
if not docs.is_dir():
sys.exit(0)
# Discover language directories: docs/<lang>/ where <lang> looks like a
# language code (en, zh-CN, ja, ko, etc — heuristic: contains a letter or dash).
LANG_DIRS = {p.name for p in docs.iterdir() if p.is_dir() and p.name not in ('dev', 'evals', 'superpowers', 'main')}
link_re = re.compile(r'\[[^\]]*\]\(([^)\s]+)\)')
violations: list[str] = []
for lang in LANG_DIRS:
lang_dir = docs / lang
for path in lang_dir.rglob('*.md'):
if path.name.endswith('_review.md'):
continue
try:
text = path.read_text(encoding='utf-8')
except (OSError, UnicodeDecodeError):
continue
in_fence = False
fence = chr(96) * 3
for lineno, line in enumerate(text.splitlines(), 1):
if line.lstrip().startswith(fence):
in_fence = not in_fence
continue
if in_fence:
continue
for m in link_re.finditer(line):
url = m.group(1).strip()
if url.startswith(('http://', 'https://', 'mailto:', '#')):
continue
# Look for ../<other-lang>/ pattern
cross_match = re.match(r'^\.\./([^/]+)/(.+)$', url)
if not cross_match:
continue
other_lang = cross_match.group(1)
other_path = cross_match.group(2).split('#', 1)[0].split('?', 1)[0]
if other_lang == lang or other_lang not in LANG_DIRS:
continue
# Exempt language-switcher links: README.md cross-language links
# are intentional (the "English | 中文 | 日本語 | 한국어" header).
# Both source and target must be README.md to qualify as a switcher.
if path.name == 'README.md' and other_path == 'README.md':
continue
# Check if the same file exists in our own language directory
same_lang_target = lang_dir / other_path
if same_lang_target.exists():
rel = path.relative_to(repo).as_posix()
violations.append(
f'{rel}:{lineno} links to ../{other_lang}/{other_path} '
f'but docs/{lang}/{other_path} exists — link should be same-language sibling'
)
if violations:
print('\n'.join(violations))
sys.exit(1)
PY
)" || CROSS_LANG_STATUS=$?
if [ "$CROSS_LANG_STATUS" -eq 0 ]; then
pass "no cross-language links where same-language sibling exists"
else
CROSS_COUNT=$(printf '%s' "$CROSS_LANG_OUTPUT" | grep -c "->.*\.md\|links to" || echo 0)
fail "cross-language link discipline violations ($CROSS_COUNT — should be same-language sibling)"
printf '%s\n' "$CROSS_LANG_OUTPUT" | head -10 | sed 's/^/ /'
fi
# ── 6. SKILL.md frontmatter ──
echo -e "${CYAN}[6/10] SKILL.md frontmatter${NC}"
for dir in $SKILL_DIRS; do
name=$(basename "$dir")
if head -1 "$dir/SKILL.md" | grep -q '^---'; then
if grep -q '^description:' "$dir/SKILL.md"; then
pass "skills/$name has frontmatter + description"
else
fail "skills/$name missing description in frontmatter"
fi
else
fail "skills/$name missing frontmatter (---)"
fi
done
# ── 7. Script permissions ──
echo -e "${CYAN}[7/10] Script permissions${NC}"
for f in "$SCRIPT_DIR"/scripts/*.sh "$SCRIPT_DIR"/scripts/*.py "$SCRIPT_DIR"/scripts/hooks/*.sh "$SCRIPT_DIR/install.sh" "$SCRIPT_DIR/test.sh" "$SCRIPT_DIR/.devcontainer/postCreate.sh"; do
if [ -f "$f" ] && [ ! -L "$f" ]; then
if [ -x "$f" ]; then
pass "$(basename "$f") is executable"
else
fail "$(basename "$f") NOT executable"
fi
fi
done
DOCKER_DEV_META=$("$SCRIPT_DIR/scripts/docker-dev.sh" print-json)
if printf '%s' "$DOCKER_DEV_META" | $QQ_PY -c '
import json
import os
import sys
data = json.load(sys.stdin)
repo_root = os.path.realpath(data["repo_root"])
git_dir = os.path.realpath(data["git_dir"])
mount_root = os.path.realpath(data["mount_root"])
assert repo_root.startswith(mount_root)
assert git_dir.startswith(mount_root)
'
then
pass "docker-dev mount root covers repo root + git dir"
else
fail "docker-dev mount root covers repo root + git dir"
fi
# ── 8. Runtime helper smoke tests ──
echo -e "${CYAN}[8/10] Runtime helper smoke tests${NC}"
RUNTIME_TEST_ROOT="$(mktemp -d)"
mkdir -p "$RUNTIME_TEST_ROOT/Docs/design" "$RUNTIME_TEST_ROOT/Docs/qq/demo"
cat > "$RUNTIME_TEST_ROOT/Docs/design/sample.md" <<'EOF'
# Sample Design
EOF
cat > "$RUNTIME_TEST_ROOT/Docs/qq/demo/sample_implementation.md" <<'EOF'
# Sample Implementation
EOF
cat > "$RUNTIME_TEST_ROOT/Sample.cs" <<'EOF'
using UnityEngine;
public class Sample : MonoBehaviour
{
void Update()
{
GetComponent<Rigidbody>();
SendMessage("Ping");
if (gameObject.tag == "Player")
{
}
}
}
EOF
RUN_JSON=$($QQ_PY "$SCRIPT_DIR/scripts/qq-run-record.py" start --project "$RUNTIME_TEST_ROOT" --stage compile --command smoke --backend test --transport local --summary "smoke start")
RUN_ID=$(printf '%s' "$RUN_JSON" | $QQ_PY -c 'import json,sys; print(json.load(sys.stdin)["run_id"])')
$QQ_PY "$SCRIPT_DIR/scripts/qq-run-record.py" finish --project "$RUNTIME_TEST_ROOT" --run-id "$RUN_ID" --status passed --summary "smoke finish" >/dev/null
if $QQ_PY - "$RUNTIME_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
compile_state = json.loads((root / ".qq" / "state" / "compile.json").read_text(encoding="utf-8"))
project_state = json.loads((root / ".qq" / "state" / "project-state.json").read_text(encoding="utf-8")) if (root / ".qq" / "state" / "project-state.json").exists() else {}
events = (root / ".qq" / "telemetry" / "events.jsonl").read_text(encoding="utf-8").strip().splitlines()
assert compile_state["status"] == "passed"
assert len(events) >= 2
assert project_state == {}
PY
then
pass "run record writes state + telemetry"
else
fail "run record writes state + telemetry"
fi
$QQ_PY "$SCRIPT_DIR/scripts/qq-project-state.py" --project "$RUNTIME_TEST_ROOT" >/dev/null
if $QQ_PY - "$RUNTIME_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
state = json.loads((root / ".qq" / "state" / "project-state.json").read_text(encoding="utf-8"))
assert state["work_mode"] == "feature"
assert state["work_mode_source"] == "default"
assert state["config_format"] == "built_in_default"
assert state["shared_config_path"].endswith("qq.yaml")
assert state["local_config_path"].endswith(".qq/local.yaml")
assert state["profile"] == "feature"
assert state["profile_source"] == "default"
assert state["task_focus"] == []
assert state["task_focus_source"] == "default"
assert state["policy_profile"] == "feature"
assert state["policy_profile_source"] == "default"
assert state["policy_profile_expectations"]["review_expectation"] == "light"
assert state["default_test_scope"] == "all"
assert state["repository_design_doc_count"] == 1
assert state["repository_implementation_plan_count"] == 1
assert state["mode_recommended_next"] == "/qq:execute"
assert state["has_design_doc"] is True
assert state["has_implementation_plan"] is True
assert state["last_compile_status_raw"] == "passed"
assert state["last_compile_status"] == "passed"
assert state["compile_status_fresh"] is True
assert state["last_test_status_raw"] == "not_run"
assert state["test_status_fresh"] is True
assert state["recommended_next"] == "/qq:execute"
PY
then
pass "project state snapshot is generated"
else
fail "project state snapshot is generated"
fi
mkdir -p "$RUNTIME_TEST_ROOT/.qq"
cat > "$RUNTIME_TEST_ROOT/qq.yaml" <<'EOF'
version: 1
default_profile: core
work_mode: feature
enabled_rules:
- find_object_of_type
- send_message
- tag_compare
- get_component_in_hot_path
EOF
cat > "$RUNTIME_TEST_ROOT/.qq/local.yaml" <<'EOF'
work_mode: prototype
policy_profile: hardening
EOF
rm -f "$RUNTIME_TEST_ROOT/Docs/design/sample.md" "$RUNTIME_TEST_ROOT/Docs/qq/demo/sample_implementation.md"
$QQ_PY "$SCRIPT_DIR/scripts/qq-project-state.py" --project "$RUNTIME_TEST_ROOT" >/dev/null
if $QQ_PY - "$RUNTIME_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
state = json.loads((root / ".qq" / "state" / "project-state.json").read_text(encoding="utf-8"))
assert state["work_mode"] == "prototype"
assert state["work_mode_source"] == "qq_local_yaml"
assert state["task_focus"] == []
assert state["task_focus_source"] == "default"
assert state["policy_profile"] == "hardening"
assert state["policy_profile_source"] == "qq_local_yaml"
assert state["policy_profile_expectations"]["review_expectation"] == "required"
assert state["default_test_scope"] == "all"
assert state["repository_design_doc_count"] == 0
assert state["mode_recommended_next"] == "prototype_direct"
assert state["recommended_next"] == "prototype_direct"
assert state["mode_profile"]["changes_summary_expected"] is True
PY
then
pass "project state respects local work mode override"
else
fail "project state respects local work mode override"
fi
YAML_CONFIG_TEST_ROOT="$(mktemp -d)"
mkdir -p "$YAML_CONFIG_TEST_ROOT/.qq"
cat > "$YAML_CONFIG_TEST_ROOT/qq.yaml" <<'EOF'
version: 1
default_profile: lightweight
profiles:
reviewless:
extends: feature
remove_packs:
- workflow-review
- hooks-review-gate
EOF
$QQ_PY "$SCRIPT_DIR/scripts/qq-project-state.py" --project "$YAML_CONFIG_TEST_ROOT" >/dev/null
if $QQ_PY - "$YAML_CONFIG_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
state = json.loads((root / ".qq" / "state" / "project-state.json").read_text(encoding="utf-8"))
assert state["config_format"] == "qq_yaml"
assert state["shared_config_path"].endswith("qq.yaml")
assert state["local_config_path"].endswith(".qq/local.yaml")
assert state["profile"] == "lightweight"
assert state["profile_source"] == "qq_yaml"
assert state["work_mode"] == "prototype"
assert state["policy_profile"] == "core"
assert state["default_test_scope"] == "editmode"
assert "plan" not in state["enabled_skills"]
assert "claude-code-review" not in state["enabled_skills"]
assert "review_gate" not in state["enabled_hooks"]
PY
then
pass "qq.yaml lightweight profile resolves built-in packs"
else
fail "qq.yaml lightweight profile resolves built-in packs"
fi
cat > "$YAML_CONFIG_TEST_ROOT/.qq/local.yaml" <<'EOF'
profile: reviewless
work_mode: hardening
EOF
$QQ_PY "$SCRIPT_DIR/scripts/qq-project-state.py" --project "$YAML_CONFIG_TEST_ROOT" >/dev/null
if $QQ_PY - "$YAML_CONFIG_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
state = json.loads((root / ".qq" / "state" / "project-state.json").read_text(encoding="utf-8"))
assert state["profile"] == "reviewless"
assert state["profile_source"] == "qq_local_yaml"
assert state["work_mode"] == "hardening"
assert state["work_mode_source"] == "qq_local_yaml"
assert state["policy_profile"] == "feature"
assert state["policy_profile_source"] == "profile"
assert "plan" in state["enabled_skills"]
assert "claude-code-review" in state["enabled_skills"]
assert "review_gate" in state["enabled_hooks"]
PY
then
pass "local.yaml can select a custom profile while policy floor restores required review packs"
else
fail "local.yaml can select a custom profile while policy floor restores required review packs"
fi
rm -rf "$YAML_CONFIG_TEST_ROOT"
FOCUS_TEST_ROOT="$(mktemp -d)"
mkdir -p "$FOCUS_TEST_ROOT/Docs/design" "$FOCUS_TEST_ROOT/.qq"
cat > "$FOCUS_TEST_ROOT/Docs/design/crew_weapon.md" <<'EOF'
# Crew Weapon
EOF
cat > "$FOCUS_TEST_ROOT/Docs/design/map_refactor.md" <<'EOF'
# Map Refactor
EOF
cat > "$FOCUS_TEST_ROOT/qq.yaml" <<'EOF'
version: 1
default_profile: feature
work_mode: prototype
EOF
$QQ_PY "$SCRIPT_DIR/scripts/qq-project-state.py" --project "$FOCUS_TEST_ROOT" >/dev/null
if $QQ_PY - "$FOCUS_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
state = json.loads((root / ".qq" / "state" / "project-state.json").read_text(encoding="utf-8"))
assert state["repository_design_doc_count"] == 2
assert state["has_design_doc"] is False
assert state["design_docs"] == []
assert state["mode_recommended_next"] == "prototype_direct"
assert state["recommended_next"] == "prototype_direct"
PY
then
pass "repo-global design docs do not force prototype planning"
else
fail "repo-global design docs do not force prototype planning"
fi
cat > "$FOCUS_TEST_ROOT/.qq/local.yaml" <<'EOF'
work_mode: prototype
policy_profile: feature
task_focus: crew weapon
EOF
$QQ_PY "$SCRIPT_DIR/scripts/qq-project-state.py" --project "$FOCUS_TEST_ROOT" >/dev/null
if $QQ_PY - "$FOCUS_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
state = json.loads((root / ".qq" / "state" / "project-state.json").read_text(encoding="utf-8"))
assert state["task_focus"] == ["crew weapon"]
assert state["task_focus_source"] == "qq_local_yaml"
assert state["has_design_doc"] is True
assert state["design_docs"] == ["Docs/design/crew_weapon.md"]
assert state["mode_recommended_next"] == "/qq:plan"
assert state["recommended_next"] == "/qq:plan"
PY
then
pass "task focus can explicitly activate relevant design docs"
else
fail "task focus can explicitly activate relevant design docs"
fi
rm -rf "$FOCUS_TEST_ROOT"
POLICY_TEST_ROOT="$(mktemp -d)"
mkdir -p "$POLICY_TEST_ROOT/.qq"
(
cd "$POLICY_TEST_ROOT" &&
git init -q
)
cat > "$POLICY_TEST_ROOT/SeaMonsterSpike.cs" <<'EOF'
using UnityEngine;
public class SeaMonsterSpike : MonoBehaviour
{
void Start()
{
Debug.Log("spike");
}
}
EOF
RUN_JSON=$($QQ_PY "$SCRIPT_DIR/scripts/qq-run-record.py" start --project "$POLICY_TEST_ROOT" --stage compile --command policy-compile --backend test --transport local --summary "policy compile start")
RUN_ID=$(printf '%s' "$RUN_JSON" | $QQ_PY -c 'import json,sys; print(json.load(sys.stdin)["run_id"])')
$QQ_PY "$SCRIPT_DIR/scripts/qq-run-record.py" finish --project "$POLICY_TEST_ROOT" --run-id "$RUN_ID" --status passed --summary "policy compile passed" >/dev/null
cat > "$POLICY_TEST_ROOT/qq.yaml" <<'EOF'
version: 1
engine: unity
default_profile: core
work_mode: prototype
EOF
$QQ_PY "$SCRIPT_DIR/scripts/qq-project-state.py" --project "$POLICY_TEST_ROOT" >/dev/null
if $QQ_PY - "$POLICY_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
state = json.loads((root / ".qq" / "state" / "project-state.json").read_text(encoding="utf-8"))
assert state["has_uncommitted_runtime_changes"] is True
assert state["policy_profile"] == "core"
assert state["default_test_scope"] == "editmode"
assert state["has_uncommitted_test_changes"] is False
assert state["changed_test_files"] == []
assert state["mode_recommended_next"] == "/qq:changes"
assert state["recommended_next"] == "/qq:changes"
PY
then
pass "core profile keeps prototype recommendation light"
else
fail "core profile keeps prototype recommendation light"
fi
if PROJECT_DIR="$POLICY_TEST_ROOT" bash -lc '
source "'"$SCRIPT_DIR"'/scripts/qq-runtime.sh"
[ "$(qq_policy_profile)" = "core" ] &&
[ "$(qq_work_mode)" = "prototype" ] &&
[ "$(qq_default_test_scope)" = "editmode" ]
'; then
pass "qq-runtime helpers expose core policy defaults"
else
fail "qq-runtime helpers expose core policy defaults"
fi
$QQ_PY "$SCRIPT_DIR/scripts/qq-run-record.py" record --project "$POLICY_TEST_ROOT" --stage changes --command qq:changes --status checked --summary "prototype summary captured" --capture-local-changes >/dev/null
$QQ_PY "$SCRIPT_DIR/scripts/qq-project-state.py" --project "$POLICY_TEST_ROOT" >/dev/null
if $QQ_PY - "$POLICY_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
state = json.loads((root / ".qq" / "state" / "project-state.json").read_text(encoding="utf-8"))
assert state["changes_summary_fresh"] is True
assert state["last_changes_status"] == "checked"
assert state["mode_recommended_next"] == "/qq:commit-push"
assert state["recommended_next"] == "/qq:add-tests"
PY
then
pass "prototype changes summary advances the controller to commit-push"
else
fail "prototype changes summary advances the controller to commit-push"
fi
printf '// follow-up\n' >> "$POLICY_TEST_ROOT/SeaMonsterSpike.cs"
$QQ_PY "$SCRIPT_DIR/scripts/qq-project-state.py" --project "$POLICY_TEST_ROOT" >/dev/null
if $QQ_PY - "$POLICY_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
state = json.loads((root / ".qq" / "state" / "project-state.json").read_text(encoding="utf-8"))
assert state["changes_summary_fresh"] is False
assert state["mode_recommended_next"] == "verify_compile"
assert state["recommended_next"] == "verify_compile"
PY
then
pass "prototype changes summary is invalidated by newer local edits"
else
fail "prototype changes summary is invalidated by newer local edits"
fi
RUN_JSON=$($QQ_PY "$SCRIPT_DIR/scripts/qq-run-record.py" start --project "$POLICY_TEST_ROOT" --stage compile --command policy-compile-refresh --backend test --transport local --summary "policy compile refresh start")
RUN_ID=$(printf '%s' "$RUN_JSON" | $QQ_PY -c 'import json,sys; print(json.load(sys.stdin)["run_id"])')
$QQ_PY "$SCRIPT_DIR/scripts/qq-run-record.py" finish --project "$POLICY_TEST_ROOT" --run-id "$RUN_ID" --status passed --summary "policy compile refresh passed" >/dev/null
cat > "$POLICY_TEST_ROOT/.qq/local.yaml" <<'EOF'
work_mode: prototype
policy_profile: hardening
EOF
$QQ_PY "$SCRIPT_DIR/scripts/qq-project-state.py" --project "$POLICY_TEST_ROOT" >/dev/null
if $QQ_PY - "$POLICY_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
state = json.loads((root / ".qq" / "state" / "project-state.json").read_text(encoding="utf-8"))
assert state["policy_profile"] == "hardening"
assert state["default_test_scope"] == "all"
assert state["mode_recommended_next"] == "/qq:changes"
assert state["recommended_next"] == "/qq:test"
PY
then
pass "hardening profile raises prototype work to test first"
else
fail "hardening profile raises prototype work to test first"
fi
if PROJECT_DIR="$POLICY_TEST_ROOT" bash -lc '
source "'"$SCRIPT_DIR"'/scripts/qq-runtime.sh"
[ "$(qq_policy_profile)" = "hardening" ] &&
[ "$(qq_work_mode)" = "prototype" ] &&
[ "$(qq_default_test_scope)" = "all" ]
'; then
pass "qq-runtime helpers respect local profile override"
else
fail "qq-runtime helpers respect local profile override"
fi
RUN_JSON=$($QQ_PY "$SCRIPT_DIR/scripts/qq-run-record.py" start --project "$POLICY_TEST_ROOT" --stage test --command policy-test --backend test --transport local --summary "policy test start")
RUN_ID=$(printf '%s' "$RUN_JSON" | $QQ_PY -c 'import json,sys; print(json.load(sys.stdin)["run_id"])')
$QQ_PY "$SCRIPT_DIR/scripts/qq-run-record.py" finish --project "$POLICY_TEST_ROOT" --run-id "$RUN_ID" --status passed --summary "policy test passed" >/dev/null
$QQ_PY "$SCRIPT_DIR/scripts/qq-project-state.py" --project "$POLICY_TEST_ROOT" >/dev/null
if $QQ_PY - "$POLICY_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
state = json.loads((root / ".qq" / "state" / "project-state.json").read_text(encoding="utf-8"))
assert state["recommended_next"] == "/qq:claude-code-review"
PY
then
pass "hardening profile escalates to review after tests pass"
else
fail "hardening profile escalates to review after tests pass"
fi
RUN_JSON=$($QQ_PY "$SCRIPT_DIR/scripts/qq-run-record.py" start --project "$POLICY_TEST_ROOT" --stage review_gate --command policy-review --backend test --transport local --summary "policy review start")
RUN_ID=$(printf '%s' "$RUN_JSON" | $QQ_PY -c 'import json,sys; print(json.load(sys.stdin)["run_id"])')
$QQ_PY "$SCRIPT_DIR/scripts/qq-run-record.py" finish --project "$POLICY_TEST_ROOT" --run-id "$RUN_ID" --status verified --summary "policy review verified" >/dev/null
$QQ_PY "$SCRIPT_DIR/scripts/qq-project-state.py" --project "$POLICY_TEST_ROOT" >/dev/null
if $QQ_PY - "$POLICY_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
state = json.loads((root / ".qq" / "state" / "project-state.json").read_text(encoding="utf-8"))
assert state["review_gate_status"] == "verified"
assert state["recommended_next"] == "/qq:doc-drift"
PY
then
pass "hardening profile escalates to doc drift after review"
else
fail "hardening profile escalates to doc drift after review"
fi
rm -rf "$POLICY_TEST_ROOT"
# ── review gate three-field format ──
echo -e "${CYAN}[gate] three-field format${NC}"
GATE_TMP="$(mktemp -d)"
# gate-set creates three-field file
echo "$(date +%s):0:0" > "$GATE_TMP/review-gate-test"
IFS=: read -r _ts _completed _expected < "$GATE_TMP/review-gate-test"
if [[ "$_completed" == "0" && "$_expected" == "0" ]]; then
pass "gate-set creates three-field format"
else
fail "gate-set creates three-field format (got $_completed:$_expected)"
fi
# gate-count preserves expected field
echo "1000:0:3" > "$GATE_TMP/review-gate-test"
IFS=: read -r _ts _count _expected < "$GATE_TMP/review-gate-test"
_new_count=$(( _count + 1 ))
echo "${_ts}:${_new_count}:${_expected}" > "$GATE_TMP/review-gate-test"
IFS=: read -r _ts2 _count2 _expected2 < "$GATE_TMP/review-gate-test"
if [[ "$_count2" == "1" && "$_expected2" == "3" ]]; then
pass "gate-count preserves expected field"
else
fail "gate-count preserves expected field (got $_count2:$_expected2)"
fi
# gate-check blocks when expected=0
echo "$(date +%s):0:0" > "$GATE_TMP/review-gate-test"
IFS=: read -r _ts _count _expected < "$GATE_TMP/review-gate-test"
if [[ ${_expected:-0} -eq 0 || ${_count:-0} -lt ${_expected:-0} ]]; then
pass "gate-check blocks when expected=0"
else
fail "gate-check blocks when expected=0"
fi
# gate-check blocks when completed < expected
echo "$(date +%s):1:3" > "$GATE_TMP/review-gate-test"
IFS=: read -r _ts _count _expected < "$GATE_TMP/review-gate-test"
if [[ ${_expected:-0} -eq 0 || ${_count:-0} -lt ${_expected:-0} ]]; then
pass "gate-check blocks when completed < expected"
else
fail "gate-check blocks when completed < expected"
fi
# gate-check allows when completed >= expected
echo "$(date +%s):3:3" > "$GATE_TMP/review-gate-test"
IFS=: read -r _ts _count _expected < "$GATE_TMP/review-gate-test"
if [[ ${_expected:-0} -gt 0 && ${_count:-0} -ge ${_expected:-0} ]]; then
pass "gate-check allows when completed >= expected"
else
fail "gate-check allows when completed >= expected"
fi
# stop hook detects incomplete verification
echo "$(date +%s):1:3" > "$GATE_TMP/review-gate-test"
IFS=: read -r _ts _count _expected < "$GATE_TMP/review-gate-test"
if [[ -f "$GATE_TMP/review-gate-test" && ${_expected:-0} -gt 0 && ${_count:-0} -lt ${_expected:-0} ]]; then
pass "stop hook detects incomplete verification"
else
fail "stop hook detects incomplete verification"
fi
# stop hook allows exit when verification complete
echo "$(date +%s):3:3" > "$GATE_TMP/review-gate-test"
IFS=: read -r _ts _count _expected < "$GATE_TMP/review-gate-test"
if [[ ! -f "$GATE_TMP/review-gate-test" ]] || [[ ${_expected:-0} -eq 0 ]] || [[ ${_count:-0} -ge ${_expected:-0} ]]; then
pass "stop hook allows exit when verification complete"
else
fail "stop hook allows exit when verification complete"
fi
rm -rf "$GATE_TMP"
FIX_TEST_ROOT="$(mktemp -d)"
mkdir -p "$FIX_TEST_ROOT/.qq"
(
cd "$FIX_TEST_ROOT" &&
git init -q
)
cat > "$FIX_TEST_ROOT/qq.yaml" <<'EOF'
version: 1
engine: unity
default_profile: feature
EOF
cat > "$FIX_TEST_ROOT/.qq/local.yaml" <<'EOF'
work_mode: fix
policy_profile: feature
EOF
cat > "$FIX_TEST_ROOT/BugFix.cs" <<'EOF'
using UnityEngine;
public class BugFix : MonoBehaviour {}
EOF
RUN_JSON=$($QQ_PY "$SCRIPT_DIR/scripts/qq-run-record.py" start --project "$FIX_TEST_ROOT" --stage compile --command fix-compile --backend test --transport local --summary "fix compile start")
RUN_ID=$(printf '%s' "$RUN_JSON" | $QQ_PY -c 'import json,sys; print(json.load(sys.stdin)["run_id"])')
$QQ_PY "$SCRIPT_DIR/scripts/qq-run-record.py" finish --project "$FIX_TEST_ROOT" --run-id "$RUN_ID" --status passed --summary "fix compile passed" >/dev/null
$QQ_PY "$SCRIPT_DIR/scripts/qq-project-state.py" --project "$FIX_TEST_ROOT" >/dev/null
if $QQ_PY - "$FIX_TEST_ROOT" <<'PY'
import json
import sys
from pathlib import Path