powermem icon indicating copy to clipboard operation
powermem copied to clipboard

bug: Real context assembly cleanup violates artifact foreign keys

Open hireview001 opened this issue 1 month ago • 0 comments

Describe the bug

The real context/profile assembly acceptance tests share _cleanup, which deletes scope-bearing tables in inspector order without respecting foreign keys. After a reviewed artifact is persisted, cleanup fails at pc_artifacts. Both tests call this helper in finally, so its exception can hide the original acceptance outcome.

This is an independently reproduced repository test-fixture defect; a production runtime deletion defect is not established.

Steps to reproduce

At commit 0c1dfc289b28e9f529555fb57bf771ce51103913, save the following as test_cleanup_probe.py at the repository root:

import asyncio
from powercontext.builtin.persistence.sqlite import SQLiteConfig
from tests.e2e.test_catalog_changes import seed
from tests.e2e.real_experience_skill.test_context_text_assembly import _cleanup

def test_cleanup_accepts_persisted_reviewed_artifact(tmp_path):
 async def scenario():
  database=SQLiteConfig(url=f'sqlite+aiosqlite:///{tmp_path / "scratch.db"}')
  async with seed(database) as (contexts,scope,source,artifact):
   review=contexts.review(scope)
   candidate=await review.propose_experience(artifact.content,sources=(source,),artifacts=(),target=None,reason='Reproduction')
   await review.approve(candidate.candidate_id,1)
  assert (await _cleanup(database,[scope]))['remaining_rows']==0
 asyncio.run(scenario())

Run with the installed repository test dependencies:

PYTHONPATH=. python -m pytest test_cleanup_probe.py -q --tb=short --junitxml=cleanup.xml

No model provider or remote database is required. The probe uses a fresh temporary SQLite database and the repository's existing seed helper.

Expected behavior

Cleanup succeeds, removes the test scope's data, and returns remaining_rows == 0.

Actual behavior

The executed probe fails (1 failed):

sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) FOREIGN KEY constraint failed
[SQL: DELETE FROM pc_artifacts WHERE scope_id IN (?)]
[SQL parameters hidden due to hide_parameters=True]

The failing shared helper is in tests/e2e/real_experience_skill/test_context_text_assembly.py:481; it is also imported by test_profile_context_assembly.py.

Environment

  • Immutable tested SHA: 0c1dfc289b28e9f529555fb57bf771ce51103913
  • Linux, Python 3.12.13
  • SQLite 3.53.1, SQLAlchemy 2.0.51, aiosqlite 0.22.1
  • Local SQLite execution; no external backend claims

Regression-proof: ca399b0f-bf82-41c3-ae54-98dd9f377e98/4b30973a12eab1dbcb69/cleanup-foreign-key

hireview001 avatar Oct 31 '26 07:10 hireview001