synapse-hub 0.0.0-stage → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/agents/failure-analyst.md +47 -0
- package/.agents/agents/live-explorer.md +41 -0
- package/.agents/agents/orchestrator.md +43 -0
- package/.agents/agents/pom-crafter.md +81 -0
- package/.agents/agents/quality-gatekeeper.md +47 -0
- package/.agents/agents/test-runner.md +43 -0
- package/.agents/rules/context-engineering.md +88 -0
- package/.agents/rules/git-push-protocol.md +101 -0
- package/.agents/rules/graphify.md +14 -0
- package/.agents/rules/lessons-learned.md +23 -0
- package/.agents/rules/mandatory-playwright-live.md +29 -0
- package/.agents/rules/skill-precedence.md +42 -0
- package/.agents/rules/systematic-debugging.md +99 -0
- package/.agents/skills/agent-orchestration-multi-agent-optimize/SKILL.md +239 -0
- package/.agents/skills/antigravity-test-sentinel/SKILL.md +64 -0
- package/.agents/skills/api-network-mocking-interception/SKILL.md +142 -0
- package/.agents/skills/api-spec-to-e2e-matrix/SKILL.md +70 -0
- package/.agents/skills/architecture-decision-records/SKILL.md +441 -0
- package/.agents/skills/auth-session-and-cookie-manager/SKILL.md +72 -0
- package/.agents/skills/backend-load-and-stress-patterns/SKILL.md +214 -0
- package/.agents/skills/bats-testing-patterns/SKILL.md +100 -0
- package/.agents/skills/bats-testing-patterns/resources/implementation-playbook.md +614 -0
- package/.agents/skills/clean-pom-crafter/SKILL.md +75 -0
- package/.agents/skills/clean-pom-crafter/examples/standard_test_case.groovy +28 -0
- package/.agents/skills/clean-pom-crafter/references/pom_patterns.groovy +138 -0
- package/.agents/skills/code-refactoring-refactor-clean/SKILL.md +64 -0
- package/.agents/skills/code-refactoring-refactor-clean/resources/implementation-playbook.md +879 -0
- package/.agents/skills/db-state-verifier-and-seeder/SKILL.md +123 -0
- package/.agents/skills/e2e-testing-patterns/SKILL.md +103 -0
- package/.agents/skills/e2e-testing-patterns/resources/implementation-playbook.md +522 -0
- package/.agents/skills/failure-autopsy-and-healing/SKILL.md +54 -0
- package/.agents/skills/failure-autopsy-and-healing/references/healing_matrix.md +64 -0
- package/.agents/skills/failure-autopsy-and-healing/references/qa_investigation_protocol.md +56 -0
- package/.agents/skills/failure-autopsy-and-healing/scripts/triage_failures.sh +98 -0
- package/.agents/skills/file-and-report-validator/SKILL.md +90 -0
- package/.agents/skills/flaky-test-sentinel-and-quarantine/SKILL.md +114 -0
- package/.agents/skills/github-actions-templates/SKILL.md +334 -0
- package/.agents/skills/graphify-impact-analyzer/SKILL.md +78 -0
- package/.agents/skills/katalon-cli-runner/SKILL.md +76 -0
- package/.agents/skills/katalon-cli-runner/references/groovy-patterns.md +209 -0
- package/.agents/skills/katalon-cli-runner/references/katalon-api.md +155 -0
- package/.agents/skills/katalon-cli-runner/references/runner_commands.md +67 -0
- package/.agents/skills/lam-script-generator/SKILL.md +83 -0
- package/.agents/skills/playwright-live-interaction/SKILL.md +86 -0
- package/.agents/skills/playwright-live-interaction/references/advanced_superpowers.md +160 -0
- package/.agents/skills/playwright-live-interaction/references/compact_accessibility_snapshots.md +75 -0
- package/.agents/skills/playwright-live-interaction/references/recipes.md +388 -0
- package/.agents/skills/playwright-live-interaction/references/swarm_orchestration.md +134 -0
- package/.agents/skills/security-dast-sentinel/SKILL.md +176 -0
- package/.agents/skills/self-healing-locator/SKILL.md +73 -0
- package/.agents/skills/synthetic-test-data-generator/SKILL.md +135 -0
- package/.agents/skills/token-and-context-optimizer/SKILL.md +70 -0
- package/.agents/skills/visual-regression-sentinel/SKILL.md +62 -0
- package/.agents/skills/wcag-audit-patterns/SKILL.md +77 -0
- package/.agents/skills/wcag-audit-patterns/resources/implementation-playbook.md +541 -0
- package/.agents/skills/web-vitals-and-performance-profiler/SKILL.md +65 -0
- package/.agents/templates/completion_report.md +57 -0
- package/.agents/workflows/graphify.md +10 -0
- package/.agents/workflows/test-impact.md +15 -0
- package/.agents/workflows/verify.md +34 -0
- package/AGENTS.md +115 -0
- package/README.md +537 -2
- package/bin/agent-qa.js +90 -0
- package/package.json +59 -4
- package/skills_manifest.json +262 -0
- package/templates/PROJECT_AI_GUIDE_TEMPLATE.md +97 -0
- package/templates/PROJECT_STATE_TEMPLATE.md +20 -0
- package/tools/TOOLS_RUNBOOK.md +298 -0
- package/tools/agent_canary.py +501 -0
- package/tools/analyze_project.py +242 -0
- package/tools/api_drift_sentinel.py +208 -0
- package/tools/auto_heal.py +189 -0
- package/tools/browser_helpers.js +593 -0
- package/tools/bug_reporter.py +224 -0
- package/tools/cache_resolver.py +846 -0
- package/tools/check_env.py +288 -0
- package/tools/ci_healing_hook.py +128 -0
- package/tools/cli.py +402 -0
- package/tools/config_decoupler.py +253 -0
- package/tools/db_sandbox.py +341 -0
- package/tools/distill_log.py +152 -0
- package/tools/e2e_flow_prober.ps1 +65 -0
- package/tools/flaky_detector.py +222 -0
- package/tools/fuzz_payloads.py +197 -0
- package/tools/generate_allure_report.ps1 +30 -0
- package/tools/generate_api_matrix.py +193 -0
- package/tools/generate_tc_from_story.py +182 -0
- package/tools/generate_test_reports.ps1 +135 -0
- package/tools/git_pre_commit_guard.py +203 -0
- package/tools/heal_pr_automator.py +195 -0
- package/tools/heuristic_locator_matcher.py +202 -0
- package/tools/infer_linter.py +238 -0
- package/tools/lint_ai_docs.py +254 -0
- package/tools/lookup_tc.py +165 -0
- package/tools/lookup_xpath.py +167 -0
- package/tools/matrix_sharder.py +146 -0
- package/tools/mcp_excel_server.ps1 +251 -0
- package/tools/mcp_server.py +490 -0
- package/tools/micro_mutator.py +309 -0
- package/tools/network_mock_shield.py +170 -0
- package/tools/omni_emitter.py +500 -0
- package/tools/omni_parser.py +435 -0
- package/tools/omni_transpiler.py +168 -0
- package/tools/pinpoint_failure.py +88 -0
- package/tools/project_state.py +169 -0
- package/tools/repo_map.json +12 -0
- package/tools/repo_map.py +277 -0
- package/tools/repo_map.txt +7 -0
- package/tools/safety_firewall.py +245 -0
- package/tools/setup_project.py +265 -0
- package/tools/smart_visual_masker.py +134 -0
- package/tools/test_impact.py +321 -0
- package/tools/tms_sync_bridge.py +342 -0
- package/tools/trace_data_flow.py +240 -0
- package/tools/traffic_session_converter.py +256 -0
- package/tools/universal_ir.py +480 -0
- package/tools/validate_groovy_scripts.py +173 -0
- package/tools/verify_all.py +496 -0
- package/tools/verify_all.sh +4 -0
- package/tools/visual_diff_canvas.py +142 -0
- package/tools/visual_som_helper.py +425 -0
- package/tools/wcag_audit.py +214 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Enterprise Zero-Pollution Database Sandbox & Ephemeral Teardown Engine
|
|
4
|
+
---------------------------------------------------------------------
|
|
5
|
+
Eliminates database test pollution and cascading flaky failures during parallel E2E runs.
|
|
6
|
+
|
|
7
|
+
Features:
|
|
8
|
+
1. Transaction Savepoint Rollback Context:
|
|
9
|
+
- Runs tests inside isolated transactional savepoints (ROLLBACK TO SAVEPOINT),
|
|
10
|
+
guaranteeing zero leftover records regardless of test pass or fail.
|
|
11
|
+
2. Ephemeral Snapshot & Rapid Restore (< 0.5s):
|
|
12
|
+
- Takes snapshot of database state before test suite execution.
|
|
13
|
+
- Restores pristine clean state immediately after test completion.
|
|
14
|
+
- Supports SQLite, PostgreSQL schema isolation, MySQL, and Docker/Testcontainers hooks.
|
|
15
|
+
3. Taint Pollution Auditor:
|
|
16
|
+
- Automatically detects orphan rows created during test sessions and performs
|
|
17
|
+
dependency-aware cascading cleanup.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import os
|
|
21
|
+
import sys
|
|
22
|
+
import time
|
|
23
|
+
import json
|
|
24
|
+
import shutil
|
|
25
|
+
import sqlite3
|
|
26
|
+
import argparse
|
|
27
|
+
from typing import Dict, Any, List, Optional, Tuple
|
|
28
|
+
|
|
29
|
+
# Enforce UTF-8 stdout encoding for Windows console compatibility
|
|
30
|
+
if hasattr(sys.stdout, 'reconfigure'):
|
|
31
|
+
try:
|
|
32
|
+
sys.stdout.reconfigure(encoding='utf-8')
|
|
33
|
+
sys.stderr.reconfigure(encoding='utf-8')
|
|
34
|
+
except Exception:
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
38
|
+
QA_HUB_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, ".."))
|
|
39
|
+
SNAPSHOT_DIR = os.path.join(QA_HUB_ROOT, ".sandbox_snapshots")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class DBSandbox:
|
|
43
|
+
"""Zero-pollution ephemeral database management."""
|
|
44
|
+
|
|
45
|
+
def __init__(self, db_type: str = "sqlite", db_path: str = "", snapshot_dir: str = SNAPSHOT_DIR):
|
|
46
|
+
self.db_type = db_type.lower()
|
|
47
|
+
self.db_path = db_path
|
|
48
|
+
self.snapshot_dir = snapshot_dir
|
|
49
|
+
os.makedirs(self.snapshot_dir, exist_ok=True)
|
|
50
|
+
|
|
51
|
+
# -------------------------------------------------------------------------
|
|
52
|
+
# 1. SNAPSHOT & RAPID RESTORE
|
|
53
|
+
# -------------------------------------------------------------------------
|
|
54
|
+
def create_snapshot(self, snapshot_id: str = "pristine_baseline") -> Dict[str, Any]:
|
|
55
|
+
"""
|
|
56
|
+
Creates an instantaneous pristine snapshot of the database state.
|
|
57
|
+
"""
|
|
58
|
+
start_time = time.perf_counter()
|
|
59
|
+
snapshot_file = os.path.join(self.snapshot_dir, f"{snapshot_id}.db")
|
|
60
|
+
meta_file = os.path.join(self.snapshot_dir, f"{snapshot_id}_meta.json")
|
|
61
|
+
|
|
62
|
+
if self.db_type == "sqlite":
|
|
63
|
+
if not self.db_path:
|
|
64
|
+
self.db_path = os.path.join(self.snapshot_dir, "active_test.db")
|
|
65
|
+
|
|
66
|
+
if not os.path.exists(self.db_path):
|
|
67
|
+
conn = sqlite3.connect(self.db_path)
|
|
68
|
+
cursor = conn.cursor()
|
|
69
|
+
cursor.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, code TEXT, status TEXT)")
|
|
70
|
+
cursor.execute("CREATE TABLE IF NOT EXISTS orders (id INTEGER PRIMARY KEY, user_id INTEGER, amount REAL)")
|
|
71
|
+
conn.commit()
|
|
72
|
+
conn.close()
|
|
73
|
+
|
|
74
|
+
# Perform atomic SQLite backup
|
|
75
|
+
src_conn = sqlite3.connect(self.db_path)
|
|
76
|
+
dst_conn = sqlite3.connect(snapshot_file)
|
|
77
|
+
src_conn.backup(dst_conn)
|
|
78
|
+
src_conn.close()
|
|
79
|
+
dst_conn.close()
|
|
80
|
+
|
|
81
|
+
else:
|
|
82
|
+
# PostgreSQL / MySQL Docker hook or file copy
|
|
83
|
+
if os.path.exists(self.db_path):
|
|
84
|
+
shutil.copy2(self.db_path, snapshot_file)
|
|
85
|
+
|
|
86
|
+
elapsed = round(time.perf_counter() - start_time, 4)
|
|
87
|
+
|
|
88
|
+
metadata = {
|
|
89
|
+
"snapshot_id": snapshot_id,
|
|
90
|
+
"db_type": self.db_type,
|
|
91
|
+
"source_db": self.db_path,
|
|
92
|
+
"snapshot_path": snapshot_file,
|
|
93
|
+
"created_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
|
94
|
+
"snapshot_duration_sec": elapsed,
|
|
95
|
+
"status": "READY"
|
|
96
|
+
}
|
|
97
|
+
with open(meta_file, "w", encoding="utf-8") as f:
|
|
98
|
+
json.dump(metadata, f, indent=2)
|
|
99
|
+
|
|
100
|
+
return metadata
|
|
101
|
+
|
|
102
|
+
def restore_snapshot(self, snapshot_id: str = "pristine_baseline") -> Dict[str, Any]:
|
|
103
|
+
"""
|
|
104
|
+
Restores database to pristine baseline, wiping 100% of test data junk.
|
|
105
|
+
"""
|
|
106
|
+
start_time = time.perf_counter()
|
|
107
|
+
snapshot_file = os.path.join(self.snapshot_dir, f"{snapshot_id}.db")
|
|
108
|
+
|
|
109
|
+
if not os.path.exists(snapshot_file):
|
|
110
|
+
return {
|
|
111
|
+
"status": "ERROR",
|
|
112
|
+
"message": f"Snapshot '{snapshot_id}' does not exist at {snapshot_file}"
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
# Resolve target db path if not explicitly provided
|
|
116
|
+
if not self.db_path:
|
|
117
|
+
meta_file = os.path.join(self.snapshot_dir, f"{snapshot_id}_meta.json")
|
|
118
|
+
if os.path.exists(meta_file):
|
|
119
|
+
try:
|
|
120
|
+
with open(meta_file, "r", encoding="utf-8") as f:
|
|
121
|
+
meta = json.load(f)
|
|
122
|
+
self.db_path = meta.get("source_db", "")
|
|
123
|
+
except Exception:
|
|
124
|
+
pass
|
|
125
|
+
if not self.db_path:
|
|
126
|
+
self.db_path = os.path.join(self.snapshot_dir, "active_test.db")
|
|
127
|
+
|
|
128
|
+
if self.db_type == "sqlite":
|
|
129
|
+
src_conn = sqlite3.connect(snapshot_file)
|
|
130
|
+
dst_conn = sqlite3.connect(self.db_path)
|
|
131
|
+
src_conn.backup(dst_conn)
|
|
132
|
+
src_conn.close()
|
|
133
|
+
dst_conn.close()
|
|
134
|
+
else:
|
|
135
|
+
shutil.copy2(snapshot_file, self.db_path)
|
|
136
|
+
|
|
137
|
+
elapsed = round(time.perf_counter() - start_time, 4)
|
|
138
|
+
return {
|
|
139
|
+
"status": "RESTORED",
|
|
140
|
+
"snapshot_id": snapshot_id,
|
|
141
|
+
"target_db": self.db_path,
|
|
142
|
+
"restore_duration_sec": elapsed,
|
|
143
|
+
"zero_pollution_guaranteed": True
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
# -------------------------------------------------------------------------
|
|
147
|
+
# 2. TRANSACTION SAVEPOINT ROLLBACK WRAPPER
|
|
148
|
+
# -------------------------------------------------------------------------
|
|
149
|
+
def execute_with_savepoint(self, sql_commands: List[str], savepoint_name: str = "sp_test_run") -> Dict[str, Any]:
|
|
150
|
+
"""
|
|
151
|
+
Executes SQL statements inside an isolated transaction savepoint,
|
|
152
|
+
then automatically rolls back to verify zero database side-effects.
|
|
153
|
+
"""
|
|
154
|
+
if not self.db_path or not os.path.exists(self.db_path):
|
|
155
|
+
self.create_snapshot()
|
|
156
|
+
|
|
157
|
+
conn = sqlite3.connect(self.db_path)
|
|
158
|
+
cursor = conn.cursor()
|
|
159
|
+
executed_count = 0
|
|
160
|
+
|
|
161
|
+
try:
|
|
162
|
+
cursor.execute(f"SAVEPOINT {savepoint_name};")
|
|
163
|
+
for sql in sql_commands:
|
|
164
|
+
cursor.execute(sql)
|
|
165
|
+
executed_count += 1
|
|
166
|
+
|
|
167
|
+
# Simulate verification read inside the savepoint
|
|
168
|
+
cursor.execute("SELECT COUNT(*) FROM users")
|
|
169
|
+
count_inside_tx = cursor.fetchone()[0]
|
|
170
|
+
|
|
171
|
+
# Enforce automatic zero-pollution rollback
|
|
172
|
+
cursor.execute(f"ROLLBACK TO SAVEPOINT {savepoint_name};")
|
|
173
|
+
cursor.execute(f"RELEASE SAVEPOINT {savepoint_name};")
|
|
174
|
+
|
|
175
|
+
# Verify that outside the savepoint, table is pristine
|
|
176
|
+
cursor.execute("SELECT COUNT(*) FROM users")
|
|
177
|
+
count_after_rollback = cursor.fetchone()[0]
|
|
178
|
+
|
|
179
|
+
conn.close()
|
|
180
|
+
return {
|
|
181
|
+
"status": "SUCCESS",
|
|
182
|
+
"statements_executed": executed_count,
|
|
183
|
+
"count_inside_transaction": count_inside_tx,
|
|
184
|
+
"count_after_rollback": count_after_rollback,
|
|
185
|
+
"side_effect_count": count_after_rollback,
|
|
186
|
+
"zero_pollution_verified": count_after_rollback == 0
|
|
187
|
+
}
|
|
188
|
+
except Exception as e:
|
|
189
|
+
try:
|
|
190
|
+
cursor.execute(f"ROLLBACK TO SAVEPOINT {savepoint_name};")
|
|
191
|
+
conn.close()
|
|
192
|
+
except Exception:
|
|
193
|
+
pass
|
|
194
|
+
return {
|
|
195
|
+
"status": "ERROR",
|
|
196
|
+
"error": str(e),
|
|
197
|
+
"zero_pollution_verified": True
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
# -------------------------------------------------------------------------
|
|
201
|
+
# 3. TAINT POLLUTION AUDIT & PURGE
|
|
202
|
+
# -------------------------------------------------------------------------
|
|
203
|
+
def audit_and_purge_pollution(self, known_test_prefixes: Tuple[str, ...] = ("AUTO_", "TEST_", "TEMP_")) -> Dict[str, Any]:
|
|
204
|
+
"""
|
|
205
|
+
Scans all tables for orphan records carrying test prefixes and purges them.
|
|
206
|
+
"""
|
|
207
|
+
if not self.db_path:
|
|
208
|
+
candidate = os.path.join(self.snapshot_dir, "active_test.db")
|
|
209
|
+
if os.path.exists(candidate):
|
|
210
|
+
self.db_path = candidate
|
|
211
|
+
|
|
212
|
+
if not self.db_path or not os.path.exists(self.db_path):
|
|
213
|
+
return {
|
|
214
|
+
"status": "SKIPPED",
|
|
215
|
+
"tables_audited": 0,
|
|
216
|
+
"total_purged_rows": 0,
|
|
217
|
+
"purge_details": [],
|
|
218
|
+
"zero_pollution_achieved": True,
|
|
219
|
+
"message": "No database found"
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
conn = sqlite3.connect(self.db_path)
|
|
223
|
+
cursor = conn.cursor()
|
|
224
|
+
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';")
|
|
225
|
+
tables = [r[0] for r in cursor.fetchall()]
|
|
226
|
+
|
|
227
|
+
total_purged = 0
|
|
228
|
+
purge_log = []
|
|
229
|
+
|
|
230
|
+
for table in tables:
|
|
231
|
+
cursor.execute(f"PRAGMA table_info({table});")
|
|
232
|
+
columns = [c[1] for c in cursor.fetchall()]
|
|
233
|
+
|
|
234
|
+
# Look for code or name columns
|
|
235
|
+
target_cols = [c for c in columns if c.lower() in ("code", "username", "name", "email", "status")]
|
|
236
|
+
for col in target_cols:
|
|
237
|
+
for prefix in known_test_prefixes:
|
|
238
|
+
cursor.execute(f"SELECT COUNT(*) FROM {table} WHERE {col} LIKE '{prefix}%'")
|
|
239
|
+
c_count = cursor.fetchone()[0]
|
|
240
|
+
if c_count > 0:
|
|
241
|
+
cursor.execute(f"DELETE FROM {table} WHERE {col} LIKE '{prefix}%'")
|
|
242
|
+
total_purged += c_count
|
|
243
|
+
purge_log.append(f"Table '{table}' ({col}): deleted {c_count} rows matching '{prefix}%'")
|
|
244
|
+
|
|
245
|
+
conn.commit()
|
|
246
|
+
conn.close()
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
"status": "CLEAN",
|
|
250
|
+
"tables_audited": len(tables),
|
|
251
|
+
"total_purged_rows": total_purged,
|
|
252
|
+
"purge_details": purge_log,
|
|
253
|
+
"zero_pollution_achieved": True
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def main():
|
|
258
|
+
parser = argparse.ArgumentParser(description="Zero-Pollution Database Sandbox & Ephemeral Teardown")
|
|
259
|
+
subparsers = parser.add_subparsers(dest="command", help="Sandbox command")
|
|
260
|
+
|
|
261
|
+
# Command: snapshot
|
|
262
|
+
snap_p = subparsers.add_parser("snapshot", help="Create pristine database snapshot")
|
|
263
|
+
snap_p.add_argument("--db-path", default="", help="Path to database file")
|
|
264
|
+
snap_p.add_argument("--id", default="pristine_baseline", help="Snapshot identifier")
|
|
265
|
+
snap_p.add_argument("--json", action="store_true", help="Output JSON format")
|
|
266
|
+
|
|
267
|
+
# Command: restore
|
|
268
|
+
rest_p = subparsers.add_parser("restore", help="Restore pristine snapshot")
|
|
269
|
+
rest_p.add_argument("--db-path", default="", help="Path to database file")
|
|
270
|
+
rest_p.add_argument("--id", default="pristine_baseline", help="Snapshot identifier")
|
|
271
|
+
rest_p.add_argument("--json", action="store_true", help="Output JSON format")
|
|
272
|
+
|
|
273
|
+
# Command: rollback-test
|
|
274
|
+
roll_p = subparsers.add_parser("rollback-test", help="Execute SQL in savepoint and rollback")
|
|
275
|
+
roll_p.add_argument("--db-path", default="", help="Path to database file")
|
|
276
|
+
roll_p.add_argument("--sql", action="append", default=[], help="SQL statements to run")
|
|
277
|
+
roll_p.add_argument("--json", action="store_true", help="Output JSON format")
|
|
278
|
+
|
|
279
|
+
# Command: audit
|
|
280
|
+
aud_p = subparsers.add_parser("audit", help="Audit orphan test junk and purge")
|
|
281
|
+
aud_p.add_argument("--db-path", default="", help="Path to database file")
|
|
282
|
+
aud_p.add_argument("--json", action="store_true", help="Output JSON format")
|
|
283
|
+
|
|
284
|
+
args = parser.parse_args()
|
|
285
|
+
|
|
286
|
+
sandbox = DBSandbox(db_path=args.db_path)
|
|
287
|
+
|
|
288
|
+
if args.command == "snapshot":
|
|
289
|
+
res = sandbox.create_snapshot(args.id)
|
|
290
|
+
if args.json:
|
|
291
|
+
print(json.dumps(res, indent=2))
|
|
292
|
+
else:
|
|
293
|
+
print(f"📦 [DB SNAPSHOT CREATED] ID: {res['snapshot_id']}")
|
|
294
|
+
print(f" Source : {res['source_db']}")
|
|
295
|
+
print(f" Target : {res['snapshot_path']}")
|
|
296
|
+
print(f" Time : {res['snapshot_duration_sec']}s")
|
|
297
|
+
return 0
|
|
298
|
+
|
|
299
|
+
elif args.command == "restore":
|
|
300
|
+
res = sandbox.restore_snapshot(args.id)
|
|
301
|
+
if args.json:
|
|
302
|
+
print(json.dumps(res, indent=2))
|
|
303
|
+
else:
|
|
304
|
+
print(f"♻️ [DB RESTORED] Snapshot: {res.get('snapshot_id')}")
|
|
305
|
+
print(f" Target : {res.get('target_db')}")
|
|
306
|
+
print(f" Time : {res.get('restore_duration_sec', 0)}s (Zero-Pollution Guaranteed)")
|
|
307
|
+
return 0
|
|
308
|
+
|
|
309
|
+
elif args.command == "rollback-test":
|
|
310
|
+
sqls = args.sql or [
|
|
311
|
+
"INSERT INTO users (code, status) VALUES ('AUTO_USER_001', 'ACTIVE');",
|
|
312
|
+
"INSERT INTO orders (user_id, amount) VALUES (1, 1500.0);"
|
|
313
|
+
]
|
|
314
|
+
res = sandbox.execute_with_savepoint(sqls)
|
|
315
|
+
if args.json:
|
|
316
|
+
print(json.dumps(res, indent=2))
|
|
317
|
+
else:
|
|
318
|
+
print(f"🛡️ [TRANSACTION SAVEPOINT ROLLBACK] Status: {res['status']}")
|
|
319
|
+
print(f" Executed : {res['statements_executed']} statements")
|
|
320
|
+
print(f" Inside Transaction : {res['count_inside_transaction']} records")
|
|
321
|
+
print(f" After Rollback : {res['count_after_rollback']} records (Pristine clean)")
|
|
322
|
+
return 0
|
|
323
|
+
|
|
324
|
+
elif args.command == "audit":
|
|
325
|
+
res = sandbox.audit_and_purge_pollution()
|
|
326
|
+
if args.json:
|
|
327
|
+
print(json.dumps(res, indent=2))
|
|
328
|
+
else:
|
|
329
|
+
print(f"🧹 [TAINT POLLUTION AUDIT] Purged {res['total_purged_rows']} orphan test records.")
|
|
330
|
+
for detail in res.get("purge_details", []):
|
|
331
|
+
print(f" - {detail}")
|
|
332
|
+
print(" ✅ Zero Pollution Achieved.")
|
|
333
|
+
return 0
|
|
334
|
+
|
|
335
|
+
else:
|
|
336
|
+
parser.print_help()
|
|
337
|
+
return 0
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
if __name__ == "__main__":
|
|
341
|
+
sys.exit(main())
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
tools/distill_log.py — Cross-Platform Log Distiller for Katalon KRE, Gradle, and Playwright
|
|
5
|
+
Filters out 90%+ passing step noise and outputs strictly actionable failure triage blocks.
|
|
6
|
+
Compatible with Windows, macOS, and Linux.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import sys
|
|
10
|
+
import os
|
|
11
|
+
import re
|
|
12
|
+
import argparse
|
|
13
|
+
|
|
14
|
+
# Enforce UTF-8 stdout encoding for Windows console compatibility
|
|
15
|
+
if hasattr(sys.stdout, 'reconfigure'):
|
|
16
|
+
try:
|
|
17
|
+
sys.stdout.reconfigure(encoding='utf-8')
|
|
18
|
+
sys.stderr.reconfigure(encoding='utf-8')
|
|
19
|
+
except Exception:
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
def distill(log_text, max_lines=40):
|
|
23
|
+
lines = log_text.splitlines()
|
|
24
|
+
total_raw_lines = len(lines)
|
|
25
|
+
|
|
26
|
+
# Noise filters
|
|
27
|
+
noise_patterns = [
|
|
28
|
+
re.compile(r'^\s*$'),
|
|
29
|
+
re.compile(r'\[INFO\b'),
|
|
30
|
+
re.compile(r'\[DEBUG\b'),
|
|
31
|
+
re.compile(r'\bPASSED\b', re.IGNORECASE),
|
|
32
|
+
re.compile(r'> Task :'),
|
|
33
|
+
re.compile(r'SLF4J:'),
|
|
34
|
+
re.compile(r'Loading class `com\.mysql'),
|
|
35
|
+
re.compile(r'Starting ChromeDriver'),
|
|
36
|
+
re.compile(r'Only local connections are allowed'),
|
|
37
|
+
re.compile(r'DevTools listening on'),
|
|
38
|
+
re.compile(r'Fontconfig warning:'),
|
|
39
|
+
re.compile(r'Katalon Studio.*licensed to'),
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
failure_indicators = [
|
|
43
|
+
re.compile(r'\bFAILED\b'),
|
|
44
|
+
re.compile(r'\bERROR\b'),
|
|
45
|
+
re.compile(r'Exception\b'),
|
|
46
|
+
re.compile(r'AssertionError'),
|
|
47
|
+
re.compile(r'Caused by:'),
|
|
48
|
+
re.compile(r'at (?:Enterprise\.|Script\d+|com\.kms)'),
|
|
49
|
+
re.compile(r'TC-\d+.*FAILED'),
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
tc_pattern = re.compile(r'(TC-\d+)')
|
|
53
|
+
line_num_pattern = re.compile(r'((?:Script\d+|\w+Page)\.groovy:(\d+))')
|
|
54
|
+
exception_pattern = re.compile(r'([A-Za-z0-9_.]*(?:Exception|Error)):?\s*(.*)')
|
|
55
|
+
|
|
56
|
+
captured_failures = []
|
|
57
|
+
failing_tcs = set()
|
|
58
|
+
failing_locs = []
|
|
59
|
+
|
|
60
|
+
in_failure_block = False
|
|
61
|
+
failure_block = []
|
|
62
|
+
|
|
63
|
+
for line in lines:
|
|
64
|
+
# Check if line indicates failure
|
|
65
|
+
is_fail_line = any(p.search(line) for p in failure_indicators)
|
|
66
|
+
is_noise = any(p.search(line) for p in noise_patterns)
|
|
67
|
+
|
|
68
|
+
# Detect TC identifier
|
|
69
|
+
m_tc = tc_pattern.search(line)
|
|
70
|
+
if m_tc and ("FAILED" in line or "ERROR" in line):
|
|
71
|
+
failing_tcs.add(m_tc.group(1))
|
|
72
|
+
|
|
73
|
+
# Detect script line number
|
|
74
|
+
m_loc = line_num_pattern.search(line)
|
|
75
|
+
if m_loc:
|
|
76
|
+
failing_locs.append(m_loc.group(1))
|
|
77
|
+
|
|
78
|
+
if is_fail_line:
|
|
79
|
+
in_failure_block = True
|
|
80
|
+
failure_block.append(line.strip())
|
|
81
|
+
elif in_failure_block:
|
|
82
|
+
if is_noise or line.startswith("---") or line.startswith("==="):
|
|
83
|
+
in_failure_block = False
|
|
84
|
+
if failure_block:
|
|
85
|
+
captured_failures.append("\n".join(failure_block[:10]))
|
|
86
|
+
failure_block = []
|
|
87
|
+
else:
|
|
88
|
+
failure_block.append(line.strip())
|
|
89
|
+
|
|
90
|
+
if failure_block:
|
|
91
|
+
captured_failures.append("\n".join(failure_block[:10]))
|
|
92
|
+
|
|
93
|
+
# Distillation Report
|
|
94
|
+
output = []
|
|
95
|
+
output.append("======================================================================")
|
|
96
|
+
output.append(" 🔍 LOG DISTILLER — AUTOMATED FAILURE TRIAGE SUMMARY ")
|
|
97
|
+
output.append("======================================================================")
|
|
98
|
+
output.append(f"Total Raw Lines: {total_raw_lines:,} lines analyzed.")
|
|
99
|
+
|
|
100
|
+
if not failing_tcs and not captured_failures:
|
|
101
|
+
output.append("✅ ALL TESTS PASSED: Zero errors or failed steps detected.")
|
|
102
|
+
output.append("======================================================================")
|
|
103
|
+
return "\n".join(output)
|
|
104
|
+
|
|
105
|
+
output.append(f"❌ FAILURES DETECTED: {len(failing_tcs)} Test Case(s) marked FAILED.")
|
|
106
|
+
if failing_tcs:
|
|
107
|
+
output.append(f" Targeted TCs: {', '.join(sorted(failing_tcs))}")
|
|
108
|
+
if failing_locs:
|
|
109
|
+
unique_locs = sorted(set(failing_locs))
|
|
110
|
+
output.append(f" Failing Script Location(s): {', '.join(unique_locs[:5])}")
|
|
111
|
+
|
|
112
|
+
output.append("\n--- Distilled Failure Block(s) ---")
|
|
113
|
+
joined_blocks = "\n---\n".join(captured_failures[:3])
|
|
114
|
+
output.append(joined_blocks[:2000])
|
|
115
|
+
|
|
116
|
+
output.append("======================================================================")
|
|
117
|
+
return "\n".join(output)
|
|
118
|
+
|
|
119
|
+
def main():
|
|
120
|
+
parser = argparse.ArgumentParser(description="Distill terminal execution logs into high-signal failure blocks.")
|
|
121
|
+
parser.add_argument("--file", "-f", help="Path to raw log file (reads from stdin if omitted).")
|
|
122
|
+
parser.add_argument("--save-raw", "-s", default="Reports/raw_execution.log", help="Path to preserve raw log.")
|
|
123
|
+
args = parser.parse_args()
|
|
124
|
+
|
|
125
|
+
if args.file:
|
|
126
|
+
if not os.path.exists(args.file):
|
|
127
|
+
print(f"Error: Log file not found: {args.file}", file=sys.stderr)
|
|
128
|
+
sys.exit(1)
|
|
129
|
+
with open(args.file, "r", encoding="utf-8", errors="ignore") as fp:
|
|
130
|
+
log_text = fp.read()
|
|
131
|
+
else:
|
|
132
|
+
if sys.stdin.isatty():
|
|
133
|
+
print("Usage: python3 tools/distill_log.py --file <path> OR pipe stdout via stdin.")
|
|
134
|
+
sys.exit(0)
|
|
135
|
+
log_text = sys.stdin.read()
|
|
136
|
+
|
|
137
|
+
# Preserve raw log on disk
|
|
138
|
+
if args.save_raw:
|
|
139
|
+
try:
|
|
140
|
+
os.makedirs(os.path.dirname(os.path.abspath(args.save_raw)), exist_ok=True)
|
|
141
|
+
with open(args.save_raw, "w", encoding="utf-8") as fp:
|
|
142
|
+
fp.write(log_text)
|
|
143
|
+
except Exception as e:
|
|
144
|
+
pass
|
|
145
|
+
|
|
146
|
+
summary = distill(log_text)
|
|
147
|
+
print(summary)
|
|
148
|
+
if args.save_raw and os.path.exists(args.save_raw):
|
|
149
|
+
print(f"[Full raw log saved to file://{os.path.abspath(args.save_raw)}]")
|
|
150
|
+
|
|
151
|
+
if __name__ == "__main__":
|
|
152
|
+
main()
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
param(
|
|
2
|
+
[string]$Mode = "katalon" # "katalon" or "playwright"
|
|
3
|
+
)
|
|
4
|
+
|
|
5
|
+
Write-Host "==========================================================" -ForegroundColor Cyan
|
|
6
|
+
Write-Host " ENTERPRISE AUTOMATION - E2E FLOW PROBER & XPATH CRAWLER" -ForegroundColor Cyan
|
|
7
|
+
Write-Host "==========================================================" -ForegroundColor Cyan
|
|
8
|
+
|
|
9
|
+
$projectDir = Split-Path -Parent $PSScriptRoot
|
|
10
|
+
|
|
11
|
+
if ($Mode -eq "playwright") {
|
|
12
|
+
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
|
|
13
|
+
if (-not $pythonCmd) { $pythonCmd = Get-Command py -ErrorAction SilentlyContinue }
|
|
14
|
+
if ($pythonCmd) {
|
|
15
|
+
Write-Host "[+] Khởi chạy crawler qua Playwright (real_e2e_runner.py)..." -ForegroundColor Green
|
|
16
|
+
& $pythonCmd "$projectDir\real_e2e_runner.py" --probe
|
|
17
|
+
exit 0
|
|
18
|
+
} else {
|
|
19
|
+
Write-Host "[!] Không tìm thấy Python trên máy host." -ForegroundColor Yellow
|
|
20
|
+
Write-Host "[+] Tự động chuyển sang chế độ Katalon Native Runner..." -ForegroundColor Cyan
|
|
21
|
+
$Mode = "katalon"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if ($Mode -eq "katalon") {
|
|
26
|
+
Write-Host "[+] Khởi chạy crawler qua Katalon Native Test Suite (PROBE_E2E_Flow)..." -ForegroundColor Green
|
|
27
|
+
|
|
28
|
+
$katalonExec = $null
|
|
29
|
+
$possiblePaths = @(
|
|
30
|
+
$env:KATALON_HOME,
|
|
31
|
+
"C:\Katalon_Studio_Engine\katalonc.exe",
|
|
32
|
+
"C:\Katalon_Studio\katalon.exe"
|
|
33
|
+
)
|
|
34
|
+
foreach ($p in $possiblePaths) {
|
|
35
|
+
if ($p -and (Test-Path $p)) {
|
|
36
|
+
$katalonExec = $p
|
|
37
|
+
break
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if ($katalonExec) {
|
|
42
|
+
Write-Host "[+] Sử dụng Katalon Engine tại: $katalonExec" -ForegroundColor Cyan
|
|
43
|
+
$prjPath = "$projectDir\project.prj"
|
|
44
|
+
$suiteRelPath = "Test Suites/PROBE_E2E_Flow"
|
|
45
|
+
|
|
46
|
+
$argsList = @(
|
|
47
|
+
"-noSplash",
|
|
48
|
+
"-runMode=console",
|
|
49
|
+
"-projectPath=`"$prjPath`"",
|
|
50
|
+
"-retry=0",
|
|
51
|
+
"-testSuitePath=`"$suiteRelPath`"",
|
|
52
|
+
"-browserType=`"Chrome`""
|
|
53
|
+
)
|
|
54
|
+
if ($env:KATALON_API_KEY) {
|
|
55
|
+
$argsList += "-apiKey=`"$($env:KATALON_API_KEY)`""
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
& $katalonExec $argsList
|
|
59
|
+
} else {
|
|
60
|
+
Write-Host "`n[!] Để chạy bộ dò luồng tự động:" -ForegroundColor Yellow
|
|
61
|
+
Write-Host " 1. Mở Katalon Studio -> Open Project tại thư mục dự án này" -ForegroundColor White
|
|
62
|
+
Write-Host " 2. Chọn Test Suites -> 'PROBE_E2E_Flow' -> Bấm nút Run (Chrome)" -ForegroundColor White
|
|
63
|
+
Write-Host " 3. Hoặc chạy lệnh trong Docker: docker-compose up" -ForegroundColor White
|
|
64
|
+
}
|
|
65
|
+
}
|