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
201pub fn render_json_to_writer<W: Write>(
203 graph: &LineageGraph,
204 sql_contents: Option<&HashMap<String, String>>,
205 fields: &HashSet<String>,
206 w: &mut W,
207 pretty: bool,
208) -> std::io::Result<()> {
209 let mut nodes: Vec<(String, Value)> = graph
210 .node_indices()
211 .map(|idx| {
212 let node = &graph[idx];
213 let sort_key = node.unique_id.clone();
214 let value = build_node_value(node, fields, sql_contents);
215 (sort_key, value)
216 })
217 .collect();
218 nodes.sort_unstable_by(|a, b| a.0.cmp(&b.0));
219 let nodes: Vec<Value> = nodes.into_iter().map(|(_, v)| v).collect();
220
221 let mut edges: Vec<JsonEdge> = graph
222 .edge_references()
223 .map(|edge| {
224 let source = &graph[edge.source()];
225 let target = &graph[edge.target()];
226 JsonEdge {
227 source: source.unique_id.clone(),
228 target: target.unique_id.clone(),
229 edge_type: edge.weight().edge_type.label().to_string(),
230 collapsed_through: edge.weight().collapsed_through,
231 }
232 })
233 .collect();
234 edges.sort_unstable_by(|a, b| {
235 a.source
236 .cmp(&b.source)
237 .then(a.target.cmp(&b.target))
238 .then(a.edge_type.cmp(&b.edge_type))
239 });
240
241 let json_graph = JsonGraph { nodes, edges };
242 if pretty {
243 serde_json::to_writer_pretty(&mut *w, &json_graph).map_err(super::serde_io_error)?;
244 } else {
245 serde_json::to_writer(&mut *w, &json_graph).map_err(super::serde_io_error)?;
246 }
247 writeln!(w)?;
248 Ok(())
249}
250
251#[cfg(test)]
252mod tests {
253 use super::*;
254 use std::path::PathBuf;
255
256 use crate::render::test_helpers::make_node;
257
258 fn all_fields() -> HashSet<String> {
259 GRAPH_NODE_FIELDS.iter().map(|s| (*s).to_string()).collect()
260 }
261
262 fn render_to_string(graph: &LineageGraph) -> String {
263 let mut buf = Vec::new();
264 render_json_to_writer(graph, None, &all_fields(), &mut buf, true).unwrap();
265 String::from_utf8(buf).unwrap()
266 }
267
268 #[test]
269 fn test_empty_graph() {
270 let graph = LineageGraph::new();
271 let output = render_to_string(&graph);
272 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
273 assert_eq!(parsed["nodes"].as_array().unwrap().len(), 0);
274 assert_eq!(parsed["edges"].as_array().unwrap().len(), 0);
275 }
276
277 #[test]
278 fn test_single_node() {
279 let mut graph = LineageGraph::new();
280 graph.add_node(make_node("model.orders", "orders", NodeType::Model));
281 let output = render_to_string(&graph);
282 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
283 let nodes = parsed["nodes"].as_array().unwrap();
284 assert_eq!(nodes.len(), 1);
285 assert_eq!(nodes[0]["unique_id"], "model.orders");
286 assert_eq!(nodes[0]["label"], "orders");
287 assert_eq!(nodes[0]["node_type"], "model");
288 assert!(nodes[0]["file_path"].is_null());
289 assert!(nodes[0]["description"].is_null());
290 }
291
292 #[test]
293 fn test_node_with_file_path_and_description() {
294 let mut graph = LineageGraph::new();
295 graph.add_node(NodeData {
296 unique_id: "model.orders".into(),
297 label: "orders".into(),
298 node_type: NodeType::Model,
299 file_path: Some(PathBuf::from("models/orders.sql")),
300 description: Some("Orders mart model".into()),
301 materialization: None,
302 tags: vec![],
303 columns: vec![],
304 exposure: None,
305 });
306 let output = render_to_string(&graph);
307 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
308 let nodes = parsed["nodes"].as_array().unwrap();
309 assert_eq!(nodes[0]["file_path"], "models/orders.sql");
310 assert_eq!(nodes[0]["description"], "Orders mart model");
311 }
312
313 #[test]
314 fn test_edges() {
315 let mut graph = LineageGraph::new();
316 let a = graph.add_node(make_node(
317 "source.raw.orders",
318 "raw.orders",
319 NodeType::Source,
320 ));
321 let b = graph.add_node(make_node("model.stg_orders", "stg_orders", NodeType::Model));
322 graph.add_edge(a, b, EdgeData::direct(EdgeType::Source));
323
324 let output = render_to_string(&graph);
325 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
326 let edges = parsed["edges"].as_array().unwrap();
327 assert_eq!(edges.len(), 1);
328 assert_eq!(edges[0]["source"], "source.raw.orders");
329 assert_eq!(edges[0]["target"], "model.stg_orders");
330 assert_eq!(edges[0]["edge_type"], "source");
331 }
332
333 #[test]
334 fn test_all_edge_types() {
335 assert_eq!(EdgeType::Ref.label(), "ref");
336 assert_eq!(EdgeType::Source.label(), "source");
337 assert_eq!(EdgeType::Test.label(), "test");
338 assert_eq!(EdgeType::Exposure.label(), "exposure");
339 }
340
341 #[test]
342 fn test_all_node_types() {
343 let mut graph = LineageGraph::new();
344 let types = [
345 ("model.a", NodeType::Model, "model"),
346 ("source.a.b", NodeType::Source, "source"),
347 ("seed.a", NodeType::Seed, "seed"),
348 ("snapshot.a", NodeType::Snapshot, "snapshot"),
349 ("test.a", NodeType::Test, "test"),
350 ("exposure.a", NodeType::Exposure, "exposure"),
351 ("model.unknown", NodeType::Phantom, "phantom"),
352 ];
353 for (id, nt, _) in &types {
354 graph.add_node(make_node(id, "a", *nt));
355 }
356 let output = render_to_string(&graph);
357 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
358 let nodes = parsed["nodes"].as_array().unwrap();
359 let mut actual: Vec<(&str, &str)> = nodes
361 .iter()
362 .map(|n| {
363 (
364 n["unique_id"].as_str().unwrap(),
365 n["node_type"].as_str().unwrap(),
366 )
367 })
368 .collect();
369 actual.sort();
370 let mut expected: Vec<(&str, &str)> = types.iter().map(|(id, _, t)| (*id, *t)).collect();
371 expected.sort();
372 assert_eq!(actual, expected);
373 }
374
375 #[test]
376 fn test_deterministic_node_order() {
377 let mut graph = LineageGraph::new();
378 graph.add_node(make_node("model.z_last", "z_last", NodeType::Model));
380 graph.add_node(make_node("model.a_first", "a_first", NodeType::Model));
381 graph.add_node(make_node("model.m_middle", "m_middle", NodeType::Model));
382 let output = render_to_string(&graph);
383 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
384 let nodes = parsed["nodes"].as_array().unwrap();
385 assert_eq!(nodes[0]["unique_id"], "model.a_first");
386 assert_eq!(nodes[1]["unique_id"], "model.m_middle");
387 assert_eq!(nodes[2]["unique_id"], "model.z_last");
388 }
389
390 #[test]
391 fn test_deterministic_edge_order() {
392 let mut graph = LineageGraph::new();
393 let a = graph.add_node(make_node("model.a", "a", NodeType::Model));
394 let b = graph.add_node(make_node("model.b", "b", NodeType::Model));
395 let c = graph.add_node(make_node("model.c", "c", NodeType::Model));
396 graph.add_edge(c, a, EdgeData::direct(EdgeType::Ref));
398 graph.add_edge(a, b, EdgeData::direct(EdgeType::Ref));
399 graph.add_edge(a, c, EdgeData::direct(EdgeType::Ref));
400 let output = render_to_string(&graph);
401 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
402 let edges = parsed["edges"].as_array().unwrap();
403 assert_eq!(edges[0]["source"], "model.a");
405 assert_eq!(edges[0]["target"], "model.b");
406 assert_eq!(edges[1]["source"], "model.a");
407 assert_eq!(edges[1]["target"], "model.c");
408 assert_eq!(edges[2]["source"], "model.c");
409 assert_eq!(edges[2]["target"], "model.a");
410 }
411
412 #[test]
413 fn test_valid_json() {
414 let mut graph = LineageGraph::new();
415 let a = graph.add_node(make_node("model.a", "a", NodeType::Model));
416 let b = graph.add_node(make_node("model.b", "b", NodeType::Model));
417 graph.add_edge(a, b, EdgeData::direct(EdgeType::Ref));
418 let output = render_to_string(&graph);
419 let _: serde_json::Value = serde_json::from_str(&output).unwrap();
421 }
422
423 #[test]
424 fn test_snapshot_lineage() {
425 let graph = crate::render::test_helpers::make_sample_lineage_graph();
426 let output = render_to_string(&graph);
427 insta::assert_snapshot!(output);
428 }
429
430 #[test]
431 fn test_snapshot_node_metadata() {
432 let mut graph = LineageGraph::new();
433 graph.add_node(NodeData {
434 unique_id: "model.orders".into(),
435 label: "orders".into(),
436 node_type: NodeType::Model,
437 file_path: Some(PathBuf::from("models/orders.sql")),
438 description: Some("Orders mart model".into()),
439 materialization: Some("table".into()),
440 tags: vec!["daily".into(), "core".into()],
441 columns: vec!["order_id".into(), "customer_id".into()],
442 exposure: None,
443 });
444 let output = render_to_string(&graph);
445 insta::assert_snapshot!(output);
446 }
447
448 #[test]
449 fn test_snapshot_json_with_sql() {
450 let mut graph = LineageGraph::new();
451 graph.add_node(NodeData {
452 unique_id: "model.orders".into(),
453 label: "orders".into(),
454 node_type: NodeType::Model,
455 file_path: Some(PathBuf::from("models/orders.sql")),
456 description: None,
457 materialization: Some("table".into()),
458 tags: vec![],
459 columns: vec![],
460 exposure: None,
461 });
462 graph.add_node(make_node(
463 "source.raw.orders",
464 "raw.orders",
465 NodeType::Source,
466 ));
467 let sql_contents = HashMap::from([(
468 "model.orders".to_string(),
469 "SELECT * FROM {{ ref('stg_orders') }}".to_string(),
470 )]);
471 let mut buf = Vec::new();
472 render_json_to_writer(&graph, Some(&sql_contents), &all_fields(), &mut buf, true).unwrap();
473 let output = String::from_utf8(buf).unwrap();
474 insta::assert_snapshot!(output);
475 }
476
477 #[test]
478 fn test_compact_json_single_line() {
479 let mut graph = LineageGraph::new();
480 let a = graph.add_node(make_node("model.a", "a", NodeType::Model));
481 let b = graph.add_node(make_node("model.b", "b", NodeType::Model));
482 graph.add_edge(a, b, EdgeData::direct(EdgeType::Ref));
483 let mut buf = Vec::new();
484 render_json_to_writer(&graph, None, &all_fields(), &mut buf, false).unwrap();
485 let output = String::from_utf8(buf).unwrap();
486 let lines: Vec<&str> = output.trim_end().split('\n').collect();
487 assert_eq!(lines.len(), 1, "compact JSON should be a single line");
488 let _: serde_json::Value = serde_json::from_str(&output).unwrap();
489 }
490
491 #[test]
492 fn test_node_with_materialization_tags_columns() {
493 let mut graph = LineageGraph::new();
494 graph.add_node(NodeData {
495 unique_id: "model.orders".into(),
496 label: "orders".into(),
497 node_type: NodeType::Model,
498 file_path: None,
499 description: None,
500 materialization: Some("table".into()),
501 tags: vec!["daily".into(), "core".into()],
502 columns: vec!["order_id".into(), "customer_id".into()],
503 exposure: None,
504 });
505 let output = render_to_string(&graph);
506 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
507 let node = &parsed["nodes"][0];
508 assert_eq!(node["materialization"], "table");
509 assert_eq!(node["tags"][0], "daily");
510 assert_eq!(node["tags"][1], "core");
511 assert_eq!(node["columns"][0], "order_id");
512 assert_eq!(node["columns"][1], "customer_id");
513 }
514
515 #[test]
516 fn test_transitive_edge_has_collapsed_through() {
517 let mut graph = LineageGraph::new();
518 let a = graph.add_node(make_node("source.raw.a", "a", NodeType::Source));
519 let b = graph.add_node(make_node("model.b", "b", NodeType::Model));
520 graph.add_edge(a, b, EdgeData::transitive(EdgeType::Source, 2));
521
522 let output = render_to_string(&graph);
523 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
524 let edges = parsed["edges"].as_array().unwrap();
525 assert_eq!(edges.len(), 1);
526 assert_eq!(edges[0]["edge_type"], "source");
527 assert_eq!(edges[0]["collapsed_through"], 2);
528 }
529
530 #[test]
531 fn test_direct_edge_omits_collapsed_through() {
532 let mut graph = LineageGraph::new();
533 let a = graph.add_node(make_node("model.a", "a", NodeType::Model));
534 let b = graph.add_node(make_node("model.b", "b", NodeType::Model));
535 graph.add_edge(a, b, EdgeData::direct(EdgeType::Ref));
536
537 let output = render_to_string(&graph);
538 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
539 let edges = parsed["edges"].as_array().unwrap();
540 assert!(edges[0].get("collapsed_through").is_none());
541 }
542
543 #[test]
546 fn test_default_fields_only() {
547 let mut graph = LineageGraph::new();
548 graph.add_node(NodeData {
549 unique_id: "model.orders".into(),
550 label: "orders".into(),
551 node_type: NodeType::Model,
552 file_path: Some(PathBuf::from("models/orders.sql")),
553 description: Some("desc".into()),
554 materialization: Some("table".into()),
555 tags: vec!["daily".into()],
556 columns: vec!["id".into()],
557 exposure: None,
558 });
559 let fields = resolve_graph_fields(None, false).unwrap();
560 let mut buf = Vec::new();
561 render_json_to_writer(&graph, None, &fields, &mut buf, false).unwrap();
562 let output = String::from_utf8(buf).unwrap();
563 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
564 let node = &parsed["nodes"][0];
565 assert_eq!(node["unique_id"], "model.orders");
567 assert_eq!(node["label"], "orders");
568 assert_eq!(node["node_type"], "model");
569 assert_eq!(node["file_path"], "models/orders.sql");
570 assert!(node.get("description").is_none());
572 assert!(node.get("materialization").is_none());
573 assert!(node.get("tags").is_none());
574 assert!(node.get("columns").is_none());
575 assert!(node.get("exposure").is_none());
576 }
577
578 #[test]
579 fn test_custom_fields() {
580 let mut graph = LineageGraph::new();
581 graph.add_node(NodeData {
582 unique_id: "model.orders".into(),
583 label: "orders".into(),
584 node_type: NodeType::Model,
585 file_path: Some(PathBuf::from("models/orders.sql")),
586 description: Some("desc".into()),
587 materialization: Some("table".into()),
588 tags: vec![],
589 columns: vec![],
590 exposure: None,
591 });
592 let fields =
593 resolve_graph_fields(Some(&["unique_id".into(), "description".into()]), false).unwrap();
594 let mut buf = Vec::new();
595 render_json_to_writer(&graph, None, &fields, &mut buf, false).unwrap();
596 let output = String::from_utf8(buf).unwrap();
597 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
598 let node = &parsed["nodes"][0];
599 assert_eq!(node["unique_id"], "model.orders");
600 assert_eq!(node["description"], "desc");
601 assert!(node.get("label").is_none());
603 assert!(node.get("node_type").is_none());
604 assert!(node.get("file_path").is_none());
605 }
606
607 #[test]
608 fn test_json_full_includes_all() {
609 let mut graph = LineageGraph::new();
610 graph.add_node(NodeData {
611 unique_id: "model.orders".into(),
612 label: "orders".into(),
613 node_type: NodeType::Model,
614 file_path: Some(PathBuf::from("models/orders.sql")),
615 description: Some("desc".into()),
616 materialization: Some("table".into()),
617 tags: vec!["daily".into()],
618 columns: vec!["id".into()],
619 exposure: None,
620 });
621 let fields = resolve_graph_fields(None, true).unwrap();
622 let mut buf = Vec::new();
623 render_json_to_writer(&graph, None, &fields, &mut buf, false).unwrap();
624 let output = String::from_utf8(buf).unwrap();
625 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
626 let node = &parsed["nodes"][0];
627 assert_eq!(node["description"], "desc");
628 assert_eq!(node["materialization"], "table");
629 assert_eq!(node["tags"][0], "daily");
630 assert_eq!(node["columns"][0], "id");
631 }
632
633 #[test]
634 fn test_unknown_field_error() {
635 let result = resolve_graph_fields(Some(&["unique_id".into(), "nonexistent".into()]), false);
636 assert!(result.is_err());
637 let err = result.unwrap_err();
638 assert!(err.contains("nonexistent"));
639 assert!(err.contains("Available fields"));
640 }
641
642 #[test]
643 fn test_exposure_fields_in_json() {
644 let mut graph = LineageGraph::new();
645 graph.add_node(NodeData {
646 unique_id: "exposure.dashboard".into(),
647 label: "dashboard".into(),
648 node_type: NodeType::Exposure,
649 file_path: None,
650 description: Some("Main dashboard".into()),
651 materialization: None,
652 tags: vec![],
653 columns: vec![],
654 exposure: Some(ExposureInfo {
655 label: Some("Main Dashboard".into()),
656 exposure_type: Some("dashboard".into()),
657 url: Some("https://bi.example.com".into()),
658 maturity: Some("high".into()),
659 owner: Some(OwnerInfo {
660 name: Some("Data Team".into()),
661 email: Some("data@example.com".into()),
662 }),
663 }),
664 });
665
666 let fields = resolve_graph_fields(None, true).unwrap();
667 let mut buf = Vec::new();
668 render_json_to_writer(&graph, None, &fields, &mut buf, true).unwrap();
669 let output = String::from_utf8(buf).unwrap();
670 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
671 let node = &parsed["nodes"][0];
672
673 let exposure = &node["exposure"];
674 assert_eq!(exposure["label"], "Main Dashboard");
675 assert_eq!(exposure["type"], "dashboard");
676 assert_eq!(exposure["url"], "https://bi.example.com");
677 assert_eq!(exposure["maturity"], "high");
678 assert_eq!(exposure["owner"]["name"], "Data Team");
679 assert_eq!(exposure["owner"]["email"], "data@example.com");
680 }
681
682 #[test]
683 fn test_exposure_null_for_non_exposure_nodes() {
684 let mut graph = LineageGraph::new();
685 graph.add_node(make_node("model.orders", "orders", NodeType::Model));
686
687 let fields = resolve_graph_fields(None, true).unwrap();
688 let mut buf = Vec::new();
689 render_json_to_writer(&graph, None, &fields, &mut buf, true).unwrap();
690 let output = String::from_utf8(buf).unwrap();
691 let parsed: serde_json::Value = serde_json::from_str(&output).unwrap();
692 let node = &parsed["nodes"][0];
693
694 assert!(node["exposure"].is_null());
695 }
696}