* feat(inspector): use recorded run history when the graph alone can't name the prompt (#386) When a file's own graph leaves the prompt open, both inspect routes ask recorded run history about the file (one run reported it and it was written during that run). The save node that run reported it from anchors the walk like a file-name match, so dataset branches that share one saver prefix show their own prompt, labelled "Recorded run". Still open at one sampler whose PromptManager text was recorded at execution (a language model's output), the recorded text shows as "Execution recorded". Results the file resolves alone never change; a failed lookup judges the file alone. * fix(inspector): recorded texts follow history's saver; conflicts anchor nothing (#386) Review follow-ups: the texts PromptManager recorded are looked up at the sampler history's saver leads to, never at a sampler the unanchored walk named; a file name naming a different saver than history anchors nothing; outputs and texts are read in one transaction; "Recorded run" ranks below every workflow-inferred source; unexpected lookup errors log at error level. * fix(history): look up recorded runs by history's own spelling of the file (#386) The history route inspects a case-normalized target on Windows, while history matches file names exactly, so the occurrence's reference names the file. * refactor(inspector): share the inspector's resolve as inspection_resolution inspect_prompt_evidence now calls inspection_resolution, which returns the resolution to use, the anchored result and whether the recorded saver chose it. Ingestion can call the same helper for files the default profile cannot decide (#247). * feat(ingestion): one per-file prompt decision for the scan and the monitor utils/file_prompt.py holds decide_file_prompt, the ladder the output scan runs today plus the inspector's rule (inspection profile, then the recorded saver) before the legacy parser, with a SCAN and a MONITOR policy. Junk text (blank, numbers, LoRA tags only, model file names) is never stored. graph_prompt_text and parse_comfyui_prompt move here; the parser accepts parsed metadata (#247). * feat(ingestion): store a file's prompt in one transaction, one prompt per file database/scanned_prompts.py links a file to the prompt of one text, creating it when new, inside one BEGIN IMMEDIATE transaction: a file linked to another prompt is a conflict, a failed link leaves no prompt behind and two writers store one prompt. pair_ingestion gains file_link_rows, link_conflict and Marks/mark_created; ingest_resolved_pair takes optional marks for the components it creates. recorded_runs and named_prompt in run_attribution become public (#247). * feat(scan): decide each scanned file with the shared ladder (#247) _ingest_scanned_file calls decide_file_prompt (scan policy) and stores the result: pairs through ingest_resolved_pair and positives through store_scanned_prompt, both with the scan marks. Files the default profile leaves undecided now get the inspector's resolve, with the saver recorded history names, before the legacy parser, so each branch of a shared-prefix dataset run links its own prompt. Junk text is never stored, a file linked to another prompt is a conflict instead of a second link, and a failed link leaves no prompt behind. _BatchHistory reads the stored prompt and the recorded saver from one recorded_runs pass. _parse_comfyui_prompt calls the moved parse_comfyui_prompt. TESTING.md documents the decision. * fix(ingestion): keep the file-name saver anchor out of the ladder (#390) The #390 ruling queues a file that only its saver's file name resolves for Needs review, never linking it. inspection_resolution gains name_anchor; the ladder passes False, so such a file falls to the legacy floor in the scan (and to Needs review) and is never stored by the monitor, while the recorded saver still decides. The inspector keeps the name anchor. * feat(config): gallery.monitoring.save_foreign_runs, default on (#247) * fix(ingestion): no joined PromptManager text from the legacy floor; junk keeps its step's status The legacy parser returns prepend + text + append, so its answer is refused when a PromptManager-family node has a prepend or append part (#343). Junk found at the undecided-graph step keeps that step's unlinked status and review, so an ambiguous file is still queued for Needs review. The monitor policy's ambiguous file no longer asks for the recorded run, and the file size may be read lazily. * fix(ingestion): keep the legacy answer that is a PromptManager node's own text The joined-text refusal also refused the #170 parity files whose PromptManager prepend is a link the browser parser does not follow: its answer is then the node's literal text, which is what the node stores. Refuse only an answer that is not such a node's own text. * feat(monitor): store the certain prompt of a foreign workflow's output (#247) A foreign output (no positive PromptManager node) is decided by the shared ladder with the MONITOR policy. Certain files are stored at settle with RUN_MARKS through survive_switch; files only recorded history can decide wait in their own bounded set and are re-checked once after the run's outputs are sealed, with the sealed reference. The setting GalleryConfig.SAVE_FOREIGN_RUNS is read for every file. * fix(scan): one prompt per file for recorded-run links; writes survive a library move The recorded run's stored prompt now links in one transaction with the file's link rows, so a file linked to another prompt is a conflict instead of a second link. The scan's stores run through survive_library_switch. A single file asks history once (a one-file _BatchHistory), the scan passes in_output=False and reads the file size only for files with prompt metadata. A conflict row reads "Kept: already linked to a different prompt". TESTING.md records the rules. * feat(settings): save_foreign_runs through POST /settings, applied live (#247) GET /settings reports settings.save_foreign_runs; a save takes a strict bool, writes gallery.monitoring.save_foreign_runs and publishes it to GalleryConfig in the commit, with no restart field. The diagnostics report lists it. The legacy contract snapshot gains the added key (an addition, no legacy key moves). * feat(system): Save prompts from other workflows in Sources & scans (#247, D147) A host setting row below Watch for new outputs drafts save_foreign_runs and saves with the one Save row; the server applies it at once, so no restart is named. While monitoring is drafted off the row is disabled and says it applies while Watch for new outputs is on. The concept comparison maps the inserted row and its mutation check covers it. * test(comfyui): a workflow of ComfyUI's own nodes creates and links its prompt (#247) The real-host attribution spec gains the foreign case (CLIPTextEncode, KSampler, SaveImage): its prompt is created and linked at settle and a second run links to the same prompt. The fixture route lists the waiting foreign files. TESTING.md records the monitor's foreign path and D147. * test(vendor): the execution matrix counts the #247 real-host case * fix(monitor): read a foreign file's size only when the ladder needs it (#247) Uses PR 1's lazy file size and pins that a foreign file linked to another prompt keeps its one link on the pair and the positive store paths. * fix(ingestion): match a file's link rows under its resolved spelling too The scan stores realpath spellings and the monitor the watcher's raw path, so a file reached through a symlinked or junction output folder could get a second generated_images row. file_link_rows now queries the path and its realpath (each normalized and raw) and dedupes by row id. TESTING.md notes the reverse order is matched only when the raw spelling is the realpath. * fix(monitor): wait for the run unless history answered; monitoring off stops foreign writes (#247) Review fixes: at settle a certain answer ends the wait only when the lookup found a record or the answer is the inspector's or the recorded saver's; the legacy floor waits for the re-check. A record without a certain prompt ends the wait at once. Foreign writes need both save_foreign_runs and monitoring_enabled, read again just before the store. Dropped foreign files are logged outside the lock (evictions as evictions, due ones too), and a drained re-check never drops a newer reference. * fix(system): the foreign row can be set while the monitor still watches; its note describes it (#247, D147) Review fixes: while monitoring is saved off but a source still reads watching until restart (D128), the row stays enabled with its note; the note is the switch's aria-describedby. The browser spec restores save_foreign_runs on the shared server. TESTING.md moves D147 into order and records the monitor's review rules. * test(comfyui): each branch of a shared-prefix foreign run links to its own prompt (#247 CUJ 1) * fix(ingestion): a switched-off PromptManager node behind a pass-through stores nothing (#90) The #90 graph walk follows only prompt-like inputs, so a PromptManagerText with Save to library off reaching the encoder through another input name (easy showAnything.anything, a custom node's value) was invisible to it, and the inspector's resolve stored its text. The ladder now checks the positive every step names: a resolved or inspected positive whose path passes a node that is off, or a legacy answer that is such a node's own text, makes the file not_saved. * fix(ingestion): any switched-off node upstream of a positive stores nothing (#90) The ladder walks every input upstream of each sampler or guider positive (not negative, model, clip, latent or image inputs) for PromptManager nodes whose Save to library is off or wired from an unreadable node, so the sampler-less step, an off node with a prepend part and a PromptManagerPair behind a pass-through no longer store its text. The legacy-floor guard reads a node's resolved text. Every guard reports not_saved for a switch that is off and not_saved_wired for one it cannot read. * fix(ingestion): the switch walk skips negative inputs by #90's own rule The upstream walk treated only names containing "negative" as negative, so an off node on a neg, neg_text or text_neg input blocked an enabled positive. prompt_graph gains is_negative_input (the _NEGATIVE_KEY rule, also used by follows_input) and the walk uses it. The guards accept a node with null inputs and a side whose provenance is not an object. * fix(ingestion): the switch walk also skips any input named with "negative" #90's rule matches only whole underscore-separated words, so negative2, negativeprompt and NegativePrompt counted as positive inputs and an off node wired only to one of them blocked the file. The walk skips those too; follows_input is unchanged. * fix(monitor): a foreign not_saved decision logs its skip and never waits (#247, #90) The foreign path stored nothing for a ladder not_saved decision, but logged it as "No certain prompt" and, when only the legacy answer was a switched-off node's text, kept the file waiting for a seal that could only store nothing. Such a decision now ends the wait at settle, and both settle and the re-check log the opted-out path's own line (a wired switch says so). Tests cover an only-PromptManager node switched off (opted out, not foreign), a switched-off PromptManagerText behind a pass-through into a core CLIPTextEncode, a wired switch, a negative-only switched-off node, recorded history holding the off text, and foreign saving off. * fix(monitor): an undecided not_saved waits for its run's record (#247, #90) A not_saved from the ladder's undecided step is not final before a record exists: the recorded saver may still resolve another branch. The settle lookup now keeps such a file waiting; with the record it stores nothing and logs the opted-out line. An early not_saved (a switched-off node upstream of any sampler's positive) never reaches the lookup and stays final. Tests: the undecided case (literal and wired switch) waits, then skips; a switched-off node feeding one branch of a shared-prefix run never waits and stores nothing, not even the branch the recorded saver names. * docs(system): renumber the foreign-runs switch deviation to D158 (#247) #430 took D147 on main; the Save prompts from other workflows row is D158. * test(monitor): a switched-off node in the recorded saver's branch is never foreign (#247, #90) PR 3's repair skips a file whose recorded saver's branch reads a switched-off PromptManager node. On the monitor the same shape never reaches the foreign path: a literal switch is the opted-out path's and a wired one the node's own run's. Nothing is stored at settle or after the run, even from a recorded run holding the off text.
331 lines
15 KiB
Python
331 lines
15 KiB
Python
"""#247 PR 2 x #90: the monitor's foreign path never stores switched-off text.
|
|
|
|
A file whose run's prompt has Save to library off is the opted-out path's,
|
|
not the foreign path's; a foreign graph whose ladder decision is
|
|
``not_saved`` (a switched-off node the #90 walk does not reach) stores
|
|
nothing at settle, at the re-check after the seal, or from recorded history,
|
|
and leaves no wait behind.
|
|
"""
|
|
|
|
import os
|
|
import unittest
|
|
|
|
from tests import saver_anchor_graphs as shapes
|
|
from tests import test_run_attribution as attribution
|
|
from tests import test_save_to_library as save_tests
|
|
from tests.test_pair_scan import sampled_graph
|
|
from utils.foreign_runs import ForeignRecheck
|
|
from utils.hashing import generate_prompt_hash
|
|
from py.config import GalleryConfig # after tests: it stubs the host
|
|
|
|
LOGGER = "prompt_manager.image_monitor"
|
|
OFF_TEXT = "SECRET OFF TEXT"
|
|
SKIPPED = "Save to library is off for this run's prompt, skipping image"
|
|
|
|
# The class dict, not the class: a TestCase bound here would run again
|
|
Fixture = vars(attribution.TestMonitorForeignRuns)
|
|
|
|
|
|
def off_behind(middle="MyNode", key="value"):
|
|
"""A switched-off PromptManagerText reaching a core CLIPTextEncode through
|
|
``middle``'s ``key`` input: the #90 walk does not follow ``key``."""
|
|
graph = save_tests.run_graph()
|
|
graph["1"] = {
|
|
"class_type": "PromptManagerText",
|
|
"inputs": {"text": 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
|
|
|
|
|
|
def off_text_unwired():
|
|
"""Only history can decide; the legacy answer is a dangling switched-off
|
|
node's own text (the ladder says ``not_saved`` once it may ask history)."""
|
|
graph = sampled_graph("unused", "blurry")
|
|
graph["1"]["inputs"]["text"] = ["30", 0]
|
|
graph["30"] = {"class_type": "VendorPromptMaker", "inputs": {"prompt": OFF_TEXT}}
|
|
graph["40"] = {
|
|
"class_type": "PromptManagerText",
|
|
"inputs": {"text": OFF_TEXT, "save_to_library": False},
|
|
}
|
|
return graph
|
|
|
|
|
|
class TestForeignPathKeepsSaveToLibrary(attribution.RecordedRuns, unittest.TestCase):
|
|
setUp = Fixture["setUp"]
|
|
close_databases = Fixture["close_databases"]
|
|
wait_for = Fixture["wait_for"]
|
|
image = Fixture["image"]
|
|
linked_text = Fixture["linked_text"]
|
|
key = Fixture["key"]
|
|
prompt_count = Fixture["prompt_count"]
|
|
settled = Fixture["settled"]
|
|
|
|
def reference(self, path):
|
|
return {
|
|
"folder_type": "output",
|
|
"subfolder": "dataset",
|
|
"filename": os.path.basename(path),
|
|
}
|
|
|
|
def seal(self, path, positives=(), nodes=("9",)):
|
|
"""Record one run reporting ``path`` (a new run id for every call)."""
|
|
self.runs = getattr(self, "runs", -1) + 1
|
|
self.record_run(
|
|
self.db,
|
|
self.output,
|
|
[("dataset", os.path.basename(path))],
|
|
list(positives),
|
|
item=self.runs,
|
|
nodes=list(nodes),
|
|
)
|
|
|
|
def recheck(self, path):
|
|
"""The re-check the seal schedules, run through the monitor's entry."""
|
|
with self.assertLogs(LOGGER, "INFO") as logs:
|
|
self.handler.process_new_image(path, ForeignRecheck(self.reference(path)))
|
|
return "\n".join(logs.output)
|
|
|
|
def assert_nothing_stored(self, path):
|
|
self.assertIsNone(self.linked_text(path))
|
|
self.assertEqual(self.prompt_count(), 0)
|
|
self.assertIsNone(self.db.get_prompt_by_hash(generate_prompt_hash(OFF_TEXT)))
|
|
self.assertEqual(self.handler.awaiting_foreign(), [])
|
|
self.assertEqual(list(self.handler._foreign_due), [])
|
|
|
|
def test_q1_the_only_prompt_manager_node_off_is_opted_out_not_foreign(self):
|
|
graph = save_tests.run_graph(save=False)
|
|
# The switched-off positive is the only PromptManager node
|
|
graph["2"] = {"class_type": "CLIPTextEncode", "inputs": {"text": "blurry"}}
|
|
sampler_less = {
|
|
"1": {
|
|
"class_type": "PromptManagerText",
|
|
"inputs": {"text": OFF_TEXT, "save_to_library": False},
|
|
}
|
|
}
|
|
for name, graph in (("sampled", graph), ("sampler-less", sampler_less)):
|
|
with self.subTest(name=name):
|
|
self.metadata = {"prompt": graph}
|
|
state, _ = self.handler._find_prompt_from_metadata(self.metadata)
|
|
self.assertEqual(state, "opted_out")
|
|
path = self.image(f"IMG_GEN_{name}_00001_.png")
|
|
with self.assertLogs(LOGGER, "INFO") as logs:
|
|
self.handler.process_new_image(path)
|
|
self.assertIn(SKIPPED, "\n".join(logs.output))
|
|
self.seal(path)
|
|
self.assertTrue(self.settled())
|
|
self.assertIn(SKIPPED, self.recheck(path))
|
|
self.assert_nothing_stored(path)
|
|
|
|
def test_q2_an_off_text_node_behind_a_pass_through_stores_nothing(self):
|
|
for middle, key in (("MyNode", "value"), ("easy showAnything", "anything")):
|
|
with self.subTest(middle=middle):
|
|
self.metadata = {"prompt": off_behind(middle, key)}
|
|
state, _ = self.handler._find_prompt_from_metadata(self.metadata)
|
|
self.assertEqual(state, "foreign")
|
|
path = self.image(f"IMG_GEN_{key}_00001_.png")
|
|
with self.assertLogs(LOGGER, "INFO") as logs:
|
|
self.handler.process_new_image(path)
|
|
self.assertIn(SKIPPED, "\n".join(logs.output))
|
|
self.assert_nothing_stored(path)
|
|
self.seal(path)
|
|
self.assertTrue(self.settled())
|
|
self.assertIn(SKIPPED, self.recheck(path))
|
|
self.assert_nothing_stored(path)
|
|
|
|
def test_q2_a_wired_switch_behind_a_pass_through_stores_nothing(self):
|
|
graph = off_behind()
|
|
graph["1"]["inputs"]["save_to_library"] = ["20", 0]
|
|
graph["20"] = {"class_type": "SomeBoolNode", "inputs": {}}
|
|
self.metadata = {"prompt": graph}
|
|
path = self.image("IMG_GEN_wired_00001_.png")
|
|
wired = "Save to library is wired from a node the image cannot show"
|
|
with self.assertLogs(LOGGER, "INFO") as logs:
|
|
self.handler.process_new_image(path)
|
|
self.assertIn(wired, "\n".join(logs.output))
|
|
self.seal(path)
|
|
self.assertTrue(self.settled())
|
|
self.assertIn(wired, self.recheck(path))
|
|
self.assert_nothing_stored(path)
|
|
|
|
def test_q3_an_undecided_not_saved_waits_for_the_record_then_skips(self):
|
|
"""No record yet: a not_saved of the undecided step is not final (a
|
|
recorded saver may resolve another branch), so the file waits for its
|
|
run; the decision with the record stores nothing and logs the skip."""
|
|
wired = off_text_unwired()
|
|
wired["40"]["inputs"]["save_to_library"] = ["20", 0]
|
|
wired["20"] = {"class_type": "SomeBoolNode", "inputs": {}}
|
|
cases = (
|
|
("off", off_text_unwired(), SKIPPED),
|
|
("wired", wired, "Save to library is wired from a node"),
|
|
)
|
|
for name, graph, line in cases:
|
|
with self.subTest(name=name):
|
|
self.metadata = {"prompt": graph}
|
|
path = self.image(f"vendor_{name}_00001_.png")
|
|
self.handler.process_new_image(path)
|
|
self.assertIsNone(self.linked_text(path))
|
|
self.assertEqual(self.handler.awaiting_foreign(), [self.key(path)])
|
|
with self.assertLogs(LOGGER, "INFO") as logs:
|
|
self.seal(path)
|
|
self.assertTrue(
|
|
self.wait_for(lambda: not self.handler.awaiting_foreign())
|
|
)
|
|
self.assertTrue(self.settled())
|
|
self.assertIn(line, "\n".join(logs.output))
|
|
self.assert_nothing_stored(path)
|
|
|
|
def test_q3_an_early_not_saved_never_waits_even_with_a_saver_branch(self):
|
|
"""Review: a switched-off node feeding one branch's positive is the
|
|
ladder's early, final not_saved (PR 1's #90 rule covers every
|
|
sampler's positive), so the file never waits and nothing is stored,
|
|
not even the plain branch the recorded saver names."""
|
|
graph = shapes.shared_prefix()
|
|
graph["20"]["inputs"]["text"] = ["50", 0]
|
|
graph["50"] = {
|
|
"class_type": "PromptManagerText",
|
|
"inputs": {"text": OFF_TEXT, "save_to_library": False},
|
|
}
|
|
self.metadata = {"prompt": graph}
|
|
path = self.image("IMG_GEN_00001_.png")
|
|
with self.assertLogs(LOGGER, "INFO") as logs:
|
|
self.handler.process_new_image(path)
|
|
self.assertIn(SKIPPED, "\n".join(logs.output))
|
|
self.assert_nothing_stored(path)
|
|
self.seal(path, nodes=("13",))
|
|
self.assertTrue(self.settled())
|
|
self.assertIn(SKIPPED, self.recheck(path))
|
|
self.assert_nothing_stored(path)
|
|
self.assertIsNone(
|
|
self.db.get_prompt_by_hash(generate_prompt_hash(shapes.BRANCH_TEXTS[0]))
|
|
)
|
|
|
|
def test_q3_an_off_node_in_the_recorded_saver_branch_is_never_foreign(self):
|
|
"""PR 3's parity case: a switched-off node feeds the very branch the
|
|
recorded saver names (saver "23" is branch 2). A literal switch is the
|
|
opted-out path's; a wired one is the node's own run's (#90), never the
|
|
foreign path's. Nothing is stored at settle or after the run, and no
|
|
file waits for a foreign re-check."""
|
|
cases = (
|
|
("off", False, "opted_out", SKIPPED),
|
|
("wired", ["52", 0], "unknown", "No certain prompt for"),
|
|
)
|
|
for name, save, state, line in cases:
|
|
with self.subTest(name=name):
|
|
graph = shapes.shared_prefix()
|
|
graph["50"] = {
|
|
"class_type": "PromptManagerText",
|
|
"inputs": {"text": OFF_TEXT, "save_to_library": save},
|
|
}
|
|
graph["20"]["inputs"]["text"] = ["50", 0]
|
|
if isinstance(save, list):
|
|
graph["52"] = {"class_type": "SomeBoolNode", "inputs": {}}
|
|
self.metadata = {"prompt": graph}
|
|
found, _ = self.handler._find_prompt_from_metadata(self.metadata)
|
|
self.assertEqual(found, state)
|
|
path = self.image(f"IMG_GEN_{name}_00001_.png")
|
|
with self.assertLogs(LOGGER, "INFO") as logs:
|
|
self.handler.process_new_image(path)
|
|
self.assertIn(line, "\n".join(logs.output))
|
|
self.assert_nothing_stored(path)
|
|
self.seal(path, positives=[OFF_TEXT], nodes=("23",))
|
|
self.assertTrue(self.settled())
|
|
self.handler.process_new_image(path)
|
|
self.assert_nothing_stored(path)
|
|
self.assertIsNone(
|
|
self.db.get_prompt_by_hash(
|
|
generate_prompt_hash(shapes.BRANCH_TEXTS[1])
|
|
)
|
|
)
|
|
|
|
def test_q4_an_off_node_on_the_negative_only_still_links_the_positive(self):
|
|
positive = "a lighthouse on a cliff at dusk"
|
|
plain = sampled_graph(positive, "unused")
|
|
plain["2"] = {
|
|
"class_type": "PromptManager",
|
|
"inputs": {"text": OFF_TEXT, "save_to_library": False},
|
|
}
|
|
behind = sampled_graph(positive, "unused")
|
|
behind["2"]["inputs"]["text"] = ["7", 0]
|
|
behind["7"] = {
|
|
"class_type": "PromptManagerText",
|
|
"inputs": {"text": OFF_TEXT, "save_to_library": False},
|
|
}
|
|
for name, graph in (("direct", plain), ("behind an encoder", behind)):
|
|
with self.subTest(name=name):
|
|
self.metadata = {"prompt": graph}
|
|
state, _ = self.handler._find_prompt_from_metadata(self.metadata)
|
|
self.assertEqual(state, "foreign")
|
|
path = self.image(f"plain_{len(name)}_00001_.png")
|
|
self.handler.process_new_image(path)
|
|
self.assertEqual(self.linked_text(path), positive)
|
|
self.assertIsNone(
|
|
self.db.get_prompt_by_hash(generate_prompt_hash(OFF_TEXT))
|
|
)
|
|
pairs = self.db.list_prompt_pairs()["pairs"]
|
|
self.assertEqual(pairs, [])
|
|
self.assertEqual(self.handler.awaiting_foreign(), [])
|
|
|
|
def test_q5_recorded_history_never_brings_back_switched_off_text(self):
|
|
"""Even a recorded run whose contexts hold the off text (an older
|
|
history row) cannot name it, at settle or at the re-check."""
|
|
cases = {"pass-through": off_behind(), "dangling": off_text_unwired()}
|
|
for name, graph in cases.items():
|
|
with self.subTest(name=name):
|
|
self.metadata = {"prompt": graph}
|
|
path = self.image(f"IMG_GEN_{len(name)}_00001_.png")
|
|
self.seal(path, positives=[OFF_TEXT], nodes=("9",))
|
|
self.handler.process_new_image(path)
|
|
self.assert_nothing_stored(path)
|
|
self.assertIn(SKIPPED, self.recheck(path))
|
|
self.assert_nothing_stored(path)
|
|
|
|
def test_q6_with_foreign_saving_off_save_to_library_is_unchanged(self):
|
|
GalleryConfig.SAVE_FOREIGN_RUNS = False
|
|
opted_out = save_tests.run_graph(save=False)
|
|
self.metadata = {"prompt": opted_out}
|
|
skipped = self.image("IMG_GEN_off_00001_.png")
|
|
with self.assertLogs(LOGGER, "INFO") as logs:
|
|
self.handler.process_new_image(skipped)
|
|
self.assertIn(SKIPPED, "\n".join(logs.output))
|
|
self.metadata = {"prompt": off_behind()}
|
|
foreign = self.image("IMG_GEN_foreign_00001_.png")
|
|
with self.assertLogs(LOGGER, "INFO") as logs:
|
|
self.handler.process_new_image(foreign)
|
|
self.assertIn("No PromptManager prompt in workflow", "\n".join(logs.output))
|
|
for path in (skipped, foreign):
|
|
self.assert_nothing_stored(path)
|
|
# A switched-on PromptManager positive still links by its metadata
|
|
stored = self.db.save_prompt(
|
|
text=save_tests.POSITIVE,
|
|
prompt_hash=generate_prompt_hash(save_tests.POSITIVE),
|
|
)
|
|
self.metadata = {"prompt": save_tests.run_graph(save=True)}
|
|
on = self.image("IMG_GEN_on_00001_.png")
|
|
self.handler.process_new_image(on)
|
|
self.assertEqual(self.linked_text(on), save_tests.POSITIVE)
|
|
self.assertEqual(
|
|
self.db.get_prompt_by_hash(generate_prompt_hash(save_tests.POSITIVE))["id"],
|
|
stored,
|
|
)
|
|
|
|
def test_the_shared_prefix_dataset_still_links_after_the_seal(self):
|
|
"""Regression guard (passes before the fix): the wait still works."""
|
|
self.metadata = {"prompt": shapes.shared_prefix()}
|
|
path = self.image("IMG_GEN_00001_.png")
|
|
self.handler.process_new_image(path)
|
|
self.assertEqual(self.handler.awaiting_foreign(), [self.key(path)])
|
|
self.seal(path, nodes=("13",))
|
|
self.assertTrue(self.wait_for(lambda: self.linked_text(path)))
|
|
self.assertTrue(self.settled())
|
|
self.assertEqual(self.linked_text(path), shapes.BRANCH_TEXTS[0])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|