Skip to content

💫 Toolkit to help you get started with SDD or any other process!

fix: add ValueError guard for timeout in _build_opencode_plugin (#3973)

Quratulain-bilal13dccdc9070d
diff --git a/src/specify_cli/events/__init__.py b/src/specify_cli/events/__init__.py
index b78e5da84..4cec7997f 100644
--- a/src/specify_cli/events/__init__.py
+++ b/src/specify_cli/events/__init__.py
@@ -1980,7 +1980,10 @@ def _build_opencode_plugin(
# S3: thread the per-handler timeout (seconds) to runEvent so the
# execFileSync cap and dispatcher arg match the configuration
# instead of a fixed 60000ms / 120s.
- timeout_sec = int(cfg.get("timeout", 60))
+ try:
+ timeout_sec = int(cfg.get("timeout", 60))
+ except (TypeError, ValueError):
+ timeout_sec = 60
if native.startswith("tool.execute."):
if matcher and matcher != "*":
tools = [t.strip().strip('"') for t in matcher.split("|")]
diff --git a/tests/specify_cli/events/test_events.py b/tests/specify_cli/events/test_events.py
index 9a193c762..d1f15bec5 100644
--- a/tests/specify_cli/events/test_events.py
+++ b/tests/specify_cli/events/test_events.py
@@ -1223,6 +1223,26 @@ class TestOpencodePluginMerging:
assert "runEvent('speckit.x" not in content
assert json.dumps("ed'it") in content
+ def test_opencode_non_numeric_timeout_uses_default(self, tmp_path):
+ """A non-numeric timeout value in event config must not crash
+ _build_opencode_plugin; it should fall back to the default (60s)."""
+ integration = OpencodeIntegration()
+ manifest = MagicMock(spec=IntegrationManifest)
+ manifest.files = {}
+ manifest.record_file = MagicMock()
+ manifest.record_existing = MagicMock()
+
+ events = {
+ "pre_tool_use": [{"command": "speckit.tdd.validate", "timeout": "not-a-number"}],
+ }
+ # Must not raise TypeError or ValueError
+ install_integration_events(integration, tmp_path, manifest, events)
+ plugin_path = tmp_path / ".opencode/plugin/speckit-events.ts"
+ assert plugin_path.is_file()
+ content = plugin_path.read_text()
+ assert "speckit.tdd.validate" in content
+ assert 'runEvent("speckit.tdd.validate", "pre_tool_use", input, output, 60)' in content
+
# -- Command runner test (core execution) -----------------------------------