* feat: introduce hindsight-api-slim and hindsight-all-slim packages Closes #552 - Move all source code from hindsight-api/ to new hindsight-api-slim/ - hindsight-api-slim has heavy ML deps (torch, sentence-transformers, transformers, einops, flashrank, mlx, mlx-lm, safetensors) and pg0-embedded as optional extras: [local-ml], [embedded-db], [all] - hindsight-api becomes a zero-code meta-package depending on hindsight-api-slim[all] for full backward compatibility - Add hindsight-all-slim meta-package: hindsight-api-slim + client + embed - hindsight-all updated to depend on hindsight-api-slim[all] - pg0.py: lazy-import pg0 with clear ImportError pointing to [embedded-db] - Dockerfile: replace sed hack with proper uv sync --extra flags - Update release.yml, test.yml, lint.sh, release.sh, CLAUDE.md and all path references throughout the repo * refactor: rename hindsight/ directory to hindsight-all/ * docs: document hindsight-api-slim and hindsight-all-slim package variants Add package variants table and extras explanation to installation.md * docs: remove emojis from installation.md, use professional tone * docs: link Docker slim variant to pip package variants section * docs: consolidate Docker image variants into single table * ci: fix working-directory paths after package restructure - Replace all hindsight-api → hindsight-api-slim in test.yml - Replace hindsight → hindsight-all in test.yml - Add --extra embedded-db to test-embed API install step * ci: add local-ml and embedded-db extras to API sync steps These extras were previously implicit in the old hindsight-api package (which bundled everything). Now that hindsight-api-slim uses optional extras, we must explicitly request local-ml and embedded-db in CI. * ci: add API install step with embedded-db to test-embed smoke test The smoke test starts hindsight-api as a daemon, which requires pg0-embedded. Add a dedicated install step for hindsight-api-slim with embedded-db extra so the daemon can start successfully. * ci: remove --no-install-project when using optional extras When --no-install-project is combined with --extra, the optional deps are not installed because extras require the project to be active. Remove --no-install-project from steps that need local-ml or embedded-db. * ci: fix ordering of uv sync steps to preserve optional extras When uv sync runs for a different workspace member, it removes optional extras installed for other members. Fix by always running extra-requiring API sync last, after other workspace member syncs. Also remove --no-install-project from embedded-db sync in test-embed, as --no-install-project prevents optional extras from being active. * ci: add local-ml extra to test-embed API install for smoke test The smoke test starts the full API server which needs sentence-transformers for local embeddings (default provider). Add local-ml extra to the install. * ci: simplify extras with --all-extras and add slim pip smoke test - Replace explicit --extra local-ml --extra embedded-db with --all-extras for cleaner, more maintainable sync steps - Add test-pip-slim job: tests hindsight-api-slim[embedded-db] without local ML models, using Cohere for embeddings/reranking (mirrors Docker slim smoke test approach) * ci: simplify slim smoke test to health check only (mirrors Docker test) |
||
|---|---|---|
| .. | ||
| __init__.py | ||
| README.md | ||
| test_embedded.py | ||
| test_embedded_namespaces.py | ||
| test_server_integration.py | ||
Hindsight Integration Tests
This directory contains integration tests for the Hindsight all-in-one package.
Test Overview
test_server_integration.py
Comprehensive integration tests that verify the complete workflow:
-
test_server_context_manager_basic_workflow: Main integration test that:- Starts the Hindsight server using a context manager
- Creates a memory bank with background information
- Stores multiple memories (both single and batch operations)
- Recalls memories based on different queries (programming preferences, ML topics)
- Reflects (generates contextual answers) multiple times with different contexts
- Automatically stops the server on context exit
-
test_server_manual_start_stop: Tests explicit server lifecycle management without context managers -
test_server_with_client_context_manager: Tests nested context managers for both server and client
Running the Tests
Prerequisites
-
Install the hindsight package with test dependencies:
cd hindsight uv pip install -e ".[test]" -
Set up your LLM credentials in the
.envfile at the project root:HINDSIGHT_API_LLM_PROVIDER=groq HINDSIGHT_API_LLM_API_KEY=your-api-key HINDSIGHT_API_LLM_MODEL=openai/gpt-oss-20b
Run All Tests
cd hindsight
source ../.env
export HINDSIGHT_LLM_PROVIDER=$HINDSIGHT_API_LLM_PROVIDER
export HINDSIGHT_LLM_API_KEY=$HINDSIGHT_API_LLM_API_KEY
export HINDSIGHT_LLM_MODEL=$HINDSIGHT_API_LLM_MODEL
pytest tests/ -v
Note on Parallel Execution: These tests use embedded PostgreSQL (pg0), which is a singleton that cannot be shared across pytest-xdist worker processes. Therefore, these tests must run sequentially. Do not use pytest -n (parallel workers) with these tests.
Why Random bank_id Values?: Each test generates a unique bank_id using UUID. This provides several benefits:
- Clean test isolation: Tests don't interfere with each other's data
- Repeatable runs: Tests can be run multiple times without cleanup
- Debugging: Easy to identify which test created which data
- Future-ready: If you switch from
pg0to a real PostgreSQL instance, these tests could run in parallel
Run Specific Test
pytest tests/test_server_integration.py::test_server_context_manager_basic_workflow -v
Run with Verbose Output
pytest tests/ -v -s
The -s flag shows print statements, which is useful to see the test progress.
Run with Timeout
These tests involve LLM calls which can take time:
pytest tests/ --timeout=300
Test Configuration
The tests use:
- Embedded PostgreSQL (
pg0) for the database - no external database required - LLM provider configured via environment variables
- Automatic port allocation for the server (no port conflicts)
Expected Behavior
When tests run successfully, you should see:
- Server starting on a random available port
- Memory bank creation with background information
- Multiple memories being stored (retain operations)
- Memories being recalled based on different queries
- Multiple reflection responses with contextual answers
- Server automatically stopping (for context manager tests)
Sample Output
The main test workflow demonstrates:
- Step 1: Create memory bank
- Step 2: Store 5 memories (3 individual + 2 batch)
- Step 3: Recall memories about programming preferences
- Step 4: Recall memories about machine learning
- Step 5: Reflect on tool recommendations
- Step 6: Reflect with additional context about framework choices
- Step 7: Server auto-stops via context manager
Skipping Tests
Tests will automatically skip if:
HINDSIGHT_LLM_API_KEYis not set
Troubleshooting
Test hangs or times out
- Increase timeout:
pytest tests/ --timeout=600 - Check your LLM API key is valid
- Verify network connectivity to LLM provider
Database errors
- The tests use embedded PostgreSQL (
pg0) which should handle cleanup automatically - If you see "database system is shutting down" errors, wait a few seconds and retry
- Between test runs, the embedded database needs time to properly shut down
Port conflicts
- Tests automatically find free ports, so conflicts should be rare
- If you see port binding errors, check for other processes using high-numbered ports