Files
AgentLab/backend/tests/test_blueprint_template_run.py
T
ThearchyHelios 277982ead3 普通用户建应用(后端):
- 蓝图:bp_* 操作和逐卡白名单、蓝图检查、留痕、按蓝图判权限;五个场景模板加自由形(骨架、关节、应用骨架、定时任务),实例化与骨架比对;BlueprintApplier / TemplateApplier(只收模板声明过的关节)与自查;look 新类别口径卡;蓝图对话和填关节两个流式接口,不同组的关节并行填、出错的组串行重试;模板列表
- 试运行与发布单:四种起点(对话、模板、问数据的一轮、已发布版本);试运行是探索运行,草稿应用按这次运行解析、印章写试运行,流程类派给自己、不触发升级;发布单九步、预检只读、每步留痕、停下后接着做、核对卡片指纹和应用管理权、启动时整理中断的单;白话层覆盖全部问题编号
- 记录表与文件:平台托管只追加的记录表、按高水位固定数据、连接上的临时视图做行级可见、写入走动作(records_append)、表版本在发布时切换、草稿不影响线上、记录列表遮敏感列;文件按哈希存、两步上传、提交时绑定运行、下载按读权限、清理、file_text、按配方导入一期(table_import_period)
- 个人应用:存成个人应用(问数据的约束)、刷新(遮罩、只读、每日上限)、只有拥有者看得见、提交审核与共享副本、开关下发到认人接口;页面编辑的候选;隐藏组件不下发;三条新检查
2026-10-15 12:09:29 +08:00

74 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""场景模板实例化出来的图真的能运行(docs/design/normal-user-apps.md §3.3「实例化 + 检查 + 运行」):周期看板按示例蓝图
实例化、生成关节填上之后,在一个小库上跑一次,口径卡用 cell() 取到格,成果按指标完整出具。库和数字都是编的。
"""
from __future__ import annotations
import asyncio
import sqlite3
import uuid
import pytest
from app.blueprints.instantiate import instantiate
from app.blueprints.templates import _common as c
from app.data.engine import engines
from app.db.base import SessionLocal
from app.db.models import DataSource, Run
from app.engine.runner import run_manager
@pytest.fixture(autouse=True)
async def engine_up():
await run_manager.setup()
yield
await run_manager.shutdown()
@pytest.fixture
async def shop(tmp_path):
path = tmp_path / "shop.db"
with sqlite3.connect(path) as db:
db.executescript("CREATE TABLE orders (id INTEGER PRIMARY KEY, amount REAL, paid_at TEXT, refunded INTEGER);")
db.executemany("INSERT INTO orders VALUES (?, ?, ?, ?)", [
(1, 100.0, "2026-10-05", 0), (2, 300.0, "2026-10-08", 1), (3, 600.0, "2026-10-11", 0),
(4, 999.0, "2026-10-12", 0)]) # 统计期外
name = f"bprun_{uuid.uuid4().hex[:6]}"
async with SessionLocal() as session:
row = DataSource(name=name, kind="sqlite", database=str(path), readonly=True, enabled=True)
session.add(row)
await session.commit()
source_id = row.id
yield name
async with SessionLocal() as session:
await session.delete(await session.get(DataSource, source_id))
await session.commit()
await engines.invalidate(source_id)
async def test_the_board_template_runs_and_issues_by_metrics(shop):
from app.blueprints.templates._common import safe_id
extras = c.EXTRAS["periodic_board"]
spec = extras.example()
for item in spec["data"]:
item["table"]["value"]["source"] = shop
node = f"fetch_{safe_id(shop)}"
fill = {k.replace("fetch_shop", node): v.replace("fetch_shop", node) for k, v in extras.example_fill().items()}
inst = instantiate(spec, filled=fill)
assert inst.problems == []
run = await run_manager.start(graph=inst.graph, input_payload={
"period": "2026-W41", "period_start": "2026-10-05", "period_end": "2026-10-11"})
for _ in range(400):
await asyncio.sleep(0.05)
async with SessionLocal() as session:
row = await session.get(Run, run.id)
if row.status in ("succeeded", "failed") and row.manifest_seq is not None:
break
assert row.status == "succeeded", row.error
output = row.output or {}
issuance = output["_issuance"]
assert (issuance["tier"], issuance["mode"]) == ("formal", "metrics"), issuance
# 销售额不含已退款的那一单;订单数、退款率按全部订单
assert output["销售额(元)"] == "700.0" and output["订单数(单)"] == "3"
assert output["退款率(%)"] == "33.33"