vibe-coding-qa 0.5.0__py3-none-any.whl

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.
Files changed (58) hide show
  1. dashboard/__init__.py +10 -0
  2. dashboard/backend/__init__.py +11 -0
  3. dashboard/backend/__main__.py +6 -0
  4. dashboard/backend/ai/__init__.py +6 -0
  5. dashboard/backend/ai/provider.py +102 -0
  6. dashboard/backend/ai/service.py +757 -0
  7. dashboard/backend/api/__init__.py +5 -0
  8. dashboard/backend/api/ai.py +142 -0
  9. dashboard/backend/api/dashboard.py +34 -0
  10. dashboard/backend/api/deps.py +51 -0
  11. dashboard/backend/api/findings.py +102 -0
  12. dashboard/backend/api/intel.py +41 -0
  13. dashboard/backend/api/repositories.py +62 -0
  14. dashboard/backend/api/scans.py +168 -0
  15. dashboard/backend/api/system.py +69 -0
  16. dashboard/backend/config.py +180 -0
  17. dashboard/backend/main.py +183 -0
  18. dashboard/backend/persistence/__init__.py +5 -0
  19. dashboard/backend/persistence/database.py +278 -0
  20. dashboard/backend/persistence/store.py +600 -0
  21. dashboard/backend/profiles.py +141 -0
  22. dashboard/backend/schemas.py +452 -0
  23. dashboard/backend/security.py +158 -0
  24. dashboard/backend/services/__init__.py +7 -0
  25. dashboard/backend/services/dashboard.py +172 -0
  26. dashboard/backend/services/intel.py +341 -0
  27. dashboard/backend/services/paths.py +38 -0
  28. dashboard/backend/services/repositories.py +123 -0
  29. dashboard/backend/services/scans.py +328 -0
  30. dashboard/backend/services/settings.py +49 -0
  31. dashboard/frontend/dist/assets/index-COC-CdqD.js +492 -0
  32. dashboard/frontend/dist/assets/index-hWDLRaLr.css +1 -0
  33. dashboard/frontend/dist/index.html +29 -0
  34. dashboard/frontend/dist/phone-mascots.gif +0 -0
  35. dashboard/launcher.py +48 -0
  36. vibe_coding_qa/__init__.py +140 -0
  37. vibe_coding_qa/__main__.py +5 -0
  38. vibe_coding_qa/ai_review.py +165 -0
  39. vibe_coding_qa/cli.py +157 -0
  40. vibe_coding_qa/engine.py +860 -0
  41. vibe_coding_qa/fixes.py +222 -0
  42. vibe_coding_qa/gates.py +300 -0
  43. vibe_coding_qa/profile.py +471 -0
  44. vibe_coding_qa/repo.py +188 -0
  45. vibe_coding_qa/reporters/__init__.py +253 -0
  46. vibe_coding_qa/scanners/__init__.py +195 -0
  47. vibe_coding_qa/scanners/compliance.py +167 -0
  48. vibe_coding_qa/scanners/database.py +316 -0
  49. vibe_coding_qa/scanners/dependencies.py +595 -0
  50. vibe_coding_qa/scanners/infrastructure.py +125 -0
  51. vibe_coding_qa/scanners/performance.py +84 -0
  52. vibe_coding_qa/scanners/quality.py +129 -0
  53. vibe_coding_qa/scanners/security.py +521 -0
  54. vibe_coding_qa-0.5.0.dist-info/METADATA +323 -0
  55. vibe_coding_qa-0.5.0.dist-info/RECORD +58 -0
  56. vibe_coding_qa-0.5.0.dist-info/WHEEL +5 -0
  57. vibe_coding_qa-0.5.0.dist-info/entry_points.txt +3 -0
  58. vibe_coding_qa-0.5.0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,253 @@
1
+ """Report generators: Markdown, JSON, HTML."""
2
+
3
+ import html
4
+ import json
5
+ from datetime import datetime, timezone
6
+ from pathlib import Path
7
+
8
+ from .. import ScanResult
9
+ from ..gates import coverage_gaps, release_decision, release_gate_label
10
+
11
+
12
+ def _h(text: str) -> str:
13
+ return html.escape(str(text))
14
+
15
+
16
+ def _value(value):
17
+ return getattr(value, "value", value)
18
+
19
+
20
+ _TEST_COUNT_FIELDS = (
21
+ ("tests_discovered", "discovered"),
22
+ ("tests_executed", "executed"),
23
+ ("tests_passed", "passed"),
24
+ ("tests_failed", "failed"),
25
+ ("tests_skipped", "skipped"),
26
+ ("tests_errors", "errors"),
27
+ )
28
+
29
+
30
+ def _test_counts(tests: dict) -> str:
31
+ parts = []
32
+ for key, label in _TEST_COUNT_FIELDS:
33
+ value = tests.get(key)
34
+ if value is not None:
35
+ parts.append(f"{label}={value}")
36
+ return ", ".join(parts)
37
+
38
+
39
+ def markdown_report(result: ScanResult, title: str = "Vibe Coding QA Production Readiness Report") -> str:
40
+ lines = [
41
+ f"# {title}",
42
+ "",
43
+ f"- **Repository:** `{result.repo}`",
44
+ f"- **Generated:** {datetime.now(timezone.utc).isoformat()}",
45
+ f"- **Overall Score:** {result.overall_score}/100",
46
+ f"- **Critical Findings:** {result.critical_count}",
47
+ f"- **High Findings:** {result.high_count}",
48
+ f"- **Release Gate:** {release_gate_label(result)}",
49
+ f"- **Decision:** {release_decision(result)}",
50
+ "",
51
+ "## Module Summary",
52
+ "",
53
+ "| Module | Score | Status | Findings |",
54
+ "|--------|-------|--------|----------|",
55
+ ]
56
+ for module in result.modules:
57
+ lines.append(f"| {module.module} | {module.score} | {module.status.value} | {len(module.findings)} |")
58
+ lines.append("")
59
+ scanner_notes = [f"{module.module}: {note}" for module in result.modules for note in module.notes]
60
+ if scanner_notes:
61
+ lines.extend(["## Scanner Notes", "", *[f"- {note}" for note in scanner_notes], ""])
62
+
63
+ arch = result.tests.get("architecture")
64
+ if arch:
65
+ lines.append("## Detected Technology Stack")
66
+ lines.append("")
67
+ lines.append(f"- **Languages:** {', '.join(f'{k} ({v})' for k, v in arch.get('languages', {}).items() if v)}")
68
+ lines.append(f"- **Frameworks:** {', '.join(arch.get('frameworks', [])) or 'none'}")
69
+ lines.append(f"- **Package manager:** {arch.get('package_manager', 'unknown')}")
70
+ lines.append(f"- **Databases:** {', '.join(arch.get('databases', [])) or 'none'}")
71
+ lines.append(f"- **Auth providers:** {', '.join(arch.get('auth_providers', [])) or 'none'}")
72
+ lines.append(f"- **Test runners:** {', '.join(arch.get('test_runners', [])) or 'none'}")
73
+ lines.append(f"- **Deployment:** {', '.join(arch.get('deployment', [])) or 'none'}")
74
+ lines.append("")
75
+
76
+ if result.tests:
77
+ lines.append("## Test Results")
78
+ lines.append("")
79
+ lines.append(f"- Status: `{_value(result.tests.get('status', 'unknown'))}`")
80
+ if result.tests.get("test_reason"):
81
+ lines.append(f"- Classification: {result.tests['test_reason']}")
82
+ if result.tests.get("test_runner"):
83
+ lines.append(f"- Test runner: {result.tests['test_runner']}")
84
+ lines.append(f"- Command: `{result.tests.get('command', 'N/A')}`")
85
+ if "duration_ms" in result.tests:
86
+ lines.append(f"- Duration: {result.tests['duration_ms']} ms")
87
+ counts = _test_counts(result.tests)
88
+ if counts:
89
+ lines.append(f"- Counts: {counts}")
90
+ if "summary" in result.tests:
91
+ lines.append(f"- Summary: {result.tests['summary']}")
92
+ lines.append("")
93
+
94
+ fixes = result.tests.get("fixes")
95
+ if fixes:
96
+ lines.append("## Fixes")
97
+ lines.append("")
98
+ lines.append(f"- Mode: {'preview' if fixes.get('dry_run') else 'applied'}")
99
+ lines.append(f"- Applied: {len(fixes.get('applied', []))}")
100
+ lines.append(f"- Skipped: {len(fixes.get('skipped', []))}")
101
+ for a in fixes.get("applied", []):
102
+ lines.append(f"- `{a['finding']['rule']}` at `{a['finding']['file']}:{a['finding']['line']}`")
103
+ if a.get("diff"):
104
+ lines.append(" ```diff")
105
+ lines.extend([" " + line for line in a["diff"].splitlines()])
106
+ lines.append(" ```")
107
+ lines.append("")
108
+
109
+ gaps = coverage_gaps(result)
110
+ if gaps:
111
+ lines.append("## Coverage Gaps and Limitations")
112
+ lines.append("")
113
+ for gap in gaps:
114
+ lines.append(f"- {gap}")
115
+ lines.append("")
116
+
117
+ lines.append("## Findings")
118
+ lines.append("")
119
+ if not result.findings:
120
+ lines.append("No findings.")
121
+ else:
122
+ for f in sorted(result.findings, key=lambda x: (x.severity.value, x.module, str(x.file), x.line)):
123
+ lines.append(f"### [{f.severity.value.upper()}] {f.rule}")
124
+ lines.append(f"- **File:** `{f.file}`:{f.line}")
125
+ lines.append(f"- **Message:** {f.message}")
126
+ lines.append(f"- **Suggestion:** {f.suggestion}")
127
+ lines.append(f"- **Confidence:** {f.confidence}")
128
+ if f.fixable:
129
+ lines.append(f"- **Auto-fixable:** yes")
130
+ lines.append("")
131
+ return "\n".join(lines)
132
+
133
+
134
+ def json_report(result: ScanResult) -> str:
135
+ data = result.to_dict()
136
+ data["release_gate"] = release_gate_label(result)
137
+ data["release_decision"] = release_decision(result)
138
+ data["coverage_gaps"] = coverage_gaps(result)
139
+ return json.dumps(data, indent=2)
140
+
141
+
142
+ def html_report(result: ScanResult, title: str = "Vibe Coding QA Production Readiness Report") -> str:
143
+ rows = ""
144
+ for f in sorted(result.findings, key=lambda x: (x.severity.value, x.module, str(x.file), x.line)):
145
+ severity_class = f"severity-{f.severity.value}"
146
+ rows += (
147
+ f"<tr class='{_h(severity_class)}'>"
148
+ f"<td>{_h(f.severity.value.upper())}</td>"
149
+ f"<td>{_h(f.module)}</td>"
150
+ f"<td><code>{_h(f.file)}:{f.line}</code></td>"
151
+ f"<td>{_h(f.message)}</td>"
152
+ f"<td>{_h(f.suggestion)}</td>"
153
+ f"<td>{'yes' if f.fixable else 'no'}</td>"
154
+ f"</tr>"
155
+ )
156
+ module_rows = ""
157
+ for m in result.modules:
158
+ module_rows += f"<tr><td>{_h(m.module)}</td><td>{m.score}</td><td>{_h(m.status.value)}</td><td>{len(m.findings)}</td></tr>"
159
+ scanner_notes = [f"{m.module}: {note}" for m in result.modules for note in m.notes]
160
+ notes_html = ""
161
+ if scanner_notes:
162
+ notes_html = "<h2>Scanner Notes</h2><ul>" + "".join(f"<li>{_h(note)}</li>" for note in scanner_notes) + "</ul>"
163
+ status = release_gate_label(result)
164
+ decision = _h(release_decision(result))
165
+ arch = result.tests.get("architecture", {})
166
+ arch_html = ""
167
+ if arch:
168
+ arch_html = (
169
+ f"<h2>Detected Technology Stack</h2><ul>"
170
+ f"<li>Languages: {_h(', '.join(f'{k} ({v})' for k, v in arch.get('languages', {}).items() if v))}</li>"
171
+ f"<li>Frameworks: {_h(', '.join(arch.get('frameworks', [])))}</li>"
172
+ f"<li>Package manager: {_h(arch.get('package_manager', 'unknown'))}</li>"
173
+ f"<li>Databases: {_h(', '.join(arch.get('databases', [])))}</li>"
174
+ f"<li>Auth providers: {_h(', '.join(arch.get('auth_providers', [])))}</li>"
175
+ f"<li>Test runners: {_h(', '.join(arch.get('test_runners', [])))}</li>"
176
+ f"</ul>"
177
+ )
178
+ test_html = ""
179
+ if result.tests:
180
+ counts = _test_counts(result.tests)
181
+ counts_html = f"<li>Counts: {_h(counts)}</li>" if counts else ""
182
+ reason_html = f"<li>Classification: {_h(result.tests['test_reason'])}</li>" if result.tests.get("test_reason") else ""
183
+ runner_html = f"<li>Test runner: {_h(result.tests['test_runner'])}</li>" if result.tests.get("test_runner") else ""
184
+ test_html = (
185
+ f"<h2>Test Results</h2><ul>"
186
+ f"<li>Status: {_h(_value(result.tests.get('status', 'unknown')))}</li>"
187
+ f"{reason_html}"
188
+ f"{runner_html}"
189
+ f"<li>Command: <code>{_h(result.tests.get('command', 'N/A'))}</code></li>"
190
+ f"<li>Duration: {_h(result.tests.get('duration_ms', 'N/A'))} ms</li>"
191
+ f"{counts_html}"
192
+ f"</ul>"
193
+ )
194
+ gaps = coverage_gaps(result)
195
+ gaps_html = ""
196
+ if gaps:
197
+ gaps_html = "<h2>Coverage Gaps and Limitations</h2><ul>" + "".join(f"<li>{_h(g)}</li>" for g in gaps) + "</ul>"
198
+ return f"""<!doctype html>
199
+ <html lang="en">
200
+ <head>
201
+ <meta charset="utf-8">
202
+ <title>{_h(title)}</title>
203
+ <style>
204
+ body {{ font-family: system-ui, sans-serif; margin: 2rem; }}
205
+ table {{ border-collapse: collapse; width: 100%; margin: 1rem 0; }}
206
+ th, td {{ border: 1px solid #ccc; padding: 0.5rem; text-align: left; }}
207
+ th {{ background: #f3f3f3; }}
208
+ .severity-critical {{ background: #ffcccc; }}
209
+ .severity-high {{ background: #ffe6cc; }}
210
+ .severity-medium {{ background: #ffffcc; }}
211
+ .severity-low {{ background: #e6f3ff; }}
212
+ .severity-info {{ background: #f0f0f0; }}
213
+ </style>
214
+ </head>
215
+ <body>
216
+ <h1>{_h(title)}</h1>
217
+ <p><strong>Repository:</strong> <code>{_h(result.repo)}</code></p>
218
+ <p><strong>Generated:</strong> {datetime.now(timezone.utc).isoformat()}</p>
219
+ <p><strong>Overall Score:</strong> {result.overall_score}/100</p>
220
+ <p><strong>Release Gate:</strong> {status}</p>
221
+ <p><strong>Decision:</strong> {decision}</p>
222
+ {arch_html}
223
+ <h2>Module Summary</h2>
224
+ <table>
225
+ <thead><tr><th>Module</th><th>Score</th><th>Status</th><th>Findings</th></tr></thead>
226
+ <tbody>{module_rows}</tbody>
227
+ </table>
228
+ {notes_html}
229
+ {test_html}
230
+ {gaps_html}
231
+ <h2>Findings</h2>
232
+ <table>
233
+ <thead><tr><th>Severity</th><th>Module</th><th>Location</th><th>Message</th><th>Suggestion</th><th>Auto-fix</th></tr></thead>
234
+ <tbody>{rows}</tbody>
235
+ </table>
236
+ </body>
237
+ </html>"""
238
+
239
+
240
+ def write_reports(result: ScanResult, output_dir: Path, prefix: str = "vcqa-report") -> dict[str, Path]:
241
+ output_dir = Path(output_dir)
242
+ output_dir.mkdir(parents=True, exist_ok=True)
243
+ paths = {}
244
+ md_path = output_dir / f"{prefix}.md"
245
+ json_path = output_dir / f"{prefix}.json"
246
+ html_path = output_dir / f"{prefix}.html"
247
+ md_path.write_text(markdown_report(result), encoding="utf-8")
248
+ json_path.write_text(json_report(result), encoding="utf-8")
249
+ html_path.write_text(html_report(result), encoding="utf-8")
250
+ paths["markdown"] = md_path
251
+ paths["json"] = json_path
252
+ paths["html"] = html_path
253
+ return paths
@@ -0,0 +1,195 @@
1
+ """Base scanner utilities and shared helpers."""
2
+
3
+ import fnmatch
4
+ import re
5
+ from pathlib import Path
6
+
7
+ from vibe_coding_qa import Finding, Severity
8
+
9
+
10
+ SECRET_PATTERNS = [
11
+ ("private-key", re.compile(r"-----BEGIN (RSA |EC |DSA |OPENSSH )?PRIVATE(?:\s+)KEY-----", re.IGNORECASE), Severity.CRITICAL),
12
+ ("aws-access-key", re.compile(r"AKIA[0-9A-Z]{16}"), Severity.CRITICAL),
13
+ ("generic-api-key", re.compile(r"(?<!\w)(api[_-]?key|apikey|api_secret|api_secret_key|secret[_-]?key|auth[_-]?token)\s*[:=]\s*['\"][A-Za-z0-9_\-]{16,}['\"]", re.IGNORECASE), Severity.HIGH),
14
+ ("supabase-service-key", re.compile(r"(eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.eyJ[A-Za-z0-9_-]*|sbp_[a-zA-Z0-9]{40,})", re.IGNORECASE), Severity.CRITICAL),
15
+ ("openai-key", re.compile(r"sk-[a-zA-Z0-9]{20,}", re.IGNORECASE), Severity.CRITICAL),
16
+ ("stripe-key", re.compile(r"sk_(live|test)_[0-9a-zA-Z]{24,}", re.IGNORECASE), Severity.CRITICAL),
17
+ ("password-in-code", re.compile(r"password\s*[:=]\s*['\"][^'\"]{4,}['\"]", re.IGNORECASE), Severity.HIGH),
18
+ ("url-with-credentials", re.compile(r"https?://[^\s:/\"']+:[^\s@/\"']+@[^\s\"']+", re.IGNORECASE), Severity.HIGH),
19
+ # Additional secret patterns for better coverage
20
+ ("jwt-token", re.compile(r"eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*"), Severity.CRITICAL),
21
+ ("bearer-token", re.compile(r"(?i)bearer\s+[A-Za-z0-9_\-]{20,}"), Severity.HIGH),
22
+ ("database-url", re.compile(r"(?i)(postgres|mysql|mongodb|redis)://[^:\s]+:[^@\s]+@[^\s\"']+"), Severity.CRITICAL),
23
+ ("github-token", re.compile(r"gh[pousr]_[A-Za-z0-9]{36,}"), Severity.CRITICAL),
24
+ ("slack-token", re.compile(r"xox[baprs]-[A-Za-z0-9-]{10,}"), Severity.HIGH),
25
+ ("sendgrid-key", re.compile(r"SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}"), Severity.CRITICAL),
26
+ ("twilio-key", re.compile(r"SK[0-9a-f]{32}"), Severity.CRITICAL),
27
+ ("heroku-key", re.compile(r"\bheroku[_-]?(?:api[_-]?)?(?:key|token)\s*['\"]?\s*[:=]\s*['\"]?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b", re.IGNORECASE), Severity.HIGH),
28
+ ("private-key-pem", re.compile(r"-----BEGIN (RSA |EC |DSA |OPENSSH |ENCRYPTED )?PRIVATE(?:\s+)KEY-----", re.IGNORECASE), Severity.CRITICAL),
29
+ ("ssh-private-key", re.compile(r"-----BEGIN OPENSSH PRIVATE(?:\s+)KEY-----", re.IGNORECASE), Severity.CRITICAL),
30
+ ("pgp-private-key", re.compile(r"-----BEGIN PGP PRIVATE(?:\s+)KEY BLOCK-----", re.IGNORECASE), Severity.CRITICAL),
31
+ ]
32
+
33
+
34
+ _PEM_BLOCK_PATTERNS = [
35
+ re.compile(r"-----BEGIN (?P<label>(?:[A-Z0-9]+ )*PRIVATE(?:\s+)KEY)-----[\s\S]*?-----END (?P=label)-----", re.IGNORECASE),
36
+ re.compile(r"-----BEGIN PGP PRIVATE(?:\s+)KEY BLOCK-----[\s\S]*?-----END PGP PRIVATE(?:\s+)KEY BLOCK-----", re.IGNORECASE),
37
+ ]
38
+ _SECRET_REDACTION_PATTERNS = _PEM_BLOCK_PATTERNS + [p for _, p, _ in SECRET_PATTERNS]
39
+
40
+
41
+ def redact_secrets(text: str) -> str:
42
+ """Redact known credentials and complete private-key blocks."""
43
+ for pattern in _SECRET_REDACTION_PATTERNS:
44
+ text = pattern.sub("[REDACTED]", text)
45
+ return text
46
+
47
+
48
+ def is_secret_finding(finding: Finding) -> bool:
49
+ """Check if a finding is related to exposed secrets."""
50
+ secret_rules = {
51
+ "private-key", "aws-access-key", "generic-api-key", "supabase-service-key",
52
+ "openai-key", "stripe-key", "password-in-code", "url-with-credentials",
53
+ "client-side-secret", "committed-env-file", "session-secret-hardcoded",
54
+ "jwt-token", "bearer-token", "database-url", "github-token",
55
+ "slack-token", "sendgrid-key", "twilio-key", "heroku-key",
56
+ "private-key-pem", "ssh-private-key", "pgp-private-key",
57
+ }
58
+ return finding.rule.split(":")[-1] in secret_rules
59
+
60
+
61
+ SQL_INJECTION_HINTS = [
62
+ re.compile(r"\.query\s*\(\s*[^,)]*%s", re.IGNORECASE),
63
+ re.compile(r"execute\s*\(\s*['\"].*%s", re.IGNORECASE),
64
+ re.compile(r"\.raw\s*\(\s*['\"].*%s", re.IGNORECASE),
65
+ ]
66
+
67
+
68
+ class BaseScanner:
69
+ module = "base"
70
+
71
+ def __init__(self, repo: Path):
72
+ self.repo = repo
73
+ self.findings: list[Finding] = []
74
+
75
+ def scan(self) -> list[Finding]:
76
+ raise NotImplementedError
77
+
78
+ def add(self, rule: str, severity: Severity, file: Path, line: int, message: str, suggestion: str = "", confidence: str = "medium", fixable: bool = False, auto_fix: str = "", column: int = 0):
79
+ self.findings.append(Finding(
80
+ rule=f"{self.module}:{rule}",
81
+ module=self.module,
82
+ severity=severity,
83
+ file=file.relative_to(self.repo) if file.is_absolute() else file,
84
+ line=line,
85
+ column=column,
86
+ message=message,
87
+ suggestion=suggestion,
88
+ confidence=confidence,
89
+ fixable=fixable,
90
+ auto_fix=auto_fix,
91
+ ))
92
+
93
+ def score(self, max_score: float = 100.0) -> float:
94
+ if not self.findings:
95
+ return max_score
96
+ weights = {Severity.CRITICAL: 40, Severity.HIGH: 20, Severity.MEDIUM: 10, Severity.LOW: 3, Severity.INFO: 1}
97
+ penalty = sum(weights.get(f.severity, 0) for f in self.findings)
98
+ return max(0.0, max_score - penalty)
99
+
100
+ def iter_source_files(self, extensions: tuple[str, ...]) -> list[Path]:
101
+ files = []
102
+ for ext in extensions:
103
+ files.extend(self.repo.rglob(f"*{ext}"))
104
+ ignore = load_ignore_patterns(self.repo)
105
+ return [
106
+ p for p in files
107
+ if "node_modules" not in p.parts
108
+ and ".git" not in p.parts
109
+ and "__pycache__" not in p.parts
110
+ and not p.name.endswith(".d.ts")
111
+ and not is_ignored(p, self.repo, ignore)
112
+ ]
113
+
114
+
115
+ def load_ignore_patterns(repo: Path) -> list[str]:
116
+ patterns: list[str] = []
117
+ ignore_file = repo / ".vcqaignore"
118
+ if ignore_file.is_file():
119
+ for line in ignore_file.read_text(encoding="utf-8", errors="ignore").splitlines():
120
+ line = line.strip()
121
+ if line and not line.startswith("#"):
122
+ patterns.append(line)
123
+ return patterns
124
+
125
+
126
+ def is_ignored(path: Path, repo: Path, patterns: list[str] | None = None) -> bool:
127
+ if patterns is None:
128
+ patterns = load_ignore_patterns(repo)
129
+ try:
130
+ rel = path.relative_to(repo).as_posix()
131
+ except ValueError:
132
+ return False
133
+ parts = Path(rel).parts
134
+ for pattern in patterns:
135
+ pat = pattern.rstrip("/")
136
+ # Match exact file or directory name anywhere in the path.
137
+ if pat in parts:
138
+ return True
139
+ # Match full relative path or glob.
140
+ if fnmatch.fnmatch(rel, pattern) or fnmatch.fnmatch(rel, f"**/{pattern}"):
141
+ return True
142
+ # Match directory prefix.
143
+ if rel.startswith(pat + "/"):
144
+ return True
145
+ return False
146
+
147
+
148
+ def normalize_line(text: str) -> str:
149
+ return re.sub(r"\s+", " ", text).strip()
150
+
151
+
152
+ def is_test_or_fixture(path: Path) -> bool:
153
+ name = path.name.lower()
154
+ parts = [p.lower() for p in path.parts]
155
+ return "test" in parts or "tests" in parts or "fixture" in parts or "fixtures" in parts or name.startswith("test_") or ".test." in name or ".spec." in name
156
+
157
+
158
+ def is_config_file(path: Path) -> bool:
159
+ return path.name.lower() in {"dockerfile", "docker-compose.yml", "docker-compose.yaml", "nginx.conf", ".env.example", ".env.local", ".env.production"}
160
+
161
+
162
+ def is_likely_client_file(path: Path, repo: Path | None = None) -> bool:
163
+ try:
164
+ relative = path.relative_to(repo) if repo else path
165
+ except ValueError:
166
+ relative = path
167
+ parts = [part.lower() for part in relative.parts]
168
+ name = path.name.lower()
169
+ if path.suffix.lower() not in {".ts", ".tsx", ".js", ".jsx", ".vue", ".svelte"}:
170
+ return False
171
+ if set(parts[:-1]) & {"api", "server", "backend", "functions", "middleware"}:
172
+ return False
173
+ if name.startswith("middleware.") or ".server." in name or name.startswith("server."):
174
+ return False
175
+ try:
176
+ text = path.read_text(encoding="utf-8", errors="ignore")
177
+ except OSError:
178
+ return False
179
+ if re.search(r"(?m)^\s*['\"]use server['\"]\s*;?", text) or re.search(r"\bimport\s+['\"]server-only['\"]", text):
180
+ return False
181
+ if re.search(r"(?m)^\s*['\"]use client['\"]\s*;?", text):
182
+ return True
183
+ if set(parts[:-1]) & {"client", "frontend", "components", "ui"} or name.startswith("client.") or ".client." in name:
184
+ return True
185
+ if "src" in parts[:-1] and repo:
186
+ package_file = repo / "package.json"
187
+ try:
188
+ if re.search(r'"next"\s*:', package_file.read_text(encoding="utf-8", errors="ignore")):
189
+ return False
190
+ except OSError:
191
+ pass
192
+ return True
193
+ if "pages" in parts[:-1]:
194
+ return not re.search(r"\b(getServerSideProps|getStaticProps|apiResolver)\b", text)
195
+ return False
@@ -0,0 +1,167 @@
1
+ """Compliance scanner: Tanzania PDPA 2022, TCRA SMS, RFC 8058 unsubscribe."""
2
+
3
+ import re
4
+ from pathlib import Path
5
+
6
+ from . import BaseScanner, load_ignore_patterns, is_ignored
7
+ from vibe_coding_qa import Finding, Severity
8
+
9
+
10
+ class ComplianceScanner(BaseScanner):
11
+ module = "compliance"
12
+
13
+ def scan(self) -> list[Finding]:
14
+ ignore = load_ignore_patterns(self.repo)
15
+ self._scan_privacy_consent(ignore)
16
+ self._scan_unsubscribe(ignore)
17
+ self._scan_sms_opt_out(ignore)
18
+ self._scan_dpo_and_register(ignore)
19
+ return self.findings
20
+
21
+ def _scan_privacy_consent(self, ignore: list[str]) -> None:
22
+ html_files = [
23
+ p for p in (list(self.repo.rglob("*.html")) + list(self.repo.rglob("*.tsx")) + list(self.repo.rglob("*.jsx")) + list(self.repo.rglob("*.vue")) + list(self.repo.rglob("*.svelte")))
24
+ if "vcqa-reports" not in p.parts and "__pycache__" not in p.parts and ".git" not in p.parts and "node_modules" not in p.parts and not is_ignored(p, self.repo, ignore)
25
+ ]
26
+ if not html_files:
27
+ return
28
+ consent_found = False
29
+ explicit_opt_in_found = False
30
+ pre_ticked_found = False
31
+ for path in html_files:
32
+ text = path.read_text(encoding="utf-8", errors="ignore").lower()
33
+ if "consent" in text or "privacy" in text or "data protection" in text:
34
+ consent_found = True
35
+ if re.search(r"checkbox[^\n]{0,200}?(checked|defaultchecked|checked=\"true\"|checked={true})", text, re.IGNORECASE):
36
+ pre_ticked_found = True
37
+ if re.search(r"checkbox[^\n]{0,200}?\b(required|must)\b", text, re.IGNORECASE) and not pre_ticked_found:
38
+ explicit_opt_in_found = True
39
+ if not consent_found:
40
+ self.add(
41
+ rule="privacy-consent-missing",
42
+ severity=Severity.HIGH,
43
+ file=html_files[0],
44
+ line=1,
45
+ message="No privacy or consent disclosure found in UI files.",
46
+ suggestion="Add a clear disclosure naming the data controller and purpose before collecting personal data.",
47
+ confidence="low",
48
+ )
49
+ if pre_ticked_found:
50
+ self.add(
51
+ rule="pre-ticked-consent-checkbox",
52
+ severity=Severity.CRITICAL,
53
+ file=html_files[0],
54
+ line=1,
55
+ message="Pre-ticked consent checkbox detected; this violates Tanzania PDPA 2022.",
56
+ suggestion="Require an explicit affirmative action (unticked checkbox) for consent.",
57
+ confidence="medium",
58
+ )
59
+ if consent_found and not explicit_opt_in_found and not pre_ticked_found:
60
+ self.add(
61
+ rule="explicit-opt-in-unverified",
62
+ severity=Severity.MEDIUM,
63
+ file=html_files[0],
64
+ line=1,
65
+ message="Consent language exists but explicit opt-in mechanism could not be verified.",
66
+ suggestion="Use an unticked checkbox and log consent events with timestamp, IP, and version.",
67
+ confidence="low",
68
+ )
69
+
70
+ def _scan_unsubscribe(self, ignore: list[str]) -> None:
71
+ for path in self.iter_source_files((".ts", ".tsx", ".js", ".jsx", ".py")):
72
+ if is_ignored(path, self.repo, ignore):
73
+ continue
74
+ text = path.read_text(encoding="utf-8", errors="ignore").lower()
75
+ if "list-unsubscribe" in text or "unsubscribe" in text:
76
+ for i, raw in enumerate(text.splitlines(), 1):
77
+ lowered = raw.lower()
78
+ if "list-unsubscribe-post" in lowered:
79
+ if "one-click" in lowered or "one click" in lowered:
80
+ self.add(
81
+ rule="rfc8058-one-click-present",
82
+ severity=Severity.INFO,
83
+ file=path,
84
+ line=i,
85
+ message="RFC 8058 one-click unsubscribe header detected.",
86
+ suggestion="Ensure the endpoint returns 200 immediately and adds the address to a suppression list within 24 hours.",
87
+ confidence="medium",
88
+ )
89
+ return
90
+ self.add(
91
+ rule="rfc8058-list-unsubscribe-incomplete",
92
+ severity=Severity.MEDIUM,
93
+ file=path,
94
+ line=1,
95
+ message="List-Unsubscribe detected but RFC 8058 List-Unsubscribe-Post: List-Unsubscribe=One-Click not found.",
96
+ suggestion="Add both List-Unsubscribe and List-Unsubscribe-Post headers to transactional emails.",
97
+ confidence="low",
98
+ )
99
+ return
100
+ self.add(
101
+ rule="rfc8058-unsubscribe-missing",
102
+ severity=Severity.MEDIUM,
103
+ file=self.repo,
104
+ line=1,
105
+ message="No unsubscribe mechanism detected for email functionality.",
106
+ suggestion="Add List-Unsubscribe and List-Unsubscribe-Post headers to automated emails.",
107
+ confidence="low",
108
+ )
109
+
110
+ def _scan_sms_opt_out(self, ignore: list[str]) -> None:
111
+ for path in self.iter_source_files((".ts", ".tsx", ".js", ".jsx", ".py")):
112
+ if is_ignored(path, self.repo, ignore):
113
+ continue
114
+ text = path.read_text(encoding="utf-8", errors="ignore").lower()
115
+ if "sms" in text or "notify africa" in text or "beem" in text:
116
+ if "stop" in text or "ondoa" in text:
117
+ self.add(
118
+ rule="sms-opt-out-present",
119
+ severity=Severity.INFO,
120
+ file=path,
121
+ line=1,
122
+ message="SMS opt-out keywords (STOP/ONDOA) detected.",
123
+ suggestion="Verify opt-out replies are processed automatically and synced to a suppression list within 24 hours.",
124
+ confidence="low",
125
+ )
126
+ return
127
+ self.add(
128
+ rule="sms-opt-out-missing",
129
+ severity=Severity.HIGH,
130
+ file=path,
131
+ line=1,
132
+ message="SMS integration detected without STOP/ONDOA opt-out handling.",
133
+ suggestion="Include STOP and ONDOA opt-out instructions and automate suppression.",
134
+ confidence="low",
135
+ )
136
+ return
137
+
138
+ def _scan_dpo_and_register(self, ignore: list[str]) -> None:
139
+ md_files = [p for p in self.repo.rglob("*.md") if not is_ignored(p, self.repo, ignore)]
140
+ has_dpo = False
141
+ has_pdpc_register = False
142
+ for path in md_files:
143
+ text = path.read_text(encoding="utf-8", errors="ignore").lower()
144
+ if "data protection officer" in text or "dpo" in text:
145
+ has_dpo = True
146
+ if "personal data protection commission" in text or "pdpc" in text:
147
+ has_pdpc_register = True
148
+ if not has_dpo:
149
+ self.add(
150
+ rule="dpo-not-documented",
151
+ severity=Severity.MEDIUM,
152
+ file=self.repo / "README.md" if (self.repo / "README.md").is_file() else self.repo,
153
+ line=1,
154
+ message="No Data Protection Officer documented.",
155
+ suggestion="Document a DPO and publish contact details for privacy inquiries.",
156
+ confidence="low",
157
+ )
158
+ if not has_pdpc_register:
159
+ self.add(
160
+ rule="pdpc-registration-not-documented",
161
+ severity=Severity.MEDIUM,
162
+ file=self.repo / "README.md" if (self.repo / "README.md").is_file() else self.repo,
163
+ line=1,
164
+ message="PDPC data controller registration is not documented.",
165
+ suggestion="Register with the Tanzania PDPC and document the registration certificate.",
166
+ confidence="low",
167
+ )