opdev 0.7.0a2__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.
- opdev/__init__.py +1 -0
- opdev/__main__.py +3 -0
- opdev/checks.py +300 -0
- opdev/cli.py +459 -0
- opdev/commands.py +76 -0
- opdev/config.py +278 -0
- opdev/document_catalog.py +107 -0
- opdev/document_review.py +115 -0
- opdev/documents.py +415 -0
- opdev/errors.py +5 -0
- opdev/files.py +82 -0
- opdev/init.py +87 -0
- opdev/junit.py +99 -0
- opdev/output.py +141 -0
- opdev/process.py +145 -0
- opdev/providers/__init__.py +1 -0
- opdev/providers/gitlab.py +374 -0
- opdev/publication.py +209 -0
- opdev/reports.py +512 -0
- opdev/requirements.py +642 -0
- opdev/resources/reports/report.css +158 -0
- opdev/resources/reports/report.html +27 -0
- opdev/resources/reports/report.js +110 -0
- opdev/resources/skills/opdev/SKILL.md +190 -0
- opdev/resources/skills/opdev/references/adoption.md +144 -0
- opdev/resources/skills/opdev/references/design.md +141 -0
- opdev/resources/skills/opdev/references/development.md +294 -0
- opdev/resources/skills/opdev/references/engineering.md +206 -0
- opdev/resources/skills/opdev/references/planning.md +101 -0
- opdev/resources/skills/opdev/references/publication.md +34 -0
- opdev/resources/templates/AGENTS.md +7 -0
- opdev/resources/templates/CLAUDE.md +6 -0
- opdev/resources/templates/guidance.md +36 -0
- opdev/snapshot.py +484 -0
- opdev/tracking.py +224 -0
- opdev/verification.py +234 -0
- opdev/version.py +45 -0
- opdev-0.7.0a2.dist-info/METADATA +99 -0
- opdev-0.7.0a2.dist-info/RECORD +42 -0
- opdev-0.7.0a2.dist-info/WHEEL +4 -0
- opdev-0.7.0a2.dist-info/entry_points.txt +3 -0
- opdev-0.7.0a2.dist-info/licenses/LICENSE +201 -0
opdev/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Small, configuration-driven development operations."""
|
opdev/__main__.py
ADDED
opdev/checks.py
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"""One selection and execution path; focused success is not full verification."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
from contextlib import nullcontext
|
|
7
|
+
from dataclasses import asdict, dataclass, field
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from tempfile import TemporaryDirectory
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from opdev.config import JUNIT_PATH, NON_CHECK_PURPOSES, Project
|
|
13
|
+
from opdev.documents import validate as validate_documents
|
|
14
|
+
from opdev.errors import OpDevError
|
|
15
|
+
from opdev.files import contained_path, read_optional, read_regular
|
|
16
|
+
from opdev.junit import MAX_BYTES, parse
|
|
17
|
+
from opdev.process import execute
|
|
18
|
+
from opdev.requirements import STORE, Database, load, revision
|
|
19
|
+
from opdev.snapshot import Capture
|
|
20
|
+
from opdev.verification import (
|
|
21
|
+
Assessment,
|
|
22
|
+
RequirementResult,
|
|
23
|
+
TestResults,
|
|
24
|
+
assess,
|
|
25
|
+
requirement_results,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class CheckResult:
|
|
31
|
+
id: str
|
|
32
|
+
argv: tuple[str, ...]
|
|
33
|
+
cwd: str
|
|
34
|
+
timeout_seconds: int | None
|
|
35
|
+
status: str = "not_run"
|
|
36
|
+
exit_code: int | None = None
|
|
37
|
+
duration_seconds: float = 0.0
|
|
38
|
+
detail: str | None = None
|
|
39
|
+
test_results: TestResults | None = None
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass
|
|
43
|
+
class CheckReport:
|
|
44
|
+
operation: str
|
|
45
|
+
scope: str
|
|
46
|
+
status: str
|
|
47
|
+
config_sha256: str
|
|
48
|
+
checks: list[CheckResult]
|
|
49
|
+
full_check_passed: bool = False
|
|
50
|
+
detail: str = (
|
|
51
|
+
"Command outcomes only; not named-test execution, semantic review or release authority."
|
|
52
|
+
)
|
|
53
|
+
requirements_revision: str | None = None
|
|
54
|
+
requirements: list[RequirementResult] = field(default_factory=list)
|
|
55
|
+
verification: Assessment | None = None
|
|
56
|
+
commands_status: str = "not_run"
|
|
57
|
+
documents: dict[str, Any] | None = None
|
|
58
|
+
|
|
59
|
+
def to_dict(self) -> dict[str, object]:
|
|
60
|
+
result = asdict(self)
|
|
61
|
+
if self.operation != "check":
|
|
62
|
+
result["commands"] = result.pop("checks")
|
|
63
|
+
return result
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def document_inputs_unchanged(self) -> bool:
|
|
67
|
+
return self.documents is None or self.documents["status"] != "changed"
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def exit_code(self) -> int:
|
|
71
|
+
if self.status == "interrupted":
|
|
72
|
+
return 130
|
|
73
|
+
if self.status == "error":
|
|
74
|
+
return 2
|
|
75
|
+
return 0 if self.status in {"passed", "planned"} else 1
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def check(
|
|
79
|
+
project: Project,
|
|
80
|
+
only: list[str] | None = None,
|
|
81
|
+
*,
|
|
82
|
+
plan: bool = False,
|
|
83
|
+
report_path: Path | None = None,
|
|
84
|
+
) -> CheckReport:
|
|
85
|
+
selected = tuple(dict.fromkeys(only)) if only is not None else project.checks
|
|
86
|
+
return run_checks(
|
|
87
|
+
project,
|
|
88
|
+
selected,
|
|
89
|
+
"focused" if only is not None else "full",
|
|
90
|
+
plan=plan,
|
|
91
|
+
report_path=report_path,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def run_checks(
|
|
96
|
+
project: Project,
|
|
97
|
+
selected: tuple[str, ...],
|
|
98
|
+
scope: str,
|
|
99
|
+
*,
|
|
100
|
+
plan: bool = False,
|
|
101
|
+
operation: str = "check",
|
|
102
|
+
report_path: Path | None = None,
|
|
103
|
+
) -> CheckReport:
|
|
104
|
+
_validate_selection(project, selected, operation, plan, report_path)
|
|
105
|
+
results = [
|
|
106
|
+
CheckResult(
|
|
107
|
+
name,
|
|
108
|
+
project.commands[name].argv,
|
|
109
|
+
project.commands[name].cwd,
|
|
110
|
+
project.commands[name].timeout_seconds,
|
|
111
|
+
test_results=TestResults() if project.commands[name].results else None,
|
|
112
|
+
)
|
|
113
|
+
for name in selected
|
|
114
|
+
]
|
|
115
|
+
report = CheckReport(
|
|
116
|
+
operation,
|
|
117
|
+
scope,
|
|
118
|
+
"planned" if plan else "passed",
|
|
119
|
+
project.digest,
|
|
120
|
+
results,
|
|
121
|
+
)
|
|
122
|
+
if plan:
|
|
123
|
+
return report
|
|
124
|
+
capture = Capture(project, report_path) if report_path is not None else None
|
|
125
|
+
database: Database | None = None
|
|
126
|
+
mapping_raw = None
|
|
127
|
+
if (
|
|
128
|
+
operation in {"check", "test"}
|
|
129
|
+
or capture is not None
|
|
130
|
+
or any(result.test_results is not None for result in results)
|
|
131
|
+
):
|
|
132
|
+
database, mapping_raw = (capture.database, capture.raw) if capture else load(project)
|
|
133
|
+
report.requirements_revision = revision(mapping_raw)
|
|
134
|
+
report.detail = (
|
|
135
|
+
"Current-run command outcomes and reported JUnit cases. Mapped tests passing "
|
|
136
|
+
"does not prove requirement adequacy, hidden retry history or release authority."
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
if scope in {"full", "publication"}:
|
|
140
|
+
report.documents = validate_documents(project)
|
|
141
|
+
if report.documents is not None and report.documents["status"] != "valid":
|
|
142
|
+
report.status = "failed"
|
|
143
|
+
report.detail = (
|
|
144
|
+
"Document structure is invalid. No configured commands ran; repair the findings."
|
|
145
|
+
)
|
|
146
|
+
else:
|
|
147
|
+
_execute_checks(project, report, database, mapping_raw)
|
|
148
|
+
_check_document_freshness(project, report)
|
|
149
|
+
if database is not None:
|
|
150
|
+
_assess_report(project, report, database, mapping_raw)
|
|
151
|
+
if (
|
|
152
|
+
scope in {"full", "publication"}
|
|
153
|
+
and report.status == "passed"
|
|
154
|
+
and report.verification is not None
|
|
155
|
+
and report.verification.status != "passed"
|
|
156
|
+
):
|
|
157
|
+
report.status = "incomplete"
|
|
158
|
+
report.detail = (
|
|
159
|
+
"Commands passed, but active requirement verification is incomplete. "
|
|
160
|
+
"Resolve the listed findings; no full pass or publication."
|
|
161
|
+
)
|
|
162
|
+
report.full_check_passed = (
|
|
163
|
+
operation == "check" and report.scope == "full" and report.status == "passed"
|
|
164
|
+
)
|
|
165
|
+
if capture:
|
|
166
|
+
capture.finish(report)
|
|
167
|
+
return report
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _check_document_freshness(project: Project, report: CheckReport) -> None:
|
|
171
|
+
if report.documents is None:
|
|
172
|
+
return
|
|
173
|
+
current = validate_documents(project)
|
|
174
|
+
if current["status"] != "valid" or current["input_sha256"] != report.documents["input_sha256"]:
|
|
175
|
+
report.documents["status"] = "changed"
|
|
176
|
+
report.documents["findings"].extend(current["findings"])
|
|
177
|
+
report.documents["findings"].append(
|
|
178
|
+
{
|
|
179
|
+
"code": "documents_changed",
|
|
180
|
+
"path": ".opdev",
|
|
181
|
+
"line": None,
|
|
182
|
+
"message": "Document inputs changed during verification.",
|
|
183
|
+
"remedy": "Inspect the current documents and rerun the affected verification.",
|
|
184
|
+
}
|
|
185
|
+
)
|
|
186
|
+
report.status = "error"
|
|
187
|
+
report.detail = "Document inputs changed during verification; no full pass or publication."
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def _validate_selection(
|
|
191
|
+
project: Project,
|
|
192
|
+
selected: tuple[str, ...],
|
|
193
|
+
operation: str,
|
|
194
|
+
plan: bool,
|
|
195
|
+
report_path: Path | None,
|
|
196
|
+
) -> None:
|
|
197
|
+
if report_path is not None and (plan or operation not in {"check", "test"}):
|
|
198
|
+
raise OpDevError("Snapshots require an executed check or test; --plan writes nothing.")
|
|
199
|
+
if not selected or any(name not in project.commands for name in selected):
|
|
200
|
+
raise OpDevError("Select at least one declared command ID. No commands ran.")
|
|
201
|
+
if project.publication and project.publication.command in selected:
|
|
202
|
+
raise OpDevError("The publisher is not a check. Use publish after explicit authorization.")
|
|
203
|
+
if operation == "check" and any(
|
|
204
|
+
project.commands[name].purpose in NON_CHECK_PURPOSES for name in selected
|
|
205
|
+
):
|
|
206
|
+
raise OpDevError("Use run or format for those commands; they are not verification checks.")
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _inputs_unchanged(
|
|
210
|
+
project: Project, database: Database | None, mapping_raw: bytes | None
|
|
211
|
+
) -> bool:
|
|
212
|
+
try:
|
|
213
|
+
return project.unchanged() and (
|
|
214
|
+
database is None or read_optional(contained_path(project.root, STORE)) == mapping_raw
|
|
215
|
+
)
|
|
216
|
+
except (OSError, OpDevError):
|
|
217
|
+
return False
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _run_command(
|
|
221
|
+
project: Project, result: CheckResult, operation: str, database: Database | None
|
|
222
|
+
) -> None:
|
|
223
|
+
cwd: Path = contained_path(project.root, result.cwd)
|
|
224
|
+
with (
|
|
225
|
+
TemporaryDirectory(prefix="opdev-junit-") if result.test_results else nullcontext()
|
|
226
|
+
) as directory:
|
|
227
|
+
path = Path(directory) / "results.xml" if directory else None
|
|
228
|
+
if path is not None:
|
|
229
|
+
result.argv = tuple(arg.replace(JUNIT_PATH, str(path)) for arg in result.argv)
|
|
230
|
+
outcome = (
|
|
231
|
+
execute(result.argv, cwd, result.timeout_seconds, interactive=True)
|
|
232
|
+
if operation == "run"
|
|
233
|
+
else execute(result.argv, cwd, result.timeout_seconds)
|
|
234
|
+
)
|
|
235
|
+
result.status = outcome.status
|
|
236
|
+
result.exit_code = outcome.exit_code
|
|
237
|
+
result.duration_seconds = outcome.duration_seconds
|
|
238
|
+
result.detail = outcome.detail
|
|
239
|
+
if result.test_results is not None and path is not None:
|
|
240
|
+
assert database is not None
|
|
241
|
+
_read_test_results(result, path, database)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _read_test_results(result: CheckResult, path: Path, database: Database) -> None:
|
|
245
|
+
assert result.test_results is not None
|
|
246
|
+
try:
|
|
247
|
+
raw = read_regular(path, limit=MAX_BYTES)
|
|
248
|
+
result.test_results.sha256 = hashlib.sha256(raw).hexdigest()
|
|
249
|
+
result.test_results.cases = parse(raw)
|
|
250
|
+
result.test_results.match(result.id, database)
|
|
251
|
+
if result.status == "passed" and result.test_results.status != "passed":
|
|
252
|
+
result.status = "failed"
|
|
253
|
+
result.detail = "JUnit cases or expected mappings did not pass."
|
|
254
|
+
except (OpDevError, OSError) as exc:
|
|
255
|
+
result.test_results.status = "error"
|
|
256
|
+
result.test_results.detail = str(exc)
|
|
257
|
+
if result.status == "passed":
|
|
258
|
+
result.status, result.detail = "error", str(exc)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def _assess_report(
|
|
262
|
+
project: Project, report: CheckReport, database: Database, mapping_raw: bytes | None
|
|
263
|
+
) -> None:
|
|
264
|
+
report.verification = assess(
|
|
265
|
+
database,
|
|
266
|
+
{r.id: (r.status, r.test_results) for r in report.checks},
|
|
267
|
+
catalog_present=mapping_raw is not None,
|
|
268
|
+
inputs_unchanged=(
|
|
269
|
+
_inputs_unchanged(project, database, mapping_raw) and report.document_inputs_unchanged
|
|
270
|
+
),
|
|
271
|
+
)
|
|
272
|
+
if _inputs_unchanged(project, database, mapping_raw) and report.document_inputs_unchanged:
|
|
273
|
+
report.requirements = requirement_results(
|
|
274
|
+
database, {r.id: (r.status, r.test_results) for r in report.checks}, include_all=True
|
|
275
|
+
)
|
|
276
|
+
else:
|
|
277
|
+
report.status = "error"
|
|
278
|
+
report.detail = "Verification inputs changed; requirement results withheld."
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def _execute_checks(
|
|
282
|
+
project: Project, report: CheckReport, database: Database | None, mapping_raw: bytes | None
|
|
283
|
+
) -> None:
|
|
284
|
+
for result in report.checks:
|
|
285
|
+
try:
|
|
286
|
+
if not _inputs_unchanged(project, database, mapping_raw):
|
|
287
|
+
raise OpDevError(
|
|
288
|
+
"Project configuration or requirement mappings changed; inspect and retry."
|
|
289
|
+
)
|
|
290
|
+
_run_command(project, result, report.operation, database)
|
|
291
|
+
if not _inputs_unchanged(project, database, mapping_raw):
|
|
292
|
+
raise OpDevError("Configuration or requirement mappings changed; no full pass.")
|
|
293
|
+
except (OpDevError, OSError) as exc:
|
|
294
|
+
result.status, result.detail = "error", str(exc)
|
|
295
|
+
except KeyboardInterrupt:
|
|
296
|
+
result.status, result.detail = "interrupted", "Verification interrupted."
|
|
297
|
+
if result.status != "passed":
|
|
298
|
+
report.status = result.status
|
|
299
|
+
break
|
|
300
|
+
report.commands_status = report.status
|