Files
aigc-home/calliope-backend/src/calliope/comfyui/fixed_document.py
T

86 lines
3.9 KiB
Python

"""Explicit source-bound editorial documents; never a conversion or execution contract."""
from __future__ import annotations
import copy
import hashlib
import json
SOURCE_PATH = (
"example_ComfyUI_workflows/0-基础处理:图像合并-音频分离-视频截取合并-图像视频放大/"
"Minimax-H3提示词增强.json"
)
# Pins the reviewed Chinese text, saved values, pointers and complete evidence citations.
DEFINITION_SHA256 = "c4c7f04fde29dc7485a341207397fcf6191e3fcbe89ecc2d238f4a4f5bc24a1d"
# Explicit path allowlist; a recomputed caller-supplied digest cannot extend trust.
DEFINITIONS = {
(
"example_ComfyUI_workflows/3-图像生成/Qwen-Image-2.1/Qwen_image2.1_图像编辑_背景移除.json"
): "5bec95e79a08f94659622c940644d6f7cb68ba725db12077e37a6b2ae6560c35",
(
"example_ComfyUI_workflows/3-图像生成/Qwen-Image-2.1/Qwen_image2.1_图像编辑_提示词增强.json"
): "88018f652604aa4ca3a5d67fc28c30fe337482620192ef98989b0aab4a5751f2",
(
"example_ComfyUI_workflows/3-图像生成/Qwen-Image-2.1/Qwen_image2.1_文生图_提示词增强.json"
): "ee2a73791e7db5af316099429bb2e0414e2008fc4672c9355957b0bc84e607ab",
SOURCE_PATH: DEFINITION_SHA256,
(
"example_ComfyUI_workflows/0-基础处理:图像合"
"并-音频分离-视频截取合并-图像视频放大/ControlNet_aux_常用样例.json"
): "987ad5369392962ccad3a795727812b9d96d3e05cc727cedcbf8b46aa10727cd",
(
"example_ComfyUI_workflows/0-基础处理:图像合"
"并-音频分离-视频截取合并-图像视频放大/音频转MP3格式.json"
): "75e9270fbbb38ddc06b7c86cf25744da428085a4179937129b0c3f0c43bbe51b",
(
"example_ComfyUI_workflows/0-基础处理:图像合"
"并-音频分离-视频截取合并-图像视频放大/音频人声分离.json"
): "765f5cfdcc5cea2c4b85ed84fa4f94217287c9c2e751ad527909bdcbaa8f007a",
(
"example_ComfyUI_workflows/0-基础处理:图像合"
"并-音频分离-视频截取合并-图像视频放大/视频-音频分离.json"
): "5844ee92471868325c95227e3a3119fa7a14dd526a019790997558b3f6ad6e0c",
(
"example_ComfyUI_workflows/0-基础处理:图像合"
"并-音频分离-视频截取合并-图像视频放大/图像嵌入文字描述.json"
): "76279a5f33243c032efc345870ba2966c6ea2665ca1f3bbfcc2f7b42982d5bc9",
(
"example_ComfyUI_workflows/1-语音生成/Qwen3-ASR-语音转文字.json"
): "715ad28157196f30f5cc58ce4f7b6206c88b53213150fe5cbccfda36e28185ad",
(
"example_ComfyUI_workflows/1-语音生成/Qwen3-ASR-Subtitle语音转字幕.json"
): "a7dcac39b659f9c509785edbb324ad1fc31f5e6a2b54e59741f91d7e9054bf3b",
}
def canonical(value: object) -> bytes:
return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode()
def fixed_document_for(path: str, source: object, review: dict | None) -> dict | None:
"""Fail closed on any source, identity, dual saved value or citation mismatch.
review_for already checks the original byte SHA1 before supplying a review.
The canonical digest also protects direct build_document callers from mixing
another source object with that review. No upstream code or network is used.
"""
if path not in DEFINITIONS:
return None
pending = {
"matched": False,
"notice": "固定版本参数说明待核对:源文件、声明版本或说明依据未匹配,未采用旧定义。",
}
block = (review or {}).get("fixed_version_document")
if not isinstance(block, dict):
return pending
if hashlib.sha256(canonical(block)).hexdigest() != DEFINITIONS[path]:
return pending
if (
block["source_path"] != path
or (review or {}).get("source_sha") != block["source_sha1"]
or hashlib.sha256(canonical(source)).hexdigest() != block["canonical_sha256"]
):
return pending
return {**copy.deepcopy(block), "matched": True}