Compare commits

...
Author SHA1 Message Date
Vito Sansevero 1244dd87ee fix(tests): wait for the LoRA save's answer in the import review spec (#631)
The spec clicked Save preferences and gave the saved status five seconds.
The save commits config.json durably, and on a busy CI disk that write
alone took 6.4 s, so the status still read Unsaved changes.

It now waits for the /lora/enable response first, as TESTING.md asks of
disk-bound steps. Under a 20 IOPS write throttle the commit takes 10.4 s:
3 of 12 runs failed before, 12 of 12 pass now.
2026-11-14 17:50:36 -08:00
Vito Sansevero 1e35805ba4 fix(tests): seed browser fixtures in the host's path style (#629)
The concept and history fixtures recorded their outputs with a hardcoded
posix path style. On Windows the server's temp root is not an absolute
POSIX path, so the root key was None, the output bundle was refused and
both reset endpoints answered 500.

They now use the host's style, as production does. A Python test starts
the test server and seeds both fixtures, so the Windows job covers it.
2026-11-14 17:15:10 -08:00
4 changed files with 57 additions and 6 deletions
@@ -29,6 +29,7 @@ test.afterEach(async ({ page, request, browserName }) => {
});
const PREVIEW_URL = '/prompt_manager/lora/import/preview';
const ENABLE_URL = '/prompt_manager/lora/enable';
/** Runs in the page: Integrations' surfaces under `mainSelector`, every row's text and control, geometry and tokens. */
function measureIntegrations(mainSelector) {
@@ -300,7 +301,10 @@ async function productionReview(page, request, theme) {
await expect(page.locator('#workspace-main #renderer-status')).toHaveText(RENDERER_NONE);
// The import reviews what is enabled: save the integration on first.
await page.locator('#workspace-main #lora-enable').check();
// The save writes config.json durably, which a busy CI disk can hold for seconds (#631): wait for its answer.
const saved = page.waitForResponse(response => response.url().endsWith(ENABLE_URL));
await page.getByRole('button', { name: 'Save preferences', exact: true }).click();
await saved;
await expect(page.locator('#settings-status')).toHaveText('Saved to the server configuration.');
const answer = page.waitForResponse(response => response.url().endsWith(PREVIEW_URL));
await page.locator('#workspace-main').getByRole('button', { name: 'Review import', exact: true }).click();
+8 -2
View File
@@ -35,6 +35,10 @@ from utils.execution_outputs import OutputBundle, OutputReference, snapshot_outp
from utils.pair_execution import EXECUTION_KEY
from tests.browser.folder_trash import replace_folder
# Recorded outputs use the host's path style, as production does (#629): a
# Windows temp root is not an absolute POSIX path and would get no root key.
HOST_PATH_STYLE = "windows" if os.name == "nt" else "posix"
if TYPE_CHECKING:
from py.api import PromptManagerAPI
@@ -433,7 +437,9 @@ def seed_workspace_concept(
folder = root / "output" / "concepts"
folder.mkdir()
roots = snapshot_output_roots("posix", str(root / "output"), str(root / "temp"))
roots = snapshot_output_roots(
HOST_PATH_STYLE, str(root / "output"), str(root / "temp")
)
# The API package needs the host stubs the server installs before importing it.
from py.api.images import _favorite_relative_key, _favorite_root_key
@@ -474,7 +480,7 @@ def seed_workspace_concept(
"3", _snapshot(prompt.positive), _snapshot(negative), "inferred"
)
reference = OutputReference(
"4", 0, "output", "concepts", name, "posix", roots.output_key
"4", 0, "output", "concepts", name, HOST_PATH_STYLE, roots.output_key
)
runs.append(
_record_run(
+5 -2
View File
@@ -15,6 +15,7 @@ from aiohttp import web
from PIL import Image
from PIL.PngImagePlugin import PngInfo
from tests.browser.workspace_concept_fixture import HOST_PATH_STYLE
from tests.browser.workspace_visual_fixture import _write_art, seed_workspace_visual
from utils.execution_contexts import (
ContextBundle,
@@ -293,7 +294,9 @@ def seed_workspace_history(
):
conn.execute(f"DELETE FROM {table}")
epoch = api.db.get_execution_epoch()
roots = snapshot_output_roots("posix", str(root / "output"), str(root / "temp"))
roots = snapshot_output_roots(
HOST_PATH_STYLE, str(root / "output"), str(root / "temp")
)
folder = root / "output" / "history"
folder.mkdir(exist_ok=True)
for index, name in enumerate(("current.png", "other.png")):
@@ -309,7 +312,7 @@ def seed_workspace_history(
kind,
"history",
name,
"posix",
HOST_PATH_STYLE,
roots.output_key if kind == "output" else roots.temp_key,
)
+40 -2
View File
@@ -6,12 +6,14 @@ down when the launcher's end of its stdin pipe closes, and still removes its
temp root. This runs on every OS in CI, where Windows is the strict case.
"""
import json
import os
import subprocess
import sys
import tempfile
import time
import unittest
import urllib.error
import urllib.request
from pathlib import Path
@@ -19,7 +21,9 @@ REPO_ROOT = Path(__file__).resolve().parent.parent
SERVER_TIMEOUT_S = 60
class TestBrowserServerLifetime(unittest.TestCase):
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)
@@ -47,7 +51,8 @@ class TestBrowserServerLifetime(unittest.TestCase):
self.addCleanup(stop)
line = process.stdout.readline().decode()
self.assertTrue(line.startswith("PM_TEST_SERVER_PORT="), line)
url = f"http://127.0.0.1:{int(line.split('=', 1)[1])}/prompt_manager/test"
self.origin = f"http://127.0.0.1:{int(line.split('=', 1)[1])}"
url = f"{self.origin}/prompt_manager/test"
deadline = time.monotonic() + SERVER_TIMEOUT_S
while True:
try:
@@ -62,6 +67,8 @@ class TestBrowserServerLifetime(unittest.TestCase):
def roots(self):
return sorted(path.name for path in Path(self.tmp.name).glob("pm-browser-*"))
class TestBrowserServerLifetime(BrowserServerCase):
def test_server_exits_and_removes_its_temp_root_when_stdin_closes(self):
process = self.start("--exit-on-stdin-eof")
self.assertEqual(len(self.roots()), 1, "the server works in its own temp root")
@@ -79,6 +86,37 @@ class TestBrowserServerLifetime(unittest.TestCase):
process.wait(timeout=1)
class TestBrowserServerSeeding(BrowserServerCase):
"""The fixtures seed on every OS (#629): Windows roots are not POSIX paths."""
def reset(self, path, body):
request = urllib.request.Request(
f"{self.origin}{path}",
json.dumps(body).encode(),
{"Content-Type": "application/json"},
)
try:
with urllib.request.urlopen( # nosec B310
request, timeout=SERVER_TIMEOUT_S
) as response:
return response.status, json.loads(response.read())
except urllib.error.HTTPError as error:
with error:
return error.code, error.read().decode(errors="replace")
def test_concept_fixture_seeds_its_recorded_runs(self):
self.start()
status, body = self.reset("/__test__/concept/reset", {})
self.assertEqual(status, 200, body)
self.assertTrue(body["success"])
def test_history_fixture_seeds_its_recorded_runs(self):
self.start()
status, body = self.reset("/__test__/reset", {"chronological_history": True})
self.assertEqual(status, 200, body)
self.assertTrue(body["success"])
class TestBrowserServerLoraIsolation(unittest.TestCase):
"""#355: page tests never read the developer's LoraManager settings."""