Skip to content

Commit ea7e3e0

Browse files
committed
fix(testing): record configured Codex model
1 parent 54e9e06 commit ea7e3e0

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

tools/dstack-test/dstack-test

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ from pathlib import Path
2424
from typing import Any
2525

2626
import render
27+
import tomllib
2728

2829
TERMINAL_STATUS = ("PASS", "FAIL", "BLOCKED", "NOT_RUN", "SKIPPED")
2930

@@ -223,6 +224,20 @@ def agent_command(
223224
raise DstackTestError(f"unsupported agent: {agent}")
224225

225226

227+
def resolve_model(agent: str, model: str | None) -> str | None:
228+
if model or agent != "codex":
229+
return model
230+
config_home = Path(os.environ.get("CODEX_HOME", Path.home() / ".codex"))
231+
config_path = config_home / "config.toml"
232+
if not config_path.is_file():
233+
return None
234+
try:
235+
configured = tomllib.loads(config_path.read_text(encoding="utf-8")).get("model")
236+
except (OSError, tomllib.TOMLDecodeError):
237+
return None
238+
return configured if isinstance(configured, str) and configured else None
239+
240+
226241
def run_case(
227242
plan: render.Plan,
228243
case: render.CaseEntry,
@@ -248,7 +263,8 @@ def run_case(
248263
stderr_path = result_dir / "agent-stderr.log"
249264
started_at = utc_now()
250265
start = time.monotonic_ns()
251-
command = agent_command(agent, model, workdir, full_prompt, extra)
266+
effective_model = resolve_model(agent, model)
267+
command = agent_command(agent, effective_model, workdir, full_prompt, extra)
252268
binary = shutil.which(command[0])
253269
if not binary:
254270
raise DstackTestError(f"agent CLI not found: {command[0]}")
@@ -272,7 +288,10 @@ def run_case(
272288
"schema_version": "1.0",
273289
"run_id": run_id,
274290
"case_id": case.id,
275-
"agent": {"type": agent, "model": detected_model or model or "unknown"},
291+
"agent": {
292+
"type": agent,
293+
"model": detected_model or effective_model or "unknown",
294+
},
276295
"session": {
277296
"format": f"{agent}-jsonl",
278297
"path": "session.jsonl",

tools/dstack-test/tests/test_dstack_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import zipfile
1616
from importlib.machinery import SourceFileLoader
1717
from pathlib import Path
18+
from unittest import mock
1819

1920
HERE = Path(__file__).resolve().parent
2021
TOOL_DIR = HERE.parent
@@ -46,6 +47,15 @@ def test_run_command_defaults(self) -> None:
4647
self.assertEqual(args.agent, "codex")
4748
self.assertRegex(args.run_id, r"^run-\d{8}T\d{6}Z-[0-9a-f]{6}$")
4849

50+
def test_codex_model_is_read_from_config(self) -> None:
51+
with tempfile.TemporaryDirectory() as temporary:
52+
config = Path(temporary) / "config.toml"
53+
config.write_text('model = "test-codex-model"\n', encoding="utf-8")
54+
with mock.patch.dict(os.environ, {"CODEX_HOME": temporary}):
55+
self.assertEqual(
56+
dstack_test.resolve_model("codex", None), "test-codex-model"
57+
)
58+
4959
def test_validate_and_render_fixture(self) -> None:
5060
plan = render.load_plan(FIXTURE)
5161
valid = dstack_test.validate_run(plan, "run-demo")

0 commit comments

Comments
 (0)