MCPcopy Create free account
hub / github.com/concensure/Semantic / validate_patch

Method validate_patch

patch_engine/src/lib.rs:54–72  ·  view source on GitHub ↗
(file_path: &str, patch: &CodePatch, existing_code: &str)

Source from the content-addressed store, hash-verified

52 }
53
54 pub fn validate_patch(file_path: &str, patch: &CodePatch, existing_code: &str) -> Result<()> {
55 let updated = match &patch.representation {
56 PatchRepresentation::UnifiedDiff(diff) => apply_unified_diff(existing_code, diff)?,
57 PatchRepresentation::ASTTransform(ast_edit) => {
58 bail!(
59 "cannot validate abstract AST transform for '{}' without a concrete rewrite",
60 ast_edit.target_symbol
61 );
62 }
63 };
64
65 if updated == existing_code {
66 bail!("patch does not modify file content");
67 }
68
69 let mut parser = parser::CodeParser::new();
70 let _ = parser.parse(file_path, &updated)?;
71 Ok(())
72 }
73
74 pub fn apply_patch(existing_code: &str, patch: &CodePatch) -> Result<String> {
75 match &patch.representation {

Callers

nothing calls this directly

Calls 2

apply_unified_diffFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected