Coverage for node / src / stigmem_conformance / __main__.py: 0%

34 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-25 01:49 +0000

1"""Public runner: ``python -m stigmem_conformance --backend <name>``. 

2 

3Runs the behavioral conformance suite against a stigmem node built on the 

4chosen backend and emits a Markdown report. 

5 

6Examples:: 

7 

8 # In-process (default) — no external services required for sqlite/libsql 

9 python -m stigmem_conformance --backend sqlite 

10 python -m stigmem_conformance --backend libsql 

11 python -m stigmem_conformance --backend postgres --pg-dsn postgresql://localhost/stigmem_test 

12 

13 # Save report for embedding in operator docs 

14 python -m stigmem_conformance --backend sqlite --report conformance-sqlite.md 

15 

16Exit code 0 = all tests passed (skips allowed); 1 = one or more failures. 

17""" 

18 

19from __future__ import annotations 

20 

21import argparse 

22import os 

23import sys 

24from pathlib import Path 

25 

26 

27def main() -> None: 

28 parser = argparse.ArgumentParser( 

29 prog="python -m stigmem_conformance", 

30 description="Run the stigmem multi-backend conformance suite.", 

31 ) 

32 parser.add_argument( 

33 "--backend", 

34 default="sqlite", 

35 choices=["sqlite", "libsql", "postgres"], 

36 help="Storage backend to test (default: sqlite)", 

37 ) 

38 parser.add_argument( 

39 "--pg-dsn", 

40 default="", 

41 help="PostgreSQL DSN, e.g. postgresql://user:pw@localhost/dbname (postgres backend only)", 

42 ) 

43 parser.add_argument( 

44 "--pg-schema", 

45 default="", 

46 help="PostgreSQL schema for table isolation (auto-generated if not set)", 

47 ) 

48 parser.add_argument( 

49 "--report", 

50 default=None, 

51 metavar="PATH", 

52 help="Write Markdown report to this file (default: print to stdout)", 

53 ) 

54 parser.add_argument( 

55 "--plugin-profile", 

56 default="default", 

57 choices=["default", "full"], 

58 help=( 

59 "Plugin install profile: default runs the v1.0 critical path with " 

60 "no plugins; full registers a representative signed plugin set." 

61 ), 

62 ) 

63 parser.add_argument( 

64 "--verbose", "-v", 

65 action="store_true", 

66 help="Verbose pytest output", 

67 ) 

68 args = parser.parse_args() 

69 

70 # Propagate Postgres settings via env vars so the conformance conftest can 

71 # read them without requiring Settings to be importable at this point. 

72 if args.pg_dsn: 

73 os.environ["STIGMEM_TEST_PG_DSN"] = args.pg_dsn 

74 if args.pg_schema: 

75 os.environ["STIGMEM_TEST_PG_SCHEMA"] = args.pg_schema 

76 

77 import pytest 

78 

79 from stigmem_conformance.report import ConformanceReporter 

80 

81 reporter = ConformanceReporter(backend=args.backend) 

82 

83 tests_dir = Path(__file__).parent / "tests" 

84 pytest_args = [ 

85 str(tests_dir), 

86 f"--conformance-backend={args.backend}", 

87 f"--conformance-plugin-profile={args.plugin_profile}", 

88 "--tb=short", 

89 "-p", "no:randomly", 

90 ] 

91 if args.verbose: 

92 pytest_args.append("-v") 

93 

94 ret = pytest.main(pytest_args, plugins=[reporter]) 

95 

96 report_md = reporter.generate_markdown() 

97 if args.report: 

98 Path(args.report).write_text(report_md, encoding="utf-8") 

99 print(f"Report written to {args.report}", file=sys.stderr) 

100 else: 

101 print(report_md) 

102 

103 sys.exit(0 if ret in (0, pytest.ExitCode.NO_TESTS_COLLECTED) else 1) 

104 

105 

106if __name__ == "__main__": 

107 main()