Skip to content

Commit 149f4d3

Browse files
anandgupta42claude
andcommitted
fix: address cubic review — avoid double blank line in validate output
Cubic flagged `altimate_core_validate`'s no-schema note: when the note was pushed into the `lines` array, its leading `\n\n` combined with the `\n` join produced three consecutive newlines in the rendered output. Fixed by storing the note without the leading blanks and inserting an explicit empty line at each call site. Also: - Extracted the warning to a module-level `NO_SCHEMA_NOTE` constant so the text lives in one place. - Added regression tests that assert the rendered output never contains three consecutive newlines for either the valid or the failure path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4ce1014 commit 149f4d3

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

packages/opencode/src/altimate/tools/altimate-core-validate.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,31 @@ function classifyValidationError(message: string): string {
7474
return "validation_error"
7575
}
7676

77+
// Warning appended when validation runs without a schema. Stored without a
78+
// leading blank so it can be pushed into a line array; a blank line is added
79+
// explicitly at each call site where spacing is desired.
80+
const NO_SCHEMA_NOTE =
81+
"Note: No schema was provided, so table/column existence checks were skipped. " +
82+
"To catch missing tables or columns, run `schema_inspect` on the referenced tables first " +
83+
"or pass `schema_context` inline with {tables: {...}}."
84+
7785
function formatValidate(data: Record<string, any>, hasSchema: boolean): string {
7886
if (data.error) return `Error: ${data.error}`
79-
const schemaNote = hasSchema
80-
? ""
81-
: "\n\nNote: No schema was provided, so table/column existence checks were skipped. " +
82-
"To catch missing tables or columns, run `schema_inspect` on the referenced tables first " +
83-
"or pass `schema_context` inline with {tables: {...}}."
84-
if (data.valid) return `SQL is valid.${schemaNote}`
87+
if (data.valid) {
88+
return hasSchema ? "SQL is valid." : `SQL is valid.\n\n${NO_SCHEMA_NOTE}`
89+
}
8590

8691
const lines = ["Validation failed:\n"]
8792
for (const err of data.errors ?? []) {
8893
lines.push(` • ${err.message}`)
8994
if (err.location) lines.push(` at line ${err.location.line}`)
9095
}
91-
if (schemaNote) lines.push(schemaNote)
96+
if (!hasSchema) {
97+
// Blank separator line, then the note — avoids the double newline that
98+
// would appear if the note itself started with `\n\n` and was joined
99+
// with `\n`.
100+
lines.push("")
101+
lines.push(NO_SCHEMA_NOTE)
102+
}
92103
return lines.join("\n")
93104
}

packages/opencode/test/altimate/tools/altimate-core-validate.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ describe("formatValidate", () => {
133133
expect(result).toContain("syntax error")
134134
expect(result).toContain("No schema was provided")
135135
})
136+
137+
test("no double blank line between valid SQL and the schema note", () => {
138+
// Regression: previously the note started with `\n\n` which produced
139+
// `SQL is valid.\n\n\n\nNote:` when concatenated. One blank separator is
140+
// enough.
141+
const result = formatValidate({ valid: true }, false)
142+
expect(result).not.toContain("\n\n\n")
143+
})
144+
145+
test("no extra blank line between failure list and the schema note", () => {
146+
// Regression: pushing a note that starts with `\n\n` into the `lines`
147+
// array and joining on `\n` produced three consecutive newlines.
148+
const result = formatValidate(
149+
{ valid: false, errors: [{ message: "missing column foo" }] },
150+
false,
151+
)
152+
expect(result).toContain("missing column foo")
153+
expect(result).toContain("No schema was provided")
154+
expect(result).not.toContain("\n\n\n")
155+
})
136156
})
137157

138158
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)