From 9c3c5d79db9322b20e1b736e2c86f945037e4dd2 Mon Sep 17 00:00:00 2001 From: David Liu Date: Sat, 7 Nov 2026 14:53:12 -0500 Subject: [PATCH 1/2] Fixed required settings not being enforced by the settings schema settings_schema.json listed the required top-level and worker settings inside "properties", which defines a setting named "required" instead of requiring anything. A worker missing "user" or "queues" passed validation and then crashed with a KeyError when the server started. Co-Authored-By: Claude Opus 5.5 --- server/autotest_server/settings_schema.json | 20 +++---- server/autotest_server/tests/test_config.py | 66 ++++++++++++++++----- 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/server/autotest_server/settings_schema.json b/server/autotest_server/settings_schema.json index 812fc638..2e3aa3e3 100644 --- a/server/autotest_server/settings_schema.json +++ b/server/autotest_server/settings_schema.json @@ -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 @@ -49,11 +49,11 @@ "minItems": 1, "items": { "type": "object", + "required": [ + "user", + "queues" + ], "properties": { - "required": [ - "user", - "queues" - ], "user": { "type": "string", "minLength": 1 diff --git a/server/autotest_server/tests/test_config.py b/server/autotest_server/tests/test_config.py index d9e08b23..a6293a9c 100644 --- a/server/autotest_server/tests/test_config.py +++ b/server/autotest_server/tests/test_config.py @@ -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): @@ -132,7 +124,9 @@ 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)) @@ -140,7 +134,7 @@ def test_files_merged_in_priority_order(self, default_root, monkeypatch, tmp_pat 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" @@ -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() From 30d80a2581a839a788e2e74f7ee26bba48819d05 Mon Sep 17 00:00:00 2001 From: David Liu Date: Sat, 7 Nov 2026 14:53:32 -0500 Subject: [PATCH 2/2] Updated Changelog Co-Authored-By: Claude Opus 5.5 --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 94f373b0..f0212877 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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)