1use std::collections::{HashMap, HashSet};
2use std::io::{IsTerminal, Write};
3
4use path_slash::PathExt as _;
5use petgraph::visit::{EdgeRef, IntoEdgeReferences};
6use serde::Serialize;
7use serde_json::Value;
8
9use crate::graph::types::*;
10
11pub const GRAPH_NODE_FIELDS: &[&str] = &[
13 "unique_id",
14 "label",
15 "node_type",
16 "file_path",
17 "description",
18 "materialization",
19 "tags",
20 "columns",
21 "sql_content",
22 "exposure",
23];
24
25pub const GRAPH_DEFAULT_FIELDS: &[&str] = &["unique_id", "label", "node_type", "file_path"];
27
28pub fn resolve_graph_fields(
31 json_fields: Option<&[String]>,
32 json_full: bool,
33) -> Result<HashSet<String>, String> {
34 if json_full {
35 return Ok(GRAPH_NODE_FIELDS.iter().map(|s| (*s).to_string()).collect());
36 }
37 match json_fields {
38 Some(fields) => {
39 let known: HashSet<&str> = GRAPH_NODE_FIELDS.iter().copied().collect();
40 let mut unknown: Vec<&str> = Vec::new();
41 for f in fields {
42 if !known.contains(f.as_str()) {
43 unknown.push(f);
44 }
45 }
46 if !unknown.is_empty() {
47 return Err(format!(
48 "unknown JSON field(s): {}. Available fields: {}",
49 unknown.join(", "),
50 GRAPH_NODE_FIELDS.join(", "),
51 ));
52 }
53 Ok(fields.iter().cloned().collect())
54 }
55 None => Ok(GRAPH_DEFAULT_FIELDS
56 .iter()
57 .map(|s| (*s).to_string())
58 .collect()),
59 }
60}
61
62#[derive(Serialize)]
63struct JsonGraph {
64 nodes: Vec<Value>,
65 edges: Vec<JsonEdge>,
66}
67
68#[derive(Serialize)]
69struct JsonEdge {
70 source: String,
71 target: String,
72 edge_type: String,
73 #[serde(skip_serializing_if = "Option::is_none")]
74 collapsed_through: Option<usize>,
75}
76
77pub fn build_node_value(
79 node: &NodeData,
80 fields: &HashSet<String>,
81 sql_contents: Option<&HashMap<String, String>>,
82) -> Value {
83 let mut map = serde_json::Map::new();
84 if fields.contains("unique_id") {
85 map.insert("unique_id".into(), Value::String(node.unique_id.clone()));
86 }
87 if fields.contains("label") {
88 map.insert("label".into(), Value::String(node.label.clone()));
89 }
90 if fields.contains("node_type") {
91 map.insert(
92 "node_type".into(),
93 Value::String(node.node_type.label().to_string()),
94 );
95 }
96 if fields.contains("file_path") {
97 map.insert(
98 "file_path".into(),
99 match node.file_path {
100 Some(ref p) => Value::String(p.to_slash_lossy().into_owned()),
101 None => Value::Null,
102 },
103 );
104 }
105 if fields.contains("description") {
106 map.insert(
107 "description".into(),
108 match node.description {
109 Some(ref d) => Value::String(d.clone()),
110 None => Value::Null,
111 },
112 );
113 }
114 if fields.contains("materialization") {
115 map.insert(
116 "materialization".into(),
117 match node.materialization {
118 Some(ref m) => Value::String(m.clone()),
119 None => Value::Null,
120 },
121 );
122 }
123 if fields.contains("tags") {
124 map.insert(
125 "tags".into(),
126 Value::Array(node.tags.iter().map(|t| Value::String(t.clone())).collect()),
127 );
128 }
129 if fields.contains("columns") {
130 map.insert(
131 "columns".into(),
132 Value::Array(
133 node.columns
134 .iter()
135 .map(|c| Value::String(c.clone()))
136 .collect(),
137 ),
138 );
139 }
140 if fields.contains("sql_content") {
141 map.insert(
142 "sql_content".into(),
143 match sql_contents.and_then(|m| m.get(&node.unique_id)) {
144 Some(sql) => Value::String(sql.clone()),
145 None => Value::Null,
146 },
147 );
148 }
149 if fields.contains("exposure") {
150 let opt_str = |v: &Option<String>| -> Value {
151 v.as_ref().map_or(Value::Null, |s| Value::String(s.clone()))
152 };
153 map.insert(
154 "exposure".into(),
155 match node.exposure {
156 Some(ref exp) => {
157 let mut exp_map = serde_json::Map::new();
158 exp_map.insert("label".into(), opt_str(&exp.label));
159 exp_map.insert("type".into(), opt_str(&exp.exposure_type));
160 exp_map.insert("url".into(), opt_str(&exp.url));
161 exp_map.insert("maturity".into(), opt_str(&exp.maturity));
162 exp_map.insert(
163 "owner".into(),
164 match exp.owner {
165 Some(ref o) => {
166 let mut owner_map = serde_json::Map::new();
167 owner_map.insert("name".into(), opt_str(&o.name));
168 owner_map.insert("email".into(), opt_str(&o.email));
169 Value::Object(owner_map)
170 }
171 None => Value::Null,
172 },
173 );
174 Value::Object(exp_map)
175 }
176 None => Value::Null,
177 },
178 );
179 }
180 Value::Object(map)
181}
182
183pub fn render_json(
186 graph: &LineageGraph,
187 sql_contents: Option<&HashMap<String, String>>,
188 fields: &HashSet<String>,
189) {
190 let mut stdout = std::io::stdout().lock();
191 let pretty = stdout.is_terminal();
192 super::handle_stdout_result(render_json_to_writer(
193 graph,
194 sql_contents,
195 fields,
196 &mut stdout,
197 pretty,
198 ));
199}
200
201fn render_json_to_writer<W: Write>(
202 graph: &LineageGraph,
203 sql_contents: Option<&HashMap<String, String>>,
204 fields: &HashSet<String>,
205 w: &mut W,
206 pretty: bool,
207) -> std::io::Result<()> {
208 let mut nodes: Vec<(String, Value)> = graph
209 .node_indices()
210 .map(|idx| {
211 let node = &graph[idx];
212 let sort_key = node.unique_id.clone();
213 let value = build_node_value(node, fields, sql_contents);
214 (sort_key, value)
215 })
216 .collect();
217 nodes.sort_unstable_by(|a, b| a.0.cmp(&b.0));
218 let nodes: Vec<Value> = nodes.into_iter().map(|(_, v)| v).collect();
219
220 let mut edges: Vec<JsonEdge> = graph
221 .edge_references()
222 .map(|edge| {
223 let source = &graph[edge.source()];
224 let target = &graph[edge.target()];
225 JsonEdge {
226 source: source.unique_id.clone(),
227 target: target.unique_id.clone(),
228 edge_type: edge.weight().edge_type.label().to_string(),
229 collapsed_through: edge.weight().collapsed_through,
230 }
231 })
232 .collect();
233 edges.sort_unstable_by(|a, b| {
234 a.source
235 .cmp(&b.source)
236 .then(a.target.cmp(&b.target))
237 .then(a.edge_type.cmp(&b.edge_type))
238 });
239
240 let json_graph = JsonGraph { nodes, edges };
241 if pretty {
242 serde_json::to_writer_pretty(&mut *w, &json_graph).map_err(super::serde_io_error)?;
243 } else {
244 serde_json::to_writer(&mut *w, &json_graph).map_err(super::serde_io_error)?;
245 }
246 writeln!(w)?;
247 Ok(())
248}
249
250#[cfg(test)]
251mod tests {
252 use super::*;
253 use std::path::PathBuf;
254
255 use crate::render::test_helpers::make_node;
256
257 fn all_fields() -> HashSet<String> {
258 GRAPH_NODE_FIELDS.iter().map(|s| (*s).to_string()).collect()
259 }
260
261 fn render_to_string(graph: &LineageGraph) -> String {
262 let mut buf = Vec::new();
263 render_json_to_writer(graph, None, &all_fields(), &mut buf, true).unwrap();
264 String::from_utf8(buf).unwrap()
265 }
266
267 #[test]
268 fn test_empty_graph() {
269 let graph = LineageGraph::new();
270 let output = render_to_string(&graph);
271 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
272 assert_eq!(parsed["nodes"].as_array().unwrap().len(), 0);
273 assert_eq!(parsed["edges"].as_array().unwrap().len(), 0);
274 }
275
276 #[test]
277 fn test_single_node() {
278 let mut graph = LineageGraph::new();
279 graph.add_node(make_node("model.orders", "orders", NodeType::Model));
280 let output = render_to_string(&graph);
281 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
282 let nodes = parsed["nodes"].as_array().unwrap();
283 assert_eq!(nodes.len(), 1);
284 assert_eq!(nodes[0]["unique_id"], "model.orders");
285 assert_eq!(nodes[0]["label"], "orders");
286 assert_eq!(nodes[0]["node_type"], "model");
287 assert!(nodes[0]["file_path"].is_null());
288 assert!(nodes[0]["description"].is_null());
289 }
290
291 #[test]
292 fn test_node_with_file_path_and_description() {
293 let mut graph = LineageGraph::new();
294 graph.add_node(NodeData {
295 unique_id: "model.orders".into(),
296 label: "orders".into(),
297 node_type: NodeType::Model,
298 file_path: Some(PathBuf::from("models/orders.sql")),
299 description: Some("Orders mart model".into()),
300 materialization: None,
301 tags: vec![],
302 columns: vec![],
303 exposure: None,
304 });
305 let output = render_to_string(&graph);
306 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
307 let nodes = parsed["nodes"].as_array().unwrap();
308 assert_eq!(nodes[0]["file_path"], "models/orders.sql");
309 assert_eq!(nodes[0]["description"], "Orders mart model");
310 }
311
312 #[test]
313 fn test_edges() {
314 let mut graph = LineageGraph::new();
315 let a = graph.add_node(make_node(
316 "source.raw.orders",
317 "raw.orders",
318 NodeType::Source,
319 ));
320 let b = graph.add_node(make_node("model.stg_orders", "stg_orders", NodeType::Model));
321 graph.add_edge(a, b, EdgeData::direct(EdgeType::Source));
322
323 let output = render_to_string(&graph);
324 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
325 let edges = parsed["edges"].as_array().unwrap();
326 assert_eq!(edges.len(), 1);
327 assert_eq!(edges[0]["source"], "source.raw.orders");
328 assert_eq!(edges[0]["target"], "model.stg_orders");
329 assert_eq!(edges[0]["edge_type"], "source");
330 }
331
332 #[test]
333 fn test_all_edge_types() {
334 assert_eq!(EdgeType::Ref.label(), "ref");
335 assert_eq!(EdgeType::Source.label(), "source");
336 assert_eq!(EdgeType::Test.label(), "test");
337 assert_eq!(EdgeType::Exposure.label(), "exposure");
338 }
339
340 #[test]
341 fn test_all_node_types() {
342 let mut graph = LineageGraph::new();
343 let types = [
344 ("model.a", NodeType::Model, "model"),
345 ("source.a.b", NodeType::Source, "source"),
346 ("seed.a", NodeType::Seed, "seed"),
347 ("snapshot.a", NodeType::Snapshot, "snapshot"),
348 ("test.a", NodeType::Test, "test"),
349 ("exposure.a", NodeType::Exposure, "exposure"),
350 ("model.unknown", NodeType::Phantom, "phantom"),
351 ];
352 for (id, nt, _) in &types {
353 graph.add_node(make_node(id, "a", *nt));
354 }
355 let output = render_to_string(&graph);
356 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
357 let nodes = parsed["nodes"].as_array().unwrap();
358 let mut actual: Vec<(&str, &str)> = nodes
360 .iter()
361 .map(|n| {
362 (
363 n["unique_id"].as_str().unwrap(),
364 n["node_type"].as_str().unwrap(),
365 )
366 })
367 .collect();
368 actual.sort();
369 let mut expected: Vec<(&str, &str)> = types.iter().map(|(id, _, t)| (*id, *t)).collect();
370 expected.sort();
371 assert_eq!(actual, expected);
372 }
373
374 #[test]
375 fn test_deterministic_node_order() {
376 let mut graph = LineageGraph::new();
377 graph.add_node(make_node("model.z_last", "z_last", NodeType::Model));
379 graph.add_node(make_node("model.a_first", "a_first", NodeType::Model));
380 graph.add_node(make_node("model.m_middle", "m_middle", NodeType::Model));
381 let output = render_to_string(&graph);
382 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
383 let nodes = parsed["nodes"].as_array().unwrap();
384 assert_eq!(nodes[0]["unique_id"], "model.a_first");
385 assert_eq!(nodes[1]["unique_id"], "model.m_middle");
386 assert_eq!(nodes[2]["unique_id"], "model.z_last");
387 }
388
389 #[test]
390 fn test_deterministic_edge_order() {
391 let mut graph = LineageGraph::new();
392 let a = graph.add_node(make_node("model.a", "a", NodeType::Model));
393 let b = graph.add_node(make_node("model.b", "b", NodeType::Model));
394 let c = graph.add_node(make_node("model.c", "c", NodeType::Model));
395 graph.add_edge(c, a, EdgeData::direct(EdgeType::Ref));
397 graph.add_edge(a, b, EdgeData::direct(EdgeType::Ref));
398 graph.add_edge(a, c, EdgeData::direct(EdgeType::Ref));
399 let output = render_to_string(&graph);
400 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
401 let edges = parsed["edges"].as_array().unwrap();
402 assert_eq!(edges[0]["source"], "model.a");
404 assert_eq!(edges[0]["target"], "model.b");
405 assert_eq!(edges[1]["source"], "model.a");
406 assert_eq!(edges[1]["target"], "model.c");
407 assert_eq!(edges[2]["source"], "model.c");
408 assert_eq!(edges[2]["target"], "model.a");
409 }
410
411 #[test]
412 fn test_valid_json() {
413 let mut graph = LineageGraph::new();
414 let a = graph.add_node(make_node("model.a", "a", NodeType::Model));
415 let b = graph.add_node(make_node("model.b", "b", NodeType::Model));
416 graph.add_edge(a, b, EdgeData::direct(EdgeType::Ref));
417 let output = render_to_string(&graph);
418 let _: serde_json::Value = serde_json::from_str(&output).unwrap();
420 }
421
422 #[test]
423 fn test_snapshot_lineage() {
424 let graph = crate::render::test_helpers::make_sample_lineage_graph();
425 let output = render_to_string(&graph);
426 insta::assert_snapshot!(output);
427 }
428
429 #[test]
430 fn test_snapshot_node_metadata() {
431 let mut graph = LineageGraph::new();
432 graph.add_node(NodeData {
433 unique_id: "model.orders".into(),
434 label: "orders".into(),
435 node_type: NodeType::Model,
436 file_path: Some(PathBuf::from("models/orders.sql")),
437 description: Some("Orders mart model".into()),
438 materialization: Some("table".into()),
439 tags: vec!["daily".into(), "core".into()],
440 columns: vec!["order_id".into(), "customer_id".into()],
441 exposure: None,
442 });
443 let output = render_to_string(&graph);
444 insta::assert_snapshot!(output);
445 }
446
447 #[test]
448 fn test_snapshot_json_with_sql() {
449 let mut graph = LineageGraph::new();
450 graph.add_node(NodeData {
451 unique_id: "model.orders".into(),
452 label: "orders".into(),
453 node_type: NodeType::Model,
454 file_path: Some(PathBuf::from("models/orders.sql")),
455 description: None,
456 materialization: Some("table".into()),
457 tags: vec![],
458 columns: vec![],
459 exposure: None,
460 });
461 graph.add_node(make_node(
462 "source.raw.orders",
463 "raw.orders",
464 NodeType::Source,
465 ));
466 let sql_contents = HashMap::from([(
467 "model.orders".to_string(),
468 "SELECT * FROM {{ ref('stg_orders') }}".to_string(),
469 )]);
470 let mut buf = Vec::new();
471 render_json_to_writer(&graph, Some(&sql_contents), &all_fields(), &mut buf, true).unwrap();
472 let output = String::from_utf8(buf).unwrap();
473 insta::assert_snapshot!(output);
474 }
475
476 #[test]
477 fn test_compact_json_single_line() {
478 let mut graph = LineageGraph::new();
479 let a = graph.add_node(make_node("model.a", "a", NodeType::Model));
480 let b = graph.add_node(make_node("model.b", "b", NodeType::Model));
481 graph.add_edge(a, b, EdgeData::direct(EdgeType::Ref));
482 let mut buf = Vec::new();
483 render_json_to_writer(&graph, None, &all_fields(), &mut buf, false).unwrap();
484 let output = String::from_utf8(buf).unwrap();
485 let lines: Vec<&str> = output.trim_end().split('\n').collect();
486 assert_eq!(lines.len(), 1, "compact JSON should be a single line");
487 let _: serde_json::Value = serde_json::from_str(&output).unwrap();
488 }
489
490 #[test]
491 fn test_node_with_materialization_tags_columns() {
492 let mut graph = LineageGraph::new();
493 graph.add_node(NodeData {
494 unique_id: "model.orders".into(),
495 label: "orders".into(),
496 node_type: NodeType::Model,
497 file_path: None,
498 description: None,
499 materialization: Some("table".into()),
500 tags: vec!["daily".into(), "core".into()],
501 columns: vec!["order_id".into(), "customer_id".into()],
502 exposure: None,
503 });
504 let output = render_to_string(&graph);
505 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
506 let node = &parsed["nodes"][0];
507 assert_eq!(node["materialization"], "table");
508 assert_eq!(node["tags"][0], "daily");
509 assert_eq!(node["tags"][1], "core");
510 assert_eq!(node["columns"][0], "order_id");
511 assert_eq!(node["columns"][1], "customer_id");
512 }
513
514 #[test]
515 fn test_transitive_edge_has_collapsed_through() {
516 let mut graph = LineageGraph::new();
517 let a = graph.add_node(make_node("source.raw.a", "a", NodeType::Source));
518 let b = graph.add_node(make_node("model.b", "b", NodeType::Model));
519 graph.add_edge(a, b, EdgeData::transitive(EdgeType::Source, 2));
520
521 let output = render_to_string(&graph);
522 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
523 let edges = parsed["edges"].as_array().unwrap();
524 assert_eq!(edges.len(), 1);
525 assert_eq!(edges[0]["edge_type"], "source");
526 assert_eq!(edges[0]["collapsed_through"], 2);
527 }
528
529 #[test]
530 fn test_direct_edge_omits_collapsed_through() {
531 let mut graph = LineageGraph::new();
532 let a = graph.add_node(make_node("model.a", "a", NodeType::Model));
533 let b = graph.add_node(make_node("model.b", "b", NodeType::Model));
534 graph.add_edge(a, b, EdgeData::direct(EdgeType::Ref));
535
536 let output = render_to_string(&graph);
537 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
538 let edges = parsed["edges"].as_array().unwrap();
539 assert!(edges[0].get("collapsed_through").is_none());
540 }
541
542 #[test]
545 fn test_default_fields_only() {
546 let mut graph = LineageGraph::new();
547 graph.add_node(NodeData {
548 unique_id: "model.orders".into(),
549 label: "orders".into(),
550 node_type: NodeType::Model,
551 file_path: Some(PathBuf::from("models/orders.sql")),
552 description: Some("desc".into()),
553 materialization: Some("table".into()),
554 tags: vec!["daily".into()],
555 columns: vec!["id".into()],
556 exposure: None,
557 });
558 let fields = resolve_graph_fields(None, false).unwrap();
559 let mut buf = Vec::new();
560 render_json_to_writer(&graph, None, &fields, &mut buf, false).unwrap();
561 let output = String::from_utf8(buf).unwrap();
562 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
563 let node = &parsed["nodes"][0];
564 assert_eq!(node["unique_id"], "model.orders");
566 assert_eq!(node["label"], "orders");
567 assert_eq!(node["node_type"], "model");
568 assert_eq!(node["file_path"], "models/orders.sql");
569 assert!(node.get("description").is_none());
571 assert!(node.get("materialization").is_none());
572 assert!(node.get("tags").is_none());
573 assert!(node.get("columns").is_none());
574 assert!(node.get("exposure").is_none());
575 }
576
577 #[test]
578 fn test_custom_fields() {
579 let mut graph = LineageGraph::new();
580 graph.add_node(NodeData {
581 unique_id: "model.orders".into(),
582 label: "orders".into(),
583 node_type: NodeType::Model,
584 file_path: Some(PathBuf::from("models/orders.sql")),
585 description: Some("desc".into()),
586 materialization: Some("table".into()),
587 tags: vec![],
588 columns: vec![],
589 exposure: None,
590 });
591 let fields =
592 resolve_graph_fields(Some(&["unique_id".into(), "description".into()]), false).unwrap();
593 let mut buf = Vec::new();
594 render_json_to_writer(&graph, None, &fields, &mut buf, false).unwrap();
595 let output = String::from_utf8(buf).unwrap();
596 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
597 let node = &parsed["nodes"][0];
598 assert_eq!(node["unique_id"], "model.orders");
599 assert_eq!(node["description"], "desc");
600 assert!(node.get("label").is_none());
602 assert!(node.get("node_type").is_none());
603 assert!(node.get("file_path").is_none());
604 }
605
606 #[test]
607 fn test_json_full_includes_all() {
608 let mut graph = LineageGraph::new();
609 graph.add_node(NodeData {
610 unique_id: "model.orders".into(),
611 label: "orders".into(),
612 node_type: NodeType::Model,
613 file_path: Some(PathBuf::from("models/orders.sql")),
614 description: Some("desc".into()),
615 materialization: Some("table".into()),
616 tags: vec!["daily".into()],
617 columns: vec!["id".into()],
618 exposure: None,
619 });
620 let fields = resolve_graph_fields(None, true).unwrap();
621 let mut buf = Vec::new();
622 render_json_to_writer(&graph, None, &fields, &mut buf, false).unwrap();
623 let output = String::from_utf8(buf).unwrap();
624 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
625 let node = &parsed["nodes"][0];
626 assert_eq!(node["description"], "desc");
627 assert_eq!(node["materialization"], "table");
628 assert_eq!(node["tags"][0], "daily");
629 assert_eq!(node["columns"][0], "id");
630 }
631
632 #[test]
633 fn test_unknown_field_error() {
634 let result = resolve_graph_fields(Some(&["unique_id".into(), "nonexistent".into()]), false);
635 assert!(result.is_err());
636 let err = result.unwrap_err();
637 assert!(err.contains("nonexistent"));
638 assert!(err.contains("Available fields"));
639 }
640
641 #[test]
642 fn test_exposure_fields_in_json() {
643 let mut graph = LineageGraph::new();
644 graph.add_node(NodeData {
645 unique_id: "exposure.dashboard".into(),
646 label: "dashboard".into(),
647 node_type: NodeType::Exposure,
648 file_path: None,
649 description: Some("Main dashboard".into()),
650 materialization: None,
651 tags: vec![],
652 columns: vec![],
653 exposure: Some(ExposureInfo {
654 label: Some("Main Dashboard".into()),
655 exposure_type: Some("dashboard".into()),
656 url: Some("https://bi.example.com".into()),
657 maturity: Some("high".into()),
658 owner: Some(OwnerInfo {
659 name: Some("Data Team".into()),
660 email: Some("data@example.com".into()),
661 }),
662 }),
663 });
664
665 let fields = resolve_graph_fields(None, true).unwrap();
666 let mut buf = Vec::new();
667 render_json_to_writer(&graph, None, &fields, &mut buf, true).unwrap();
668 let output = String::from_utf8(buf).unwrap();
669 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
670 let node = &parsed["nodes"][0];
671
672 let exposure = &node["exposure"];
673 assert_eq!(exposure["label"], "Main Dashboard");
674 assert_eq!(exposure["type"], "dashboard");
675 assert_eq!(exposure["url"], "https://bi.example.com");
676 assert_eq!(exposure["maturity"], "high");
677 assert_eq!(exposure["owner"]["name"], "Data Team");
678 assert_eq!(exposure["owner"]["email"], "data@example.com");
679 }
680
681 #[test]
682 fn test_exposure_null_for_non_exposure_nodes() {
683 let mut graph = LineageGraph::new();
684 graph.add_node(make_node("model.orders", "orders", NodeType::Model));
685
686 let fields = resolve_graph_fields(None, true).unwrap();
687 let mut buf = Vec::new();
688 render_json_to_writer(&graph, None, &fields, &mut buf, true).unwrap();
689 let output = String::from_utf8(buf).unwrap();
690 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
691 let node = &parsed["nodes"][0];
692
693 assert!(node["exposure"].is_null());
694 }
695}