Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

feat: initial work on endpoints for creating/updating workspace config #1107

Merged
merged 23 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7cd8ec5
feat: initial work on endpoints for creating/updating
alex-mcgovern Feb 19, 2025
b0141ab
Merge branch 'main' of github.com:stacklok/codegate into feat/configu…
alex-mcgovern Feb 19, 2025
57ec255
fix: return newly created `FullWorkspace` from POST /api/v1/workspaces
alex-mcgovern Feb 19, 2025
cd83f56
formatting
alex-mcgovern Feb 19, 2025
efbfa64
test: create workspace with config happy path
alex-mcgovern Feb 19, 2025
7e91e5e
Merge branch 'main' of github.com:stacklok/codegate into feat/configu…
alex-mcgovern Feb 19, 2025
358f7e5
Merge branch 'main' of github.com:stacklok/codegate into feat/configu…
alex-mcgovern Feb 20, 2025
af7251d
1 db per test
alex-mcgovern Feb 20, 2025
b87c276
test: basic happy path test for create/update workspace config
alex-mcgovern Feb 21, 2025
033e16b
Merge branch 'main' of github.com:stacklok/codegate into feat/configu…
alex-mcgovern Feb 21, 2025
37f7e78
fix failing test
alex-mcgovern Feb 21, 2025
56cc0de
chore: fmt pass
alex-mcgovern Feb 21, 2025
1a69daf
fix: internal server error when no config passed
alex-mcgovern Feb 21, 2025
7de81b5
tidy up
alex-mcgovern Feb 21, 2025
36a9551
test: more integration tests
alex-mcgovern Mar 4, 2025
2a50d9f
chore: tidy ups
alex-mcgovern Mar 4, 2025
76bb197
Merge branch 'main' of github.com:stacklok/codegate into feat/configu…
alex-mcgovern Mar 4, 2025
3b4787d
chore: revert openapi changes
alex-mcgovern Mar 4, 2025
d329538
lint fixes
alex-mcgovern Mar 4, 2025
bb4f838
Merge branch 'main' into feat/configure-workspace-endpoint
alex-mcgovern Mar 4, 2025
e5eb6b4
remove manual rollbacks, ensure re-raising all exceptions
alex-mcgovern Mar 4, 2025
7bcab23
Merge branch 'main' of github.com:stacklok/codegate into feat/configu…
alex-mcgovern Mar 4, 2025
baa7aa6
Merge branch 'main' into feat/configure-workspace-endpoint
alex-mcgovern Mar 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/codegate/muxing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MuxRule(pydantic.BaseModel):
def try_from_db_model(cls, db_model: DbMuxRule) -> "MuxRule":
try:
return cls(
provider_name=db_model.provider_endpoint_name,
provider_name=None,
provider_id=db_model.provider_endpoint_id,
model=db_model.provider_model_name,
matcher_type=MuxMatcherType(db_model.matcher_type),
Expand Down
60 changes: 60 additions & 0 deletions tests/api/test_v1_workspaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from unittest.mock import MagicMock
from uuid import uuid4 as uuid

import httpx
import pytest
from httpx import AsyncClient

from codegate.pipeline.factory import PipelineFactory
from codegate.server import init_app


@pytest.fixture
def mock_pipeline_factory():
"""Create a mock pipeline factory."""
mock_factory = MagicMock(spec=PipelineFactory)
# Mock the methods that are called on the pipeline factory
mock_factory.create_input_pipeline.return_value = MagicMock()
mock_factory.create_fim_pipeline.return_value = MagicMock()
mock_factory.create_output_pipeline.return_value = MagicMock()
mock_factory.create_fim_output_pipeline.return_value = MagicMock()
return mock_factory


@pytest.mark.asyncio
async def test_create_workspace_happy_path(mock_pipeline_factory) -> None:
"""Test creating a workspace (happy path)."""
app = init_app(mock_pipeline_factory)

name: str = str(uuid())
custom_instructions: str = "Respond to every request in iambic pentameter"
muxing_rules = [
{
"provider_name": None,
"provider_id": "0653607e-bf47-42d8-9a9d-86cdca3cf19f",
"model": "deepseek-r1:1.5b",
"matcher": "*.ts",
"matcher_type": "filename_match",
},
{
"provider_name": None,
"provider_id": "0653607e-bf47-42d8-9a9d-86cdca3cf19f",
"model": "deepseek-r1:1.5b",
"matcher_type": "catch_all",
"matcher": "",
},
]

payload = {
"name": name,
"config": {"custom_instructions": custom_instructions, "muxing_rules": muxing_rules},
}
async with AsyncClient(transport=httpx.ASGITransport(app=app), base_url="http://test") as ac:
response = await ac.post("/api/v1/workspaces", json=payload)
assert response.status_code == 201
response_body = response.json()
print(response_body["config"]["muxing_rules"])

assert response_body["name"] == name
assert response_body["config"]["custom_instructions"] == custom_instructions
assert response_body["config"]["muxing_rules"] == muxing_rules
Loading