fix: harden task2 preprocessing and vector guards

This commit is contained in:
2026-08-11 06:47:07 +02:00
parent f62b4dbc4c
commit f5e76fff53
6 changed files with 185 additions and 9 deletions
+38 -1
View File
@@ -225,7 +225,7 @@ def test_vector_index_schema_json_failure_is_safe(monkeypatch, tmp_path):
_write_schema_artifacts(tmp_path)
monkeypatch.setattr(
"tht.adapters.factory.build_vector_store",
lambda cfg, require_write: (_ for _ in ()).throw(RuntimeError("secret qdrant endpoint")),
lambda cfg, require_write: (_ for _ in ()).throw(Exception("secret qdrant endpoint")),
)
response = CliRunner().invoke(app, ["vector", "index-schema", "--json", "-c", str(cfg)])
assert response.exit_code != 0
@@ -233,6 +233,7 @@ def test_vector_index_schema_json_failure_is_safe(monkeypatch, tmp_path):
payload = json.loads(response.stdout)
assert payload == {"status": "failed", "code": "schema_index_failed"}
assert "secret qdrant" not in response.stdout
assert response.stderr == ""
@@ -294,3 +295,39 @@ def test_vector_index_schema_json_legacy_config_has_no_stderr_on_failure(tmp_pat
assert json.loads(response.stdout) == {
"status": "failed", "code": "physical_schema_missing"
}
def test_vector_index_schema_guards_before_artifact_access(tmp_path, monkeypatch):
import tht.cli.vector_cmd as command
cfg = _legacy_qdrant_runtime_config(tmp_path)
text = cfg.read_text()
text = text.replace("vectors:\n type: qdrant\n base_url: http://qdrant:6333\n collection: psd-clinical\n", "")
text = text.replace("embeddings:\n provider: ollama_internal\n base_url: http://embedding:11434\n model: qwen3-embedding:0.6b\n dim: 1024\n", "")
cfg.write_text(text)
monkeypatch.setattr(command, "_load_schema_artifacts", lambda cfg: (_ for _ in ()).throw(AssertionError("artifact access")))
response = CliRunner().invoke(app, ["vector", "index-schema", "--json", "-c", str(cfg)])
assert response.exit_code == 1
assert json.loads(response.stdout) == {"status": "failed", "code": "vector_configuration_missing"}
assert response.stderr == ""
def test_vector_index_schema_core_reuses_injected_artifacts_without_path_resolution(tmp_path, monkeypatch):
import tht.cli.vector_cmd as command
from tht.config import load_config
from tht.mschema.models import Annotations, PhysicalSchema
cfg_path = _qdrant_runtime_config(tmp_path)
_write_schema_artifacts(tmp_path)
physical = PhysicalSchema.from_yaml(tmp_path / "artifacts" / "mschema" / "physical.yaml")
annotations = Annotations.from_yaml(tmp_path / "artifacts" / "mschema" / "annotations.yaml")
store = _FakeVectorStore()
monkeypatch.setattr(command, "physical_path", lambda cfg: (_ for _ in ()).throw(AssertionError("physical path")))
monkeypatch.setattr(command, "annotations_path", lambda cfg: (_ for _ in ()).throw(AssertionError("annotations path")))
monkeypatch.setattr("tht.adapters.factory.build_vector_store", lambda cfg, require_write: store)
monkeypatch.setattr(command, "make_embedder", lambda _: _FakeEmbedder())
payload = command.index_schema_data(load_config(cfg_path), physical=physical, annotations=annotations)
assert payload["status"] == "succeeded"