Files
ausboss-ComfyUI-AusBoss/tests/image_size.test.mjs
ausboss 05038baaa3 Five basics the normal nodes have: sums, any wire into Show Text, name tokens, word weights, Image Size's numbers
Found in a sweep of the pack against ComfyUI's own nodes: things the normal
node does that the pack's node did not.

- Every number box takes a sum. Click a number, type 1024*1.5 or
  (1920-64)/2 and press Enter, as in ComfyUI's own number boxes: + - * / %,
  brackets and a sign. The reader is the pack's own (sumValue in
  js/shared/scrub_input.mjs) and is only asked when the text is not a plain
  number.
- Show Text takes any wire. Its input was STRING only. A number, an on/off
  value or a list is shown too; a picture or a latent is shown by its size.
  The output stays STRING and carries the text that is shown, so text
  passes through unchanged and a number comes out as text.
- Save Image takes name tokens in the file name, as ComfyUI's own Save
  Image does: %date:yyyy-MM-dd% and %Node.setting% are filled in the
  browser when a run is sent (js/shared/name_tokens.mjs, now shared with
  Save Video), %width% %height% and the time tokens on the server. The
  path preview shows them. A linked filename is never read for tokens.
- Ctrl + Up and Ctrl + Down change a word's weight in the pack's prompt
  boxes (Text, Krea 2 Encode). The card's text box stopped the key before
  ComfyUI's own listener saw it; those two keys now go on from a multiline
  box, and from nowhere else.
- Image Size shows what it measured beside its outputs after a run
  ("width: 1024"). The numbers go into the output labels, so the node keeps
  its size. ComfyUI says nothing about a node whose answer came from its
  cache, so the numbers are kept in the node's properties and come back
  when a workflow is opened again; a changed picture wire clears them.

No input was added, renamed or reordered. Help pages, README lines, tests
and CHANGELOG entries are included.
2026-10-11 17:10:52 -05:00

42 lines
2.2 KiB
JavaScript

// Image Size shows what it measured beside its outputs, and saves none of it.
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";
import { savedLabel, sizeLabel, sizesFromExecuted } from "../js/shared/image_size.mjs";
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
test("the numbers of one measured batch are read from the run's message", () => {
assert.deepEqual(sizesFromExecuted({ ausboss_size: [832, 480, 832, 480, 2] }), [832, 480, 832, 480, 2]);
assert.equal(sizeLabel("width", 832), "width: 832");
assert.equal(sizeLabel("count", 2), "count: 2");
});
test("anything else shows nothing", () => {
assert.equal(sizesFromExecuted(undefined), null);
assert.equal(sizesFromExecuted({}), null);
assert.equal(sizesFromExecuted({ ausboss_size: "832" }), null);
assert.equal(sizesFromExecuted({ ausboss_size: [832, 480] }), null);
assert.equal(sizesFromExecuted({ ausboss_size: [832, 480, 832, 480, "2"] }), null);
// Two batches measured in one go (a list): no one number is true for both.
assert.equal(sizesFromExecuted({ ausboss_size: [832, 480, 832, 480, 2, 640, 640, 640, 640, 1] }), null);
});
test("a shown number is never saved: the output keeps the label its user gave it, or none", () => {
assert.equal(savedLabel({ shown: true, own: undefined }, "width: 832"), undefined);
assert.equal(savedLabel({ shown: true, own: "W" }, "W: 832"), "W");
// An output that never showed a size is saved as it is.
assert.equal(savedLabel({ shown: false, own: undefined }, "my width"), "my width");
assert.equal(savedLabel({ shown: false, own: undefined }, undefined), undefined);
});
test("the backend sends the numbers in the order of the outputs, and the outputs are unchanged", () => {
const backend = readFileSync(join(ROOT, "nodes", "node_image_size.py"), "utf-8");
assert.match(backend, /RETURN_NAMES = \("width", "height", "longest_edge", "shortest_edge", "count"\)/);
assert.match(backend, /sizes = \(width, height, max\(width, height\), min\(width, height\), int\(image\.shape\[0\]\)\)/);
assert.match(backend, /return \{"ui": \{"ausboss_size": list\(sizes\)\}, "result": sizes\}/);
});