Skip to content

Refuse a draft written under another Spec commit at resume and save - #224

Merged
guijacquemet merged 1 commit into
mainfrom
claude/draft-spec-commit-check
Nov 8, 2026
Merged

guijacquemet merged 1 commit into
mainfrom
claude/draft-spec-commit-check

Conversation

@guijacquemet

Copy link
Copy Markdown
Contributor

Fixes #223

What

  • run/draft_file.py: new _require_current_spec(answers), called in _resume() (so load_draft and publish_draft) right after the strict read, and in save_draft() after the strict round trip. If answers.spec_commit != SPEC_COMMIT it raises DraftFileError with code spec_commit_mismatch. The message names both commits, says the published morphobricks.toml is untouched, and says to start a fresh draft from the folders.
  • The stored commit is never rewritten, and the stale draft file is neither deleted nor repaired.
  • docs/contract.md §18 (reading, resume, saving rules) and CHANGELOG.md updated. Docstrings of DraftFileError, save_draft, load_draft and the module list the new code.

Why

answers_from_bytes() accepts any 40-hex spec_commit, and _resume() checked only base_sha256. A draft written under another Spec revision was resumed and published with its old confirmations (repeats, ID choices) as if given under the current rules.

Owner decision (2026-11-08)

A draft whose spec_commit differs from the current pinned SPEC_COMMIT is refused at resume. The published file is untouched, and the caller derives a fresh draft from the folders. Library code does not silently rewrite or delete the stale draft.

Regression evidence

New tests/test_draft_spec_commit.py (6 tests). Complete valid draft with only spec_commit changed to another valid 40-hex SHA:

  • load_draft refuses with spec_commit_mismatch, message names both commits, draft bytes identical;
  • publish_draft refuses, absent morphobricks.toml stays absent, draft bytes identical;
  • publish_draft refuses, existing morphobricks.toml byte-identical, draft bytes identical;
  • save_draft with a mismatching commit refuses and writes nothing (also keeps an earlier draft byte-identical);
  • control: a draft with the current commit round-trips and publishes.

Old code (src stashed, new tests kept): 5 failed, 1 passed (the control). New code: 6 passed.

Checks

python tools/check.py: ruff check and format clean, pytest 4575 passed, 4 skipped (4 skips are the pre-existing case-sensitivity / file-permission ones), code rules pass (no file over 600 lines, baselines not grown).


Generated by Claude Code

…223)

load_draft and publish_draft now raise DraftFileError(spec_commit_mismatch) when the
draft's spec_commit is not the pinned SPEC_COMMIT; save_draft refuses such answers.
The stored commit is never rewritten and the stale draft is left as it is.

Fixes #223

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Scma6W3LC11s3qjXHZuGDm
@guijacquemet
guijacquemet merged commit 61864c0 into main Nov 8, 2026
7 checks passed
@guijacquemet
guijacquemet deleted the claude/draft-spec-commit-check branch November 8, 2026 07:32
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.

Draft spec_commit is parsed but never compared: a draft from another Spec revision is resumed and published

2 participants