Core regression / Python core, intervention UI and release configuration (pull_request) Canceled after 0s
Core regression / JavaScript syntax (pull_request) Canceled after 0s
Core regression / Python core, intervention UI and release configuration (push) Canceled after 1m15s
Core regression / JavaScript syntax (push) Canceled after 0s
82 lines
3.1 KiB
Python
82 lines
3.1 KiB
Python
import json
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from dx_productivity.dsh import availability
|
|
|
|
|
|
@pytest.fixture
|
|
def local_probe(tmp_path, monkeypatch):
|
|
for key in (*availability._HOST_KEYS, 'DEEPSEEK_API_KEY'):
|
|
monkeypatch.delenv(key, raising=False)
|
|
root = tmp_path / 'runtime'
|
|
package = root / 'node_modules/@deepseek-ai/dsh/package.json'
|
|
package.parent.mkdir(parents=True)
|
|
package.write_text('{}', encoding='utf8')
|
|
data = tmp_path / 'data'
|
|
credentials = data / 'dsh/harness-home/.credentials.yaml'
|
|
credentials.parent.mkdir(parents=True)
|
|
credentials.write_text('{}', encoding='utf8')
|
|
monkeypatch.setattr(availability, 'integration_root', lambda: root)
|
|
monkeypatch.setattr(availability, 'node_executable', lambda: 'controlled-node')
|
|
return data
|
|
|
|
|
|
def reply(code='available'):
|
|
return SimpleNamespace(returncode=0, stderr='', stdout=json.dumps({
|
|
'available': code == 'available', 'code': code,
|
|
'source': 'native', 'environment_refs': [],
|
|
'model_selection': {'provider': 'configured', 'model': 'fixture'}}))
|
|
|
|
|
|
def test_one_cold_probe_timeout_recovers_without_disabling_ai(local_probe, monkeypatch):
|
|
calls = []
|
|
def probe(*args, **kwargs):
|
|
calls.append(kwargs['timeout'])
|
|
if len(calls) == 1:
|
|
raise availability.subprocess.TimeoutExpired('fake-private-command', 3)
|
|
return reply()
|
|
monkeypatch.setattr(availability.subprocess, 'run', probe)
|
|
result = availability.check_availability(local_probe)
|
|
assert result['available']
|
|
assert result['model_selection'] == {'provider': 'configured', 'model': 'fixture'}
|
|
assert calls == [3, 3]
|
|
assert 'fake-private' not in json.dumps(result)
|
|
|
|
|
|
def test_repeated_timeout_is_bounded_and_distinct_from_missing_model(local_probe, monkeypatch):
|
|
calls = []
|
|
def probe(*args, **kwargs):
|
|
calls.append(kwargs['timeout'])
|
|
raise availability.subprocess.TimeoutExpired('fake-secret', 3)
|
|
monkeypatch.setattr(availability.subprocess, 'run', probe)
|
|
result = availability.check_availability(local_probe)
|
|
assert result['code'] == 'configuration_timeout'
|
|
assert not result['available']
|
|
assert calls == [3, 3]
|
|
assert 'fake-secret' not in json.dumps(result)
|
|
|
|
|
|
@pytest.mark.parametrize('code', ['missing_credential', 'invalid_configuration'])
|
|
def test_confirmed_configuration_error_is_not_retried(local_probe, monkeypatch, code):
|
|
calls = []
|
|
def probe(*args, **kwargs):
|
|
calls.append(True)
|
|
return reply(code)
|
|
monkeypatch.setattr(availability.subprocess, 'run', probe)
|
|
assert availability.check_availability(local_probe)['code'] == code
|
|
assert calls == [True]
|
|
|
|
|
|
def test_invalid_child_output_is_not_retried_or_exposed(local_probe, monkeypatch):
|
|
calls = []
|
|
def probe(*args, **kwargs):
|
|
calls.append(True)
|
|
return SimpleNamespace(returncode=0, stdout='fake-secret-not-json', stderr='')
|
|
monkeypatch.setattr(availability.subprocess, 'run', probe)
|
|
result = availability.check_availability(local_probe)
|
|
assert result['code'] == 'runtime_unavailable'
|
|
assert calls == [True]
|
|
assert 'fake-secret' not in json.dumps(result)
|