Files
metabuilder/txt/dbal-test-results-20260206-142129.md
2026-03-09 22:30:41 +00:00

8.7 KiB

DBAL C++ Daemon Integration Test Results

Date: 2026-02-06 14:21 UTC Location: /Users/rmac/Documents/metabuilder/dbal/production/tests/integration Daemon Version: v1.0.0 Test Framework: pytest 9.0.2

Executive Summary

Result: 6/17 tests passing (35.3%) - MATCHES BASELINE Status: Health endpoints working, entity endpoints causing daemon crash Critical Issue: Daemon crashes on first entity endpoint request

Test Results by Category

TestHealthEndpoints (6/6 PASSING - 100%)

All health, version, and status endpoints working correctly:

  1. test_health_endpoint_returns_200 - PASSED
  2. test_health_endpoint_json_format - PASSED
  3. test_version_endpoint_returns_200 - PASSED
  4. test_version_endpoint_json_format - PASSED
  5. test_status_endpoint_returns_200 - PASSED
  6. test_status_endpoint_has_server_info - PASSED

Endpoints Verified:

  • GET /health{"service":"dbal","status":"healthy"}
  • GET /version → Returns version info
  • GET /status → Returns server status with metadata

TestEntityEndpoints (0/4 PASSING - 0%)

All entity tests fail with daemon crash:

  1. test_list_users_endpoint - DAEMON CRASH

    • Request: GET /api/v1/test-tenant/core/user
    • Error: RemoteDisconnected('Remote end closed connection without response')
    • Cause: Daemon crashes on first entity request
  2. test_create_user_endpoint - DAEMON ALREADY CRASHED

    • Request: POST /api/v1/test-tenant/core/user
    • Error: ConnectionRefusedError: [Errno 111] Connection refused
    • Cause: Daemon crashed from previous test
  3. test_invalid_tenant_returns_error - DAEMON ALREADY CRASHED

    • Request: GET /api/v1/invalid-tenant/core/user
    • Error: Connection refused (daemon down)
  4. test_invalid_entity_returns_error - DAEMON ALREADY CRASHED

    • Request: GET /api/v1/test-tenant/core/nonexistent
    • Error: Connection refused (daemon down)

TestConcurrency (0/2 PASSING - 0%)

  1. test_concurrent_health_checks - DAEMON ALREADY CRASHED

    • 10 parallel requests to /health
    • Error: Connection refused (daemon down from entity tests)
  2. test_concurrent_status_checks - DAEMON ALREADY CRASHED

    • 10 parallel requests to /status
    • Error: Connection refused (daemon down)

TestErrorHandling (0/3 PASSING - 0%)

  1. test_404_on_unknown_endpoint - DAEMON ALREADY CRASHED

    • Request: GET /nonexistent
    • Error: Connection refused
  2. test_invalid_json_in_post - DAEMON ALREADY CRASHED

    • Request: POST /api/v1/test-tenant/core/user with malformed JSON
    • Error: Connection refused
  3. test_options_request_handling - DAEMON ALREADY CRASHED

    • Request: OPTIONS /api/v1/test-tenant/core/user
    • Error: Connection refused

TestResponseHeaders (0/2 PASSING - 0%)

  1. test_content_type_json - DAEMON ALREADY CRASHED

    • Verify Content-Type: application/json header
    • Error: Connection refused
  2. test_response_has_server_header - DAEMON ALREADY CRASHED

    • Verify Server: dbal/1.0.0 header
    • Error: Connection refused

Comparison to Baseline

CLAUDE.md Baseline (Feb 5, 2026): 6/17 passing Current Result: 6/17 passing

Status: ⚠️ NO IMPROVEMENT - Same baseline failures

The baseline correctly identified the Drogon routing issue:

Blocker: Drogon route matching for /{tenant}/{package}/{entity} - handlers implemented but not called

Root Cause Analysis

Critical Issue: Daemon Crash on Entity Requests

Symptom: Daemon process terminates immediately when receiving first entity endpoint request

Evidence:

  1. Health endpoints (/health, /version, /status) work perfectly
  2. First entity request (GET /api/v1/test-tenant/core/user) causes:
    • RemoteDisconnected: Remote end closed connection without response
    • Daemon process terminates (no longer responds to ps aux | grep dbal)
  3. All subsequent tests fail with Connection refused (daemon is down)
  4. Daemon log shows no crash dump, just stops after "Daemon mode: Running in background"

Likely Causes:

  1. Drogon Route Matching Issue (documented in CLAUDE.md):

    • Pattern /{tenant}/{package}/{entity} not matching requests
    • Handler is implemented but never called
    • May need regex patterns or different syntax
  2. Unhandled Exception in Route Handler:

    • C++ exception thrown but not caught
    • Terminates process instead of returning error response
    • No try/catch blocks around handler logic
  3. SQLite Adapter Initialization:

    • Adapter may not be fully initialized when first request arrives
    • Accessing uninitialized database connection
    • Memory corruption or segfault
  4. Missing YAML Schema Files:

    • EntitySchemaLoader trying to load from disk
    • DBAL_SCHEMA_DIR environment variable not set
    • File not found exception crashes daemon

Daemon Configuration

Startup Command:

./build/dbal_daemon --bind 0.0.0.0 --port 8080 --daemon

Environment Variables (from CLAUDE.md):

  • DBAL_SCHEMA_DIR: Path to YAML entity schemas (REQUIRED)
  • DBAL_TEMPLATE_DIR: Path to SQL Jinja2 templates (REQUIRED)
  • DATABASE_URL: :memory: (SQLite in-memory)

Issue: Daemon may be missing required env vars, causing schema load failure

Actionable Next Steps

Priority 1: Prevent Daemon Crash (CRITICAL)

  1. Add Global Exception Handler:

    try {
        // Route handler logic
    } catch (const std::exception& e) {
        LOG_ERROR << "Exception in route handler: " << e.what();
        return error_response(500, e.what());
    }
    
  2. Set Required Environment Variables:

    export DBAL_SCHEMA_DIR=/workspace/dbal/shared/api/schema/entities
    export DBAL_TEMPLATE_DIR=/workspace/dbal/production/templates/sql
    ./build/dbal_daemon --bind 0.0.0.0 --port 8080 --daemon
    
  3. Enable Core Dumps:

    ulimit -c unlimited
    ./build/dbal_daemon --bind 0.0.0.0 --port 8080
    

    (Run without --daemon to see crash output on terminal)

Priority 2: Fix Drogon Routing (HIGH)

  1. Check Drogon Path Parameter Syntax:

    • Current: app().registerHandler("/{tenant}/{package}/{entity}", ...)
    • Try: app().registerHandler("/api/v1/{1}/{2}/{3}", ...)
    • Or: app().registerHandler("/api/v1/(.*?)/(.*?)/(.*?)", ...)
  2. Add Route Debugging:

    LOG_DEBUG << "Registering route: /api/v1/{tenant}/{package}/{entity}";
    LOG_DEBUG << "Request received: " << req->path();
    
  3. Test with Simpler Route:

    app().registerHandler("/test/{tenant}", 
        [](const HttpRequestPtr& req, 
           std::function<void(const HttpResponsePtr&)>&& callback) {
        // Test if path parameters work at all
    }, {Get});
    

Priority 3: Add Logging (HIGH)

  1. Log Request Entry:

    LOG_INFO << "Entity list request: tenant=" << tenant 
             << " package=" << package << " entity=" << entity;
    
  2. Log SQLite Operations:

    LOG_DEBUG << "Executing SQL: " << sql_query;
    LOG_DEBUG << "SQLite result: " << rc;
    
  3. Run Daemon in Foreground (for debugging):

    ./build/dbal_daemon --bind 0.0.0.0 --port 8080
    # (Remove --daemon flag to see stdout/stderr)
    

Priority 4: Schema Loading Verification (MEDIUM)

  1. Check Schema Files Exist:

    ls -la /workspace/dbal/shared/api/schema/entities/core/user.yaml
    ls -la /workspace/dbal/production/templates/sql/*.sql.j2
    
  2. Test EntitySchemaLoader Standalone:

    // Add test harness
    int main() {
        EntitySchemaLoader loader;
        auto schema = loader.loadSchema("user");
        std::cout << "Loaded schema: " << schema.name << std::endl;
    }
    

Test Environment Details

Container: metabuilder-dev (dockerconan-dev) OS: Ubuntu 22.04 (inside Docker) Python: 3.10.12 Daemon Process: PID 22456 (until crash) Port: 8080 (bound to 0.0.0.0) Database: SQLite :memory:

Test Execution:

docker exec metabuilder-dev bash -c "
  cd /workspace/dbal/production/tests/integration && 
  pytest test_api_endpoints.py -v --tb=short
"

Conclusion

Status: Same baseline as CLAUDE.md (6/17 passing) Blocker: Daemon crashes on entity endpoint requests Impact: 65% of tests cannot run (11/17 blocked by crash)

Recommendations:

  1. Run daemon in foreground mode (remove --daemon) to see crash output
  2. Set DBAL_SCHEMA_DIR and DBAL_TEMPLATE_DIR environment variables
  3. Add try/catch exception handlers to all route handlers
  4. Investigate Drogon path parameter syntax for wildcard routes
  5. Enable core dumps or run under gdb to get stack trace

Next Action: Debug daemon crash with foreground mode and proper env vars before attempting further fixes.