Skip to content

Commit c369641

Browse files
anandgupta42claude
andcommitted
fix: address PR review comments — export functions, use tmpdir fixture, fix portability
- Export `findDownstream`, `formatImpactReport`, `DownstreamModel` from `impact-analysis.ts` and import in tests instead of copying - Export `parseMarkdownSections`, `slugify`, `MarkdownSection` from `training-import.ts` and import in tests instead of copying - Replace manual `beforeEach`/`afterEach` temp dir lifecycle in `seek-sequence.test.ts` with shared `tmpdir()` fixture pattern - Replace `require("fs").writeFileSync` with async `fs.writeFile` - Replace hardcoded `/tmp/` path with `path.join(tmp.path, ...)` - Use cross-platform PATH separator in `is-tool-on-path.test.ts` Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 95f4b8c commit c369641

6 files changed

Lines changed: 59 additions & 269 deletions

File tree

‎packages/opencode/src/altimate/tools/impact-analysis.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ export const ImpactAnalysisTool = Tool.define("impact_analysis", {
152152
},
153153
})
154154

155-
interface DownstreamModel {
155+
export interface DownstreamModel {
156156
name: string
157157
depth: number
158158
materialized?: string
159159
path: string[]
160160
}
161161

162-
function findDownstream(
162+
export function findDownstream(
163163
targetName: string,
164164
models: Array<{ name: string; depends_on: string[]; materialized?: string }>,
165165
): DownstreamModel[] {
@@ -188,7 +188,7 @@ function findDownstream(
188188
return results
189189
}
190190

191-
function formatImpactReport(data: {
191+
export function formatImpactReport(data: {
192192
model: string
193193
column?: string
194194
changeType: string

‎packages/opencode/src/altimate/tools/training-import.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ export const TrainingImportTool = Tool.define("training_import", {
159159
},
160160
})
161161

162-
interface MarkdownSection {
162+
export interface MarkdownSection {
163163
name: string
164164
content: string
165165
}
166166

167-
function parseMarkdownSections(markdown: string): MarkdownSection[] {
167+
export function parseMarkdownSections(markdown: string): MarkdownSection[] {
168168
const sections: MarkdownSection[] = []
169169
const lines = markdown.split("\n")
170170
let currentH1 = ""
@@ -222,7 +222,7 @@ function parseMarkdownSections(markdown: string): MarkdownSection[] {
222222
return sections
223223
}
224224

225-
function slugify(text: string): string {
225+
export function slugify(text: string): string {
226226
const result = text
227227
.normalize("NFKD")
228228
.replace(/[\u0300-\u036f]/g, "")

‎packages/opencode/test/altimate/tools/impact-analysis.test.ts‎

Lines changed: 2 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,6 @@
11
import { describe, test, expect } from "bun:test"
2-
3-
// Copy of findDownstream and formatImpactReport from
4-
// src/altimate/tools/impact-analysis.ts (not exported, tested standalone)
5-
6-
interface DownstreamModel {
7-
name: string
8-
depth: number
9-
materialized?: string
10-
path: string[]
11-
}
12-
13-
function findDownstream(
14-
targetName: string,
15-
models: Array<{ name: string; depends_on: string[]; materialized?: string }>,
16-
): DownstreamModel[] {
17-
const results: DownstreamModel[] = []
18-
const visited = new Set<string>()
19-
20-
function walk(name: string, depth: number, path: string[]) {
21-
for (const model of models) {
22-
if (visited.has(model.name)) continue
23-
const deps = model.depends_on.map((d) => d.split(".").pop())
24-
if (deps.includes(name)) {
25-
visited.add(model.name)
26-
const newPath = [...path, model.name]
27-
results.push({
28-
name: model.name,
29-
depth,
30-
materialized: model.materialized,
31-
path: newPath,
32-
})
33-
walk(model.name, depth + 1, newPath)
34-
}
35-
}
36-
}
37-
38-
walk(targetName, 1, [targetName])
39-
return results
40-
}
41-
42-
function formatImpactReport(data: {
43-
model: string
44-
column?: string
45-
changeType: string
46-
direct: DownstreamModel[]
47-
transitive: DownstreamModel[]
48-
affectedTestCount: number
49-
columnImpact: string[]
50-
totalModels: number
51-
}): string {
52-
const lines: string[] = []
53-
const target = data.column ? `${data.model}.${data.column}` : data.model
54-
lines.push(`Impact Analysis: ${data.changeType.toUpperCase()} ${target}`)
55-
lines.push("".padEnd(60, "="))
56-
57-
const totalAffected = data.direct.length + data.transitive.length
58-
const pct = data.totalModels > 0 ? ((totalAffected / data.totalModels) * 100).toFixed(1) : "0"
59-
lines.push(`Blast radius: ${totalAffected}/${data.totalModels} models (${pct}%)`)
60-
lines.push("")
61-
62-
if (data.changeType === "remove" && totalAffected > 0) {
63-
lines.push("WARNING: This is a BREAKING change. All downstream models will fail.")
64-
lines.push("")
65-
} else if (data.changeType === "rename" && totalAffected > 0) {
66-
lines.push("WARNING: Rename requires updating all downstream references.")
67-
lines.push("")
68-
} else if (data.changeType === "retype" && totalAffected > 0) {
69-
lines.push("CAUTION: Type change may cause implicit casts or failures in downstream models.")
70-
lines.push("")
71-
}
72-
73-
if (data.direct.length > 0) {
74-
lines.push(`Direct Dependents (${data.direct.length})`)
75-
lines.push("".padEnd(40, "-"))
76-
for (const d of data.direct) {
77-
const mat = d.materialized ? ` [${d.materialized}]` : ""
78-
lines.push(` ${d.name}${mat}`)
79-
}
80-
lines.push("")
81-
}
82-
83-
if (data.transitive.length > 0) {
84-
lines.push(`Transitive Dependents (${data.transitive.length})`)
85-
lines.push("".padEnd(40, "-"))
86-
for (const d of data.transitive) {
87-
const mat = d.materialized ? ` [${d.materialized}]` : ""
88-
const path = d.path.join(" \u2192 ")
89-
lines.push(` ${d.name}${mat} (via: ${path})`)
90-
}
91-
lines.push("")
92-
}
93-
94-
if (data.column && data.columnImpact.length > 0) {
95-
lines.push(`Affected Output Columns (${data.columnImpact.length})`)
96-
lines.push("".padEnd(40, "-"))
97-
for (const col of data.columnImpact) {
98-
lines.push(` ${col}`)
99-
}
100-
lines.push("")
101-
}
102-
103-
if (data.affectedTestCount > 0) {
104-
lines.push(`Tests in project: ${data.affectedTestCount}`)
105-
lines.push("".padEnd(40, "-"))
106-
lines.push(` Run \`dbt test\` to verify all ${data.affectedTestCount} tests still pass after this change.`)
107-
lines.push("")
108-
}
109-
110-
if (totalAffected === 0) {
111-
lines.push("No downstream models depend on this. Change is safe to make.")
112-
}
113-
114-
if (totalAffected > 0) {
115-
lines.push("Recommended Actions")
116-
lines.push("".padEnd(40, "-"))
117-
if (data.changeType === "remove") {
118-
lines.push("1. Update all downstream models to remove references")
119-
lines.push("2. Run `dbt test` to verify no broken references")
120-
lines.push("3. Consider deprecation period before removal")
121-
} else if (data.changeType === "rename") {
122-
lines.push("1. Update all downstream SQL references to new name")
123-
lines.push("2. Run `dbt compile` to verify all models compile")
124-
lines.push("3. Run `dbt test` to verify correctness")
125-
} else if (data.changeType === "retype") {
126-
lines.push("1. Check downstream models for implicit type casts")
127-
lines.push("2. Verify aggregations and joins still work correctly")
128-
lines.push("3. Run `dbt test` with data validation")
129-
} else {
130-
lines.push("1. Review downstream models for compatibility")
131-
lines.push("2. Run `dbt compile` and `dbt test`")
132-
}
133-
}
134-
135-
return lines.join("\n")
136-
}
2+
import { findDownstream, formatImpactReport } from "../../../src/altimate/tools/impact-analysis"
3+
import type { DownstreamModel } from "../../../src/altimate/tools/impact-analysis"
1374

1385
describe("findDownstream: DAG traversal", () => {
1396
test("returns empty for leaf model with no dependents", () => {

‎packages/opencode/test/altimate/tools/training-import.test.ts‎

Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,8 @@
11
import { describe, test, expect } from "bun:test"
2-
3-
// Copy of parseMarkdownSections and slugify from
4-
// src/altimate/tools/training-import.ts (not exported, tested standalone)
5-
6-
interface MarkdownSection {
7-
name: string
8-
content: string
9-
}
10-
11-
function parseMarkdownSections(markdown: string): MarkdownSection[] {
12-
const sections: MarkdownSection[] = []
13-
const lines = markdown.split("\n")
14-
let currentH1 = ""
15-
let currentName = ""
16-
let currentContent: string[] = []
17-
18-
for (const line of lines) {
19-
if (line.match(/^#\s+/)) {
20-
if (currentName && currentContent.length > 0) {
21-
sections.push({
22-
name: slugify(currentName),
23-
content: currentContent.join("\n").trim(),
24-
})
25-
}
26-
currentH1 = line.replace(/^#\s+/, "").trim()
27-
currentName = ""
28-
currentContent = []
29-
continue
30-
}
31-
32-
if (line.match(/^##\s+/)) {
33-
if (currentName && currentContent.length > 0) {
34-
sections.push({
35-
name: slugify(currentName),
36-
content: currentContent.join("\n").trim(),
37-
})
38-
}
39-
currentName = line.replace(/^##\s+/, "").trim()
40-
if (currentH1) {
41-
currentContent = [`Context: ${currentH1}`, ""]
42-
} else {
43-
currentContent = []
44-
}
45-
continue
46-
}
47-
48-
if (currentName) {
49-
currentContent.push(line)
50-
}
51-
}
52-
53-
if (currentName && currentContent.length > 0) {
54-
sections.push({
55-
name: slugify(currentName),
56-
content: currentContent.join("\n").trim(),
57-
})
58-
}
59-
60-
return sections
61-
}
62-
63-
function slugify(text: string): string {
64-
const result = text
65-
.normalize("NFKD")
66-
.replace(/[\u0300-\u036f]/g, "")
67-
.toLowerCase()
68-
.replace(/[^a-z0-9\s-]/g, "")
69-
.replace(/\s+/g, "-")
70-
.slice(0, 64)
71-
.replace(/^-+|-+$/g, "")
72-
return result || "untitled"
73-
}
2+
import {
3+
parseMarkdownSections,
4+
slugify,
5+
} from "../../../src/altimate/tools/training-import"
746

757
describe("slugify", () => {
768
test("lowercases and replaces spaces with hyphens", () => {

‎packages/opencode/test/cli/is-tool-on-path.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ describe("isToolOnPath", () => {
9999
delete process.env.ALTIMATE_BIN_DIR
100100

101101
savedEnv.PATH = process.env.PATH
102-
process.env.PATH = path.join(tmp.path, "path-bin") + ":" + (process.env.PATH ?? "")
102+
const sep = process.platform === "win32" ? ";" : ":"
103+
process.env.PATH = path.join(tmp.path, "path-bin") + sep + (process.env.PATH ?? "")
103104

104105
await Instance.provide({
105106
directory: tmp.path,

0 commit comments

Comments
 (0)