Skip to content

Commit 3e5d531

Browse files
committed
refactor: read workspace id from HOTDATA_WORKSPACE_ID only
Drop the legacy HOTDATA_WORKSPACE fallback so runtime workspace selection matches the canonical env var used across adapters.
1 parent 161a142 commit 3e5d531

3 files changed

Lines changed: 9 additions & 19 deletions

File tree

CONTRACT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Adapters should import from `hotdata_runtime` and treat this surface as the stab
6363
- `default_api_key()` reads `HOTDATA_API_KEY`.
6464
- `default_host()` reads `HOTDATA_API_URL` (default: `https://api.hotdata.dev`) and normalizes it.
6565
- `default_session_id()` reads `HOTDATA_SANDBOX`.
66+
- `explicit_workspace_id()` reads `HOTDATA_WORKSPACE_ID` (workspace public id).
6667
- `pick_workspace()` prefers explicit env workspace, then active workspace, then first workspace.
6768
- `resolve_workspace_selection()` is the canonical workspace selection algorithm. It returns `WorkspaceSelection` with selected workspace id, selection source, and discovered workspaces when auto-selected.
6869

hotdata_runtime/env.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ def default_api_key() -> str:
2323

2424

2525
def explicit_workspace_id() -> str | None:
26-
return os.environ.get("HOTDATA_WORKSPACE") or os.environ.get(
27-
"HOTDATA_WORKSPACE_ID"
28-
)
26+
return os.environ.get("HOTDATA_WORKSPACE_ID")
2927

3028

3129
def default_host() -> str:

tests/test_client.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def test_normalize_host(raw: str, expected: str):
2525
assert normalize_host(raw) == expected
2626

2727

28-
def test_pick_workspace_prefers_env(monkeypatch: pytest.MonkeyPatch):
29-
monkeypatch.setenv("HOTDATA_WORKSPACE", "ws_explicit")
28+
def test_pick_workspace_prefers_workspace_id_env(monkeypatch: pytest.MonkeyPatch):
29+
monkeypatch.setenv("HOTDATA_WORKSPACE_ID", "ws_explicit")
3030
assert pick_workspace("k", "https://api.hotdata.dev", None) == "ws_explicit"
3131

3232

3333
def test_resolve_workspace_selection_prefers_env_without_listing(
3434
monkeypatch: pytest.MonkeyPatch,
3535
):
36-
monkeypatch.setenv("HOTDATA_WORKSPACE", "ws_explicit")
36+
monkeypatch.setenv("HOTDATA_WORKSPACE_ID", "ws_explicit")
3737
with patch("hotdata_runtime.env.list_workspaces") as listing:
3838
resolved = resolve_workspace_selection(
3939
"k", "https://api.hotdata.dev", None
@@ -44,14 +44,8 @@ def test_resolve_workspace_selection_prefers_env_without_listing(
4444
assert resolved.workspaces == []
4545

4646

47-
def test_pick_workspace_prefers_workspace_id_env(monkeypatch: pytest.MonkeyPatch):
48-
monkeypatch.delenv("HOTDATA_WORKSPACE", raising=False)
49-
monkeypatch.setenv("HOTDATA_WORKSPACE_ID", "ws_from_id")
50-
assert pick_workspace("k", "https://api.hotdata.dev", None) == "ws_from_id"
51-
5247

5348
def test_pick_workspace_chooses_first_active(monkeypatch: pytest.MonkeyPatch):
54-
monkeypatch.delenv("HOTDATA_WORKSPACE", raising=False)
5549
monkeypatch.delenv("HOTDATA_WORKSPACE_ID", raising=False)
5650

5751
items = [
@@ -67,7 +61,6 @@ def test_pick_workspace_chooses_first_active(monkeypatch: pytest.MonkeyPatch):
6761

6862

6963
def test_pick_workspace_falls_back_to_first(monkeypatch: pytest.MonkeyPatch):
70-
monkeypatch.delenv("HOTDATA_WORKSPACE", raising=False)
7164
monkeypatch.delenv("HOTDATA_WORKSPACE_ID", raising=False)
7265

7366
items = [
@@ -82,7 +75,6 @@ def test_pick_workspace_falls_back_to_first(monkeypatch: pytest.MonkeyPatch):
8275

8376

8477
def test_resolve_workspace_selection_source_first(monkeypatch: pytest.MonkeyPatch):
85-
monkeypatch.delenv("HOTDATA_WORKSPACE", raising=False)
8678
monkeypatch.delenv("HOTDATA_WORKSPACE_ID", raising=False)
8779
items = [
8880
SimpleNamespace(public_id="ws_1", active=False),
@@ -102,7 +94,6 @@ def test_resolve_workspace_selection_source_first(monkeypatch: pytest.MonkeyPatc
10294
def test_resolve_workspace_selection_returns_workspaces_and_source(
10395
monkeypatch: pytest.MonkeyPatch,
10496
):
105-
monkeypatch.delenv("HOTDATA_WORKSPACE", raising=False)
10697
monkeypatch.delenv("HOTDATA_WORKSPACE_ID", raising=False)
10798

10899
items = [
@@ -224,14 +215,14 @@ class FakeRunsApi:
224215
def __init__(self):
225216
self.kwargs = None
226217

227-
def list_query_runs(self, *, limit: int, offset: int):
228-
self.kwargs = {"limit": limit, "offset": offset}
218+
def list_query_runs(self, *, limit: int):
219+
self.kwargs = {"limit": limit}
229220
return listing
230221

231222
fake_runs = FakeRunsApi()
232223
with patch.object(client, "query_runs", return_value=fake_runs):
233-
out = client.list_run_history(limit=5, offset=3)
224+
out = client.list_run_history(limit=5)
234225
assert [r.query_run_id for r in out] == ["run_1"]
235226
assert out[0].execution_time_ms == 7
236227
assert out[0].to_dict()["result_id"] == "res_1"
237-
assert fake_runs.kwargs == {"limit": 5, "offset": 3}
228+
assert fake_runs.kwargs == {"limit": 5}

0 commit comments

Comments
 (0)