Skip to content

Commit 9f92fa2

Browse files
hkaltaiclaude
andcommitted
fix: include_graph leaves out the tests of upstream models
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8521242 commit 9f92fa2

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎packages/opencode/src/altimate/native/dbt/graph.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ export function lineageGraph(manifest: any, id: string): LineageGraph {
8080
const isTest = (one: string) => ["test", "unit_test"].includes(lookup(manifest, one)?.resource_type ?? one.split(".")[0])
8181
const keep = new Set([id])
8282
// Breadth first, so a cut keeps the nearest nodes.
83-
const walk = (links: Record<string, string[]>, limit: number) => {
83+
const walk = (links: Record<string, string[]>, limit: number, seen = new Set([id])) => {
8484
const queue = [id]
85-
const seen = new Set([id])
8685
let count = 0
8786
while (queue.length) {
8887
for (const next of links[queue.shift()!] ?? []) {
@@ -97,14 +96,16 @@ export function lineageGraph(manifest: any, id: string): LineageGraph {
9796
return false
9897
}
9998
const upTruncated = walk(parents, MAX_UPSTREAM)
100-
const truncated = walk(children, MAX_DOWNSTREAM)
99+
// Tests are counted for the target and what is downstream of it only; upstream ones would only add weight.
100+
const counted = new Set([id])
101+
const truncated = walk(children, MAX_DOWNSTREAM, counted)
101102
const graph: LineageGraph = { nodes: {}, parents: {}, children: {}, truncated, upTruncated }
102103
for (const one of keep) {
103104
graph.nodes[one] = nodeOf(one, lookup(manifest, one))
104105
graph.parents[one] = (parents[one] ?? []).filter((other) => keep.has(other))
105106
graph.children[one] = (children[one] ?? []).filter((other) => {
106107
if (keep.has(other)) return true
107-
if (!isTest(other)) return false
108+
if (!isTest(other) || !counted.has(one)) return false
108109
if (!graph.nodes[other]) {
109110
graph.nodes[other] = { ...nodeOf(other, lookup(manifest, other)), type: "test" }
110111
graph.parents[other] = (parents[other] ?? []).filter((p) => keep.has(p))

‎packages/opencode/test/altimate/column-reach.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ describe("lineageGraph", () => {
323323
test("a twelve-hop chain comes back whole to its source; upstream past 500 nodes is cut and marked", () => {
324324
const chain: Record<string, any> = {}
325325
for (let i = 1; i <= 12; i++) chain[`model.shop.m${i}`] = model(`m${i}`, [i === 1 ? "source.shop.raw.orders" : `model.shop.m${i - 1}`], "select 1", [])
326+
chain["test.shop.m3_unique"] = { resource_type: "test", name: "m3_unique", depends_on: { nodes: ["model.shop.m3"] } }
326327
const graph = lineageGraph({ nodes: chain, sources: { "source.shop.raw.orders": { resource_type: "source", name: "orders", source_name: "raw" } } }, "model.shop.m12")
328+
// An upstream model's tests are left out: only the target's and downstream tests are counted.
329+
expect(graph.nodes["test.shop.m3_unique"]).toBeUndefined()
327330
expect(graph.nodes["source.shop.raw.orders"]).toBeDefined()
328331
expect(Object.keys(graph.nodes)).toHaveLength(13)
329332
expect(graph.upTruncated).toBe(false)

0 commit comments

Comments
 (0)