Skip to content

Define a non-lossy semantic round-trip contract#595

Draft
claell wants to merge 4 commits into
sciunto-org:mainfrom
claell:test/594-semantic-roundtrip
Draft

Define a non-lossy semantic round-trip contract#595
claell wants to merge 4 commits into
sciunto-org:mainfrom
claell:test/594-semantic-roundtrip

Conversation

@claell

@claell claell commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Define an ordered semantic inventory for entries, strings, preambles, comments, and failed blocks.
  • Require full parse/write/reparse paths to preserve that inventory without a cached-raw bypass.
  • Protect block and field order, comment position, and unrelated records during edits.
  • Permit documented canonical cleanup such as line-ending, whitespace, and enclosure normalization.
  • Fail explicitly if a future model block type is not classified by the contract.

Closes #594.

Dependency and commit structure

The first three commits are the exact failed-block behavior from PR #589, which is required for retained failures to survive without generated annotation blocks. The semantic contract is the final test-only commit. Once #589 merges, this branch should be rebased so reviewers see only the contract diff.

The default macro-linkage and enclosure-style proposals in PRs #591 and #593 are intentionally independent. This contract does not bundle those product decisions.

Validation

  • pytest -p no:cacheprovider -W error tests/test_roundtrip_contract.py: 6 passed.
  • Complete upstream suite: 2,589 passed, 12 skipped, with the four existing deprecation warnings in tests/test_entrypoint.py.
  • Complete pre-commit hook suite: passed.

Review note

This is deliberately not a byte-identity promise. The writer remains canonical and may normalize documented layout. The protected invariant is that all modeled bibliography meaning survives in order, including retained failed raw source, and that edits serialize through the actual model and writer.

AI assistance

This pull request was prepared with ChatGPT Codex using GPT-5.6 Sol with high reasoning effort. Codex assisted with contract design, dependency reduction, fixture adaptation, and validation. Automated validation is not a substitute for maintainer review.

claell added 4 commits July 16, 2026 17:02
* Format failed blocks with BibtexFormat.parsing_failed_comment.\n* Preserve the documented source-line placeholder.
* Write retained raw failures unchanged by default.
* Offer explicit annotate and fail-closed policies.
* Document why normal mutable blocks cannot safely use stale raw source.
* Recognize an existing annotation attached to the next failed block.
* Avoid adding a second terminal newline to retained raw source.
* Keep repeated opt-in annotation writes idempotent.
* Preserve meaningful blocks, order, comments, fields, values, and failures.
* Permit documented layout normalization without semantic drift.
* Exercise edited-record serialization without bypassing the parsed model.
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.

Define a non-lossy semantic round-trip contract

1 participant