Files
ThothII/harness/tests/test_workspace.py
marcopanandClaude Fable 5 c4951e2aa5 chore: hygiene pass — ruff clean, docs storage-model truth, replay /me, failSession log
Audit findings 6.1-6.4 + the audit's remediation plan itself
(docs/superpowers/plans/2026-07-20-full-audit-remediation-plan.md).

- ruff: 34 → 0 (unused imports/f-strings auto-fixed; E702 semicolon lines
  split in test files; one unused local dropped). Suite still 819 green.
- CLAUDE.md + PROJECT_STATE.md no longer claim "no database / settings in
  settings.json": the harness selects filesystem OR PostgreSQL session
  storage (repository.py, server mode), and settings flow through harness
  preferences with the JSON file as fallback only.
- tools/replay: stub /me (SPA boot was parsing the SPA's own HTML as JSON)
  and /runtime/prewarm.
- failSession best-effort persistence now logs its failure server-side
  instead of vanishing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-20 01:55:41 +02:00

83 lines
3.1 KiB
Python

from tht.workspace import load_workspace, WorkspaceError
def test_load_workspace_expands_env_vars(monkeypatch, tmp_path):
# Isolate profile: load_dotenv (conftest D3) injects THT_PROFILE from the real
# harness/.env into os.environ; this test asserts the *default* (server), so it
# must del THT_PROFILE rather than inherit whatever the operator set.
monkeypatch.delenv("THT_PROFILE", raising=False)
monkeypatch.setenv("THT_VEC_API_KEY", "secret-reader")
monkeypatch.setenv("THT_VEC_WRITE_API_KEY", "secret-writer")
monkeypatch.setenv("THT_VEC_REST_URL", "https://example/vector/v1/")
monkeypatch.setenv("THT_DWH_REST_URL", "https://example/dwh/")
monkeypatch.setenv("THT_DWH_API_KEY", "dwh-key")
monkeypatch.setenv("THT_DB_HOST", "h")
monkeypatch.setenv("THT_DB_NAME", "db")
monkeypatch.setenv("THT_DB_USER", "u")
monkeypatch.setenv("THT_DB_PASSWORD", "p")
monkeypatch.setenv("THT_VEC_HOST", "vh")
monkeypatch.setenv("THT_VEC_USER", "vu")
monkeypatch.setenv("THT_VEC_PASSWORD", "vp")
monkeypatch.setenv("THT_OLLAMA_URL", "http://ollama")
monkeypatch.setenv("THT_DOCS_ROOT", str(tmp_path / "docs"))
yaml = tmp_path / "w.yaml"
yaml.write_text(
"database:\n"
" host: ${THT_DB_HOST}\n"
" port: 5432\n"
" database: ${THT_DB_NAME}\n"
" schema: datawarehouse\n"
" user: ${THT_DB_USER}\n"
" password: ${THT_DB_PASSWORD}\n"
" transport: rest\n"
"rest:\n"
" base_url: ${THT_DWH_REST_URL}\n"
" api_key: ${THT_DWH_API_KEY}\n"
"vector_db:\n"
" host: ${THT_VEC_HOST}\n"
" port: 5438\n"
" database: postgres\n"
" schema: vectors\n"
" user: ${THT_VEC_USER}\n"
" password: ${THT_VEC_PASSWORD}\n"
"vector_rest:\n"
" base_url: ${THT_VEC_REST_URL}\n"
" api_key: ${THT_VEC_API_KEY}\n"
"vector_write_rest:\n"
" base_url: ${THT_VEC_REST_URL}\n"
" api_key: ${THT_VEC_WRITE_API_KEY}\n"
"embeddings:\n"
" base_url: ${THT_OLLAMA_URL}\n"
" model: nomic-embed-text-v2-moe\n"
" dim: 768\n"
"evidence:\n"
" source_root: ${THT_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("THT_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: '${THT_VEC_API_KEY}'\n"
)
try:
load_workspace(yaml)
assert False, "should have raised"
except WorkspaceError as e:
assert "THT_VEC_API_KEY" in str(e)