Files
aigc-home/docs/hel-892/refonly-document-evidence/verify_sources.py
T

177 lines
6.8 KiB
Python

"""Verify original bytes and absent declarations without implementation guesses."""
import collections
import hashlib
import json
from build_definition import OUT, PATHS, REF, REPO, build, canonical
from inventory import inventory
def main():
inv, block = inventory(), build()
raw = (REPO / PATHS[0]).read_bytes()
g = json.loads(raw)
assert inv["sha256"] == "e501089f36c4c7f76a9e926e09ab9c467316d0778e62dff4c9e9faa6b155cb83"
assert len(g["nodes"]) == 22 and len(g["links"]) == 26 and g["extra"] == {}
assert not g.get("definitions") and "frontendVersion" not in g["extra"]
assert len(inv["fields"]) == 40 and not inv["notes"]
assert inv["scopes"][0]["named_nodes"] == 0
assert collections.Counter(f["json_type"] for f in inv["fields"]) == dict(
str=22, int=10, float=6, bool=2
)
assert len(inv["empty"]) == 4 and all(e["state"] == "empty_list" for e in inv["empty"])
nodes = {n["id"]: n for n in g["nodes"]}
assert {e["node"] for e in inv["empty"]} == {126, 125, 121, 122}
declarations = []
for i, n in enumerate(g["nodes"]):
assert n["mode"] == 0 and "widgets_values" in n and "widgets_values_named" not in n
assert all(k not in n["properties"] for k in ["cnr_id", "aux_id", "ver"])
declarations.append(
dict(
node=n["id"],
class_type=n["type"],
pointer=f"/nodes/{i}/properties",
properties=n["properties"],
identity="unknown",
exact_implementation_sources=0,
)
)
assert g["links"] == json.loads((OUT / "expected-edges.json").read_bytes())
for eid, src, si, dst, di, typ in g["links"]:
assert eid in nodes[src]["outputs"][si]["links"] and nodes[dst]["inputs"][di]["link"] == eid
assert nodes[src]["outputs"][si]["type"] == nodes[dst]["inputs"][di]["type"] == typ
for f, x in zip(block["fields"], inv["fields"], strict=True):
assert f["pointer"] == x["pointer"] and f["json_type"] == x["json_type"]
assert canonical(f["value"]) == canonical(x["value"])
assert f["named_state"] == "missing" and "named_pointer" not in f and "named_value" not in f
assert f["evidence"] == [] and f["role"] == "saved_reference"
assert (
f["schema_default"].startswith("未知")
and f["unit"].startswith("未知")
and f["limits"].startswith("未知")
)
assert len(block["node_bindings"]) == 22 and all(
b["source_id"] == "unknown" and not b["candidates"] for b in block["node_bindings"]
)
assert block["sources"] == [] == json.loads((REF / "sources.json").read_bytes())["sources"]
assert block["comments"] == [] and block["boundaries"] == []
def inp(n, k):
return next(x for x in nodes[n]["inputs"] if x["name"] == k)
assert nodes[900]["widgets_values"] == [0.9, "64", 8192, 0, True, True]
assert type(nodes[900]["widgets_values"][1]) is str
assert nodes[142]["widgets_values"] == [12.0, 3.0] and all(
type(v) is float for v in nodes[142]["widgets_values"]
)
assert nodes[133]["widgets_values"] == [10.0] and type(nodes[133]["widgets_values"][0]) is float
assert (
nodes[124]["widgets_values"] == ["simple", 4, 1.0]
and type(nodes[124]["widgets_values"][2]) is float
)
assert (
inp(132, "values")["link"] is None
and nodes[132]["inputs"][1]["name"] == "values.a"
and nodes[132]["inputs"][1]["link"] == 1
)
assert inp(116, "values")["link"] is None and all(
o["links"] is None for o in nodes[116]["outputs"]
)
assert (
nodes[901]["widgets_values"] == ["reference_1.png"]
and nodes[901]["outputs"][1]["links"] is None
)
assert all(
inp(131, k)["link"] is None
for k in ["ref_images", "ref_videos", "ref_video_audios", "ref_audios"]
)
assert nodes[131]["inputs"][11]["link"] == 10 and inp(125, "latent_image")["link"] == 19
assert [o["links"] for o in nodes[125]["outputs"]] == [[20, 22], None]
assert nodes[130]["widgets_values"] == [24, 8, "sRGB"] and nodes[92]["widgets_values"] == [
"video/05_ref2va_4step_sla",
"auto",
"auto",
]
assert nodes[92]["outputs"][0]["links"] is None
prompt = nodes[1]["widgets_values"][0]
digest = hashlib.sha256(prompt.encode()).hexdigest()
assert (
len(prompt),
prompt.count("\n"),
prompt.count("\r"),
prompt.count("\\n"),
prompt.endswith("\n"),
digest,
) == (458, 15, 0, 0, False, "af5ba4aa01b3db65d6a02c65f448fba704de1e5e92530b159897410353dcb56e")
sensitive = []
def scan(x, p=""):
if isinstance(x, dict):
for k, v in x.items():
if k.lower() in [
"api_key",
"apikey",
"secret",
"password",
"token",
"access_token",
"authorization",
] and v not in [None, "", [], {}]:
sensitive.append(p + "/" + k)
scan(v, p + "/" + k)
elif isinstance(x, list):
for i, v in enumerate(x):
scan(v, p + "/" + str(i))
scan(g)
assert not sensitive
def write(name, value):
(OUT / name).write_text(json.dumps(value, ensure_ascii=False, indent=2) + "\n")
write(
"declaration-audit.json",
dict(
source_sha256=inv["sha256"],
extra=g["extra"],
frontend_version="missing",
nodes=declarations,
external_metadata_requests=0,
candidate_sources_acquired=0,
scope="仅本原件所有22个properties及根extra;没有做全仓/外部类不存在调查",
),
)
write(
"identity-gaps.json",
dict(
accurate_implementation_sources=0,
unknown_nodes=[n["id"] for n in g["nodes"]],
all_missing_provider_version=True,
frontend_version="missing",
defaults_units_ranges_mapping_algorithms_io_license_dependencies="unknown",
bounded_investigation="只读原件声明、位置与连线;未选main/最新版或下载候选源码/资产",
not_repository_absence_proof=True,
),
)
write(
"source-check.json",
dict(
source_sha256=inv["sha256"],
implementation_sources=0,
unknown_nodes=22,
fields=40,
notes=[],
texts=[dict(node="1", characters=458, LF=15, CR=0, tail_LF=False, sha256=digest)],
nonempty_credential_keys=sensitive,
no_upstream_execution=True,
),
)
print(
"PASS40 positions/22 unknown identities/no named/no Notes/four []/full prompt SHA/26 edges"
)
if __name__ == "__main__":
main()