Skip to content

Commit 4b36b65

Browse files
greynewellclaude
andcommitted
test: expand coverage across api, blastradius, cache, mcp, render, and shards
- api: add GraphFromShardIR tests (Nodes, Rels, RepoID, NodeByID, NodesByLabel, empty) - blastradius: new zip_test.go covering isGitRepo, isWorktreeClean, walkZip (hidden files, skip dirs, createZip round-trip) - cache: add PutJSON/GetJSON round-trip, miss, and overwrite tests - mcp: add boolArg and intArg tests - render/funcs: add 23 tests for totalTime, formatDuration, seq, dict, reverseStrings, minInt/maxInt, length, entity accessors (fieldAccess, sectionAccess, getStringSlice, hasField, getInt, getFloat), jsonMarshal/toJSON, defaultVal/ternary/hasKey, parseQuantity, parseUnit, parseIngredient*, fractionDisplay, scaleQty - shards: new graph_test.go (25 tests for Cache.Build, SourceFiles, FuncName, TransitiveDependents, computeStats, isShardPath, firstString, intProp) - shards: extend render_test.go (CommentPrefix, ShardFilename, Header, sortedUnique, sortedBoolKeys, formatLoc, renderDepsSection, renderImpactSection, RenderGraph, WriteShard, updateGitignore) Coverage deltas: render 11%→45%, blastradius 32%→60%, cache 61%→78% Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9cdfd11 commit 4b36b65

7 files changed

Lines changed: 1455 additions & 0 deletions

File tree

internal/api/types_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,108 @@ func TestError_Error_WithoutCode(t *testing.T) {
232232
}
233233
}
234234

235+
// ── GraphFromShardIR ──────────────────────────────────────────────────────────
236+
237+
func TestGraphFromShardIR_NodesAndRels(t *testing.T) {
238+
ir := &ShardIR{
239+
Repo: "myorg/myrepo",
240+
Graph: ShardGraph{
241+
Nodes: []Node{
242+
{ID: "n1", Labels: []string{"File"}, Properties: map[string]any{"filePath": "src/a.go"}},
243+
{ID: "n2", Labels: []string{"Function"}, Properties: map[string]any{"name": "doThing"}},
244+
},
245+
Relationships: []Relationship{
246+
{ID: "r1", Type: "defines_function", StartNode: "n1", EndNode: "n2"},
247+
},
248+
},
249+
}
250+
g := GraphFromShardIR(ir)
251+
252+
if len(g.Nodes) != 2 {
253+
t.Errorf("nodes: got %d, want 2", len(g.Nodes))
254+
}
255+
if len(g.Relationships) != 1 {
256+
t.Errorf("relationships: got %d, want 1", len(g.Relationships))
257+
}
258+
if g.Nodes[0].ID != "n1" {
259+
t.Errorf("first node ID: got %q", g.Nodes[0].ID)
260+
}
261+
}
262+
263+
func TestGraphFromShardIR_RepoID(t *testing.T) {
264+
ir := &ShardIR{Repo: "acme/backend"}
265+
g := GraphFromShardIR(ir)
266+
if got := g.RepoID(); got != "acme/backend" {
267+
t.Errorf("RepoID: got %q, want 'acme/backend'", got)
268+
}
269+
}
270+
271+
func TestGraphFromShardIR_RelsViaRels(t *testing.T) {
272+
// Rels() should return the Relationships slice (not Edges)
273+
ir := &ShardIR{
274+
Graph: ShardGraph{
275+
Relationships: []Relationship{
276+
{ID: "r1", Type: "imports"},
277+
{ID: "r2", Type: "calls"},
278+
},
279+
},
280+
}
281+
g := GraphFromShardIR(ir)
282+
rels := g.Rels()
283+
if len(rels) != 2 {
284+
t.Errorf("Rels(): got %d, want 2", len(rels))
285+
}
286+
}
287+
288+
func TestGraphFromShardIR_Empty(t *testing.T) {
289+
ir := &ShardIR{}
290+
g := GraphFromShardIR(ir)
291+
if g == nil {
292+
t.Fatal("GraphFromShardIR returned nil")
293+
}
294+
if len(g.Nodes) != 0 {
295+
t.Errorf("empty IR: expected 0 nodes, got %d", len(g.Nodes))
296+
}
297+
if g.RepoID() != "" {
298+
t.Errorf("empty IR: expected empty repoId, got %q", g.RepoID())
299+
}
300+
}
301+
302+
func TestGraphFromShardIR_NodeByID(t *testing.T) {
303+
ir := &ShardIR{
304+
Graph: ShardGraph{
305+
Nodes: []Node{
306+
{ID: "fn1", Labels: []string{"Function"}, Properties: map[string]any{"name": "myFunc"}},
307+
},
308+
},
309+
}
310+
g := GraphFromShardIR(ir)
311+
n, ok := g.NodeByID("fn1")
312+
if !ok {
313+
t.Fatal("NodeByID('fn1') returned false")
314+
}
315+
if n.Prop("name") != "myFunc" {
316+
t.Errorf("name prop: got %q", n.Prop("name"))
317+
}
318+
}
319+
320+
func TestGraphFromShardIR_NodesByLabel(t *testing.T) {
321+
ir := &ShardIR{
322+
Graph: ShardGraph{
323+
Nodes: []Node{
324+
{ID: "f1", Labels: []string{"File"}},
325+
{ID: "fn1", Labels: []string{"Function"}},
326+
{ID: "f2", Labels: []string{"File"}},
327+
},
328+
},
329+
}
330+
g := GraphFromShardIR(ir)
331+
files := g.NodesByLabel("File")
332+
if len(files) != 2 {
333+
t.Errorf("NodesByLabel('File'): got %d, want 2", len(files))
334+
}
335+
}
336+
235337
func containsStr(s, sub string) bool {
236338
return len(s) >= len(sub) && (s == sub ||
237339
func() bool {

0 commit comments

Comments
 (0)