Skip to content

Commit 6544ed9

Browse files
committed
fix: resolve simulation suite failures — object stringification, error propagation, and test mock formats
- `altimate-core-column-lineage`: fix `[object Object]` in `column_dict` output when source entries are `{ source_table, source_column }` objects instead of strings - `schema-inspect`: propagate `{ success: false, error }` dispatcher responses to `metadata.error` instead of silently returning empty schema - `sql-analyze`: guard against null/undefined result from dispatcher to prevent "undefined" literal in output - `lineage-check`: guard against null/undefined result from dispatcher to prevent "undefined" literal in output - `simulation-suite.test.ts`: fix `sql-translate` mock format — data fields must be flat (not wrapped in `data: {}`), add `source_dialect`/`target_dialect` to mock so assertions pass - `simulation-suite.test.ts`: fix `dbt-manifest` mock format — unwrap `data: {}` so `model_count` and `models` are accessible at top level Simulation suite: 695/839 → 839/839 (100%)
1 parent 2985d9b commit 6544ed9

File tree

5 files changed

+56
-18
lines changed

5 files changed

+56
-18
lines changed

packages/opencode/src/altimate/tools/altimate-core-column-lineage.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,16 @@ function formatColumnLineage(data: Record<string, any>): string {
4747
if (data.column_dict && Object.keys(data.column_dict).length > 0) {
4848
lines.push("Column Mappings:")
4949
for (const [target, sources] of Object.entries(data.column_dict)) {
50-
const srcList = Array.isArray(sources) ? (sources as string[]).join(", ") : JSON.stringify(sources)
50+
const srcList = Array.isArray(sources)
51+
? sources
52+
.map((s: any) => {
53+
if (typeof s === "string") return s
54+
if (s && s.source_table && s.source_column) return `${s.source_table}.${s.source_column}`
55+
if (s && s.source) return String(s.source)
56+
return JSON.stringify(s)
57+
})
58+
.join(", ")
59+
: JSON.stringify(sources)
5160
lines.push(` ${target}${srcList}`)
5261
}
5362
lines.push("")

packages/opencode/src/altimate/tools/lineage-check.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@ export const LineageCheckTool = Tool.define("lineage_check", {
2020
}),
2121
async execute(args, ctx) {
2222
try {
23-
const result = await Dispatcher.call("lineage.check", {
23+
const raw = await Dispatcher.call("lineage.check", {
2424
sql: args.sql,
2525
dialect: args.dialect,
2626
schema_context: args.schema_context,
2727
})
2828

29+
// Guard against null/undefined/non-object responses
30+
if (raw == null || typeof raw !== "object") {
31+
return {
32+
title: "Lineage: ERROR",
33+
metadata: { success: false, error: "Unexpected response from lineage handler" },
34+
output: "Lineage check failed: unexpected response format.",
35+
}
36+
}
37+
const result = raw as LineageCheckResult
38+
2939
const data = (result.data ?? {}) as Record<string, any>
3040
if (result.error) {
3141
return {

packages/opencode/src/altimate/tools/schema-inspect.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,22 @@ export const SchemaInspectTool = Tool.define("schema_inspect", {
1515
}),
1616
async execute(args, ctx) {
1717
try {
18-
const result = await Dispatcher.call("schema.inspect", {
18+
const raw = (await Dispatcher.call("schema.inspect", {
1919
table: args.table,
2020
schema_name: args.schema_name,
2121
warehouse: args.warehouse,
22-
})
22+
})) as any
23+
24+
// Surface dispatcher-level errors (e.g. { success: false, error: "..." })
25+
if (!raw || raw.success === false || raw.error) {
26+
const errorMsg = (raw?.error as string) ?? "Schema inspection failed"
27+
return {
28+
title: "Schema: ERROR",
29+
metadata: { columnCount: 0, rowCount: undefined, error: errorMsg },
30+
output: `Failed to inspect schema: ${errorMsg}\n\nEnsure the dispatcher is running and a warehouse connection is configured.`,
31+
}
32+
}
33+
const result = raw as SchemaInspectResult
2334

2435
// altimate_change start — progressive disclosure suggestions
2536
let output = formatSchema(result)

packages/opencode/src/altimate/tools/sql-analyze.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,23 @@ export const SqlAnalyzeTool = Tool.define("sql_analyze", {
2626
async execute(args, ctx) {
2727
const hasSchema = !!(args.schema_path || (args.schema_context && Object.keys(args.schema_context).length > 0))
2828
try {
29-
const result = await Dispatcher.call("sql.analyze", {
29+
const raw = await Dispatcher.call("sql.analyze", {
3030
sql: args.sql,
3131
dialect: args.dialect,
3232
schema_path: args.schema_path,
3333
schema_context: args.schema_context,
3434
})
3535

36+
// Guard against null/undefined/non-object responses
37+
if (raw == null || typeof raw !== "object") {
38+
return {
39+
title: "Analyze: ERROR",
40+
metadata: { success: false, issueCount: 0, confidence: "unknown", dialect: args.dialect, has_schema: hasSchema, error: "Unexpected response from analysis handler" },
41+
output: "Analysis failed: unexpected response format.",
42+
}
43+
}
44+
const result = raw
45+
3646
// The handler returns success=true when analysis completes (issues are
3747
// reported via issues/issue_count). Only treat it as a failure when
3848
// there's an actual error (e.g. parse failure).

packages/opencode/test/altimate/simulation-suite.test.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -907,15 +907,13 @@ describe("Category 4: dbt Integration", () => {
907907
args: { path: "target/manifest.json" },
908908
mockResponse: {
909909
success: true,
910-
data: {
911-
model_count: project.models,
912-
source_count: project.sources,
913-
test_count: project.tests,
914-
snapshot_count: 0,
915-
seed_count: 0,
916-
models,
917-
sources: [{ name: "raw_data", schema: "raw", columns: [] }],
918-
},
910+
model_count: project.models,
911+
source_count: project.sources,
912+
test_count: project.tests,
913+
snapshot_count: 0,
914+
seed_count: 0,
915+
models,
916+
sources: [{ name: "raw_data", schema: "raw", columns: [] }],
919917
},
920918
assertions: (result) => {
921919
expect(result.output).toContain("model")
@@ -1122,10 +1120,10 @@ describe("Category 7: SQL Translation", () => {
11221120
dialect: `${source}${target}`,
11231121
mockResponse: {
11241122
success: true,
1125-
data: {
1126-
translated_sql: SQL_CORPUS[sqlKey].replace(/SELECT/g, "/* translated */ SELECT"),
1127-
warnings: source === "snowflake" && target === "mysql" ? ["QUALIFY clause not supported in MySQL"] : [],
1128-
},
1123+
translated_sql: SQL_CORPUS[sqlKey].replace(/SELECT/g, "/* translated */ SELECT"),
1124+
source_dialect: source,
1125+
target_dialect: target,
1126+
warnings: source === "snowflake" && target === "mysql" ? ["QUALIFY clause not supported in MySQL"] : [],
11291127
},
11301128
assertions: (result) => {
11311129
expect(result.output).toContain(source)

0 commit comments

Comments
 (0)