Skip to content
Open
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
24 changes: 23 additions & 1 deletion responses_api_agents/swe_agents/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,28 @@ def get_run_command(self) -> ExecuteContainerCommandArgs:
)


# A jest invocation:
# runner-prefixed (npx/yarn), or bare `jest` in command position (line start or after &&/;/|),
# but never inside words ("ts-jest", "config_jest"), quotes (grep '"jest"'), or assignments.
_JEST_INVOCATION_RE = re.compile(r"((?:^|&&|;|\|)\s*|\b(?:npx|yarn)\s+)(jest\b)")


def _serialize_nv_internal_jest(run_script: str) -> str:
"""Force Jest in-band: large worker pools can wedge rootless Apptainer FUSE mid-eval."""
serialized_lines = []
for line in run_script.splitlines(keepends=True):
if _JEST_INVOCATION_RE.search(line):
flags = []
if "--runInBand" not in line and "--maxWorkers" not in line:
flags.append("--runInBand")
if "--forceExit" not in line:
flags.append("--forceExit")
if flags:
line = _JEST_INVOCATION_RE.sub(rf"\1\2 {' '.join(flags)}", line, count=1)
serialized_lines.append(line)
return "".join(serialized_lines)


class NVInternalDatasetProcessor(BaseDatasetHarnessProcessor):
def get_run_command(self) -> ExecuteContainerCommandArgs:
instance_dict = orjson.loads(self.config.problem_info["instance_dict"])
Expand Down Expand Up @@ -752,7 +774,7 @@ def get_run_command(self) -> ExecuteContainerCommandArgs:
else:
test_files = ",".join(test_files_str)

run_script = instance_dict["run_script.sh"]
run_script = _serialize_nv_internal_jest(instance_dict["run_script.sh"])
parsing_script = instance_dict["parsing_script.py"]
run_script_path = self.config.persistent_dir / "run_script.sh"
parsing_script_path = self.config.persistent_dir / "parsing_script.py"
Expand Down
30 changes: 30 additions & 0 deletions responses_api_agents/swe_agents/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,36 @@ def test_get_run_command_list_test_files(self) -> None:
result = processor.get_run_command()
assert "test_x.py,test_y.py" in result.command

def test_get_run_command_serializes_jest(self) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
processor = self._make_processor(
tmpdir,
{
"run_script.sh": (
"#!/bin/bash\n"
"npx jest tests/\n"
"yarn jest --maxWorkers=2 suite/\n"
". /root/.nvm/nvm.sh && jest --config verbose_jest.config.json\n"
"elif grep -q '\"jest\"' package.json; then\n"
'"preset": "ts-jest",\n'
"config_jest\n"
"echo done"
)
},
)
processor.get_run_command()
script = (processor.config.persistent_dir / "run_script.sh").read_text()
assert "npx jest --runInBand --forceExit tests/" in script
# An explicit worker count is respected; only --forceExit is added.
assert "yarn jest --forceExit --maxWorkers=2 suite/" in script
# Bare command-position jest (on PATH after nvm sourcing) is rewritten too.
assert "&& jest --runInBand --forceExit --config verbose_jest.config.json" in script
# Mentions that are not invocations stay untouched.
assert "elif grep -q '\"jest\"' package.json; then" in script
assert '"preset": "ts-jest",' in script
assert "config_jest\n" in script
assert "echo done" in script

def test_get_run_command_no_repo_cmd(self) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
processor = self._make_processor(
Expand Down
Loading