tzero-mcp 11.12.1 → 11.15.2
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/LICENSE +661 -21
- package/NOTICE +22 -0
- package/README.md +3 -3
- package/bin/postinstall.js +22 -0
- package/bin/tzero-mcp.js +2 -1
- package/bin/tzero.js +8 -1
- package/index.js +5 -0
- package/package.json +4 -2
- package/src/addmcp.py +3 -3
- package/src/app.py +1 -1
- package/src/tzero/__init__.py +5 -0
- package/src/tzero/addmcp.py +18 -0
- package/src/tzero/tzero_benchmark.py +2 -2
- package/src/tzero/tzero_blackboard.py +1 -1
- package/src/tzero/tzero_budget.py +1 -1
- package/src/tzero/tzero_card.py +1 -1
- package/src/tzero/tzero_ci.py +658 -10
- package/src/tzero/tzero_commit.py +1 -1
- package/src/tzero/tzero_contracts.py +2 -2
- package/src/tzero/tzero_cost.py +1 -1
- package/src/tzero/tzero_dashboard.py +3 -3
- package/src/tzero/tzero_debt.py +1 -1
- package/src/tzero/tzero_drift.py +1 -1
- package/src/tzero/tzero_explain.py +1 -1
- package/src/tzero/tzero_features.py +268 -37
- package/src/tzero/tzero_golden.py +2 -2
- package/src/tzero/tzero_hallucination_proof.py +901 -0
- package/src/tzero/tzero_infra.py +1 -1
- package/src/tzero/tzero_jarvis/__init__.py +15 -1
- package/src/tzero/tzero_jarvis/agent_guard.py +620 -0
- package/src/tzero/tzero_jarvis/creative_director.py +1 -1
- package/src/tzero/tzero_jarvis/orchestrator.py +36 -34
- package/src/tzero/tzero_jarvis/self_healing.py +325 -250
- package/src/tzero/tzero_lsp.py +1 -1
- package/src/tzero/tzero_mcp.py +184 -53
- package/src/tzero/tzero_promo.py +504 -0
- package/src/tzero/tzero_replay.py +1 -1
- package/src/tzero/tzero_semantic_merge.py +1 -1
- package/src/tzero/tzero_stubs.py +1 -1
- package/src/tzero/tzero_task_benchmark.py +2 -2
- package/src/tzero/tzero_tui.py +2 -2
- package/src/tzero/tzero_turbo.py +1 -1
- package/src/tzero/tzero_v3.py +124 -13
- package/src/tzero/tzero_welcome.py +135 -0
- package/test/package.test.js +1 -1
package/src/tzero/tzero_ci.py
CHANGED
|
@@ -1,26 +1,51 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
|
|
2
|
+
"""Siber Akademi — T-Zero Local CI Suite & Pre-Push Verification Engine.
|
|
3
|
+
|
|
4
4
|
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
5
|
+
Repository: https://github.com/toprakahmetaydogmus/TZeroAlgorithm
|
|
5
6
|
License: MIT
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
Features:
|
|
9
|
+
1. Local CI Verification Pipeline:
|
|
10
|
+
- Stage 1: Release Metadata & Manifests Sync Gate
|
|
11
|
+
- Stage 2: 100% Zero-Leak Security & Personal Data Guard
|
|
12
|
+
- Stage 3: AST Syntax Integrity & Architectural Boundaries Guard
|
|
13
|
+
- Stage 4: Static Code Quality & Linter Gate
|
|
14
|
+
- Stage 5: Comprehensive Automated Unit & Regression Tests
|
|
15
|
+
- Stage 6: Cross-Ecosystem Smoke Gate (Node.js & VS Code Extensions)
|
|
16
|
+
- Stage 7: M8ven MCP Compliance Gate
|
|
17
|
+
2. Automated Git Pre-Push Hook:
|
|
18
|
+
- Automatically intercepts `git push` on developer's machine
|
|
19
|
+
- Runs local verification in seconds; blocks push if any check fails
|
|
20
|
+
- Eliminates remote GitHub Actions failures and saves 100% of runner quota
|
|
21
|
+
3. Turnkey CI Template Generator (GitHub Actions, GitLab CI, Pre-commit)
|
|
11
22
|
"""
|
|
12
23
|
|
|
13
24
|
import sys
|
|
14
25
|
if sys.platform == "win32":
|
|
15
26
|
try:
|
|
16
|
-
sys.stdout.reconfigure
|
|
17
|
-
|
|
27
|
+
if sys.stdout and hasattr(sys.stdout, "reconfigure"):
|
|
28
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
29
|
+
if sys.stderr and hasattr(sys.stderr, "reconfigure"):
|
|
30
|
+
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
|
|
18
31
|
except Exception:
|
|
19
32
|
pass
|
|
20
33
|
|
|
21
34
|
import os
|
|
22
|
-
|
|
35
|
+
import re
|
|
36
|
+
import ast
|
|
37
|
+
import time
|
|
38
|
+
import json
|
|
39
|
+
import shutil
|
|
40
|
+
import argparse
|
|
41
|
+
import subprocess
|
|
42
|
+
from typing import Tuple, Dict, Any, List, Optional
|
|
43
|
+
from dataclasses import dataclass, field, asdict
|
|
44
|
+
|
|
23
45
|
|
|
46
|
+
# ============================================================================
|
|
47
|
+
# 1. CI / CD TEMPLATE GENERATOR (BACKWARDS COMPATIBILITY)
|
|
48
|
+
# ============================================================================
|
|
24
49
|
|
|
25
50
|
GITHUB_WORKFLOW_TEMPLATE = """name: T-Zero Autonomous Quality & Zero-Leak Gate
|
|
26
51
|
|
|
@@ -38,7 +63,7 @@ jobs:
|
|
|
38
63
|
fail-fast: false
|
|
39
64
|
matrix:
|
|
40
65
|
os: [ubuntu-24.04, windows-latest]
|
|
41
|
-
python-version: ["3.
|
|
66
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
42
67
|
|
|
43
68
|
steps:
|
|
44
69
|
- name: Checkout Codebase
|
|
@@ -120,6 +145,13 @@ PRE_COMMIT_CONFIG_TEMPLATE = """repos:
|
|
|
120
145
|
language: system
|
|
121
146
|
pass_filenames: false
|
|
122
147
|
always_run: true
|
|
148
|
+
|
|
149
|
+
- id: tzero-local-ci
|
|
150
|
+
name: T-Zero Local Pre-Push CI Suite
|
|
151
|
+
entry: tzero local-ci --quick
|
|
152
|
+
language: system
|
|
153
|
+
pass_filenames: false
|
|
154
|
+
always_run: true
|
|
123
155
|
"""
|
|
124
156
|
|
|
125
157
|
|
|
@@ -151,3 +183,619 @@ class CIPipelineGenerator:
|
|
|
151
183
|
with open(pc_path, "w", encoding="utf-8") as f:
|
|
152
184
|
f.write(PRE_COMMIT_CONFIG_TEMPLATE.strip() + "\n")
|
|
153
185
|
return True, pc_path
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# ============================================================================
|
|
189
|
+
# 2. LOCAL CI VERIFICATION RUNNER & ENGINE
|
|
190
|
+
# ============================================================================
|
|
191
|
+
|
|
192
|
+
SECRET_PATTERNS = [
|
|
193
|
+
(r"sk-[a-zA-Z0-9]{20,}", "OpenAI Secret Key"),
|
|
194
|
+
(r"nvapi-[a-zA-Z0-9_-]{20,}", "NVIDIA API Key"),
|
|
195
|
+
(r"ghp_[a-zA-Z0-9]{20,}", "GitHub Personal Access Token"),
|
|
196
|
+
(r"AIza[0-9A-Za-z-_]{35}", "Google API / Cloud Token"),
|
|
197
|
+
(r"xox[baprs]-[0-9a-zA-Z]{10,48}", "Slack API Token"),
|
|
198
|
+
(r"(?i)api[_-]?key\s*[:=]\s*['\"][a-zA-Z0-9_-]{16,}['\"]", "Generic API Key Assignment"),
|
|
199
|
+
(r"(?i)password\s*[:=]\s*['\"][a-zA-Z0-9_-]{8,}['\"]", "Plaintext Password Assignment"),
|
|
200
|
+
(r"\b[1-9][0-9]{10}\b", "Potential Turkish ID Number (TCKN)"),
|
|
201
|
+
]
|
|
202
|
+
|
|
203
|
+
SECRET_FALSE_POSITIVES = [
|
|
204
|
+
"YOUR_KEY_HERE",
|
|
205
|
+
"ENTER_YOUR_KEY",
|
|
206
|
+
"password_example",
|
|
207
|
+
"test_password",
|
|
208
|
+
"invalid passphrase or corrupted backup",
|
|
209
|
+
"sha256",
|
|
210
|
+
"tzero_seed_",
|
|
211
|
+
"mock",
|
|
212
|
+
"placeholder",
|
|
213
|
+
"example",
|
|
214
|
+
"00000000000",
|
|
215
|
+
"12345678901",
|
|
216
|
+
"11111111111",
|
|
217
|
+
"132999209",
|
|
218
|
+
"437749791",
|
|
219
|
+
]
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@dataclass
|
|
223
|
+
class LocalCIStepResult:
|
|
224
|
+
name: str
|
|
225
|
+
description: str
|
|
226
|
+
passed: bool
|
|
227
|
+
duration: float
|
|
228
|
+
output: str = ""
|
|
229
|
+
error: str = ""
|
|
230
|
+
auto_fixed: bool = False
|
|
231
|
+
warning: bool = False
|
|
232
|
+
|
|
233
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
234
|
+
return asdict(self)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
@dataclass
|
|
238
|
+
class LocalCIReport:
|
|
239
|
+
workspace: str
|
|
240
|
+
passed: bool
|
|
241
|
+
total_steps: int
|
|
242
|
+
passed_steps: int
|
|
243
|
+
failed_steps: int
|
|
244
|
+
total_duration: float
|
|
245
|
+
estimated_actions_minutes_saved: float
|
|
246
|
+
steps: List[LocalCIStepResult] = field(default_factory=list)
|
|
247
|
+
|
|
248
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
249
|
+
return {
|
|
250
|
+
"workspace": self.workspace,
|
|
251
|
+
"passed": self.passed,
|
|
252
|
+
"total_steps": self.total_steps,
|
|
253
|
+
"passed_steps": self.passed_steps,
|
|
254
|
+
"failed_steps": self.failed_steps,
|
|
255
|
+
"total_duration": round(self.total_duration, 3),
|
|
256
|
+
"estimated_actions_minutes_saved": round(self.estimated_actions_minutes_saved, 1),
|
|
257
|
+
"steps": [s.to_dict() for s in self.steps],
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def get_python_executable() -> str:
|
|
262
|
+
"""Returns the real python executable, even when running inside a frozen PyInstaller binary."""
|
|
263
|
+
if getattr(sys, "frozen", False):
|
|
264
|
+
for candidate in (shutil.which("python"), shutil.which("python3"), shutil.which("py")):
|
|
265
|
+
if candidate:
|
|
266
|
+
return candidate
|
|
267
|
+
return "python"
|
|
268
|
+
return sys.executable
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
class LocalCIRunner:
|
|
272
|
+
"""Enterprise Local CI Pipeline Runner & Pre-Push Shield.
|
|
273
|
+
|
|
274
|
+
Executes complete verification batteries locally on the developer machine:
|
|
275
|
+
- 0 runner minutes consumed
|
|
276
|
+
- 0 remote CI failures & spam emails
|
|
277
|
+
- 100% offline-ready & private
|
|
278
|
+
"""
|
|
279
|
+
|
|
280
|
+
def __init__(self, repo_dir: str = ".", quick: bool = False, auto_fix: bool = False):
|
|
281
|
+
self.repo_dir = os.path.abspath(repo_dir)
|
|
282
|
+
self.quick = quick
|
|
283
|
+
self.auto_fix = auto_fix
|
|
284
|
+
|
|
285
|
+
# ------------------------------------------------------------------------
|
|
286
|
+
# STAGE 1: Metadata & Manifests Sync Gate
|
|
287
|
+
# ------------------------------------------------------------------------
|
|
288
|
+
def check_metadata_sync(self) -> LocalCIStepResult:
|
|
289
|
+
t0 = time.time()
|
|
290
|
+
sync_script = os.path.join(self.repo_dir, "scripts", "sync_release_metadata.py")
|
|
291
|
+
if not os.path.exists(sync_script):
|
|
292
|
+
return LocalCIStepResult(
|
|
293
|
+
name="Metadata & Version Sync",
|
|
294
|
+
description="Checks single-source-of-truth version and badge consistency",
|
|
295
|
+
passed=True,
|
|
296
|
+
duration=time.time() - t0,
|
|
297
|
+
output="No sync_release_metadata.py present; skipped."
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
py_bin = get_python_executable()
|
|
301
|
+
cmd = [py_bin, sync_script, "--check"]
|
|
302
|
+
proc = subprocess.run(cmd, cwd=self.repo_dir, capture_output=True, text=True)
|
|
303
|
+
if proc.returncode == 0:
|
|
304
|
+
return LocalCIStepResult(
|
|
305
|
+
name="Metadata & Version Sync",
|
|
306
|
+
description="Checks single-source-of-truth version and badge consistency",
|
|
307
|
+
passed=True,
|
|
308
|
+
duration=time.time() - t0,
|
|
309
|
+
output=proc.stdout.strip()
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
# Check if auto-fix is requested
|
|
313
|
+
if self.auto_fix:
|
|
314
|
+
fix_proc = subprocess.run([py_bin, sync_script], cwd=self.repo_dir, capture_output=True, text=True)
|
|
315
|
+
if fix_proc.returncode == 0:
|
|
316
|
+
recheck = subprocess.run(cmd, cwd=self.repo_dir, capture_output=True, text=True)
|
|
317
|
+
if recheck.returncode == 0:
|
|
318
|
+
return LocalCIStepResult(
|
|
319
|
+
name="Metadata & Version Sync",
|
|
320
|
+
description="Checks single-source-of-truth version and badge consistency",
|
|
321
|
+
passed=True,
|
|
322
|
+
duration=time.time() - t0,
|
|
323
|
+
output="Automatically synchronized release metadata.",
|
|
324
|
+
auto_fixed=True
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
return LocalCIStepResult(
|
|
328
|
+
name="Metadata & Version Sync",
|
|
329
|
+
description="Checks single-source-of-truth version and badge consistency",
|
|
330
|
+
passed=False,
|
|
331
|
+
duration=time.time() - t0,
|
|
332
|
+
error=proc.stderr.strip() or proc.stdout.strip() or "Version mismatch detected."
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
# ------------------------------------------------------------------------
|
|
336
|
+
# STAGE 2: 100% Zero-Leak Security & Personal Data Guard
|
|
337
|
+
# ------------------------------------------------------------------------
|
|
338
|
+
def check_zero_leak_security(self) -> LocalCIStepResult:
|
|
339
|
+
t0 = time.time()
|
|
340
|
+
ignored_dirs = {
|
|
341
|
+
".git", "__pycache__", ".pytest_cache", "target", "dist",
|
|
342
|
+
"build", ".venv", "venv", ".egg-info", "node_modules", "tests"
|
|
343
|
+
}
|
|
344
|
+
allowed_extensions = (
|
|
345
|
+
".py", ".rs", ".json", ".toml", ".bat", ".md", ".txt", ".html", ".js", ".css", ".sh"
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
findings = []
|
|
349
|
+
for root, dirs, files in os.walk(self.repo_dir):
|
|
350
|
+
dirs[:] = [d for d in dirs if d not in ignored_dirs and not any(ign in d for ign in ignored_dirs)]
|
|
351
|
+
if any(ign in root for ign in ignored_dirs):
|
|
352
|
+
continue
|
|
353
|
+
for f in files:
|
|
354
|
+
if f.endswith(allowed_extensions):
|
|
355
|
+
fpath = os.path.join(root, f)
|
|
356
|
+
try:
|
|
357
|
+
with open(fpath, "r", encoding="utf-8", errors="ignore") as fp:
|
|
358
|
+
content = fp.read()
|
|
359
|
+
for pat, label in SECRET_PATTERNS:
|
|
360
|
+
matches = re.findall(pat, content)
|
|
361
|
+
filtered = [
|
|
362
|
+
m for m in matches
|
|
363
|
+
if not any(fp_str in str(m) for fp_str in SECRET_FALSE_POSITIVES)
|
|
364
|
+
]
|
|
365
|
+
if filtered:
|
|
366
|
+
rel_path = os.path.relpath(fpath, self.repo_dir)
|
|
367
|
+
findings.append((rel_path, label, len(filtered)))
|
|
368
|
+
except Exception:
|
|
369
|
+
pass
|
|
370
|
+
|
|
371
|
+
if findings:
|
|
372
|
+
err_msg = "\n".join([f" - {f}: {label} ({cnt} match)" for f, label, cnt in findings[:10]])
|
|
373
|
+
return LocalCIStepResult(
|
|
374
|
+
name="100% Zero-Leak Security Audit",
|
|
375
|
+
description="Scans workspace for hardcoded secrets, API tokens and personal data",
|
|
376
|
+
passed=False,
|
|
377
|
+
duration=time.time() - t0,
|
|
378
|
+
error=f"Detected potential secret leaks:\n{err_msg}"
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
return LocalCIStepResult(
|
|
382
|
+
name="100% Zero-Leak Security Audit",
|
|
383
|
+
description="Scans workspace for hardcoded secrets, API tokens and personal data",
|
|
384
|
+
passed=True,
|
|
385
|
+
duration=time.time() - t0,
|
|
386
|
+
output="Clean! Zero hardcoded secrets or personal data found."
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
# ------------------------------------------------------------------------
|
|
390
|
+
# STAGE 3: AST Syntax Integrity & Architectural Boundaries Guard
|
|
391
|
+
# ------------------------------------------------------------------------
|
|
392
|
+
def check_ast_and_boundaries(self) -> LocalCIStepResult:
|
|
393
|
+
t0 = time.time()
|
|
394
|
+
syntax_errors = []
|
|
395
|
+
total_py_files = 0
|
|
396
|
+
ignored_dirs = {".git", "__pycache__", ".venv", "venv", "dist", "build", "node_modules"}
|
|
397
|
+
|
|
398
|
+
for root, dirs, files in os.walk(self.repo_dir):
|
|
399
|
+
dirs[:] = [d for d in dirs if d not in ignored_dirs]
|
|
400
|
+
for f in files:
|
|
401
|
+
if f.endswith(".py"):
|
|
402
|
+
total_py_files += 1
|
|
403
|
+
fpath = os.path.join(root, f)
|
|
404
|
+
try:
|
|
405
|
+
with open(fpath, "r", encoding="utf-8", errors="ignore") as fp:
|
|
406
|
+
ast.parse(fp.read(), filename=fpath)
|
|
407
|
+
except SyntaxError as e:
|
|
408
|
+
rel = os.path.relpath(fpath, self.repo_dir)
|
|
409
|
+
syntax_errors.append(f"{rel}:{e.lineno}: {e.msg}")
|
|
410
|
+
|
|
411
|
+
if syntax_errors:
|
|
412
|
+
return LocalCIStepResult(
|
|
413
|
+
name="AST & Architecture Boundaries",
|
|
414
|
+
description="Verifies syntax compilation and architectural layers",
|
|
415
|
+
passed=False,
|
|
416
|
+
duration=time.time() - t0,
|
|
417
|
+
error=f"AST Syntax Errors in {len(syntax_errors)} files:\n" + "\n".join(syntax_errors[:5])
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
# Check boundaries rule file if present
|
|
421
|
+
rules_file = os.path.join(self.repo_dir, "tzero.rules.json")
|
|
422
|
+
rules_info = "Rules: Active (tzero.rules.json)" if os.path.exists(rules_file) else "Rules: Default"
|
|
423
|
+
return LocalCIStepResult(
|
|
424
|
+
name="AST & Architecture Boundaries",
|
|
425
|
+
description="Verifies syntax compilation and architectural layers",
|
|
426
|
+
passed=True,
|
|
427
|
+
duration=time.time() - t0,
|
|
428
|
+
output=f"Parsed {total_py_files} Python AST modules with 0 syntax faults. {rules_info}."
|
|
429
|
+
)
|
|
430
|
+
|
|
431
|
+
# ------------------------------------------------------------------------
|
|
432
|
+
# STAGE 4: Static Code Quality & Linter Gate
|
|
433
|
+
# ------------------------------------------------------------------------
|
|
434
|
+
def check_code_quality_lint(self) -> LocalCIStepResult:
|
|
435
|
+
t0 = time.time()
|
|
436
|
+
# Try running flake8 if installed
|
|
437
|
+
flake8_bin = shutil.which("flake8")
|
|
438
|
+
if flake8_bin:
|
|
439
|
+
cmd = [flake8_bin, ".", "--count", "--select=E9,F63,F7,F82", "--show-source", "--statistics"]
|
|
440
|
+
proc = subprocess.run(cmd, cwd=self.repo_dir, capture_output=True, text=True)
|
|
441
|
+
if proc.returncode == 0:
|
|
442
|
+
return LocalCIStepResult(
|
|
443
|
+
name="Static Code Quality & Lint",
|
|
444
|
+
description="Scans for Python syntax, undefined symbols, and code smells",
|
|
445
|
+
passed=True,
|
|
446
|
+
duration=time.time() - t0,
|
|
447
|
+
output="flake8 critical lint checks passed cleanly."
|
|
448
|
+
)
|
|
449
|
+
else:
|
|
450
|
+
return LocalCIStepResult(
|
|
451
|
+
name="Static Code Quality & Lint",
|
|
452
|
+
description="Scans for Python syntax, undefined symbols, and code smells",
|
|
453
|
+
passed=False,
|
|
454
|
+
duration=time.time() - t0,
|
|
455
|
+
error=proc.stdout.strip() or proc.stderr.strip()
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
# Fallback: AST based validator (already covered in stage 3)
|
|
459
|
+
return LocalCIStepResult(
|
|
460
|
+
name="Static Code Quality & Lint",
|
|
461
|
+
description="Scans for Python syntax, undefined symbols, and code smells",
|
|
462
|
+
passed=True,
|
|
463
|
+
duration=time.time() - t0,
|
|
464
|
+
output="flake8 not in PATH; AST static code analyzer verified OK."
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
# ------------------------------------------------------------------------
|
|
468
|
+
# STAGE 5: Comprehensive Automated Unit & Regression Tests
|
|
469
|
+
# ------------------------------------------------------------------------
|
|
470
|
+
def check_unit_tests(self) -> LocalCIStepResult:
|
|
471
|
+
t0 = time.time()
|
|
472
|
+
tests_dir = os.path.join(self.repo_dir, "tests")
|
|
473
|
+
if not os.path.isdir(tests_dir):
|
|
474
|
+
return LocalCIStepResult(
|
|
475
|
+
name="Automated Unit Test Suite",
|
|
476
|
+
description="Runs local unit and integration tests",
|
|
477
|
+
passed=True,
|
|
478
|
+
duration=time.time() - t0,
|
|
479
|
+
output="No tests directory found."
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
py_bin = get_python_executable()
|
|
483
|
+
if self.quick:
|
|
484
|
+
# In quick mode, run key verification gates
|
|
485
|
+
target_modules = [
|
|
486
|
+
"tests.test_ci_workflow",
|
|
487
|
+
"tests.test_m8ven_compliance",
|
|
488
|
+
"tests.test_commit_and_ci"
|
|
489
|
+
]
|
|
490
|
+
cmd = [py_bin, "-m", "unittest"] + target_modules
|
|
491
|
+
else:
|
|
492
|
+
cmd = [py_bin, "-m", "unittest", "discover", "-s", "tests", "-p", "test_*.py"]
|
|
493
|
+
|
|
494
|
+
proc = subprocess.run(cmd, cwd=self.repo_dir, capture_output=True, text=True)
|
|
495
|
+
dur = time.time() - t0
|
|
496
|
+
if proc.returncode == 0:
|
|
497
|
+
lines = proc.stderr.splitlines()
|
|
498
|
+
ran_line = [l for l in lines if "Ran" in l and "tests" in l]
|
|
499
|
+
summary = ran_line[-1] if ran_line else "All unit tests passed successfully."
|
|
500
|
+
mode_label = "Quick mode" if self.quick else "Full matrix mode"
|
|
501
|
+
return LocalCIStepResult(
|
|
502
|
+
name="Automated Unit Test Suite",
|
|
503
|
+
description="Runs local unit and integration tests",
|
|
504
|
+
passed=True,
|
|
505
|
+
duration=dur,
|
|
506
|
+
output=f"{mode_label}: {summary}"
|
|
507
|
+
)
|
|
508
|
+
else:
|
|
509
|
+
return LocalCIStepResult(
|
|
510
|
+
name="Automated Unit Test Suite",
|
|
511
|
+
description="Runs local unit and integration tests",
|
|
512
|
+
passed=False,
|
|
513
|
+
duration=dur,
|
|
514
|
+
error=proc.stderr.strip() or proc.stdout.strip()
|
|
515
|
+
)
|
|
516
|
+
|
|
517
|
+
# ------------------------------------------------------------------------
|
|
518
|
+
# STAGE 6: Cross-Ecosystem Smoke Gate (Node.js & Extensions)
|
|
519
|
+
# ------------------------------------------------------------------------
|
|
520
|
+
def check_node_ecosystem(self) -> LocalCIStepResult:
|
|
521
|
+
t0 = time.time()
|
|
522
|
+
node_bin = shutil.which("node")
|
|
523
|
+
npm_test = os.path.join(self.repo_dir, "installers", "npm", "test", "package.test.js")
|
|
524
|
+
vscode_test = os.path.join(self.repo_dir, "extensions", "vscode", "test", "extension.test.js")
|
|
525
|
+
|
|
526
|
+
if not os.path.exists(npm_test) and not os.path.exists(vscode_test):
|
|
527
|
+
return LocalCIStepResult(
|
|
528
|
+
name="Ecosystem & Extension Tests",
|
|
529
|
+
description="Runs npm installer and VS Code extension test runners",
|
|
530
|
+
passed=True,
|
|
531
|
+
duration=time.time() - t0,
|
|
532
|
+
output="No npm/extension test suites in workspace."
|
|
533
|
+
)
|
|
534
|
+
|
|
535
|
+
if not node_bin:
|
|
536
|
+
return LocalCIStepResult(
|
|
537
|
+
name="Ecosystem & Extension Tests",
|
|
538
|
+
description="Runs npm installer and VS Code extension test runners",
|
|
539
|
+
passed=True,
|
|
540
|
+
duration=time.time() - t0,
|
|
541
|
+
output="Node.js not installed locally; cross-ecosystem gate skipped.",
|
|
542
|
+
warning=True
|
|
543
|
+
)
|
|
544
|
+
|
|
545
|
+
outputs = []
|
|
546
|
+
if os.path.exists(npm_test):
|
|
547
|
+
p1 = subprocess.run([node_bin, "--test", "installers/npm/test/package.test.js"], cwd=self.repo_dir, capture_output=True, text=True)
|
|
548
|
+
if p1.returncode != 0:
|
|
549
|
+
return LocalCIStepResult(
|
|
550
|
+
name="Ecosystem & Extension Tests",
|
|
551
|
+
description="Runs npm installer and VS Code extension test runners",
|
|
552
|
+
passed=False,
|
|
553
|
+
duration=time.time() - t0,
|
|
554
|
+
error=f"npm test failed:\n{p1.stderr or p1.stdout}"
|
|
555
|
+
)
|
|
556
|
+
outputs.append("npm: OK")
|
|
557
|
+
|
|
558
|
+
if os.path.exists(vscode_test):
|
|
559
|
+
p2 = subprocess.run([node_bin, "--test", "extensions/vscode/test/extension.test.js"], cwd=self.repo_dir, capture_output=True, text=True)
|
|
560
|
+
if p2.returncode != 0:
|
|
561
|
+
return LocalCIStepResult(
|
|
562
|
+
name="Ecosystem & Extension Tests",
|
|
563
|
+
description="Runs npm installer and VS Code extension test runners",
|
|
564
|
+
passed=False,
|
|
565
|
+
duration=time.time() - t0,
|
|
566
|
+
error=f"VS Code extension test failed:\n{p2.stderr or p2.stdout}"
|
|
567
|
+
)
|
|
568
|
+
outputs.append("vscode: OK")
|
|
569
|
+
|
|
570
|
+
return LocalCIStepResult(
|
|
571
|
+
name="Ecosystem & Extension Tests",
|
|
572
|
+
description="Runs npm installer and VS Code extension test runners",
|
|
573
|
+
passed=True,
|
|
574
|
+
duration=time.time() - t0,
|
|
575
|
+
output=f"Cross-ecosystem tests passed ({', '.join(outputs)})."
|
|
576
|
+
)
|
|
577
|
+
|
|
578
|
+
# ------------------------------------------------------------------------
|
|
579
|
+
# STAGE 7: M8ven MCP Compliance Gate
|
|
580
|
+
# ------------------------------------------------------------------------
|
|
581
|
+
def check_m8ven_compliance(self) -> LocalCIStepResult:
|
|
582
|
+
t0 = time.time()
|
|
583
|
+
readme_path = os.path.join(self.repo_dir, "README.md")
|
|
584
|
+
if not os.path.exists(readme_path):
|
|
585
|
+
return LocalCIStepResult(
|
|
586
|
+
name="M8ven MCP Compliance",
|
|
587
|
+
description="Validates M8ven verified publisher badge & MCP server status",
|
|
588
|
+
passed=True,
|
|
589
|
+
duration=time.time() - t0,
|
|
590
|
+
output="README.md not found; skipped."
|
|
591
|
+
)
|
|
592
|
+
|
|
593
|
+
with open(readme_path, "r", encoding="utf-8", errors="ignore") as fp:
|
|
594
|
+
readme = fp.read()
|
|
595
|
+
|
|
596
|
+
has_badge = "https://m8ven.ai/badge/mcp/toprakahmetaydogmus/tzeroalgorithm" in readme
|
|
597
|
+
if not has_badge:
|
|
598
|
+
return LocalCIStepResult(
|
|
599
|
+
name="M8ven MCP Compliance",
|
|
600
|
+
description="Validates M8ven verified publisher badge & MCP server status",
|
|
601
|
+
passed=False,
|
|
602
|
+
duration=time.time() - t0,
|
|
603
|
+
error="M8ven verified publisher badge is missing from README.md."
|
|
604
|
+
)
|
|
605
|
+
|
|
606
|
+
return LocalCIStepResult(
|
|
607
|
+
name="M8ven MCP Compliance",
|
|
608
|
+
description="Validates M8ven verified publisher badge & MCP server status",
|
|
609
|
+
passed=True,
|
|
610
|
+
duration=time.time() - t0,
|
|
611
|
+
output="M8ven Verified Publisher badge active and verified in README.md."
|
|
612
|
+
)
|
|
613
|
+
|
|
614
|
+
# ------------------------------------------------------------------------
|
|
615
|
+
# MASTER RUNNER
|
|
616
|
+
# ------------------------------------------------------------------------
|
|
617
|
+
def run(self) -> LocalCIReport:
|
|
618
|
+
t_start = time.time()
|
|
619
|
+
steps = [
|
|
620
|
+
self.check_metadata_sync(),
|
|
621
|
+
self.check_zero_leak_security(),
|
|
622
|
+
self.check_ast_and_boundaries(),
|
|
623
|
+
self.check_code_quality_lint(),
|
|
624
|
+
self.check_unit_tests(),
|
|
625
|
+
self.check_node_ecosystem(),
|
|
626
|
+
self.check_m8ven_compliance(),
|
|
627
|
+
]
|
|
628
|
+
t_total = time.time() - t_start
|
|
629
|
+
passed_steps = sum(1 for s in steps if s.passed)
|
|
630
|
+
failed_steps = len(steps) - passed_steps
|
|
631
|
+
all_passed = (failed_steps == 0)
|
|
632
|
+
|
|
633
|
+
# Average remote CI run takes ~3-6 minutes per OS across 3 matrix environments = ~15-20 minutes
|
|
634
|
+
estimated_minutes_saved = 15.0 if all_passed else 0.0
|
|
635
|
+
|
|
636
|
+
return LocalCIReport(
|
|
637
|
+
workspace=self.repo_dir,
|
|
638
|
+
passed=all_passed,
|
|
639
|
+
total_steps=len(steps),
|
|
640
|
+
passed_steps=passed_steps,
|
|
641
|
+
failed_steps=failed_steps,
|
|
642
|
+
total_duration=t_total,
|
|
643
|
+
estimated_actions_minutes_saved=estimated_minutes_saved,
|
|
644
|
+
steps=steps,
|
|
645
|
+
)
|
|
646
|
+
|
|
647
|
+
# ------------------------------------------------------------------------
|
|
648
|
+
# GIT HOOK MANAGEMENT (AUTOMATIC PRE-PUSH INTERCEPTION)
|
|
649
|
+
# ------------------------------------------------------------------------
|
|
650
|
+
@classmethod
|
|
651
|
+
def install_git_pre_push_hook(cls, repo_dir: str = ".") -> Tuple[bool, str]:
|
|
652
|
+
"""Installs pre-push hook into .git/hooks/pre-push to automatically run Local CI."""
|
|
653
|
+
hooks_dir = os.path.join(repo_dir, ".git", "hooks")
|
|
654
|
+
if not os.path.isdir(hooks_dir):
|
|
655
|
+
return False, f"Not a git repository: {hooks_dir} not found."
|
|
656
|
+
|
|
657
|
+
hook_path = os.path.join(hooks_dir, "pre-push")
|
|
658
|
+
hook_content = """#!/bin/sh
|
|
659
|
+
# Siber Akademi T-Zero Autonomous Local CI Pre-Push Gate
|
|
660
|
+
# Developer: Toprak Ahmet Aydoğmuş
|
|
661
|
+
echo "⚡ [T-Zero Pre-Push Shield] Executing local CI verification..."
|
|
662
|
+
|
|
663
|
+
if command -v tzero >/dev/null 2>&1; then
|
|
664
|
+
tzero local-ci --quick
|
|
665
|
+
elif [ -f "tzero/tzero_ci.py" ] || [ -f "tzero_v3.py" ]; then
|
|
666
|
+
python -m tzero.tzero_ci --quick
|
|
667
|
+
else
|
|
668
|
+
python -m unittest discover tests -v
|
|
669
|
+
fi
|
|
670
|
+
|
|
671
|
+
EXIT_CODE=$?
|
|
672
|
+
if [ $EXIT_CODE -ne 0 ]; then
|
|
673
|
+
echo ""
|
|
674
|
+
echo "❌ [T-Zero Pre-Push Shield] Local CI failed! Push ABORTED."
|
|
675
|
+
echo "👉 Remote GitHub Actions quota protected (0 minutes burned)."
|
|
676
|
+
echo "👉 Fix errors locally or run 'tzero local-ci --fix' to auto-heal."
|
|
677
|
+
echo "👉 (Emergency override: git push --no-verify)"
|
|
678
|
+
exit 1
|
|
679
|
+
fi
|
|
680
|
+
|
|
681
|
+
echo "✔ [T-Zero Pre-Push Shield] All local gates passed! Proceeding with push."
|
|
682
|
+
exit 0
|
|
683
|
+
"""
|
|
684
|
+
with open(hook_path, "w", encoding="utf-8", newline="\n") as f:
|
|
685
|
+
f.write(hook_content)
|
|
686
|
+
|
|
687
|
+
# Try to make executable on POSIX systems
|
|
688
|
+
try:
|
|
689
|
+
os.chmod(hook_path, 0o755)
|
|
690
|
+
except Exception:
|
|
691
|
+
pass
|
|
692
|
+
|
|
693
|
+
return True, hook_path
|
|
694
|
+
|
|
695
|
+
@classmethod
|
|
696
|
+
def uninstall_git_pre_push_hook(cls, repo_dir: str = ".") -> Tuple[bool, str]:
|
|
697
|
+
"""Removes .git/hooks/pre-push."""
|
|
698
|
+
hook_path = os.path.join(repo_dir, ".git", "hooks", "pre-push")
|
|
699
|
+
if os.path.exists(hook_path):
|
|
700
|
+
try:
|
|
701
|
+
os.remove(hook_path)
|
|
702
|
+
return True, "Pre-push hook removed successfully."
|
|
703
|
+
except Exception as e:
|
|
704
|
+
return False, f"Failed to remove pre-push hook: {e}"
|
|
705
|
+
return True, "Pre-push hook was not installed."
|
|
706
|
+
|
|
707
|
+
# ------------------------------------------------------------------------
|
|
708
|
+
# BEAUTIFUL TERMINAL UI RENDERER
|
|
709
|
+
# ------------------------------------------------------------------------
|
|
710
|
+
@classmethod
|
|
711
|
+
def render_terminal_report(cls, report: LocalCIReport) -> str:
|
|
712
|
+
lines = []
|
|
713
|
+
lines.append("\033[36m┌────────────────────────────────────────────────────────────────────────┐\033[0m")
|
|
714
|
+
lines.append("\033[36m│\033[0m \033[1;37m⚡ T-ZERO LOCAL CI & PRE-PUSH VERIFICATION RUNNER\033[0m \033[36m│\033[0m")
|
|
715
|
+
lines.append("\033[36m│\033[0m \033[32mZero Quota Burn\033[0m • \033[33m100% Offline\033[0m • \033[35mZero-Leak Guaranteed\033[0m \033[36m│\033[0m")
|
|
716
|
+
lines.append("\033[36m└────────────────────────────────────────────────────────────────────────┘\033[0m")
|
|
717
|
+
lines.append("")
|
|
718
|
+
|
|
719
|
+
for i, s in enumerate(report.steps, 1):
|
|
720
|
+
if s.passed:
|
|
721
|
+
status = "\033[32m[PASS]\033[0m"
|
|
722
|
+
else:
|
|
723
|
+
status = "\033[31m[FAIL]\033[0m"
|
|
724
|
+
|
|
725
|
+
name_col = f"[{i}/{report.total_steps}] {s.name}"
|
|
726
|
+
dots = "." * max(2, 45 - len(name_col))
|
|
727
|
+
dur_str = f"({s.duration:.2f}s)"
|
|
728
|
+
lines.append(f" {name_col} {dots} {status} \033[90m{dur_str}\033[0m")
|
|
729
|
+
|
|
730
|
+
if s.output and not s.passed:
|
|
731
|
+
lines.append(f" \033[90m{s.output}\033[0m")
|
|
732
|
+
if s.error:
|
|
733
|
+
for eline in s.error.splitlines()[:5]:
|
|
734
|
+
lines.append(f" \033[31m↳ {eline}\033[0m")
|
|
735
|
+
|
|
736
|
+
lines.append("")
|
|
737
|
+
lines.append("\033[36m════════════════════════════════════════════════════════════════════════\033[0m")
|
|
738
|
+
if report.passed:
|
|
739
|
+
lines.append("\033[32m✔ ALL LOCAL CI GATES PASSED! Safe to push to remote.\033[0m")
|
|
740
|
+
lines.append(f" \033[33m⚡ Remote CI minutes saved: ~{report.estimated_actions_minutes_saved:.1f} minutes\033[0m (Execution took {report.total_duration:.2f}s)")
|
|
741
|
+
else:
|
|
742
|
+
lines.append(f"\033[31m❌ {report.failed_steps} OF {report.total_steps} LOCAL CI GATES FAILED.\033[0m")
|
|
743
|
+
lines.append(" \033[33mPush blocked locally to protect GitHub Actions quota and avoid failed builds.\033[0m")
|
|
744
|
+
lines.append(" Run with \033[1;37m--fix\033[0m to attempt auto-repair, or inspect the errors above.")
|
|
745
|
+
lines.append("\033[36m════════════════════════════════════════════════════════════════════════\033[0m")
|
|
746
|
+
return "\n".join(lines)
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
# ============================================================================
|
|
750
|
+
# 3. CLI ENTRYPOINT
|
|
751
|
+
# ============================================================================
|
|
752
|
+
|
|
753
|
+
def main():
|
|
754
|
+
parser = argparse.ArgumentParser(
|
|
755
|
+
prog="tzero-ci",
|
|
756
|
+
description="Siber Akademi T-Zero Local CI Pipeline & Pre-Push Verification Shield"
|
|
757
|
+
)
|
|
758
|
+
parser.add_argument("--quick", "-q", action="store_true", help="Run fast verification battery (seconds)")
|
|
759
|
+
parser.add_argument("--all", "-a", action="store_true", help="Run full matrix verification battery")
|
|
760
|
+
parser.add_argument("--fix", action="store_true", help="Attempt auto-repair for auto-fixable gates (metadata sync)")
|
|
761
|
+
parser.add_argument("--install-hook", action="store_true", help="Install automated Git pre-push hook into .git/hooks/pre-push")
|
|
762
|
+
parser.add_argument("--uninstall-hook", action="store_true", help="Uninstall automated Git pre-push hook")
|
|
763
|
+
parser.add_argument("--json", action="store_true", help="Output machine-readable JSON report")
|
|
764
|
+
parser.add_argument("--dir", default=".", help="Target repository directory (default: .)")
|
|
765
|
+
|
|
766
|
+
args = parser.parse_args()
|
|
767
|
+
|
|
768
|
+
# Hook installation fast path
|
|
769
|
+
if args.install_hook:
|
|
770
|
+
ok, msg = LocalCIRunner.install_git_pre_push_hook(args.dir)
|
|
771
|
+
if ok:
|
|
772
|
+
print(f"\033[32m[SUCCESS] Installed T-Zero Pre-Push Gate:\033[0m {msg}")
|
|
773
|
+
print("💡 'git push' will now run local CI automatically and protect your GitHub Actions quota!")
|
|
774
|
+
sys.exit(0)
|
|
775
|
+
else:
|
|
776
|
+
print(f"\033[31m[FAILED]\033[0m {msg}")
|
|
777
|
+
sys.exit(1)
|
|
778
|
+
|
|
779
|
+
if args.uninstall_hook:
|
|
780
|
+
ok, msg = LocalCIRunner.uninstall_git_pre_push_hook(args.dir)
|
|
781
|
+
if ok:
|
|
782
|
+
print(f"\033[32m[SUCCESS]\033[0m {msg}")
|
|
783
|
+
sys.exit(0)
|
|
784
|
+
else:
|
|
785
|
+
print(f"\033[31m[FAILED]\033[0m {msg}")
|
|
786
|
+
sys.exit(1)
|
|
787
|
+
|
|
788
|
+
# Run Local CI
|
|
789
|
+
runner = LocalCIRunner(repo_dir=args.dir, quick=args.quick, auto_fix=args.fix)
|
|
790
|
+
report = runner.run()
|
|
791
|
+
|
|
792
|
+
if args.json:
|
|
793
|
+
print(json.dumps(report.to_dict(), indent=2))
|
|
794
|
+
else:
|
|
795
|
+
print(LocalCIRunner.render_terminal_report(report))
|
|
796
|
+
|
|
797
|
+
sys.exit(0 if report.passed else 1)
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
if __name__ == "__main__":
|
|
801
|
+
main()
|