HEL-892: document Krea2 API named inputs without inferred identities
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
"""Collect final foreground browser evidence and verify typed document equality."""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
import socket
|
||||
from collections import Counter
|
||||
|
||||
from build_definition import OUT, PATHS, REPO, canonical
|
||||
|
||||
|
||||
def sha(path):
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def main():
|
||||
browser = REPO / ".local-evidence/krea-api-document/browser"
|
||||
data = REPO / ".local-evidence/krea-api-document-server"
|
||||
result = json.loads((browser / "browser-results.json").read_bytes())
|
||||
assert not result["errors"]
|
||||
assert len(result["interceptions"]) == 6
|
||||
actual = json.loads((browser / "actual-get.json").read_bytes())
|
||||
isolated = json.loads((OUT / "actual-Krea2_t2i_20260818_API.json").read_bytes())
|
||||
assert canonical(actual["doc_json"]) == canonical(isolated)
|
||||
assert actual["doc_json"] == isolated
|
||||
block = isolated["fixed_version"]
|
||||
for field in block["fields"]:
|
||||
original = json.loads((REPO / PATHS[0]).read_bytes())[field["node_id"]]["inputs"][
|
||||
field["field"]
|
||||
]
|
||||
assert type(original) is type(field["value"])
|
||||
report = (OUT.parent / "Krea2基础文生图API格式固定参考中文说明.md").read_text()
|
||||
report_block = json.loads(report.split("```json\n", 1)[1].rsplit("\n```", 1)[0])
|
||||
assert canonical(report_block) == canonical({k: v for k, v in block.items() if k != "matched"})
|
||||
backend = Counter(
|
||||
re.findall(r'"GET ([^ ]+) HTTP/1.1"', (browser / "service-0.log").read_text())
|
||||
)
|
||||
fixed = Counter(result["request_accounting"]["fixed_paths"])
|
||||
polls = Counter(result["request_accounting"]["polling_paths"])
|
||||
expected = fixed + polls
|
||||
expected["/api/workflows"] += 1 # Wrapper readiness before browser.
|
||||
intercepted = Counter(
|
||||
__import__("urllib.parse", fromlist=["urlsplit"]).urlsplit(r["url"]).path
|
||||
for r in result["interceptions"]
|
||||
)
|
||||
expected.subtract(intercepted)
|
||||
delta = backend - expected
|
||||
assert not (expected - backend)
|
||||
assert set(delta) <= {"/api/jobs"} and delta.get("/api/jobs", 0) <= 1
|
||||
stop = json.loads((browser / "service-stop.json").read_bytes())
|
||||
assert stop["ports_released"] == stop["independent_connection_refused"] == [8247, 5173]
|
||||
for port in (8247, 5173):
|
||||
with socket.socket() as sock:
|
||||
sock.settimeout(1)
|
||||
assert sock.connect_ex(("127.0.0.1", port)) != 0
|
||||
with socket.socket() as sock:
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock.bind(("127.0.0.1", port))
|
||||
pngs = [
|
||||
dict(file=p.name, bytes=p.stat().st_size, sha256=sha(p))
|
||||
for p in sorted(browser.glob("*.png"))
|
||||
]
|
||||
assert len(pngs) == 40
|
||||
for p in browser.iterdir():
|
||||
if p.is_file() and p.suffix != ".png":
|
||||
shutil.copyfile(p, OUT / p.name)
|
||||
shutil.copyfile(REPO / PATHS[0], OUT / "original-Krea2_t2i_20260818_API.json")
|
||||
for p in (REPO / ".local-evidence").glob("kapi-*.txt"):
|
||||
shutil.copyfile(p, OUT / p.name)
|
||||
validation = dict(
|
||||
assertions=result["assertion_count"],
|
||||
groups=result["assertionGroups"],
|
||||
final_screenshots=pngs,
|
||||
actual_get_equals_isolated_json=True,
|
||||
canonical_sha256=hashlib.sha256(canonical(isolated)).hexdigest(),
|
||||
float_dom="解析值/类型,不称HTTP原字节或float DOM原字节",
|
||||
report_reversible=True,
|
||||
forbidden_requests=0,
|
||||
http_fixtures=6,
|
||||
readiness_get=1,
|
||||
backend_paths=dict(backend),
|
||||
browser_accounting=result["request_accounting"],
|
||||
intercepted_paths=dict(intercepted),
|
||||
polling_delta=dict(delta),
|
||||
ports_refused_bindable=[8247, 5173],
|
||||
fresh_db_path=str(data.relative_to(REPO)),
|
||||
)
|
||||
(OUT / "validation-results.json").write_text(
|
||||
json.dumps(validation, ensure_ascii=False, indent=2) + "\n"
|
||||
)
|
||||
print("PASS typed GET/doc/report equality, request ledger,40PNG, released ports")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user