Add cooperative task recovery and persistent live status
Build custom container images / build (map[base_image:php:8-fpm-alpine build_args:PHP_VERSION=8 context:php8-pgsql fingerprint_command:{ apk info -v | LC_ALL=C sort; find /usr/local/lib/php/extensions /usr/local/etc/php/conf.d -type f -exec sha256sum {} + | LC_ALL=C sort; } name:ph… (push) Successful in 40s
Build custom container images / build (map[base_image:postgres:18 build_args:PG_VERSION=18 POSTGIS_VERSION=3 VCHORD_VERSION=0.5.3 context:postgres fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; find /usr/lib/postgresql -type f -exec sha256su… (push) Successful in 49s
Build custom container images / build (map[base_image:python:3 build_args:PYTHON_VERSION=3 context:python-tools fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; } name:python-tools oci_labels:org.opencontainers.ima… (push) Successful in 1m37s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim context:linkki-tiedotus fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; } name:linkki-tiedotus oci_labels:… (push) Successful in 36s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim context:timepoll fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; } name:timepoll oci_labels:org.opencontai… (push) Successful in 42s

This commit is contained in:
ajp_anton committed 2026-10-29 22:12:04 +00:00
1 parent 034fecbd51
commit 3bfd199b9c
28 files changed
+2356 -172

No files matched your search

@@ -0,0 +1,261 @@
"""Optional Playwright checks against disposable, locally served task fixtures."""
import json
import os
import threading
from pathlib import Path
import pytest
from werkzeug.serving import make_server
from .conftest import write_task
from .test_live_status import live_app as live_app, start_live_run
playwright = pytest.importorskip("playwright.sync_api")
@pytest.fixture(scope="module")
def browser():
with playwright.sync_playwright() as driver:
executable = os.environ.get("PLAYWRIGHT_CHROMIUM_EXECUTABLE", driver.chromium.executable_path)
if not Path(executable).is_file():
pytest.skip("Install Playwright's Chromium or set PLAYWRIGHT_CHROMIUM_EXECUTABLE")
browser = driver.chromium.launch(executable_path=executable)
yield browser
browser.close()
@pytest.fixture
def live_server(live_app):
server = make_server("127.0.0.1", 0, live_app, threaded=True)
thread = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
yield live_app, f"http://127.0.0.1:{server.server_port}"
server.shutdown()
thread.join(timeout=5)
server.server_close()
@pytest.fixture
def live_page(browser, live_server):
app, url = live_server
context = browser.new_context(accept_downloads=True)
context.add_init_script("""(() => {
window.leaveListeners = [];
const original = window.addEventListener;
window.addEventListener = function(type, ...args) {
if (type === 'beforeunload') window.leaveListeners.push(type);
return original.call(this, type, ...args);
};
})();""")
page = context.new_page()
errors = []
dialogs = []
page.on("pageerror", lambda error: errors.append(str(error)))
def dismiss(dialog):
dialogs.append(dialog.type)
dialog.dismiss()
page.on("dialog", dismiss)
yield app, url, page
context.close()
assert not errors
assert not dialogs
def task_form(page, task_id):
return page.locator(f'form[data-task-id="{task_id}"]')
@pytest.mark.parametrize("width", [1280, 390, 320])
@pytest.mark.parametrize("status", ["queued", "running", "recovering", "recovery queued"])
def test_reload_navigation_and_multiline_progress(live_page, tmp_path, width, status):
app, url, page = live_page
run = start_live_run(
app, status="queued" if status in {"queued", "recovery queued"} else "running",
recovery=status in {"recovering", "recovery queued"},
)
page.set_viewport_size({"width": width, "height": 844})
page.goto(url)
own = task_form(page, "example/long.py")
playwright.expect(own.locator(".task-result")).to_contain_text(status.capitalize())
playwright.expect(own.locator(".task-progress")).to_have_text("2 of 5\nETA: 3 minutes")
assert own.locator('button[type="submit"]').is_disabled()
for name in ("example/sibling.py", "related/change.py"):
form = task_form(page, name)
playwright.expect(form.locator(".task-result")).to_contain_text("Blocked by")
assert form.locator('button[type="submit"]').is_disabled()
assert task_form(page, "independent/free.py").locator('button[type="submit"]').is_enabled()
page.reload()
playwright.expect(own.locator(".task-progress")).to_have_text("2 of 5\nETA: 3 minutes")
own.locator(f'.task-result a[href="/runs/{run.id}"]').click()
playwright.expect(page.locator("#run-progress")).to_have_text("2 of 5\nETA: 3 minutes")
page.reload()
playwright.expect(page.locator("#run-progress")).to_have_text("2 of 5\nETA: 3 minutes")
playwright.expect(page.locator("#run-status")).to_have_text("Recovery queued" if status == "recovery queued" else status)
assert page.locator("#run-progress").evaluate("el => getComputedStyle(el).whiteSpace") == "pre-wrap"
page.screenshot(path=str(tmp_path / f"run-{status}-{width}.png"), full_page=True)
assert page.evaluate("window.leaveListeners") == []
page.locator('main a[href="/"]').first.click()
playwright.expect(own.locator(".task-result")).to_contain_text(status.capitalize())
assert page.evaluate("document.documentElement.scrollWidth <= innerWidth")
page.screenshot(path=str(tmp_path / f"live-{status}-{width}.png"), full_page=True)
def test_first_render_blocks_conflicts_without_javascript(browser, live_server):
app, url = live_server
start_live_run(app)
context = browser.new_context(java_script_enabled=False)
try:
page = context.new_page()
page.goto(url)
assert task_form(page, "example/long.py").locator('button[type="submit"]').is_disabled()
assert task_form(page, "related/change.py").locator('button[type="submit"]').is_disabled()
assert task_form(page, "independent/free.py").locator('button[type="submit"]').is_enabled()
assert task_form(page, "example/long.py").locator(".task-progress").inner_text() == "2 of 5\nETA: 3 minutes"
finally:
context.close()
def test_live_changes_and_racing_conflict_show_blocking_run(live_page):
app, url, page = live_page
page.goto(url)
snapshot = {"value": app.test_client().get("/tasks/state").get_json()}
page.route("**/tasks/state", lambda route: route.fulfill(json=snapshot["value"]))
run = start_live_run(app, status="queued")
related = task_form(page, "related/change.py")
with page.expect_response(lambda response: response.url.endswith("/tasks/related/change.py/run") and response.status == 409):
related.locator('button[type="submit"]').click()
snapshot["value"] = app.test_client().get("/tasks/state").get_json()
playwright.expect(related.locator(".task-result")).to_contain_text(f"Blocked by run #{run.id}")
assert related.locator('button[type="submit"]').is_disabled()
own = task_form(page, "example/long.py")
playwright.expect(own.locator(".task-result")).to_contain_text("Queued")
app.extensions["run_store"].claim_next("example")
snapshot["value"] = app.test_client().get("/tasks/state").get_json()
playwright.expect(own.locator(".task-result")).to_contain_text("Running")
app.extensions["run_store"].finish(run.id, status="succeeded")
snapshot["value"] = app.test_client().get("/tasks/state").get_json()
playwright.expect(own.locator(".task-result")).to_contain_text("Completed successfully.")
playwright.expect(related.locator('button[type="submit"]')).to_be_enabled()
def test_long_task_submission_redirects_and_restores_on_return(live_page):
app, url, page = live_page
page.goto(url)
task_form(page, "example/long.py").locator('button[type="submit"]').click()
page.wait_for_url("**/runs/*")
playwright.expect(page.locator("#run-status")).to_have_text("queued")
page.locator('main a[href="/"]').first.click()
playwright.expect(task_form(page, "example/long.py").locator(".task-result")).to_contain_text("Queued")
assert app.extensions["run_store"].last_run("task", "example/long.py").status == "queued"
def test_csv_download_after_reload_does_not_repeat(live_page, settings):
app, url, page = live_page
task = write_task(settings.task_root, "exports", "review.py", 'print("done")\n')
(task.parent / "task-inputs.json").write_text(json.dumps({
"version": 1, "tasks": {task.name: {"wait_for_result": True, "download_artifacts": True}},
}))
page.goto(url)
form = task_form(page, "exports/review.py")
form.locator('button[type="submit"]').click()
playwright.expect(form.locator(".task-result")).to_contain_text("Queued")
page.reload()
playwright.expect(form.locator(".task-result")).to_contain_text("Queued")
assert page.evaluate("window.leaveListeners") == []
run = app.extensions["run_store"].last_run("task", "exports/review.py")
artifacts = settings.state_root / "runs" / f"{run.id}.artifacts"
artifacts.mkdir(parents=True, exist_ok=True)
(artifacts / "report.json").write_text('{"ok":true}')
(artifacts / "review.csv").write_text("item,decision\n1,keep\n")
downloads = []
page.on("download", lambda download: downloads.append(download.suggested_filename))
with page.expect_download() as downloaded:
app.extensions["run_store"].finish(run.id, status="succeeded")
download = downloaded.value
assert download.suggested_filename == "review.csv"
assert Path(download.path()).read_text() == "item,decision\n1,keep\n"
playwright.expect(form.locator(".task-result")).to_contain_text("Completed successfully.")
assert form.locator('button[type="submit"]').is_enabled()
page.wait_for_timeout(2200)
assert downloads == ["review.csv"]
assert (artifacts / "report.json").is_file()
assert not (artifacts / "review.csv").exists()
def test_incremental_output_preserves_selection_and_stops_polling(live_page, settings):
app, url, page = live_page
run = start_live_run(app)
log = settings.state_root / "runs" / f"{run.id}.log"
log.write_text("Select this text\n")
store = app.extensions["run_store"]
store.set_log_path(run.id, str(log))
polls = []
artifacts = []
def record(request):
if "/output?" in request.url:
polls.append(request.url)
if request.url.endswith("/artifacts"):
artifacts.append(request.url)
page.on("request", record)
page.goto(f"{url}/runs/{run.id}")
page.evaluate("""() => {
const node = document.querySelector('#run-output').firstChild;
const range = document.createRange();
range.setStart(node, 0); range.setEnd(node, 16);
getSelection().removeAllRanges(); getSelection().addRange(range);
}""")
with log.open("a") as stream:
stream.write("More output\n")
progress = settings.state_root / "runs" / f"{run.id}.progress.json"
temporary = progress.with_suffix(".tmp")
temporary.write_text(json.dumps({"text": "3 of 5\nETA: 2 minutes"}))
temporary.replace(progress)
playwright.expect(page.locator("#run-output")).to_contain_text("More output")
playwright.expect(page.locator("#run-progress")).to_have_text("3 of 5\nETA: 2 minutes")
assert page.evaluate("getSelection().toString()") == "Select this text"
assert not artifacts
with log.open("a") as stream:
stream.write("Finished\n")
store.finish(run.id, status="succeeded")
playwright.expect(page.locator("#run-output")).to_contain_text("Finished")
playwright.expect(page.locator('form[action$="/cancel"]')).to_have_count(0)
assert page.evaluate("getSelection().toString()") == "Select this text"
finished_polls = len(polls)
page.wait_for_timeout(2300)
assert len(polls) == finished_polls
assert len(artifacts) == 1
assert all("offset=" in request for request in polls)
def test_execute_control_appears_and_tracks_conflicts_after_completion(live_page, settings):
app, url, page = live_page
manifest = settings.task_root / "example" / "task-inputs.json"
manifest.write_text(json.dumps({
"version": 1, "tasks": {"long.py": {"execution": {
"field": "mode", "dry_run_value": "review", "dry_run_label": "Review",
"execute_value": "apply", "execute_label": "Execute",
}}},
}))
manager = app.extensions["run_manager"]
catalog = app.extensions["catalog"]
run, _ = manager.run_task(catalog.task("example/long.py"), {"mode": "review"})
manager.store.claim_next("example")
page.goto(f"{url}/runs/{run.id}")
manager.store.finish(run.id, status="succeeded")
execute = task_form(page, "example/long.py")
playwright.expect(execute.locator('button[type="submit"]')).to_be_visible()
blocker, _ = manager.run_task(catalog.task("example/sibling.py"))
playwright.expect(execute.locator(".task-result")).to_contain_text(f"Blocked by run #{blocker.id}")
assert execute.locator('button[type="submit"]').is_disabled()
manager.store.finish(blocker.id, status="succeeded")
playwright.expect(execute.locator('button[type="submit"]')).to_be_enabled()
execute.locator('button[type="submit"]').click()
page.wait_for_url(lambda current: current.startswith(f"{url}/runs/") and current != f"{url}/runs/{run.id}")
accepted = manager.store.last_run("task", "example/long.py")
assert accepted.id != run.id
assert json.loads(accepted.input_json) == {"mode": "apply"}