Compare commits

..

45 Commits

Author SHA1 Message Date
Jedrzej Kosinski
96020c2cc7 Merge branch 'master' into assets-redo-part2 2026-01-30 23:09:25 -08:00
Jedrzej Kosinski
6b20d0e9f5 Fix test setup for assets_test after move 2026-01-30 23:09:00 -08:00
Jedrzej Kosinski
e8e1c13e83 Moved assets test to unit tests dir 2026-01-30 23:05:19 -08:00
Alexander Brown
942b2a6526 Add pruning of Assets not reachable through the current configs (#12168)
* Not sure about this one, but try removing assets from old sessions.

* Simplify _prune_orphaned_assets: merge functions, use list comprehensions

Amp-Thread-ID: https://ampcode.com/threads/T-019c0917-0dc3-75ab-870d-a32b3fdc1927
Co-authored-by: Amp <amp@ampcode.com>

* Refactor _prune_orphaned_assets for readability

Amp-Thread-ID: https://ampcode.com/threads/T-019c0917-0dc3-75ab-870d-a32b3fdc1927
Co-authored-by: Amp <amp@ampcode.com>

* Add unit tests for pruning

* Add unit tests for _prune_orphaned_assets

Tests cover:

- Orphaned seed assets pruned when file removed

- Seed assets with valid files survive

- Hashed assets not pruned even without file

- Multi-root pruning

- SQL LIKE escape handling for %, _, spaces

Amp-Thread-ID: https://ampcode.com/threads/T-019c0c7a-5c8a-7548-b6c3-823e9829ce74
Co-authored-by: Amp <amp@ampcode.com>

* Ruff fix

---------

Co-authored-by: Amp <amp@ampcode.com>
2026-01-29 18:34:14 -08:00
Jedrzej Kosinski
a999cbcfbc Merge branch 'master' into assets-redo-part2 2026-01-29 17:44:25 -08:00
Jedrzej Kosinski
612893018c Use windows-latest runner for test-assets 2026-01-29 17:37:16 -08:00
Jedrzej Kosinski
c0e26b93cc Added test-assets.yml to github workflows, added a requirements.txt to test-assets (blake3 can eventually be removed from there when it becomes a core dependency) 2026-01-29 17:33:21 -08:00
Jedrzej Kosinski
11da0e6c46 Satisfy ruff 2026-01-29 17:00:52 -08:00
Jedrzej Kosinski
1e622d3923 Fixed issues in manager.py that had to do with creating a result after closing the db session 2026-01-29 16:58:48 -08:00
Jedrzej Kosinski
eb78ea0cff Added @ROUTES.post("/api/assets/seed") for now to help with tests 2026-01-29 16:57:37 -08:00
Jedrzej Kosinski
6840ad0bbe Added tests, rewritten from the ones present in the asset-management branch 2026-01-29 16:56:39 -08:00
DrJKL
2f0db0e680 Order the tags by when they were added (Ends up being directory depth order) 2026-01-28 22:17:52 -08:00
DrJKL
69f6c37868 Leave the preview_url blank, don't serialize it as null 2026-01-28 21:49:14 -08:00
Jedrzej Kosinski
f484d66eb0 Merge branch 'master' into assets-redo-part2 2026-01-28 19:15:32 -08:00
Jedrzej Kosinski
25f83d7401 Fixed resolve_asset_content_for_download accessing asset outside of session with statement 2026-01-28 18:57:54 -08:00
Jedrzej Kosinski
2aafb71388 Add node for custom node authors in routes.py 2026-01-28 17:01:29 -08:00
Jedrzej Kosinski
902e84d7ad Remove tags from body of @ROUTES.put(f"/api/assets/{{id:{UUID_RE}}}"), add note about blake3 requirement to test out 2026-01-28 16:04:19 -08:00
Jedrzej Kosinski
d5e6e2a81f Fixed inconsistent spacing in routes.py 2026-01-28 15:39:08 -08:00
Jedrzej Kosinski
e735a8fd85 Satisfy ruff 2026-01-28 15:34:19 -08:00
Jedrzej Kosinski
32ce7a70a7 Removed 501 early returns on endpoints intended to be released, removed @ROUTES.put(f"/api/assets/{{id:{UUID_RE}}}/preview") and @ROUTES.post("/api/assets/scan/seed") and their related schema_in objects 2026-01-28 15:31:06 -08:00
Jedrzej Kosinski
cf950e47ab Merge branch 'master' into assets-redo-part2 2026-01-28 15:05:24 -08:00
Jedrzej Kosinski
724145fb55 Merge branch 'master' into assets-redo-part2 2026-01-27 16:40:19 -08:00
Jedrzej Kosinski
32d4888d99 Fix import for currently unused upload_asset_from_temp_path function 2026-01-27 16:28:05 -08:00
Jedrzej Kosinski
b16390c2fd Made some routes returmn 501's while functionality is worked on 2026-01-26 21:02:05 -08:00
Jedrzej Kosinski
4866bbfd8c Comment out import for commented out code 2026-01-26 20:30:20 -08:00
Jedrzej Kosinski
e17542b5c7 Comment out @ROUTES.post("/api/assets/scan/seed") 2026-01-26 20:25:57 -08:00
Jedrzej Kosinski
0bb6d3a3e9 Merge branch 'master' into assets-redo-part2 2026-01-26 20:17:32 -08:00
Jedrzej Kosinski
6a450a8070 Revert seed_assets to only do models root, remove blake3 requirement for now, make posting assets endpoint inaccessible with a 501 2026-01-26 19:28:00 -08:00
Jedrzej Kosinski
702cfcde3a Merge branch 'master' into assets-redo-part2 2026-01-26 14:38:18 -08:00
Jedrzej Kosinski
8e9c801940 Add input + output roots to scans 2026-01-24 16:26:42 -08:00
Jedrzej Kosinski
facda426b4 Remove extra whitespace at end of routes.py 2026-01-16 01:04:26 -08:00
Jedrzej Kosinski
65a5992f2d Remove unnecessary logging statement used for testing 2026-01-16 01:02:40 -08:00
Jedrzej Kosinski
287da646e5 Finished @ROUTES.post("/api/assets/scan/seed") 2026-01-16 01:01:49 -08:00
Jedrzej Kosinski
63f9f1b11b Finish @ROUTES.delete(f"/api/assets/{{id:{UUID_RE}}}/tags") 2026-01-16 00:50:13 -08:00
Jedrzej Kosinski
9e3f559189 Finished @ROUTES.post(f"/api/assets/{{id:{UUID_RE}}}/tags") 2026-01-16 00:45:36 -08:00
Jedrzej Kosinski
63c98d0c75 Finished @ROUTES.delete(f"/api/assets/{{id:{UUID_RE}}}") 2026-01-16 00:31:06 -08:00
Jedrzej Kosinski
e69a5aa1be Finished @ROUTES.put(f"/api/assets/{{id:{UUID_RE}}}/preview") 2026-01-16 00:14:03 -08:00
Jedrzej Kosinski
e0c063f93e Finished @ROUTES.put(f"/api/assets/{{id:{UUID_RE}}}") 2026-01-15 23:57:23 -08:00
Jedrzej Kosinski
6db4f4e3f1 Finished @ROUTES.post("/api/assets") 2026-01-15 23:41:19 -08:00
Jedrzej Kosinski
41d364030b Finished @ROUTES.post("/api/assets/from-hash") 2026-01-15 23:09:54 -08:00
Jedrzej Kosinski
fab9b71f5d Finished @ROUTES.head("/api/assets/hash/{hash}") 2026-01-15 21:13:34 -08:00
Jedrzej Kosinski
e5c1de4777 Finished @ROUTES.get(f"/api/assets/{{id:{UUID_RE}}}/content") 2026-01-15 21:00:35 -08:00
Jedrzej Kosinski
a5ed151e51 Merge branch 'master' into assets-redo-part2 2026-01-15 20:34:44 -08:00
Jedrzej Kosinski
e527b72b09 more progress 2026-01-15 18:16:00 -08:00
Jedrzej Kosinski
f14129947c in progress GET /api/assets/{uuid}/content endpoint support 2026-01-14 22:54:21 -08:00
10 changed files with 30 additions and 210 deletions

View File

@@ -1,7 +1,7 @@
import torch
import torch.nn as nn
from dataclasses import dataclass
from typing import Optional, Any, Tuple
from typing import Optional, Any
import math
from comfy.ldm.modules.attention import optimized_attention_for_device
@@ -32,7 +32,6 @@ class Llama2Config:
k_norm = None
rope_scale = None
final_norm: bool = True
lm_head: bool = False
@dataclass
class Mistral3Small24BConfig:
@@ -55,7 +54,6 @@ class Mistral3Small24BConfig:
k_norm = None
rope_scale = None
final_norm: bool = True
lm_head: bool = False
@dataclass
class Qwen25_3BConfig:
@@ -78,7 +76,6 @@ class Qwen25_3BConfig:
k_norm = None
rope_scale = None
final_norm: bool = True
lm_head: bool = False
@dataclass
class Qwen3_06BConfig:
@@ -101,7 +98,6 @@ class Qwen3_06BConfig:
k_norm = "gemma3"
rope_scale = None
final_norm: bool = True
lm_head: bool = False
@dataclass
class Qwen3_4BConfig:
@@ -124,7 +120,6 @@ class Qwen3_4BConfig:
k_norm = "gemma3"
rope_scale = None
final_norm: bool = True
lm_head: bool = False
@dataclass
class Qwen3_8BConfig:
@@ -147,7 +142,6 @@ class Qwen3_8BConfig:
k_norm = "gemma3"
rope_scale = None
final_norm: bool = True
lm_head: bool = False
@dataclass
class Ovis25_2BConfig:
@@ -170,7 +164,6 @@ class Ovis25_2BConfig:
k_norm = "gemma3"
rope_scale = None
final_norm: bool = True
lm_head: bool = False
@dataclass
class Qwen25_7BVLI_Config:
@@ -193,7 +186,6 @@ class Qwen25_7BVLI_Config:
k_norm = None
rope_scale = None
final_norm: bool = True
lm_head: bool = False
@dataclass
class Gemma2_2B_Config:
@@ -217,7 +209,6 @@ class Gemma2_2B_Config:
sliding_attention = None
rope_scale = None
final_norm: bool = True
lm_head: bool = False
@dataclass
class Gemma3_4B_Config:
@@ -241,7 +232,6 @@ class Gemma3_4B_Config:
sliding_attention = [1024, 1024, 1024, 1024, 1024, False]
rope_scale = [8.0, 1.0]
final_norm: bool = True
lm_head: bool = False
@dataclass
class Gemma3_12B_Config:
@@ -265,7 +255,6 @@ class Gemma3_12B_Config:
sliding_attention = [1024, 1024, 1024, 1024, 1024, False]
rope_scale = [8.0, 1.0]
final_norm: bool = True
lm_head: bool = False
vision_config = {"num_channels": 3, "hidden_act": "gelu_pytorch_tanh", "hidden_size": 1152, "image_size": 896, "intermediate_size": 4304, "model_type": "siglip_vision_model", "num_attention_heads": 16, "num_hidden_layers": 27, "patch_size": 14}
mm_tokens_per_image = 256
@@ -367,7 +356,6 @@ class Attention(nn.Module):
attention_mask: Optional[torch.Tensor] = None,
freqs_cis: Optional[torch.Tensor] = None,
optimized_attention=None,
past_key_value: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
):
batch_size, seq_length, _ = hidden_states.shape
xq = self.q_proj(hidden_states)
@@ -385,30 +373,11 @@ class Attention(nn.Module):
xq, xk = apply_rope(xq, xk, freqs_cis=freqs_cis)
present_key_value = None
if past_key_value is not None:
index = 0
num_tokens = xk.shape[2]
if len(past_key_value) > 0:
past_key, past_value, index = past_key_value
if past_key.shape[2] >= (index + num_tokens):
past_key[:, :, index:index + xk.shape[2]] = xk
past_value[:, :, index:index + xv.shape[2]] = xv
xk = past_key[:, :, :index + xk.shape[2]]
xv = past_value[:, :, :index + xv.shape[2]]
present_key_value = (past_key, past_value, index + num_tokens)
else:
xk = torch.cat((past_key[:, :, :index], xk), dim=2)
xv = torch.cat((past_value[:, :, :index], xv), dim=2)
present_key_value = (xk, xv, index + num_tokens)
else:
present_key_value = (xk, xv, index + num_tokens)
xk = xk.repeat_interleave(self.num_heads // self.num_kv_heads, dim=1)
xv = xv.repeat_interleave(self.num_heads // self.num_kv_heads, dim=1)
output = optimized_attention(xq, xk, xv, self.num_heads, mask=attention_mask, skip_reshape=True)
return self.o_proj(output), present_key_value
return self.o_proj(output)
class MLP(nn.Module):
def __init__(self, config: Llama2Config, device=None, dtype=None, ops: Any = None):
@@ -439,17 +408,15 @@ class TransformerBlock(nn.Module):
attention_mask: Optional[torch.Tensor] = None,
freqs_cis: Optional[torch.Tensor] = None,
optimized_attention=None,
past_key_value: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
):
# Self Attention
residual = x
x = self.input_layernorm(x)
x, present_key_value = self.self_attn(
x = self.self_attn(
hidden_states=x,
attention_mask=attention_mask,
freqs_cis=freqs_cis,
optimized_attention=optimized_attention,
past_key_value=past_key_value,
)
x = residual + x
@@ -459,7 +426,7 @@ class TransformerBlock(nn.Module):
x = self.mlp(x)
x = residual + x
return x, present_key_value
return x
class TransformerBlockGemma2(nn.Module):
def __init__(self, config: Llama2Config, index, device=None, dtype=None, ops: Any = None):
@@ -484,7 +451,6 @@ class TransformerBlockGemma2(nn.Module):
attention_mask: Optional[torch.Tensor] = None,
freqs_cis: Optional[torch.Tensor] = None,
optimized_attention=None,
past_key_value: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
):
if self.transformer_type == 'gemma3':
if self.sliding_attention:
@@ -502,12 +468,11 @@ class TransformerBlockGemma2(nn.Module):
# Self Attention
residual = x
x = self.input_layernorm(x)
x, present_key_value = self.self_attn(
x = self.self_attn(
hidden_states=x,
attention_mask=attention_mask,
freqs_cis=freqs_cis,
optimized_attention=optimized_attention,
past_key_value=past_key_value,
)
x = self.post_attention_layernorm(x)
@@ -520,7 +485,7 @@ class TransformerBlockGemma2(nn.Module):
x = self.post_feedforward_layernorm(x)
x = residual + x
return x, present_key_value
return x
class Llama2_(nn.Module):
def __init__(self, config, device=None, dtype=None, ops=None):
@@ -551,10 +516,9 @@ class Llama2_(nn.Module):
else:
self.norm = None
if config.lm_head:
self.lm_head = ops.Linear(config.hidden_size, config.vocab_size, bias=False, device=device, dtype=dtype)
# self.lm_head = ops.Linear(config.hidden_size, config.vocab_size, bias=False, device=device, dtype=dtype)
def forward(self, x, attention_mask=None, embeds=None, num_tokens=None, intermediate_output=None, final_layer_norm_intermediate=True, dtype=None, position_ids=None, embeds_info=[], past_key_values=None):
def forward(self, x, attention_mask=None, embeds=None, num_tokens=None, intermediate_output=None, final_layer_norm_intermediate=True, dtype=None, position_ids=None, embeds_info=[]):
if embeds is not None:
x = embeds
else:
@@ -563,13 +527,8 @@ class Llama2_(nn.Module):
if self.normalize_in:
x *= self.config.hidden_size ** 0.5
seq_len = x.shape[1]
past_len = 0
if past_key_values is not None and len(past_key_values) > 0:
past_len = past_key_values[0][2]
if position_ids is None:
position_ids = torch.arange(past_len, past_len + seq_len, device=x.device).unsqueeze(0)
position_ids = torch.arange(0, x.shape[1], device=x.device).unsqueeze(0)
freqs_cis = precompute_freqs_cis(self.config.head_dim,
position_ids,
@@ -580,16 +539,14 @@ class Llama2_(nn.Module):
mask = None
if attention_mask is not None:
mask = 1.0 - attention_mask.to(x.dtype).reshape((attention_mask.shape[0], 1, -1, attention_mask.shape[-1])).expand(attention_mask.shape[0], 1, seq_len, attention_mask.shape[-1])
mask = 1.0 - attention_mask.to(x.dtype).reshape((attention_mask.shape[0], 1, -1, attention_mask.shape[-1])).expand(attention_mask.shape[0], 1, attention_mask.shape[-1], attention_mask.shape[-1])
mask = mask.masked_fill(mask.to(torch.bool), float("-inf"))
if seq_len > 1:
causal_mask = torch.empty(past_len + seq_len, past_len + seq_len, dtype=x.dtype, device=x.device).fill_(float("-inf")).triu_(1)
if mask is not None:
mask += causal_mask
else:
mask = causal_mask
causal_mask = torch.empty(x.shape[1], x.shape[1], dtype=x.dtype, device=x.device).fill_(float("-inf")).triu_(1)
if mask is not None:
mask += causal_mask
else:
mask = causal_mask
optimized_attention = optimized_attention_for_device(x.device, mask=mask is not None, small_input=True)
intermediate = None
@@ -605,27 +562,16 @@ class Llama2_(nn.Module):
elif intermediate_output < 0:
intermediate_output = len(self.layers) + intermediate_output
next_key_values = []
for i, layer in enumerate(self.layers):
if all_intermediate is not None:
if only_layers is None or (i in only_layers):
all_intermediate.append(x.unsqueeze(1).clone())
past_kv = None
if past_key_values is not None:
past_kv = past_key_values[i] if len(past_key_values) > 0 else []
x, current_kv = layer(
x = layer(
x=x,
attention_mask=mask,
freqs_cis=freqs_cis,
optimized_attention=optimized_attention,
past_key_value=past_kv,
)
if current_kv is not None:
next_key_values.append(current_kv)
if i == intermediate_output:
intermediate = x.clone()
@@ -642,10 +588,7 @@ class Llama2_(nn.Module):
if intermediate is not None and final_layer_norm_intermediate and self.norm is not None:
intermediate = self.norm(intermediate)
if len(next_key_values) > 0:
return x, intermediate, next_key_values
else:
return x, intermediate
return x, intermediate
class Gemma3MultiModalProjector(torch.nn.Module):

View File

@@ -1248,7 +1248,6 @@ class Hidden(str, Enum):
class NodeInfoV1:
input: dict=None
input_order: dict[str, list[str]]=None
is_input_list: bool=None
output: list[str]=None
output_is_list: list[bool]=None
output_name: list[str]=None
@@ -1475,7 +1474,6 @@ class Schema:
info = NodeInfoV1(
input=input,
input_order={key: list(value.keys()) for (key, value) in input.items()},
is_input_list=self.is_input_list,
output=output,
output_is_list=output_is_list,
output_name=output_name,

View File

@@ -146,7 +146,8 @@ class ImageSaveHelper:
metadata = ImageSaveHelper._create_png_metadata(cls)
for batch_number, image_tensor in enumerate(images):
img = ImageSaveHelper._convert_tensor_to_pil(image_tensor)
file = folder_paths.format_output_filename(filename, counter, "png", batch_num=str(batch_number))
filename_with_batch_num = filename.replace("%batch_num%", str(batch_number))
file = f"{filename_with_batch_num}_{counter:05}_.png"
img.save(os.path.join(full_output_folder, file), pnginfo=metadata, compress_level=compress_level)
results.append(SavedResult(file, subfolder, folder_type))
counter += 1
@@ -175,7 +176,7 @@ class ImageSaveHelper:
)
pil_images = [ImageSaveHelper._convert_tensor_to_pil(img) for img in images]
metadata = ImageSaveHelper._create_animated_png_metadata(cls)
file = folder_paths.format_output_filename(filename, counter, "png")
file = f"{filename}_{counter:05}_.png"
save_path = os.path.join(full_output_folder, file)
pil_images[0].save(
save_path,
@@ -219,7 +220,7 @@ class ImageSaveHelper:
)
pil_images = [ImageSaveHelper._convert_tensor_to_pil(img) for img in images]
pil_exif = ImageSaveHelper._create_webp_metadata(pil_images[0], cls)
file = folder_paths.format_output_filename(filename, counter, "webp")
file = f"{filename}_{counter:05}_.webp"
pil_images[0].save(
os.path.join(full_output_folder, file),
save_all=True,
@@ -283,7 +284,8 @@ class AudioSaveHelper:
results = []
for batch_number, waveform in enumerate(audio["waveform"].cpu()):
file = folder_paths.format_output_filename(filename, counter, format, batch_num=str(batch_number))
filename_with_batch_num = filename.replace("%batch_num%", str(batch_number))
file = f"{filename_with_batch_num}_{counter:05}_.{format}"
output_path = os.path.join(full_output_folder, file)
# Use original sample rate initially

View File

@@ -642,7 +642,7 @@ class SaveGLB(IO.ComfyNode):
metadata[x] = json.dumps(cls.hidden.extra_pnginfo[x])
for i in range(mesh.vertices.shape[0]):
f = folder_paths.format_output_filename(filename, counter, "glb")
f = f"{filename}_{counter:05}_.glb"
save_glb(mesh.vertices[i], mesh.faces[i], os.path.join(full_output_folder, f), metadata)
results.append({
"filename": f,

View File

@@ -460,7 +460,8 @@ class SaveSVGNode(IO.ComfyNode):
for batch_number, svg_bytes in enumerate(svg.data):
file = folder_paths.format_output_filename(filename, counter, "svg", batch_num=str(batch_number))
filename_with_batch_num = filename.replace("%batch_num%", str(batch_number))
file = f"{filename_with_batch_num}_{counter:05}_.svg"
# Read SVG content
svg_bytes.seek(0)

View File

@@ -36,7 +36,7 @@ class SaveWEBM(io.ComfyNode):
filename_prefix, folder_paths.get_output_directory(), images[0].shape[1], images[0].shape[0]
)
file = folder_paths.format_output_filename(filename, counter, "webm")
file = f"{filename}_{counter:05}_.webm"
container = av.open(os.path.join(full_output_folder, file), mode="w")
if cls.hidden.prompt is not None:
@@ -102,7 +102,7 @@ class SaveVideo(io.ComfyNode):
metadata["prompt"] = cls.hidden.prompt
if len(metadata) > 0:
saved_metadata = metadata
file = folder_paths.format_output_filename(filename, counter, Types.VideoContainer.get_extension(format))
file = f"{filename}_{counter:05}_.{Types.VideoContainer.get_extension(format)}"
video.save_to(
os.path.join(full_output_folder, file),
format=Types.VideoContainer(format),

View File

@@ -4,7 +4,6 @@ import os
import time
import mimetypes
import logging
from datetime import datetime, timezone
from typing import Literal, List
from collections.abc import Collection
@@ -12,46 +11,6 @@ from comfy.cli_args import args
supported_pt_extensions: set[str] = {'.ckpt', '.pt', '.pt2', '.bin', '.pth', '.safetensors', '.pkl', '.sft'}
def get_timestamp() -> str:
"""Generate a filesystem-safe timestamp string for output filenames.
Returns a UTC timestamp in the format YYYYMMDD-HHMMSS-ffffff (microseconds)
which is human-readable, lexicographically sortable, and Windows-safe.
"""
now = datetime.now(timezone.utc)
return now.strftime("%Y%m%d-%H%M%S-%f")
def format_output_filename(
filename: str,
counter: int,
ext: str,
*,
batch_num: str | None = None,
timestamp: str | None = None,
) -> str:
"""Format an output filename with counter and timestamp for cache-busting.
Args:
filename: The base filename prefix
counter: The numeric counter for uniqueness
ext: The file extension (with or without leading dot)
batch_num: Optional batch number to replace %batch_num% placeholder
timestamp: Optional timestamp string (defaults to current UTC time)
Returns:
Formatted filename like: filename_00001_20260131-123456-789012_.ext
"""
ext = ext.lstrip(".")
if timestamp is None:
timestamp = get_timestamp()
if batch_num is not None:
filename = filename.replace("%batch_num%", batch_num)
return f"{filename}_{counter:05}_{timestamp}_.{ext}"
folder_names_and_paths: dict[str, tuple[list[str], set[str]]] = {}
# --base-directory - Resets all default paths configured in folder_paths with a new base path

View File

@@ -1667,7 +1667,8 @@ class SaveImage:
for x in extra_pnginfo:
metadata.add_text(x, json.dumps(extra_pnginfo[x]))
file = folder_paths.format_output_filename(filename, counter, "png", batch_num=str(batch_number))
filename_with_batch_num = filename.replace("%batch_num%", str(batch_number))
file = f"{filename_with_batch_num}_{counter:05}_.png"
img.save(os.path.join(full_output_folder, file), pnginfo=metadata, compress_level=self.compress_level)
results.append({
"filename": file,

View File

@@ -656,7 +656,6 @@ class PromptServer():
info = {}
info['input'] = obj_class.INPUT_TYPES()
info['input_order'] = {key: list(value.keys()) for (key, value) in obj_class.INPUT_TYPES().items()}
info['is_input_list'] = getattr(obj_class, "INPUT_IS_LIST", False)
info['output'] = obj_class.RETURN_TYPES
info['output_is_list'] = obj_class.OUTPUT_IS_LIST if hasattr(obj_class, 'OUTPUT_IS_LIST') else [False] * len(obj_class.RETURN_TYPES)
info['output_name'] = obj_class.RETURN_NAMES if hasattr(obj_class, 'RETURN_NAMES') else info['output']

View File

@@ -1,83 +0,0 @@
"""Tests for folder_paths.format_output_filename and get_timestamp functions."""
import sys
import os
import unittest
# Add the ComfyUI root to the path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
import folder_paths
class TestGetTimestamp(unittest.TestCase):
"""Tests for get_timestamp function."""
def test_returns_string(self):
"""Should return a string."""
result = folder_paths.get_timestamp()
self.assertIsInstance(result, str)
def test_format_matches_expected_pattern(self):
"""Should return format YYYYMMDD-HHMMSS-ffffff."""
result = folder_paths.get_timestamp()
# Pattern: 8 digits, hyphen, 6 digits, hyphen, 6 digits
pattern = r"^\d{8}-\d{6}-\d{6}$"
self.assertRegex(result, pattern)
def test_is_filesystem_safe(self):
"""Should not contain characters that are unsafe for filenames."""
result = folder_paths.get_timestamp()
unsafe_chars = ['/', '\\', ':', '*', '?', '"', '<', '>', '|', ' ']
for char in unsafe_chars:
self.assertNotIn(char, result)
class TestFormatOutputFilename(unittest.TestCase):
"""Tests for format_output_filename function."""
def test_basic_format(self):
"""Should format filename with counter and timestamp."""
result = folder_paths.format_output_filename("test", 1, "png")
# Pattern: test_00001_YYYYMMDD-HHMMSS-ffffff_.png
pattern = r"^test_00001_\d{8}-\d{6}-\d{6}_\.png$"
self.assertRegex(result, pattern)
def test_counter_padding(self):
"""Should pad counter to 5 digits."""
result = folder_paths.format_output_filename("test", 42, "png")
self.assertIn("_00042_", result)
def test_extension_with_leading_dot(self):
"""Should handle extension with leading dot."""
result = folder_paths.format_output_filename("test", 1, ".png")
self.assertTrue(result.endswith("_.png"))
self.assertNotIn("..png", result)
def test_extension_without_leading_dot(self):
"""Should handle extension without leading dot."""
result = folder_paths.format_output_filename("test", 1, "webm")
self.assertTrue(result.endswith("_.webm"))
def test_batch_num_replacement(self):
"""Should replace %batch_num% placeholder."""
result = folder_paths.format_output_filename("test_%batch_num%", 1, "png", batch_num="3")
self.assertIn("test_3_", result)
self.assertNotIn("%batch_num%", result)
def test_custom_timestamp(self):
"""Should use provided timestamp instead of generating one."""
custom_ts = "20260101-120000-000000"
result = folder_paths.format_output_filename("test", 1, "png", timestamp=custom_ts)
self.assertIn(custom_ts, result)
def test_different_extensions(self):
"""Should work with various extensions."""
extensions = ["png", "webp", "webm", "svg", "glb", "safetensors", "latent"]
for ext in extensions:
result = folder_paths.format_output_filename("test", 1, ext)
self.assertTrue(result.endswith(f"_.{ext}"))
if __name__ == "__main__":
unittest.main()