Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions services/chat_with_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async def chat_with_agent(
tools=tools,
model_id=current_model,
usage_id=usage_id,
created_by=f"{base_args['sender_id']}:{base_args['sender_name']}",
)
break

Expand Down
2 changes: 2 additions & 0 deletions services/claude/chat_with_claude.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def chat_with_claude(
tools: list[ToolUnionParam],
model_id: ClaudeModelId,
usage_id: int,
created_by: str,
):
# https://docs.anthropic.com/en/api/client-sdks
# Apply message optimization functions to save tokens
Expand Down Expand Up @@ -131,6 +132,7 @@ def chat_with_claude(
output_message=assistant_message,
output_tokens=token_output,
response_time_ms=response_time_ms,
created_by=created_by,
)

return (
Expand Down
4 changes: 4 additions & 0 deletions services/claude/test_chat_with_claude.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_chat_with_claude_success(mock_claude, mock_insert_llm_request):
tools=tools,
model_id=ClaudeModelId.SONNET_4_6,
usage_id=123,
created_by="4:test-user",
)

assistant_message, tool_calls, token_input, token_output = result
Expand Down Expand Up @@ -84,6 +85,7 @@ def test_chat_with_claude_with_tool_use(mock_claude, mock_insert_llm_request):
tools=tools,
model_id=ClaudeModelId.SONNET_4_6,
usage_id=456,
created_by="4:test-user",
)

_, tool_calls, _, _ = result
Expand Down Expand Up @@ -111,6 +113,7 @@ def test_chat_with_claude_no_usage_response(mock_claude, mock_insert_llm_request
tools=[],
model_id=ClaudeModelId.SONNET_4_6,
usage_id=789,
created_by="4:test-user",
)

_, _, _, token_output = result
Expand Down Expand Up @@ -145,6 +148,7 @@ def test_chat_with_claude_calls_optimization_functions(
tools=[],
model_id=ClaudeModelId.SONNET_4_6,
usage_id=101,
created_by="4:test-user",
)

mock_remove_outdated_apply_diff_to_file_attempts_and_results.assert_called_once()
19 changes: 16 additions & 3 deletions services/supabase/coverages/test_update_issue_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ def test_update_issue_url_success(self, mock_supabase_success):
repo_id=repo_id,
file_path=file_path,
github_issue_url=github_issue_url,
updated_by="system",
)

# Assert
mock_supabase.table.assert_called_once_with("coverages")
mock_table.update.assert_called_once_with(
{"github_issue_url": github_issue_url}
{"github_issue_url": github_issue_url, "updated_by": "system"}
)
mock_table.eq.assert_any_call("repo_id", repo_id)
mock_table.eq.assert_any_call("full_path", file_path)
Expand All @@ -82,12 +83,13 @@ def test_update_issue_url_with_empty_response(self, mock_supabase_empty_response
repo_id=repo_id,
file_path=file_path,
github_issue_url=github_issue_url,
updated_by="system",
)

# Assert
mock_supabase.table.assert_called_once_with("coverages")
mock_table.update.assert_called_once_with(
{"github_issue_url": github_issue_url}
{"github_issue_url": github_issue_url, "updated_by": "system"}
)
mock_table.eq.assert_any_call("repo_id", repo_id)
mock_table.eq.assert_any_call("full_path", file_path)
Expand All @@ -108,6 +110,7 @@ def test_update_issue_url_with_zero_repo_id(self, mock_supabase_success):
repo_id=repo_id,
file_path=file_path,
github_issue_url=github_issue_url,
updated_by="system",
)

# Assert
Expand All @@ -128,6 +131,7 @@ def test_update_issue_url_with_negative_repo_id(self, mock_supabase_success):
repo_id=repo_id,
file_path=file_path,
github_issue_url=github_issue_url,
updated_by="system",
)

# Assert
Expand All @@ -148,6 +152,7 @@ def test_update_issue_url_with_empty_file_path(self, mock_supabase_success):
repo_id=repo_id,
file_path=file_path,
github_issue_url=github_issue_url,
updated_by="system",
)

# Assert
Expand All @@ -168,10 +173,13 @@ def test_update_issue_url_with_empty_github_url(self, mock_supabase_success):
repo_id=repo_id,
file_path=file_path,
github_issue_url=github_issue_url,
updated_by="system",
)

# Assert
mock_table.update.assert_called_once_with({"github_issue_url": ""})
mock_table.update.assert_called_once_with(
{"github_issue_url": "", "updated_by": "system"}
)
assert result == [
{"id": 1, "github_issue_url": "https://github.com/owner/repo/issues/123"}
]
Expand All @@ -190,6 +198,7 @@ def test_update_issue_url_with_long_file_path(self, mock_supabase_success):
repo_id=repo_id,
file_path=file_path,
github_issue_url=github_issue_url,
updated_by="system",
)

# Assert
Expand All @@ -212,6 +221,7 @@ def test_update_issue_url_with_special_characters_in_path(
repo_id=repo_id,
file_path=file_path,
github_issue_url=github_issue_url,
updated_by="system",
)

# Assert
Expand All @@ -232,6 +242,7 @@ def test_update_issue_url_with_large_repo_id(self, mock_supabase_success):
repo_id=repo_id,
file_path=file_path,
github_issue_url=github_issue_url,
updated_by="system",
)

# Assert
Expand All @@ -252,6 +263,7 @@ def test_update_issue_url_exception_handling(self):
repo_id=123456,
file_path="src/main.py",
github_issue_url="https://github.com/owner/repo/issues/123",
updated_by="system",
)

# Assert - The handle_exceptions decorator should return None on error
Expand All @@ -268,6 +280,7 @@ def test_update_issue_url_method_chaining(self, mock_supabase_success):
repo_id=123456,
file_path="src/main.py",
github_issue_url="https://github.com/owner/repo/issues/123",
updated_by="system",
)

# Assert - Verify the method chaining sequence
Expand Down
8 changes: 6 additions & 2 deletions services/supabase/coverages/update_issue_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

@handle_exceptions(default_return_value=None, raise_on_error=False)
def update_issue_url(
owner_id: int, repo_id: int, file_path: str, github_issue_url: str
owner_id: int,
repo_id: int,
file_path: str,
github_issue_url: str,
updated_by: str,
):
result = (
supabase.table("coverages")
.update({"github_issue_url": github_issue_url})
.update({"github_issue_url": github_issue_url, "updated_by": updated_by})
.eq("owner_id", owner_id)
.eq("repo_id", repo_id)
.eq("full_path", file_path)
Expand Down
1 change: 1 addition & 0 deletions services/supabase/create_user_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def create_user_request(
repo_name=repo_name,
pr_number=pr_number,
user_id=user_id,
user_name=user_name,
installation_id=installation_id,
source=source,
trigger=trigger,
Expand Down
3 changes: 3 additions & 0 deletions services/supabase/installations/insert_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ def insert_installation(
owner_id: int,
owner_type: str,
owner_name: str,
user_id: int,
user_name: str,
):
supabase.table(table_name="installations").insert(
json={
"installation_id": installation_id,
"owner_id": owner_id,
"owner_type": owner_type,
"owner_name": owner_name,
"created_by": f"{user_id}:{user_name}",
}
).execute()
35 changes: 33 additions & 2 deletions services/supabase/installations/test_insert_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def valid_installation_data():
"owner_id": TEST_OWNER_ID,
"owner_type": TEST_OWNER_TYPE,
"owner_name": TEST_OWNER_NAME,
"user_id": 11111,
"user_name": "test-sender",
}


Expand Down Expand Up @@ -70,6 +72,8 @@ def test_insert_installation_with_minimal_data(mock_supabase_client):
"owner_id": 67890,
"owner_type": "User",
"owner_name": "test-user",
"user_id": 11111,
"user_name": "test-sender",
}

result = insert_installation(**minimal_data)
Expand All @@ -94,6 +98,8 @@ def test_insert_installation_with_organization_owner(mock_supabase_client):
"owner_id": 11111,
"owner_type": "Organization",
"owner_name": "test-org",
"user_id": 22222,
"user_name": "test-sender",
}

result = insert_installation(**org_data)
Expand Down Expand Up @@ -125,6 +131,8 @@ def test_insert_installation_with_various_data_types(
owner_id=owner_id,
owner_type=owner_type,
owner_name=owner_name,
user_id=11111,
user_name="test-sender",
)

assert result is None
Expand All @@ -145,6 +153,8 @@ def test_insert_installation_supabase_chain_calls(mock_supabase_client):
owner_id=TEST_OWNER_ID,
owner_type=TEST_OWNER_TYPE,
owner_name=TEST_OWNER_NAME,
user_id=11111,
user_name="test-sender",
)

# Verify the method chain: supabase.table().insert().execute()
Expand All @@ -168,8 +178,15 @@ def test_insert_installation_function_signature():
sig = inspect.signature(insert_installation)

# Assert parameter count and names
assert len(sig.parameters) == 4
expected_params = ["installation_id", "owner_id", "owner_type", "owner_name"]
assert len(sig.parameters) == 6
expected_params = [
"installation_id",
"owner_id",
"owner_type",
"owner_name",
"user_id",
"user_name",
]
for param in expected_params:
assert param in sig.parameters

Expand All @@ -178,6 +195,8 @@ def test_insert_installation_function_signature():
assert sig.parameters["owner_id"].annotation is int
assert sig.parameters["owner_type"].annotation is str
assert sig.parameters["owner_name"].annotation is str
assert sig.parameters["user_id"].annotation is int
assert sig.parameters["user_name"].annotation is str


def test_insert_installation_with_supabase_exception():
Expand All @@ -197,6 +216,8 @@ def test_insert_installation_with_supabase_exception():
owner_id=TEST_OWNER_ID,
owner_type=TEST_OWNER_TYPE,
owner_name=TEST_OWNER_NAME,
user_id=11111,
user_name="test-sender",
)


Expand Down Expand Up @@ -225,6 +246,8 @@ def test_insert_installation_with_http_error():
owner_id=TEST_OWNER_ID,
owner_type=TEST_OWNER_TYPE,
owner_name=TEST_OWNER_NAME,
user_id=11111,
user_name="test-sender",
)


Expand All @@ -246,6 +269,8 @@ def test_insert_installation_with_special_characters_in_owner_name(
owner_id=TEST_OWNER_ID,
owner_type=TEST_OWNER_TYPE,
owner_name=owner_name,
user_id=11111,
user_name="test-sender",
)

# Verify the special characters are preserved
Expand All @@ -267,6 +292,8 @@ def test_insert_installation_with_large_ids(mock_supabase_client):
owner_id=large_owner_id,
owner_type=TEST_OWNER_TYPE,
owner_name=TEST_OWNER_NAME,
user_id=11111,
user_name="test-sender",
)

insert_call_args = mock_supabase_client.table.return_value.insert.call_args
Expand All @@ -288,6 +315,8 @@ def test_insert_installation_with_empty_owner_name(mock_supabase_client):
owner_id=TEST_OWNER_ID,
owner_type=TEST_OWNER_TYPE,
owner_name="",
user_id=11111,
user_name="test-sender",
)

insert_call_args = mock_supabase_client.table.return_value.insert.call_args
Expand All @@ -306,6 +335,8 @@ def test_insert_installation_with_different_owner_types(mock_supabase_client):
owner_id=TEST_OWNER_ID,
owner_type=owner_type,
owner_name=TEST_OWNER_NAME,
user_id=11111,
user_name="test-sender",
)

insert_call_args = mock_supabase_client.table.return_value.insert.call_args
Expand Down
2 changes: 1 addition & 1 deletion services/supabase/llm_requests/clear_old_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def clear_old_content(retention_days: int = 14):
ids = [row["id"] for row in batch.data]

supabase.table("llm_requests").update(
{"input_content": "", "output_content": ""}
{"input_content": "", "output_content": "", "updated_by": "system"}
).in_("id", ids).execute()

total_cleared += len(ids)
Expand Down
2 changes: 1 addition & 1 deletion services/supabase/llm_requests/insert_llm_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def insert_llm_request(
input_tokens: int,
output_message: MessageParam,
output_tokens: int,
created_by: str,
response_time_ms: int | None = None,
error_message: str | None = None,
created_by: str | None = None,
):
# Convert messages to JSON strings
input_content = json.dumps(input_messages, ensure_ascii=False)
Expand Down
4 changes: 3 additions & 1 deletion services/supabase/llm_requests/test_clear_old_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def test_clear_old_content_single_batch(mock_datetime, mock_supabase):
mock_select.lt.assert_called_with("created_at", expected_cutoff)
mock_lt_select.neq.assert_called_with("input_content", "")
mock_neq.limit.assert_called_with(SUPABASE_BATCH_SIZE)
mock_table.update.assert_called_with({"input_content": "", "output_content": ""})
mock_table.update.assert_called_with(
{"input_content": "", "output_content": "", "updated_by": "system"}
)
mock_update.in_.assert_called_with("id", [1, 2, 3])


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_insert_llm_request_database_error(mock_supabase):
input_tokens=10,
output_message={"role": "assistant", "content": "response"},
output_tokens=5,
created_by="4:test-user",
)

assert result is None
Loading