From 86c56feb1661414787d3622548ffd1c3a77996d6 Mon Sep 17 00:00:00 2001 From: anandgupta42 Date: Sun, 18 Oct 2026 12:21:02 -0700 Subject: [PATCH 1/3] chore: bump @altimateai/altimate-core to 0.9.0 - pin `@altimateai/altimate-core` to `0.9.0` in `packages/opencode/package.json` - update `bun.lock` for the core package and its five platform bindings - no source changes needed: nothing in altimate-code reads the new `plan_status`, `POLICY_SKIPPED` or `plan_unavailable` outputs Co-Authored-By: Claude Opus 5.5 --- bun.lock | 14 +++++++------- packages/opencode/package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bun.lock b/bun.lock index bc4498575b..c348366159 100644 --- a/bun.lock +++ b/bun.lock @@ -272,7 +272,7 @@ "@ai-sdk/togetherai": "2.0.41", "@ai-sdk/vercel": "2.0.39", "@ai-sdk/xai": "3.0.82", - "@altimateai/altimate-core": "0.8.0", + "@altimateai/altimate-core": "0.9.0", "@altimateai/drivers": "workspace:*", "@aws-sdk/credential-providers": "3.1057.0", "@clack/prompts": "1.0.0-alpha.1", @@ -645,17 +645,17 @@ "@altimateai/altimate-code": ["@altimateai/altimate-code@workspace:packages/opencode"], - "@altimateai/altimate-core": ["@altimateai/altimate-core@0.8.0", "", { "optionalDependencies": { "@altimateai/altimate-core-darwin-arm64": "0.8.0", "@altimateai/altimate-core-darwin-x64": "0.8.0", "@altimateai/altimate-core-linux-arm64-gnu": "0.8.0", "@altimateai/altimate-core-linux-x64-gnu": "0.8.0", "@altimateai/altimate-core-win32-x64-msvc": "0.8.0" } }, "sha512-Wmw99OBnrYF1faBDD4zrY6/LH6DLNOJKg1XBOPaNPf8HbFoskmOnsvUEnZK6qVAb11YHjVw/lh0y33zyatDaOQ=="], + "@altimateai/altimate-core": ["@altimateai/altimate-core@0.9.0", "", { "optionalDependencies": { "@altimateai/altimate-core-darwin-arm64": "0.9.0", "@altimateai/altimate-core-darwin-x64": "0.9.0", "@altimateai/altimate-core-linux-arm64-gnu": "0.9.0", "@altimateai/altimate-core-linux-x64-gnu": "0.9.0", "@altimateai/altimate-core-win32-x64-msvc": "0.9.0" } }, "sha512-1nheHkeAsCJwhc59mCuFUfqwxfEOly2JKJ3LDOOHCbitZqAqgqqYLFf4X6nNDFxauf4DWN9KLxYU9V+8gMVaXA=="], - "@altimateai/altimate-core-darwin-arm64": ["@altimateai/altimate-core-darwin-arm64@0.8.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-qFvLLIE7WTCCWrSKFDylK9ypi9mHhRvphs/wcHIDWMhVUtLYmmP2KqYK7+2WKslGJafy9iypoP65VkqQx0cibg=="], + "@altimateai/altimate-core-darwin-arm64": ["@altimateai/altimate-core-darwin-arm64@0.9.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-Gozy3etd94aw3nYhb3/TAIQ339WIdVsEGSg6EYKwOm616dDpIDXeI3e0iw7eMTzOGrXk1HBFPvZhel1H5rd3dA=="], - "@altimateai/altimate-core-darwin-x64": ["@altimateai/altimate-core-darwin-x64@0.8.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-DhQGxdyAdyK6uNlJEMPiE7OsdtzNv2eIpCpBhCtXVFNZTVKebwpXxb5RObpLq70j+x4NgjAMf1PVM8NHD/mRpA=="], + "@altimateai/altimate-core-darwin-x64": ["@altimateai/altimate-core-darwin-x64@0.9.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-+uI97u23d5A404CA4R7uLLQwqhZ/7DAF6+SmA6X6WfiHY+pb4HvyTVWBV7NoWRu9Eb9delV5pW8U7WI4fOl56Q=="], - "@altimateai/altimate-core-linux-arm64-gnu": ["@altimateai/altimate-core-linux-arm64-gnu@0.8.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-UhhSJiTH7TRZSVQFzqc11MuHvYfdSDtqatXy6Q/RhFJ3s7AfL0XPL0BY3xW+BY9n+dsNxzeybkwtosGPE+iVTw=="], + "@altimateai/altimate-core-linux-arm64-gnu": ["@altimateai/altimate-core-linux-arm64-gnu@0.9.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-8YfWq8adhAOj1WrG801LhBFOb8JjqM8o5kHu5yJ186UB+dZzjqT9jUwwwJfacMaL9+Zo7efsyMiK9MQjF+bgaQ=="], - "@altimateai/altimate-core-linux-x64-gnu": ["@altimateai/altimate-core-linux-x64-gnu@0.8.0", "", { "os": "linux", "cpu": "x64" }, "sha512-6LHZXcZi3DYwTvbGgzicS2dtC+MeJ6bzuFqWtb963Ulr1zFEUDWKUiiWWUsXs6JHVEoU9cX/xlGD0t3hZxA8Zg=="], + "@altimateai/altimate-core-linux-x64-gnu": ["@altimateai/altimate-core-linux-x64-gnu@0.9.0", "", { "os": "linux", "cpu": "x64" }, "sha512-w9g01DTf/JwtfJSurwyXPHQwk9yYboMAjRG9PTppcX9ITgkx7BF0xZJjZ9fICG/iALiKxWymr88T6mipV0kyiQ=="], - "@altimateai/altimate-core-win32-x64-msvc": ["@altimateai/altimate-core-win32-x64-msvc@0.8.0", "", { "os": "win32", "cpu": "x64" }, "sha512-AxjfES6ez0agb/2+hG82sVtRx/F/mlqmDC6WNPBBd5M1OALCNm/MKK5ydGRfNA94is9/mbqhNTtk1fGYUuJRGg=="], + "@altimateai/altimate-core-win32-x64-msvc": ["@altimateai/altimate-core-win32-x64-msvc@0.9.0", "", { "os": "win32", "cpu": "x64" }, "sha512-MoELhLPzJGAxJMtL7C/g/gj464I9pbSmfJ6IamhFwsyz7nfUrKOkAnixVXuQrLEJ9I+sVZJuPMq2H1HUCkpOwA=="], "@altimateai/dbt-integration": ["@altimateai/dbt-integration@0.2.14", "", { "dependencies": { "@altimateai/altimate-core": "0.1.6", "node-abort-controller": "^3.1.1", "node-fetch": "^3.3.2", "python-bridge": "^1.1.0", "semver": "^7.6.3", "yaml": "^2.5.0" }, "peerDependencies": { "patch-package": "^8.0.0" } }, "sha512-44hFBx3gXss2RUlRZE9cIpAocffB3miAzpjvmma1EED0jiOhyrgmzGsw3RXEZqs73OuLYpDehixvRUt1vTfcfQ=="], diff --git a/packages/opencode/package.json b/packages/opencode/package.json index 5df16693ba..3599641b6c 100644 --- a/packages/opencode/package.json +++ b/packages/opencode/package.json @@ -79,7 +79,7 @@ "@ai-sdk/togetherai": "2.0.41", "@ai-sdk/vercel": "2.0.39", "@ai-sdk/xai": "3.0.82", - "@altimateai/altimate-core": "0.8.0", + "@altimateai/altimate-core": "0.9.0", "@altimateai/drivers": "workspace:*", "@aws-sdk/credential-providers": "3.1057.0", "@clack/prompts": "1.0.0-alpha.1", From 10faf5472ed0d4c1338f986fa292385a24e60fad Mon Sep 17 00:00:00 2001 From: anandgupta42 Date: Sun, 18 Oct 2026 12:29:57 -0700 Subject: [PATCH 2/3] fix: fail closed when altimate-core skips plan-based policy and semantic analysis altimate-core 0.9.0 validates statements that 0.8.0 rejected as invalid (table-valued functions such as `TABLE(fn())`, `LATERAL FLATTEN`, `read_csv('x')`), but it has no logical plan for them. `checkPolicy` then returns `allowed: true` with a `plan_unavailable` warning and `policies_evaluated: 0`, and `checkSemantics` returns no findings with a "plan-based analysis was skipped" note. Both read as clean. - `altimate_core.policy` handler: treat a `plan_unavailable` / `POLICY_SKIPPED` warning as not evaluated: `allowed: false`, `policy_skipped: true`, plus a `policy_not_evaluated` error violation. CLI `check`, the agent policy tool and every other consumer inherit this. - `altimate_core.semantics` handler: set `skipped` and `skip_reason` when the engine skipped analysis; `check --checks semantic` reports a finding (error with a schema, warning without) and the semantics tool reports `SKIPPED` instead of VALID. - add tests pinning the 0.9.0 behavior for three TVF shapes and an unaffected normal query - update the pin in `docs/internal/deterministic-checks-engine-split.md` Co-Authored-By: Claude Opus 5.5 --- .../deterministic-checks-engine-split.md | 2 +- .../src/altimate/native/altimate-core.ts | 44 ++++++++++++- .../altimate/tools/altimate-core-semantics.ts | 7 +- packages/opencode/src/cli/cmd/check.ts | 16 ++++- .../core-plan-skip-fail-closed.test.ts | 66 +++++++++++++++++++ packages/opencode/test/cli/check-e2e.test.ts | 37 +++++++++++ 6 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 packages/opencode/test/altimate/core-plan-skip-fail-closed.test.ts diff --git a/docs/internal/deterministic-checks-engine-split.md b/docs/internal/deterministic-checks-engine-split.md index 6f96af9a63..e2001cb90f 100644 --- a/docs/internal/deterministic-checks-engine-split.md +++ b/docs/internal/deterministic-checks-engine-split.md @@ -34,7 +34,7 @@ Relevant because it sets the cost of "add something engine-side". layer), `altimate-core-node` (napi-rs), plus `polyglot-sql` for multi-dialect parse and transpile. - Published as the npm package `@altimateai/altimate-core` (per-platform native addon). - altimate-code pins it exactly: `packages/opencode/package.json` → `"@altimateai/altimate-core": "0.8.0"`. + altimate-code pins it exactly: `packages/opencode/package.json` → `"@altimateai/altimate-core": "0.9.0"`. - Consumer binding: `packages/opencode/src/altimate/native/altimate-core.ts` registers 42 `altimate_core.*` handlers on the dispatcher. Registration is lazy — the napi binary loads on the first `Dispatcher.call()` (`packages/opencode/src/altimate/native/index.ts`), so a diff --git a/packages/opencode/src/altimate/native/altimate-core.ts b/packages/opencode/src/altimate/native/altimate-core.ts index 1e8a22b7ef..4089f0e74e 100644 --- a/packages/opencode/src/altimate/native/altimate-core.ts +++ b/packages/opencode/src/altimate/native/altimate-core.ts @@ -28,6 +28,46 @@ export function isExistenceError(err: unknown): boolean { } // altimate_change end +// altimate_change start — fail closed when the engine skips plan-based analysis +// Core 0.9.0 returns allowed:true / valid:true with no findings for statements it rewrites +// around table-valued functions (no logical plan). That is "not evaluated", not "clean": +// policy must block, and semantics must say it did not run. +const PLAN_SKIP_RULES = new Set(["plan_unavailable", "POLICY_SKIPPED"]) +const PLAN_SKIP_NOTE = /plan-based analysis was skipped|logical plan unavailable/i + +export const POLICY_NOT_EVALUATED_MESSAGE = + "policy could not be evaluated for this statement (table-valued function, no plan available); treated as blocked" +export const SEMANTICS_SKIPPED_MESSAGE = + "semantic analysis skipped (no plan available for this statement, e.g. table-valued function)" + +/** Mark a policy result not-allowed when the engine skipped evaluation. */ +export function applyPolicySkipGuard(data: Record): Record { + const warnings = Array.isArray(data.warnings) ? (data.warnings as Array>) : [] + const skipped = warnings.some((w) => PLAN_SKIP_RULES.has(String(w?.rule)) || PLAN_SKIP_RULES.has(String(w?.code))) + if (!skipped) return data + const violations = Array.isArray(data.violations) ? (data.violations as unknown[]) : [] + data.allowed = false + data.policy_skipped = true + data.violations = [ + ...violations, + { rule: "policy_not_evaluated", severity: "error", message: POLICY_NOT_EVALUATED_MESSAGE }, + ] + const audit = data.audit as Record | undefined + if (audit && typeof audit === "object") audit.allowed = false + return data +} + +/** Flag a semantics result whose analysis did not run. */ +export function applySemanticsSkipGuard(data: Record): Record { + const notes = Array.isArray(data.notes) ? (data.notes as unknown[]) : [] + if (notes.some((n) => PLAN_SKIP_NOTE.test(String(n)))) { + data.skipped = true + data.skip_reason = SEMANTICS_SKIPPED_MESSAGE + } + return data +} +// altimate_change end + function toData(obj: unknown): Record { if (obj === null || obj === undefined) return {} if (typeof obj !== "object") return { value: obj } @@ -400,7 +440,7 @@ export function registerAll(): void { try { const { sql, schema } = prepareSql(params.sql, params.schema_path, params.schema_context) const raw = await core.checkPolicy(sql, schema, params.policy_json) - const data = toData(raw) + const data = applyPolicySkipGuard(toData(raw)) return ok(true, data) } catch (e) { return fail(e) @@ -412,7 +452,7 @@ export function registerAll(): void { try { const { sql, schema } = prepareSql(params.sql, params.schema_path, params.schema_context) const raw = await core.checkSemantics(sql, schema) - const data = toData(raw) + const data = applySemanticsSkipGuard(toData(raw)) return ok(true, data) } catch (e) { return fail(e) diff --git a/packages/opencode/src/altimate/tools/altimate-core-semantics.ts b/packages/opencode/src/altimate/tools/altimate-core-semantics.ts index d4691012aa..8a89875a17 100644 --- a/packages/opencode/src/altimate/tools/altimate-core-semantics.ts +++ b/packages/opencode/src/altimate/tools/altimate-core-semantics.ts @@ -34,7 +34,10 @@ export const AltimateCoreSemanticsTool = Tool.define("altimate_core_semantics", // (e.g. cartesian product). Never gate the count or title on `valid`. const issues = (data.findings ?? data.issues ?? []) as any[] const issueCount = issues.length - const error = result.error ?? data.error ?? extractSemanticsErrors(data) + // altimate_change start — a skipped analysis (no plan) is not a clean result + const error = + result.error ?? data.error ?? extractSemanticsErrors(data) ?? (data.skipped ? String(data.skip_reason) : undefined) + // altimate_change end const hasError = Boolean(error) // altimate_change start — sql quality findings for telemetry const findings: Telemetry.Finding[] = issues.map((f: any) => ({ @@ -42,7 +45,7 @@ export const AltimateCoreSemanticsTool = Tool.define("altimate_core_semantics", })) // altimate_change end return { - title: hasError ? "Semantics: ERROR" : `Semantics: ${issueCount === 0 ? "VALID" : `${issueCount} issues`}`, + title: data.skipped ? "Semantics: SKIPPED" : hasError ? "Semantics: ERROR" : `Semantics: ${issueCount === 0 ? "VALID" : `${issueCount} issues`}`, metadata: { // Semantic issues are findings, not failures — but a failed engine // call or an abstention (validation_errors) must not report success: diff --git a/packages/opencode/src/cli/cmd/check.ts b/packages/opencode/src/cli/cmd/check.ts index 1b68bbe924..197bdfed45 100644 --- a/packages/opencode/src/cli/cmd/check.ts +++ b/packages/opencode/src/cli/cmd/check.ts @@ -263,8 +263,20 @@ async function runSemantic(sql: string, file: string, schemaPath?: string): Prom if (!result.success && issues.length === 0) { return [dispatcherErrorFinding("semantic", file, result.error ?? "altimate_core.semantics failed")] } + // altimate_change start — skipped analysis (no plan) must not read as zero findings + const skippedFinding: Finding[] = result.data.skipped + ? [ + { + file, + rule: "semantic", + severity: schemaPath ? ("error" as const) : ("warning" as const), + message: String(result.data.skip_reason ?? "semantic analysis skipped (no plan available)"), + }, + ] + : [] + // altimate_change end if (issues.length > 0) { - return issues.map((f) => ({ + const issueFindings = issues.map((f) => ({ file, line: f.line as number | undefined, column: f.column as number | undefined, @@ -274,7 +286,9 @@ async function runSemantic(sql: string, file: string, schemaPath?: string): Prom message: (f.message ?? f.description ?? "") as string, suggestion: f.suggestion as string | undefined, })) + return [...skippedFinding, ...issueFindings] } + if (skippedFinding.length > 0) return skippedFinding if (result.data.valid === false) { // SemanticResult.validation_errors carries the reason the query is // unplannable — surface it instead of a bare generic message. With a diff --git a/packages/opencode/test/altimate/core-plan-skip-fail-closed.test.ts b/packages/opencode/test/altimate/core-plan-skip-fail-closed.test.ts new file mode 100644 index 0000000000..f02e074c0c --- /dev/null +++ b/packages/opencode/test/altimate/core-plan-skip-fail-closed.test.ts @@ -0,0 +1,66 @@ +import { describe, expect, test, beforeAll, afterAll } from "bun:test" +import * as Dispatcher from "../../src/altimate/native/dispatcher" +import { registerAll } from "../../src/altimate/native/altimate-core" +import { formatSemantics } from "../../src/altimate/tools/altimate-core-semantics" + +// Pins altimate-core 0.9.0: statements rewritten around table-valued functions have no +// logical plan, and the engine returns allowed:true / valid:true with no findings. The +// native handlers must report that as not evaluated, never as clean. + +beforeAll(() => { + process.env.ALTIMATE_TELEMETRY_DISABLED = "true" + registerAll() +}) +afterAll(() => { + delete process.env.ALTIMATE_TELEMETRY_DISABLED +}) + +const schema_context = { + version: "1", + dialect: "generic", + database: null, + schema_name: null, + tables: { t: { columns: [{ name: "id", type: "INT" }, { name: "name", type: "VARCHAR" }] } }, +} +const policy_json = JSON.stringify({ rules: [] }) +const TVF_QUERIES = [ + "SELECT * FROM TABLE(my_fn())", + "SELECT * FROM t, LATERAL FLATTEN(input => t.name)", + "SELECT * FROM read_csv('x')", +] + +describe("altimate_core.policy fails closed when no plan is available", () => { + for (const sql of TVF_QUERIES) { + test(`not allowed: ${sql}`, async () => { + const r = await Dispatcher.call("altimate_core.policy", { sql, policy_json, schema_context }) + expect(r.data.allowed).toBe(false) + expect(r.data.policy_skipped).toBe(true) + const violations = r.data.violations as Array<{ rule: string; message: string }> + expect(violations.some((v) => v.rule === "policy_not_evaluated")).toBe(true) + expect(violations.find((v) => v.rule === "policy_not_evaluated")?.message).toContain("treated as blocked") + }) + } + + test("a normal query is unaffected", async () => { + const r = await Dispatcher.call("altimate_core.policy", { sql: "SELECT id FROM t", policy_json, schema_context }) + expect(r.data.allowed).toBe(true) + expect(r.data.policy_skipped).toBeUndefined() + expect(r.data.violations).toEqual([]) + }) +}) + +describe("altimate_core.semantics reports skipped analysis", () => { + for (const sql of TVF_QUERIES) { + test(`skipped: ${sql}`, async () => { + const r = await Dispatcher.call("altimate_core.semantics", { sql, schema_context }) + expect(r.data.skipped).toBe(true) + expect(String(r.data.skip_reason)).toContain("semantic analysis skipped") + }) + } + + test("a normal query is unaffected", async () => { + const r = await Dispatcher.call("altimate_core.semantics", { sql: "SELECT id FROM t", schema_context }) + expect(r.data.skipped).toBeUndefined() + expect(formatSemantics(r.data)).toBe("No semantic issues found.") + }) +}) diff --git a/packages/opencode/test/cli/check-e2e.test.ts b/packages/opencode/test/cli/check-e2e.test.ts index 930c1ea42c..12352da57f 100644 --- a/packages/opencode/test/cli/check-e2e.test.ts +++ b/packages/opencode/test/cli/check-e2e.test.ts @@ -489,6 +489,43 @@ describe("check command E2E", () => { expect(j.summary.total_findings).toBe(0) }) + test("policy check reports a skipped evaluation as a blocking finding", async () => { + const file = await writeSql(tmpDir.dir, "m.sql", "SELECT * FROM TABLE(my_fn());") + const policyFile = path.join(tmpDir.dir, "policy.json") + await fs.writeFile(policyFile, JSON.stringify({ rules: [] })) + + // Shape produced by the native handler when core returns plan_unavailable (0.9.0). + setDispatcherResponse("altimate_core.policy", () => ({ + success: true, + data: { + allowed: false, + policy_skipped: true, + violations: [{ rule: "policy_not_evaluated", severity: "error", message: "policy could not be evaluated" }], + warnings: [{ rule: "plan_unavailable", message: "Policy check skipped: no plan is available." }], + }, + })) + installDispatcherMocks() + + const r = await runHandler(baseArgs({ files: [file], checks: "policy", policy: policyFile })) + const j = parseJson(r.stdout) + expect(j.summary.total_findings).toBe(1) + expect(j.summary.errors).toBe(1) + }) + + test("semantic check reports skipped analysis instead of zero findings", async () => { + const file = await writeSql(tmpDir.dir, "m.sql", "SELECT * FROM TABLE(my_fn());") + setDispatcherResponse("altimate_core.semantics", () => ({ + success: true, + data: { findings: [], valid: true, skipped: true, skip_reason: "semantic analysis skipped (no plan available)" }, + })) + installDispatcherMocks() + + const r = await runHandler(baseArgs({ files: [file], checks: "semantic" })) + const j = parseJson(r.stdout) + expect(j.summary.total_findings).toBe(1) + expect(JSON.stringify(j)).toContain("semantic analysis skipped") + }) + // --- Unknown checks --- test("warns on unknown check names", async () => { From fb1d6f97d27ecacb8c683e7eb5a73a48e2da2583 Mon Sep 17 00:00:00 2001 From: anandgupta42 Date: Sun, 18 Oct 2026 12:32:49 -0700 Subject: [PATCH 3/3] fix: report skipped semantics in `sql.analyze` instead of crediting it as evaluated `sql.analyze` called `core.checkSemantics` directly, so a table-valued-function statement (no plan, analysis skipped by altimate-core 0.9.0) still returned confidence `high` with `semantics` listed as evaluated and "no issues". - apply the same skip guard as `altimate_core.semantics` - add a semantic warning issue, drop `semantics` from `confidence_factors` and lower confidence to `medium` when skipped - add tests for a TVF statement and an unaffected normal query Co-Authored-By: Claude Opus 5.5 --- .../src/altimate/native/sql/register.ts | 21 +++++++++++++++---- .../core-plan-skip-fail-closed.test.ts | 18 ++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/packages/opencode/src/altimate/native/sql/register.ts b/packages/opencode/src/altimate/native/sql/register.ts index 8eab811850..7714f4e3a7 100644 --- a/packages/opencode/src/altimate/native/sql/register.ts +++ b/packages/opencode/src/altimate/native/sql/register.ts @@ -9,7 +9,7 @@ import * as core from "@altimateai/altimate-core" import { register } from "../dispatcher" import { prepareSql } from "../schema-resolver" -import { preprocessIff, postprocessQualify } from "../altimate-core" +import { preprocessIff, postprocessQualify, applySemanticsSkipGuard } from "../altimate-core" import { EngineCoerce } from "../engine-coerce" import type { SqlAnalyzeResult, @@ -37,7 +37,10 @@ export function registerAllSql(): void { ]) const lint = JSON.parse(JSON.stringify(lintRaw)) - const semantics = JSON.parse(JSON.stringify(semanticsRaw)) + // altimate_change start — a skipped semantic analysis (no plan) is not a clean result + const semantics = applySemanticsSkipGuard(JSON.parse(JSON.stringify(semanticsRaw))) as any + const semanticsSkipped = semantics.skipped === true + // altimate_change end // Redact raw-input echoes (multi_statement quotes the input verbatim). const safety = EngineCoerce.redactScan(JSON.parse(JSON.stringify(safetyRaw))) as any @@ -65,6 +68,16 @@ export function registerAllSql(): void { }) } + if (semanticsSkipped) { + issues.push({ + type: "semantic", + severity: "warning", + message: String(semantics.skip_reason), + recommendation: "", + confidence: "high", + }) + } + for (const t of safety.threats ?? []) { issues.push({ type: "safety", @@ -80,8 +93,8 @@ export function registerAllSql(): void { success: true, issues, issue_count: issues.length, - confidence: "high", - confidence_factors: ["lint", "semantics", "safety"], + confidence: semanticsSkipped ? "medium" : "high", + confidence_factors: semanticsSkipped ? ["lint", "safety"] : ["lint", "semantics", "safety"], } satisfies SqlAnalyzeResult } catch (e) { return { diff --git a/packages/opencode/test/altimate/core-plan-skip-fail-closed.test.ts b/packages/opencode/test/altimate/core-plan-skip-fail-closed.test.ts index f02e074c0c..d52ea04d5f 100644 --- a/packages/opencode/test/altimate/core-plan-skip-fail-closed.test.ts +++ b/packages/opencode/test/altimate/core-plan-skip-fail-closed.test.ts @@ -1,6 +1,7 @@ import { describe, expect, test, beforeAll, afterAll } from "bun:test" import * as Dispatcher from "../../src/altimate/native/dispatcher" import { registerAll } from "../../src/altimate/native/altimate-core" +import { registerAllSql } from "../../src/altimate/native/sql/register" import { formatSemantics } from "../../src/altimate/tools/altimate-core-semantics" // Pins altimate-core 0.9.0: statements rewritten around table-valued functions have no @@ -10,6 +11,7 @@ import { formatSemantics } from "../../src/altimate/tools/altimate-core-semantic beforeAll(() => { process.env.ALTIMATE_TELEMETRY_DISABLED = "true" registerAll() + registerAllSql() }) afterAll(() => { delete process.env.ALTIMATE_TELEMETRY_DISABLED @@ -64,3 +66,19 @@ describe("altimate_core.semantics reports skipped analysis", () => { expect(formatSemantics(r.data)).toBe("No semantic issues found.") }) }) + +describe("sql.analyze does not report skipped semantics as evaluated", () => { + test("TVF query: skipped issue, semantics not credited", async () => { + const r: any = await Dispatcher.call("sql.analyze", { sql: "SELECT id FROM TABLE(my_fn()) LIMIT 10", schema_context }) + expect(r.issues.some((i: any) => i.type === "semantic" && String(i.message).includes("semantic analysis skipped"))).toBe(true) + expect(r.confidence_factors).not.toContain("semantics") + expect(r.confidence).toBe("medium") + }) + + test("normal query is unaffected", async () => { + const r: any = await Dispatcher.call("sql.analyze", { sql: "SELECT id FROM t", schema_context }) + expect(r.issues.some((i: any) => i.type === "semantic")).toBe(false) + expect(r.confidence_factors).toContain("semantics") + expect(r.confidence).toBe("high") + }) +})