Repository navigation
feat(domain): ratify guarded test edit precondition DTOs (Closes #1902) - #12649
EffortlessSteven wants to merge 2 commits into
Conversation
Accept ADR 0025 and RIPR-SPEC-0320 for one bounded test-only assertion replacement class. Add fail-closed ExactTestEditPrecondition minting, GuardedEditUnavailable reasons, corpus fixtures, and traceability without emitting LSP edits. Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 43 minutes. View limit details
|
Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>
|
|
EffortlessSteven
left a comment
There was a problem hiding this comment.
REPAIR_REQUIRED — head 9414057
Reviewed against current main (0244de7) on a trial merge. Executed here: cargo test -p ripr --lib guarded_edit (6 passed, 0 failed) and the xtask gates named below. No unresolved review threads on this PR. Three repairs and one owner decision are open.
1. Silent mis-merge in .ripr/traceability.toml (no conflict markers). Main and this PR both append at the end of the file, so git interleaves them: the RIPR-SPEC-0320 block lands inside main's last entry (RIPR-SPEC-0408) and loses its [[behavior]] header. cargo xtask check-traceability fails: .ripr/traceability.toml:21759 expected quoted string ... RIPR-SPEC-0320 ... is missing from .ripr/traceability.toml. Repair: restore main's tail and append the PR's [[behavior]] block after it (with the blank line and header). Better still, put it in .ripr/traceability.d/ as a fragment, which is how specs register on main and avoids this append collision.
2. check-architecture fails. crates/ripr/src/domain/guarded_edit.rs contains forbidden architecture pattern serde_json (domain must not know JSON rendering). The use is in the cfg(test) corpus test (line 692 onward). policy/architecture.txt exempts one domain file for the same reason (!crates/ripr/src/domain/next_action.rs|serde_json|...) with a stated reason. Either add the same kind of exemption for guarded_edit.rs with its reason (test-only corpus parsing), or move the corpus test to an integration test under crates/ripr/tests/. The second keeps the policy file untouched.
3. Two text conflicts with main.
docs/identity/REGISTRY.md: keep main'sDiagnosticResultIdrow (domain::analysis_execution_identity::DiagnosticResultId) and this PR'sEditInstructionIdrow (domain::guarded_edit::EditInstructionId).policy/doc-artifacts.toml: keep both artifact blocks (main's RIPR-SPEC-0411 and this PR's RIPR-SPEC-0320), each under its own[[artifact]].
registry.v1.jsonmerges cleanly, andcheck-identity-registrypasses after the two resolutions above.
4. Owner decision, not a code defect: ADR 0025 is written as Status: accepted. The ADR changes the editor surface's standing posture from read-only to read-only with one opt-in exception, and RIPR-SPEC-0069's non-goals are amended to match. Issue #1902 records that this is a pending design decision ("If the guarded edit is accepted, require both ..."; the 2026-08-01 note calls it "genuinely pending"). The PR matches the policy requirements stated there (workspace-edit capability plus explicit opt-in; digest, range, version and instruction id in passive data). Nothing I found shows the acceptance itself was given. Recommendation: keep the ADR at Status: proposed until the owner rules, as with ADR 0024, and flip it in a one-line follow-up; or get the owner's explicit yes on #1902 first. That is the owner's call, so I am flagging it rather than resolving it.
Passing on the merged tree: check-spec-format, check-doc-artifacts, check-doc-index, check-identity-registry, check-output-contracts, check-public-api, check-fixture-contracts, check-generated-clean, check-static-language, check-file-policy and check-dependencies. Not run: the full lib suite, goldens, clippy and the hosted Result.
The merged tree with repairs 1 and 3 applied, as a patch against main 0244de7, is at /mnt/project-files/merge-queue/drafts/12649-resolved-on-main-0244de7d.patch. Repair 2 and the ADR status are left for the author lane. A fresh native review is needed at the repaired head. I did not touch the Cursor branch.
Generated by Claude Code
| pub fn verify_document_version( | ||
| precondition: &ExactTestEditPrecondition, | ||
| current_document_version: Option<u32>, | ||
| ) -> Result<(), GuardedEditUnavailable> { | ||
| match (precondition.document_version, current_document_version) { | ||
| (Some(expected), Some(actual)) if expected == actual => Ok(()), | ||
| (None, _) => Ok(()), | ||
| _ => Err(GuardedEditUnavailable::new( | ||
| GuardedEditUnavailableReason::DocumentVersionMismatch, | ||
| )), | ||
| } | ||
| } |
There was a problem hiding this comment.
verify_document_version fails open. When precondition.document_version is None, the (None, _) => Ok(()) arm accepts any current document version. The builder also accepts document_version: None, and validate() never requires it. A precondition minted without a version therefore passes the apply-time stale-document check even after the buffer has changed.
If the precondition carries no version, return DocumentVersionMismatch (or SourcePreconditionMissing) instead of Ok. Alternatively, require document_version in the builder and in validate().
match (precondition.document_version, current_document_version) {
(Some(e), Some(a)) if e == a => Ok(()),
_ => Err(GuardedEditUnavailable::new(DocumentVersionMismatch)),
}| pub fn verify_document_version( | |
| precondition: &ExactTestEditPrecondition, | |
| current_document_version: Option<u32>, | |
| ) -> Result<(), GuardedEditUnavailable> { | |
| match (precondition.document_version, current_document_version) { | |
| (Some(expected), Some(actual)) if expected == actual => Ok(()), | |
| (None, _) => Ok(()), | |
| _ => Err(GuardedEditUnavailable::new( | |
| GuardedEditUnavailableReason::DocumentVersionMismatch, | |
| )), | |
| } | |
| } | |
| pub fn verify_document_version( | |
| precondition: &ExactTestEditPrecondition, | |
| current_document_version: Option<u32>, | |
| ) -> Result<(), GuardedEditUnavailable> { | |
| match (precondition.document_version, current_document_version) { | |
| (Some(expected), Some(actual)) if expected == actual => Ok(()), | |
| _ => Err(GuardedEditUnavailable::new( | |
| GuardedEditUnavailableReason::DocumentVersionMismatch, | |
| )), | |
| } | |
| } | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
| pub fn verify_source_text( | ||
| precondition: &ExactTestEditPrecondition, | ||
| current_text: &str, | ||
| ) -> Result<(), GuardedEditUnavailable> { | ||
| let expected = precondition | ||
| .original_source_text | ||
| .as_deref() | ||
| .ok_or_else(|| { | ||
| GuardedEditUnavailable::new(GuardedEditUnavailableReason::SourcePreconditionMissing) | ||
| })?; | ||
| if expected != current_text { | ||
| return Err(GuardedEditUnavailable::new( | ||
| GuardedEditUnavailableReason::SourceTextMismatch, | ||
| )); | ||
| } | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
verify_source_text only works when original_source_text is present. validate() and the ADR explicitly allow digest-only preconditions (original_source_text = None with original_source_digest = Some). For those, this function returns SourcePreconditionMissing even when the current text matches the digest, so a valid digest-only precondition can never be applied.
When the text is absent, fall back to comparing sha256_digest(current_text) with original_source_digest. Also compare the digest when both fields are present.
| pub fn verify_source_text( | |
| precondition: &ExactTestEditPrecondition, | |
| current_text: &str, | |
| ) -> Result<(), GuardedEditUnavailable> { | |
| let expected = precondition | |
| .original_source_text | |
| .as_deref() | |
| .ok_or_else(|| { | |
| GuardedEditUnavailable::new(GuardedEditUnavailableReason::SourcePreconditionMissing) | |
| })?; | |
| if expected != current_text { | |
| return Err(GuardedEditUnavailable::new( | |
| GuardedEditUnavailableReason::SourceTextMismatch, | |
| )); | |
| } | |
| Ok(()) | |
| } | |
| pub fn verify_source_text( | |
| precondition: &ExactTestEditPrecondition, | |
| current_text: &str, | |
| ) -> Result<(), GuardedEditUnavailable> { | |
| let expected_text = precondition.original_source_text.as_deref(); | |
| let expected_digest = precondition.original_source_digest.as_deref(); | |
| if expected_text.is_none() && expected_digest.is_none() { | |
| return Err(GuardedEditUnavailable::new( | |
| GuardedEditUnavailableReason::SourcePreconditionMissing, | |
| )); | |
| } | |
| if let Some(expected) = expected_text { | |
| if expected != current_text { | |
| return Err(GuardedEditUnavailable::new( | |
| GuardedEditUnavailableReason::SourceTextMismatch, | |
| )); | |
| } | |
| } | |
| if let Some(expected) = expected_digest { | |
| if expected != sha256_digest(current_text) { | |
| return Err(GuardedEditUnavailable::new( | |
| GuardedEditUnavailableReason::SourceTextMismatch, | |
| )); | |
| } | |
| } | |
| Ok(()) | |
| } | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
| fn mint_edit_instruction_id(input: &GuardedEditBuildInput) -> EditInstructionId { | ||
| let canonical = input | ||
| .canonical_item | ||
| .as_ref() | ||
| .map(|item| item.as_str()) | ||
| .unwrap_or(""); | ||
| let digest = identity_digest(&[ | ||
| ("canonical_item", canonical), | ||
| ("test_file", &normalize_path(&input.test_file)), | ||
| ("test_selector", &input.test_selector), | ||
| ( | ||
| "original", | ||
| input.original_source_text.as_deref().unwrap_or(""), | ||
| ), | ||
| ("replacement", &input.exact_replacement_text), | ||
| ( | ||
| "range", | ||
| &format!( | ||
| "{}:{}-{}:{}", | ||
| input.assertion_range.start_line, | ||
| input.assertion_range.start_character, | ||
| input.assertion_range.end_line, | ||
| input.assertion_range.end_character | ||
| ), | ||
| ), | ||
| ]); | ||
| EditInstructionId(format!("edit-instruction:{digest:016x}")) | ||
| } |
There was a problem hiding this comment.
The minted EditInstructionId ignores document_version, instruction_instance_id and instruction_semantic_id. The identity registry (docs/identity/REGISTRY.md and registry.v1.json) declares its invalidation rule as "Any source, range, or document-version change" and lists document_version and instruction_instance as semantic inputs. Two preconditions that differ only in document version, or only in instruction instance, get the same id. A snapshot-bound id then fails to change when it must.
Include document_version and the instruction ids in the identity_digest parts.
| fn mint_edit_instruction_id(input: &GuardedEditBuildInput) -> EditInstructionId { | |
| let canonical = input | |
| .canonical_item | |
| .as_ref() | |
| .map(|item| item.as_str()) | |
| .unwrap_or(""); | |
| let digest = identity_digest(&[ | |
| ("canonical_item", canonical), | |
| ("test_file", &normalize_path(&input.test_file)), | |
| ("test_selector", &input.test_selector), | |
| ( | |
| "original", | |
| input.original_source_text.as_deref().unwrap_or(""), | |
| ), | |
| ("replacement", &input.exact_replacement_text), | |
| ( | |
| "range", | |
| &format!( | |
| "{}:{}-{}:{}", | |
| input.assertion_range.start_line, | |
| input.assertion_range.start_character, | |
| input.assertion_range.end_line, | |
| input.assertion_range.end_character | |
| ), | |
| ), | |
| ]); | |
| EditInstructionId(format!("edit-instruction:{digest:016x}")) | |
| } | |
| fn mint_edit_instruction_id(input: &GuardedEditBuildInput) -> EditInstructionId { | |
| let canonical = input | |
| .canonical_item | |
| .as_ref() | |
| .map(|item| item.as_str()) | |
| .unwrap_or(""); | |
| let digest = identity_digest(&[ | |
| ("canonical_item", canonical), | |
| ("test_file", &normalize_path(&input.test_file)), | |
| ("test_selector", &input.test_selector), | |
| ( | |
| "original", | |
| input.original_source_text.as_deref().unwrap_or(""), | |
| ), | |
| ("replacement", &input.exact_replacement_text), | |
| ( | |
| "range", | |
| &format!( | |
| "{}:{}-{}:{}", | |
| input.assertion_range.start_line, | |
| input.assertion_range.start_character, | |
| input.assertion_range.end_line, | |
| input.assertion_range.end_character | |
| ), | |
| ), | |
| ("document_version", &format!("{:?}", input.document_version)), | |
| ( | |
| "instruction_instance_id", | |
| &format!("{:?}", input.instruction_instance_id), | |
| ), | |
| ( | |
| "instruction_semantic_id", | |
| &format!("{:?}", input.instruction_semantic_id), | |
| ), | |
| ]); | |
| EditInstructionId(format!("edit-instruction:{digest:016x}")) | |
| } | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
| pub fn is_recognized_rust_test_source_file(path: &str) -> bool { | ||
| let normalized = path.replace('\\', "/"); | ||
| normalized.starts_with("tests/") | ||
| || normalized.contains("/tests/") | ||
| || normalized.ends_with("_test.rs") | ||
| || normalized.ends_with("_tests.rs") | ||
| } |
There was a problem hiding this comment.
is_recognized_rust_test_source_file is purely lexical. A path such as tests/../src/lib.rs starts with tests/, so it is accepted as a test file. It can also be set as the allowed edit surface, which defeats the test-only, no-production-file guarantee. Paths containing /tests/ or ending in _test.rs under src/ are likewise accepted. ExactTestEditPrecondition::validate() does not re-check the path at all, so a deserialized precondition can target any file.
Reject .. segments and absolute paths. Apply the same recognition check in validate().
| pub fn is_recognized_rust_test_source_file(path: &str) -> bool { | |
| let normalized = path.replace('\\', "/"); | |
| normalized.starts_with("tests/") | |
| || normalized.contains("/tests/") | |
| || normalized.ends_with("_test.rs") | |
| || normalized.ends_with("_tests.rs") | |
| } | |
| pub fn is_recognized_rust_test_source_file(path: &str) -> bool { | |
| let normalized = path.replace('\\', "/"); | |
| // Reject absolute paths (POSIX, UNC) and Windows drive-prefixed paths. | |
| if normalized.starts_with('/') { | |
| return false; | |
| } | |
| let bytes = normalized.as_bytes(); | |
| if bytes.len() >= 2 && bytes[0].is_ascii_alphabetic() && bytes[1] == b':' { | |
| return false; | |
| } | |
| // Reject empty, `.` and `..` segments so the path cannot escape the | |
| // directory it appears to be in. | |
| let segments: Vec<&str> = normalized.split('/').collect(); | |
| if segments | |
| .iter() | |
| .any(|segment| segment.is_empty() || *segment == "." || *segment == "..") | |
| { | |
| return false; | |
| } | |
| let Some((file_name, dirs)) = segments.split_last() else { | |
| return false; | |
| }; | |
| // Production source lives under `src/`; never treat it as a test surface. | |
| if dirs.contains(&"src") { | |
| return false; | |
| } | |
| if !file_name.ends_with(".rs") { | |
| return false; | |
| } | |
| dirs.first() == Some(&"tests") | |
| || dirs.contains(&"tests") | |
| || file_name.ends_with("_test.rs") | |
| || file_name.ends_with("_tests.rs") | |
| } | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
|
Superseded by #12962 (head be5b62e), rebuilt on main 075e4e8. It keeps all of this PR's content and fixes the REPAIR_REQUIRED findings. Registrations moved to Generated by Claude Code |
…1902, carries #12649) (#12962) * feat(domain): add guarded test edit precondition DTOs, ADR 0025 proposed (#1902) Carrier for #12649 on current main. Registrations moved to the per-PR fragments (.ripr/traceability.d, policy/doc-artifacts.d, docs/spec-index.d) instead of appending to shared tails. check-architecture exempts the cfg(test) corpus loader's serde_json like next_action.rs. ADR 0025 is proposed, not accepted (#1902 keeps acceptance a pending design decision). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG * docs(spec): reference SUPPORT_TIERS in RIPR-SPEC-0320 support-tier impact Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG * fix(domain): repair guarded-edit precondition review findings (#1902) Bind the edit instruction id to document version, instruction identities and snapshot identity; require passed parse/format evidence; hold decoded DTOs to the builder's rules through one validate(); admit only contained Rust test sources; make the documented module reachable and record it in public_api.txt; verify digest-only sources against the digest. Corpus ids are literals from an independent reference. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG * test: build the drive-prefixed path negative so it is not a local path literal (#1902) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG * fix(domain): drop the naming-convention test-role rule from the guarded-edit path check (#1902) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG * Add Alternatives Considered section to ADR 0025 (check-doc-roles) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG * Add changelog section marker Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG * Name the mutation tuple type to satisfy clippy Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG * guarded-edit: verify_document_version fails closed on absent versions (#1902) Absent version on the precondition or the current document now refuses with document_version_mismatch; adds a test for both None cases and one spec sentence in RIPR-SPEC-0320. Resolves the Graphite finding and closes the #12986 item 1 note (spec states the (None, _) outcome). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG * guarded-edit: scope RIPR-SPEC-0320 out of the verdict corpora (#1902) verdict-corpus check-all required a spec-scopes fragment for every corpus (perl, python, rust, typescript) because the spec has numbered acceptance examples. It is a domain precondition DTO, not an analyzer verdict. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG * guarded-edit: version the second corpus case and re-derive its identity (#1902) Case 2 now carries document_version 3 (matching case 1); its edit-instruction id is re-derived with the reference transliteration (b0aad19c46de8d3e; source digest unchanged). Spec: a version-less precondition mints but never verifies; the reference is described as a transliteration, not an independent oracle. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG * guarded-edit: assertion range must cover the retained source text (#1902) Builder and validate now refuse (source_text_mismatch) a range that does not cover original_source_text: LSP convention, 0-based, UTF-16 units, end exclusive; multi-line ranges check line count and last-line width. Corrects all 15 corpus ranges and sample_input, re-derives both edit-instruction ids with ref_id.py, adds one-short and one-long negative rows, a covers_text unit test and two decoded-DTO mutations, and a spec clause. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Governing issue or accepted claim: #1902
Acceptance delta (one sentence): ADR 0025 and RIPR-SPEC-0320 accept one bounded test-only assertion replacement class and add versioned
ExactTestEditPrecondition/GuardedEditUnavailabletyping with corpus-backed fail-closed minting, without emitting or applying LSP edits.Summary
crates/ripr/src/domain/guarded_edit.rswith schema versionexact_test_edit_precondition.v1, closed unavailable reasons, builder, and apply-time checks.fixtures/boundary_gap/expected/guarded-edit-precondition/corpus.jsonwith broad-error and boundary-value positive rows plus negative fail-closed rows.Proof
cargo fmtcargo test -p ripr --lib fix_instruction(18 passed)cargo xtask check-spec-format,check-doc-artifacts,check-output-contracts,check-fixture-contracts,check-traceability,check-public-apicargo xtask precommitfailed locally on unrelatedowner_return_pin_*golden drift incargo xtask goldens check(not re-blessed per instruction); hosted CI is the qualification path.Claim boundary
This ratifies and types the safety boundary only. It does not produce
TextEdit, advertise guarded edits in the LSP, modify source, or prove replacements are correct. #1903 / #8183 remain out of scope.