* test(inspect): add synthetic inspection parity fixtures and legacy characterization * test(inspect): pin test-time parity vectors and keep fixtures fully synthetic * fix(inspect): bound resolver work instead of graph size * fix(inspect): bound shared-node and stripped-text work in the inspection profile Keep one memo per resolution whose entries carry their unfolded visit cost; a memo hit charges that cost to the current candidate's allowance only. Cache node validation and charge input keys, stripped characters and copied provenance entries to a whole-resolution work budget before doing the work. The default profile is unchanged. * fix(inspect): keep memoized depth honest across inspection candidates A memo entry now records its height below the reusing depth; a hit raises depth-limit exactly where a fresh walk would, so each candidate's outcome matches its anchored result and does not depend on trace or node order. The default profile is unchanged. * test(inspect): pin memo height propagation Three samplers share one chain, each later one hanging below a memo hit. The third candidate must report depth-limit in both trace orders and when anchored; removing the memo-hit height propagation fails this test. The provenance test now asserts a plain subset. * fix(inspect): tolerate ComfyUI node metadata quirks in projections Projections now take a kind. Each prompt node keeps exactly class_type and inputs; _meta, is_changed and other node keys are validated and dropped, so "is_changed": [NaN] no longer marks the whole prompt graph malformed. A nonfinite value inside inputs, anywhere in a workflow, or in a retained carrier member projects to null and is never reported as a number. The carrier applies the prompt/workflow kinds to its members. Exact numbers are unchanged (Decimal spelling, unsafe integers as strings) and duplicate keys are still malformed. The 500-node gate is replaced by a 20,000-node backstop (workflow count includes subgraph definitions). Raw records are untouched. The f14 inspection vector's facts become known; default vectors are unchanged. * fix(inspect): budget metadata per record so large workflows never hide prompts PNG inspection no longer counts every text chunk against one shared 2 MiB budget. Role records (prompt, parameters, the pair execution record) keep a 2 MiB budget together, encoded and decoded, and exceeding it still fails the whole read. A workflow has its own 4 MiB budget: a chunk over it is skipped by seek, and a compressed one stops inflating at budget + 1. Only the workflow is then reported as limited (record format "limited", no raw text, workflow_graph limited); prompts, facts and the prompt graph are unaffected. Each text chunk's keyword is read first (at most 80 bytes). Chunks that are not retained are skipped by length without being read or checksummed, so memory stays bounded. Byte-identical duplicates of a retained record are accepted and do not consume budget; differing duplicates still raise "Duplicate prompt metadata", and a duplicate of a limited workflow stays limited. The chunk-count limit is unchanged. InspectionRead gains limited_records (empty by default). The reader is only used by the inspection routes, so ingestion, scan and import are unchanged. Vectors: f04-inspection (2.5 MB workflow, within the new workflow budget) and f15-inspection (identical duplicate chunks) now read and resolve, with the same outcome and facts as f05-inspection. Default vectors are unchanged. * fix(inspect): keep prompt evidence longest under the response budget * fix(inspect): bound identical duplicate chunk reads * fix(inspect): fail closed when role duplicates exceed their budget * fix(inspect): use the bounded inspection profile end to end Inspection routes resolve with INSPECTION_PROFILE and expose reason_code and node on the resolution; scan, live monitor and admin import keep the default profile (pinned by spies over the real resolver on f03). JS facts drop the entries and workflow node-count gates; per-lookup visit sets and the server's node ceiling bound the work. The validator accepts the textless `limited` workflow format, follows the workflow-first response omission order, and checks the closed reason-code vocabulary. The file inspector labels limited records and disables their workflow download. vectors.json: 12 inspection vectors gain their reason codes; f03 facts become known and f01 facts ambiguous. Default vectors are unchanged. A new parity test asserts vectors.json facts through the workspace JS. * chore(tools): add read-only inspection corpus tool tools/inspection_corpus.py runs the inspection route pipeline and the workspace JS facts of a chosen code tree over a media folder, read-only, and reports the #240 invariants H1 to H8 with aggregate counts. Rows hold statuses and SHA-256 digests of resolved role texts, never file names or prompt text unless --with-paths is given. Outputs inside the root or a code tree are refused. The facts-over-vectors test now fails instead of skipping when CI is set and Node.js is missing. * docs(testing): document bounded inspection work * fix(tools): fail the corpus run when facts or inspection did not run Rows whose facts were never computed (no or exiting Node.js) now fail H3, and a new harness line fails on any tool exception or missing facts, so a run where nothing was measured can no longer exit 0. Unreadable files stay inspector outcomes. A missing --node binary is refused, an exited harness is reaped, H8 has a 50 ms floor for tiny baselines, and JSONL rows are sorted by id. * docs(inspect): correct ceiling wording and bandit annotations Describe the two 20,000-node ceilings (prompt entries, workflow UI plus subgraph nodes) in TESTING.md, and use bare nosec ids so Bandit stops warning about unparsed test names. * test(inspect): make parity observation tuples explicit
149 lines
6.6 KiB
Python
149 lines
6.6 KiB
Python
"""Committed synthetic inspection parity fixtures stay reproducible and referenced."""
|
|
|
|
import json
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
try:
|
|
from tests import inspection_parity as parity
|
|
except ImportError: # pragma: no cover - discover -s tests puts tests/ first
|
|
import inspection_parity as parity
|
|
|
|
|
|
class InspectionParityFixtureTests(unittest.TestCase):
|
|
def test_committed_fixtures_match_builders(self):
|
|
# Decoded text chunks, not bytes: zlib output differs between platforms.
|
|
for name in parity.COMMITTED:
|
|
with self.subTest(fixture=name):
|
|
path = parity.fixture_path(name)
|
|
self.assertTrue(path.is_file(), f"missing committed fixture {path}")
|
|
self.assertLess(path.stat().st_size, parity.MAX_FIXTURE_BYTES)
|
|
self.assertEqual(
|
|
parity.read_text_chunks(path),
|
|
parity.expected_text_chunks(parity.build(name)),
|
|
)
|
|
|
|
def test_no_uncommitted_files_in_fixture_directory(self):
|
|
# Only fixture data counts; OS litter (.DS_Store, Thumbs.db) is ignored.
|
|
expected = {f"{name}.png" for name in parity.COMMITTED} | {"vectors.json"}
|
|
present = {
|
|
path.name
|
|
for path in parity.FIXTURE_DIR.iterdir()
|
|
if path.suffix in (".png", ".json")
|
|
}
|
|
self.assertEqual(present, expected)
|
|
|
|
def test_writer_round_trips_extra_raw_chunks(self):
|
|
for name in ("f15", "f16"):
|
|
built = parity.build(name)
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path = Path(directory) / f"{name}.png"
|
|
parity.write_png(path, built)
|
|
chunks = parity.read_text_chunks(path)
|
|
with self.subTest(fixture=name):
|
|
self.assertEqual(chunks, parity.expected_text_chunks(built))
|
|
self.assertGreater(len(chunks), 2)
|
|
|
|
def test_duplicate_fixtures_have_the_intended_shape(self):
|
|
identical = parity.read_text_chunks(parity.fixture_path("f15"))
|
|
self.assertEqual(len(identical), 8)
|
|
self.assertEqual(len(set(identical)), 2)
|
|
conflicting = [
|
|
text
|
|
for key, text in parity.read_text_chunks(parity.fixture_path("f16"))
|
|
if key == "prompt"
|
|
]
|
|
self.assertEqual(len(conflicting), 2)
|
|
self.assertNotEqual(conflicting[0], conflicting[1])
|
|
|
|
def test_nan_fixture_keeps_comfyui_spelling_outside_inputs(self):
|
|
prompt = dict(parity.read_text_chunks(parity.fixture_path("f14")))["prompt"]
|
|
self.assertIn('"is_changed": [NaN]', prompt)
|
|
self.assertIn('"_meta": {"title": "CheckpointLoaderSimple"}', prompt)
|
|
for node in json.loads(prompt).values():
|
|
for value in node["inputs"].values():
|
|
self.assertEqual(value, value, "NaN stays outside inputs")
|
|
|
|
def test_builders_are_deterministic_and_fresh(self):
|
|
for name in parity.COMMITTED + parity.TEST_TIME:
|
|
with self.subTest(fixture=name):
|
|
first, second = parity.build(name), parity.build(name)
|
|
self.assertEqual(
|
|
parity.expected_text_chunks(first),
|
|
parity.expected_text_chunks(second),
|
|
)
|
|
if first["prompt"] is not None:
|
|
first["prompt"].clear()
|
|
self.assertTrue(parity.build(name)["prompt"])
|
|
with self.assertRaises(KeyError):
|
|
parity.build("f99")
|
|
|
|
def test_test_time_shapes_exceed_commit_size(self):
|
|
sizes = {
|
|
name: sum(
|
|
len(text) for _, text in parity.expected_text_chunks(parity.build(name))
|
|
)
|
|
for name in parity.TEST_TIME
|
|
}
|
|
self.assertGreater(sizes["f01"], 3 * parity.MAX_FIXTURE_BYTES)
|
|
prompt = parity.build("f01")["prompt"]
|
|
self.assertEqual(len(prompt), 688)
|
|
self.assertEqual(sum(":" in node_id for node_id in prompt), 600)
|
|
self.assertGreater(sizes["f04"], 2_500_000)
|
|
self.assertGreater(sizes["f05"], 900_000)
|
|
|
|
def test_vectors_reference_existing_fixtures(self):
|
|
vectors = parity.load_vectors()
|
|
self.assertTrue(vectors)
|
|
names = [vector["name"] for vector in vectors]
|
|
self.assertEqual(len(names), len(set(names)), "vector names are unique")
|
|
known = set(parity.COMMITTED) | set(parity.TEST_TIME)
|
|
for vector in vectors:
|
|
with self.subTest(vector=vector["name"]):
|
|
self.assertIn(vector["fixture"], known)
|
|
if vector["fixture"] in parity.COMMITTED:
|
|
self.assertTrue(parity.fixture_path(vector["fixture"]).is_file())
|
|
self.assertIn(vector["profile"], ("default", "inspection"))
|
|
self.assertEqual(set(vector["expect"]), set(parity.EXPECT_KEYS))
|
|
facts = vector["expect"]["facts"]
|
|
if vector["profile"] == "default":
|
|
# Facts are a property of the inspection response only.
|
|
self.assertIsNone(facts)
|
|
else:
|
|
self.assertEqual(set(facts), set(parity.FACT_FIELDS))
|
|
for fact in facts.values():
|
|
self.assertEqual(set(fact), {"status", "value"})
|
|
for profile in ("inspection", "default"):
|
|
covered = {
|
|
vector["fixture"] for vector in vectors if vector["profile"] == profile
|
|
}
|
|
self.assertEqual(
|
|
covered, set(parity.COMMITTED) | set(parity.TEST_TIME), profile
|
|
)
|
|
|
|
def test_vectors_match_current_resolution(self):
|
|
"""Baseline vectors pin today's outcomes; behavior changes edit them."""
|
|
for vector in parity.load_vectors():
|
|
with self.subTest(vector=vector["name"]):
|
|
expected = dict(vector["expect"])
|
|
expected.pop("facts")
|
|
self.assertEqual(parity.observe(vector), expected)
|
|
|
|
def test_observe_builds_test_time_fixtures_instead_of_reading_missing_files(self):
|
|
# A missing file would otherwise read as "unreadable" and hide a stale vector.
|
|
for name in parity.TEST_TIME:
|
|
with self.subTest(fixture=name):
|
|
self.assertFalse(parity.fixture_path(name).exists())
|
|
observed = parity.observe(
|
|
{"fixture": name, "profile": "default", "anchor": None}
|
|
)
|
|
self.assertEqual(observed["metadata_status"], "available")
|
|
self.assertNotEqual(observed["state"], "absent")
|
|
with self.assertRaises(FileNotFoundError):
|
|
parity.observe({"fixture": "f02", "profile": "inspection"}, "missing-dir")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|