Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c96c84a85 | ||
|
|
e0ccfb09e6 | ||
|
|
2d23cd9e55 | ||
|
|
d315772b3f | ||
|
|
1ff1433d04 |
@@ -19,3 +19,4 @@
|
||||
/.flake8
|
||||
/.pre-commit-config.yaml
|
||||
/.gitignore
|
||||
/.gitattributes
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# Pinned files are compared byte for byte with their recorded hashes
|
||||
# (npm run --prefix tools/vendor check). Git must never convert their line
|
||||
# endings, which Git for Windows does by default (core.autocrlf=true, #636).
|
||||
/web/lib/viewerjs/** -text
|
||||
/web/js/shared/toolkit/** -text
|
||||
/web/js/workspace/concept.css -text
|
||||
/docs/concepts/workspace/style.css -text
|
||||
+16
@@ -277,6 +277,22 @@ the process exits non-zero.
|
||||
A test that waits on a fixed busy timeout, a network name (`\\server\share`:
|
||||
use `\\localhost\<missing share>`) or a default TLS context (it reads the
|
||||
Windows certificate store) costs seconds there; the slowest list shows it.
|
||||
- On a Windows development machine (#636), give the suite a short `TEMP`
|
||||
(for example `C:\t`) or turn long paths on
|
||||
(`HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled` = 1).
|
||||
Under the default `C:\Users\<user>\AppData\Local\Temp`, the visual fixture's
|
||||
182-character file name passes Windows' 260-character limit once a test
|
||||
nests its own temp folder, and the chronological-history reset answers 500.
|
||||
Three other differences from the CI runner are handled in the tests:
|
||||
a virtual environment's `python.exe` is a launcher that runs the real
|
||||
interpreter as a child, so a test that kills a server it started removes its
|
||||
folder with `tests/process_cleanup.py`'s `remove_when_released`, which waits
|
||||
for that child to end (a handle the test process itself still holds never
|
||||
releases, so the bound still fails it); Git for Windows checks text files out
|
||||
with CRLF, so `.gitattributes` keeps the pinned vendored files byte for byte
|
||||
and a test that parses source text normalizes line endings; and a test that
|
||||
expects no ComfyUI nearby works two folders inside its temp folder, because
|
||||
the output-folder fallback looks two levels up.
|
||||
|
||||
Every job in `test.yml`, `code-quality.yml`, `viewerjs-check.yml` and
|
||||
`portability.yml` has `timeout-minutes` (`tests/vendor/ci-workflow.test.mjs`
|
||||
|
||||
@@ -1033,7 +1033,9 @@ test('the bulk options pick and reset like the Tag image dialog (D204)', async (
|
||||
|
||||
test('the client Built-in copy equals the server DEFAULT_TAG_TEMPLATE (#431)', async () => {
|
||||
const { BUILTIN_INSTRUCTIONS } = await load();
|
||||
const source = require('node:fs').readFileSync(require('node:path').join(__dirname, '../../py/tagging_defaults.py'), 'utf8');
|
||||
// A Windows checkout may hold the file with CRLF line endings (#636).
|
||||
const source = require('node:fs').readFileSync(require('node:path').join(__dirname, '../../py/tagging_defaults.py'), 'utf8')
|
||||
.replace(/\r\n/g, '\n');
|
||||
const block = source.slice(source.indexOf('DEFAULT_TAG_TEMPLATE = ('), source.indexOf('\n)\n', source.indexOf('DEFAULT_TAG_TEMPLATE = (')));
|
||||
const text = [...block.matchAll(/"((?:[^"\\]|\\.)*)"/g)].map(([, part]) => JSON.parse(`"${part}"`)).join('');
|
||||
assert.ok(text.length > 100);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
"""Remove a folder that a killed test server may still hold for a moment (#636).
|
||||
|
||||
On Windows a virtual environment's ``python.exe`` is a launcher: it starts
|
||||
the real interpreter as a child process and ends it with itself. Killing the
|
||||
launcher returns at once, while Windows is still ending that child, which
|
||||
still has its log file open, so removing the folder at that moment fails with
|
||||
WinError 32. ``remove_when_released`` waits until the folder can be removed,
|
||||
up to a bound, and raises the last error after it.
|
||||
"""
|
||||
|
||||
import shutil
|
||||
import time
|
||||
|
||||
RELEASE_TIMEOUT_S = 30
|
||||
POLL_S = 0.05
|
||||
|
||||
|
||||
def remove_when_released(path: str, timeout: float = RELEASE_TIMEOUT_S) -> None:
|
||||
deadline = time.monotonic() + timeout
|
||||
while True:
|
||||
try:
|
||||
shutil.rmtree(path)
|
||||
return
|
||||
except FileNotFoundError:
|
||||
return
|
||||
except PermissionError:
|
||||
if time.monotonic() >= deadline:
|
||||
raise
|
||||
time.sleep(POLL_S)
|
||||
@@ -17,6 +17,11 @@ import urllib.error
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
try:
|
||||
from tests.process_cleanup import remove_when_released
|
||||
except ImportError: # discovered with tests/ as the top-level directory
|
||||
from process_cleanup import remove_when_released
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
SERVER_TIMEOUT_S = 60
|
||||
|
||||
@@ -25,12 +30,12 @@ class BrowserServerCase(unittest.TestCase):
|
||||
"""Starts the test server in a temp folder of its own; holds no tests."""
|
||||
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.tmp.cleanup)
|
||||
self.tmp = tempfile.mkdtemp()
|
||||
self.addCleanup(remove_when_released, self.tmp)
|
||||
|
||||
def start(self, *extra):
|
||||
env = {**os.environ, "TMPDIR": self.tmp.name}
|
||||
env.update(TEMP=self.tmp.name, TMP=self.tmp.name)
|
||||
env = {**os.environ, "TMPDIR": self.tmp}
|
||||
env.update(TEMP=self.tmp, TMP=self.tmp)
|
||||
process = subprocess.Popen(
|
||||
[sys.executable, "-m", "tests.browser.server", "--port", "0", *extra],
|
||||
cwd=REPO_ROOT,
|
||||
@@ -65,7 +70,7 @@ class BrowserServerCase(unittest.TestCase):
|
||||
time.sleep(0.1)
|
||||
|
||||
def roots(self):
|
||||
return sorted(path.name for path in Path(self.tmp.name).glob("pm-browser-*"))
|
||||
return sorted(path.name for path in Path(self.tmp).glob("pm-browser-*"))
|
||||
|
||||
|
||||
class TestBrowserServerLifetime(BrowserServerCase):
|
||||
|
||||
@@ -22,6 +22,11 @@ from pathlib import Path
|
||||
from tests.browser import slow_reset_watch
|
||||
from tests.browser.slow_reset_watch import REPORT_PREFIX, ResetWatch, is_reset_path
|
||||
|
||||
try:
|
||||
from tests.process_cleanup import remove_when_released
|
||||
except ImportError: # discovered with tests/ as the top-level directory
|
||||
from process_cleanup import remove_when_released
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
SERVER_TIMEOUT_S = 60
|
||||
HOLD_SECONDS = slow_reset_watch.SLOW_RESET_SECONDS + 4
|
||||
@@ -108,10 +113,10 @@ class TestSlowResetOnTheServer(unittest.TestCase):
|
||||
"""A reset behind another process's write lock, on tests/browser/server.py."""
|
||||
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.tmp.cleanup)
|
||||
env = {**os.environ, "TMPDIR": self.tmp.name}
|
||||
env.update(TEMP=self.tmp.name, TMP=self.tmp.name)
|
||||
self.tmp = tempfile.mkdtemp()
|
||||
self.addCleanup(remove_when_released, self.tmp)
|
||||
env = {**os.environ, "TMPDIR": self.tmp}
|
||||
env.update(TEMP=self.tmp, TMP=self.tmp)
|
||||
self.stderr = tempfile.TemporaryFile()
|
||||
self.addCleanup(self.stderr.close)
|
||||
process = subprocess.Popen(
|
||||
@@ -145,9 +150,7 @@ class TestSlowResetOnTheServer(unittest.TestCase):
|
||||
self.assertIsNone(process.poll(), "the server exited early")
|
||||
self.assertLess(time.monotonic(), deadline, "never ready")
|
||||
time.sleep(0.1)
|
||||
[self.db_path] = glob.glob(
|
||||
os.path.join(self.tmp.name, "pm-browser-*", "browser.db")
|
||||
)
|
||||
[self.db_path] = glob.glob(os.path.join(self.tmp, "pm-browser-*", "browser.db"))
|
||||
|
||||
def reset(self) -> tuple[int, float]:
|
||||
request = urllib.request.Request(
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
"""Pinned files keep their bytes in every clone (#636).
|
||||
|
||||
``npm run --prefix tools/vendor check`` compares the vendored Viewer.js and
|
||||
ComfyAssets Toolkit files, and the workspace's copy of the concept
|
||||
stylesheet, with recorded hashes. Git for Windows converts text files to CRLF
|
||||
on checkout by default, which changes those bytes, so ``.gitattributes`` marks
|
||||
them as never converted. This holds that for every tracked file under them.
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess # nosec B404 - fixed git arguments, no shell
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
PINNED = (
|
||||
"web/lib/viewerjs",
|
||||
"web/js/shared/toolkit",
|
||||
"web/js/workspace/concept.css",
|
||||
"docs/concepts/workspace/style.css",
|
||||
)
|
||||
|
||||
|
||||
def _git(*args: str) -> str:
|
||||
# Without GIT_* variables: the pre-push hook exports GIT_DIR and
|
||||
# GIT_INDEX_FILE, which must not choose the repository read here.
|
||||
env = {
|
||||
key: value for key, value in os.environ.items() if not key.startswith("GIT_")
|
||||
}
|
||||
return subprocess.run( # nosec B603 B607 - fixed git arguments, no shell
|
||||
["git", *args], cwd=ROOT, env=env, check=True, capture_output=True, text=True
|
||||
).stdout
|
||||
|
||||
|
||||
@unittest.skipUnless(
|
||||
shutil.which("git") and (ROOT / ".git").exists(), "needs a git checkout"
|
||||
)
|
||||
class TestPinnedLineEndings(unittest.TestCase):
|
||||
def test_every_pinned_file_is_never_converted(self):
|
||||
files = _git("ls-files", "-z", "--", *PINNED).split("\0")
|
||||
files = [name for name in files if name]
|
||||
self.assertGreater(len(files), 8, files)
|
||||
report = _git("check-attr", "-z", "text", "--", *files).split("\0")
|
||||
# -z output: path, attribute, value, repeated.
|
||||
values = dict(zip(report[0::3], report[2::3]))
|
||||
for name in files:
|
||||
with self.subTest(path=name):
|
||||
self.assertEqual(values[name], "unset")
|
||||
|
||||
def test_the_repository_stores_them_with_lf(self):
|
||||
report = _git("ls-files", "--eol", "--", *PINNED).splitlines()
|
||||
self.assertTrue(report)
|
||||
for line in report:
|
||||
with self.subTest(line=line):
|
||||
self.assertNotIn("i/crlf", line)
|
||||
self.assertNotIn("i/mixed", line)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -312,6 +312,13 @@ class LoraImportAPITestCase(LoraAPITestCase):
|
||||
class LoraImportRouteTests(LoraImportAPITestCase):
|
||||
|
||||
async def test_preview_writes_nothing_and_makes_no_requests(self):
|
||||
# The review shows a settings file under the home folder as ~/...
|
||||
# (test_lora_manager_layout). Home is pinned beside the temp root, so
|
||||
# the full path below holds wherever TEMP is: on Windows it sits
|
||||
# under the profile (#636).
|
||||
home = patch.object(Path, "home", return_value=self.tmp_root / "home")
|
||||
home.start()
|
||||
self.addCleanup(home.stop)
|
||||
self._two_loras()
|
||||
(self.loras / "broken.metadata.json").write_text("{{{")
|
||||
db_path = self.api.db.model.db_path
|
||||
|
||||
@@ -22,6 +22,7 @@ DEVELOPMENT = (
|
||||
"images/x.png",
|
||||
"TESTING.md",
|
||||
"requirements-dev.txt",
|
||||
".gitattributes",
|
||||
)
|
||||
KEPT = (
|
||||
"__init__.py",
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
"""remove_when_released waits for a dying process's files, within a bound (#636)."""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
import unittest.mock
|
||||
|
||||
try:
|
||||
from tests import process_cleanup
|
||||
except ImportError: # discovered with tests/ as the top-level directory
|
||||
import process_cleanup
|
||||
|
||||
|
||||
class TestRemoveWhenReleased(unittest.TestCase):
|
||||
def test_removes_the_folder(self):
|
||||
folder = tempfile.mkdtemp()
|
||||
with open(os.path.join(folder, "server.log"), "w") as handle:
|
||||
handle.write("x")
|
||||
process_cleanup.remove_when_released(folder)
|
||||
self.assertFalse(os.path.exists(folder))
|
||||
|
||||
def test_a_missing_folder_is_already_removed(self):
|
||||
folder = tempfile.mkdtemp()
|
||||
os.rmdir(folder)
|
||||
process_cleanup.remove_when_released(folder)
|
||||
|
||||
def test_retries_while_another_process_still_holds_a_file(self):
|
||||
held = PermissionError(32, "being used by another process")
|
||||
with (
|
||||
unittest.mock.patch.object(
|
||||
process_cleanup.shutil, "rmtree", side_effect=[held, held, None]
|
||||
) as rmtree,
|
||||
unittest.mock.patch.object(process_cleanup.time, "sleep") as sleep,
|
||||
):
|
||||
process_cleanup.remove_when_released("folder")
|
||||
self.assertEqual(rmtree.call_count, 3)
|
||||
self.assertEqual(sleep.call_count, 2)
|
||||
|
||||
def test_raises_the_last_error_after_the_bound(self):
|
||||
held = PermissionError(32, "being used by another process")
|
||||
clock = iter([0.0, 0.0, 5.0, 11.0])
|
||||
with (
|
||||
unittest.mock.patch.object(
|
||||
process_cleanup.shutil, "rmtree", side_effect=held
|
||||
),
|
||||
unittest.mock.patch.object(process_cleanup.time, "sleep"),
|
||||
unittest.mock.patch.object(
|
||||
process_cleanup.time, "monotonic", side_effect=lambda: next(clock)
|
||||
),
|
||||
):
|
||||
with self.assertRaises(PermissionError):
|
||||
process_cleanup.remove_when_released("folder", timeout=10)
|
||||
|
||||
def test_other_errors_are_not_retried(self):
|
||||
with unittest.mock.patch.object(
|
||||
process_cleanup.shutil, "rmtree", side_effect=OSError("disk gone")
|
||||
) as rmtree:
|
||||
with self.assertRaises(OSError):
|
||||
process_cleanup.remove_when_released("folder")
|
||||
self.assertEqual(rmtree.call_count, 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -50,6 +50,17 @@ class DiagnosticsTestCase(unittest.TestCase):
|
||||
os.chdir(path)
|
||||
self.addCleanup(os.chdir, previous)
|
||||
|
||||
def _chdir_without_comfyui(self):
|
||||
"""Work two levels inside the temp folder (#636).
|
||||
|
||||
The fallback looks up to two levels above the working folder for
|
||||
``output`` and ``ComfyUI/output``; from here that never leaves the
|
||||
temp folder, wherever the machine keeps it or installs ComfyUI.
|
||||
"""
|
||||
folder = os.path.join(self.tmp.name, "a", "b")
|
||||
os.makedirs(folder)
|
||||
self._chdir(folder)
|
||||
|
||||
|
||||
class TestDatabaseChecks(DiagnosticsTestCase):
|
||||
def test_missing_database_is_an_error(self):
|
||||
@@ -159,9 +170,7 @@ class TestComfyUIOutputCheck(DiagnosticsTestCase):
|
||||
)
|
||||
|
||||
def test_nothing_found_is_a_warning(self):
|
||||
empty = os.path.join(self.tmp.name, "empty")
|
||||
os.makedirs(empty)
|
||||
self._chdir(empty)
|
||||
self._chdir_without_comfyui()
|
||||
with mock.patch.dict(sys.modules, {"folder_paths": None, "py.config": None}):
|
||||
result = self.diag.check_comfyui_output()
|
||||
self.assertEqual(result["status"], "warning")
|
||||
@@ -203,7 +212,7 @@ class TestDependenciesAndFullRun(DiagnosticsTestCase):
|
||||
|
||||
def test_full_diagnostic_reports_every_category(self):
|
||||
self._populate()
|
||||
self._chdir(self.tmp.name)
|
||||
self._chdir_without_comfyui()
|
||||
with mock.patch.dict(sys.modules, {"folder_paths": None, "py.config": None}):
|
||||
results = self.diag.run_full_diagnostic()
|
||||
self.assertEqual(
|
||||
|
||||
Reference in New Issue
Block a user