Skip to content

fix(library): validate snippet lock flag before writing on import - #2

Open
lukisch wants to merge 2 commits into
masterfrom
claude/determined-mayer-1fp8hs
Open

lukisch wants to merge 2 commits into
masterfrom
claude/determined-mayer-1fp8hs

Conversation

@lukisch

@lukisch lukisch commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Found while reviewing #1; independent of it and based on master.

Problem

LibraryManager.import_payload saved each snippet first and checked its locked value afterwards. If the value was invalid (for example "locked": "maybe"), it deleted the snippet again. A snippet of the same name that existed before the import was overwritten and then deleted, so the user lost it.

Fix

The locked value is checked before anything is written. Entries with an invalid value are skipped and counted as skipped; the library is not touched.

Verification

  • pytest: 122 passed (121 before, 1 new), Linux, Python 3.11, PySide6 6.11.3, offscreen.
  • The new test fails on master without the source change.
  • ruff check tests: clean.

Not changed


Generated by Claude Code

import_payload saved each snippet first and checked its locked value
afterwards. An invalid value made it delete the snippet again, which
also removed a snippet of the same name that existed before the import.
The value is now checked first and such entries are skipped untouched.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01THB2F2DbFt7kDuUx3ZdWAr
@github-actions

Copy link
Copy Markdown

Welcome! 👋 Thanks for your first pull request in this repository.

A maintainer will review it soon. Please make sure:

  • Your changes are tested
  • Documentation is updated if needed
  • The PR description explains what and why

Thanks for contributing!

@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.

Second-model review: no blocking findings, ready to merge. (Posted as a comment because the bot account is also the PR author and cannot approve.)

Checked on head 709e5ea, Linux, Python 3.11, PySide6 6.11.3, offscreen:

  • pytest: 122 passed. All 10 CI checks are green.
  • Negative control: with PythonBox_v8.py from master and the tests from this PR, the new test fails (1 failed, 121 passed). So the test does cover the data loss.
  • The change only moves the locked check ahead of save_snippet; valid imports take the same path as before.

Merge order: this PR and #1 both add a test at the same place in tests/test_pythonbox_regressions.py and conflict there (the PR description only mentions the changelog). The source changes do not overlap. Whichever is merged second needs a rebase, and the tests badge should then read 127.


Generated by Claude Code

Keeps this branch mergeable alongside the open path-traversal PR, which
appends tests at the same place in LibraryExportRegressionTests.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01THB2F2DbFt7kDuUx3ZdWAr

@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, 2026-11-11) auf 95475e3: freigabefähig, keine Blocker. Eine formale Approval ist nicht möglich, weil der Bot unter demselben Konto läuft wie der PR-Autor.

  • Die Änderung verschiebt nur die locked-Prüfung vor save_snippet; der Rest von import_payload bleibt gleich. Ein ungültiger Wert führt jetzt zu skipped, ohne dass geschrieben oder gelöscht wird.
  • pytest lokal: 122 passed (Linux, Python 3.11, PySide6 6.11.3, offscreen). CI: alle 9 Checks grün.
  • Zusammen mit #1 gemergt: kein Konflikt, 127 passed. Das Tests-Badge muss danach auf 127.

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 auf 95475e3: inhaltlich freigegeben, keine Einwände. (Als Kommentar, weil GitHub eine formale Freigabe des eigenen PRs nicht zulässt.)

  • Die Reihenfolge stimmt jetzt: _coerce_portable_bool(locked) läuft vor save_snippet, ein ungültiger locked-Wert fasst die Bibliothek nicht mehr an. Der alte Pfad (speichern, dann delete_item) hat ein vorhandenes gleichnamiges Snippet tatsächlich überschrieben und gelöscht.
  • Der neue Test deckt beide Fälle ab (vorhandenes Snippet bleibt, neues wird nicht angelegt).
  • CI auf dem Head ist grün (Regression 3.10–3.13, Smoke Ubuntu/macOS, CodeQL). Lokal konnte ich die Suite nicht ausführen (kein libEGL im Container), die Prüfung stützt sich auf Diff und CI.
  • Lässt sich konfliktfrei mit #1 zusammenführen (git merge-tree geprüft).

Kleinigkeit, nicht blockierend: Der Test-Badge in README.md/README_de.md wird hier nicht angehoben. #1 setzt ihn auf 126; nach beiden Merges sind es 127 Tests.


Generated by Claude Code

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