Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ai company
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
ai company
Commits
4a71e6b7
Commit
4a71e6b7
authored
Jun 01, 2026
by
Admin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: add integration test for budgets overview, org charts, and slug resolution
parent
6af0848f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
120 additions
and
0 deletions
+120
-0
test_agent_flow.py
backend/tests/test_agent_flow.py
+120
-0
No files found.
backend/tests/test_agent_flow.py
View file @
4a71e6b7
...
@@ -171,3 +171,123 @@ async def test_agent_wake_route_integration():
...
@@ -171,3 +171,123 @@ async def test_agent_wake_route_integration():
settings
.
openai_api_key
=
original_key
settings
.
openai_api_key
=
original_key
# Clean up dependency overrides
# Clean up dependency overrides
app
.
dependency_overrides
.
clear
()
app
.
dependency_overrides
.
clear
()
@
pytest
.
mark
.
asyncio
async
def
test_agent_slug_lookup_and_budgets_overview
():
"""Verify company org, budgets, and slug resolution endpoints work correctly."""
import
httpx
from
datetime
import
datetime
from
server
import
app
from
database
import
get_db_session
from
middleware.auth
import
get_current_user
mock_auth_user
=
MagicMock
()
mock_auth_user
.
id
=
"user_123"
async
def
mock_get_current_user
():
return
mock_auth_user
mock_session
=
AsyncMock
()
async
def
mock_get_db_session
():
yield
mock_session
from
middleware.auth
import
require_company_scope
from
schemas.common
import
CompanyScope
async
def
mock_require_company_scope
(
company_id
:
str
=
None
):
return
CompanyScope
(
company_id
=
company_id
or
"company_123"
)
app
.
dependency_overrides
[
get_current_user
]
=
mock_get_current_user
app
.
dependency_overrides
[
get_db_session
]
=
mock_get_db_session
app
.
dependency_overrides
[
require_company_scope
]
=
mock_require_company_scope
transport
=
httpx
.
ASGITransport
(
app
=
app
)
for
r
in
app
.
routes
:
print
(
"ROUTE:"
,
r
.
path
,
getattr
(
r
,
"name"
,
""
))
try
:
async
with
httpx
.
AsyncClient
(
transport
=
transport
,
base_url
=
"http://testserver"
)
as
client
:
# 1. Test /api/companies/{company_id}/org
mock_agent
=
MagicMock
()
mock_agent
.
id
=
"uuid-agent-123"
mock_agent
.
company_id
=
"company_123"
mock_agent
.
name
=
"My Coder Agent"
mock_agent
.
role
=
"coder"
mock_agent
.
status
=
"active"
mock_agent
.
reports_to
=
None
mock_agent
.
adapter_type
=
"claude"
mock_agent
.
adapter_config
=
{}
mock_agent
.
runtime_config
=
{}
mock_agent
.
budget_monthly_cents
=
0
mock_agent
.
max_concurrent_sessions
=
1
mock_agent
.
tags
=
[]
mock_agent
.
agent_metadata
=
{}
mock_agent
.
metadata
=
{}
mock_agent
.
last_heartbeat_at
=
None
mock_agent
.
created_at
=
datetime
.
utcnow
()
mock_agent
.
updated_at
=
datetime
.
utcnow
()
mock_agent
.
urlKey
=
"my-coder-agent"
mock_result_agents
=
MagicMock
()
mock_result_agents
.
scalars
.
return_value
.
all
.
return_value
=
[
mock_agent
]
mock_session
.
execute
.
return_value
=
mock_result_agents
response
=
await
client
.
get
(
"/api/companies/company_123/org"
)
print
(
"DEBUG ORG PATH: /api/companies/company_123/org, STATUS:"
,
response
.
status_code
,
"BODY:"
,
response
.
text
)
assert
response
.
status_code
==
200
org_data
=
response
.
json
()
assert
len
(
org_data
)
==
1
assert
org_data
[
0
][
"name"
]
==
"My Coder Agent"
assert
org_data
[
0
][
"id"
]
==
"uuid-agent-123"
# 2. Test slug resolution on /api/agents/{agent_id}
# Slug "my-coder-agent" -> resolve to UUID
# First select query will be UUID check (returns None), second is all agents (returns list)
mock_uuid_check_result
=
MagicMock
()
mock_uuid_check_result
.
scalar_one_or_none
.
return_value
=
None
mock_all_agents_result
=
MagicMock
()
mock_all_agents_result
.
scalars
.
return_value
.
all
.
return_value
=
[
mock_agent
]
mock_session
.
execute
.
side_effect
=
[
mock_uuid_check_result
,
mock_all_agents_result
]
response
=
await
client
.
get
(
"/api/agents/my-coder-agent?company_id=company_123"
)
assert
response
.
status_code
==
200
agent_data
=
response
.
json
()
assert
agent_data
[
"id"
]
==
"uuid-agent-123"
assert
agent_data
[
"name"
]
==
"My Coder Agent"
assert
agent_data
[
"urlKey"
]
==
"my-coder-agent"
# 3. Test GET /api/companies/{company_id}/budgets/overview
mock_policy
=
MagicMock
()
mock_policy
.
id
=
"policy-1"
mock_policy
.
company_id
=
"company_123"
mock_policy
.
name
=
"Test Agent Budget"
mock_policy
.
scope
=
"agent"
mock_policy
.
scope_id
=
"uuid-agent-123"
mock_policy
.
monthly_limit_cents
=
5000
mock_policy
.
current_spend_cents
=
1200
mock_policy
.
is_enabled
=
True
mock_policy
.
created_at
=
datetime
.
utcnow
()
mock_policies_result
=
MagicMock
()
mock_policies_result
.
scalars
.
return_value
.
all
.
return_value
=
[
mock_policy
]
mock_count_result
=
MagicMock
()
mock_count_result
.
scalar
.
return_value
=
1
mock_session
.
execute
.
side_effect
=
[
mock_policies_result
,
mock_count_result
,
mock_count_result
]
response
=
await
client
.
get
(
"/api/companies/company_123/budgets/overview"
)
assert
response
.
status_code
==
200
overview_data
=
response
.
json
()
assert
overview_data
[
"companyId"
]
==
"company_123"
assert
len
(
overview_data
[
"policies"
])
==
1
assert
overview_data
[
"policies"
][
0
][
"observedAmount"
]
==
1200
assert
overview_data
[
"policies"
][
0
][
"amount"
]
==
5000
assert
overview_data
[
"pausedAgentCount"
]
==
1
finally
:
app
.
dependency_overrides
.
clear
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment