deployproof 0.1.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.
- deployproof/__init__.py +3 -0
- deployproof/cli.py +288 -0
- deployproof/dependencies.py +874 -0
- deployproof/diff.py +234 -0
- deployproof/mutator.py +475 -0
- deployproof/reporter.py +281 -0
- deployproof/secrets.py +221 -0
- deployproof/symlinks.py +156 -0
- deployproof/wsl.py +147 -0
- deployproof-0.1.0.dist-info/METADATA +111 -0
- deployproof-0.1.0.dist-info/RECORD +15 -0
- deployproof-0.1.0.dist-info/WHEEL +5 -0
- deployproof-0.1.0.dist-info/entry_points.txt +2 -0
- deployproof-0.1.0.dist-info/licenses/LICENSE +21 -0
- deployproof-0.1.0.dist-info/top_level.txt +1 -0
deployproof/__init__.py
ADDED
deployproof/cli.py
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"""Command-line interface for DeployProof."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import List, Optional
|
|
7
|
+
|
|
8
|
+
from deployproof import __version__
|
|
9
|
+
from deployproof.dependencies import (
|
|
10
|
+
extract_all_new_dependencies,
|
|
11
|
+
scan_dependencies,
|
|
12
|
+
)
|
|
13
|
+
from deployproof.diff import (
|
|
14
|
+
DiffScopeError,
|
|
15
|
+
InvalidBaseRefError,
|
|
16
|
+
NotAGitRepositoryError,
|
|
17
|
+
get_git_root,
|
|
18
|
+
is_test_file,
|
|
19
|
+
resolve_changed_python_files,
|
|
20
|
+
resolve_changed_session_files,
|
|
21
|
+
)
|
|
22
|
+
from deployproof.mutator import run_mutation_tests
|
|
23
|
+
from deployproof.reporter import LARGE_FILE_LOC_THRESHOLD, format_report
|
|
24
|
+
from deployproof.secrets import scan_session_files_for_secrets
|
|
25
|
+
from deployproof.symlinks import scan_session_files_for_symlinks
|
|
26
|
+
from deployproof.wsl import check_wsl_readiness, run_wsl_mutmut
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def create_parser() -> argparse.ArgumentParser:
|
|
30
|
+
"""Create and configure the command-line argument parser."""
|
|
31
|
+
parser = argparse.ArgumentParser(
|
|
32
|
+
prog="deployproof",
|
|
33
|
+
description="DeployProof: A deterministic AI-code deployability checker.",
|
|
34
|
+
)
|
|
35
|
+
parser.add_argument(
|
|
36
|
+
"-v",
|
|
37
|
+
"--version",
|
|
38
|
+
action="version",
|
|
39
|
+
version=f"%(prog)s {__version__}",
|
|
40
|
+
help="Show program's version number and exit.",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
subparsers = parser.add_subparsers(dest="command", help="Available commands")
|
|
44
|
+
|
|
45
|
+
# 'check' command for V1 scope
|
|
46
|
+
check_parser = subparsers.add_parser(
|
|
47
|
+
"check",
|
|
48
|
+
help="Run deployability verification checks against session changes.",
|
|
49
|
+
)
|
|
50
|
+
check_parser.add_argument(
|
|
51
|
+
"--base",
|
|
52
|
+
type=str,
|
|
53
|
+
default=None,
|
|
54
|
+
help="Base git ref (branch/commit/tag) to diff against.",
|
|
55
|
+
)
|
|
56
|
+
check_parser.add_argument(
|
|
57
|
+
"--files",
|
|
58
|
+
nargs="+",
|
|
59
|
+
type=str,
|
|
60
|
+
default=None,
|
|
61
|
+
help="Explicit files to evaluate (bypasses git diff).",
|
|
62
|
+
)
|
|
63
|
+
check_parser.add_argument(
|
|
64
|
+
"--tests",
|
|
65
|
+
nargs="+",
|
|
66
|
+
type=str,
|
|
67
|
+
default=None,
|
|
68
|
+
help="Specific test file(s) or directories to execute.",
|
|
69
|
+
)
|
|
70
|
+
check_parser.add_argument(
|
|
71
|
+
"--threshold",
|
|
72
|
+
type=float,
|
|
73
|
+
default=80.0,
|
|
74
|
+
help="Minimum mutation score percentage to pass (default: 80.0).",
|
|
75
|
+
)
|
|
76
|
+
check_parser.add_argument(
|
|
77
|
+
"--timeout",
|
|
78
|
+
type=float,
|
|
79
|
+
default=10.0,
|
|
80
|
+
help="Test runner timeout in seconds per mutant (default: 10.0).",
|
|
81
|
+
)
|
|
82
|
+
check_parser.add_argument(
|
|
83
|
+
"--wsl",
|
|
84
|
+
action="store_true",
|
|
85
|
+
default=False,
|
|
86
|
+
help="Delegate mutation testing to mutmut inside WSL (Windows only).",
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# Placeholder 'init' command
|
|
90
|
+
subparsers.add_parser(
|
|
91
|
+
"init",
|
|
92
|
+
help="Initialize DeployProof configuration in the current repository.",
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
return parser
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def handle_check(args: argparse.Namespace) -> int:
|
|
99
|
+
"""Handle the 'check' subcommand."""
|
|
100
|
+
cwd = Path.cwd().resolve()
|
|
101
|
+
repo_root: Optional[Path] = None
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
if args.files:
|
|
105
|
+
session_files = [Path(f).resolve() for f in args.files]
|
|
106
|
+
if session_files:
|
|
107
|
+
try:
|
|
108
|
+
repo_root = get_git_root(session_files[0].parent)
|
|
109
|
+
except DiffScopeError:
|
|
110
|
+
repo_root = session_files[0].parent
|
|
111
|
+
else:
|
|
112
|
+
repo_root = cwd
|
|
113
|
+
else:
|
|
114
|
+
repo_root = get_git_root(cwd)
|
|
115
|
+
session_files = resolve_changed_session_files(cwd=cwd, base=args.base)
|
|
116
|
+
except NotAGitRepositoryError:
|
|
117
|
+
print("Error: Not a git repository. Initialize git or specify files with --files.", file=sys.stderr)
|
|
118
|
+
return 1
|
|
119
|
+
except InvalidBaseRefError as e:
|
|
120
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
121
|
+
return 1
|
|
122
|
+
except DiffScopeError as e:
|
|
123
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
124
|
+
return 1
|
|
125
|
+
|
|
126
|
+
if not session_files:
|
|
127
|
+
print("DeployProof: No modified files detected in current session.")
|
|
128
|
+
print("Working tree is clean. Use --base <ref> or --files <path...> to evaluate specific files.")
|
|
129
|
+
return 0
|
|
130
|
+
|
|
131
|
+
# 1. Run Symlink & Sandbox Escape Scanner across all session files
|
|
132
|
+
symlink_result = scan_session_files_for_symlinks(session_files, repo_root=repo_root or cwd)
|
|
133
|
+
|
|
134
|
+
# 2. Run Secrets & Credentials Scanner across all session files
|
|
135
|
+
secrets_result = scan_session_files_for_secrets(session_files)
|
|
136
|
+
|
|
137
|
+
# 3. Run Slopsquatting & Dependency Hallucination Scanner across session files
|
|
138
|
+
extracted_deps = extract_all_new_dependencies(session_files, root=repo_root or cwd, base=args.base)
|
|
139
|
+
dependency_result = scan_dependencies(extracted_deps)
|
|
140
|
+
|
|
141
|
+
# 4. Filter target Python files for mutation testing
|
|
142
|
+
if args.files:
|
|
143
|
+
target_files = [f for f in session_files if f.is_file() and f.suffix == ".py"]
|
|
144
|
+
else:
|
|
145
|
+
target_files = [f for f in session_files if f.is_file() and f.suffix == ".py" and not is_test_file(f)]
|
|
146
|
+
|
|
147
|
+
# Notify upfront if large files are in scope
|
|
148
|
+
for f in target_files:
|
|
149
|
+
try:
|
|
150
|
+
loc = len(f.read_text(encoding="utf-8", errors="replace").splitlines())
|
|
151
|
+
if loc >= LARGE_FILE_LOC_THRESHOLD:
|
|
152
|
+
try:
|
|
153
|
+
rel = f.relative_to(repo_root or cwd)
|
|
154
|
+
except ValueError:
|
|
155
|
+
rel = f
|
|
156
|
+
print(
|
|
157
|
+
f"Notice: Large file '{rel}' ({loc} LOC) detected - mutation testing may take several minutes."
|
|
158
|
+
)
|
|
159
|
+
except Exception:
|
|
160
|
+
pass
|
|
161
|
+
|
|
162
|
+
# Optional WSL delegation
|
|
163
|
+
if getattr(args, "wsl", False):
|
|
164
|
+
wsl_ready, wsl_msg = check_wsl_readiness()
|
|
165
|
+
if wsl_ready:
|
|
166
|
+
print("DeployProof - Delegating to mutmut in WSL...")
|
|
167
|
+
wsl_res = run_wsl_mutmut(repo_root or cwd, target_files)
|
|
168
|
+
if wsl_res.get("success"):
|
|
169
|
+
print(wsl_res.get("stdout", ""))
|
|
170
|
+
has_security_issue = bool(
|
|
171
|
+
secrets_result.findings
|
|
172
|
+
or symlink_result.escape_findings
|
|
173
|
+
or dependency_result.high_risk_count > 0
|
|
174
|
+
)
|
|
175
|
+
return 1 if has_security_issue else 0
|
|
176
|
+
else:
|
|
177
|
+
print(f"WSL execution error: {wsl_res.get('error') or wsl_res.get('stderr')}", file=sys.stderr)
|
|
178
|
+
print("Falling back to Tier 1 local pre-check...")
|
|
179
|
+
else:
|
|
180
|
+
print(wsl_msg)
|
|
181
|
+
print("-" * 68)
|
|
182
|
+
|
|
183
|
+
result = run_mutation_tests(
|
|
184
|
+
target_files=target_files,
|
|
185
|
+
repo_root=repo_root or cwd,
|
|
186
|
+
test_runner_timeout=args.timeout,
|
|
187
|
+
extra_pytest_args=args.tests,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
report_text = format_report(
|
|
191
|
+
result=result,
|
|
192
|
+
target_files=target_files,
|
|
193
|
+
secrets_result=secrets_result,
|
|
194
|
+
symlink_result=symlink_result,
|
|
195
|
+
dependency_result=dependency_result,
|
|
196
|
+
repo_root=repo_root or cwd,
|
|
197
|
+
threshold=args.threshold,
|
|
198
|
+
)
|
|
199
|
+
print(report_text)
|
|
200
|
+
|
|
201
|
+
# Fail if mutation score threshold not met, secrets detected, symlink sandbox escapes found, or hallucinated packages detected
|
|
202
|
+
if (
|
|
203
|
+
result.mutation_score < args.threshold
|
|
204
|
+
or len(result.untested_files) > 0
|
|
205
|
+
or len(secrets_result.findings) > 0
|
|
206
|
+
or len(symlink_result.escape_findings) > 0
|
|
207
|
+
or dependency_result.high_risk_count > 0
|
|
208
|
+
):
|
|
209
|
+
return 1
|
|
210
|
+
return 0
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def handle_init(args: argparse.Namespace) -> int:
|
|
214
|
+
"""Handle the 'init' subcommand to initialize configuration and git hooks."""
|
|
215
|
+
cwd = Path.cwd().resolve()
|
|
216
|
+
try:
|
|
217
|
+
repo_root = get_git_root(cwd)
|
|
218
|
+
except DiffScopeError:
|
|
219
|
+
repo_root = cwd
|
|
220
|
+
|
|
221
|
+
print(f"DeployProof: Initializing in {repo_root}...")
|
|
222
|
+
|
|
223
|
+
# 1. Create or verify configuration file (.deployproof.json)
|
|
224
|
+
config_path = repo_root / ".deployproof.json"
|
|
225
|
+
if not config_path.exists():
|
|
226
|
+
import json
|
|
227
|
+
default_config = {
|
|
228
|
+
"version": __version__,
|
|
229
|
+
"threshold": 80.0,
|
|
230
|
+
"timeout": 10.0,
|
|
231
|
+
"secrets_scanning": True,
|
|
232
|
+
"symlink_scanning": True,
|
|
233
|
+
"dependency_scanning": True,
|
|
234
|
+
}
|
|
235
|
+
config_path.write_text(json.dumps(default_config, indent=2) + "\n", encoding="utf-8")
|
|
236
|
+
print(f" [+] Created configuration file: {config_path.name}")
|
|
237
|
+
else:
|
|
238
|
+
print(f" [.] Configuration file already exists: {config_path.name}")
|
|
239
|
+
|
|
240
|
+
# 2. Install / verify git pre-push hook if inside git repo
|
|
241
|
+
hooks_dir = repo_root / ".git" / "hooks"
|
|
242
|
+
if hooks_dir.is_dir():
|
|
243
|
+
pre_push_hook = hooks_dir / "pre-push"
|
|
244
|
+
hook_script = "#!/usr/bin/env sh\n# DeployProof deterministic pre-push verification gate\ndeployproof check\n"
|
|
245
|
+
pre_push_hook.write_text(hook_script, encoding="utf-8")
|
|
246
|
+
try:
|
|
247
|
+
import stat
|
|
248
|
+
pre_push_hook.chmod(pre_push_hook.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
|
|
249
|
+
except Exception:
|
|
250
|
+
pass
|
|
251
|
+
print(" [+] Installed git pre-push hook: .git/hooks/pre-push")
|
|
252
|
+
else:
|
|
253
|
+
print(" [i] Note: .git/hooks directory not found. Initialize git to enable automatic pre-push gating.")
|
|
254
|
+
|
|
255
|
+
print("\nDeployProof initialization complete. Run 'deployproof check' to verify your session changes.")
|
|
256
|
+
return 0
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def main(argv: Optional[List[str]] = None) -> int:
|
|
260
|
+
"""Entry point for the DeployProof CLI."""
|
|
261
|
+
if hasattr(sys.stdout, "reconfigure"):
|
|
262
|
+
try:
|
|
263
|
+
sys.stdout.reconfigure(errors="replace")
|
|
264
|
+
except Exception:
|
|
265
|
+
pass
|
|
266
|
+
if hasattr(sys.stderr, "reconfigure"):
|
|
267
|
+
try:
|
|
268
|
+
sys.stderr.reconfigure(errors="replace")
|
|
269
|
+
except Exception:
|
|
270
|
+
pass
|
|
271
|
+
|
|
272
|
+
parser = create_parser()
|
|
273
|
+
args = parser.parse_args(argv)
|
|
274
|
+
|
|
275
|
+
if not args.command:
|
|
276
|
+
parser.print_help()
|
|
277
|
+
return 0
|
|
278
|
+
|
|
279
|
+
if args.command == "check":
|
|
280
|
+
return handle_check(args)
|
|
281
|
+
elif args.command == "init":
|
|
282
|
+
return handle_init(args)
|
|
283
|
+
|
|
284
|
+
return 0
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
if __name__ == "__main__":
|
|
288
|
+
sys.exit(main())
|