Skip to content

fix: harden settings cancel, snapshot redaction, store readiness & atomic writes - #14

Merged
ellmos-multi-bot merged 1 commit into
mainfrom
fix/bugsweep-snapshot-readiness-settings-resilience-20261123
Nov 23, 2026
Merged

ellmos-multi-bot merged 1 commit into
mainfrom
fix/bugsweep-snapshot-readiness-settings-resilience-20261123

Conversation

@lukisch

@lukisch lukisch commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Systematic [SOFTWARE_BUGSEARCH] bugsweep iteration (WC-20261123-SOFTWARE-BUGSEARCH-MAILPROCESSOR) across the pre-declared focus area (tray.py, settings_dialog.py, snapshot_export.py, store_readiness.py, update_files.py).

Fixed Bug Complex (BS-01 – BS-05)

  1. BS-01 — Settings Cancel Persistence & Autostart Command Validation (tray.py, settings_dialog.py):
    • MailProcessorTray._open_settings() previously restored tools on Cancel, but still overwrote cfg.language from global get_language(), left start_with_windows mutated, and unconditionally called config.save(self._cfg) — writing unintended config state to %LOCALAPPDATA%\MailProcessor\config.json when the user cancelled the dialog. It now snapshots and restores tools, language, start_with_windows, and UI language on Cancel without saving to disk.
    • settings_dialog._command_tokens() and _is_current_autostart_command() previously accepted any stored registry command with len(current) >= len(expected) and split on whitespace on shlex.split errors, leaving broken autostart entries with trailing flags (e.g. --self-test) or unbalanced quotes unrepaired. It now enforces exact token length and balanced quoting, and _refresh_table() renders script paths via pathlib.Path instead of hardcoded backslashes.
  2. BS-02 — Snapshot Path Redaction, Scoped TOML Version Lookup & Atomic Export (snapshot_export.py):
    • _redact_path_hint() preserved "LOCALAPPDATA" ahead of "HOME" even when LOCALAPPDATA_ROOT fell back to Path.home(), mislabeling home paths as "LOCALAPPDATA/..." and making "HOME" unreachable; it also allowed relative paths to expand against CWD and sliced raw Path.parts[-2:] without normalizing .. segments.
    • _read_app_version() now scopes pyproject.toml lookups to [project].version (via tomllib with a bracket-aware Python 3.10 fallback), and write_snapshot() rejects blank/directory/symlink targets and writes atomically via os.replace() with finally temp-file cleanup.
  3. BS-03 & BS-04 — Fail-Closed Store Readiness Gates (store_readiness.py):
    • Enforces exact version boundaries ((?<![0-9.]){version}(?![0-9.])) in SHA256SUMS.txt (preventing 10.1.0 from matching 0.1.0) and rejects drive-relative, root-relative, and symlink-escaping artifact paths.
    • Parses [project].version via tomllib (with Python 3.10 fallback) so multiline arrays inside [project] do not truncate version lookup.
    • Requires the restrictedcapabilities XML namespace (rescap:Capability) for runFullTrust in AppxManifest.xml.
    • Parses requirements.txt with PEP-508 environment marker/comment stripping and PEP-503 token-boundary normalization against THIRD_PARTY_LICENSES.txt (eliminating substring false positives such as ring matching keyring), while catching UnicodeDecodeError fail-closed as a blocker check.
    • Distinguishes genuine Windows App Certification Kit (appcert.exe) XML OVERALL_RESULT="PASS" / structured Result: PASS reports from prose templates (Status: PENDING_MSIX_BUILD ... must pass), and excludes .git/.venv/_archive/build/dist trees.
  4. BS-05 — Maintenance Script Temp Cleanup & UTF-8 Error Handling (update_files.py):
    • _atomic_write() cleans up temporary files in finally if handle.write() or os.replace() fails, and plan_updates() turns UnicodeDecodeError into MaintenanceError (exit code 2).

Verification

  • TDD Red -> Green: 8/8 new regression tests in tests/test_bugsweep_snapshot_readiness_and_settings_20261123.py failed against unmodified main (c602ff1) and pass after the fix.
  • Full Pytest Suite: 114 passed, 6 subtests passed (QT_QPA_PLATFORM=offscreen).
  • Cross-Platform & CLI Smokes: python tests/source_platform_smoke.py (PASS), python store_readiness.py --json (exit 2, valid schema mailprocessor-store-readiness-v1), python update_files.py (exit 0, all 4 targets already current), real write_snapshot() roundtrip (1,018 bytes).
  • Linters & Gates: ruff check --no-cache . (All checks passed!), python -m compileall -q . (exit 0), lint_mermaid.py (CLEAN), git diff --check (exit 0).
  • Independent Second Review: Tier-1a adversarial code review completed with VERDICT: IMPRIMATUR / PASS (0 P0, 0 P1, 0 P2).

…omic writes

Bugsweep iteration WC-20261123-SOFTWARE-BUGSEARCH-MAILPROCESSOR (BS-01..BS-05):
- tray.py & settings_dialog.py: restore language/autostart/tools on Cancel without
  saving config.json; require exact token count & balanced quotes in autostart check.
- snapshot_export.py: preserve HOME label on LOCALAPPDATA fallback, avoid CWD
  expansion on relative paths, normalize '..' before tail redaction, scope TOML
  version lookup to [project], and write snapshots atomically with temp cleanup.
- store_readiness.py: enforce exact version boundaries, reject drive/root/symlink
  escapes, require rescap namespace for runFullTrust, check PEP-508/503 license
  tokens, distinguish WACK XML/protocol PASS from prose templates, ignore archive
  trees, and catch UnicodeDecodeError fail-closed.
- update_files.py: clean up temp files on replace failure and catch invalid UTF-8.
- tests: add 8 regression tests in test_bugsweep_snapshot_readiness_and_settings_20261123.py.

lukisch commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Zweitprüfung (Cloud-Bot)

Ergebnis: freigegeben ✅ (formales Approve geht nicht, weil es derselbe Account ist)

CI: Alle 15 Checks sind grün: Windows 3.10–3.13, Source-Smoke auf Ubuntu und macOS, CodeQL.

Code-Review (tray.py, settings_dialog.py, snapshot_export.py):

  • _open_settings() bei Abbruch: tools, language, start_with_windows und die UI-Sprache werden zurückgesetzt, ohne config.save() aufzurufen. Das ist korrekt. Die Registry wird nur in _on_save() beschrieben, beim Abbruch bleibt also kein Seiteneffekt zurück.
  • _command_tokens(): Bei unbalancierten Quotes kommt [] zurück, und _is_current_autostart_command() verlangt exakt gleich viele Tokens. Ein Eintrag mit angehängten Flags gilt damit als veraltet und wird repariert. Plausibel.
  • write_snapshot(): Schreibt atomar über NamedTemporaryFile plus os.replace, mit Aufräumen in finally, und lehnt Symlink- und Verzeichnisziele ab. Gut so.
    • Kleiner Nebeneffekt: NamedTemporaryFile legt die Datei mit Modus 0600 an, und os.replace übernimmt diesen. Auf POSIX ist der Snapshot dadurch nur noch für den Eigentümer lesbar. Für einen datenschutzbezogenen Export ist das eher erwünscht. Nur zur Info.

Lokal (Linux, Python 3.11, ohne libEGL): 72 passed. Die 6 Qt-Testmodule ließen sich mangels libEGL.so.1 nicht laden, das ist ein Umgebungsproblem. Der einzige Fehler, test_snapshot_export::…platform == "windows", tritt auf main genauso auf, weil der Test auf Windows festgelegt ist. Er hat nichts mit diesem PR zu tun.

Scope-Hinweis: Der PR enthält auch fachfremde Änderungen, nämlich neu erzeugte mobile_icons/* und das Entfernen von MARKETING-LOG.txt aus dem Tracking. Das ist unkritisch, sollte aber in der PR-Beschreibung stehen.


Generated by Claude Code

lukisch commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Zweitprüfung (Cloud-Bot)

Ergebnis: freigegeben ✅ (formales Approve nicht möglich, da gleicher Account)

  • Lokaler Testlauf auf dc8fe0c (Linux, Py 3.11, offscreen): 113 passed, 1 failed.
    • Der Fehlschlag ist test_build_snapshot_payload_redacts_private_paths_and_reports_statuses. Der Test erwartet platform == "windows" und hängt damit vom Host ab.
    • Er scheitert auf der Base c602ff1 genauso, ist also keine Regression durch diesen PR.
    • Die neuen Regressionstests laufen grün, CI ist auf allen Plattformen grün.
  • Im Code nachvollzogen:
    • Settings-Cancel: Es wird nichts mehr gespeichert, weder vom Dialog noch von ToolManager (scan/register/unregister). Tools, Sprache und Autostart werden zurückgesetzt.
    • Autostart-Tokens: Pfade mit Leerzeichen, Apostroph und --self-test werden korrekt behandelt.
    • Snapshot-Export: Der Schreibvorgang ist atomar (Temp-Datei im Zielverzeichnis, os.replace, Aufräumen im finally). Das ist auch unter Windows korrekt, weil die Temp-Datei vor dem Replace geschlossen wird. Die Pfadschwärzung entfernt .. und löst relative Pfade nicht mehr gegen das Arbeitsverzeichnis auf.
    • store_readiness.py --json: Base und Head liefern je Prüfung identische Ergebnisse. Ein BOM in AppxManifest.xml wird korrekt eingelesen.
    • update_files.py: Die Temp-Datei wird in jedem Fehlerpfad aufgeräumt.

Nicht blockierende Hinweise:

  1. store_readiness.py (_IGNORED_DIRS) überspringt build/dist. build_exe.bat schreibt aber nach dist\. Ein später dort erzeugtes MSIX, Manifest oder WACK-Report würde nicht gefunden, und das Gate meldet dann fälschlich einen Blocker.
  2. _extract_requirement_name überspringt jetzt -r/-c-Zeilen stillschweigend, vorher gab es dafür einen Blocker. Eingebundene Requirements-Dateien laufen damit nicht mehr durch die Lizenzprüfung. Mit der aktuellen requirements.txt (nur PySide6) wirkt sich das noch nicht aus.

Generated by Claude Code

@lukisch lukisch left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zweitprüfung (Cloud-Bot): freigabefähig, mit zwei kleinen Hinweisen. Geprüft am Head dc8fe0c.

Geprüft und plausibel

  • BS-01 Cancel-Pfad (tray.py): SettingsDialog schreibt Sprache, Autostart-Registry und Config nur in _on_save(). Bei Cancel stellt der Tray jetzt tools, language, start_with_windows und die UI-Sprache wieder her, ohne cfg_module.save() aufzurufen. Das passt, Registry und Config können nicht auseinanderlaufen. _command_tokens mit exakter Tokenlänge: _expected_autostart_command() erzeugt nur "exe" bzw. "exe" "main.py". Einträge mit zusätzlichen Flags wurden bisher fälschlich als aktuell erkannt und werden jetzt repariert.
  • BS-02 write_snapshot: Die atomische Ersetzung samt finally-Cleanup ist korrekt. Ein TOMLDecodeError in _extract_pyproject_version landet im bestehenden except Exception von _read_app_version. Bei _redact_path_hint ist die Gleichsetzung LOCALAPPDATA = HOME jetzt richtig aufgelöst.
  • BS-03/04 store_readiness.py: Der Versions-Lookaround (10.1.0 ≠ 0.1.0) ist korrekt. Die Pfadprüfung lehnt Laufwerk, Root, .. und Symlinks vor resolve() ab. Die PEP-503-Tokenisierung behebt die Substring-Falschtreffer (ring ⊂ keyring). Gegengeprüft: ET.fromstring() verträgt auch einen UTF-8-BOM vor der XML-Deklaration, gegenüber ET.parse() geht also nichts verloren.
  • BS-05 update_files.py: temporary_path wird jetzt vor dem write gesetzt und im finally aufgeräumt. Das korrigiert auch das bisherige Leck, wenn write() fehlschlug.
  • CI: alle 15 Checks grün (Windows 3.10–3.13, ubuntu/macOS-Smokes, CodeQL).

Hinweise (nicht blockierend)

  1. tempfile.NamedTemporaryFile legt die Datei unter POSIX mit Modus 0600 an. Nach os.replace hat der Snapshot deshalb restriktivere Rechte als vorher (umask). Für einen redigierten Diagnose-Export ist das eher ein Vorteil. Falls ein anderer Prozess die Datei lesen soll, wäre ein os.chmod nötig.
  2. Lokal konnte ich nur die Nicht-Qt-Teile prüfen, weil der Sandbox-Host kein libEGL hat. Die Qt-abhängigen Regressionstests sind nur durch die CI belegt.

Generated by Claude Code

@ellmos-multi-bot ellmos-multi-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Second-Instance Review (APPROVE)

  • Model & Independence: Gemini 4 Carbon (Medium) (fresh scheduled operator instance + independent second-instance verification, review_independence = instance)
  • Reviewed Head SHA: dc8fe0cc285c44e1c31cbdb1070750fd25a9abef (base: main @ c602ff16462edd33600f345f3fba2d67f8d4be3f)
  • Scope Read: Complete diff across all 7 modified files (+751 / -73: CHANGELOG.md, settings_dialog.py, snapshot_export.py, store_readiness.py, tray.py, update_files.py, tests/test_bugsweep_snapshot_readiness_and_settings_20261123.py) and adjacent source modules.
  • Full Test Suite & Verification:
    • python -m pytest -q: 114 passed, 6 subtests passed (full repository test suite including Qt/PySide6 tray and settings tests)
    • ruff check --no-cache .: 0 issues
    • python -m compileall -q .: pass
    • Mermaid syntax check & repository privacy check: pass; version 0.1.0 unchanged (pyproject.toml:7); GitHub Actions CI 15/15 green.

Verified Changes & Non-Blocking Follow-up Notes

  • Verified: Settings cancel path (tray.py:147-161) cleanly restores tools, language, start_with_windows, and active UI locale without writing config.json; atomic temp-file replacement with finally cleanup (snapshot_export.py:87-107, update_files.py:196-214); LOCALAPPDATA == HOME fallback preservation and .. normalization in _redact_path_hint() (snapshot_export.py:245-277); and fail-closed rescap:Capability, PEP-503 boundary, exact version boundary, and WACK XML/report checks in store_readiness.py.
  • [P2 — Follow-up] Trailing unbalanced quote check (settings_dialog.py:52-60): _command_tokens() rejects unclosed leading quotes (startswith(q) and not endswith(q)), whereas a stray trailing quote without a leading quote (MailProcessor.exe") would pass shlex.split(..., posix=False) and be stripped in _normalize_cmd_token() (settings_dialog.py:34). Tightening to symmetric startswith(q) != endswith(q) in a future cleanup pass will catch that edge case too.
  • [Nit — Follow-up] Duplicate save on Accepted (settings_dialog.py:344, tray.py:166): _on_save() already persists self._cfg before _open_settings() calls cfg_module.save(self._cfg) again.

@ellmos-multi-bot
ellmos-multi-bot merged commit 6795e5c into main Nov 23, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants