Skip to content

feat(domain): ratify guarded test edit precondition DTOs (Closes #1902) - #12649

Closed
EffortlessSteven wants to merge 2 commits into
mainfrom
cursor/guarded-edit-precondition-1902
Closed

EffortlessSteven wants to merge 2 commits into
mainfrom
cursor/guarded-edit-precondition-1902

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

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 / GuardedEditUnavailable typing with corpus-backed fail-closed minting, without emitting or applying LSP edits.

Summary

  • Record the design acceptance in ADR 0025 and amend RIPR-SPEC-0069’s read-only default to reference the guarded exception (RIPR-SPEC-0320 owns the contract).
  • Add crates/ripr/src/domain/guarded_edit.rs with schema version exact_test_edit_precondition.v1, closed unavailable reasons, builder, and apply-time checks.
  • Add fixtures/boundary_gap/expected/guarded-edit-precondition/corpus.json with broad-error and boundary-value positive rows plus negative fail-closed rows.

Proof

  • cargo fmt
  • cargo 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-api
  • cargo xtask precommit failed locally on unrelated owner_return_pin_* golden drift in cargo 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.

Open in Web Open in Cursor 

Devin Review

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>
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 75 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: dc86579e-2441-409c-99b3-ae708ead2d09
Commits

Reviewing files that changed from the base of the PR and between 8cc4285 and 9414057.

Files selected for processing: 14
  • .ripr/traceability.toml
  • changelog.d/guarded-edit-precondition-1902.md
  • crates/ripr/src/domain/guarded_edit.rs
  • crates/ripr/src/domain/identity/catalog.rs
  • crates/ripr/src/domain/mod.rs
  • docs/adr/0025-guarded-test-only-edit-boundary.md
  • docs/adr/README.md
  • docs/identity/REGISTRY.md
  • docs/identity/registry.v1.json
  • docs/specs/README.md
  • docs/specs/RIPR-SPEC-0069-lsp-agent-feedback-use-case.md
  • docs/specs/RIPR-SPEC-0320-guarded-test-edit-precondition.md
  • fixtures/boundary_gap/expected/guarded-edit-precondition/corpus.json
  • policy/doc-artifacts.toml
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

merge-ready was requested, but this PR conflicts with main (head 9414057c), so GitHub creates no test-merge ref and no qualification run can start. Merge main into the branch and resolve the conflicts, then remove and re-apply merge-ready.

@EffortlessSteven EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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's DiagnosticResultId row (domain::analysis_execution_identity::DiagnosticResultId) and this PR's EditInstructionId row (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.json merges cleanly, and check-identity-registry passes 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

Comment on lines +489 to +500
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,
)),
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)),
}
Suggested change
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

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +502 to +518
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(())
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +533 to +560
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}"))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +301 to +307
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")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Suggested change
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

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Copy link
Copy Markdown
Member Author

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 .ripr/traceability.d, policy/doc-artifacts.d and docs/spec-index.d. policy/architecture.txt now exempts the serde_json use in the domain test. ADR 0025 is set to proposed, since #1902 records acceptance as pending.


Generated by Claude Code

EffortlessSteven added a commit that referenced this pull request Nov 4, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants