Skip to content
Merged
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
3 changes: 3 additions & 0 deletions app/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

APP = Path(__file__).resolve().parents[1]
FIXTURES = Path(__file__).resolve().parent / "fixtures"
# Seconds a test gives another process to answer or end. Each wait stops on its condition; this is only its
# limit, long enough for a machine shared with other work.
PATIENCE = 60

if str(APP) not in sys.path:
sys.path.insert(0, str(APP))
Expand Down
14 changes: 7 additions & 7 deletions app/tests/test_kit_check_isolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from nullius.standard.backends import container
from nullius.standard.contract import definitions
from nullius.standard.protocols import jsonl
from tests import APP
from tests import APP, PATIENCE
from tests.execution_support import gone

KIT = os.path.join(definitions.KITS, "agent-workspace-v1", "driver.py")
Expand Down Expand Up @@ -50,9 +50,9 @@ def plant_calc(self):

def test_on_docker_the_fix_check_runs_in_a_container_of_the_units_image(self):
d = self.driver(**{container.CHECK_IMAGE: "nullius/base:test", "PATH": self.bin + os.pathsep + os.environ["PATH"]})
d.request("setup", unit="fix", dir=self.ws, timeout=10)
d.request("setup", unit="fix", dir=self.ws, timeout=PATIENCE)
marker = self.plant_calc()
reply = d.request("score", unit="fix", dir=self.ws, transcript="", answer="", timeout=10)
reply = d.request("score", unit="fix", dir=self.ws, transcript="", answer="", timeout=PATIENCE)
self.assertFalse(os.path.exists(marker)) # the agent's calc.py was never imported here
self.assertTrue(reply["passed"])
argv = json.loads(Path(self.argv_log).read_text())
Expand All @@ -63,9 +63,9 @@ def test_on_docker_the_fix_check_runs_in_a_container_of_the_units_image(self):

def test_locally_the_fix_check_runs_here_as_the_agent_did(self):
d = self.driver()
d.request("setup", unit="fix", dir=self.ws, timeout=10)
d.request("setup", unit="fix", dir=self.ws, timeout=PATIENCE)
marker = self.plant_calc()
self.assertTrue(d.request("score", unit="fix", dir=self.ws, transcript="", answer="", timeout=10)["passed"])
self.assertTrue(d.request("score", unit="fix", dir=self.ws, transcript="", answer="", timeout=PATIENCE)["passed"])
self.assertTrue(os.path.exists(marker))
self.assertFalse(os.path.exists(self.argv_log))

Expand All @@ -74,11 +74,11 @@ def test_a_planted_link_is_not_followed(self):
with open(secret, "w") as f:
f.write("nullius-ok") # would even pass, read through the link
os.symlink(secret, os.path.join(self.ws, "result.txt"))
reply = self.driver().request("score", unit="write", dir=self.ws, transcript="", answer="", timeout=10)
reply = self.driver().request("score", unit="write", dir=self.ws, transcript="", answer="", timeout=PATIENCE)
self.assertEqual((reply["passed"], reply["detail"]["result.txt"]), (False, None))
bashrc = Path(self.tmp, "bashrc"); bashrc.write_text("mine\n")
os.symlink(bashrc, os.path.join(self.ws, "test_calc.py")) # the test is rewritten in place, never through a link
self.driver().request("score", unit="fix", dir=self.ws, transcript="", answer="", timeout=10)
self.driver().request("score", unit="fix", dir=self.ws, transcript="", answer="", timeout=PATIENCE)
self.assertEqual(bashrc.read_text(), "mine\n")


Expand Down
4 changes: 3 additions & 1 deletion app/tests/test_osworld1_entry_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,9 @@ def runner(self, code):
def test_the_driver_answers_once_the_runner_says_the_window_is_closed(self):
sock_dir = self.runner("import os, sys, json, time\nfd, data = int(sys.argv[1]), b''\n"
"while b'task-given\\n' not in data:\n data += os.read(fd, 64)\n"
"json.dump({'ok': True}, open(os.path.join(sys.argv[2], 'given.json'), 'w'))\n"
"said = os.path.join(sys.argv[2], 'given.json')\n"
"json.dump({'ok': True}, open(said + '.part', 'w'))\n" # whole, as computer_port.ready writes it
"os.replace(said + '.part', said)\n"
"time.sleep(30)\n")
self.assertEqual(self.d.task_given("os__t1", self.ws), {})
self.assertFalse(os.path.exists(os.path.join(sock_dir, "given.json")))
Expand Down
7 changes: 4 additions & 3 deletions app/tests/test_standard_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from nullius.standard.requirements import install
from nullius.standard.runner import payload
from nullius.standard.contract import definitions, proofs
from tests import PATIENCE


class Snapshot(unittest.TestCase):
Expand Down Expand Up @@ -389,7 +390,7 @@ def test_installed_local_execution_has_one_backend_provider_and_keeps_helpers_an
"catalogue_entry": definition["_here"], "args": sys.argv[1:]}))
''')
cwd = self.tmp / "outside-checkout"; cwd.mkdir()
driver = '''import hashlib, json, pathlib, sys
driver = f"PATIENCE = {PATIENCE}\n" + '''import hashlib, json, pathlib, sys
import nullius
from nullius import execution, paths
from nullius.standard.pages import recipe
Expand All @@ -407,7 +408,7 @@ def inventory():
before = inventory()
for index in range(3):
execution_ = execution.Execution(make_plan(index)).start()
execution_.thread.join(15)
execution_.thread.join(PATIENCE)
assert not execution_.thread.is_alive(), "fixture did not finish"
assert execution_.state == "done", execution_.lines
assert execution_.app_on_target == str(snapshot), "a later launch must reuse the same snapshot"
Expand All @@ -420,7 +421,7 @@ def inventory():
"snapshot": execution_.app_on_target, "successful_launches": 3}))
'''
ran = subprocess.run([str(python), "-I", "-B", "-c", driver], cwd=cwd, env=env,
capture_output=True, text=True, timeout=120)
capture_output=True, text=True, timeout=4 * PATIENCE) # three runs, and the venv's start
self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr)
parent = json.loads(ran.stdout)
self.assertEqual(parent["providers"], [str(installed)])
Expand Down
Loading