Make signature artifact timestamps deterministic
This commit is contained in:
@@ -2,7 +2,9 @@ import json
|
|||||||
import tempfile
|
import tempfile
|
||||||
import textwrap
|
import textwrap
|
||||||
import unittest
|
import unittest
|
||||||
|
from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from tools.generate_popular_node_signatures import (
|
from tools.generate_popular_node_signatures import (
|
||||||
extract_repo_signatures,
|
extract_repo_signatures,
|
||||||
@@ -12,10 +14,6 @@ from tools.generate_popular_node_signatures import (
|
|||||||
|
|
||||||
|
|
||||||
class StaticExtractionTests(unittest.TestCase):
|
class StaticExtractionTests(unittest.TestCase):
|
||||||
def _normalise_generated_at(self, text):
|
|
||||||
parsed = json.loads(text)
|
|
||||||
return text.replace(parsed["generated_at"], "<generated-at>")
|
|
||||||
|
|
||||||
def _extract_source(self, source, pack_id="sample-pack"):
|
def _extract_source(self, source, pack_id="sample-pack"):
|
||||||
with tempfile.TemporaryDirectory() as tmp:
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
Path(tmp, "__init__.py").write_text(textwrap.dedent(source), encoding="utf-8")
|
Path(tmp, "__init__.py").write_text(textwrap.dedent(source), encoding="utf-8")
|
||||||
@@ -4766,9 +4764,23 @@ NODE_CLASS_MAPPINGS = {
|
|||||||
self.assertEqual("no_static_nodes", result["pack"]["status"])
|
self.assertEqual("no_static_nodes", result["pack"]["status"])
|
||||||
|
|
||||||
def test_write_artifact_is_deterministic(self):
|
def test_write_artifact_is_deterministic(self):
|
||||||
|
class FakeDateTime:
|
||||||
|
values = iter(
|
||||||
|
(
|
||||||
|
datetime(2026, 1, 1, tzinfo=timezone.utc),
|
||||||
|
datetime(2026, 1, 2, tzinfo=timezone.utc),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def now(cls, tz=None):
|
||||||
|
value = next(cls.values)
|
||||||
|
return value if tz is None else value.astimezone(tz)
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmp:
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
out_one = Path(tmp, "one.json")
|
out_one = Path(tmp, "one.json")
|
||||||
out_two = Path(tmp, "two.json")
|
out_two = Path(tmp, "two.json")
|
||||||
|
with mock.patch("tools.generate_popular_node_signatures.datetime", FakeDateTime):
|
||||||
write_artifact(
|
write_artifact(
|
||||||
out_one,
|
out_one,
|
||||||
sources={
|
sources={
|
||||||
@@ -4867,7 +4879,21 @@ NODE_CLASS_MAPPINGS = {
|
|||||||
|
|
||||||
self.assertEqual(["a-pack", "b-pack"], list(parsed["packs"]))
|
self.assertEqual(["a-pack", "b-pack"], list(parsed["packs"]))
|
||||||
self.assertEqual(["ANode", "BNode"], list(parsed["nodes"]))
|
self.assertEqual(["ANode", "BNode"], list(parsed["nodes"]))
|
||||||
self.assertEqual(self._normalise_generated_at(text_one), self._normalise_generated_at(text_two))
|
self.assertEqual(text_one, text_two)
|
||||||
|
|
||||||
|
def test_write_artifact_uses_explicit_generated_at(self):
|
||||||
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
|
out = Path(tmp, "popular_node_signatures.json")
|
||||||
|
write_artifact(
|
||||||
|
out,
|
||||||
|
sources={"manager_url": "https://example.invalid/manager.json", "limit": 1},
|
||||||
|
packs={},
|
||||||
|
nodes={},
|
||||||
|
generated_at="2026-07-02T00:00:00Z",
|
||||||
|
)
|
||||||
|
parsed = json.loads(out.read_text(encoding="utf-8"))
|
||||||
|
|
||||||
|
self.assertEqual("2026-07-02T00:00:00Z", parsed["generated_at"])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from pathlib import Path
|
|||||||
SCHEMA_VERSION = 1
|
SCHEMA_VERSION = 1
|
||||||
MANAGER_LIST_URL = "https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json"
|
MANAGER_LIST_URL = "https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json"
|
||||||
REGISTRY_NODES_URL = "https://api.comfy.org/nodes"
|
REGISTRY_NODES_URL = "https://api.comfy.org/nodes"
|
||||||
|
DEFAULT_GENERATED_AT = "1970-01-01T00:00:00Z"
|
||||||
|
|
||||||
|
|
||||||
class UnsupportedStaticExpression(Exception):
|
class UnsupportedStaticExpression(Exception):
|
||||||
@@ -2410,10 +2411,20 @@ def _sorted_json_value(value):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
def write_artifact(path, sources, packs, nodes):
|
def _format_generated_at(generated_at):
|
||||||
|
if isinstance(generated_at, datetime):
|
||||||
|
if generated_at.tzinfo is None:
|
||||||
|
generated_at = generated_at.replace(tzinfo=timezone.utc)
|
||||||
|
else:
|
||||||
|
generated_at = generated_at.astimezone(timezone.utc)
|
||||||
|
return generated_at.replace(microsecond=0).isoformat().replace("+00:00", "Z")
|
||||||
|
return str(generated_at)
|
||||||
|
|
||||||
|
|
||||||
|
def write_artifact(path, sources, packs, nodes, *, generated_at=DEFAULT_GENERATED_AT):
|
||||||
payload = {
|
payload = {
|
||||||
"schema_version": SCHEMA_VERSION,
|
"schema_version": SCHEMA_VERSION,
|
||||||
"generated_at": datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z"),
|
"generated_at": _format_generated_at(generated_at),
|
||||||
"sources": _sorted_json_value(sources),
|
"sources": _sorted_json_value(sources),
|
||||||
"packs": _sorted_json_value(packs),
|
"packs": _sorted_json_value(packs),
|
||||||
"nodes": _sorted_json_value(nodes),
|
"nodes": _sorted_json_value(nodes),
|
||||||
|
|||||||
Reference in New Issue
Block a user