M1 最小闭环:CLI + FastAPI 网关 + SQL 闸 + 100% 覆盖率验收链
- CLI:init/serve/update/query/export/status(typer + rich),单写者锁三元判活 - 存储:DuckDB schema migrations(14 表 + 8 联邦视图,语句元组逐条执行) - ETL:A股证券/日历/日K,整区替换幂等;日历全年补全(calendar 语义唯一) - 网关:POST /v1/query(线程池 + interrupt 超时 504)、/v1/export、meta/stats/state、healthz/ready - 安全:SQL 闸 sqlglot fail-closed(文件/网络表函数默认拒)、非 loopback 空 token 拒启、导出路径双判 - 验收:254 测试全绿、1265 语句 100% 覆盖、[CI] 真起服验收链、smoke_m1.py 交付自检 - 文档:设计文档 v0.7(圆桌 45 条采纳 + 3 条实施校准),README 重写 - 发布:release.yml Trusted Publishing(OIDC 免密钥),action refs 已核验
This commit is contained in:
commit
d37c697bbe
59 files changed
+7586
No files matched your search
@@ -0,0 +1,52 @@
|
||||
"""store/db.py:连接管理、只读约束、查询连接安全预设。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from pyquantdata.store import CatalogNotInitialized, open_catalog
|
||||
from pyquantdata.store.db import configure_query_conn
|
||||
|
||||
|
||||
def test_open_read_only_uninitialized_raises(tmp_path):
|
||||
with pytest.raises(CatalogNotInitialized):
|
||||
open_catalog(tmp_path, read_only=True)
|
||||
|
||||
|
||||
def test_open_write_creates_catalog(layout):
|
||||
conn = open_catalog(layout.root)
|
||||
conn.execute("SELECT 1")
|
||||
conn.close()
|
||||
|
||||
|
||||
def test_configure_query_conn_sets_guards(catalog):
|
||||
configure_query_conn(catalog, memory_limit="1GB")
|
||||
autoinstall = catalog.execute(
|
||||
"SELECT current_setting('autoinstall_known_extensions')"
|
||||
).fetchone()[0]
|
||||
autoload = catalog.execute(
|
||||
"SELECT current_setting('autoload_known_extensions')"
|
||||
).fetchone()[0]
|
||||
assert autoinstall in ("false", False)
|
||||
assert autoload in ("false", False)
|
||||
mem = catalog.execute("SELECT current_setting('memory_limit')").fetchone()[0]
|
||||
# duckdb 会把 1GB 规范化显示(如 '953.6 MiB');断言数值≈1GiB 而非字面量
|
||||
import re as _re
|
||||
|
||||
m = _re.match(r"([\d.]+)\s*(KiB|MiB|GiB|KB|MB|GB)", str(mem))
|
||||
assert m, mem
|
||||
val, unit = float(m.group(1)), m.group(2)
|
||||
gib = val / 1024 if unit in ("MiB", "MB") else val
|
||||
assert 0.9 <= gib <= 1.1, mem
|
||||
|
||||
|
||||
def test_read_only_blocks_write(layout):
|
||||
conn = open_catalog(layout.root)
|
||||
from pyquantdata.store import migrate
|
||||
|
||||
migrate(conn)
|
||||
conn.close()
|
||||
ro = open_catalog(layout.root, read_only=True)
|
||||
with pytest.raises(Exception):
|
||||
ro.execute("CREATE TABLE nope (a INT)")
|
||||
ro.close()
|
||||
Reference in new issue
Block a user