* test(inspect): use a neutral unknown class in the pass-through fixtures The #381 fixtures used rgthree's Any Switch as their example of an unknown node. The table is about to describe that class (#657), so the stand-in becomes PMTest Unknown Multi and any_switch_graph becomes unknown_multi_graph. Resolver results are unchanged. * feat(inspect): resolve rgthree Any Switch by its first proven input (#657) rgthree's Any Switch outputs the first any_* input that is not None. The inspection resolver treated it as an unknown node, so the model-compare sweep (PromptManagerText into any_01, the same text joined after a LoRA trigger into any_02) was ambiguous in Inspect. The table gains a first-present selector strategy and lists the switch under it. The resolver takes the first participating input when it is a literal or its traced path proves a value (every node is a PromptManager, code-traced, default-adapter or encoders/strings/conditioning/composites class). Otherwise each input is one choice, unless all of them trace to one text; limits and upstream divergences propagate, and no PromptManager path is preferred. A missing or null input does not take part. The browser resolver and its table compiler follow the same rules, with the same strict entry check as the server. Only graphs holding the class change their class projection, so only their pending inspection items move; INSPECTION_RESOLVER_VERSION stays 2. * fix(inspect): list a repeated Any Switch outcome once (#657) A switch with three or more inputs can offer one text through two of them (a, b, a). Each input was its own candidate, so one text read as a choice between two, and two equal resolved candidates beside a failed one would count as reviewable. Like an unknown node passing several texts, a first-present divergence now collapses equal outcomes. The browser resolver does the same. The table compiler test also checks the 128-character prefix bound in code points, as Python counts it. * feat(inspect): show a role every candidate shares (#658) An ambiguous file used to withhold both roles, even when every candidate had the same negative. Inspect now judges each role on its own: a role is shown resolved when every candidate is resolved with the same text, stored recipe and left-out parts for it, using the first candidate's text and source. A role that differs, or any unresolved candidate, keeps the ambiguous line, and resolution.state stays ambiguous, so Send pair, ingestion and Needs review behave as before. The browser-local resolver applies the same rule; the footer Send to ComfyUI still needs both roles. A multistage detailer run whose stages share one negative (fixture f19) now shows that negative. * feat(monitor): ask the ladder for PromptManager runs nothing else links A PromptManager output whose metadata and tracked run cannot name its prompt now takes the ladder path foreign outputs use: decided at settle under the monitor policy, or after its run is sealed through the ladder wait. Wait entries carry their run kind; the kind selects the settings gate (SAVE_FOREIGN_RUNS for foreign entries, MONITORING_ENABLED for PromptManager ones) and the marks of a created prompt. Keyless images, placeholder batch entries and unreadable metadata never enter the wait. Every final unlinked outcome hands the file to the review recorder. Refs #659 * test(monitor): pin the final unlinked outcomes that reach Needs review The sweep, joined-text and shared-prefix graphs move to a shared fixture module. New tests pin when the monitor hands a file to its review recorder: after the sealed re-check, a settle lookup that found the run's record, a file outside ComfyUI's output folder and the keyless re-check; never before the run is sealed, and never for a linked file. A PromptManager output waiting for its run now logs that at INFO. Refs #659 * feat(review): offer inspection choices for default-unresolved files Decision.default_unresolved marks a file the default profile itself calls unresolved (a blank positive does not count). With inspection on, record_ambiguous_file now sends such a captured file with a prompt graph straight to the inspection-profile branch: a reviewable ambiguous or saver-anchored result is recorded, anything else is untraced. Apply is unchanged; it re-resolves with the item's recorded profile. Refs #659 * feat(review): one review dispatch and a review worker for monitor outputs review_dispatch holds the scan's per-file Needs review decision and is now also used by the monitor. The scan replaces its inline dispatch with it (and offers default-unresolved files their inspection choices). record_review_file runs the scan's per-file steps for one file, read only: the scan-policy ladder with the sealed history and the recorded-run check. A file the scan would link is skipped; otherwise the dispatch's record outcome is the answer. The monitor queues paths through queue_review_file onto one daemon worker (pm-review-recorder) with a bounded queue that coalesces by path and a bounded deferred set it replays once no job blocker remains. The package teardown stops it right after the monitor and reports it as part review once started. Refs #659 * docs(testing): the monitor queues what the scan would (#659) Rewrite the Needs review paragraph for the 2026-11-19 decision: the final-outcome points, the review worker and its bounds, the deferred replay and the default-unresolved rule. Document the PromptManager-run ladder path, the review step of the package teardown and the proven-value allowlist every future semantics table entry must keep. Refs #659 * fix(review): lock the untraced memory the scan and review worker share Refs #659 * feat(inspect): name the file's Needs review item in the inspection responses Inspect and the run-history current-file inspection gain a review field: {"state": "pending", "item_id": ...} for the newest pending item at the stat the inspection took, {"state": "decided"} once its item was decided, and null otherwise. It is read only when a role is ambiguous and the file is unlinked, by locator and stat (review_item_at), so Inspect never hashes the file. A LoRA root, a failed read and any malformed value give null. Refs #659 * feat(review): a single-item mode for the review controller and a shared option list createReviewController({api, itemId}) holds one named item: it never reads the queue, loads that item's detail, ends in phase decided (decided: true) after a recorded decision or for an item already decided, and re-reads the detail after a review-conflict, review-missing or restore refusal. The queue mode is unchanged. The Sampler context option list moves into renderReviewOptions (review-options.mjs, re-exported by review.mjs), so Needs review and the Inspect picker render the same options without Inspect importing the Needs review page. Refs #659 * feat(inspect): choose the prompt of an ambiguous file in Inspect When the inspection names the file's pending Needs review item, the inspector shows a Choose prompt section after its prompt blocks (Images panel, viewer details, recorded run current file). It reads the item's detail through the review controller's single-item mode: one Sampler context option per candidate (unusable ones disabled with their reason), the chosen option's prompt blocks with Copy and Send, Use this prompt and Leave unresolved over the Needs review apply flow. A recorded decision shows Needs review's toast and re-reads the inspection, so the file shows its link; an item with nothing to choose offers Open in Needs review. Refs #659 * fix(inspect): read the history review item only when Inspect asks The run-history reader locates the file under the scan roots inside the read, so an unambiguous or linked file costs no realpath of the output folders. The docstring names the linked-subfolder limit, and the newest pending item test pins the rowid tie-break. Refs #659 * fix(inspect): end Choose prompt on another read and on a decision made elsewhere The inspector disposes the section when it reads another file, fails or defers, so a decision in flight never re-reads the next file. A decided item hides the section and re-reads the inspection once, also when it was decided in another tab or in Needs review. Refs #659 * test(inspect): the rooted inspect shape gains the review facet Refs #659 * docs(testing): first-present candidates and per-role results (#657, #658) * test(review): keep the review cases ambiguous now that Any Switch resolves Part 1 resolves rgthree's Any Switch, so the sweep fixture links. The review and monitor tests that need a default-unresolved, inspection-ambiguous file now use ambiguous_sweep_graph(): Part A's any_switch_sweep_graph() with its switch class replaced by the never-listed PMTest Unknown Multi (one sweep graph instead of two). A new test pins that the real sweep links at settle from the inspector. Refs #657 #659 * fix(review): start the review worker again after an unexpected error * fix(inspect): pass the inspection refresh to Choose prompt by reference * feat(review): queue an ambiguous file with one readable choice (#657) An ambiguous result is reviewable when at least one candidate carries a resolved prompt (MIN_CHOOSABLE = 1). The sweep with an LLM enhancer on Any Switch any_01 now records an item, by the scan and the monitor, with the run-time branch listed beside the readable one. A file with no choosable candidate still records nothing. * feat(review): collapse too many candidates into the most used prompts (#657) More than 16 distinct candidates no longer make a limited item without choices. The choosable ones are grouped by their positive and negative texts, ordered by group size then first appearance, and the first 16 are kept, one real candidate each. The evidence names collapsed: {shown, total, paths} and the item detail returns it. Limited stays for evidence that cannot be projected or is over 8 MiB. REVIEW_EVIDENCE_VERSION is folded into every item version (default items now carry RESOLVER_VERSION + 1, inspection items fold it into their seed), so the next scan supersedes pending, undecided items of the old shape; decided items are kept. RESOLVER_VERSION, the ingestion's provenance version, is unchanged. * feat(inspect): record the Needs review item when Inspect finds none (#657) When Inspect asks for the review facet (an ambiguous role, an unlinked file under an output root) and no item exists at the inspected stat, the images and History current-file inspections run record_review_file, the review worker's own per-file path, in the executor and read the item again. A file the scan would link or that offers nothing to choose records nothing; a deferred or failed recording leaves review null and a failure is logged, never failing the response. * docs(testing): one readable choice, collapsed candidates, Inspect records (#657) * feat(review): say when a file's prompts were shortened to the most used (#657) The item detail now passes the stored evidence's optional `collapsed` counts ({shown, total, paths}) through to the page, null when absent, malformed, or when the detail was capped for size. Needs review and Inspect's Choose prompt show one line under Sampler context: "Showing the n most used of t prompts in this file." * feat(review): list the image's own prompts first in Link to a prompt (#657) With an empty search the dialog now lists the item's choosable candidates under "From this image" (positive / negative, one per prompt pair), then the Library's prompts under "Library". Choosing one of the image's prompts and pressing Link image applies that candidate by its hash, the same decision as Apply association (new controller.applyCandidate); no negative is asked for, the candidate carries its own. Typing searches the Library only. Items with no choosable candidate show the dialog as before. A refusal stays in the dialog with the server's sentence. * feat(review): load more of the queue on scroll (#657) The Needs review continuation now works like the Images page: an IntersectionObserver (250 px ahead) loads the next page when the end of the queue scrolls into view, and the line reads "40 of 45 images · more load as you scroll" without a button. Nothing loads behind an open dialog or the viewer; when one closes, focus returning to the page checks again. A failed page shows the failure line and a Retry button. Without IntersectionObserver the Load more images button stays. * fix(review): ask the inspection profile when the default choice is partial (#657) With one readable choice enough, a default result with one choice beside unresolved branches was recorded as is, so the inspection profile, which may read those branches (a Qwen image-edit sampler), was never asked and a rescan replaced older inspection items with the poorer default ones. Such a partial result now yields to the inspection result when that offers more choosable candidates. * fix(review): collapse only too many prompts, and apply any offered one (#657) Collapsing triggered on more than 16 distinct candidates, sampler ids included, so twenty samplers sharing three texts lost their run-time branches behind a collapsed note. Now only more than 16 choosable texts collapse; otherwise one candidate per text is kept and the branches without a prompt fill the remaining places, as an ordinary item. Apply's still-offered check compared the chosen hash with a fresh collapse, so a reorder that changed the representatives refused Apply. It now checks every projected, de-duplicated candidate hash (candidate_hashes). * fix(inspect): keep Inspect's recording quiet, bounded and current (#657) A busy capture store (the worker copying a fresh output) is an expected outcome: Inspect logs it at debug level and reads the item once more, also after a failed recording. A file Inspect found unrecordable (the scan would link it, or it offers nothing to choose) is remembered by its locator, stat and review versions, at most 4,096 files, so a repeated Inspect does not copy it again. A pending item of an older item version is recorded again, so the current record supersedes it. * docs(testing): partial default choices, bounded candidates, Inspect recording (#657) * fix(review): Link to a prompt drops an image choice it no longer shows (#657) Typing in the search box hid the "From this image" list but kept its chosen prompt, so Link image applied a candidate the reviewer could no longer see. Typing now drops that choice; Link image waits for a Library prompt and sends a Library link. Emptying the box lists the image's prompts again, none chosen. When the item's detail is read again while the dialog is open, the list follows what it offers now; a chosen prompt no longer offered is dropped with "This prompt is no longer offered for this file. Choose again." applyCandidate says the same when the hash cannot be chosen, and an unanswered apply from the dialog asks to press Link image again. * fix(review): keep the panel in place when Info brings it into view at one column (#657) At one column, Info scrolls the panel into view past the queue, which could bring the continuation into view and load the next page, pushing the panel away. As on the Images page, loading now waits for the reader's next wheel, touch move or key press. * docs(review): say why the review worker's recorder is a lambda * test(review): open the dialog of the D5 dialog test beside the queue (#657) At one column (touch) the review panel follows the queue just above the continuation, so scrolling Link to a prompt… into view brings the continuation within the observer's 250 px margin. The next page then loads before the dialog opens whenever the observer's callback runs first (CI shard 4/4, touch), and the test found no continuation to scroll to. That load is the page working as designed: the reader has reached the end of the queue. The test is about loading behind an open dialog, so it now runs at two columns, where Link sits in the sticky panel beside the queue, and it checks that the continuation is out of range before the dialog opens.
812 lines
35 KiB
Python
812 lines
35 KiB
Python
"""The per-file prompt decision shared by the scan and the monitor (#247).
|
|
|
|
One test per case, named by the ladder step of the design
|
|
(``docs/egm/247-foreign-workflows``). The ladder does no file or database
|
|
I/O: history comes in through ``lookup``.
|
|
"""
|
|
|
|
import json
|
|
import unittest
|
|
import unittest.mock as mock
|
|
|
|
from database.run_attribution import RecordedOutput
|
|
from tests.test_pair_scan import flux_graph, sampled_graph
|
|
from tests.test_prompt_attribution import issue_graph, pair_evidence
|
|
from tests import test_save_to_library as save_tests
|
|
from tests.sweep_graphs import ambiguous_sweep_graph
|
|
from utils import file_prompt
|
|
from utils.file_prompt import Policy, decide_file_prompt, junk_text
|
|
from utils.prompt_inspector import InspectionResult
|
|
|
|
try:
|
|
from tests import inspection_parity as parity
|
|
from tests import saver_anchor_graphs as shapes
|
|
from tests import unknown_node_graphs as switch_graphs
|
|
except ImportError: # pragma: no cover - discover -s tests puts tests/ first
|
|
import inspection_parity as parity
|
|
import saver_anchor_graphs as shapes
|
|
import unknown_node_graphs as switch_graphs
|
|
|
|
SHARED_NAME = "IMG_GEN_00371_.png"
|
|
LORA = "<lora:style:1.00>"
|
|
|
|
|
|
def _decide(
|
|
metadata,
|
|
*,
|
|
policy=Policy.SCAN,
|
|
lookup=None,
|
|
in_output=True,
|
|
file_name=SHARED_NAME,
|
|
file_size=None,
|
|
):
|
|
return decide_file_prompt(
|
|
metadata,
|
|
file_name=file_name,
|
|
file_size=file_size,
|
|
in_output=in_output,
|
|
lookup=lookup,
|
|
policy=policy,
|
|
)
|
|
|
|
|
|
def _graph(graph):
|
|
return {"prompt": json.dumps(graph)}
|
|
|
|
|
|
class _Lookup:
|
|
"""A history lookup that counts its calls."""
|
|
|
|
def __init__(self, saver=None):
|
|
self.calls = 0
|
|
self.found = RecordedOutput(saver, {}) if saver is not None else None
|
|
|
|
def __call__(self):
|
|
self.calls += 1
|
|
return self.found
|
|
|
|
|
|
def _inspected(state, malformed=False):
|
|
resolution = {"state": state, "positive": None, "negative": None}
|
|
return InspectionResult(resolution, malformed=malformed)
|
|
|
|
|
|
def _untraced_by_both():
|
|
"""A sampled graph whose positive no profile traces; the legacy parser does."""
|
|
return mock.patch.object(
|
|
file_prompt, "inspection_resolution", return_value=_inspected("unresolved")
|
|
)
|
|
|
|
|
|
def _gated(graph):
|
|
"""``graph`` past the default profile's node gate, so it is unresolved."""
|
|
graph = dict(graph)
|
|
for index in range(510):
|
|
graph[f"pad{index}"] = {"class_type": "Note", "inputs": {}}
|
|
return graph
|
|
|
|
|
|
def _prompt_manager_branches(prepend="PRE", append="APP"):
|
|
"""Two KSampler branches, each fed by a PromptManagerText string."""
|
|
graph = sampled_graph()
|
|
del graph["1"]
|
|
sampler = graph.pop("3")
|
|
for index, text in enumerate(("a cat", "a dog"), start=1):
|
|
base = index * 10
|
|
graph[str(base)] = {
|
|
"class_type": "PromptManagerText",
|
|
"inputs": {"text": text, "prepend_text": prepend, "append_text": append},
|
|
}
|
|
graph[str(base + 1)] = {
|
|
"class_type": "CLIPTextEncode",
|
|
"inputs": {"text": [str(base), 0]},
|
|
}
|
|
graph[str(base + 2)] = {
|
|
**sampler,
|
|
"inputs": {**sampler["inputs"], "positive": [str(base + 1), 0]},
|
|
}
|
|
return graph
|
|
|
|
|
|
def _numeric_first_branches():
|
|
"""Three branches; the legacy parser's answer (the first) is a number."""
|
|
graph = sampled_graph("2048")
|
|
for index, text in ((5, "a cat"), (6, "a dog")):
|
|
graph[str(index * 10)] = {
|
|
"class_type": "CLIPTextEncode",
|
|
"inputs": {"text": text},
|
|
}
|
|
graph[str(index * 10 + 1)] = {
|
|
**graph["3"],
|
|
"inputs": {**graph["3"]["inputs"], "positive": [str(index * 10), 0]},
|
|
}
|
|
return graph
|
|
|
|
|
|
class TestStepsBeforeResolving(unittest.TestCase):
|
|
def test_step_1_no_metadata_tries_the_recorded_run(self):
|
|
for metadata in ({}, None):
|
|
decision = _decide(metadata)
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertTrue(decision.try_recorded_run)
|
|
self.assertIsNone(decision.unlinked_status)
|
|
self.assertEqual(decision.canonical, {})
|
|
|
|
def test_step_3_neither_prompt_nor_parameters_tries_the_recorded_run(self):
|
|
decision = _decide({"workflow": json.dumps({"nodes": []})})
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertTrue(decision.try_recorded_run)
|
|
self.assertIsNone(decision.unlinked_status)
|
|
self.assertEqual(decision.canonical, {"workflow": {"nodes": []}})
|
|
|
|
def test_strings_are_parsed_and_malformed_ones_kept(self):
|
|
decision = _decide({"prompt": "{not json", "workflow": "{}"})
|
|
self.assertEqual(decision.canonical["prompt"], "{not json")
|
|
self.assertEqual(decision.canonical["workflow"], {})
|
|
|
|
def test_the_file_size_is_recorded_unless_the_metadata_has_one(self):
|
|
meta = _graph(sampled_graph())
|
|
self.assertEqual(
|
|
_decide(meta, file_size=42).canonical["file_info"], {"size": 42}
|
|
)
|
|
meta["file_info"] = {"size": 7, "width": 3}
|
|
self.assertEqual(
|
|
_decide(meta, file_size=42).canonical["file_info"], {"size": 7, "width": 3}
|
|
)
|
|
self.assertNotIn("file_info", _decide(_graph(sampled_graph())).canonical)
|
|
|
|
def test_a_file_size_reader_is_called_only_for_prompt_metadata(self):
|
|
reads = []
|
|
|
|
def size():
|
|
reads.append(1)
|
|
return 9
|
|
|
|
for metadata in ({}, {"workflow": "{}"}):
|
|
_decide(metadata, file_size=size)
|
|
self.assertEqual(reads, [])
|
|
decision = _decide(_graph(sampled_graph()), file_size=size)
|
|
self.assertEqual((reads, decision.canonical["file_info"]), ([1], {"size": 9}))
|
|
|
|
|
|
def _off_behind(middle, key):
|
|
"""A switched-off PromptManagerText reaching the encoder through
|
|
``middle``'s ``key`` input."""
|
|
graph = save_tests.run_graph()
|
|
graph["1"] = {
|
|
"class_type": "PromptManagerText",
|
|
"inputs": {"text": "SECRET OFF TEXT", "save_to_library": False},
|
|
}
|
|
graph["7"] = {"class_type": middle, "inputs": {key: ["1", 0]}}
|
|
graph["8"] = {
|
|
"class_type": "CLIPTextEncode",
|
|
"inputs": {"text": ["7", 0], "clip": ["4", 1]},
|
|
}
|
|
graph["3"]["inputs"]["positive"] = ["8", 0]
|
|
return graph
|
|
|
|
|
|
class TestSaveToLibrarySteps(unittest.TestCase):
|
|
"""#90: a PromptManager node with Save to library off stores nothing."""
|
|
|
|
def test_step_2_an_opted_out_file_is_not_saved(self):
|
|
lookup = _Lookup("9")
|
|
graph = save_tests.run_graph(save=False)
|
|
graph["5"] = {**graph["3"], "inputs": {**graph["3"]["inputs"]}}
|
|
graph["5"]["inputs"]["positive"] = ["2", 0] # ambiguous otherwise
|
|
for policy in Policy:
|
|
decision = _decide(_graph(graph), policy=policy, lookup=lookup)
|
|
self.assertEqual(decision.kind, "not_saved")
|
|
self.assertFalse(decision.try_recorded_run)
|
|
self.assertIsNone(decision.review)
|
|
self.assertEqual(lookup.calls, 0)
|
|
|
|
def test_step_2_a_wired_switch_is_not_saved_wired(self):
|
|
graph = save_tests.run_graph(save=["9", 0])
|
|
graph["9"] = {"class_type": "SomeCustomSwitch", "inputs": {}}
|
|
lookup = _Lookup("9")
|
|
decision = _decide(_graph(graph), lookup=lookup)
|
|
self.assertEqual(decision.kind, "not_saved_wired")
|
|
self.assertFalse(decision.try_recorded_run)
|
|
self.assertIsNone(decision.review)
|
|
self.assertEqual(lookup.calls, 0)
|
|
|
|
def test_step_8_1_an_off_node_behind_a_pass_through_is_not_saved(self):
|
|
"""The #90 graph walk does not follow ``anything`` or ``value``; the
|
|
inspector does, so its positive is checked against the switch."""
|
|
for middle, key in (("easy showAnything", "anything"), ("MyNode", "value")):
|
|
with self.subTest(middle=middle):
|
|
graph = _off_behind(middle, key)
|
|
for policy in Policy:
|
|
decision = _decide(_graph(graph), policy=policy, lookup=_Lookup())
|
|
self.assertEqual(decision.kind, "not_saved")
|
|
self.assertIsNone(decision.text)
|
|
|
|
def test_step_8_4_a_legacy_answer_from_an_off_node_is_not_saved(self):
|
|
graph = _off_behind("MyNode", "value")
|
|
graph["9"] = {"class_type": "CLIPTextEncode", "inputs": {"text": "on text"}}
|
|
graph["5"] = {**graph["3"], "inputs": {**graph["3"]["inputs"]}}
|
|
graph["5"]["inputs"]["positive"] = ["9", 0]
|
|
decision = _decide(_graph(graph), lookup=_Lookup())
|
|
self.assertEqual(decision.kind, "not_saved")
|
|
self.assertIsNone(decision.text)
|
|
|
|
def test_step_2_an_off_node_on_any_positive_input_is_not_saved(self):
|
|
"""Any input name upstream of a positive, not only prompt-like ones."""
|
|
guider = _off_behind("MyNode", "value")
|
|
guider["3"] = {
|
|
"class_type": "BasicGuider",
|
|
"inputs": {"model": ["4", 0], "conditioning": ["8", 0]},
|
|
}
|
|
prepended = _off_behind("MyNode", "value")
|
|
prepended["1"]["inputs"]["prepend_text"] = "pre"
|
|
pair = _off_behind("MyNode", "value")
|
|
pair["1"] = {
|
|
"class_type": "PromptManagerPair",
|
|
"inputs": {"text": "x", "negative_text": "y", "save_to_library": False},
|
|
}
|
|
pair["2"]["inputs"]["text"] = ["1", 1]
|
|
cases = {"sampler-less guider": guider, "prepend": prepended, "pair": pair}
|
|
for name, graph in cases.items():
|
|
with self.subTest(name=name):
|
|
lookup = _Lookup("9")
|
|
decision = _decide(_graph(graph), lookup=lookup)
|
|
self.assertEqual(decision.kind, "not_saved")
|
|
self.assertFalse(decision.try_recorded_run)
|
|
self.assertEqual(lookup.calls, 0)
|
|
|
|
def test_step_2_a_wired_switch_behind_a_pass_through_is_not_saved_wired(self):
|
|
graph = _off_behind("MyNode", "value")
|
|
graph["1"]["inputs"]["save_to_library"] = ["20", 0]
|
|
graph["20"] = {"class_type": "SomeBoolNode", "inputs": {}}
|
|
self.assertEqual(_decide(_graph(graph)).kind, "not_saved_wired")
|
|
|
|
def test_a_switched_on_node_behind_a_pass_through_is_stored(self):
|
|
"""Regression guard: on, or no switch at all (older files)."""
|
|
for value in (True, None):
|
|
with self.subTest(value=value):
|
|
graph = _off_behind("MyNode", "value")
|
|
if value is None:
|
|
del graph["1"]["inputs"]["save_to_library"]
|
|
else:
|
|
graph["1"]["inputs"]["save_to_library"] = value
|
|
decision = _decide(_graph(graph), lookup=_Lookup())
|
|
self.assertEqual(decision.kind, "positive")
|
|
self.assertEqual(decision.text, "SECRET OFF TEXT")
|
|
|
|
def test_an_off_node_on_a_negative_input_name_never_blocks(self):
|
|
"""The walk skips negative inputs: #90's own rule (``neg``,
|
|
``neg_text``, ``text_neg``) and any name containing "negative"."""
|
|
for key in (
|
|
"neg",
|
|
"neg_text",
|
|
"text_neg",
|
|
"negative_text",
|
|
"negative2",
|
|
"negativeprompt",
|
|
"NegativePrompt",
|
|
):
|
|
with self.subTest(key=key):
|
|
graph = {
|
|
"1": {
|
|
"class_type": "PromptManagerText",
|
|
"inputs": {"text": "bad hands", "save_to_library": False},
|
|
},
|
|
"9": {
|
|
"class_type": "PromptManagerText",
|
|
"inputs": {"text": "a cat", "save_to_library": True},
|
|
},
|
|
"7": {
|
|
"class_type": "PipeEncode",
|
|
"inputs": {"pos_text": ["9", 0], key: ["1", 0]},
|
|
},
|
|
"4": {"class_type": "CheckpointLoaderSimple", "inputs": {}},
|
|
"3": {
|
|
"class_type": "KSampler",
|
|
"inputs": {
|
|
"model": ["4", 0],
|
|
"positive": ["7", 0],
|
|
"negative": ["7", 1],
|
|
},
|
|
},
|
|
}
|
|
self.assertIsNone(file_prompt._switched_off_upstream(graph))
|
|
self.assertNotIn(
|
|
_decide(_graph(graph)).kind, ("not_saved", "not_saved_wired")
|
|
)
|
|
|
|
def test_the_guards_accept_malformed_nodes(self):
|
|
graph = {
|
|
"1": {"class_type": "PromptManagerText", "inputs": None},
|
|
"2": {"class_type": "PromptManagerText"},
|
|
}
|
|
self.assertIsNone(file_prompt._off_text(graph, "x"))
|
|
side = {"provenance": ["not", "a", "dict"]}
|
|
with mock.patch.object(file_prompt, "side_opted_out", return_value=True):
|
|
self.assertIsNone(file_prompt._side_switch(graph, side))
|
|
|
|
def test_the_off_text_guard_reads_a_nodes_resolved_text(self):
|
|
graph = {
|
|
"1": {
|
|
"class_type": "PromptManagerText",
|
|
"inputs": {"text": ["30", 0], "save_to_library": False},
|
|
},
|
|
"30": {
|
|
"class_type": "PrimitiveStringMultiline",
|
|
"inputs": {"value": "SECRET OFF TEXT"},
|
|
},
|
|
"2": {
|
|
"class_type": "PromptManagerText",
|
|
"inputs": {"text": "WIRED", "save_to_library": ["9", 0]},
|
|
},
|
|
"9": {"class_type": "SomeBoolNode", "inputs": {}},
|
|
}
|
|
self.assertEqual(file_prompt._off_text(graph, " SECRET OFF TEXT"), "not_saved")
|
|
self.assertEqual(file_prompt._off_text(graph, "WIRED"), "not_saved_wired")
|
|
self.assertIsNone(file_prompt._off_text(graph, "other"))
|
|
|
|
def test_steps_5_and_7_check_the_resolved_positive_too(self):
|
|
"""A resolved positive through an off node the #90 walk missed."""
|
|
cases = {
|
|
"pair": save_tests.run_graph(save=False),
|
|
"negative off": save_tests.run_graph(save=False, negative_save=False),
|
|
}
|
|
for name, graph in cases.items():
|
|
with (
|
|
self.subTest(name=name),
|
|
mock.patch.object(
|
|
file_prompt, "metadata_opted_out", return_value=False
|
|
),
|
|
):
|
|
self.assertEqual(_decide(_graph(graph)).kind, "not_saved")
|
|
|
|
def test_step_5_a_junk_positive_is_never_stored(self):
|
|
"""Pinned: the positive alone still passes the junk gate, and a blank
|
|
positive (never storable) stores nothing either."""
|
|
graph = save_tests.run_graph(save=True, negative_save=False)
|
|
graph["1"]["inputs"]["text"] = "2048"
|
|
decision = _decide(_graph(graph))
|
|
self.assertEqual((decision.kind, decision.source), ("never", "junk:number"))
|
|
self.assertEqual(decision.unlinked_status, "found")
|
|
graph["1"]["inputs"]["text"] = ""
|
|
decision = _decide(_graph(graph))
|
|
self.assertEqual((decision.kind, decision.text), ("never", None))
|
|
|
|
def test_step_2_a_workflow_only_opt_out_comes_before_step_3(self):
|
|
workflow = {
|
|
"nodes": [{"id": 1, "type": "PromptManager", "widgets_values": [False]}]
|
|
}
|
|
decision = _decide({"workflow": json.dumps(workflow)})
|
|
self.assertEqual(decision.kind, "not_saved")
|
|
|
|
def test_step_5_an_opted_out_negative_stores_the_positive_alone(self):
|
|
graph = save_tests.run_graph(save=True, negative_save=False)
|
|
decision = _decide(_graph(graph))
|
|
self.assertEqual(decision.kind, "positive")
|
|
self.assertEqual(decision.source, "opted-out-negative")
|
|
self.assertEqual(decision.text, save_tests.POSITIVE)
|
|
|
|
|
|
class TestResolvedSteps(unittest.TestCase):
|
|
def test_step_6_a_blank_positive_counts_as_unresolved(self):
|
|
meta = {
|
|
"prompt": json.dumps(issue_graph()),
|
|
"comfyassets_prompt_pairs": json.dumps(pair_evidence()),
|
|
}
|
|
decision = _decide(meta, policy=Policy.MONITOR, in_output=False)
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertEqual(decision.resolution["state"], "unresolved")
|
|
|
|
def test_step_7_a_resolved_pair(self):
|
|
lookup = _Lookup("9")
|
|
decision = _decide(_graph(sampled_graph("cat", "blur")), lookup=lookup)
|
|
self.assertEqual(decision.kind, "pair")
|
|
self.assertEqual(decision.source, "resolver")
|
|
self.assertEqual(decision.text, "cat")
|
|
self.assertEqual(decision.resolution["negative"]["text"], "blur")
|
|
self.assertIsNone(decision.review)
|
|
self.assertEqual(lookup.calls, 0, "decided before step 8: history not asked")
|
|
|
|
def test_step_7_a_blank_negative_stays_a_pair(self):
|
|
decision = _decide(_graph(sampled_graph("cat", "")))
|
|
self.assertEqual(decision.kind, "pair")
|
|
self.assertEqual(decision.resolution["negative"]["text"], "")
|
|
|
|
|
|
class TestUndecidedGraph(unittest.TestCase):
|
|
def test_step_8_1_the_inspector_alone_decides(self):
|
|
decision = _decide({"prompt": parity.build("f03")["prompt"]})
|
|
self.assertEqual(decision.kind, "positive")
|
|
self.assertEqual(decision.source, "inspector")
|
|
self.assertEqual(decision.text, parity.POS)
|
|
self.assertEqual(decision.resolution["state"], "unresolved")
|
|
|
|
def test_step_8_1_the_inspector_links_the_any_switch_sweep(self):
|
|
# #657: the default profile cannot read rgthree's Any Switch; the
|
|
# inspector proves its first input and links it under both policies.
|
|
graph = switch_graphs.any_switch_sweep_graph()
|
|
for policy in (Policy.SCAN, Policy.MONITOR):
|
|
with self.subTest(policy=policy):
|
|
decision = _decide(_graph(graph), policy=policy, lookup=_Lookup())
|
|
self.assertEqual(decision.kind, "positive")
|
|
self.assertEqual(decision.source, "inspector")
|
|
self.assertEqual(decision.text, switch_graphs.POSITIVE)
|
|
|
|
def test_step_8_1_the_recorded_saver_names_its_branch(self):
|
|
lookup = _Lookup("23")
|
|
decision = _decide(_graph(shapes.shared_prefix()), lookup=lookup)
|
|
self.assertEqual(decision.kind, "positive")
|
|
self.assertEqual(decision.source, "recorded-run")
|
|
self.assertEqual(decision.text, shapes.BRANCH_TEXTS[1])
|
|
self.assertEqual(decision.review, "ambiguous")
|
|
self.assertEqual(lookup.calls, 1)
|
|
|
|
def test_step_8_1_stores_the_storage_text_without_prepend_or_append(self):
|
|
graph = shapes.shared_prefix()
|
|
graph["20"]["inputs"]["text"] = ["25", 1]
|
|
graph["25"] = {
|
|
"class_type": "PromptManagerSplit",
|
|
"inputs": {
|
|
"text": shapes.BRANCH_TEXTS[1],
|
|
"prepend_text": "trigger",
|
|
"append_text": "detail",
|
|
},
|
|
}
|
|
decision = _decide(_graph(graph), lookup=_Lookup("23"))
|
|
self.assertEqual(decision.source, "recorded-run")
|
|
self.assertEqual(decision.text, shapes.BRANCH_TEXTS[1])
|
|
|
|
def test_step_8_1_a_file_name_naming_another_saver_anchors_nothing(self):
|
|
graph = shapes.branch_bench()
|
|
for index in (1, 3, 4):
|
|
graph[str(index * 10 + 3)]["inputs"]["filename_prefix"] = "bench/shared"
|
|
decision = _decide(
|
|
_graph(graph), lookup=_Lookup("43"), file_name="s45_branch_2_00001_.png"
|
|
)
|
|
# The name contradicts history's branch 4: no recorded anchor.
|
|
self.assertEqual(decision.source, "legacy-parser")
|
|
|
|
def test_step_8_1_the_file_name_anchor_alone_never_decides(self):
|
|
"""#390: the file-name anchor never decides a link. The scan's legacy
|
|
floor may still link the file (as before #247), and a file nothing
|
|
links is queued with the anchor's choice per #390; the monitor
|
|
stores nothing."""
|
|
name = "s45_branch_2_00001_.png"
|
|
scan = _decide(_graph(shapes.branch_bench()), lookup=_Lookup(), file_name=name)
|
|
self.assertEqual((scan.kind, scan.source), ("positive", "legacy-parser"))
|
|
self.assertEqual(scan.review, "ambiguous")
|
|
monitor = _decide(
|
|
_graph(shapes.branch_bench()),
|
|
policy=Policy.MONITOR,
|
|
lookup=_Lookup(),
|
|
file_name=name,
|
|
)
|
|
self.assertEqual(monitor.kind, "never")
|
|
recorded = _decide(
|
|
_graph(shapes.branch_bench()), lookup=_Lookup("43"), file_name=name
|
|
)
|
|
# The recorded saver still decides: history says branch 4, but the
|
|
# file name names branch 2, which contradicts it.
|
|
self.assertNotEqual(recorded.source, "recorded-run")
|
|
recorded = _decide(_graph(shapes.branch_bench()), lookup=_Lookup("43"))
|
|
self.assertEqual(recorded.source, "recorded-run")
|
|
self.assertEqual(recorded.text, shapes.BRANCH_TEXTS[3])
|
|
|
|
def test_step_8_2_the_monitor_waits_for_history_inside_the_output_folder(self):
|
|
decision = _decide(_graph(shapes.shared_prefix()), policy=Policy.MONITOR)
|
|
self.assertEqual(decision.kind, "history")
|
|
|
|
def test_step_8_2_outside_the_output_folder_steps_8_3_and_8_4_apply(self):
|
|
decision = _decide(
|
|
_graph(shapes.shared_prefix()), policy=Policy.MONITOR, in_output=False
|
|
)
|
|
self.assertEqual(decision.kind, "never")
|
|
with _untraced_by_both():
|
|
decision = _decide(
|
|
_graph(_gated(sampled_graph())), policy=Policy.MONITOR, in_output=False
|
|
)
|
|
self.assertEqual(
|
|
(decision.kind, decision.source), ("positive", "legacy-parser")
|
|
)
|
|
|
|
def test_step_8_3_an_ambiguous_file_is_left_unlinked_by_the_monitor(self):
|
|
lookup = _Lookup("missing")
|
|
decision = _decide(
|
|
_graph(shapes.shared_prefix()), policy=Policy.MONITOR, lookup=lookup
|
|
)
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertEqual(decision.unlinked_status, "ambiguous")
|
|
self.assertFalse(decision.try_recorded_run)
|
|
self.assertEqual(lookup.calls, 1)
|
|
|
|
def test_step_8_4_joined_prompt_manager_text_is_never_the_legacy_answer(self):
|
|
"""The legacy parser returns prepend + text + append; the stored text
|
|
of a PromptManager node cannot be told from it."""
|
|
decision = _decide(_graph(_prompt_manager_branches()), lookup=_Lookup())
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertEqual(decision.unlinked_status, "ambiguous")
|
|
self.assertEqual(decision.review, "ambiguous")
|
|
self.assertTrue(decision.try_recorded_run)
|
|
# A linked part the parser does not follow: its answer is the node's
|
|
# own text, which is what the node stores (#170 parity).
|
|
linked = _prompt_manager_branches(prepend=["99", 0], append="")
|
|
decision = _decide(_graph(linked), lookup=_Lookup())
|
|
self.assertEqual((decision.kind, decision.text), ("positive", "a cat"))
|
|
|
|
def test_step_8_4_prompt_manager_text_without_parts_keeps_the_floor(self):
|
|
"""Regression guard (passes on the base): no prepend or append."""
|
|
graph = _prompt_manager_branches(prepend="", append=" ")
|
|
decision = _decide(_graph(graph), lookup=_Lookup())
|
|
self.assertEqual((decision.kind, decision.text), ("positive", "a cat"))
|
|
|
|
def test_step_8_4_an_ambiguous_file_gets_the_legacy_answer_in_the_scan(self):
|
|
decision = _decide(_graph(shapes.shared_prefix()), lookup=_Lookup())
|
|
self.assertEqual(decision.kind, "positive")
|
|
self.assertEqual(decision.source, "legacy-parser")
|
|
self.assertEqual(decision.text, shapes.BRANCH_TEXTS[0])
|
|
self.assertEqual(decision.review, "ambiguous")
|
|
|
|
def test_step_8_4_an_untraceable_file_gets_the_legacy_answer_in_both(self):
|
|
for policy in Policy:
|
|
for inspected in (_inspected("unresolved"), _inspected("x", True)):
|
|
with (
|
|
self.subTest(policy=policy, malformed=inspected.malformed),
|
|
mock.patch.object(
|
|
file_prompt, "inspection_resolution", return_value=inspected
|
|
),
|
|
):
|
|
decision = _decide(
|
|
_graph(_gated(sampled_graph("cat"))),
|
|
policy=policy,
|
|
lookup=_Lookup(),
|
|
)
|
|
self.assertEqual(decision.kind, "positive")
|
|
self.assertEqual(decision.source, "legacy-parser")
|
|
self.assertEqual(decision.text, "cat")
|
|
|
|
def test_step_8_4_nothing_traced_tries_the_recorded_run(self):
|
|
graph = sampled_graph()
|
|
graph["5"] = {**graph["3"]}
|
|
for sampler in ("3", "5"):
|
|
graph[sampler]["inputs"]["positive"] = ["9", 0]
|
|
graph["9"] = {"class_type": "BasicGuider", "inputs": {"width": 2048}}
|
|
decision = _decide(_graph(graph), lookup=_Lookup())
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertTrue(decision.try_recorded_run)
|
|
# Ambiguous without a choice is reported unresolved.
|
|
self.assertEqual(decision.unlinked_status, "unresolved")
|
|
self.assertEqual(decision.review, "untraced")
|
|
|
|
|
|
def _search_list(text="fox", side="positive"):
|
|
"""f22: a PromptSearchList batch (no PromptManager node) feeds CLIPTextEncode."""
|
|
graph = parity.build("f22")["prompt"]
|
|
graph["10"]["inputs"]["text"] = text
|
|
if side == "negative":
|
|
# The search feeds the negative; the positive is typed text.
|
|
graph["6"]["inputs"]["text"] = parity.POS
|
|
graph["7"]["inputs"]["text"] = ["10", 0]
|
|
return graph
|
|
|
|
|
|
class TestSearchTextIsNeverAPrompt(unittest.TestCase):
|
|
"""#548: the PromptSearchList query is a search, never the prompt."""
|
|
|
|
def test_the_search_text_is_never_linked_or_stored(self):
|
|
for policy in Policy:
|
|
with self.subTest(policy=policy):
|
|
decision = _decide(
|
|
_graph(_search_list()), policy=policy, lookup=_Lookup()
|
|
)
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertIsNone(decision.text)
|
|
self.assertEqual(decision.unlinked_status, "unresolved")
|
|
self.assertTrue(decision.try_recorded_run)
|
|
|
|
def test_a_search_text_from_a_primitive_is_never_linked(self):
|
|
graph = _search_list()
|
|
graph["10"]["inputs"]["text"] = ["30", 0]
|
|
graph["30"] = {"class_type": "PrimitiveString", "inputs": {"value": "fox"}}
|
|
for policy in Policy:
|
|
with self.subTest(policy=policy):
|
|
decision = _decide(_graph(graph), policy=policy, lookup=_Lookup())
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertIsNone(decision.text)
|
|
|
|
def test_an_empty_search_text_is_unchanged(self):
|
|
"""Regression guard (passes on the base): nothing to exclude."""
|
|
for policy in Policy:
|
|
with self.subTest(policy=policy):
|
|
decision = _decide(
|
|
_graph(_search_list("")), policy=policy, lookup=_Lookup()
|
|
)
|
|
self.assertEqual((decision.kind, decision.text), ("never", None))
|
|
|
|
def test_without_a_sampler_any_search_list_query_is_excluded(self):
|
|
graph = _search_list()
|
|
del graph["3"]
|
|
self.assertTrue(file_prompt._search_text(graph, " fox "))
|
|
self.assertFalse(file_prompt._search_text(graph, "a fox"))
|
|
self.assertFalse(file_prompt._search_text(None, "fox"))
|
|
|
|
def test_a_search_on_the_negative_keeps_the_typed_positive(self):
|
|
"""Regression guard (passes on the base): only the positive's source
|
|
is excluded, so the legacy answer from typed text still links."""
|
|
graph = _search_list(side="negative")
|
|
decision = _decide(_graph(graph), lookup=_Lookup())
|
|
self.assertEqual((decision.kind, decision.text), ("positive", parity.POS))
|
|
self.assertEqual(decision.source, "legacy-parser")
|
|
|
|
|
|
class TestStepsWithoutAnUndecidedGraph(unittest.TestCase):
|
|
def test_step_9_ambiguous_parameters_only(self):
|
|
meta = {
|
|
"parameters": (
|
|
"cat\nNegative prompt: blur\nNegative prompt: noise"
|
|
"\nSteps: 20, Sampler: Euler"
|
|
)
|
|
}
|
|
decision = _decide(meta)
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertFalse(decision.try_recorded_run)
|
|
self.assertEqual(decision.unlinked_status, "unresolved")
|
|
|
|
def test_step_10_unresolved_without_a1111_text(self):
|
|
decision = _decide({"prompt": {}, "parameters": 5})
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertFalse(decision.try_recorded_run)
|
|
self.assertEqual(decision.unlinked_status, "unresolved")
|
|
|
|
def test_step_11_sampler_less_with_one_text(self):
|
|
decision = _decide(_graph(flux_graph()))
|
|
self.assertEqual((decision.kind, decision.source), ("positive", "sampler-less"))
|
|
self.assertEqual(decision.text, "a red fox")
|
|
|
|
def test_step_11_sampler_less_with_several_texts(self):
|
|
graph = flux_graph()
|
|
graph["50"] = {
|
|
"class_type": "Lora Loader (LoraManager)",
|
|
"inputs": {"model": ["1", 0], "clip": ["2", 0], "text": "a lora note"},
|
|
}
|
|
graph["22"]["inputs"]["model"] = ["50", 0]
|
|
graph["6"]["inputs"]["clip"] = ["50", 1]
|
|
decision = _decide(_graph(graph))
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertTrue(decision.try_recorded_run)
|
|
self.assertEqual(decision.unlinked_status, "unresolved")
|
|
meta = {**_graph(graph), "parameters": "a red fox\nNegative prompt: x"}
|
|
decision = _decide(meta)
|
|
self.assertEqual((decision.kind, decision.source), ("positive", "a1111"))
|
|
self.assertEqual(decision.text, "a red fox")
|
|
|
|
def test_step_11_sampler_less_without_a_text(self):
|
|
graph = {"40": {"class_type": "easy showAnything", "inputs": {"text": "x"}}}
|
|
decision = _decide(_graph(graph))
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertTrue(decision.try_recorded_run)
|
|
self.assertEqual(decision.unlinked_status, "found")
|
|
|
|
def test_step_12_a1111_only(self):
|
|
decision = _decide({"parameters": "a cat"})
|
|
self.assertEqual((decision.kind, decision.source), ("positive", "a1111"))
|
|
self.assertEqual(decision.text, "a cat")
|
|
decision = _decide({"parameters": "Negative prompt: blur"})
|
|
self.assertEqual((decision.kind, decision.unlinked_status), ("never", "found"))
|
|
self.assertFalse(decision.try_recorded_run)
|
|
|
|
def test_step_12_parsed_metadata_never_raises(self):
|
|
# The monitor hands parsed values: a dict prompt, non-string parameters.
|
|
decision = _decide({"prompt": {}, "parameters": "a cat"})
|
|
self.assertEqual(decision.text, "a cat")
|
|
decision = _decide({"parameters": 5})
|
|
self.assertEqual((decision.kind, decision.unlinked_status), ("never", "found"))
|
|
|
|
|
|
class TestJunkGate(unittest.TestCase):
|
|
JUNK = {
|
|
"blank": " ",
|
|
"number": "2048",
|
|
"lora-only": f"{LORA}, <lora:detail:0.5> |",
|
|
"model-file": "models/checkpoints/Flux-Dev.SafeTensors",
|
|
}
|
|
|
|
def test_each_junk_class_is_named(self):
|
|
for name, text in self.JUNK.items():
|
|
with self.subTest(name=name):
|
|
self.assertEqual(junk_text(text), name)
|
|
for ending in ("ckpt", "pt", "pth", "bin", "gguf", "sft"):
|
|
self.assertEqual(junk_text(f"model.{ending}"), "model-file")
|
|
|
|
def test_near_misses_are_not_junk(self):
|
|
for text in (
|
|
f"a red fox {LORA}",
|
|
"a.safetensors b.safetensors",
|
|
"nan",
|
|
"a portrait saved as final.safetensors",
|
|
"4k",
|
|
"C:\\My Models\\x.safetensors",
|
|
):
|
|
with self.subTest(text=text):
|
|
self.assertIsNone(junk_text(text))
|
|
|
|
def test_step_13_junk_from_any_step_is_never_stored(self):
|
|
cases = {
|
|
"resolver": _graph(sampled_graph("2048", "blur")),
|
|
"sampler-less": _graph(flux_graph(text=LORA)),
|
|
"a1111": {"parameters": "model.safetensors"},
|
|
}
|
|
for step, meta in cases.items():
|
|
with self.subTest(step=step):
|
|
decision = _decide(meta)
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertTrue(decision.source.startswith("junk:"), decision.source)
|
|
self.assertTrue(decision.try_recorded_run)
|
|
self.assertEqual(decision.unlinked_status, "found")
|
|
|
|
def test_step_13_a_junk_legacy_answer_is_never_stored(self):
|
|
with _untraced_by_both():
|
|
decision = _decide(_graph(_gated(sampled_graph(LORA))), lookup=_Lookup())
|
|
self.assertEqual(decision.source, "junk:lora-only")
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertEqual(decision.unlinked_status, "unresolved")
|
|
|
|
def test_step_13_junk_at_step_8_keeps_that_steps_status_and_review(self):
|
|
# An ambiguous file whose legacy answer is a number is still a
|
|
# Needs review case: its status stays "ambiguous".
|
|
decision = _decide(_graph(_numeric_first_branches()), lookup=_Lookup())
|
|
self.assertEqual((decision.kind, decision.source), ("never", "junk:number"))
|
|
self.assertEqual(decision.unlinked_status, "ambiguous")
|
|
self.assertEqual(decision.review, "ambiguous")
|
|
self.assertTrue(decision.try_recorded_run)
|
|
|
|
|
|
class TestParseComfyuiPrompt(unittest.TestCase):
|
|
def test_a_parsed_prompt_and_non_string_values_are_kept(self):
|
|
parsed = file_prompt.parse_comfyui_prompt(
|
|
{"prompt": {"1": {}}, "workflow": {"nodes": []}, "steps": 20}
|
|
)
|
|
self.assertEqual(parsed["prompt"], {"1": {}})
|
|
self.assertEqual(parsed["workflow"], {"nodes": []})
|
|
self.assertEqual(parsed["parameters"]["steps"], 20)
|
|
self.assertIsNone(parsed["positive_prompt"])
|
|
|
|
def test_non_string_parameters_are_ignored(self):
|
|
parsed = file_prompt.parse_comfyui_prompt({"parameters": {"a": 1}})
|
|
self.assertIsNone(parsed["positive_prompt"])
|
|
|
|
|
|
class TestDefaultUnresolved(unittest.TestCase):
|
|
"""#659 C2: ``default_unresolved`` marks a graph the default profile
|
|
itself calls unresolved, so a scan can still offer its inspection
|
|
choices in Needs review."""
|
|
|
|
def test_the_sweep_graph_is_default_unresolved(self):
|
|
decision = _decide(_graph(ambiguous_sweep_graph()), lookup=_Lookup())
|
|
self.assertEqual(decision.kind, "never")
|
|
self.assertIsNone(decision.review)
|
|
self.assertTrue(decision.default_unresolved)
|
|
self.assertEqual(decision.unlinked_status, "unresolved")
|
|
|
|
def test_a_blank_positive_is_not_default_unresolved(self):
|
|
meta = {
|
|
"prompt": json.dumps(issue_graph()),
|
|
"comfyassets_prompt_pairs": json.dumps(pair_evidence()),
|
|
}
|
|
decision = _decide(meta, lookup=_Lookup())
|
|
self.assertEqual(decision.resolution["state"], "unresolved")
|
|
self.assertFalse(decision.default_unresolved)
|
|
|
|
def test_resolved_and_ambiguous_graphs_are_not_default_unresolved(self):
|
|
for name, graph in (
|
|
("resolved", sampled_graph("cat", "blur")),
|
|
("ambiguous", shapes.shared_prefix()),
|
|
):
|
|
with self.subTest(name=name):
|
|
decision = _decide(_graph(graph), lookup=_Lookup())
|
|
self.assertFalse(decision.default_unresolved)
|
|
self.assertFalse(_decide({}).default_unresolved)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|