Spaces:
Paused

File size: 2,150 Bytes
b7980f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import asyncio
import uuid
from core.database import async_session_factory
from models.kb_article import KBArticle
from api.v1.kb import _execute_article_indexing_lifecycle
from sqlalchemy import select

async def verify_kb_autocat():
    async with async_session_factory() as db:
        # 1. Create a test article with NO category
        test_id = uuid.uuid4()
        
        # Get a real workspace and author
        ws_id = (await db.execute(select(KBArticle.workspace_id).limit(1))).scalar_one()
        auth_id = (await db.execute(select(KBArticle.author_id).limit(1))).scalar_one()
        
        article = KBArticle(
            id=test_id,
            title="How to Secure Your API Keys",
            content="To secure your API keys, use environment variables and never commit them to version control. Rotate them every 90 days.",
            category=None, # Explicitly missing
            workspace_id=ws_id,
            author_id=auth_id,
            is_published=True
        )
        db.add(article)
        await db.commit()
        
        print(f"CREATED Article {test_id} with category='{article.category}'")
        
        # 2. Manually trigger the indexing lifecycle
        print("TRIGGERING Auto-Categorization Pipeline...")
        try:
            await _execute_article_indexing_lifecycle(db, test_id)
        except Exception as e:
            print(f"PIPELINE CRASHED: {e}")
        
        # 3. Refresh and Inspect
        # We need to expire the session or re-fetch to see background commits
        await db.rollback() # Ensure we don't have stale state
        res = await db.execute(select(KBArticle).where(KBArticle.id == test_id))
        fresh_article = res.scalar_one_or_none()
        
        print(f"FINAL RESULT: Category for {test_id} is now '{fresh_article.category}'")
        
        if fresh_article.category and fresh_article.category not in [None, "N/A", "General"]:
            print("SUCCESS: Auto-categorization is ACTIVE.")
        else:
            print("FAILURE: Multi-Indexing lifecycle did not update the category.")

if __name__ == "__main__":
    asyncio.run(verify_kb_autocat())