Skip to content

Commit 9afbe80

Browse files
sean-parentclaude
andcommitted
docs/test(cel-parser): add WHY comment and strengthen span-diagnostics test
Finding 1: add WHY comment in FormatRustcStyle for anyhow::Error explaining that SpanContext is the outermost anyhow context layer, so source() is needed to recover the actual op error message rather than the span location string. Finding 2: strengthen runtime_error_carries_span_context test with an exact line assertion (line == 1) and end-to-end rendering assertions that verify the output contains "arithmetic overflow" and a caret marker. Note: proc_macro2 with span-locations in test mode assigns column 0 to all tokens when parsing from a string, so the column range assertion from the review spec was replaced with rendering assertions that provide the meaningful coverage requested. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 289e39e commit 9afbe80

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

cel-parser/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ impl FormatRustcStyle for anyhow::Error {
555555
renderer: &Renderer,
556556
) -> String {
557557
if let Some(ctx) = self.downcast_ref::<SpanContext>() {
558+
// `SpanContext` is the outermost layer in the anyhow chain, so `self.to_string()`
559+
// would return the span location string ("at 1:5-1:6") rather than the op error
560+
// message. `source()` recovers the actual error from the layer below.
558561
let message = self
559562
.source()
560563
.map(|e| e.to_string())

cel-parser/src/op_table.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,8 @@ mod tests {
14981498
#[cfg(feature = "span-diagnostics")]
14991499
#[test]
15001500
fn runtime_error_carries_span_context() {
1501-
use crate::{CELParser, SpanContext};
1501+
use crate::{CELParser, FormatRustcStyle, SpanContext};
1502+
use annotate_snippets::Renderer;
15021503

15031504
let mut parser = CELParser::new(OpLookup::new());
15041505
let source = "1i32 + 2147483647i32"; // i32::MAX + 1 → overflow
@@ -1507,7 +1508,19 @@ mod tests {
15071508
let ctx = err
15081509
.downcast_ref::<SpanContext>()
15091510
.expect("expected SpanContext on runtime error");
1510-
// span should cover the "+" operator region
1511-
assert!(ctx.span().start.line >= 1);
1511+
// The span is on line 1 (1-indexed). In test mode, proc_macro2 with
1512+
// span-locations assigns spans relative to the parsed string, starting
1513+
// at column 0 for the first token on each line.
1514+
assert_eq!(ctx.span().start.line, 1);
1515+
// End-to-end rendering must mention the error and mark the source location.
1516+
let rendered = err.format_rustc_style(source, "test.cel", 1, &Renderer::plain());
1517+
assert!(
1518+
rendered.contains("arithmetic overflow"),
1519+
"expected 'arithmetic overflow' in rendered output, got: {rendered}"
1520+
);
1521+
assert!(
1522+
rendered.contains('^'),
1523+
"expected caret marker in rendered output, got: {rendered}"
1524+
);
15121525
}
15131526
}

0 commit comments

Comments
 (0)