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
4 changes: 3 additions & 1 deletion core/framework/orchestrator/safe_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
MAX_POWER_RESULT_BITS = 4_096
# Typical edge-condition evaluations in this repo complete well under 1ms.
# 100ms leaves ample headroom for legitimate checks while failing fast on abuse.
DEFAULT_TIMEOUT_MS = 100
# On Windows (where SIGALRM is unavailable) the fallback relies on periodic
# perf_counter polling which is less precise, so we use a wider margin.
DEFAULT_TIMEOUT_MS = 100 if hasattr(signal, "SIGALRM") else 500


def _safe_pow(base: Any, exp: Any) -> Any:
Expand Down
6 changes: 6 additions & 0 deletions core/tests/test_cli_entry_point.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for the hive CLI entry point and path auto-configuration."""

import platform
import shutil
import subprocess
import sys
Expand All @@ -9,6 +10,8 @@

from framework.cli import _configure_paths

_IS_WINDOWS = platform.system() == "Windows"


@pytest.fixture
def project_root():
Expand Down Expand Up @@ -41,6 +44,7 @@ def test_does_not_duplicate_paths(self):
class TestFrameworkModule:
"""Test ``python -m framework`` invocation."""

@pytest.mark.skipif(_IS_WINDOWS, reason="subprocess capture unreliable on Windows CI")
def test_module_help(self, project_root):
result = subprocess.run(
[sys.executable, "-m", "framework", "--help"],
Expand All @@ -52,6 +56,7 @@ def test_module_help(self, project_root):
assert result.returncode == 0
assert "hive" in result.stdout.lower()

@pytest.mark.skipif(_IS_WINDOWS, reason="subprocess capture unreliable on Windows CI")
def test_module_serve_subcommand(self, project_root):
"""Verify ``python -m framework serve --help`` prints usage."""
result = subprocess.run(
Expand All @@ -73,6 +78,7 @@ def _require_hive(self):
if shutil.which("hive") is None:
pytest.skip("'hive' entry point not installed (run: pip install -e core/)")

@pytest.mark.skipif(_IS_WINDOWS, reason="subprocess capture unreliable on Windows CI")
def test_hive_help(self):
"""Verify ``hive --help`` exits 0 and lists the new commands."""
result = subprocess.run(
Expand Down
5 changes: 4 additions & 1 deletion core/tests/test_safe_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ def test_complex_expression(self):

class TestExecutionTimeout:
def test_default_timeout(self):
assert safe_eval_module.DEFAULT_TIMEOUT_MS == 100
import signal

expected = 100 if hasattr(signal, "SIGALRM") else 500
assert safe_eval_module.DEFAULT_TIMEOUT_MS == expected

def test_timeout_must_be_positive(self):
with pytest.raises(ValueError, match="timeout_ms"):
Expand Down
16 changes: 10 additions & 6 deletions tools/tests/tools/test_file_system_toolkits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import asyncio
import json
import os
import sys
from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -438,13 +439,16 @@ async def test_background_job_start_poll_and_complete(
):
"""A run_in_background job can be started, polled, and reports
its exit status once the command finishes."""
# Use sys.executable and double-quoted -c argument so this works
# on Windows (cmd.exe does not support single-quoted arguments).
py_script = (
"import time,sys;"
"print('one');sys.stdout.flush();time.sleep(0.1);"
"print('two');sys.stdout.flush();time.sleep(0.1);"
"print('three')"
)
start_result = await execute_command_fn(
command=(
"python -c 'import time,sys;"
'print("one");sys.stdout.flush();time.sleep(0.1);'
'print("two");sys.stdout.flush();time.sleep(0.1);'
'print("three")\''
),
command=f'"{sys.executable}" -c "{py_script}"',
run_in_background=True,
**mock_workspace,
)
Expand Down
Loading