mirror of
https://github.com/storytold/craft-ai-integrations.git
synced 2026-11-28 17:31:59 +01:00
* feat(ai-comfyui): import a selection workflow and run it with the picture sent first Adds the `image.segment` capability to imported ComfyUI workflows. A selection workflow maps a text prompt and one source picture; the picture is uploaded, the graph is queued with the name ComfyUI gave it, and every queued graph gets a sink name of its own so a repeat is not answered from cache with no output. Clicks or a box are refused in plain words before anything is sent, and a stored workflow file may declare a source binding and no mask. The answer is the graph's image as it comes. Checking the mask is the next change. * feat(ai-comfyui): check a selection workflow's mask and answer in the shared shape A selection workflow's image is now a mask the shared contract can trust. It must be the size of the picture sent (a JPEG may come back turned a quarter, because ComfyUI's loader applies the EXIF turn), is reduced to one 8-bit channel, and is followed by the shared `Found` result. A mask with no pixel above half is an empty mask and `matched: false`, never a failed job. Picture sizes are read from the PNG or JPEG header and bounded. This is not calibrated absence detection: the example Florence graph finds a box for any phrase. * fix(ai-comfyui): hand on a binary mask, white where selected and black elsewhere A review finding: the first channel was kept as the graph saved it, so pixels from 128 to 254 reached the app as partly selected, while the shared contract says selected pixels are white. Every pixel above half is now 255 and the rest 0. Written first and seen to fail (the answer kept [0, 100, 128, 200, 255]); mutation cases added for a grey kept as selected and a low grey kept. * docs(ai-comfyui): state the selection mask's byte limit, test it, and rename a mutation case Two review findings. The mask is read inline under the provider's output limit (never more than the 32 MiB inline cap) and never to the output folder, because the checks need its bytes in hand; that is now written in the module header and the provider, and a test shows a mask over a lowered limit fails the job and hands on nothing, with a mutation case for the limit being ignored. The case that only removed the media-type guard is renamed so it no longer implies JPEG answers are covered. The limit test passed on first run, as the behaviour already existed: it is a guard, not a red-first fix.
30 lines
2.7 KiB
Python
30 lines
2.7 KiB
Python
"""Deliberate-bug cases for group `gm`: the mask the generic `image.segment` route on ComfyUI hands
|
|
on (its size, its one channel, the empty-mask answer and the picture header).
|
|
|
|
Loaded by mutation_check.py. Each case breaks one rule and names the test that should notice.
|
|
Format: (name, file, old, new, package, test target, test filter).
|
|
|
|
Equivalent, so not listed: the pixel limit on the mask in `finish` (a mask must equal the size of
|
|
a picture that already passed the same limit).
|
|
"""
|
|
SR = 'crates/ai-comfyui/src/segment_route.rs'
|
|
PV = 'crates/ai-comfyui/src/provider.rs'
|
|
CC = 'craft-ai-comfyui'
|
|
SIZE = 'if width == 0 || height == 0 || u64::from(width) * u64::from(height) > MAX_PIXELS {'
|
|
|
|
GM_CASES = [
|
|
('mask-turn-allowed-for-png', SR, '|| (self.turnable && width == self.height && height == self.width)', '|| (width == self.height && height == self.width)', CC, 'lib', 'a_mask_of_the_wrong_size'),
|
|
('mask-size-not-checked', SR, 'if !size.accepts(width, height) {', 'if false {', CC, 'lib', 'a_mask_of_the_wrong_size'),
|
|
('any-pixel-is-selected', SR, 'gray.iter().any(|v| *v > 127)', 'gray.iter().any(|v| *v > 0)', CC, 'lib', 'half_is_the_line'),
|
|
('over-half-is-needed', SR, 'gray.iter().any(|v| *v > 127)', 'gray.iter().any(|v| *v > 128)', CC, 'lib', 'half_is_the_line'),
|
|
('grey-kept-as-selected', SR, '*v = if *v > 127 { 255 } else { 0 }', '*v = if *v > 127 { *v } else { 0 }', CC, 'lib', 'the_answer_is_binary'),
|
|
('low-grey-kept-as-not-selected', SR, '*v = if *v > 127 { 255 } else { 0 }', '*v = if *v > 127 { 255 } else { *v }', CC, 'lib', 'a_mask_with_nothing_selected'),
|
|
('alpha-is-the-mask', SR, '.map(|p| p.first().copied().unwrap_or(0))', '.map(|p| p.last().copied().unwrap_or(0))', CC, 'lib', 'the_first_channel'),
|
|
('media-type-guard-removed', SR, 'if media_type.as_str() != "image/png" {', 'if false {', CC, 'lib', 'something_that_is_not_a_png'),
|
|
('table-marker-taken-for-frame', SR, '0xC0..=0xCF if !matches!(*marker, 0xC4 | 0xC8 | 0xCC) => {', '0xC0..=0xCF => {', CC, 'lib', 'jpeg_segments_before'),
|
|
('huge-picture-accepted', SR, SIZE, 'if width == 0 || height == 0 {', CC, 'lib', 'no_readable_or_a_huge'),
|
|
('empty-picture-accepted', SR, SIZE, 'if u64::from(width) * u64::from(height) > MAX_PIXELS {', CC, 'lib', 'no_readable_or_a_huge'),
|
|
('mask-handed-on-unchecked', PV, '.and_then(|event| segment_route::answer(event, &size)),', '.map(|event| vec![event]),', CC, 'segment_route', 'a_mask_of_the_wrong_size_fails'),
|
|
('mask-ignores-the-output-limit', PV, 'Some(size) => output::fetch(&self.http, n, false, None, self.max_output_bytes)', 'Some(size) => output::fetch(&self.http, n, false, None, 1024 * 1024 * 1024)', CC, 'segment_route', 'a_mask_over_the_output_limit'),
|
|
]
|