|
| 1 | +"""Non-finite time settings must not reach Slack's timers or command runner.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from grapharc.slack.command import SlackCommandError, parse_command |
| 8 | +from grapharc.slack.config import SlackBotConfig, SlackConfigError |
| 9 | + |
| 10 | + |
| 11 | +@pytest.mark.parametrize("value", ["nan", "inf", "-inf", "1e309"]) |
| 12 | +@pytest.mark.parametrize( |
| 13 | + "key", ["GRAPHARC_SLACK_TIMEOUT", "GRAPHARC_SLACK_WORK_TIMEOUT", "GRAPHARC_SLACK_LIVE_INTERVAL"] |
| 14 | +) |
| 15 | +def test_environment_timing_values_must_be_finite(tmp_path, key, value): |
| 16 | + env = { |
| 17 | + "SLACK_BOT_TOKEN": "test-bot", |
| 18 | + "SLACK_APP_TOKEN": "test-app", |
| 19 | + "GRAPHARC_SLACK_WORKDIR": str(tmp_path), |
| 20 | + key: value, |
| 21 | + } |
| 22 | + |
| 23 | + with pytest.raises(SlackConfigError, match=key): |
| 24 | + SlackBotConfig.from_env(env) |
| 25 | + |
| 26 | + |
| 27 | +@pytest.mark.parametrize("form", ["--approval-timeout nan", "--approval-timeout=NaN"]) |
| 28 | +def test_a_nan_approval_wait_is_refused(tmp_path, form): |
| 29 | + with pytest.raises(SlackCommandError, match="does not fit this command's budget"): |
| 30 | + parse_command( |
| 31 | + f"plan goal --scripted --go {form}", |
| 32 | + workdir=tmp_path, |
| 33 | + timeout_seconds=60, |
| 34 | + work_timeout_seconds=180, |
| 35 | + ) |
| 36 | + |
| 37 | + |
| 38 | +def test_finite_fractional_timings_remain_configurable(tmp_path): |
| 39 | + config = SlackBotConfig.from_env( |
| 40 | + { |
| 41 | + "SLACK_BOT_TOKEN": "test-bot", |
| 42 | + "SLACK_APP_TOKEN": "test-app", |
| 43 | + "GRAPHARC_SLACK_WORKDIR": str(tmp_path), |
| 44 | + "GRAPHARC_SLACK_TIMEOUT": "12.5", |
| 45 | + "GRAPHARC_SLACK_WORK_TIMEOUT": "25.5", |
| 46 | + "GRAPHARC_SLACK_LIVE_INTERVAL": "0.25", |
| 47 | + } |
| 48 | + ) |
| 49 | + |
| 50 | + assert config.timeout_seconds == 12.5 |
| 51 | + assert config.work_timeout_seconds == 25.5 |
| 52 | + assert config.live_interval_seconds == 0.25 |
| 53 | + argv = parse_command( |
| 54 | + "plan goal --scripted --approval-timeout 1.5", |
| 55 | + workdir=tmp_path, |
| 56 | + timeout_seconds=config.timeout_seconds, |
| 57 | + work_timeout_seconds=config.work_timeout_seconds, |
| 58 | + ) |
| 59 | + assert argv[argv.index("--approval-timeout") + 1] == "1.5" |
0 commit comments