From 3c77c5e8537f8315f671bdc8e57f9174bb2a226f Mon Sep 17 00:00:00 2001 From: Aniket Kulkarni Date: Thu, 26 Mar 2026 14:11:13 -0400 Subject: [PATCH] feat: prepend breadcrumb comment to all SQL queries (DX-117497) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All SQL submitted through dremio-cli now carries a leading comment: /* dremio-cli: submitter=cli */ This enables backend query attribution — the Jobs service can detect queries originating from the CLI, consistent with how dremio-mcp uses /* dremioai: submitter=agent */. The breadcrumb is added in the single submit_sql() method in client.py, so every command that runs SQL (query, job, schema, folder, reflection) gets it automatically. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/drs/client.py | 2 +- tests/test_client.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/drs/client.py b/src/drs/client.py index e45ea69..c487852 100644 --- a/src/drs/client.py +++ b/src/drs/client.py @@ -164,7 +164,7 @@ async def delete_project(self, project_id: str) -> dict: async def submit_sql(self, sql: str, context: list[str] | None = None) -> dict: """Submit a SQL query. Returns job metadata including job_id.""" - body: dict[str, Any] = {"sql": sql} + body: dict[str, Any] = {"sql": f"/* dremio-cli: submitter=cli */ {sql}"} if context: body["context"] = context return await self._post(self._v0("/sql"), json=body) diff --git a/tests/test_client.py b/tests/test_client.py index ec4bd00..93114c6 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -17,6 +17,7 @@ from __future__ import annotations +import httpx import pytest from drs.auth import DrsConfig @@ -100,3 +101,41 @@ def test_auth_header(self, client: DremioClient) -> None: def test_content_type(self, client: DremioClient) -> None: assert client._client.headers["content-type"] == "application/json" + + +class TestSQLBreadcrumb: + @pytest.mark.asyncio + async def test_submit_sql_prepends_breadcrumb(self, client: DremioClient) -> None: + """SQL submitted via the client must carry the dremio-cli breadcrumb comment.""" + captured: dict = {} + + async def _capture(request: httpx.Request) -> httpx.Response: + import json + + captured["body"] = json.loads(request.content) + return httpx.Response(200, json={"id": "job-1"}) + + client._client = httpx.AsyncClient(transport=httpx.MockTransport(_capture)) + + await client.submit_sql("SELECT 1") + + assert captured["body"]["sql"] == "/* dremio-cli: submitter=cli */ SELECT 1" + + @pytest.mark.asyncio + async def test_submit_sql_breadcrumb_with_context(self, client: DremioClient) -> None: + """Breadcrumb should be present even when a schema context is provided.""" + captured: dict = {} + + async def _capture(request: httpx.Request) -> httpx.Response: + import json + + captured["body"] = json.loads(request.content) + return httpx.Response(200, json={"id": "job-2"}) + + client._client = httpx.AsyncClient(transport=httpx.MockTransport(_capture)) + + await client.submit_sql("SELECT * FROM orders", context=["myspace"]) + + assert captured["body"]["sql"].startswith("/* dremio-cli: submitter=cli */") + assert "SELECT * FROM orders" in captured["body"]["sql"] + assert captured["body"]["context"] == ["myspace"]