okstra 0.228.1 → 0.229.0
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/docs/architecture/storage-model.md +86 -0
- package/docs/cli.md +1 -1
- package/docs/project-structure-overview.md +5 -3
- package/package.json +1 -1
- package/runtime/BUILD.json +2 -2
- package/runtime/bin/okstra-provider-exec.py +53 -4
- package/runtime/prompts/duties/code-reviewer.json +5 -2
- package/runtime/python/okstra_ctl/code_review_coverage.py +18 -6
- package/runtime/python/okstra_ctl/code_review_scope.py +2 -1
- package/runtime/python/okstra_ctl/code_review_target.py +41 -23
- package/runtime/python/okstra_ctl/conformance.py +31 -0
- package/runtime/python/okstra_ctl/execution_mutation_audit.py +100 -2
- package/runtime/python/okstra_ctl/model_io/renderers.py +10 -1
- package/runtime/python/okstra_ctl/paths.py +12 -1
- package/runtime/python/okstra_ctl/qa_commands.py +8 -1
- package/runtime/python/okstra_ctl/qa_procedures.py +60 -17
- package/runtime/python/okstra_ctl/verification_conformance.py +163 -0
- package/runtime/python/okstra_ctl/verification_generation.py +238 -0
- package/runtime/python/okstra_ctl/verification_input_types.py +21 -2
- package/runtime/python/okstra_ctl/verification_inputs.py +91 -24
- package/runtime/python/okstra_ctl/verification_target.py +13 -5
- package/runtime/skills/okstra-code-review/SKILL.md +80 -46
- package/runtime/skills/okstra-code-review/references/census-rules.md +8 -2
- package/runtime/skills/okstra-code-review/references/review-calibration.md +9 -6
- package/runtime/validators/validate-run.py +8 -33
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"""Immutable source and inspection-file seals for verification generations."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from dataclasses import replace
|
|
5
|
+
from functools import partial
|
|
6
|
+
from itertools import pairwise
|
|
7
|
+
from pathlib import Path, PurePosixPath
|
|
8
|
+
from typing import Any, Literal, Mapping, TypedDict, cast
|
|
9
|
+
|
|
10
|
+
from okstra_project.dirs import OKSTRA_DIR_NAME
|
|
11
|
+
|
|
12
|
+
from .execution_mutation_audit import (
|
|
13
|
+
VerificationSourceSnapshot, capture_verification_source,
|
|
14
|
+
is_generated_verification_path,
|
|
15
|
+
)
|
|
16
|
+
from .json_boundary import load_owned_object_snapshot
|
|
17
|
+
from .paths import RunRef
|
|
18
|
+
from .qa_commands import (
|
|
19
|
+
QA_COMMAND_EXECUTING_TASK_TYPES, QA_SOURCE_DIGEST_PATTERN, qa_relative_path_valid,
|
|
20
|
+
)
|
|
21
|
+
from .qa_procedures import content_digest, existing_qa_file, safe_qa_path
|
|
22
|
+
from .verification_input_ref import VerificationInputReference
|
|
23
|
+
from .verification_conformance import capture_generation_conformance
|
|
24
|
+
from .verification_inputs import publish_verification_snapshot, read_verification_inputs
|
|
25
|
+
from .verification_target import read_verification_head
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class FrozenVerificationSource(TypedDict):
|
|
29
|
+
trackedPaths: list[str]
|
|
30
|
+
generatedRoots: list[str]
|
|
31
|
+
inputPaths: list[str]
|
|
32
|
+
protectedFiles: dict[str, str]
|
|
33
|
+
generatedFiles: dict[str, str]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class _OptionalGenerationConformance(TypedDict, total=False):
|
|
37
|
+
conformanceStages: list[int]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class VerificationGenerationRecord(_OptionalGenerationConformance):
|
|
41
|
+
schemaVersion: Literal["1.0"]
|
|
42
|
+
kind: Literal["verification-generation"]
|
|
43
|
+
generation: int
|
|
44
|
+
taskType: str
|
|
45
|
+
runManifestPath: str
|
|
46
|
+
verificationInputsPath: str
|
|
47
|
+
verificationInputsDigest: str
|
|
48
|
+
head: str
|
|
49
|
+
sourceRoot: str
|
|
50
|
+
source: FrozenVerificationSource
|
|
51
|
+
artifactInputs: dict[str, str]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
_MAX_GENERATION_PATH_LENGTH = 4096
|
|
55
|
+
_DIGEST = {"type": "string", "pattern": f"^{QA_SOURCE_DIGEST_PATTERN.pattern}$"}
|
|
56
|
+
_PATH = {"type": "string", "minLength": 1, "maxLength": _MAX_GENERATION_PATH_LENGTH}
|
|
57
|
+
_PATHS = {"type": "array", "uniqueItems": True, "items": _PATH}
|
|
58
|
+
_FILES = {"type": "object", "additionalProperties": _DIGEST}
|
|
59
|
+
_SOURCE = {
|
|
60
|
+
"type": "object", "additionalProperties": False,
|
|
61
|
+
"required": ["trackedPaths", "generatedRoots", "inputPaths",
|
|
62
|
+
"protectedFiles", "generatedFiles"],
|
|
63
|
+
"properties": {
|
|
64
|
+
"trackedPaths": _PATHS, "generatedRoots": _PATHS, "inputPaths": _PATHS,
|
|
65
|
+
"protectedFiles": _FILES, "generatedFiles": _FILES,
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
_SCHEMA = {
|
|
69
|
+
"type": "object", "additionalProperties": False,
|
|
70
|
+
"required": list(VerificationGenerationRecord.__required_keys__),
|
|
71
|
+
"properties": {
|
|
72
|
+
"schemaVersion": {"const": "1.0"},
|
|
73
|
+
"kind": {"const": "verification-generation"},
|
|
74
|
+
"generation": {"type": "integer", "minimum": 1},
|
|
75
|
+
"taskType": {"enum": list(QA_COMMAND_EXECUTING_TASK_TYPES)},
|
|
76
|
+
"runManifestPath": _PATH, "verificationInputsPath": _PATH,
|
|
77
|
+
"verificationInputsDigest": _DIGEST,
|
|
78
|
+
"head": {"type": "string", "pattern": "^[0-9a-f]{40}([0-9a-f]{24})?$"},
|
|
79
|
+
"sourceRoot": _PATH, "source": _SOURCE, "artifactInputs": _FILES,
|
|
80
|
+
"conformanceStages": {"type": "array",
|
|
81
|
+
"items": {"type": "integer", "minimum": 1}},
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
_ARTIFACT = "verification generation"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _generation_errors(payload: dict[str, Any]) -> list[str]:
|
|
88
|
+
stages = payload.get("conformanceStages", [])
|
|
89
|
+
if any(left >= right for left, right in pairwise(stages)):
|
|
90
|
+
return ["generation conformance stages must be strictly increasing"]
|
|
91
|
+
if not Path(payload["sourceRoot"]).is_absolute():
|
|
92
|
+
return ["generation source root must be absolute"]
|
|
93
|
+
source = payload["source"]
|
|
94
|
+
declarations = [*source["generatedRoots"], *source["inputPaths"],
|
|
95
|
+
*payload["artifactInputs"], payload["runManifestPath"],
|
|
96
|
+
payload["verificationInputsPath"]]
|
|
97
|
+
if any(not qa_relative_path_valid(path) for path in declarations):
|
|
98
|
+
return ["generation declarations require safe relative POSIX paths"]
|
|
99
|
+
for field in ("runManifestPath", "verificationInputsPath"):
|
|
100
|
+
if PurePosixPath(payload[field]).parts[0] != OKSTRA_DIR_NAME:
|
|
101
|
+
return ["generation references must remain in project artifacts"]
|
|
102
|
+
protected, generated = source["protectedFiles"], source["generatedFiles"]
|
|
103
|
+
paths = {*source["trackedPaths"], *protected, *generated, *declarations}
|
|
104
|
+
for relative in paths:
|
|
105
|
+
if len(relative) > _MAX_GENERATION_PATH_LENGTH:
|
|
106
|
+
return ["generation source path is too long"]
|
|
107
|
+
path = PurePosixPath(relative)
|
|
108
|
+
if (not path.parts or path.is_absolute() or ".." in path.parts
|
|
109
|
+
or path.as_posix() != relative):
|
|
110
|
+
return ["generation source paths must be canonical and relative"]
|
|
111
|
+
if not set(source["inputPaths"]).issubset(protected):
|
|
112
|
+
return ["generation declared inputs must remain protected"]
|
|
113
|
+
roots = frozenset(source["generatedRoots"])
|
|
114
|
+
required = frozenset(source["trackedPaths"]) | frozenset(source["inputPaths"])
|
|
115
|
+
if any(is_generated_verification_path(path, roots, required) for path in protected):
|
|
116
|
+
return ["generation protected path conflicts with classification"]
|
|
117
|
+
if any(not is_generated_verification_path(path, roots, required)
|
|
118
|
+
for path in generated):
|
|
119
|
+
return ["generation output path conflicts with classification"]
|
|
120
|
+
return []
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _capture_generation_source(
|
|
124
|
+
project: Path, source_root: Path, *, source_inputs: frozenset[str],
|
|
125
|
+
generated_roots: frozenset[str], artifact_inputs: frozenset[str],
|
|
126
|
+
) -> tuple[VerificationSourceSnapshot, dict[str, str]]:
|
|
127
|
+
files = {existing_qa_file(project, path) for path in artifact_inputs}
|
|
128
|
+
if source_root == project:
|
|
129
|
+
source_inputs |= frozenset(
|
|
130
|
+
path.relative_to(project).as_posix() for path in files
|
|
131
|
+
)
|
|
132
|
+
snapshot = capture_verification_source(
|
|
133
|
+
source_root, generated_roots=generated_roots, input_paths=source_inputs,
|
|
134
|
+
)
|
|
135
|
+
artifacts = {}
|
|
136
|
+
for path in files:
|
|
137
|
+
relative = path.relative_to(project).as_posix()
|
|
138
|
+
artifacts[relative] = (
|
|
139
|
+
snapshot.protected_files[relative] if source_root == project
|
|
140
|
+
else content_digest(path.read_bytes())
|
|
141
|
+
)
|
|
142
|
+
return snapshot, artifacts
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _capture_generation(
|
|
146
|
+
project: Path, ref: RunRef, reference: VerificationInputReference, *,
|
|
147
|
+
generation: int, expected_head: str, source_inputs: frozenset[str],
|
|
148
|
+
generated_roots: frozenset[str], artifact_inputs: frozenset[str],
|
|
149
|
+
changed_artifact_paths: frozenset[str], conformance_baseline: Mapping[int, str],
|
|
150
|
+
) -> VerificationGenerationRecord:
|
|
151
|
+
inputs = read_verification_inputs(
|
|
152
|
+
safe_qa_path(project, reference.relative_path), reference.digest,
|
|
153
|
+
)
|
|
154
|
+
source_root = Path(inputs["sourceRoot"])
|
|
155
|
+
head = read_verification_head(source_root, expected_head)
|
|
156
|
+
conformance = None
|
|
157
|
+
if "approvedPlan" in inputs:
|
|
158
|
+
conformance = capture_generation_conformance(
|
|
159
|
+
project, ref, inputs["approvedPlan"], changed_artifact_paths,
|
|
160
|
+
conformance_baseline,
|
|
161
|
+
)
|
|
162
|
+
artifact_inputs |= conformance.artifact_paths
|
|
163
|
+
snapshot, artifacts = _capture_generation_source(
|
|
164
|
+
project, source_root, generated_roots=generated_roots,
|
|
165
|
+
source_inputs=source_inputs,
|
|
166
|
+
artifact_inputs=artifact_inputs,
|
|
167
|
+
)
|
|
168
|
+
if conformance is not None and conformance.manifest is not None:
|
|
169
|
+
relative, digest = conformance.manifest
|
|
170
|
+
if artifacts[relative] != digest:
|
|
171
|
+
raise ValueError("verification conformance manifest changed during capture")
|
|
172
|
+
read_verification_head(source_root, head)
|
|
173
|
+
return {
|
|
174
|
+
"schemaVersion": "1.0", "kind": "verification-generation",
|
|
175
|
+
"generation": generation, "taskType": ref.task_type,
|
|
176
|
+
"runManifestPath": ref.manifest.relative_to(project).as_posix(),
|
|
177
|
+
**reference.to_artifact_fields(), "head": head,
|
|
178
|
+
"sourceRoot": str(snapshot.root),
|
|
179
|
+
"source": {
|
|
180
|
+
"trackedPaths": sorted(snapshot.tracked_paths),
|
|
181
|
+
"generatedRoots": sorted(snapshot.generated_roots),
|
|
182
|
+
"inputPaths": sorted(snapshot.input_paths),
|
|
183
|
+
"protectedFiles": dict(snapshot.protected_files),
|
|
184
|
+
"generatedFiles": dict(snapshot.generated_files),
|
|
185
|
+
},
|
|
186
|
+
"artifactInputs": artifacts,
|
|
187
|
+
**({"conformanceStages": list(conformance.stages)}
|
|
188
|
+
if conformance is not None else {}),
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def prepare_verification_generation(
|
|
193
|
+
project: Path, ref: RunRef, reference: VerificationInputReference, *,
|
|
194
|
+
generation: int, expected_head: str, source_inputs: frozenset[str],
|
|
195
|
+
generated_roots: frozenset[str], artifact_inputs: frozenset[str],
|
|
196
|
+
changed_artifact_paths: frozenset[str], conformance_baseline: Mapping[int, str],
|
|
197
|
+
) -> tuple[Path, str]:
|
|
198
|
+
if ref.task_type not in QA_COMMAND_EXECUTING_TASK_TYPES:
|
|
199
|
+
raise ValueError("verification generations require a QA-executing phase")
|
|
200
|
+
reference_root = ref.project_root or project
|
|
201
|
+
project = project.resolve()
|
|
202
|
+
if reference_root.resolve() != project:
|
|
203
|
+
raise ValueError("verification generation project root mismatch")
|
|
204
|
+
relative_task = ref.task_root.absolute().relative_to(reference_root.absolute())
|
|
205
|
+
ref = replace(
|
|
206
|
+
ref, task_root_override=safe_qa_path(project, relative_task.as_posix()),
|
|
207
|
+
)
|
|
208
|
+
input_path = ref.verification_inputs.relative_to(project).as_posix()
|
|
209
|
+
if reference.relative_path != input_path:
|
|
210
|
+
raise ValueError("generation input reference belongs to a different run")
|
|
211
|
+
return publish_verification_snapshot(
|
|
212
|
+
project, ref.verification_generation(generation),
|
|
213
|
+
capture=partial(
|
|
214
|
+
_capture_generation, project, ref, reference, generation=generation,
|
|
215
|
+
expected_head=expected_head, source_inputs=source_inputs,
|
|
216
|
+
generated_roots=generated_roots, artifact_inputs=artifact_inputs,
|
|
217
|
+
changed_artifact_paths=changed_artifact_paths,
|
|
218
|
+
conformance_baseline=conformance_baseline,
|
|
219
|
+
),
|
|
220
|
+
artifact=_ARTIFACT, schema=_SCHEMA,
|
|
221
|
+
validate_cross_fields=_generation_errors, comparison_key=_generation_identity,
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def _generation_identity(payload: Mapping[str, Any]) -> dict[str, Any]:
|
|
226
|
+
return {**payload, "source": {**payload["source"], "generatedFiles": {}}}
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def read_verification_generation(
|
|
230
|
+
path: Path, expected_digest: str,
|
|
231
|
+
) -> VerificationGenerationRecord:
|
|
232
|
+
stored = load_owned_object_snapshot(
|
|
233
|
+
path, artifact=_ARTIFACT, schema=_SCHEMA,
|
|
234
|
+
validate_cross_fields=_generation_errors,
|
|
235
|
+
)
|
|
236
|
+
if content_digest(stored.raw_bytes) != expected_digest:
|
|
237
|
+
raise ValueError("verification generation digest mismatch")
|
|
238
|
+
return cast(VerificationGenerationRecord, stored.value)
|
|
@@ -12,6 +12,24 @@ class FrozenProcedure(TypedDict):
|
|
|
12
12
|
digest: str
|
|
13
13
|
|
|
14
14
|
|
|
15
|
+
QaSourceStatus = Literal[
|
|
16
|
+
"not-declared", "not-queried", "no-baseline", "unchanged", "changed",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class _OptionalQaSourceObservation(TypedDict, total=False):
|
|
21
|
+
observedSourceDigest: str
|
|
22
|
+
error: str
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class QaSourceObservation(_OptionalQaSourceObservation):
|
|
26
|
+
sourceStatus: QaSourceStatus
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class FrozenQaSourceObservation(QaSourceObservation):
|
|
30
|
+
entryDigest: str
|
|
31
|
+
|
|
32
|
+
|
|
15
33
|
class FrozenVerificationPlan(TypedDict):
|
|
16
34
|
path: str
|
|
17
35
|
digest: str
|
|
@@ -20,11 +38,12 @@ class FrozenVerificationPlan(TypedDict):
|
|
|
20
38
|
conformance: list[dict[str, Any]]
|
|
21
39
|
|
|
22
40
|
|
|
23
|
-
class
|
|
41
|
+
class _OptionalVerificationInputs(TypedDict, total=False):
|
|
24
42
|
approvedPlan: FrozenVerificationPlan
|
|
43
|
+
qaSourceObservations: dict[str, list[FrozenQaSourceObservation]]
|
|
25
44
|
|
|
26
45
|
|
|
27
|
-
class VerificationInputs(
|
|
46
|
+
class VerificationInputs(_OptionalVerificationInputs):
|
|
28
47
|
schemaVersion: Literal["1.0", "2.0"]
|
|
29
48
|
kind: Literal["verification-inputs"]
|
|
30
49
|
sourceRoot: str
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
"""Preparation must allow inspection scripts that implementation creates later."""
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
|
+
from functools import partial
|
|
4
5
|
from pathlib import Path
|
|
5
|
-
from typing import Any, Mapping, cast
|
|
6
|
+
from typing import Any, Callable, Mapping, cast
|
|
6
7
|
|
|
7
8
|
from okstra_project.dirs import OKSTRA_DIR_NAME, json_lock_path, registry_lock
|
|
8
9
|
|
|
9
10
|
from .json_boundary import load_owned_object_snapshot, write_owned_object_atomic
|
|
10
11
|
from .paths import RunRef
|
|
11
|
-
from .qa_commands import
|
|
12
|
+
from .qa_commands import (
|
|
13
|
+
QA_COMMAND_EXECUTING_TASK_TYPES, QA_SOURCE_DIGEST_PATTERN, validate_qa_commands,
|
|
14
|
+
)
|
|
12
15
|
from .qa_procedures import (
|
|
13
|
-
content_digest, existing_qa_file, load_qa_config,
|
|
16
|
+
canonical_json_digest, content_digest, existing_qa_file, load_qa_config,
|
|
17
|
+
new_qa_source_digest_reader, observe_qa_sources, procedure_root, qa_source_status,
|
|
14
18
|
read_validated_procedure, safe_qa_path, validate_procedure_sections,
|
|
15
19
|
)
|
|
16
20
|
|
|
@@ -25,7 +29,7 @@ from .verification_plan import (
|
|
|
25
29
|
INPUT_ARTIFACT = "verification inputs"
|
|
26
30
|
QA_INPUT_FIELDS = (
|
|
27
31
|
"label", "cmd", "id", "procedurePath", "sourcePaths", "resourceKeys",
|
|
28
|
-
"sourceBaselineDigest",
|
|
32
|
+
"sourceBaselineDigest", "language",
|
|
29
33
|
)
|
|
30
34
|
|
|
31
35
|
|
|
@@ -40,6 +44,7 @@ INPUT_SCHEMA = {
|
|
|
40
44
|
"qaCommands": {"type": "object"},
|
|
41
45
|
"procedures": {"type": "object"},
|
|
42
46
|
"approvedPlan": VERIFICATION_PLAN_SCHEMA,
|
|
47
|
+
"qaSourceObservations": {"type": "object"},
|
|
43
48
|
},
|
|
44
49
|
}
|
|
45
50
|
|
|
@@ -53,6 +58,41 @@ def _procedure_paths(commands: Mapping[str, list[dict[str, Any]]]) -> tuple[str,
|
|
|
53
58
|
))
|
|
54
59
|
|
|
55
60
|
|
|
61
|
+
def _verification_source_errors(
|
|
62
|
+
commands: dict[str, list[dict[str, Any]]], observations: dict[str, Any],
|
|
63
|
+
) -> list[str]:
|
|
64
|
+
if set(observations) != set(commands):
|
|
65
|
+
return ["source observation categories must match qaCommands"]
|
|
66
|
+
required = {"entryDigest", "sourceStatus"}
|
|
67
|
+
allowed = required | {"observedSourceDigest", "error"}
|
|
68
|
+
for category, entries in commands.items():
|
|
69
|
+
rows = observations[category]
|
|
70
|
+
if not isinstance(rows, list) or len(rows) != len(entries):
|
|
71
|
+
return ["source observation rows must match qaCommands"]
|
|
72
|
+
for entry, row in zip(entries, rows):
|
|
73
|
+
if (not isinstance(row, dict) or not required.issubset(row)
|
|
74
|
+
or set(row).difference(allowed)
|
|
75
|
+
or not all(isinstance(value, str) for value in row.values())):
|
|
76
|
+
return ["invalid source observation fields"]
|
|
77
|
+
if row["entryDigest"] != canonical_json_digest(entry):
|
|
78
|
+
return ["source observation declaration digest mismatch"]
|
|
79
|
+
observed = row.get("observedSourceDigest")
|
|
80
|
+
if observed is not None and not QA_SOURCE_DIGEST_PATTERN.fullmatch(
|
|
81
|
+
observed,
|
|
82
|
+
):
|
|
83
|
+
return ["invalid source observation digest"]
|
|
84
|
+
has_sources = bool(entry.get("sourcePaths"))
|
|
85
|
+
if observed is not None and (not has_sources or "error" in row):
|
|
86
|
+
return ["source observation digest conflicts with its declaration"]
|
|
87
|
+
if observed is None and has_sources and not row.get("error", "").strip():
|
|
88
|
+
return ["unavailable source observation requires an error"]
|
|
89
|
+
if not has_sources and "error" in row:
|
|
90
|
+
return ["undeclared source observation must not contain an error"]
|
|
91
|
+
if row["sourceStatus"] != qa_source_status(entry, observed):
|
|
92
|
+
return ["source observation status is inconsistent"]
|
|
93
|
+
return []
|
|
94
|
+
|
|
95
|
+
|
|
56
96
|
def _verification_input_errors(payload: dict[str, Any]) -> list[str]:
|
|
57
97
|
has_plan = "approvedPlan" in payload
|
|
58
98
|
if payload["schemaVersion"] == PLAN_INPUT_SCHEMA_VERSION and not has_plan:
|
|
@@ -91,6 +131,10 @@ def _verification_input_errors(payload: dict[str, Any]) -> list[str]:
|
|
|
91
131
|
continue
|
|
92
132
|
if content_digest(raw) != procedure["digest"]:
|
|
93
133
|
errors.append(f"frozen procedure digest mismatch: {relative}")
|
|
134
|
+
if "qaSourceObservations" in payload:
|
|
135
|
+
errors.extend(_verification_source_errors(
|
|
136
|
+
commands, payload["qaSourceObservations"],
|
|
137
|
+
))
|
|
94
138
|
return errors
|
|
95
139
|
|
|
96
140
|
|
|
@@ -98,6 +142,7 @@ def capture_verification_inputs(
|
|
|
98
142
|
project: Path, source: Path, *, approved_plan: Path | None = None,
|
|
99
143
|
) -> VerificationInputs:
|
|
100
144
|
declared = load_qa_config(project).get("qaCommands") or {}
|
|
145
|
+
read_digest = new_qa_source_digest_reader()
|
|
101
146
|
commands = {
|
|
102
147
|
category: [{key: entry[key] for key in QA_INPUT_FIELDS if key in entry}
|
|
103
148
|
for entry in entries]
|
|
@@ -117,6 +162,12 @@ def capture_verification_inputs(
|
|
|
117
162
|
"schemaVersion": INPUT_SCHEMA_VERSION, "kind": INPUT_KIND,
|
|
118
163
|
"sourceRoot": str(source.resolve()), "qaCommands": commands,
|
|
119
164
|
"procedures": procedures,
|
|
165
|
+
"qaSourceObservations": {
|
|
166
|
+
category: [{**observe_qa_sources(source, entry, read_digest),
|
|
167
|
+
"entryDigest": canonical_json_digest(entry)}
|
|
168
|
+
for entry in entries]
|
|
169
|
+
for category, entries in commands.items()
|
|
170
|
+
},
|
|
120
171
|
}
|
|
121
172
|
if approved_plan is not None:
|
|
122
173
|
payload["schemaVersion"] = PLAN_INPUT_SCHEMA_VERSION
|
|
@@ -134,29 +185,45 @@ def read_verification_inputs(path: Path, expected_digest: str) -> VerificationIn
|
|
|
134
185
|
return cast(VerificationInputs, snapshot.value)
|
|
135
186
|
|
|
136
187
|
|
|
137
|
-
def
|
|
138
|
-
project: Path,
|
|
188
|
+
def publish_verification_snapshot(
|
|
189
|
+
project: Path, destination: Path, *,
|
|
190
|
+
capture: Callable[[], Mapping[str, Any]], artifact: str,
|
|
191
|
+
schema: Mapping[str, Any],
|
|
192
|
+
validate_cross_fields: Callable[[dict[str, Any]], list[str]],
|
|
193
|
+
comparison_key: Callable[[Mapping[str, Any]], object],
|
|
139
194
|
) -> tuple[Path, str]:
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
path = safe_qa_path(project, artifact_relative.as_posix())
|
|
148
|
-
lock = safe_qa_path(project, json_lock_path(artifact_relative).as_posix())
|
|
149
|
-
payload = capture_verification_inputs(project, source, approved_plan=approved_plan)
|
|
195
|
+
project = project.absolute()
|
|
196
|
+
destination = destination.absolute()
|
|
197
|
+
if not destination.is_relative_to(project / OKSTRA_DIR_NAME):
|
|
198
|
+
raise ValueError(f"{artifact} must remain in project artifacts")
|
|
199
|
+
relative = destination.relative_to(project).as_posix()
|
|
200
|
+
safe_qa_path(project, relative)
|
|
201
|
+
lock = safe_qa_path(project, json_lock_path(Path(relative)).as_posix())
|
|
150
202
|
with registry_lock(lock):
|
|
203
|
+
path = safe_qa_path(project, relative)
|
|
204
|
+
payload = dict(capture())
|
|
151
205
|
if not path.exists():
|
|
152
206
|
write_owned_object_atomic(
|
|
153
|
-
path, payload, artifact=
|
|
154
|
-
validate_cross_fields=
|
|
207
|
+
path, payload, artifact=artifact, schema=schema,
|
|
208
|
+
validate_cross_fields=validate_cross_fields,
|
|
155
209
|
)
|
|
156
|
-
|
|
157
|
-
path, artifact=
|
|
158
|
-
validate_cross_fields=
|
|
210
|
+
stored = load_owned_object_snapshot(
|
|
211
|
+
path, artifact=artifact, schema=schema,
|
|
212
|
+
validate_cross_fields=validate_cross_fields,
|
|
159
213
|
)
|
|
160
|
-
if
|
|
161
|
-
raise ValueError("
|
|
162
|
-
return path, content_digest(
|
|
214
|
+
if comparison_key(stored.value) != comparison_key(payload):
|
|
215
|
+
raise ValueError(f"{artifact} is immutable")
|
|
216
|
+
return path, content_digest(stored.raw_bytes)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def prepare_verification_inputs(
|
|
220
|
+
project: Path, source: Path, ref: RunRef, *, approved_plan: Path | None = None,
|
|
221
|
+
) -> tuple[Path, str]:
|
|
222
|
+
if ref.task_type not in QA_COMMAND_EXECUTING_TASK_TYPES:
|
|
223
|
+
raise ValueError("verification inputs require a QA-executing phase")
|
|
224
|
+
payload = capture_verification_inputs(project, source, approved_plan=approved_plan)
|
|
225
|
+
return publish_verification_snapshot(
|
|
226
|
+
project, ref.verification_inputs, capture=partial(dict, payload),
|
|
227
|
+
artifact=INPUT_ARTIFACT, schema=INPUT_SCHEMA,
|
|
228
|
+
validate_cross_fields=_verification_input_errors, comparison_key=dict,
|
|
229
|
+
)
|
|
@@ -77,6 +77,18 @@ def read_verification_target(project_root: Path, relative: str) -> dict | None:
|
|
|
77
77
|
return parsed
|
|
78
78
|
|
|
79
79
|
|
|
80
|
+
def read_verification_head(worktree: Path, expected_head: str) -> str:
|
|
81
|
+
git = ["git", "-C", str(worktree), "rev-parse"]
|
|
82
|
+
head = subprocess.check_output([*git, "HEAD"], text=True).strip()
|
|
83
|
+
actual_root = subprocess.check_output([*git, "--show-toplevel"], text=True).strip()
|
|
84
|
+
if head != expected_head or Path(actual_root).resolve() != worktree:
|
|
85
|
+
raise ValueError(
|
|
86
|
+
f"verification target mismatch: expected HEAD {expected_head}, "
|
|
87
|
+
f"actual {head}, root {actual_root}"
|
|
88
|
+
)
|
|
89
|
+
return head
|
|
90
|
+
|
|
91
|
+
|
|
80
92
|
def capture_verification_target(
|
|
81
93
|
project_root: Path, manifest_path: Path, expected_head: str, command: str,
|
|
82
94
|
) -> dict:
|
|
@@ -106,11 +118,7 @@ def capture_verification_target(
|
|
|
106
118
|
defects = verification_command_defects(command)
|
|
107
119
|
if defects:
|
|
108
120
|
raise ValueError("; ".join(defects))
|
|
109
|
-
|
|
110
|
-
head = subprocess.check_output([*git, "HEAD"], text=True).strip()
|
|
111
|
-
actual_root = subprocess.check_output([*git, "--show-toplevel"], text=True).strip()
|
|
112
|
-
if head != expected_head or Path(actual_root).resolve() != worktree:
|
|
113
|
-
raise ValueError(f"verification target mismatch: expected HEAD {expected_head}, actual {head}, root {actual_root}")
|
|
121
|
+
head = read_verification_head(worktree, expected_head)
|
|
114
122
|
files = source_content_snapshot(worktree, frozenset({".okstra"}))
|
|
115
123
|
digest = hashlib.sha256(json.dumps(files, sort_keys=True).encode()).hexdigest()
|
|
116
124
|
result = {
|