Skip to content

Commit 8f08b40

Browse files
committed
fix(eval_optimize_loop): address second code review round
- Add missing import asyncio (live-mode path would NameError) - Guard _EvaluationCasesFailed private import with ImportError fallback - Remove /tmp whitelist hack in _resolve_paths (use isabs() only) - Warn via stderr when max_cost_usd is set but cost tracking unimplemented - Fix test isolation: use tempfile instead of shared /tmp paths - Add example tests to CI (testpaths + workflow command)
1 parent bcad2f3 commit 8f08b40

4 files changed

Lines changed: 35 additions & 15 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
7676
- name: Run tests with coverage
7777
# run: pytest --cov=trpc_agent_sdk --cov-report=xml --cov-report=term tests/
78-
run: pytest --cov=trpc_agent_sdk --cov-report=xml --cov-report=term --cov-fail-under=80 tests/
78+
run: pytest --cov=trpc_agent_sdk --cov-report=xml --cov-report=term --cov-fail-under=80 tests/ examples/optimization/eval_optimize_loop/tests/
7979

8080
- name: Upload coverage reports to Codecov
8181
uses: codecov/codecov-action@v4

examples/optimization/eval_optimize_loop/pipeline.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from __future__ import annotations
22

3+
import asyncio
34
import os
4-
import time
5+
import sys
56
import tempfile
7+
import time
68
from datetime import datetime, timezone
79
from typing import Callable, Optional
810

@@ -15,7 +17,10 @@
1517
EvaluateResult,
1618
TargetPrompt,
1719
)
18-
from trpc_agent_sdk.evaluation._agent_evaluator import _EvaluationCasesFailed
20+
try:
21+
from trpc_agent_sdk.evaluation._agent_evaluator import _EvaluationCasesFailed
22+
except ImportError:
23+
_EvaluationCasesFailed = AssertionError
1924

2025
from .delta import compute_delta
2126
from .failure_attribution import attribute_failures
@@ -73,6 +78,16 @@ def from_config(
7378
pipeline = cls(config)
7479
pipeline._live_call_agent = call_agent
7580
pipeline._live_target_prompt = target_prompt
81+
82+
if config.gate.max_cost_usd is not None:
83+
print(
84+
"Note: gate.max_cost_usd is set but cost tracking is not yet "
85+
"implemented in the pipeline (cost_usd is always 0.0). "
86+
"The cost gate rule will not reject candidates on cost grounds. "
87+
"Monitor costs via your LLM provider dashboard.",
88+
file=sys.stderr,
89+
)
90+
7691
return pipeline
7792

7893
@staticmethod
@@ -89,9 +104,8 @@ def _resolve_paths(config: PipelineConfig, base_dir: str) -> None:
89104
("live_val_evalset", config.live_val_evalset),
90105
("optimizer_config_path", config.optimizer_config_path),
91106
]
92-
import tempfile
93107
for name, value in paths:
94-
if value is not None and not os.path.isabs(value) and not value.startswith("/tmp"):
108+
if value is not None and not os.path.isabs(value):
95109
setattr(config, name, os.path.normpath(os.path.join(base_dir, value)))
96110

97111
if not os.path.isabs(config.output_dir):

examples/optimization/eval_optimize_loop/tests/test_pipeline.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,22 @@ def test_pipeline_from_config_trace_mode():
5757

5858
def test_pipeline_from_config_live_mode():
5959
"""Pipeline loads live mode config correctly."""
60-
Path("/tmp/train.json").touch()
61-
Path("/tmp/val.json").touch()
62-
Path("/tmp/optimizer.json").touch()
60+
import json
61+
62+
train_f = tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False)
63+
val_f = tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False)
64+
opt_f = tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False)
65+
train_f.close()
66+
val_f.close()
67+
opt_f.close()
6368

6469
config_data = {
6570
"mode": "live",
66-
"live_train_evalset": "/tmp/train.json",
67-
"live_val_evalset": "/tmp/val.json",
68-
"optimizer_config_path": "/tmp/optimizer.json",
71+
"live_train_evalset": train_f.name,
72+
"live_val_evalset": val_f.name,
73+
"optimizer_config_path": opt_f.name,
6974
"target_prompt_name": "system_prompt",
70-
"output_dir": "/tmp/outputs",
75+
"output_dir": tempfile.mkdtemp(),
7176
"evaluate": {
7277
"metrics": [
7378
{
@@ -81,8 +86,6 @@ def test_pipeline_from_config_live_mode():
8186
"seed": 42,
8287
}
8388
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
84-
import json
85-
8689
json.dump(config_data, f)
8790
config_path = f.name
8891

@@ -94,6 +97,9 @@ def test_pipeline_from_config_live_mode():
9497
assert pipeline._live_call_agent is not None
9598
finally:
9699
os.unlink(config_path)
100+
os.unlink(train_f.name)
101+
os.unlink(val_f.name)
102+
os.unlink(opt_f.name)
97103

98104

99105
def test_pipeline_live_mode_missing_params():

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,5 @@ split_before_logical_operator = true
204204
[tool.pytest.ini_options]
205205
minversion = "6.0"
206206
addopts = "-ra -q"
207-
testpaths = ["tests"]
207+
testpaths = ["tests", "examples/optimization/eval_optimize_loop/tests"]
208208
asyncio_mode = "auto"

0 commit comments

Comments
 (0)