Files
ThothII/harness/tests/test_workspace.py
T
marcopan 6ba3336775 feat(harness): config.py + workspace.py (D3 confine) + chirone.example.yaml
- config.py ported from ChironeWp3, PSD_PROFILE -> THOTH_PROFILE; dual vector key
  (vector_rest/vector_write_rest top-level) preserved verbatim
- workspace.py: thin boundary wrapper (D3) around load_config
- workspaces/chirone.example.yaml: aligned to the real Config shape
- tests/test_workspace.py: 2 tests (env expand + dual key; missing env raises)
- .env.example: added DWH + DOCS_ROOT vars
All tests pass (2/2).
2026-06-26 22:25:00 +02:00

80 lines
2.9 KiB
Python

from pathlib import Path
from nsp.workspace import load_workspace, WorkspaceError
def test_load_workspace_expands_env_vars(monkeypatch, tmp_path):
monkeypatch.setenv("THOTH_VEC_API_KEY", "secret-reader")
monkeypatch.setenv("THOTH_VEC_WRITE_API_KEY", "secret-writer")
monkeypatch.setenv("THOTH_VEC_REST_URL", "https://example/vector/v1/")
monkeypatch.setenv("THOTH_DWH_REST_URL", "https://example/dwh/")
monkeypatch.setenv("THOTH_DWH_API_KEY", "dwh-key")
monkeypatch.setenv("THOTH_DB_HOST", "h")
monkeypatch.setenv("THOTH_DB_NAME", "db")
monkeypatch.setenv("THOTH_DB_USER", "u")
monkeypatch.setenv("THOTH_DB_PASSWORD", "p")
monkeypatch.setenv("THOTH_VEC_HOST", "vh")
monkeypatch.setenv("THOTH_VEC_USER", "vu")
monkeypatch.setenv("THOTH_VEC_PASSWORD", "vp")
monkeypatch.setenv("THOTH_OLLAMA_URL", "http://ollama")
monkeypatch.setenv("THOTH_DOCS_ROOT", str(tmp_path / "docs"))
yaml = tmp_path / "w.yaml"
yaml.write_text(
"database:\n"
" host: ${THOTH_DB_HOST}\n"
" port: 5432\n"
" database: ${THOTH_DB_NAME}\n"
" schema: datawarehouse\n"
" user: ${THOTH_DB_USER}\n"
" password: ${THOTH_DB_PASSWORD}\n"
" transport: rest\n"
"rest:\n"
" base_url: ${THOTH_DWH_REST_URL}\n"
" api_key: ${THOTH_DWH_API_KEY}\n"
"vector_db:\n"
" host: ${THOTH_VEC_HOST}\n"
" port: 5438\n"
" database: postgres\n"
" schema: vectors\n"
" user: ${THOTH_VEC_USER}\n"
" password: ${THOTH_VEC_PASSWORD}\n"
"vector_rest:\n"
" base_url: ${THOTH_VEC_REST_URL}\n"
" api_key: ${THOTH_VEC_API_KEY}\n"
"vector_write_rest:\n"
" base_url: ${THOTH_VEC_REST_URL}\n"
" api_key: ${THOTH_VEC_WRITE_API_KEY}\n"
"embeddings:\n"
" base_url: ${THOTH_OLLAMA_URL}\n"
" model: nomic-embed-text-v2-moe\n"
" dim: 768\n"
"evidence:\n"
" source_root: ${THOTH_DOCS_ROOT}\n"
)
ws = load_workspace(yaml)
# Dual vector key (top-level, per Config reale): reader and writer separate
assert ws.vector_rest.api_key == "secret-reader"
assert ws.vector_write_rest.api_key == "secret-writer"
# DWH key distinct from vector keys
assert ws.rest.api_key == "dwh-key"
# profile default = server
assert ws.profile == "server"
def test_load_workspace_missing_env_raises(monkeypatch, tmp_path):
monkeypatch.delenv("THOTH_VEC_API_KEY", raising=False)
yaml = tmp_path / "w.yaml"
yaml.write_text(
"database:\n"
" host: h\n port: 5432\n database: db\n schema: s\n"
" user: u\n password: p\n transport: direct\n"
"vector_rest:\n"
" base_url: 'https://v/'\n"
" api_key: '${THOTH_VEC_API_KEY}'\n"
)
try:
load_workspace(yaml)
assert False, "should have raised"
except WorkspaceError as e:
assert "THOTH_VEC_API_KEY" in str(e)