Skip to content

fix(add): preserve user keys & interior comments on tool overwrite#7

Merged
prostomarkeloff merged 1 commit into
mainfrom
fix/write-tool-preserve-user-keys
Jun 17, 2026
Merged

fix(add): preserve user keys & interior comments on tool overwrite#7
prostomarkeloff merged 1 commit into
mainfrom
fix/write-tool-preserve-user-keys

Conversation

@prostomarkeloff

Copy link
Copy Markdown
Owner

TL;DR

write_tool rebuilt [tool.ohbin.tools.<name>] from scratch, so re-publishing an
existing tool silently dropped user-authored keys (e.g. password_committed_ok),
ate interior comments, and could inject a stray blank line before the next section.
It now overwrites an existing entry in place, touching only the generated fields.

The bug

add-gist / add overwrites go through write_tool, which built a brand-new table
from the resolved ToolConfig and kept only the known fields plus the trailing
comment block. Everything else in the table was lost:

  • user-authored keys that aren't regenerated — e.g. password_committed_ok
  • comments sitting between keys (e.g. a "password intentionally committed" note)
  • the blank-line separator before the following section could double up

The fix

When the entry already exists, mutate it in place instead of rebuilding:

  • update only the ohbin-owned fields (repo / version / binary / encrypted /
    password) and the per-platform asset hashes;
  • leave extra keys, interior comments, and the trailing comment block untouched;
  • same platform set (the common re-publish): asset sub-tables are updated
    value-by-value — zero structural change, so surrounding trivia is preserved exactly;
  • changed set: reconcile (keep / update / drop / append) rather than
    empty-and-rebuild, which previously perturbed the leading blank line.

Testing

  • 2 new regression tests (same-set + changed-set overwrites) assert that the user
    key, the interior comment, the sibling section's layout, and the absence of doubled
    blank lines all survive an overwrite;
  • full suite green (70 passed); ruff format + ruff check clean; pyright reports
    0 errors;
  • end-to-end: re-running the fixed add-gist against a real consumer's pyproject is
    now idempotent and preserves password_committed_ok.

Bumps the package version to 0.2.3.

write_tool rebuilt [tool.ohbin.tools.<name>] from scratch, keeping only the generated ToolConfig fields plus trailing trivia. Re-publishing an existing tool therefore dropped any user-authored key (e.g. password_committed_ok), ate interior comments, and could inject a stray blank line before the next section.

Overwrite an existing entry in place instead: update only the generated fields and asset hashes, leaving extra keys, interior comments, and the trailing comment block untouched. The common re-publish keeps the same platform set, so asset sub-tables are updated value-by-value with no structural change; a changed set reconciles (update/keep/drop/append) rather than emptying the table, which previously perturbed the leading blank line.

Regression tests cover same-set and changed-set overwrites.
@prostomarkeloff prostomarkeloff merged commit 5c09900 into main Jun 17, 2026
13 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.

1 participant