From d5f752dd7b0b5e9e47d54abbe53d76fb10afe083 Mon Sep 17 00:00:00 2001 From: mptyl Date: Tue, 11 Aug 2026 05:49:15 +0200 Subject: [PATCH] fix: suppress legacy warnings in machine JSON paths --- harness/tests/test_qdrant_cli_commands.py | 42 +++++++++++++++++++++ harness/tests/test_schema_fk_annotations.py | 6 +++ harness/tht/cli/schema_cmd.py | 18 +++++++-- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/harness/tests/test_qdrant_cli_commands.py b/harness/tests/test_qdrant_cli_commands.py index 175b105d..d6827edb 100644 --- a/harness/tests/test_qdrant_cli_commands.py +++ b/harness/tests/test_qdrant_cli_commands.py @@ -61,6 +61,18 @@ embeddings: return cfg +def _legacy_qdrant_runtime_config(tmp_path: Path) -> Path: + cfg = _qdrant_runtime_config(tmp_path) + text = cfg.read_text() + text = text.replace( + "dwh:\n type: postgres_direct\n connection: {database: analytics, schema: mart, user: reader, password: secret}\n", + "database: {database: analytics, schema: mart, user: reader, password: secret}\n", + ) + text = text.replace("roots:\n", "paths:\n") + cfg.write_text(text) + return cfg + + def _write_schema_artifacts(tmp_path: Path) -> None: (tmp_path / "artifacts" / "mschema").mkdir(parents=True, exist_ok=True) (tmp_path / "artifacts" / "mschema" / "physical.yaml").write_text( @@ -252,3 +264,33 @@ def test_vector_index_schema_human_missing_config_has_original_error(tmp_path): assert response.exit_code == 1 assert response.output assert "ERRORE:" in response.output + + +def test_vector_index_schema_json_legacy_config_has_no_stderr_on_success(monkeypatch, tmp_path): + cfg = _legacy_qdrant_runtime_config(tmp_path) + _write_schema_artifacts(tmp_path) + store = _FakeVectorStore() + monkeypatch.setattr("tht.adapters.factory.build_vector_store", lambda cfg, require_write: store) + monkeypatch.setattr("tht.cli.vector_cmd.make_embedder", lambda _: _FakeEmbedder()) + + response = CliRunner().invoke(app, ["vector", "index-schema", "--json", "-c", str(cfg)]) + + assert response.exit_code == 0, response.output + assert response.stderr == "" + assert response.stdout.count("\n") == 1 + assert json.loads(response.stdout)["status"] == "succeeded" + + +def test_vector_index_schema_json_legacy_config_has_no_stderr_on_failure(tmp_path): + cfg = _legacy_qdrant_runtime_config(tmp_path) + _write_schema_artifacts(tmp_path) + (tmp_path / "artifacts" / "mschema" / "physical.yaml").unlink() + + response = CliRunner().invoke(app, ["vector", "index-schema", "--json", "-c", str(cfg)]) + + assert response.exit_code == 1 + assert response.stderr == "" + assert response.stdout.count("\n") == 1 + assert json.loads(response.stdout) == { + "status": "failed", "code": "physical_schema_missing" + } diff --git a/harness/tests/test_schema_fk_annotations.py b/harness/tests/test_schema_fk_annotations.py index 7f46c1b6..99eb7926 100644 --- a/harness/tests/test_schema_fk_annotations.py +++ b/harness/tests/test_schema_fk_annotations.py @@ -241,6 +241,7 @@ def test_suggest_fks_json_is_single_deterministic_document_without_writing(tmp_p app, ["schema", "suggest-fks", "--json", "-c", str(cfg), "--from-sql", str(staged)] ) assert response.exit_code == 0, response.output + assert response.stderr == "" assert response.stdout.count("\n") == 1 payload = json.loads(response.stdout) assert payload["status"] == "succeeded" @@ -261,6 +262,7 @@ def test_suggest_fks_json_failure_is_safe_and_single_document(tmp_path): (tmp_path / "artifacts" / "mschema" / "physical.yaml").unlink() response = CliRunner().invoke(app, ["schema", "suggest-fks", "--json", "-c", str(cfg)]) assert response.exit_code != 0 + assert response.stderr == "" assert response.stdout.count("\n") == 1 payload = json.loads(response.stdout) assert payload == {"status": "failed", "code": "physical_schema_missing"} @@ -276,6 +278,7 @@ def test_schema_check_json_reports_orphan_count_without_prose(tmp_path): ) response = CliRunner().invoke(app, ["schema", "check", "--json", "-c", str(cfg)]) assert response.exit_code == 3 + assert response.stderr == "" assert response.stdout.count("\n") == 1 assert json.loads(response.stdout) == { "status": "failed", "code": "annotation_orphans", "orphan_count": 1, @@ -327,11 +330,14 @@ def test_schema_check_json_success_and_reviewed_annotations_are_preserved(tmp_pa check = CliRunner().invoke(app, ["schema", "check", "--json", "-c", str(cfg)]) assert check.exit_code == 0, check.output + assert check.stderr == "" + assert check.stdout.count("\n") == 1 assert json.loads(check.stdout) == { "status": "succeeded", "code": "ok", "orphan_count": 0, "orphans": [] } suggest = CliRunner().invoke(app, ["schema", "suggest-fks", "--json", "-c", str(cfg)]) assert suggest.exit_code == 0, suggest.output + assert suggest.stderr == "" assert json.loads(suggest.stdout)["candidate_count"] == 0 assert annotations_path.read_text() == before diff --git a/harness/tht/cli/schema_cmd.py b/harness/tht/cli/schema_cmd.py index 083ac030..96a86807 100644 --- a/harness/tht/cli/schema_cmd.py +++ b/harness/tht/cli/schema_cmd.py @@ -1,5 +1,6 @@ # ruff: noqa: BLE001, S110, B008 import logging +import warnings from pathlib import Path from typing import TypedDict @@ -143,10 +144,19 @@ def _schema_json(payload: dict) -> None: def _machine_config(config: Path): - try: - return load_config(config) - except ConfigError: - raise _MachineSchemaError("invalid_configuration") from None + # Legacy resource keys remain accepted, but their deprecation warning is not part of + # the JSON machine contract. Keep this filter scoped to this call so human commands + # (and unrelated warnings/errors) retain their existing behavior. + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + message=r"^DEPRECATION: legacy workspace resource keys are deprecated;", + category=FutureWarning, + ) + try: + return load_config(config) + except ConfigError: + raise _MachineSchemaError("invalid_configuration") from None def _physical_or_error(cfg):