Files
olivv-cs-ComfyUI-FunPack/app/composer/tests/rule_no_module_styling.test.js
T
digital-garbage 835fab7864 core+shell: the bridge, and the first module through it
One declaration does three jobs: renders the panel, carries the defaults, names
the values that come back. A module writes no DOM and reads no DOM.

Validation refuses rather than repairs -- unknown type, a renderer its type does
not have, a label that is not text, a default outside its own bounds, a when
naming a key the module never declared. A module that is wrong does not get a
best-effort panel; it does not load, and says why once.

Ordering is by declared relation and stage, never priority numbers, and a cycle
drops only the modules in it. Compatibility is by trait, never model name.

The shell hands a module { composer, values, on, shell } and nothing else: no
node, no document, no kit internals. It cannot style anything because it is
never given anything that could.

catalogue/hide.html puts one good module and five broken ones through the real
shell and shows the result: one panel, five absent, no placeholders. The lint
fixtures make the scanner prove it catches each rule, so a clean scan means
something.

First slice: modules/system/appearance. Two settings, an optional ui.js, and
clicking Light actually turns the app light.
2026-08-28 19:58:06 +03:00

73 lines
3.0 KiB
JavaScript

// Rule 1: a module never styles anything.
//
// The runtime half is stronger than this -- a module is handed { composer,
// values, on } and nothing that could style or build -- but a scanner catches
// the attempt in the file rather than at the moment it would have run.
import test from "node:test";
import assert from "node:assert/strict";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import { readFileSync } from "node:fs";
import { scan, scanSource, code } from "../../../tools/kit_lint/scan.js";
import { MODULE_RULES, KIT_RULES } from "../../../tools/kit_lint/rules.js";
const here = dirname(fileURLToPath(import.meta.url));
const repo = join(here, "..", "..", "..");
const FIXTURES = join(here, "lint_fixtures");
test("every module in the tree is clean", () => {
// Empty today; the value is that it stays empty as modules arrive.
const violations = scan(join(repo, "modules"), MODULE_RULES);
assert.deepEqual(violations, [],
violations.map((v) => `${v.file}:${v.line} ${v.rule} -- ${v.why}`).join("\n"));
});
test("the kit never interprets content", () => {
// The kit may style and may build elements; that is its job. What it may not
// do is parse anything a module gave it.
const violations = scan(join(repo, "app", "composer"), KIT_RULES);
assert.deepEqual(violations, [],
violations.map((v) => `${v.file}:${v.line} ${v.rule}`).join("\n"));
});
test("the shell never interprets content either", () => {
assert.deepEqual(scan(join(repo, "app", "shell"), KIT_RULES), []);
});
// --- the scanner has to actually catch things ------------------------------
test("a clean module passes", () => {
const source = readFileSync(join(FIXTURES, "clean", "ui.js"), "utf8");
assert.deepEqual(scanSource(source, MODULE_RULES), []);
});
test("the scanner catches every rule it claims to", () => {
// Without this, "zero violations" could mean "the scanner is broken" -- which
// is the failure mode of every lint nobody tests.
const source = readFileSync(join(FIXTURES, "offenders", "ui.js"), "utf8");
const caught = new Set(scanSource(source, MODULE_RULES).map((v) => v.rule));
for (const rule of ["inline-style", "style-attribute", "class-manipulation",
"raw-element", "markup", "stylesheet", "hardcoded-colour",
"hardcoded-size", "eval"]) {
assert.ok(caught.has(rule), `the offender fixture was not caught by "${rule}"`);
}
});
test("prose is not code", () => {
// Otherwise every rule becomes unmentionable in the comment explaining it.
const commented = `
// never write innerHTML here
/* and #ff0000 and 12px are fine to discuss */
export const ok = 1;
`;
assert.deepEqual(scanSource(commented, MODULE_RULES), []);
assert.ok(!code(commented).includes("innerHTML"));
});
test("a url containing a hash is not a colour", () => {
assert.deepEqual(scanSource('export const a = "#abc";', MODULE_RULES).map((v) => v.rule),
["hardcoded-colour"], "a real colour is caught");
});