From 8220064d21a7bdbd76aa97ab844f4419e91e26c6 Mon Sep 17 00:00:00 2001 From: Harish Kumar Date: Tue, 17 Nov 2026 21:36:50 +0530 Subject: [PATCH 1/5] fix: derive placeholder tool tests from the stub marker, return dbt_sql_graph as structured content, and let run_results readers take a target folder The placeholder tests no longer assume which feature tools are still stubs: a tool is a placeholder iff its source still carries the stub sentence, and a test checks that classification against actually running the tool. dbt_sql_graph's model, nodes and edges are passed through MCP structured content. resolveDbtTargetPath and readRunResults accept a caller-named target folder, and readRunResults also returns the invocation id, elapsed time and per-node execution time and rejects a file rewritten during the read. Co-Authored-By: Claude Opus 5.5 --- .../src/altimate/mcp-server/server.ts | 1 + .../altimate/validators/validator-utils.ts | 56 ++++++++++++--- .../test/altimate/column-reach.test.ts | 6 ++ .../test/altimate/dbt-adapter-access.test.ts | 22 +++++- .../validators/dbt-build-green.test.ts | 13 ++++ .../validators/dbt-nothing-built.test.ts | 71 ++++++++++++++++++- 6 files changed, 157 insertions(+), 12 deletions(-) diff --git a/packages/opencode/src/altimate/mcp-server/server.ts b/packages/opencode/src/altimate/mcp-server/server.ts index c89ebee902..64639f6998 100644 --- a/packages/opencode/src/altimate/mcp-server/server.ts +++ b/packages/opencode/src/altimate/mcp-server/server.ts @@ -51,6 +51,7 @@ export async function serverInstructions(): Promise { // fields are passed, and the whole is capped. const STRUCTURED_FIELDS: Record = { dbt_lineage: ["model_name", "model_unique_id", "confidence", "confidence_factors", "upstream", "columns", "edges", "error"], + dbt_sql_graph: ["model", "nodes", "edges", "error"], impact_analysis: [ "model", "column", diff --git a/packages/opencode/src/altimate/validators/validator-utils.ts b/packages/opencode/src/altimate/validators/validator-utils.ts index e1d85c476e..1e87ef7a4b 100644 --- a/packages/opencode/src/altimate/validators/validator-utils.ts +++ b/packages/opencode/src/altimate/validators/validator-utils.ts @@ -838,10 +838,15 @@ function collectDeliverableTokens(tokens: string[]): { models: string[]; files: // --------------------------------------------------------------------------- /** - * Resolve the project's artifact directory. Honours `DBT_TARGET_PATH` and a - * `target-path:` key in `dbt_project.yml`; defaults to `target`. - */ -export async function resolveDbtTargetPath(dbtRoot: string): Promise { + * Resolve the project's artifact directory. A `targetPath` the caller names (the + * folder a `--target-path` run wrote to) wins; else `DBT_TARGET_PATH` and a + * `target-path:` key in `dbt_project.yml` are honoured; defaults to `target`. + */ +export async function resolveDbtTargetPath(dbtRoot: string, targetPath?: string): Promise { + // A folder the caller names (the one a `--target-path` run wrote to) wins over the environment and the project file. + if (targetPath && targetPath.trim().length > 0) { + return isAbsolutePath(targetPath) ? targetPath : join(dbtRoot, targetPath) + } const fromEnv = process.env.DBT_TARGET_PATH if (fromEnv && fromEnv.trim().length > 0) { return isAbsolutePath(fromEnv) ? fromEnv : join(dbtRoot, fromEnv) @@ -1191,6 +1196,8 @@ export interface RunResultNode { status: string /** dbt's message for the node, when present. */ message: string | null + /** Seconds dbt spent on the node (`execution_time`), when it wrote a number. */ + executionTimeSec: number | null } /** A parsed `run_results.json` plus its freshness. */ @@ -1212,6 +1219,10 @@ export interface RunResultsArtifact { * not evidence that anything was built. */ command: string | null + /** `metadata.invocation_id`, when the file carries one. */ + invocationId: string | null + /** The run's `elapsed_time` in seconds, when the file carries one. */ + elapsedSec: number | null } /** @@ -1348,14 +1359,26 @@ export function isFailedRunStatus(status: string): boolean { * Read and parse `/run_results.json`. Returns null when the artifact * is absent or unparseable — callers decide what that means for their gate. */ -export async function readRunResults(dbtRoot: string): Promise { - const targetPath = await resolveDbtTargetPath(dbtRoot) +export async function readRunResults(dbtRoot: string, targetPathOverride?: string): Promise { + const targetPath = await resolveDbtTargetPath(dbtRoot, targetPathOverride) const path = join(targetPath, "run_results.json") try { - const stat = await fs.stat(path) + const stat = await fs.stat(path, { bigint: true }) if (!stat.isFile()) return null const raw = await fs.readFile(path, "utf8") - const parsed = JSON.parse(raw) as { results?: unknown; args?: unknown } + // The time keeps the plain stat's own rounding: every other caller compares it with mtimes read the same way, and a different rounding of equal timestamps would order them apart. It is taken between the two bigint stats, so the comparison below proves it describes the same file version as the rows. + const plain = await fs.stat(path) + // A rewrite during the read changes the file's identity, size or times (nanosecond precision): the rows and the time would belong to different runs, so there is no evidence. + const after = await fs.stat(path, { bigint: true }) + if ( + after.ino !== stat.ino || + after.size !== stat.size || + after.mtimeNs !== stat.mtimeNs || + after.ctimeNs !== stat.ctimeNs + ) + return null + const mtimeMs = plain.mtimeMs + const parsed = JSON.parse(raw) as { results?: unknown; args?: unknown; metadata?: unknown; elapsed_time?: unknown } // A file that parses but carries no `results` array is not a run artifact. // Returning an empty one would read as "a build happened and recorded // nothing", which lets an unbuilt model through; null means "no evidence". @@ -1383,9 +1406,24 @@ export async function readRunResults(dbtRoot: string): Promise) + : null + const invocation = meta && typeof meta["invocation_id"] === "string" ? meta["invocation_id"] : "" + const elapsed = typeof parsed.elapsed_time === "number" && Number.isFinite(parsed.elapsed_time) ? parsed.elapsed_time : null + return { + path, + mtimeMs, + results, + command, + invocationId: invocation || null, + elapsedSec: elapsed, + } } catch { return null } diff --git a/packages/opencode/test/altimate/column-reach.test.ts b/packages/opencode/test/altimate/column-reach.test.ts index 6362ae9bb8..9f8e743bff 100644 --- a/packages/opencode/test/altimate/column-reach.test.ts +++ b/packages/opencode/test/altimate/column-reach.test.ts @@ -863,6 +863,12 @@ describe("structuredError", () => { .report, ).toBe("Model: x") }) + test("dbt_sql_graph's model, nodes and edges reach the structured fields", () => { + const nodes = [{ id: "a", name: "a" }] + expect( + structuredResult("dbt_sql_graph", { model: "orders", nodes, edges: [], success: true }, "SQL graph for orders"), + ).toEqual({ model: "orders", nodes, edges: [], report: "SQL graph for orders" }) + }) test("exposures_error reaches the structured fields", () => { expect(structuredResult("impact_analysis", { exposures_error: "bad json" }, "R")).toEqual({ exposures_error: "bad json", diff --git a/packages/opencode/test/altimate/dbt-adapter-access.test.ts b/packages/opencode/test/altimate/dbt-adapter-access.test.ts index 4317672e42..7819dc37ad 100644 --- a/packages/opencode/test/altimate/dbt-adapter-access.test.ts +++ b/packages/opencode/test/altimate/dbt-adapter-access.test.ts @@ -3,7 +3,7 @@ // dbt adapter is replaced through `dbtAdapterInternals`, so these tests need no Python or dbt. import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from "bun:test" import { chmod, mkdtemp, rm, writeFile } from "node:fs/promises" -import { realpathSync } from "node:fs" +import { existsSync, readFileSync, realpathSync } from "node:fs" import os from "node:os" import path from "node:path" import { Effect } from "effect" @@ -32,6 +32,12 @@ const MINIMAL_ARGS: Record> = { } const FEATURE_TOOLS = Object.keys(MINIMAL_ARGS) +/** The sentence every stub's answer carries; a real tool replaces the whole file, so it no longer has it. */ +const PLACEHOLDER_MARKER = "is not implemented in this build of altimate-code yet." +const toolSource = (id: string) => path.join(import.meta.dir, "../../src/altimate/tools", `${id.replaceAll("_", "-")}.ts`) +const isPlaceholder = (id: string) => readFileSync(toolSource(id), "utf8").includes(PLACEHOLDER_MARKER) +const PLACEHOLDERS = FEATURE_TOOLS.filter(isPlaceholder) + const ctx: Tool.Context = { sessionID: SessionID.make("ses_dbt_adapter_access"), messageID: MessageID.make("msg_dbt_adapter_access"), @@ -82,8 +88,20 @@ describe("feature tools in the allow-list", () => { expect(listed).toEqual([...listed].sort()) }) - test("each placeholder answers that it isn't implemented, as a failure", async () => { + test("every feature tool has its source file, so the placeholder marker is always read", () => { + for (const id of FEATURE_TOOLS) expect(existsSync(toolSource(id))).toBe(true) + }) + + test("a tool is classed a placeholder by its source's marker exactly when it answers that it isn't implemented", async () => { for (const id of FEATURE_TOOLS) { + const tool = await initTool(EXPOSED[id] as any) + const result = await tool.execute(MINIMAL_ARGS[id], ctx) + expect(result.title === `${id}: not implemented`).toBe(isPlaceholder(id)) + } + }) + + test("each placeholder answers that it isn't implemented, as a failure", async () => { + for (const id of PLACEHOLDERS) { const tool = await initTool(EXPOSED[id] as any) expect(tool.id).toBe(id) const result = await tool.execute(MINIMAL_ARGS[id], ctx) diff --git a/packages/opencode/test/altimate/validators/dbt-build-green.test.ts b/packages/opencode/test/altimate/validators/dbt-build-green.test.ts index df91fd655a..fbacda0529 100644 --- a/packages/opencode/test/altimate/validators/dbt-build-green.test.ts +++ b/packages/opencode/test/altimate/validators/dbt-build-green.test.ts @@ -113,6 +113,19 @@ describe("DbtBuildGreenValidator — fresh artifact", () => { expect(r.details!["verdict"]).toBe("fresh-build") }) + test("a model and an artifact stamped with the same instant read as built, not edited after the build", async () => { + await makeProject() + await writeModel("stg_orders") + await writeRunResults([{ id: "model.t.stg_orders", status: "success" }]) + // A coarse filesystem clock gives writes in one tick the same nanosecond timestamp. + const t = 1_800_000_000.004123 + await fs.utimes(join(dir, "models", "stg_orders.sql"), t, t) + await fs.utimes(join(dir, "target", "run_results.json"), t, t) + const r = await DbtBuildGreenValidator.check(ctx()) + expect(r.ok).toBe(true) + expect(r.details!["verdict"]).toBe("fresh-build") + }) + test("treats warn as a clean build", async () => { await makeProject() await writeModel("stg_orders") diff --git a/packages/opencode/test/altimate/validators/dbt-nothing-built.test.ts b/packages/opencode/test/altimate/validators/dbt-nothing-built.test.ts index 7dfaef7d38..1c93258d2e 100644 --- a/packages/opencode/test/altimate/validators/dbt-nothing-built.test.ts +++ b/packages/opencode/test/altimate/validators/dbt-nothing-built.test.ts @@ -1,5 +1,5 @@ // altimate_change start — tests for the nothing-built inverse completion gate -import { describe, expect, test, beforeEach, afterEach } from "bun:test" +import { describe, expect, test, beforeEach, afterEach, spyOn } from "bun:test" import { promises as fs } from "fs" import { tmpdir } from "os" import { join } from "path" @@ -274,6 +274,75 @@ describe("run_results and inventory helpers", () => { expect(await resolveDbtTargetPath(dir)).toBe(join(dir, "alt_target")) }) + test("resolveDbtTargetPath lets a caller-named folder win over DBT_TARGET_PATH and the project file", async () => { + await makeProject() + await fs.appendFile(join(dir, "dbt_project.yml"), 'target-path: "build_out"\n') + process.env.DBT_TARGET_PATH = "alt_target" + expect(await resolveDbtTargetPath(dir, "chosen")).toBe(join(dir, "chosen")) + expect(await resolveDbtTargetPath(dir, join(dir, "abs"))).toBe(join(dir, "abs")) + expect(await resolveDbtTargetPath(dir, " ")).toBe(join(dir, "alt_target")) + }) + + test("readRunResults reads a caller-named folder and returns the invocation id, elapsed time and per-node time", async () => { + await makeProject() + await fs.mkdir(join(dir, "chosen"), { recursive: true }) + await fs.writeFile( + join(dir, "chosen", "run_results.json"), + JSON.stringify({ + metadata: { invocation_id: "abc-123" }, + elapsed_time: 4.5, + args: { which: "build" }, + results: [ + { unique_id: "model.t.a", status: "success", execution_time: 1.25 }, + { unique_id: "model.t.b", status: "success" }, + ], + }), + ) + expect(await readRunResults(dir)).toBeNull() + const artifact = await readRunResults(dir, "chosen") + expect(artifact?.invocationId).toBe("abc-123") + expect(artifact?.elapsedSec).toBe(4.5) + expect(artifact?.results.map((r) => r.executionTimeSec)).toEqual([1.25, null]) + }) + + test("readRunResults returns null for a file rewritten while it was being read", async () => { + await makeProject() + await fs.mkdir(join(dir, "target"), { recursive: true }) + const file = join(dir, "target", "run_results.json") + await fs.writeFile(file, JSON.stringify({ args: { which: "build" }, results: [] })) + const real = fs.stat + let bigints = 0 + const spy = spyOn(fs, "stat").mockImplementation((async (p: any, o?: any) => { + const stat: any = await real(p, o) + if (String(p) === file && o?.bigint && ++bigints === 2) return { ...stat, isFile: () => true, size: stat.size + 1n } + return stat + }) as any) + try { + expect(await readRunResults(dir)).toBeNull() + } finally { + spy.mockRestore() + } + }) + + test("readRunResults takes the time from between the two identity stats, so it describes the version the rows came from", async () => { + const dir = await fs.mkdtemp(join(tmpdir(), "rr-order-")) + await fs.mkdir(join(dir, "target"), { recursive: true }) + await fs.writeFile(join(dir, "target", "run_results.json"), JSON.stringify({ args: { which: "build" }, results: [] })) + const real = fs.stat + const kinds: string[] = [] + const spy = spyOn(fs, "stat").mockImplementation(((p: any, o?: any) => { + if (String(p).endsWith("run_results.json")) kinds.push(o?.bigint ? "bigint" : "plain") + return real(p, o) + }) as any) + try { + await readRunResults(dir) + } finally { + spy.mockRestore() + await fs.rm(dir, { recursive: true, force: true }) + } + expect(kinds).toEqual(["bigint", "plain", "bigint"]) + }) + test("readRunResults returns null when the artifact is missing", async () => { await makeProject() expect(await readRunResults(dir)).toBeNull() From c3216af9f0b035afe6d444b189fb17c1db10fea3 Mon Sep 17 00:00:00 2001 From: Harish Kumar Date: Tue, 17 Nov 2026 23:55:49 +0530 Subject: [PATCH 2/5] test: every feature tool, built or not, is registered under its own id Co-Authored-By: Claude Opus 5.5 --- packages/opencode/test/altimate/dbt-adapter-access.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/opencode/test/altimate/dbt-adapter-access.test.ts b/packages/opencode/test/altimate/dbt-adapter-access.test.ts index 7819dc37ad..7ecd9e7d6c 100644 --- a/packages/opencode/test/altimate/dbt-adapter-access.test.ts +++ b/packages/opencode/test/altimate/dbt-adapter-access.test.ts @@ -95,6 +95,7 @@ describe("feature tools in the allow-list", () => { test("a tool is classed a placeholder by its source's marker exactly when it answers that it isn't implemented", async () => { for (const id of FEATURE_TOOLS) { const tool = await initTool(EXPOSED[id] as any) + expect(tool.id).toBe(id) const result = await tool.execute(MINIMAL_ARGS[id], ctx) expect(result.title === `${id}: not implemented`).toBe(isPlaceholder(id)) } From d7973dd83910519b051b97d3443ab163c7cbf3cf Mon Sep 17 00:00:00 2001 From: Harish Kumar Date: Wed, 18 Nov 2026 00:48:46 +0530 Subject: [PATCH 3/5] fix: dbt_sql_graph's structured answer keeps only its report's header; tests read placeholder files when they run, ignore an ambient DBT_TARGET_PATH and check the returned time Co-Authored-By: Claude Opus 5.5 --- .../opencode/src/altimate/mcp-server/server.ts | 10 ++++++++-- .../test/altimate/column-reach.test.ts | 18 ++++++++++++++---- .../test/altimate/dbt-adapter-access.test.ts | 4 ++-- .../validators/dbt-nothing-built.test.ts | 17 +++++++++++++---- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/packages/opencode/src/altimate/mcp-server/server.ts b/packages/opencode/src/altimate/mcp-server/server.ts index 64639f6998..b216998ae1 100644 --- a/packages/opencode/src/altimate/mcp-server/server.ts +++ b/packages/opencode/src/altimate/mcp-server/server.ts @@ -97,8 +97,14 @@ export function structuredResult(tool: string, metadata: Record return Buffer.byteLength(JSON.stringify(full)) <= STRUCTURED_MAX_BYTES ? full : capReport(report, true) } const fields = Object.fromEntries((STRUCTURED_FIELDS[tool] ?? []).filter((key) => key in metadata).map((key) => [key, metadata[key]])) - // dbt_lineage's text prints the same mappings and edges as `columns` and `edges`: keep its header. - const head = tool === "dbt_lineage" && "columns" in fields ? report.split(/\n(?:Column Mappings|Lineage Edges):/)[0]!.trim() : report + // dbt_lineage's text prints the same mappings and edges as `columns` and `edges`, and dbt_sql_graph's + // lists the same nodes as `nodes`: keep only the header. + const head = + tool === "dbt_lineage" && "columns" in fields + ? report.split(/\n(?:Column Mappings|Lineage Edges):/)[0]!.trim() + : tool === "dbt_sql_graph" && "nodes" in fields + ? report.split("\n")[0]!.trim() + : report const full = { ...fields, report: head } if (Buffer.byteLength(JSON.stringify(full)) <= STRUCTURED_MAX_BYTES) return full // The column answer is the largest field: past the cap it goes first, so the model-level fields diff --git a/packages/opencode/test/altimate/column-reach.test.ts b/packages/opencode/test/altimate/column-reach.test.ts index 9f8e743bff..2f32d9cd8e 100644 --- a/packages/opencode/test/altimate/column-reach.test.ts +++ b/packages/opencode/test/altimate/column-reach.test.ts @@ -863,11 +863,21 @@ describe("structuredError", () => { .report, ).toBe("Model: x") }) - test("dbt_sql_graph's model, nodes and edges reach the structured fields", () => { + test("dbt_sql_graph's model, nodes and edges reach the structured fields, with only the report's header", () => { const nodes = [{ id: "a", name: "a" }] - expect( - structuredResult("dbt_sql_graph", { model: "orders", nodes, edges: [], success: true }, "SQL graph for orders"), - ).toEqual({ model: "orders", nodes, edges: [], report: "SQL graph for orders" }) + const report = "SQL graph for orders: 1 nodes, 0 edges\n- a (cte): 1 columns\n columns: id\n sql: select id from x" + expect(structuredResult("dbt_sql_graph", { model: "orders", nodes, edges: [], success: true }, report)).toEqual({ + model: "orders", + nodes, + edges: [], + report: "SQL graph for orders: 1 nodes, 0 edges", + }) + }) + test("a dbt_sql_graph failure keeps its whole report", () => { + expect(structuredResult("dbt_sql_graph", { success: false, error: "no key" }, "Failed: no key\nsee the docs")).toEqual({ + error: "no key", + report: "Failed: no key\nsee the docs", + }) }) test("exposures_error reaches the structured fields", () => { expect(structuredResult("impact_analysis", { exposures_error: "bad json" }, "R")).toEqual({ diff --git a/packages/opencode/test/altimate/dbt-adapter-access.test.ts b/packages/opencode/test/altimate/dbt-adapter-access.test.ts index 7ecd9e7d6c..3f47caa7f6 100644 --- a/packages/opencode/test/altimate/dbt-adapter-access.test.ts +++ b/packages/opencode/test/altimate/dbt-adapter-access.test.ts @@ -35,8 +35,8 @@ const FEATURE_TOOLS = Object.keys(MINIMAL_ARGS) /** The sentence every stub's answer carries; a real tool replaces the whole file, so it no longer has it. */ const PLACEHOLDER_MARKER = "is not implemented in this build of altimate-code yet." const toolSource = (id: string) => path.join(import.meta.dir, "../../src/altimate/tools", `${id.replaceAll("_", "-")}.ts`) +// Read when a test runs, so a missing source file fails the test that checks for it rather than the import. const isPlaceholder = (id: string) => readFileSync(toolSource(id), "utf8").includes(PLACEHOLDER_MARKER) -const PLACEHOLDERS = FEATURE_TOOLS.filter(isPlaceholder) const ctx: Tool.Context = { sessionID: SessionID.make("ses_dbt_adapter_access"), @@ -102,7 +102,7 @@ describe("feature tools in the allow-list", () => { }) test("each placeholder answers that it isn't implemented, as a failure", async () => { - for (const id of PLACEHOLDERS) { + for (const id of FEATURE_TOOLS.filter(isPlaceholder)) { const tool = await initTool(EXPOSED[id] as any) expect(tool.id).toBe(id) const result = await tool.execute(MINIMAL_ARGS[id], ctx) diff --git a/packages/opencode/test/altimate/validators/dbt-nothing-built.test.ts b/packages/opencode/test/altimate/validators/dbt-nothing-built.test.ts index 1c93258d2e..ac0579c023 100644 --- a/packages/opencode/test/altimate/validators/dbt-nothing-built.test.ts +++ b/packages/opencode/test/altimate/validators/dbt-nothing-built.test.ts @@ -284,6 +284,7 @@ describe("run_results and inventory helpers", () => { }) test("readRunResults reads a caller-named folder and returns the invocation id, elapsed time and per-node time", async () => { + delete process.env.DBT_TARGET_PATH await makeProject() await fs.mkdir(join(dir, "chosen"), { recursive: true }) await fs.writeFile( @@ -306,6 +307,7 @@ describe("run_results and inventory helpers", () => { }) test("readRunResults returns null for a file rewritten while it was being read", async () => { + delete process.env.DBT_TARGET_PATH await makeProject() await fs.mkdir(join(dir, "target"), { recursive: true }) const file = join(dir, "target", "run_results.json") @@ -325,22 +327,29 @@ describe("run_results and inventory helpers", () => { }) test("readRunResults takes the time from between the two identity stats, so it describes the version the rows came from", async () => { + delete process.env.DBT_TARGET_PATH const dir = await fs.mkdtemp(join(tmpdir(), "rr-order-")) await fs.mkdir(join(dir, "target"), { recursive: true }) await fs.writeFile(join(dir, "target", "run_results.json"), JSON.stringify({ args: { which: "build" }, results: [] })) const real = fs.stat + // Only the stat between the two identity checks answers this time, so the time returned is that one. + const between = 1_234_567 const kinds: string[] = [] - const spy = spyOn(fs, "stat").mockImplementation(((p: any, o?: any) => { - if (String(p).endsWith("run_results.json")) kinds.push(o?.bigint ? "bigint" : "plain") - return real(p, o) + const spy = spyOn(fs, "stat").mockImplementation((async (p: any, o?: any) => { + const stat: any = await real(p, o) + if (!String(p).endsWith("run_results.json")) return stat + kinds.push(o?.bigint ? "bigint" : "plain") + return kinds.length === 2 && !o?.bigint ? Object.assign(Object.create(Object.getPrototypeOf(stat)), stat, { mtimeMs: between }) : stat }) as any) + let artifact: Awaited> = null try { - await readRunResults(dir) + artifact = await readRunResults(dir) } finally { spy.mockRestore() await fs.rm(dir, { recursive: true, force: true }) } expect(kinds).toEqual(["bigint", "plain", "bigint"]) + expect(artifact?.mtimeMs).toBe(between) }) test("readRunResults returns null when the artifact is missing", async () => { From a2a8081a8a270310b0b9acb4d1c937f5a4acb678 Mon Sep 17 00:00:00 2001 From: Harish Kumar Date: Wed, 18 Nov 2026 01:01:11 +0530 Subject: [PATCH 4/5] docs: name the text in the structured-result comment Co-Authored-By: Claude Opus 5.5 --- packages/opencode/src/altimate/mcp-server/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opencode/src/altimate/mcp-server/server.ts b/packages/opencode/src/altimate/mcp-server/server.ts index b216998ae1..c76914b528 100644 --- a/packages/opencode/src/altimate/mcp-server/server.ts +++ b/packages/opencode/src/altimate/mcp-server/server.ts @@ -98,7 +98,7 @@ export function structuredResult(tool: string, metadata: Record } const fields = Object.fromEntries((STRUCTURED_FIELDS[tool] ?? []).filter((key) => key in metadata).map((key) => [key, metadata[key]])) // dbt_lineage's text prints the same mappings and edges as `columns` and `edges`, and dbt_sql_graph's - // lists the same nodes as `nodes`: keep only the header. + // text lists the same nodes as `nodes`: keep only the header. const head = tool === "dbt_lineage" && "columns" in fields ? report.split(/\n(?:Column Mappings|Lineage Edges):/)[0]!.trim() From db8753bb846ddfee2514d918ae845ed8a148cb98 Mon Sep 17 00:00:00 2001 From: Harish Kumar Date: Wed, 18 Nov 2026 06:58:22 +0530 Subject: [PATCH 5/5] refactor: replace the nested ternary in the structured result header with if/else Co-Authored-By: Claude Opus 5.5 --- packages/opencode/src/altimate/mcp-server/server.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/opencode/src/altimate/mcp-server/server.ts b/packages/opencode/src/altimate/mcp-server/server.ts index c76914b528..c153e8b921 100644 --- a/packages/opencode/src/altimate/mcp-server/server.ts +++ b/packages/opencode/src/altimate/mcp-server/server.ts @@ -99,12 +99,12 @@ export function structuredResult(tool: string, metadata: Record const fields = Object.fromEntries((STRUCTURED_FIELDS[tool] ?? []).filter((key) => key in metadata).map((key) => [key, metadata[key]])) // dbt_lineage's text prints the same mappings and edges as `columns` and `edges`, and dbt_sql_graph's // text lists the same nodes as `nodes`: keep only the header. - const head = - tool === "dbt_lineage" && "columns" in fields - ? report.split(/\n(?:Column Mappings|Lineage Edges):/)[0]!.trim() - : tool === "dbt_sql_graph" && "nodes" in fields - ? report.split("\n")[0]!.trim() - : report + let head = report + if (tool === "dbt_lineage" && "columns" in fields) { + head = report.split(/\n(?:Column Mappings|Lineage Edges):/)[0]!.trim() + } else if (tool === "dbt_sql_graph" && "nodes" in fields) { + head = report.split("\n")[0]!.trim() + } const full = { ...fields, report: head } if (Buffer.byteLength(JSON.stringify(full)) <= STRUCTURED_MAX_BYTES) return full // The column answer is the largest field: past the cap it goes first, so the model-level fields