MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / validate_code

Method validate_code

codeclash/arenas/scml/scml.py:43–77  ·  view source on GitHub ↗
(self, agent: Player)

Source from the content-addressed store, hash-verified

41 return getattr(self, "game_config", {}).get(key, self.default_args[key])
42
43 def validate_code(self, agent: Player) -> tuple[bool, str | None]:
44 quoted_submission = shlex.quote(self.submission)
45 file_check = agent.environment.execute(f"test -f {quoted_submission} && echo exists")
46 if "exists" not in file_check["output"]:
47 return False, f"Submission file `{self.submission}` not found in the workspace root"
48
49 content = agent.environment.execute(f"cat {quoted_submission}")["output"]
50 if not content.strip():
51 return False, f"`{self.submission}` is empty"
52
53 syntax_check = agent.environment.execute(f"python -m py_compile {quoted_submission}")
54 if syntax_check["returncode"] != 0:
55 return False, f"Python syntax error in `{self.submission}`:\n{syntax_check['output']}"
56
57 validation_timeout = int(self._game_arg("validation_timeout"))
58 try:
59 import_check = agent.environment.execute(
60 "python - <<'PY'\n"
61 "import importlib.util\n"
62 f"spec = importlib.util.spec_from_file_location('submission_agent', {self.submission!r})\n"
63 "module = importlib.util.module_from_spec(spec)\n"
64 "spec.loader.exec_module(module)\n"
65 "assert hasattr(module, 'decide'), 'decide function not found'\n"
66 "assert callable(module.decide), 'decide must be callable'\n"
67 "result = module.decide({'event': 'validate', 'awi': {}, 'state': {}, 'nmi': {}})\n"
68 "assert result is None or isinstance(result, dict), 'decide must return a dictionary or None'\n"
69 "PY",
70 timeout=validation_timeout,
71 )
72 except subprocess.TimeoutExpired:
73 return False, f"`decide` validation exceeded {validation_timeout}s timeout"
74 if import_check["returncode"] != 0:
75 return False, f"Could not import or call `decide` from `{self.submission}`:\n{import_check['output']}"
76
77 return True, None
78
79 def execute_round(self, agents: list[Player]) -> None:
80 agent_args = []

Callers

nothing calls this directly

Calls 2

_game_argMethod · 0.95
executeMethod · 0.45

Tested by

no test coverage detected