Skip to content

Commit 405f986

Browse files
committed
fix: change the default save path of evalset file
1 parent 49ba1be commit 405f986

File tree

4 files changed

+85
-4
lines changed

4 files changed

+85
-4
lines changed

tests/test_misc.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
import sys
17+
import types
18+
19+
from veadk.utils.misc import get_agents_dir
20+
21+
22+
class GetAgentsDirTest:
23+
def test_get_agents_dir_from_main_file(monkeypatch):
24+
"""
25+
Case 1: __main__.__file__ exists (common in CLI or uv run environments)
26+
"""
27+
fake_main = types.SimpleNamespace(__file__="/tmp/project/testapp/agent.py")
28+
monkeypatch.setitem(sys.modules, "__main__", fake_main)
29+
30+
result = get_agents_dir()
31+
assert result == "/tmp/project"
32+
33+
def test_get_agents_dir_from_sys_argv(monkeypatch):
34+
"""
35+
Case 2: Fallback to sys.argv[0]
36+
"""
37+
fake_main = types.SimpleNamespace()
38+
monkeypatch.setitem(sys.modules, "__main__", fake_main)
39+
monkeypatch.setattr(sys, "argv", ["/tmp/project/testapp/agent.py"])
40+
41+
result = get_agents_dir()
42+
assert result == "/tmp/project"
43+
44+
def test_get_agents_dir_from_cwd(monkeypatch, tmp_path):
45+
"""
46+
Case 3: Fallback to current working directory (REPL or no file context)
47+
"""
48+
fake_main = types.SimpleNamespace()
49+
monkeypatch.setitem(sys.modules, "__main__", fake_main)
50+
monkeypatch.setattr(sys, "argv", [])
51+
52+
fake_cwd = tmp_path / "some_dir"
53+
fake_cwd.mkdir()
54+
55+
monkeypatch.setattr(os, "getcwd", lambda: str(fake_cwd))
56+
result = get_agents_dir()
57+
58+
# should return the parent of fake_cwd
59+
assert result == str(tmp_path)

tests/test_runtime_data_collecting.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import json
1616
import os
17+
import uuid
1718

1819
import pytest
1920
from utils import generate_events, generate_session
@@ -25,7 +26,7 @@
2526
USER_ID = "user"
2627
SESSION_ID = "session"
2728

28-
EVAL_SET_ID = "temp_unittest"
29+
EVAL_SET_ID = "temp_unittest" + uuid.uuid4().hex
2930

3031

3132
@pytest.mark.asyncio
@@ -46,7 +47,7 @@ async def test_runtime_data_collecting():
4647
recorder = EvalSetRecorder(session_service=session_service, eval_set_id=EVAL_SET_ID)
4748
dump_path = await recorder.dump(APP_NAME, USER_ID, SESSION_ID)
4849

49-
assert dump_path == f"/tmp/{APP_NAME}/{recorder.eval_set_id}.evalset.json"
50+
# assert dump_path == f"/tmp/{APP_NAME}/{recorder.eval_set_id}.evalset.json"
5051
assert os.path.exists(dump_path) and os.path.isfile(dump_path)
5152
assert os.path.getsize(dump_path) > 0
5253

veadk/evaluation/eval_set_recorder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from google.adk.sessions import BaseSessionService
2222

2323
from veadk.utils.logger import get_logger
24-
from veadk.utils.misc import formatted_timestamp, get_temp_dir
24+
from veadk.utils.misc import formatted_timestamp, get_agents_dir
2525

2626
logger = get_logger(__name__)
2727

@@ -53,7 +53,7 @@ def __init__(
5353
Raises:
5454
ValueError: If eval_set_id is invalid.
5555
"""
56-
super().__init__(agents_dir=get_temp_dir())
56+
super().__init__(agents_dir=get_agents_dir())
5757
self.eval_set_id = eval_set_id if eval_set_id != "" else "default"
5858
self.session_service: BaseSessionService = session_service
5959

veadk/utils/misc.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import requests
2424
from yaml import safe_load
25+
import __main__
2526

2627

2728
def read_file(file_path):
@@ -166,3 +167,23 @@ def get_temp_dir():
166167
else:
167168
# Non-Windows systems (macOS, Linux, etc.) uniformly return /tmp
168169
return "/tmp"
170+
171+
172+
def get_agents_dir():
173+
"""
174+
Get the directory of the currently executed entry script.
175+
176+
Returns:
177+
str: The agents directory (parent directory of the app)
178+
"""
179+
# Try using __main__.__file__ (works for most CLI scripts and uv run environments)
180+
if hasattr(__main__, "__file__"):
181+
full_path = os.path.dirname(os.path.abspath(__main__.__file__))
182+
# Fallback to sys.argv[0] (usually gives the entry script path)
183+
elif len(sys.argv) > 0 and sys.argv[0]:
184+
full_path = os.path.dirname(os.path.abspath(sys.argv[0]))
185+
# Fallback to current working directory (for REPL / Jupyter Notebook)
186+
else:
187+
full_path = os.getcwd()
188+
189+
return os.path.dirname(full_path)

0 commit comments

Comments
 (0)