Files
metabuilder/dbal/scripts/test.py
johndoe6345789 49f40177b5 Generated by Spark: I was thinking more like this, you can replace python with ts if you like: dbal/
README.md
  LICENSE
  AGENTS.md

  api/                          # Language-agnostic contract (source of truth)
    schema/
      entities/                 # Entity definitions (conceptual models)
        user.yaml
        session.yaml
        ...
      operations/               # CRUD + domain operations (semantic, not SQL)
        user.ops.yaml
        ...
      errors.yaml               # Standard error codes (conflict, not_found, etc.)
      capabilities.yaml         # Feature flags per backend (tx, joins, ttl, etc.)
    idl/
      dbal.proto                # Optional: RPC/IPC contract if needed
      dbal.fbs                  # Optional: FlatBuffers schema if you prefer
    versioning/
      compat.md                 # Compatibility rules across TS/C++

  common/                       # Shared test vectors + fixtures + golden results
    fixtures/
      seed/
      datasets/
    golden/
      query_results/
    contracts/
      conformance_cases.yaml

  ts/                           # Development implementation in TypeScript
    package.json
    tsconfig.json
    src/
      index.ts                  # Public entrypoint (creates client)
      core/
        client.ts               # DBAL client facade
        types.ts                # TS types mirroring api/schema
        errors.ts               # Error mapping to api/errors.yaml
        validation/             # Runtime validation (zod/io-ts/etc.)
          input.ts
          output.ts
        capabilities.ts         # Capability negotiation
        telemetry/
          logger.ts
          metrics.ts
          tracing.ts
      adapters/                 # Backend implementations (TS)
        prisma/
          index.ts
          prisma_client.ts      # Wraps Prisma client (server-side only)
          mapping.ts            # DB <-> entity mapping, select shaping
          migrations/           # Optional: Prisma migration helpers
        sqlite/
          index.ts
          sqlite_driver.ts
          schema.ts
          migrations/
        mongodb/
          index.ts
          mongo_driver.ts
          schema.ts
      query/                    # Query builder / AST (no backend leakage)
        ast.ts
        builder.ts
        normalize.ts
        optimize.ts
      runtime/
        config.ts               # DBAL config (env, URLs, pool sizes)
        secrets.ts              # Secret loading boundary (server-only)
      util/
        assert.ts
        retry.ts
        backoff.ts
        time.ts
    tests/
      unit/
      integration/
      conformance/              # Runs common/contract vectors on TS adapters
      harness/
        setup.ts

  cpp/                          # Production implementation in C++
    CMakeLists.txt
    include/
      dbal/
        dbal.hpp                # Public API
        client.hpp              # Facade
        types.hpp               # Entity/DTO types
        errors.hpp
        capabilities.hpp
        telemetry.hpp
        query/
          ast.hpp
          builder.hpp
          normalize.hpp
        adapters/
          adapter.hpp           # Adapter interface
          sqlite/
            sqlite_adapter.hpp
          mongodb/
            mongodb_adapter.hpp
          prisma/
            prisma_adapter.hpp  # Usually NOT direct; see note below
        util/
          expected.hpp
          result.hpp
          uuid.hpp
    src/
      client.cpp
      errors.cpp
      capabilities.cpp
      telemetry.cpp
      query/
        ast.cpp
        builder.cpp
        normalize.cpp
      adapters/
        sqlite/
          sqlite_adapter.cpp
          sqlite_pool.cpp
          sqlite_migrations.cpp
        mongodb/
          mongodb_adapter.cpp
          mongo_pool.cpp
        prisma/
          prisma_adapter.cpp    # See note below (often an RPC bridge)
      util/
        uuid.cpp
        backoff.cpp
    tests/
      unit/
      integration/
      conformance/              # Runs common/contract vectors on C++ adapters
      harness/
        main.cpp

  backends/                     # Backend-specific assets not tied to one lang
    sqlite/
      schema.sql
      migrations/
    mongodb/
      indexes.json
    prisma/
      schema.prisma
      migrations/

  tools/                        # Codegen + build helpers (prefer Python)
    codegen/
      gen_types.py              # api/schema -> ts/core/types.ts and cpp/types.hpp
      gen_errors.py
      gen_capabilities.py
    conformance/
      run_all.py                # runs TS + C++ conformance suites
    dev/
      lint.py
      format.py

  scripts/                      # Cross-platform entrypoints (Python per your pref)
    build.py
    test.py
    conformance.py
    package.py

  dist/                         # Build outputs (gitignored)
  .github/
    workflows/
      ci.yml

  .gitignore
  .editorconfig
2025-12-24 20:13:18 +00:00

105 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""
Test runner for DBAL
Runs unit tests, integration tests, and conformance tests
"""
import subprocess
import sys
from pathlib import Path
import argparse
def test_typescript(root_dir: Path, test_type: str = 'all') -> bool:
"""Run TypeScript tests"""
print(f"\n=== Running TypeScript {test_type} Tests ===")
ts_dir = root_dir / 'ts'
test_commands = {
'unit': ['npm', 'run', 'test:unit'],
'integration': ['npm', 'run', 'test:integration'],
'all': ['npm', 'test']
}
try:
subprocess.run(test_commands[test_type], cwd=ts_dir, check=True)
print(f"✓ TypeScript {test_type} tests passed")
return True
except subprocess.CalledProcessError:
print(f"✗ TypeScript {test_type} tests failed", file=sys.stderr)
return False
def test_cpp(root_dir: Path, test_type: str = 'all') -> bool:
"""Run C++ tests"""
print(f"\n=== Running C++ {test_type} Tests ===")
build_dir = root_dir / 'cpp' / 'build'
if not build_dir.exists():
print("✗ C++ build directory not found. Run build.py first.", file=sys.stderr)
return False
test_executables = {
'unit': ['./unit_tests'],
'integration': ['./integration_tests'],
'all': ['ctest', '--output-on-failure']
}
try:
subprocess.run(test_executables[test_type], cwd=build_dir, check=True)
print(f"✓ C++ {test_type} tests passed")
return True
except subprocess.CalledProcessError:
print(f"✗ C++ {test_type} tests failed", file=sys.stderr)
return False
def test_conformance(root_dir: Path) -> bool:
"""Run conformance tests"""
print("\n=== Running Conformance Tests ===")
conformance_script = root_dir / 'tools' / 'conformance' / 'run_all.py'
try:
subprocess.run(['python3', str(conformance_script)], check=True)
print("✓ Conformance tests passed")
return True
except subprocess.CalledProcessError:
print("✗ Conformance tests failed", file=sys.stderr)
return False
def main():
parser = argparse.ArgumentParser(description='Run DBAL tests')
parser.add_argument('--type', default='all', choices=['unit', 'integration', 'conformance', 'all'],
help='Type of tests to run')
parser.add_argument('--lang', default='all', choices=['ts', 'cpp', 'all'],
help='Language implementation to test')
args = parser.parse_args()
root_dir = Path(__file__).parent.parent
print("DBAL Test Runner")
print("=" * 60)
success = True
if args.type == 'conformance' or args.type == 'all':
success = test_conformance(root_dir) and success
else:
if args.lang in ['ts', 'all']:
success = test_typescript(root_dir, args.type) and success
if args.lang in ['cpp', 'all']:
success = test_cpp(root_dir, args.type) and success
if success:
print("\n✓ All tests passed!")
return 0
else:
print("\n✗ Some tests failed", file=sys.stderr)
return 1
if __name__ == '__main__':
sys.exit(main())