WIP
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Canceled after 0s
ChangeDetection.io App Test / lint-code (push) Canceled after 0s
ChangeDetection.io App Test / lint-translations (push) Canceled after 0s
ChangeDetection.io App Test / lint-template-i18n (push) Canceled after 0s
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Test the built package works basically. (push) Canceled after 0s
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Canceled after 0s
ChangeDetection.io App Test / test-application-3-11 (push) Canceled after 0s
ChangeDetection.io App Test / test-application-3-12 (push) Canceled after 0s
ChangeDetection.io App Test / test-application-3-13 (push) Canceled after 0s
ChangeDetection.io App Test / test-application-3-14 (push) Canceled after 0s

This commit is contained in:
dgtlmoon
2026-09-17 21:56:26 +02:00
parent e4c75bf486
commit 6154178d1e
3 changed files with 125 additions and 60 deletions
+6 -5
View File
@@ -57,7 +57,6 @@ def construct_blueprint(datastore: ChangeDetectionStore):
# Fallback: if processor doesn't have preview module, use default text preview
content = []
versions = []
timestamp = None
extra_stylesheets = [url_for('static_content', group='styles', filename='diff.css')]
@@ -70,20 +69,22 @@ def construct_blueprint(datastore: ChangeDetectionStore):
ignored_line_numbers = []
blocked_line_numbers = []
if datastore.data['watching'][uuid].history_n == 0 and (watch.get_error_text() or watch.get_error_snapshot()):
# Gate on whether there is a snapshot to show, NOT on whether an error was recorded: a
# watch that has never completed a check and has no error text either (freshly added, or
# paused before its first check) has nothing to index into, and asking for the newest of
# no versions used to be a 500 on a page reachable from the watch list.
versions = list(watch.history.keys())
if not versions:
flash(gettext("Preview unavailable - No fetch/check completed or triggers not reached"), "error")
else:
# So prepare the latest preview or not
preferred_version = request.values.get('version') if request.method == 'POST' else request.args.get('version')
versions = list(watch.history.keys())
timestamp = versions[-1]
if preferred_version and preferred_version in versions:
timestamp = preferred_version
try:
versions = list(watch.history.keys())
content = watch.get_history_snapshot(timestamp=timestamp)
triggered_line_numbers = html_tools.strip_ignore_text(content=content,
@@ -66,3 +66,21 @@ def test_fetch_pdf(client, live_server, measure_memory_usage, datastore_path):
assert changed_md5.encode('utf-8') in res.data
assert b'here is a change' in res.data
def test_preview_of_a_watch_with_no_history(client, live_server, measure_memory_usage, datastore_path):
"""/preview must not 500 on a watch that has never completed a check.
The page is linked from the watch list, so it is reachable for a freshly added or paused
watch. The old guard only skipped the history lookup when history_n == 0 AND an error had
been recorded, so a clean never-checked watch asked for the newest of no versions and the
request died with IndexError.
"""
datastore = client.application.config.get('DATASTORE')
uuid = datastore.add_watch(url="https://example.com", extras={'paused': True})
assert datastore.data['watching'][uuid].history_n == 0
assert not datastore.data['watching'][uuid].get_error_text()
res = client.get(url_for("ui.ui_preview.preview_page", uuid=uuid), follow_redirects=True)
assert res.status_code == 200
assert b'Preview unavailable' in res.data
+101 -55
View File
File diff suppressed because one or more lines are too long