Skip to content

Commit 2be5150

Browse files
hyperpolymathclaude
andcommitted
fix: patch seamctl build errors (graph, report, validate)
Fix unescaped quotes in report.rs, switch DiGraphMap to DiGraph for non-Copy String nodes, use Draft::Draft7 instead of Draft202012. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 72dddac commit 2be5150

3 files changed

Lines changed: 22 additions & 26 deletions

File tree

tools/seamctl/src/graph.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use anyhow::{anyhow, Context, Result};
22
use camino::Utf8PathBuf;
3-
use petgraph::graphmap::DiGraphMap;
3+
use petgraph::graph::DiGraph;
44
use serde_json::json;
5+
use std::collections::HashMap;
56
use walkdir::WalkDir;
67

78
use crate::model::SeamRecord;
@@ -39,46 +40,41 @@ pub fn run(root: Option<&str>, format: &str, out: Option<&str>) -> Result<()> {
3940
return Err(anyhow!("no seam records found"));
4041
}
4142

42-
let mut g: DiGraphMap<String, String> = DiGraphMap::new(); // edge weight = seam id
43+
let mut g = DiGraph::<String, String>::new();
44+
let mut node_map: HashMap<String, petgraph::graph::NodeIndex> = HashMap::new();
4345
let mut seams = vec![];
4446

4547
for f in files {
4648
let raw = std::fs::read_to_string(&f).with_context(|| format!("read {f}"))?;
4749
let rec: SeamRecord = serde_json::from_str(&raw).with_context(|| format!("decode {f}"))?;
48-
g.add_node(rec.side_a.clone());
49-
g.add_node(rec.side_b.clone());
50-
g.add_edge(rec.side_a.clone(), rec.side_b.clone(), rec.id.clone());
51-
seams.push(rec.id);
52-
}
5350

54-
// Cycle detection (simple): if any node reachable to itself via DFS in a small graph, flag.
55-
// In v0: warnings only.
56-
let mut warnings = vec![];
57-
for n in g.nodes() {
58-
// naive: if there's a path back, petgraph doesn't give easy on graphmap; skip deep analysis v0.
59-
let _ = n;
51+
let a_idx = *node_map.entry(rec.side_a.clone()).or_insert_with(|| g.add_node(rec.side_a.clone()));
52+
let b_idx = *node_map.entry(rec.side_b.clone()).or_insert_with(|| g.add_node(rec.side_b.clone()));
53+
g.add_edge(a_idx, b_idx, rec.id.clone());
54+
seams.push(rec.id);
6055
}
6156

62-
if !warnings.is_empty() {
63-
eprintln!("Warnings:");
64-
for w in warnings {
65-
eprintln!("- {w}");
66-
}
67-
}
57+
let components: Vec<&String> = g.node_weights().collect();
58+
let edges: Vec<serde_json::Value> = g.edge_indices().map(|ei| {
59+
let (a, b) = g.edge_endpoints(ei).unwrap();
60+
let id = &g[ei];
61+
json!({"from": g[a], "to": g[b], "seam": id})
62+
}).collect();
6863

6964
let payload = json!({
70-
"components": g.nodes().collect::<Vec<_>>(),
71-
"edges": g.all_edges().map(|(a,b,id)| json!({"from":a,"to":b,"seam":id})).collect::<Vec<_>>(),
65+
"components": components,
66+
"edges": edges,
7267
"seams": seams,
7368
});
7469

7570
let rendered = if format == "json" {
7671
serde_json::to_string_pretty(&payload)?
7772
} else if format == "dot" {
78-
// Minimal DOT emission
7973
let mut s = String::from("digraph seams {\n");
80-
for (a, b, id) in g.all_edges() {
81-
s.push_str(&format!(" \"{}\" -> \"{}\" [label=\"{}\"];\n", a, b, id));
74+
for ei in g.edge_indices() {
75+
let (a, b) = g.edge_endpoints(ei).unwrap();
76+
let id = &g[ei];
77+
s.push_str(&format!(" \"{}\" -> \"{}\" [label=\"{}\"];\n", g[a], g[b], id));
8278
}
8379
s.push_str("}\n");
8480
s

tools/seamctl/src/report.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn run(root: Option<&str>, out: Option<&str>) -> Result<()> {
7575
let mut doc = String::new();
7676
doc.push_str("= Seam Report\n:toc:\n\n");
7777
doc.push_str("== Inventory\n\n");
78-
doc.push_str("[cols="1,3,1,2,2,2",options="header"]\n|===\n");
78+
doc.push_str("[cols=\"1,3,1,2,2,2\",options=\"header\"]\n|===\n");
7979
doc.push_str("|ID |Title |Status |Side A |Side B |Risk flags\n");
8080
for (id, title, status, a, b, flags) in rows {
8181
doc.push_str(&format!("|{id} |{title} |{status} |{a} |{b} |{flags}\n"));

tools/seamctl/src/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn load_json(path: &Utf8PathBuf) -> Result<Value> {
4646
fn compile_schema(schema_path: &Utf8PathBuf) -> Result<JSONSchema> {
4747
let schema_json = load_json(schema_path)?;
4848
JSONSchema::options()
49-
.with_draft(Draft::Draft202012)
49+
.with_draft(Draft::Draft7)
5050
.compile(&schema_json)
5151
.map_err(|e| anyhow!("schema compile failed: {e}"))
5252
}

0 commit comments

Comments
 (0)