tempergraph 0.7.1__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.
- tempergraph/__init__.py +8 -0
- tempergraph/__main__.py +5 -0
- tempergraph/api.py +428 -0
- tempergraph/audit/__init__.py +305 -0
- tempergraph/audit/catalog.py +342 -0
- tempergraph/audit/definition.py +387 -0
- tempergraph/audit/history.py +414 -0
- tempergraph/audit/history_rules.py +268 -0
- tempergraph/audit/history_rules_more.py +244 -0
- tempergraph/audit/host.py +270 -0
- tempergraph/audit/owned.py +96 -0
- tempergraph/audit/prompts.py +89 -0
- tempergraph/audit/report.py +248 -0
- tempergraph/audit/revisit.py +220 -0
- tempergraph/audit/surface.py +224 -0
- tempergraph/audit/text_health.py +176 -0
- tempergraph/audit/tools.py +391 -0
- tempergraph/author/__init__.py +2 -0
- tempergraph/author/blueprint.py +346 -0
- tempergraph/author/compare.py +122 -0
- tempergraph/author/criteria_lint.py +200 -0
- tempergraph/author/draw.py +112 -0
- tempergraph/author/inventory.py +210 -0
- tempergraph/author/literals.py +138 -0
- tempergraph/author/scaffold.py +568 -0
- tempergraph/author/session.py +439 -0
- tempergraph/author/trial.py +391 -0
- tempergraph/author/verify.py +353 -0
- tempergraph/builtin/__init__.py +1 -0
- tempergraph/builtin/upgrade.py +288 -0
- tempergraph/catalog.py +134 -0
- tempergraph/check_helpers.py +99 -0
- tempergraph/cli/__init__.py +1 -0
- tempergraph/cli/audit.py +190 -0
- tempergraph/cli/author.py +361 -0
- tempergraph/cli/improve.py +564 -0
- tempergraph/cli/improve_review.py +111 -0
- tempergraph/cli/install.py +35 -0
- tempergraph/cli/main.py +1261 -0
- tempergraph/cli/observe_cli.py +544 -0
- tempergraph/cli/outcome.py +77 -0
- tempergraph/cli/schedule_cli.py +1090 -0
- tempergraph/cli/upgrade.py +126 -0
- tempergraph/cli/workflows.py +96 -0
- tempergraph/compiler/__init__.py +6 -0
- tempergraph/compiler/graph.py +305 -0
- tempergraph/compiler/state.py +229 -0
- tempergraph/constants.py +72 -0
- tempergraph/contracts.py +1025 -0
- tempergraph/data/executor_compat.json +11 -0
- tempergraph/data/promotion.json +35 -0
- tempergraph/data/release.json +20 -0
- tempergraph/detach.py +65 -0
- tempergraph/docs.py +90 -0
- tempergraph/durability/__init__.py +2 -0
- tempergraph/durability/alias.py +66 -0
- tempergraph/durability/carry.py +591 -0
- tempergraph/durability/checkpoint.py +179 -0
- tempergraph/durability/control.py +109 -0
- tempergraph/durability/engine_file.py +301 -0
- tempergraph/durability/lock.py +138 -0
- tempergraph/durability/status.py +390 -0
- tempergraph/engine_identity.py +42 -0
- tempergraph/executor_compat.py +56 -0
- tempergraph/executors/__init__.py +4 -0
- tempergraph/executors/binding.py +91 -0
- tempergraph/executors/capabilities.py +95 -0
- tempergraph/executors/claude.py +603 -0
- tempergraph/executors/launcher.py +394 -0
- tempergraph/executors/mcpconfig.py +156 -0
- tempergraph/executors/mcpproxy.py +216 -0
- tempergraph/executors/preflight.py +196 -0
- tempergraph/executors/registry.py +71 -0
- tempergraph/executors/scripted.py +18 -0
- tempergraph/executors/session.py +107 -0
- tempergraph/executors/standins.py +118 -0
- tempergraph/executors/summary.py +110 -0
- tempergraph/executors/viewcatalog.py +27 -0
- tempergraph/git.py +403 -0
- tempergraph/identity.py +65 -0
- tempergraph/improve/__init__.py +5 -0
- tempergraph/improve/analysis.py +437 -0
- tempergraph/improve/artifact.py +477 -0
- tempergraph/improve/autonomy.py +192 -0
- tempergraph/improve/bindings.py +191 -0
- tempergraph/improve/calibration.py +1016 -0
- tempergraph/improve/causes.py +416 -0
- tempergraph/improve/child.py +651 -0
- tempergraph/improve/codehost.py +520 -0
- tempergraph/improve/digest.py +472 -0
- tempergraph/improve/escape.py +100 -0
- tempergraph/improve/filing.py +1047 -0
- tempergraph/improve/harvest.py +158 -0
- tempergraph/improve/issue_context.py +192 -0
- tempergraph/improve/lenses.py +204 -0
- tempergraph/improve/lessons.py +233 -0
- tempergraph/improve/loop_report.py +138 -0
- tempergraph/improve/loop_summary.py +85 -0
- tempergraph/improve/lost.py +119 -0
- tempergraph/improve/measure.py +121 -0
- tempergraph/improve/params.py +98 -0
- tempergraph/improve/pause_facts.py +134 -0
- tempergraph/improve/pr_later.py +186 -0
- tempergraph/improve/prebinding.py +130 -0
- tempergraph/improve/promotion.py +413 -0
- tempergraph/improve/proposals.py +934 -0
- tempergraph/improve/record.py +322 -0
- tempergraph/improve/release.py +89 -0
- tempergraph/improve/reliability.py +457 -0
- tempergraph/improve/repeat.py +115 -0
- tempergraph/improve/review.py +910 -0
- tempergraph/improve/suites.py +586 -0
- tempergraph/improve/trials.py +525 -0
- tempergraph/install/__init__.py +11 -0
- tempergraph/install/bootstrap.py +133 -0
- tempergraph/install/environment.py +173 -0
- tempergraph/install/launch.py +37 -0
- tempergraph/install/python.py +53 -0
- tempergraph/install/reconcile.py +52 -0
- tempergraph/install/selfcheck.py +29 -0
- tempergraph/install/shim.py +81 -0
- tempergraph/install/update.py +400 -0
- tempergraph/model/__init__.py +0 -0
- tempergraph/model/diagram.py +185 -0
- tempergraph/model/flow.py +324 -0
- tempergraph/model/prompt_lint.py +203 -0
- tempergraph/model/retire.py +52 -0
- tempergraph/model/subworkflow.py +274 -0
- tempergraph/model/text.py +67 -0
- tempergraph/model/validate.py +1158 -0
- tempergraph/observe/__init__.py +1 -0
- tempergraph/observe/attention.py +196 -0
- tempergraph/observe/detail.py +773 -0
- tempergraph/observe/forget.py +138 -0
- tempergraph/observe/hooks.py +272 -0
- tempergraph/observe/labels.py +95 -0
- tempergraph/observe/overlay.py +46 -0
- tempergraph/observe/report.py +402 -0
- tempergraph/observe/risk_report.py +110 -0
- tempergraph/observe/rows.py +444 -0
- tempergraph/observe/sinks.py +793 -0
- tempergraph/observe/supervision_cost.py +797 -0
- tempergraph/observe/supervision_report.py +295 -0
- tempergraph/observe/switch_report.py +140 -0
- tempergraph/package/__init__.py +2 -0
- tempergraph/package/change_report.py +116 -0
- tempergraph/package/changelog.py +263 -0
- tempergraph/package/docs_check.py +115 -0
- tempergraph/package/importer.py +90 -0
- tempergraph/package/inventory.py +111 -0
- tempergraph/package/loader.py +250 -0
- tempergraph/package/manifest.py +256 -0
- tempergraph/package/readiness.py +124 -0
- tempergraph/package/registry.py +383 -0
- tempergraph/package/rules.py +128 -0
- tempergraph/package/scan.py +65 -0
- tempergraph/package/selftest.py +348 -0
- tempergraph/package/stamp.py +213 -0
- tempergraph/package/transforms.py +481 -0
- tempergraph/package/upgrade.py +625 -0
- tempergraph/provenance.py +183 -0
- tempergraph/py.typed +0 -0
- tempergraph/release.py +17 -0
- tempergraph/render/__init__.py +0 -0
- tempergraph/render/output.py +72 -0
- tempergraph/render/prompt.py +166 -0
- tempergraph/render/template.py +86 -0
- tempergraph/run/__init__.py +2 -0
- tempergraph/run/asking.py +233 -0
- tempergraph/run/audit.py +63 -0
- tempergraph/run/check_worker.py +167 -0
- tempergraph/run/checks.py +517 -0
- tempergraph/run/commands.py +210 -0
- tempergraph/run/complexity.py +268 -0
- tempergraph/run/contest.py +76 -0
- tempergraph/run/council.py +368 -0
- tempergraph/run/council_run.py +527 -0
- tempergraph/run/events.py +279 -0
- tempergraph/run/finalize.py +132 -0
- tempergraph/run/gate.py +747 -0
- tempergraph/run/guard.py +89 -0
- tempergraph/run/judging.py +357 -0
- tempergraph/run/ladder.py +230 -0
- tempergraph/run/log.py +600 -0
- tempergraph/run/mapping.py +183 -0
- tempergraph/run/nodes.py +2304 -0
- tempergraph/run/outcome.py +255 -0
- tempergraph/run/outcome_record.py +292 -0
- tempergraph/run/outcome_trust.py +99 -0
- tempergraph/run/rerun.py +351 -0
- tempergraph/run/reserve.py +85 -0
- tempergraph/run/resources.py +76 -0
- tempergraph/run/risk.py +231 -0
- tempergraph/run/runner.py +1579 -0
- tempergraph/run/scriptcache.py +178 -0
- tempergraph/run/selfcheck.py +105 -0
- tempergraph/run/session_record.py +72 -0
- tempergraph/run/subrun.py +278 -0
- tempergraph/run/supervision.py +125 -0
- tempergraph/run/tool_access.py +101 -0
- tempergraph/schedule/__init__.py +25 -0
- tempergraph/schedule/credentials.py +167 -0
- tempergraph/schedule/echo.py +169 -0
- tempergraph/schedule/exact.py +275 -0
- tempergraph/schedule/export.py +164 -0
- tempergraph/schedule/launch.py +89 -0
- tempergraph/schedule/ledger.py +133 -0
- tempergraph/schedule/loop.py +176 -0
- tempergraph/schedule/model.py +440 -0
- tempergraph/schedule/policies.py +414 -0
- tempergraph/schedule/store.py +150 -0
- tempergraph/schedule/tick.py +377 -0
- tempergraph/schedule/token.py +81 -0
- tempergraph/schedule/triggers.py +210 -0
- tempergraph/schedule/words.py +423 -0
- tempergraph/security/__init__.py +0 -0
- tempergraph/security/launch.py +25 -0
- tempergraph/security/scrub.py +58 -0
- tempergraph/settings.py +950 -0
- tempergraph/store/__init__.py +0 -0
- tempergraph/store/codelog.py +73 -0
- tempergraph/store/layout.py +198 -0
- tempergraph/store/logs.py +325 -0
- tempergraph/store/manifest.py +99 -0
- tempergraph/store/migrate.py +188 -0
- tempergraph/workspace.py +874 -0
- tempergraph-0.7.1.dist-info/METADATA +70 -0
- tempergraph-0.7.1.dist-info/RECORD +232 -0
- tempergraph-0.7.1.dist-info/WHEEL +5 -0
- tempergraph-0.7.1.dist-info/entry_points.txt +5 -0
- tempergraph-0.7.1.dist-info/top_level.txt +2 -0
- tempergraph_pytest_plugin.py +64 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
"""The generated tests of a scaffolded package (SCF-B14, SCF-B15, SCF-B16, SCF-B17), as engine functions: the package's own
|
|
2
|
+
`tests/test_<module>_generated.py` calls them, and `author verify` rung 4 calls them in process, so both
|
|
3
|
+
give the same answer. Each returns the problems found; an empty list passes. Model-free."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import shutil
|
|
9
|
+
from collections.abc import Callable
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from tempergraph.contracts import WorkflowSpec
|
|
14
|
+
|
|
15
|
+
GIT_FILE = "git.json"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _spec(root: Path) -> WorkflowSpec:
|
|
19
|
+
from tempergraph.package.loader import load_package
|
|
20
|
+
|
|
21
|
+
return load_package(root).spec
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def diagram_current(root: Path, tmp: Path) -> list[str]:
|
|
25
|
+
from tempergraph.model.diagram import diagram_model
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
have = json.loads((root / "diagram" / "model.json").read_text(encoding="utf-8"))
|
|
29
|
+
except (OSError, ValueError):
|
|
30
|
+
return ["diagram/model.json is missing; run `tempergraph scaffold <session> --out <dir> --update` or "
|
|
31
|
+
"`tempergraph upgrade-check <workflow> --stamp`"]
|
|
32
|
+
if not (root / "diagram" / "workflow.md").is_file():
|
|
33
|
+
return ["diagram/workflow.md is missing; regenerate it with `tempergraph upgrade-check <workflow> --stamp`"]
|
|
34
|
+
want = diagram_model(_spec(root))["digest"]
|
|
35
|
+
return [] if have.get("digest") == want else [
|
|
36
|
+
"diagram/model.json does not match the spec (digest); regenerate it with "
|
|
37
|
+
"`tempergraph upgrade-check <workflow> --stamp`"]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def summaries(root: Path, tmp: Path) -> list[str]:
|
|
41
|
+
out = []
|
|
42
|
+
spec = _spec(root)
|
|
43
|
+
for name in spec.order:
|
|
44
|
+
u = spec.units[name]
|
|
45
|
+
text = (u.step.summary if u.step else u.script.summary if u.script else "x") or ""
|
|
46
|
+
if u.kind in ("step", "script") and not (0 < len(text) <= 60):
|
|
47
|
+
out.append(f"{name}: a summary of 1 to 60 characters is required (has {len(text)})")
|
|
48
|
+
return out
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def examples_resolve(root: Path, tmp: Path) -> list[str]:
|
|
52
|
+
spec = _spec(root)
|
|
53
|
+
decl = spec.input
|
|
54
|
+
out = []
|
|
55
|
+
for ex in decl.examples:
|
|
56
|
+
if not str(ex).strip():
|
|
57
|
+
out.append("an empty start example")
|
|
58
|
+
elif decl.kind == "resolver" and decl.resolver is not None:
|
|
59
|
+
got = decl.resolver.resolve()(str(ex))
|
|
60
|
+
if getattr(got, "status", "error") == "error":
|
|
61
|
+
out.append(f"start example {ex!r} does not resolve: {getattr(got, 'message', '')}")
|
|
62
|
+
return out
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _fixture_dirs(root: Path, unit: str) -> dict[str, list[Path]]:
|
|
66
|
+
"""A fixture is one file, or a folder of files when the check reads more than one artifact."""
|
|
67
|
+
base = root / "evals" / "checks" / unit
|
|
68
|
+
return {w: sorted(p for p in (base / w).glob("*") if p.is_file() or p.is_dir()) for w in ("must-pass", "must-fail")}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _files(fixture: Path) -> list[Path]:
|
|
72
|
+
if not fixture.is_dir():
|
|
73
|
+
return [fixture]
|
|
74
|
+
return sorted(p for p in fixture.rglob("*") if p.is_file() and p != fixture / GIT_FILE) # EVS-B9: git facts, not a file
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _git_facts(fixture: Path) -> Any:
|
|
78
|
+
"""The fixture's git facts from `git.json` at the top of its folder (EVS-B9); the default facts without one."""
|
|
79
|
+
import dataclasses
|
|
80
|
+
|
|
81
|
+
from tempergraph.run.checks import GitFacts
|
|
82
|
+
|
|
83
|
+
path = fixture / GIT_FILE
|
|
84
|
+
if not fixture.is_dir() or not path.is_file():
|
|
85
|
+
return GitFacts()
|
|
86
|
+
try:
|
|
87
|
+
fields = json.loads(path.read_text(encoding="utf-8"))
|
|
88
|
+
except (OSError, ValueError) as exc:
|
|
89
|
+
raise ValueError(f"{GIT_FILE} of fixture {fixture.name} is not readable JSON: {exc}") from exc
|
|
90
|
+
known = {f.name for f in dataclasses.fields(GitFacts)}
|
|
91
|
+
if not isinstance(fields, dict) or set(fields) - known:
|
|
92
|
+
raise ValueError(f"{GIT_FILE} of fixture {fixture.name} must be a JSON object of git fact fields "
|
|
93
|
+
f"({', '.join(sorted(known))})")
|
|
94
|
+
for key in ("changed_paths", "commits_since_base"):
|
|
95
|
+
if key in fields:
|
|
96
|
+
fields[key] = tuple(fields[key])
|
|
97
|
+
try:
|
|
98
|
+
return GitFacts(**fields)
|
|
99
|
+
except TypeError as exc:
|
|
100
|
+
raise ValueError(f"{GIT_FILE} of fixture {fixture.name} is not valid: {exc}") from exc
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _produces(spec: WorkflowSpec, unit: str) -> dict[str, Any]:
|
|
104
|
+
u = spec.units[unit]
|
|
105
|
+
return dict(u.step.produces if u.step else u.script.produces if u.script else {})
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _artifacts(spec: WorkflowSpec, unit: str, files: list[Path], base: Path) -> dict[str, dict[str, str]]:
|
|
109
|
+
"""Each file whose stem is an artifact key, as the artifact of the unit producing it, the unit under test
|
|
110
|
+
first when two units produce the same key; the unit's own keys take the fixture's files when no stem matches
|
|
111
|
+
(a one-file fixture)."""
|
|
112
|
+
owner = {k: n for n in spec.order for k in _produces(spec, n)} | {k: unit for k in _produces(spec, unit)}
|
|
113
|
+
out: dict[str, dict[str, str]] = {}
|
|
114
|
+
for f in files:
|
|
115
|
+
if f.stem in owner:
|
|
116
|
+
out.setdefault(owner[f.stem], {})[f.stem] = f.relative_to(base).as_posix()
|
|
117
|
+
if not out.get(unit) and files:
|
|
118
|
+
out[unit] = {k: files[0].relative_to(base).as_posix() for k in _produces(spec, unit)}
|
|
119
|
+
return out
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def fixture_runs(root: Path, tmp: Path, spec: WorkflowSpec | None = None) -> list[dict[str, Any]]:
|
|
123
|
+
"""Every check fixture run with LF and with CRLF line endings (EVS-B9, EVS-B2, EVS-B10): `{unit, which, fixture, crlf,
|
|
124
|
+
result, named, evidence}`, where `named` says the findings name one of the check's criteria. A unit whose
|
|
125
|
+
check lacks a must-pass or a must-fail fixture gives one row with `missing`."""
|
|
126
|
+
from tempergraph.run.checks import CheckContext, run_check
|
|
127
|
+
|
|
128
|
+
spec = spec or _spec(root)
|
|
129
|
+
out: list[dict[str, Any]] = []
|
|
130
|
+
for name in spec.order:
|
|
131
|
+
u = spec.units[name]
|
|
132
|
+
if u.gate.check is None:
|
|
133
|
+
continue
|
|
134
|
+
dirs = _fixture_dirs(root, name)
|
|
135
|
+
ids = {c.id for c in u.gate.criteria if c.mechanical or c.verified_by == "check"}
|
|
136
|
+
if not dirs["must-pass"] or not dirs["must-fail"]:
|
|
137
|
+
out.append({"unit": name, "missing": [w for w in dirs if not dirs[w]]})
|
|
138
|
+
continue
|
|
139
|
+
for which, paths in dirs.items():
|
|
140
|
+
for p in paths:
|
|
141
|
+
base = p if p.is_dir() else p.parent
|
|
142
|
+
for crlf in (False, True):
|
|
143
|
+
work = tmp / f"{name}-{which}-{p.name}-{int(crlf)}"
|
|
144
|
+
copied = []
|
|
145
|
+
for f in _files(p):
|
|
146
|
+
data = f.read_bytes()
|
|
147
|
+
if crlf:
|
|
148
|
+
data = data.replace(b"\r\n", b"\n").replace(b"\n", b"\r\n")
|
|
149
|
+
target = work / f.relative_to(base)
|
|
150
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
151
|
+
target.write_bytes(data)
|
|
152
|
+
copied.append(target)
|
|
153
|
+
facts = _git_facts(p)
|
|
154
|
+
ctx = CheckContext(unit=name, workdir=work, request={}, git=facts,
|
|
155
|
+
changed_paths=tuple(facts.changed_paths),
|
|
156
|
+
artifacts=_artifacts(spec, name, copied, work),
|
|
157
|
+
allow=spec.allow_commands, out_dir=work / ".out")
|
|
158
|
+
res, _ = run_check(u.gate, ctx)
|
|
159
|
+
out.append({"unit": name, "which": which, "fixture": p.name, "crlf": crlf, "result": res.result,
|
|
160
|
+
"named": bool({f.criterion for f in res.findings} & ids),
|
|
161
|
+
"evidence": res.evidence[:120], "criteria": sorted(i for i in ids if i)})
|
|
162
|
+
return out
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def check_fixtures(root: Path, tmp: Path) -> list[str]:
|
|
166
|
+
"""Every check passes its must-pass and fails its must-fail fixtures, naming a criterion id; each fixture
|
|
167
|
+
also with CRLF line endings (EVS-B9, EVS-B2, EVS-B10)."""
|
|
168
|
+
out = []
|
|
169
|
+
for r in fixture_runs(root, tmp):
|
|
170
|
+
name = r["unit"]
|
|
171
|
+
if "missing" in r:
|
|
172
|
+
out.append(f"{name}: the check needs a must-pass and a must-fail fixture under evals/checks/{name}/")
|
|
173
|
+
continue
|
|
174
|
+
which = r["which"]
|
|
175
|
+
tag = f"{name} {which}/{r['fixture']}{' (CRLF)' if r['crlf'] else ''}"
|
|
176
|
+
if which == "must-pass" and r["result"] != "PASS":
|
|
177
|
+
out.append(f"{tag}: expected PASS, got {r['result']} ({r['evidence']})")
|
|
178
|
+
if which == "must-fail" and r["result"] != "FAIL":
|
|
179
|
+
out.append(f"{tag}: expected FAIL, got {r['result']}")
|
|
180
|
+
if not r["named"]:
|
|
181
|
+
out.append(f"{tag}: the check names none of its criteria {r['criteria']}")
|
|
182
|
+
return out
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _standin_files(root: Path, unit: str, produces: dict[str, Any], workdir: Path) -> dict[str, str]:
|
|
186
|
+
"""Write the unit's must-pass fixture files into the workspace; each produced key and its path or value."""
|
|
187
|
+
fixtures = _fixture_dirs(root, unit)["must-pass"]
|
|
188
|
+
first = fixtures[0] if fixtures else None
|
|
189
|
+
base = first if first is not None and first.is_dir() else (first.parent if first is not None else workdir)
|
|
190
|
+
# a fixture's `.tempergraph/` folder is the run's own record a check reads, not a step's output: the run wrote it
|
|
191
|
+
files = [f for f in (_files(first) if first is not None else []) if f.relative_to(base).parts[0] != ".tempergraph"]
|
|
192
|
+
by_stem = {f.stem: f for f in files}
|
|
193
|
+
out: dict[str, str] = {}
|
|
194
|
+
for key, kind in produces.items():
|
|
195
|
+
if kind == "file":
|
|
196
|
+
src = by_stem.get(key) or (files[0] if files else None)
|
|
197
|
+
rel = src.relative_to(base).as_posix() if src is not None else f"{key}.md"
|
|
198
|
+
target = workdir / rel
|
|
199
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
200
|
+
if src is not None:
|
|
201
|
+
shutil.copyfile(src, target)
|
|
202
|
+
else:
|
|
203
|
+
target.write_text(f"# {key}\n\nStand-in output.\n", encoding="utf-8")
|
|
204
|
+
out[key] = rel
|
|
205
|
+
else:
|
|
206
|
+
choices = getattr(kind, "choices", None)
|
|
207
|
+
out[key] = str(choices[0]) if choices else "stand-in"
|
|
208
|
+
for src in files: # what else the fixture holds beside the produced files: a test a check will open, or a
|
|
209
|
+
target = workdir / src.relative_to(base) # later version of an earlier unit's file the step edits
|
|
210
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
211
|
+
shutil.copyfile(src, target)
|
|
212
|
+
return out
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def standin_script(ctx: Any) -> dict[str, str]: # pragma: no cover - replaced per unit by `standin_run`
|
|
216
|
+
raise RuntimeError("stand-in script called outside a stand-in run")
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def standin_run(root: Path, tmp: Path) -> list[str]:
|
|
220
|
+
"""A scripted executor stands in for each step and judge and for the outcome judge, and a stand-in for each
|
|
221
|
+
script unit; the run reaches the finalizer (SCF-B14, SCF-B15, SCF-B16, SCF-B17). Step and script stand-ins write the unit's must-pass
|
|
222
|
+
fixtures as its files and give a value its first choice; an approval is answered `proceed`. Each session is
|
|
223
|
+
answered by the unit that asks, at most once, so a unit the routes skip on the stand-in path asks nothing."""
|
|
224
|
+
import dataclasses
|
|
225
|
+
|
|
226
|
+
from tempergraph import git
|
|
227
|
+
from tempergraph.constants import ExitCode
|
|
228
|
+
from tempergraph.contracts import CallableRef
|
|
229
|
+
from tempergraph.executors.scripted import answer, scripted_registry
|
|
230
|
+
from tempergraph.run.runner import RunSettings, resume, start
|
|
231
|
+
|
|
232
|
+
spec = _spec(root)
|
|
233
|
+
repo = tmp / "standin-repo"
|
|
234
|
+
repo.mkdir(parents=True, exist_ok=True)
|
|
235
|
+
git.git(["init", "-q", "-b", "main"], repo)
|
|
236
|
+
git.git(["-c", "user.email=standin@example.invalid", "-c", "user.name=standin", "commit", "-q",
|
|
237
|
+
"--allow-empty", "-m", "start"], repo)
|
|
238
|
+
executors = {(st.executor if (st := spec.units[n].step) is not None else None) or spec.default_executor
|
|
239
|
+
for n in spec.order if spec.units[n].kind == "step"}
|
|
240
|
+
if executors - {"claude"}:
|
|
241
|
+
return [f"stand-in run: executors {sorted(executors - {'claude'})} are not in release 1"]
|
|
242
|
+
|
|
243
|
+
def script_standin(unit: str, produces: dict[str, Any]) -> CallableRef:
|
|
244
|
+
def call(ctx: Any) -> dict[str, str]:
|
|
245
|
+
return _standin_files(root, unit, produces, Path(ctx.workdir))
|
|
246
|
+
return CallableRef(module=__name__, qualname="standin_script", func=call)
|
|
247
|
+
|
|
248
|
+
units = dict(spec.units)
|
|
249
|
+
for name in spec.order:
|
|
250
|
+
u = units[name]
|
|
251
|
+
if u.kind == "script" and u.script is not None:
|
|
252
|
+
sc = dataclasses.replace(u.script, run=None, call=script_standin(name, dict(u.script.produces)))
|
|
253
|
+
units[name] = dataclasses.replace(u, script=sc)
|
|
254
|
+
spec = dataclasses.replace(spec, units=units)
|
|
255
|
+
|
|
256
|
+
def step_reply(unit: str) -> Callable[[Any], Any]:
|
|
257
|
+
def reply(req: Any) -> Any:
|
|
258
|
+
got = _standin_files(root, unit, _produces(spec, unit), Path(req.workdir))
|
|
259
|
+
lines = [f"ARTIFACT {k}: {v}" for k, v in got.items()]
|
|
260
|
+
return answer("Stand-in.\n" + "\n".join(lines), session_id=f"s-{unit}")
|
|
261
|
+
return reply
|
|
262
|
+
|
|
263
|
+
def verdict(n: int, sid: str) -> Any:
|
|
264
|
+
rows = [{"n": i, "status": "MET", "evidence": "stand-in", "defect_in": None, "no_change": False}
|
|
265
|
+
for i in range(1, n + 1)]
|
|
266
|
+
return answer("Stand-in.\n```json\n" + json.dumps({"criteria": rows, "gap": False, "confidence": 0.9})
|
|
267
|
+
+ "\n```", tools=("Read",), session_id=sid)
|
|
268
|
+
|
|
269
|
+
step_by: dict[str, Any] = {}
|
|
270
|
+
judge_by: dict[str, Any] = {}
|
|
271
|
+
maps = {n for n in spec.order if spec.units[n].kind == "map" and spec.units[n].step is not None}
|
|
272
|
+
for name in spec.order:
|
|
273
|
+
u = spec.units[name]
|
|
274
|
+
if u.kind == "step" or name in maps:
|
|
275
|
+
step_by[name] = step_reply(name)
|
|
276
|
+
if u.gate.judge is not None:
|
|
277
|
+
judge_by[name] = verdict(len(u.gate.criteria), f"j-{name}") # the judge rows every criterion
|
|
278
|
+
if spec.outcome is not None and any(c.verified_by == "judge" for c in spec.outcome.final):
|
|
279
|
+
# the outcome judge rows every graded criterion, the checked ones too (OUT-B15, OUT-B16, OUT-B17)
|
|
280
|
+
judge_by["outcome"] = verdict(sum(1 for c in spec.outcome.final if c.verified_by in ("judge", "check")),
|
|
281
|
+
"j-outcome")
|
|
282
|
+
|
|
283
|
+
def by_unit(table: dict[str, Any], what: str) -> Callable[[Any], Any]:
|
|
284
|
+
"""A reply for the unit named by the session key (`<unit>.<attempt>.<kind>`), each one used once: a
|
|
285
|
+
second session of a unit, or one of a unit with no reply, ends the run as a dry queue would. A map unit has
|
|
286
|
+
one session for each of its items, so its reply stays for all of them."""
|
|
287
|
+
def reply(req: Any) -> Any:
|
|
288
|
+
unit = str(req.session_key).split(".", 1)[0]
|
|
289
|
+
got = table.get(unit) if unit in maps else table.pop(unit, None)
|
|
290
|
+
if got is None:
|
|
291
|
+
raise AssertionError(f"no scripted {what} reply left for {req.session_key}")
|
|
292
|
+
return got(req) if callable(got) else got
|
|
293
|
+
return reply
|
|
294
|
+
|
|
295
|
+
items = 20 * len(maps) # the most a map runs (MAP-B7): the queue holds a reply for each item's session
|
|
296
|
+
r = scripted_registry("claude", [by_unit(step_by, "step")] * (len(step_by) + items),
|
|
297
|
+
[by_unit(judge_by, "judge")] * (len(judge_by) + items))
|
|
298
|
+
quiet = RunSettings(sleep=lambda s: None)
|
|
299
|
+
try:
|
|
300
|
+
got = start(spec, "STANDIN-1", {"request": "stand-in"}, repo, r, quiet)
|
|
301
|
+
for _ in range(len(spec.order) + 1): # each approval once, then the outcome's sign-off
|
|
302
|
+
if got.exit_code is not ExitCode.PAUSED or (got.payload or {}).get("kind") != "approval":
|
|
303
|
+
break
|
|
304
|
+
got = resume(spec, "STANDIN-1", repo, r, decision="proceed", settings=quiet)
|
|
305
|
+
except AssertionError as exc: # a stand-in queue ran dry: the run asked for more sessions than scripted
|
|
306
|
+
return [f"stand-in run: {exc}"]
|
|
307
|
+
if got.exit_code is not ExitCode.FINISHED:
|
|
308
|
+
return [f"stand-in run ended {got.exit_code.name}: {got.reason} {got.message}".strip()]
|
|
309
|
+
return []
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def compatibility(root: Path, tmp: Path) -> list[str]:
|
|
313
|
+
from tempergraph.executors.capabilities import DECLARED
|
|
314
|
+
from tempergraph.model.validate import validate
|
|
315
|
+
from tempergraph.package.changelog import compatibility as compat
|
|
316
|
+
from tempergraph.package.loader import PackageNotLoaded, load_package
|
|
317
|
+
from tempergraph.package.stamp import read_stamp
|
|
318
|
+
|
|
319
|
+
try:
|
|
320
|
+
lp = load_package(root)
|
|
321
|
+
except PackageNotLoaded as exc:
|
|
322
|
+
return [str(exc)]
|
|
323
|
+
errors = [f"{f.code}: {f.message}" for f in validate(lp.spec, {"claude": DECLARED["claude"]})
|
|
324
|
+
if f.severity == "error"]
|
|
325
|
+
state = compat(lp.spec, root, read_stamp(root), finding_codes=set())["state"]
|
|
326
|
+
if state not in ("current", "unstamped", "compatible"):
|
|
327
|
+
errors.append(f"compatibility state {state}")
|
|
328
|
+
return errors
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def docs(root: Path, tmp: Path) -> list[str]:
|
|
332
|
+
from tempergraph.package.docs_check import docs_check
|
|
333
|
+
|
|
334
|
+
return [f.message for f in docs_check(_spec(root), root, "stable")]
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
CHECKS: dict[str, Callable[[Path, Path], list[str]]] = {
|
|
338
|
+
"diagram_current": diagram_current, "summaries": summaries, "examples_resolve": examples_resolve,
|
|
339
|
+
"check_fixtures": check_fixtures, "standin_run": standin_run, "compatibility": compatibility, "docs": docs,
|
|
340
|
+
}
|
|
341
|
+
NAMES = tuple(CHECKS)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def run(name: str, root: Path, tmp: Path) -> list[str]:
|
|
345
|
+
try:
|
|
346
|
+
return CHECKS[name](root, tmp)
|
|
347
|
+
except Exception as exc: # noqa: BLE001 - a broken package is a problem, not a crash
|
|
348
|
+
return [f"{name}: {type(exc).__name__}: {exc}"]
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"""`upgrade --check [--stamp]` and `upgrade-check [--stamp]` in release 1 (WUP-B10, WUP-B11, WUP-B12, WUP-B13, WUP-B19; VER-B16).
|
|
2
|
+
|
|
3
|
+
Release 1 builds the check and the stamp only; the transforms, the upgrade workflow, the branch and the pull
|
|
4
|
+
request are release 3 (ADR `first-release-is-simple-trusted-workflows-on-one-machine`). `--check` runs WUP phases 1 to 3 (locate, baseline, plan) read-only.
|
|
5
|
+
`--stamp` on a clean check runs the model-free verification V1 to V7 and writes `stamp.json` in the
|
|
6
|
+
package. V4 runs the audit's definition layer and fails on a finding at warning or above that the last
|
|
7
|
+
stamp's `audit` list lacks (a first stamp records the list). V6 (model-free suites) reports `skipped` until
|
|
8
|
+
eval suites (release 2) exist. V7 regenerates `diagram/` with the stamp, because the diagram is generated
|
|
9
|
+
and never typed (PKG-B11, PKG-B12).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
from collections.abc import Mapping, Sequence
|
|
16
|
+
from dataclasses import dataclass, field
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from tempergraph.constants import ENGINE_VERSION, WORKFLOW_API
|
|
21
|
+
from tempergraph.contracts import READ_ONLY_CAPABILITIES, Capabilities, WorkflowSpec
|
|
22
|
+
from tempergraph.docs import write_json
|
|
23
|
+
from tempergraph.executors.capabilities import DECLARED
|
|
24
|
+
from tempergraph.model.diagram import diagram_model, to_mermaid
|
|
25
|
+
from tempergraph.model.validate import Finding, validate
|
|
26
|
+
from tempergraph.package.changelog import compatibility
|
|
27
|
+
from tempergraph.package.loader import LoadedPackage, PackageNotLoaded, load_package
|
|
28
|
+
from tempergraph.package.registry import plugin_cache
|
|
29
|
+
from tempergraph.store.layout import now_iso
|
|
30
|
+
|
|
31
|
+
STAMP = "stamp.json"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def read_stamp(root: Path) -> dict[str, Any] | None:
|
|
35
|
+
try:
|
|
36
|
+
doc = json.loads((root / STAMP).read_text(encoding="utf-8"))
|
|
37
|
+
except (OSError, ValueError):
|
|
38
|
+
return None
|
|
39
|
+
return doc if isinstance(doc, dict) and doc.get("engine_version") else None
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _audit_keys(lp: Any, caps: Mapping[str, Capabilities]) -> list[str]:
|
|
43
|
+
"""V4 (WUP-B19): the definition layer's findings at warning or above, by rule and location. The host
|
|
44
|
+
layer is left out: it describes this machine, not the package."""
|
|
45
|
+
from tempergraph.audit import AuditContext, audit
|
|
46
|
+
|
|
47
|
+
rep = audit(lp.spec, {"definition"}, AuditContext(target=lp.root, caps=caps), manifest=lp.manifests.engine)
|
|
48
|
+
return sorted({f"{f.rule}|{f.unit or ''}|{f.item or ''}|{f.location.get('file', '')}" for f in rep.findings
|
|
49
|
+
if f.ignored is None and f.severity in ("error", "warning")})
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def tool_set(spec: WorkflowSpec) -> dict[str, list[str]]:
|
|
53
|
+
"""Per executor, the tool names the steps and judges were checked against (VER-B16 `tool_set`)."""
|
|
54
|
+
out: dict[str, set[str]] = {}
|
|
55
|
+
for u in spec.units.values():
|
|
56
|
+
ex = (u.step.executor if u.step else None) or spec.default_executor
|
|
57
|
+
caps = DECLARED.get(ex)
|
|
58
|
+
if caps is None:
|
|
59
|
+
continue
|
|
60
|
+
names = out.setdefault(ex, set())
|
|
61
|
+
tools = list(u.step.tools) if u.step else []
|
|
62
|
+
if u.gate.judge is not None:
|
|
63
|
+
tools += sorted(READ_ONLY_CAPABILITIES & {"read", "search", "list"})
|
|
64
|
+
for t in tools:
|
|
65
|
+
key = "mcp:*" if t.startswith("mcp:") else "skill:*" if t.startswith("skill:") else t
|
|
66
|
+
names.update(n.replace("{server}", t[4:].split("/")[0]).replace("{tool}", t.split("/")[-1])
|
|
67
|
+
for n in caps.tool_map.get(key, ()))
|
|
68
|
+
return {k: sorted(v) for k, v in sorted(out.items())}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass(kw_only=True)
|
|
72
|
+
class Verification:
|
|
73
|
+
check: str
|
|
74
|
+
state: str # passed, failed, skipped
|
|
75
|
+
evidence: str = ""
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@dataclass(kw_only=True)
|
|
79
|
+
class StampReport:
|
|
80
|
+
workflow: str
|
|
81
|
+
exit_code: int = 0
|
|
82
|
+
compat: dict[str, Any] = field(default_factory=dict)
|
|
83
|
+
pending: list[dict[str, Any]] = field(default_factory=list)
|
|
84
|
+
not_touched: list[str] = field(default_factory=list) # WUP-B1: entries in range with no hit
|
|
85
|
+
checks: list[Verification] = field(default_factory=list)
|
|
86
|
+
findings: list[Finding] = field(default_factory=list)
|
|
87
|
+
stamp: dict[str, Any] | None = None
|
|
88
|
+
refused: str = ""
|
|
89
|
+
|
|
90
|
+
def to_json(self) -> dict[str, Any]:
|
|
91
|
+
return {"schema_version": 1, "workflow": self.workflow, "exit_code": self.exit_code, "refused": self.refused,
|
|
92
|
+
"compatibility": self.compat, "pending": self.pending, "not_touched": self.not_touched,
|
|
93
|
+
"verification": [v.__dict__ for v in self.checks],
|
|
94
|
+
"findings": [{"severity": f.severity, "code": f.code, "unit": f.unit, "message": f.message}
|
|
95
|
+
for f in self.findings],
|
|
96
|
+
"stamp": self.stamp}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _diagram_current(lp: LoadedPackage, model: Mapping[str, Any]) -> bool:
|
|
100
|
+
try:
|
|
101
|
+
doc = json.loads((lp.root / "diagram" / "model.json").read_text(encoding="utf-8"))
|
|
102
|
+
except (OSError, ValueError):
|
|
103
|
+
return False
|
|
104
|
+
return isinstance(doc, dict) and doc.get("digest") == model.get("digest")
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _outcome_revision(lp: Any) -> int:
|
|
108
|
+
outcome = getattr(lp.spec, "outcome", None)
|
|
109
|
+
return int(getattr(outcome, "revision", 0) or 0)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def check(path: Path, caps: Mapping[str, Capabilities], *, stamp: bool = False,
|
|
113
|
+
fail_on_pending: bool = False, accept_revision: bool = False) -> StampReport:
|
|
114
|
+
"""`accept_revision` is `author verify`'s rung 10 (SCF-B18, SCF-B19, SCF-B20, SCF-B21, SCF-B22): an outcome revision newer than the last
|
|
115
|
+
stamp's is the owner's re-approval, so V4 records the audit list anew instead of comparing (WUP-B19)."""
|
|
116
|
+
root = path.resolve()
|
|
117
|
+
rep = StampReport(workflow=root.name)
|
|
118
|
+
if root.is_relative_to(plugin_cache().resolve()): # WUP-B14, WUP-B7: phase 1 locate
|
|
119
|
+
rep.refused, rep.exit_code = "upgrade the workflow's source; this is an installed copy", 2
|
|
120
|
+
return rep
|
|
121
|
+
try:
|
|
122
|
+
lp = load_package(root) # V1
|
|
123
|
+
except PackageNotLoaded as exc:
|
|
124
|
+
rep.checks.append(Verification(check="V1 load", state="failed", evidence=str(exc)))
|
|
125
|
+
rep.exit_code = 4 if stamp else 2
|
|
126
|
+
return rep
|
|
127
|
+
rep.workflow = lp.spec.name
|
|
128
|
+
rep.checks.append(Verification(check="V1 load", state="passed", evidence=lp.workflow_version))
|
|
129
|
+
found = validate(lp.spec, caps) # baseline and V2
|
|
130
|
+
rep.findings = found
|
|
131
|
+
prior = read_stamp(root)
|
|
132
|
+
rep.compat = compatibility(lp.spec, root, prior, finding_codes={f.code for f in found})
|
|
133
|
+
rep.pending = [{"item_id": eid, "hits": hits} for eid, hits in rep.compat["hits"].items()]
|
|
134
|
+
rep.not_touched = [str(e) for e in rep.compat.get("entries") or [] if e not in rep.compat["hits"]]
|
|
135
|
+
if not stamp:
|
|
136
|
+
rep.exit_code = 6 if fail_on_pending and rep.pending else 0
|
|
137
|
+
return rep
|
|
138
|
+
errors = [f for f in found if f.severity == "error"]
|
|
139
|
+
rep.checks.append(Verification(check="V2 validation", state="failed" if errors else "passed",
|
|
140
|
+
evidence=f"{len(errors)} errors, {len(found) - len(errors)} warnings"))
|
|
141
|
+
rep.checks.append(Verification(check="V3 proof", state="failed" if rep.pending else "passed",
|
|
142
|
+
evidence=f"{len(rep.pending)} changelog items pending"))
|
|
143
|
+
audit_keys = _audit_keys(lp, caps)
|
|
144
|
+
before = (prior or {}).get("audit")
|
|
145
|
+
revision = _outcome_revision(lp)
|
|
146
|
+
stamped_revision = int((prior or {}).get("outcome_revision") or 1)
|
|
147
|
+
if isinstance(before, list) and accept_revision and revision > stamped_revision:
|
|
148
|
+
added = sorted(set(audit_keys) - set(before))
|
|
149
|
+
rep.checks.append(Verification(check="V4 audit", state="passed",
|
|
150
|
+
evidence=(f"outcome revision {revision} is newer than the stamped "
|
|
151
|
+
f"{stamped_revision}; new findings recorded: "
|
|
152
|
+
f"{', '.join(added) or 'none'}")))
|
|
153
|
+
elif isinstance(before, list):
|
|
154
|
+
new = sorted(set(audit_keys) - set(before))
|
|
155
|
+
rep.checks.append(Verification(check="V4 audit", state="failed" if new else "passed",
|
|
156
|
+
evidence=(f"new findings: {', '.join(new)}" if new else
|
|
157
|
+
f"no new finding at warning or above ({len(audit_keys)} known)")))
|
|
158
|
+
else:
|
|
159
|
+
rep.checks.append(Verification(check="V4 audit", state="passed",
|
|
160
|
+
evidence=f"no audit baseline yet; {len(audit_keys)} findings recorded"))
|
|
161
|
+
rep.checks.append(Verification(check="V5 change classes", state="passed", evidence="no change was made"))
|
|
162
|
+
from tempergraph.improve.suites import green_model_free
|
|
163
|
+
|
|
164
|
+
red = green_model_free(lp.spec) # EVS-B7: the model-free regression suites must be green
|
|
165
|
+
rep.checks.append(Verification(check="V6 suites", state="failed" if red else "passed",
|
|
166
|
+
evidence="; ".join(red)[:400] if red else "check suites pass with LF and CRLF"))
|
|
167
|
+
model = diagram_model(lp.spec)
|
|
168
|
+
if any(v.state == "failed" for v in rep.checks):
|
|
169
|
+
rep.exit_code = 4
|
|
170
|
+
return rep
|
|
171
|
+
current = _diagram_current(lp, model)
|
|
172
|
+
write_json(root / "diagram" / "model.json", model, mode=0o644)
|
|
173
|
+
(root / "diagram" / "workflow.md").write_text("```mermaid\n" + to_mermaid(model) + "\n```\n", encoding="utf-8")
|
|
174
|
+
rep.checks.append(Verification(check="V7 diagram", state="passed",
|
|
175
|
+
evidence="current" if current else "regenerated"))
|
|
176
|
+
lp = load_package(root) # the stamp records what the package now holds
|
|
177
|
+
rep.stamp = {
|
|
178
|
+
"schema_version": 1, "engine_version": ENGINE_VERSION, "workflow_api": WORKFLOW_API,
|
|
179
|
+
"workflow_version": lp.workflow_version, "docs_digest": lp.docs_digest, "shape_digest": model["digest"],
|
|
180
|
+
"entries_applied": _entries_applied(prior, rep.compat["entries"]),
|
|
181
|
+
"tool_set": tool_set(lp.spec),
|
|
182
|
+
"revisit": _revisit_states(lp.spec),
|
|
183
|
+
"audit": audit_keys,
|
|
184
|
+
"outcome_revision": revision,
|
|
185
|
+
"baseline": {"error": 0, "warning": sum(1 for f in found if f.severity == "warning")},
|
|
186
|
+
"stamped_at": now_iso(),
|
|
187
|
+
}
|
|
188
|
+
write_json(root / STAMP, rep.stamp, mode=0o644)
|
|
189
|
+
return rep
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _revisit_states(spec: WorkflowSpec) -> dict[str, dict[str, str]]:
|
|
193
|
+
"""DRV-B3: the states of the decision records' revisit triggers that read offline (no issue, no CLI version)."""
|
|
194
|
+
from tempergraph.audit.revisit import Readers, states
|
|
195
|
+
|
|
196
|
+
return states(spec, Readers(engine_version=ENGINE_VERSION))
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _entries_applied(prior: Mapping[str, Any] | None, new_ids: Sequence[str],
|
|
200
|
+
by: Mapping[str, str] | None = None) -> list[dict[str, str]]:
|
|
201
|
+
"""VER-B16: the entries handled over the package's life. A restamp keeps what the prior stamp held, with
|
|
202
|
+
its `by`, and adds the entries met since; a restamp of a package already current adds nothing."""
|
|
203
|
+
out: list[dict[str, str]] = []
|
|
204
|
+
seen: set[str] = set()
|
|
205
|
+
for e in (prior or {}).get("entries_applied") or []:
|
|
206
|
+
if isinstance(e, Mapping) and e.get("id") and str(e["id"]) not in seen:
|
|
207
|
+
seen.add(str(e["id"]))
|
|
208
|
+
out.append({"id": str(e["id"]), "by": str(e.get("by") or "none")})
|
|
209
|
+
for eid in new_ids:
|
|
210
|
+
if eid not in seen:
|
|
211
|
+
seen.add(eid)
|
|
212
|
+
out.append({"id": eid, "by": (by or {}).get(eid) or "none"})
|
|
213
|
+
return out
|