File size: 3,025 Bytes
37c76c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""Quick verification script for the Rules feature implementation."""
import ast, os, sys

all_ok = True

def chk(label, passed):
    global all_ok
    if not passed:
        all_ok = False
    print(('OK  ' if passed else 'FAIL') + ' ' + label)

root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def read(rel):
    return open(os.path.join(root, rel.replace('/', os.sep)), encoding='utf-8').read()

# Python parses
for f in ['routers/rule_requests.py', 'auth/rule_models.py', 'api_server.py']:
    try:
        ast.parse(read(f))
        chk('parse: ' + f, True)
    except SyntaxError as e:
        chk('parse FAIL: ' + f + ' ' + str(e), False)

# Backend content
r = read('routers/rule_requests.py')
for t in [
    'add_keyword', 'move_rule', 'move_category', 'delete_rule', 'delete_category',
    'dest_category_id is required', 'dest_group_name is required',
    'target.category_id = req.dest_category_id', 'cat.sheet_name = req.dest_group_name',
    'An identical request is already pending',
]:
    chk('rule_requests: ' + t[:50], t in r)

m = read('auth/rule_models.py')
for t in ['RuleChangeRequest', 'dest_category_id', 'dest_category_name', 'dest_group_name', 'to_dict']:
    chk('rule_models: ' + t, t in m)

a = read('api_server.py')
for t in ['rule_requests_router', 'auth.rule_models']:
    chk('api_server: ' + t, t in a)

# Frontend files exist
for f in [
    'befree-frontend/features/rules/RulesFeature.tsx',
    'befree-frontend/app/rules/page.tsx',
]:
    chk('exists: ' + f.split('/')[-1], os.path.exists(os.path.join(root, f)))

# Frontend content
fe = read('befree-frontend/features/rules/RulesFeature.tsx')
for t in [
    'RulesFeature', 'AdminRequestsPanel', 'MyRequestsPanel', 'RequestRuleForm',
    'move_rule', 'move_category', 'delete_rule', 'delete_category',
    'fixed inset-0 z-50', 'backdrop-blur-sm', 'selectedGroup', 'handleTypeChange',
    'conflictMessage', 'Destination group', 'Destination category', 'Move to',
    'dest_category_name', 'dest_group_name',
]:
    chk('RulesFeature: ' + t[:40], t in fe)

# Sidebar
sb = read('befree-frontend/components/layout/Sidebar.tsx')
chk('Sidebar: BookOpen', 'BookOpen' in sb)
chk('Sidebar: /rules', '/rules' in sb)

# DB columns (optional — requires DB connection)
try:
    from dotenv import load_dotenv
    load_dotenv(os.path.join(root, '.env'))
    sys.path.insert(0, root)
    from auth.database import engine
    from sqlalchemy import text
    with engine.connect() as conn:
        rows = conn.execute(text(
            "SELECT column_name FROM information_schema.columns "
            "WHERE table_name = 'rule_change_requests' ORDER BY ordinal_position"
        )).fetchall()
        cols = [r[0] for r in rows]
    for col in ['dest_category_id', 'dest_category_name', 'dest_group_name']:
        chk('DB column: ' + col, col in cols)
except Exception as e:
    print('SKIP DB check: ' + str(e))

print()
print('ALL IMPLEMENTED' if all_ok else 'GAPS FOUND — see FAIL lines above')
sys.exit(0 if all_ok else 1)