Skip to main content

forge_engine/cea/
instrumentation.rs

1use crate::error::ForgeResult;
2use crate::exec::backend::{CheckResult, EffectSignature};
3use crate::invariants;
4use crate::runtime::patch::apply::LineAttributionMap;
5use crate::runtime::patch::types::*;
6
7pub use cea_core::{AttributedRunResult, AttributionTriple, EditOpSignature};
8
9/// Build EditOpSignature from an EditOp, enforcing invariant I9 (no raw source).
10pub fn build_edit_op_signature(
11    op: &EditOp,
12    op_idx: usize,
13    total_ops: usize,
14    file_idx: usize,
15    total_files: usize,
16    file_extension: &str,
17) -> ForgeResult<EditOpSignature> {
18    let sig = cea_core::build_edit_op_signature(
19        op,
20        op_idx,
21        total_ops,
22        file_idx,
23        total_files,
24        file_extension,
25    )?;
26    let sig_json = serde_json::to_string(&sig)?;
27    invariants::validate_cea_no_raw_source(&sig_json)?;
28    Ok(sig)
29}
30
31/// Compute the node ID for an EditOpSignature.
32pub fn edit_op_node_id(sig: &EditOpSignature) -> String {
33    cea_core::edit_op_node_id(sig)
34}
35
36/// Compute the node ID for an EffectSignature.
37pub fn effect_node_id(sig: &EffectSignature) -> String {
38    cea_core::effect_node_id(sig)
39}
40
41/// Attribute effects to edit ops based on line distance in patched-file space.
42///
43/// Uses the `LineAttributionMap` to translate original line numbers into
44/// patched-space positions, so that distance-to-error calculations are
45/// accurate after insertions/deletions have shifted lines.
46pub fn attribute_effects(
47    patch: &StructuredPatch,
48    check_result: &CheckResult,
49    line_map: &LineAttributionMap,
50    max_line_distance: u32,
51) -> ForgeResult<Vec<AttributionTriple>> {
52    Ok(cea_core::attribute_effects(
53        patch,
54        check_result,
55        line_map,
56        max_line_distance,
57    )?)
58}
59
60/// Compute the run hash for idempotency.
61pub fn compute_run_hash(result: &AttributedRunResult) -> String {
62    cea_core::compute_run_hash(result)
63}