Add test suite, fix three import-time bugs, target Python 3.12/3.13#7
Merged
Conversation
Tests (46, passing on CPython 3.12 and 3.13): - SMK quantization boundaries and feature extraction (tool-mask OR, bucket mapping) - Model invariants: to_rust_args positional order (guards the Rust FFI contract), unit-interval bounds, frozen candidates - Storage settings: DSN construction, override sanitization - MemorySystem orchestration with protocol fakes: remember fan-out (STM TTL expiry, LTM upsert, index ingest, WM event), recall aggregation, optional STM/assistant paths - RedisWorkingMemory against an in-memory fake client (timestamping, TTL, limit semantics, per-user partitioning) - Real Rust engine round trips (built via maturin): vector search ranking, per-user isolation, remove/mark_accessed, SMK assistant index topic/tool filtering and id->uid mapping; auto-skips when the extension is absent Bug fixes the tests surfaced: - pydantic-settings was imported (config.py, storage/settings.py) but never declared as a dependency: clean installs crashed on import - storage/database.py imported datetime under TYPE_CHECKING while SQLAlchemy needs it at runtime to resolve Mapped[datetime]: importing the package raised MappedAnnotationError - core/models.py imported the SMK enums under TYPE_CHECKING while they are pydantic field types: AssistantMemoryTrace was permanently "not fully defined", breaking the entire assistant-memory feature Packaging: pytest-asyncio in dev extras, pytest config (testpaths, pythonpath, asyncio auto), 3.12/3.13 classifiers, .python-version pinned to the preferred 3.13. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016erjEoxcmpDXDVGqaqf7Xt
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request adds a comprehensive Python test suite for memory_core_py and uses it to identify/fix three import-time failures that prevented clean installs and key subsystems from working, while explicitly targeting Python 3.12/3.13 for development and packaging.
Changes:
- Added a new pytest suite (46 tests) covering SMK feature extraction, settings DSN/override behavior,
MemorySystemorchestration, Redis working memory behavior, and optional Rust-extension round trips. - Fixed import-time issues by making required types available at runtime (SQLAlchemy
Mapped[datetime]and Pydantic enum field types). - Updated packaging/dev dependencies and pytest configuration (adds
pydantic-settingsandpytest-asyncio, pins preferred Python via.python-version).
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
uv.lock |
Locks in pydantic-settings and pytest-asyncio to support runtime settings imports and async tests. |
pyproject.toml |
Declares new dependencies/extras, adds 3.12/3.13 classifiers, and configures pytest + asyncio mode. |
.python-version |
Pins preferred local interpreter to Python 3.13. |
memory_core_py/storage/database.py |
Fixes SQLAlchemy annotation resolution by importing datetime at runtime. |
memory_core_py/core/models.py |
Fixes Pydantic model completeness by importing SMK enums at runtime. |
tests/conftest.py |
Adds shared fakes/fixtures for storage/index/working-memory tests without external services. |
tests/test_models.py |
Adds invariants/contract tests for Pydantic models and Rust-FFI argument ordering. |
tests/test_settings.py |
Adds DSN construction and override-sanitization tests for storage settings. |
tests/test_smk.py |
Adds SMK quantization and feature-extraction tests, including tool-mask behavior. |
tests/test_system.py |
Adds orchestration tests for MemorySystem remember/recall and assistant paths. |
tests/test_working_memory.py |
Adds async tests validating Redis working-memory semantics using an in-memory fake client. |
tests/test_rust_engine.py |
Adds integration tests that exercise the real Rust bindings when available (auto-skipped otherwise). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Magic-Man-us
pushed a commit
that referenced
this pull request
Jul 20, 2026
Main's PR #7 independently fixed the same three import-time bugs (runtime datetime in storage/database.py, runtime SMK enums in core/models.py, undeclared pydantic-settings) in the old memory_core_py layout and added a 46-test suite for the Redis/MariaDB architecture. This branch had already replaced that architecture, so the merge keeps the SQL-only layout and ports everything portable from main: - adopted: 3.12/3.13 classifiers, .python-version (3.13), pytest-asyncio fixture-loop-scope config, the explanatory noqa: TC001 comment on the runtime enum imports, pydantic-settings>=2.6 floor - ported to the new layout: SMK quantization/feature tests, Rust-engine wrapper round trips (ranking, isolation, remove/mark_accessed, id->uid mapping, topic/tool filters), model invariants (frozen candidates, unit-interval bounds, to_rust_args order), remember/recall skip flags, make_trace/make_assistant_trace factories - dropped with the old architecture: Redis working-memory tests and fake client, MySQL DSN settings tests, protocol-fake orchestration tests now covered end-to-end against real SQLite + the real index 59 tests pass; ruff clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018W7Afhk8WCxZcHtwj3dYHH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a 46-test suite (passing on CPython 3.12 and 3.13), which immediately surfaced and fixed three real import-time bugs — two of which made whole subsystems unusable. No CI workflow is included, per preference; run locally with
uv sync --extra dev && uv run pytest(the sync builds the Rust extension via maturin).Bugs found by the tests (fixed here)
pydantic-settings— imported byconfig.pyandstorage/settings.pybut never declared, so any clean install crashed withModuleNotFoundErroronimport memory_core_py. Added todependencies.storage/database.py:datetimeimported underTYPE_CHECKINGonly — SQLAlchemy resolvesMapped[datetime]annotations at class-declaration time, so importing the package raisedMappedAnnotationError. Moved to a runtime import with a comment explaining why it must stay.core/models.py: SMK enums (TopicBucket,MemoryKind,ToolFlag) imported underTYPE_CHECKINGonly — they're Pydantic field types onAssistantMemoryTrace, leaving the model permanently "not fully defined" (PydanticUserError) and breaking the entire assistant-memory/SMK feature on first construction.Test coverage
_quantize_levelat 0.25/0.5/0.75 edges),build_smk_featurestool-mask OR-composition and scalar→bucket mapping.MemoryTrace.to_rust_args()exact positional order and types (guards the Rust FFI contract the code comments call out), unit-interval bounds onAssistantMemoryTrace, frozenMemoryCandidate.apply_overridessanitization (unknown keys andNonevalues dropped; no-op returns the same instance).MemorySystemorchestration (protocol fakes, no MariaDB/Redis needed) —rememberfan-out: STM insert withcreated_at + ttlexpiry, LTM upsert, index ingest, working-memory event,also_working_mem=False, optional STM;recallaggregation of LTM/WM/STM layers with the include toggle; assistant paths no-op without an index.RedisWorkingMemory— against an in-memory fake client: timestamp stamping, TTL application,lrange(-limit, -1)recency semantics, per-user partitioning.pytest.importorskip("memory_core"), so it auto-skips where the extension isn't built) —RustMemoryIndexingest/search ranking, per-user isolation,remove/mark_accessed;AssistantMemoryIndexid→trace_uid mapping, topic filtering, and required-tools mask filtering throughPySmkQuery.Packaging
requires-pythonstays>=3.12;.python-versionpins the preferred 3.13; 3.12/3.13 trove classifiers added.pytest-asyncioadded to thedevextra;[tool.pytest.ini_options]configurestestpaths,pythonpath=["."], and asyncio auto mode.uv.lockregenerated for the dependency fix.Verified by building the extension and running the full suite on both interpreters: 46 passed on 3.12.3 and on 3.13.12.
🤖 Generated with Claude Code
https://claude.ai/code/session_016erjEoxcmpDXDVGqaqf7Xt
Generated by Claude Code