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
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ All notable changes to this project will be documented here.
- Added test suite and coverage reporting for the autotest server, with pinned dev dependencies in `server/requirements-dev.txt`, and Coveralls coverage reporting in CI (#775)
- Fixed `copy_tree` skipping every file when given an exclude list (#777)
- Fixed `start_stop.py clean --dry-run` expiring settings whose scripts directory doesn't exist (#778)
- Fixed required settings not being enforced by the server settings schema (#779)

## [v2.9.0]
- Install stack with GHCup (#626)
Expand Down
20 changes: 10 additions & 10 deletions server/autotest_server/settings_schema.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"type": "object",
"required": [
"workspace",
"redis_url",
"supervisor_url",
"workers"
],
"properties": {
"required": [
"workspace",
"redis_url",
"supervisor_url",
"workers"
],
"workspace": {
"type": "string",
"minLength": 1
Expand Down Expand Up @@ -49,11 +49,11 @@
"minItems": 1,
"items": {
"type": "object",
"required": [
"user",
"queues"
],
"properties": {
"required": [
"user",
"queues"
],
"user": {
"type": "string",
"minLength": 1
Expand Down
66 changes: 51 additions & 15 deletions server/autotest_server/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ def test_shared_local_file_raises(default_root):
_Config()


@pytest.mark.parametrize("value, valid", [({"GATEWAY_API_KEY": "gw-key"}, True), ({"GATEWAY_API_KEY": 123}, False)])
def test_schema_requires_string_ai_tester_env_values(value, valid):
with open(os.path.join(DEFAULT_ROOT, "settings_schema.json")) as f:
schema = json.load(f)
errors = list(jsonschema.Draft7Validator(schema).iter_errors({"ai_tester_env": value}))
assert (not errors) is valid


class TestAccess:
@pytest.fixture
def config(self, monkeypatch, tmp_path):
Expand Down Expand Up @@ -132,15 +124,17 @@ def test_files_merged_in_priority_order(self, default_root, monkeypatch, tmp_pat
with open(default_root / "settings.yml", "a") as f:
f.write("max_test_timeout: 10\nrlimit_settings:\n nproc: [1, 2]\n")
env_file = tmp_path / "env.yml"
env_file.write_text("max_test_timeout: 20\nrlimit_settings:\n cpu: [3, 4]\nworkers:\n - user: env_user\n")
env_file.write_text(
"max_test_timeout: 20\nrlimit_settings:\n cpu: [3, 4]\nworkers:\n - user: env_user\n queues: [low]\n"
)
os.chmod(env_file, 0o600)
monkeypatch.setenv("AUTOTESTER_CONFIG", str(env_file))

config = _Config()

assert config["max_test_timeout"] == 20
assert config["rlimit_settings"] == {"cpu": [3, 4], "nproc": [1, 2]}
assert config["workers"] == [{"user": "env_user"}]
assert config["workers"] == [{"user": "env_user", "queues": ["low"]}]

def test_empty_file_ignored(self, default_root, monkeypatch, tmp_path):
env_file = tmp_path / "env.yml"
Expand All @@ -153,8 +147,50 @@ def test_invalid_settings(self, monkeypatch, tmp_path):
_load(monkeypatch, tmp_path, "max_test_timeout: 0\n", 0o600)


@pytest.mark.xfail(strict=True, reason="settings_schema.json puts its required lists inside properties")
def test_schema_requires_core_settings():
with open(os.path.join(DEFAULT_ROOT, "settings_schema.json")) as f:
schema = json.load(f)
assert list(jsonschema.Draft7Validator(schema).iter_errors({}))
class TestSettingsSchema:
@pytest.fixture
def schema(self):
with open(os.path.join(DEFAULT_ROOT, "settings_schema.json")) as f:
return json.load(f)

@pytest.fixture
def settings(self):
return {
"workspace": "/workspace",
"redis_url": "redis://localhost",
"supervisor_url": "localhost:9001",
"workers": [{"user": "autotst0", "queues": ["low"]}],
}

def test_schema_is_valid(self, schema):
jsonschema.Draft7Validator.check_schema(schema)

def test_valid_settings(self, schema, settings):
jsonschema.Draft7Validator(schema).validate(settings)

@pytest.mark.parametrize("key", ["workspace", "redis_url", "supervisor_url", "workers"])
def test_required_setting(self, schema, settings, key):
del settings[key]
with pytest.raises(jsonschema.ValidationError, match=f"'{key}' is a required property"):
jsonschema.Draft7Validator(schema).validate(settings)

@pytest.mark.parametrize("key", ["user", "queues"])
def test_required_worker_setting(self, schema, settings, key):
del settings["workers"][0][key]
with pytest.raises(jsonschema.ValidationError, match=f"'{key}' is a required property"):
jsonschema.Draft7Validator(schema).validate(settings)

@pytest.mark.parametrize("value, valid", [({"GATEWAY_API_KEY": "gw-key"}, True), ({"GATEWAY_API_KEY": 123}, False)])
def test_ai_tester_env_values_must_be_strings(self, schema, settings, value, valid):
errors = list(jsonschema.Draft7Validator(schema).iter_errors({**settings, "ai_tester_env": value}))
assert (not errors) is valid


def test_worker_missing_queues_rejected_on_load(default_root, monkeypatch, tmp_path):
"""Workers in a config file replace the default workers, so each one must be complete."""
env_file = tmp_path / "env.yml"
env_file.write_text("workers:\n - user: env_user\n")
os.chmod(env_file, 0o600)
monkeypatch.setenv("AUTOTESTER_CONFIG", str(env_file))
with pytest.raises(jsonschema.ValidationError, match="'queues' is a required property"):
_Config()
Loading