feat: add label parameter to add_column and modify_column tools

Allow setting a human-readable display label for columns, separate from
the column_id used in formulas and API calls. The label defaults to the
column_id if not provided.
This commit is contained in:
2026-01-26 15:18:11 -05:00
parent d4e793224b
commit 33bb464102
5 changed files with 94 additions and 5 deletions

View File

@@ -155,6 +155,27 @@ async def test_add_column(client, httpx_mock: HTTPXMock):
col_id = await client.add_column("Table1", "NewCol", "Text", formula=None)
assert col_id == "NewCol"
request = httpx_mock.get_request()
import json
payload = json.loads(request.content)
assert payload == {"columns": [{"id": "NewCol", "fields": {"type": "Text"}}]}
@pytest.mark.asyncio
async def test_add_column_with_label(client, httpx_mock: HTTPXMock):
httpx_mock.add_response(
url="https://grist.example.com/api/docs/abc123/tables/Table1/columns",
method="POST",
json={"columns": [{"id": "first_name"}]},
)
col_id = await client.add_column("Table1", "first_name", "Text", label="First Name")
assert col_id == "first_name"
request = httpx_mock.get_request()
import json
payload = json.loads(request.content)
assert payload == {"columns": [{"id": "first_name", "fields": {"type": "Text", "label": "First Name"}}]}
@pytest.mark.asyncio
@@ -169,6 +190,22 @@ async def test_modify_column(client, httpx_mock: HTTPXMock):
await client.modify_column("Table1", "Amount", type="Int", formula="$Price * $Qty")
@pytest.mark.asyncio
async def test_modify_column_with_label(client, httpx_mock: HTTPXMock):
httpx_mock.add_response(
url="https://grist.example.com/api/docs/abc123/tables/Table1/columns",
method="PATCH",
json={},
)
await client.modify_column("Table1", "Col1", label="Column One")
request = httpx_mock.get_request()
import json
payload = json.loads(request.content)
assert payload == {"columns": [{"id": "Col1", "fields": {"label": "Column One"}}]}
@pytest.mark.asyncio
async def test_delete_column(client, httpx_mock: HTTPXMock):
httpx_mock.add_response(

View File

@@ -81,6 +81,25 @@ async def test_add_column(auth, mock_client):
)
assert result == {"column_id": "NewCol"}
mock_client.add_column.assert_called_once_with(
"Table1", "NewCol", "Text", formula=None, label=None
)
@pytest.mark.asyncio
async def test_add_column_with_label(auth, mock_client):
agent = auth.authenticate("schema-token")
result = await add_column(
agent, auth, "budget", "Table1", "first_name", "Text",
label="First Name",
client=mock_client,
)
assert result == {"column_id": "NewCol"}
mock_client.add_column.assert_called_once_with(
"Table1", "first_name", "Text", formula=None, label="First Name"
)
@pytest.mark.asyncio
@@ -95,6 +114,25 @@ async def test_modify_column(auth, mock_client):
)
assert result == {"modified": True}
mock_client.modify_column.assert_called_once_with(
"Table1", "Col1", type="Int", formula="$A + $B", label=None
)
@pytest.mark.asyncio
async def test_modify_column_with_label(auth, mock_client):
agent = auth.authenticate("schema-token")
result = await modify_column(
agent, auth, "budget", "Table1", "Col1",
label="Column One",
client=mock_client,
)
assert result == {"modified": True}
mock_client.modify_column.assert_called_once_with(
"Table1", "Col1", type=None, formula=None, label="Column One"
)
@pytest.mark.asyncio