125 lines
5.0 KiB
Python
125 lines
5.0 KiB
Python
"""Select two retained import rows read-only, with original and case01 byte gates."""
|
|
|
|
import ast
|
|
import hashlib
|
|
import json
|
|
import sqlite3
|
|
|
|
from audit import HERE, ROOT, api_compare, same, sha, write
|
|
|
|
|
|
def main():
|
|
manifest_path = "docs/hel-892/supplied-api/manifest.json"
|
|
manifest = json.loads((ROOT / manifest_path).read_text())
|
|
binding = next(case for case in manifest["cases"] if case["id"] == "01")
|
|
paths = {
|
|
"krea": "example_ComfyUI_workflows/Krea2_t2i_20260818_API.json",
|
|
"controlnet": binding["source_path"],
|
|
}
|
|
api_path = "docs/hel-892/supplied-api/01.api.json"
|
|
assert sha((ROOT / api_path).read_bytes()) == binding["export_sha256"]
|
|
assert sha((ROOT / binding["source_path"]).read_bytes()) == binding["source_sha256"]
|
|
assert binding["source_export_equivalence_verified"] is False
|
|
for key in ("exported_at", "frontend_version", "node_versions"):
|
|
assert binding[key] is None
|
|
reviews_path = "calliope-backend/src/calliope/comfyui/source_reviews.json"
|
|
reviews = json.loads((ROOT / reviews_path).read_text())
|
|
pins_path = "calliope-backend/src/calliope/comfyui/fixed_document.py"
|
|
tree = ast.parse((ROOT / pins_path).read_text())
|
|
definitions = next(
|
|
node.value
|
|
for node in tree.body
|
|
if isinstance(node, ast.Assign)
|
|
and any(isinstance(t, ast.Name) and t.id == "DEFINITIONS" for t in node.targets)
|
|
)
|
|
pins = {
|
|
ast.literal_eval(key): ast.literal_eval(value)
|
|
for key, value in zip(definitions.keys, definitions.values)
|
|
if isinstance(key, ast.Constant) and key.value in paths.values()
|
|
}
|
|
result = {"baseline": json.loads((HERE / "baseline.json").read_text())["commit"]}
|
|
db_path = ".local-evidence/batch175-closure/library.db"
|
|
conn = sqlite3.connect(f"file:{ROOT / db_path}?mode=ro", uri=True)
|
|
conn.row_factory = sqlite3.Row
|
|
conn.execute("PRAGMA query_only=ON")
|
|
for key, path in paths.items():
|
|
rows = list(conn.execute("SELECT * FROM workflows WHERE source_repo_path=?", (path,)))
|
|
assert len(rows) == 1
|
|
row = rows[0]
|
|
block = reviews[path]["fixed_version_document"]
|
|
raw = (ROOT / path).read_bytes()
|
|
assert sha(raw) == block["source_sha256"]
|
|
assert hashlib.sha1(raw).hexdigest() == row["source_sha"] == block["source_sha1"]
|
|
canonical_block = json.dumps(
|
|
block, ensure_ascii=False, sort_keys=True, separators=(",", ":")
|
|
).encode()
|
|
assert sha(canonical_block) == pins[path]
|
|
assert same(json.loads(row["raw_source_json"]), json.loads(raw))
|
|
doc = json.loads(row["doc_json"])
|
|
result[key] = dict(
|
|
source_path=path,
|
|
original_sha256=sha(raw),
|
|
imported_api=json.loads(row["workflow_json"]),
|
|
imported_workflow_json_sha256=sha(row["workflow_json"].encode()),
|
|
doc_json_sha256=sha(row["doc_json"].encode()),
|
|
doc=doc,
|
|
block=block,
|
|
definition_pin=pins[path],
|
|
import_fields={
|
|
field: json.loads(row[field])
|
|
if row[field] is not None and field not in ("output_node_name", "output_map_source")
|
|
else row[field]
|
|
for field in (
|
|
"input_node_map",
|
|
"output_node_name",
|
|
"input_schema",
|
|
"output_schema",
|
|
"output_map",
|
|
"output_map_source",
|
|
"import_issues",
|
|
)
|
|
},
|
|
qualification={
|
|
field: row[field]
|
|
for field in (
|
|
"source_sha",
|
|
"source_commit",
|
|
"import_state",
|
|
"is_enabled",
|
|
"doc_completed_at",
|
|
"exec_verified_at",
|
|
"imported_at",
|
|
)
|
|
},
|
|
)
|
|
assert row["is_enabled"] == 0
|
|
assert row["doc_completed_at"] is None and row["exec_verified_at"] is None
|
|
assert doc["draft"] and doc["dependencies"]["check_state"] == "unchecked"
|
|
if key == "controlnet":
|
|
result[key]["binding"] = binding
|
|
assert not api_compare(
|
|
result[key]["imported_api"], json.loads((ROOT / api_path).read_text())
|
|
)
|
|
conn.close()
|
|
result["retained_db"] = dict(path=db_path, mode="ro+query_only", provenance="batch175")
|
|
evidence_paths = [
|
|
manifest_path,
|
|
api_path,
|
|
reviews_path,
|
|
pins_path,
|
|
*paths.values(),
|
|
"calliope-backend/src/calliope/comfyui/library.py",
|
|
"calliope-backend/src/calliope/comfyui/parser.py",
|
|
"calliope-backend/src/calliope/comfyui/ui2api.py",
|
|
"calliope-backend/src/calliope/comfyui/companions.py",
|
|
]
|
|
result["file_evidence"] = [
|
|
dict(path=p, sha256=sha((ROOT / p).read_bytes())) for p in evidence_paths
|
|
]
|
|
write("inputs.json", result)
|
|
print("two read-only retained rows; originals and case01 SHA gates passed")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|