b0939cf309
`09` §3 decision 145. MARKER_IGNORE in upgrade-test.py: per app, the files the
files_may_change mark does not count — first immich's six 13-byte
{encoded-video,library,backups,profile,thumbs,upload}/.immich folder markers,
rewritten at every start (bench measurement 2026-09-30). A listed file is
ignored only when changed/added and still <= 64 bytes; a removed or grown
marker, any unlisted file, and a moved tree the file walk cannot name still
mark the step. The verdict records files_ignored with the reasons.
HARNESS_VERSION 5. Tests: test_upgrade_bench.py MarkerIgnore (red-proved).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
151 lines
7.5 KiB
Python
151 lines
7.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""test_upgrade_bench.py — the test bench's two night-of-2026-09-23 faults (R-653, R-656). No Docker.
|
|
|
|
python3 scripts/test_upgrade_bench.py
|
|
"""
|
|
import importlib.util
|
|
import os
|
|
import shutil
|
|
import tempfile
|
|
import unittest
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
spec = importlib.util.spec_from_file_location("upgrade_test_mod", os.path.join(HERE, "upgrade-test.py"))
|
|
ut = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(ut)
|
|
|
|
|
|
class LoadVerdict(unittest.TestCase):
|
|
"""R-653. RED-PROOF (REPORT.md): make load_verdict always return "reached" — the ghost case fails."""
|
|
|
|
def test_every_request_errored_is_inconclusive(self):
|
|
# ghost's first watch, 2026-09-23 night: 11 797 requests, all `err`
|
|
self.assertEqual(ut.load_verdict(11797, {"err": 11797}), "inconclusive")
|
|
|
|
def test_answers_of_any_code_are_the_app_answering(self):
|
|
self.assertEqual(ut.load_verdict(11429, {"200": 5712, "401": 5717}), "reached")
|
|
self.assertEqual(ut.load_verdict(10, {"302": 5, "err": 5}), "reached")
|
|
|
|
def test_under_half_is_inconclusive_and_none_is_inconclusive(self):
|
|
self.assertEqual(ut.load_verdict(10, {"200": 4, "err": 6}), "inconclusive")
|
|
self.assertEqual(ut.load_verdict(0, {}), "inconclusive")
|
|
|
|
|
|
class ClearScratch(unittest.TestCase):
|
|
"""R-656. RED-PROOF (REPORT.md): make clear_scratch_folders return [] without removing — the first
|
|
test fails with the last run's config still there."""
|
|
|
|
def setUp(self):
|
|
self.root = tempfile.mkdtemp(prefix="bench-scratch-")
|
|
self.hdd = os.path.join(self.root, "hdd")
|
|
self.env = {"HDD_PATH": self.hdd, "USERDATA_PATH": self.hdd + "/userdata"}
|
|
self.said = []
|
|
|
|
def tearDown(self):
|
|
shutil.rmtree(self.root, ignore_errors=True)
|
|
|
|
def plant(self, rel):
|
|
p = os.path.join(self.hdd, rel, "config", "config.php")
|
|
os.makedirs(os.path.dirname(p), exist_ok=True)
|
|
open(p, "w").write("last run")
|
|
return p
|
|
|
|
def test_the_apps_own_folders_are_cleared_and_said(self):
|
|
mine = self.plant("appdata/nextcloud")
|
|
other = self.plant("appdata/immich")
|
|
comp = "services:\n nextcloud:\n volumes:\n - ${HDD_PATH}/appdata/nextcloud:/var/www/html\n"
|
|
got = ut.clear_scratch_folders(comp, self.env, self.said.append)
|
|
self.assertFalse(os.path.exists(mine), "the last run's files are still there")
|
|
self.assertTrue(os.path.exists(other), "another app's folder was touched")
|
|
self.assertEqual(len(got), 1)
|
|
self.assertTrue(any("cleared before FROM" in s for s in self.said))
|
|
|
|
def test_never_a_bare_root_never_outside(self):
|
|
keep = self.plant("appdata/x")
|
|
comp = (" volumes:\n - ${HDD_PATH}:/data\n - ${HDD_PATH}/:/d2\n"
|
|
" - ${HDD_PATH}/../escape:/e\n")
|
|
got = ut.clear_scratch_folders(comp, self.env, self.said.append)
|
|
self.assertEqual(got, [])
|
|
self.assertTrue(os.path.exists(keep))
|
|
|
|
|
|
class ChangedFiles(unittest.TestCase):
|
|
"""2026-09-30: a `files_may_change` mark names its files (R-734's method, now in the harness)."""
|
|
|
|
def test_names_changed_added_removed_and_nothing_else(self):
|
|
before = {"/d": {"a.txt": "1:aa", "b.txt": "1:bb", "gone": "1:cc"}}
|
|
after = {"/d": {"a.txt": "1:aa", "b.txt": "2:bd", "new": "1:dd"}}
|
|
self.assertEqual(ut.changed_files(before, after),
|
|
["/d/b.txt (changed)", "/d/gone (removed)", "/d/new (added)"])
|
|
self.assertEqual(ut.changed_files(before, before), [])
|
|
|
|
|
|
class MarkerIgnore(unittest.TestCase):
|
|
"""R-734 (`09` §3 decision 145): app-owned marker files do not make the `files_may_change` mark; any other
|
|
changed file still does. The data is the bench's own measurement (audits/more-night-apps-2026-09-30/D/evidence/
|
|
D-immich-0b82-768/files-{before,after}-detail.json). RED-PROOF (REPORT): make classify_changes ignore every
|
|
changed file of an app with a list — test_an_unlisted_changed_file_still_marks fails."""
|
|
|
|
SRC = "/srv/felhom-gate/hdd/appdata/immich"
|
|
BEFORE = {SRC: {"profile/.immich": "13:7cb1f8a19d944d7e", "upload/.immich": "13:67848ba791bd7ef6",
|
|
"encoded-video/.immich": "13:68bdf71e87fabadc", "backups/.immich": "13:7cb1f8a19d944d7e",
|
|
"thumbs/.immich": "13:7cb1f8a19d944d7e", "library/.immich": "13:67848ba791bd7ef6"},
|
|
"/srv/felhom-gate/hdd/userdata/media/photos": {}}
|
|
AFTER = {SRC: {"profile/.immich": "13:0bacc6528e07d8cb", "upload/.immich": "13:a68db79a3fbe6725",
|
|
"encoded-video/.immich": "13:2cb994a10bfe243c", "backups/.immich": "13:648fe4b9664fadff",
|
|
"thumbs/.immich": "13:0bacc6528e07d8cb", "library/.immich": "13:a68db79a3fbe6725"},
|
|
"/srv/felhom-gate/hdd/userdata/media/photos": {}}
|
|
|
|
def mark(self, app, before, after):
|
|
counted, ignored = ut.classify_changes(app, before, after)
|
|
tree = sorted({c.split(" (")[0].rsplit("/", 2)[0] for c in counted + [i["file"] for i in ignored]})
|
|
return ut.files_may_change(tree, counted, ignored), counted, ignored
|
|
|
|
def test_the_six_measured_markers_do_not_mark_and_each_carries_a_reason(self):
|
|
marked, counted, ignored = self.mark("immich", self.BEFORE, self.AFTER)
|
|
self.assertFalse(marked)
|
|
self.assertEqual(counted, [])
|
|
self.assertEqual(len(ignored), 6)
|
|
self.assertTrue(all(i["reason"] for i in ignored))
|
|
|
|
def test_an_unlisted_changed_file_still_marks(self):
|
|
after = {k: dict(v) for k, v in self.AFTER.items()}
|
|
after[self.SRC]["library/admin/2026/IMG_0001.jpg"] = "2048:abcd" # added: a household photo
|
|
before = {k: dict(v) for k, v in self.BEFORE.items()}
|
|
before[self.SRC]["upload/upload/x.jpg"] = "10:aa"
|
|
after[self.SRC]["upload/upload/x.jpg"] = "10:bb" # changed, same size as a marker
|
|
marked, counted, ignored = self.mark("immich", before, after)
|
|
self.assertTrue(marked)
|
|
self.assertIn(self.SRC + "/library/admin/2026/IMG_0001.jpg (added)", counted)
|
|
self.assertIn(self.SRC + "/upload/upload/x.jpg (changed)", counted)
|
|
self.assertEqual(len(ignored), 6)
|
|
|
|
def test_a_listed_name_that_grew_or_vanished_still_marks(self):
|
|
after = {k: dict(v) for k, v in self.AFTER.items()}
|
|
after[self.SRC]["thumbs/.immich"] = "4096:ffff" # no longer a 13-byte marker
|
|
del after[self.SRC]["upload/.immich"] # removed
|
|
marked, counted, _ = self.mark("immich", self.BEFORE, after)
|
|
self.assertTrue(marked)
|
|
self.assertIn(self.SRC + "/thumbs/.immich (changed)", counted)
|
|
self.assertIn(self.SRC + "/upload/.immich (removed)", counted)
|
|
|
|
def test_the_list_belongs_to_its_app(self):
|
|
# the same files under another app (and another bind) count: the list is per app
|
|
marked, counted, ignored = self.mark("calibre-web", self.BEFORE, self.AFTER)
|
|
self.assertTrue(marked)
|
|
self.assertEqual((len(counted), ignored), (6, []))
|
|
|
|
def test_a_moved_tree_the_file_walk_cannot_name_keeps_the_mark(self):
|
|
self.assertTrue(ut.files_may_change(["/d"], [], []))
|
|
self.assertFalse(ut.files_may_change([], [], []))
|
|
|
|
def test_every_entry_has_a_reason(self):
|
|
for app, rules in ut.MARKER_IGNORE.items():
|
|
for suffix, path, max_size, reason in rules:
|
|
self.assertTrue(suffix and path and max_size > 0 and len(reason) > 40, (app, path))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=2)
|