mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-25 04:03:13 +00:00
合入 W1-b 已知遗留:人工驳回记成已取消 + end_reason=rejected(不重试、不被出错时继续吞掉),各处照实写「被驳回」;个人渠道「我发起的实例完成 / 失败」生效;导入清单如实记「是否认证」;使用者选人按候选池、开登录时服务端核对;自由形蓝图按导入的图列「谁来做」;tick 按 id 断言
This commit is contained in:
@@ -2361,7 +2361,7 @@ def _manifest(*, staging_id: str, kind: str, source_id: str, info: table_version
|
||||
ex_dict: dict[str, Any], file: dict[str, Any], recipe_meta: dict[str, Any], checks: list[dict[str, Any]],
|
||||
overrides: list[dict[str, Any]], waivers: list[dict[str, Any]], confirmed: list[dict[str, Any]],
|
||||
notes: SchemaNotes, ai: dict[str, Any], signed_by: str | None,
|
||||
edits: list[dict[str, Any]] | None = None) -> dict[str, Any]:
|
||||
edits: list[dict[str, Any]] | None = None, signer_verified: bool = False) -> dict[str, Any]:
|
||||
receipt = copy.deepcopy(ex_dict)
|
||||
receipt.pop("problems", None)
|
||||
return {
|
||||
@@ -2383,7 +2383,8 @@ def _manifest(*, staging_id: str, kind: str, source_id: str, info: table_version
|
||||
"ai": ai,
|
||||
# 期 3:修复、框选的修改记录(含已被整份替换覆盖的,作为历史;不带撤销用的修改前起点)
|
||||
"edits": copy.deepcopy(list(edits or [])),
|
||||
"signed_by": {"name": signed_by, "verified": False},
|
||||
# 是否认证照实记(05-已知遗留 (c)):开了登录、署名是登录的人时为真。以前写死 False,封存的证据记错了事实
|
||||
"signed_by": {"name": signed_by, "verified": bool(signer_verified and signed_by)},
|
||||
"staging_id": staging_id, "kind": kind,
|
||||
"created_at": _now_iso(),
|
||||
}
|
||||
@@ -2411,7 +2412,8 @@ def _file_sha(path: Path) -> str | None:
|
||||
|
||||
|
||||
async def commit_staging(session: AsyncSession, staging: ImportStaging, *, trial_id: str, confirmations: list[str],
|
||||
acceptances: list[Acceptance], signed_by: str | None) -> CommitResult:
|
||||
acceptances: list[Acceptance], signed_by: str | None,
|
||||
signer_verified: bool = False) -> CommitResult:
|
||||
"""POST imports/{id}/commit(7.8):预检 → (与现行导入相同时)不新建记录 → 发布构建、写配方、导入记录、
|
||||
快照、清单,切指针。失败时指针不动,暂存区退回 drafting(试运行库已被发布流程消耗)。
|
||||
|
||||
@@ -2532,6 +2534,8 @@ async def commit_staging(session: AsyncSession, staging: ImportStaging, *, trial
|
||||
|
||||
ex = extraction_from_dict(ex_dict)
|
||||
who = signed_by or staging.signed_by
|
||||
# 署名是这次请求的(signed_by)才谈得上认证;退回暂存区上记的那个,是否认证这里不知道,照实记未认证
|
||||
who_verified = bool(signer_verified and signed_by)
|
||||
acc = [Acceptance(check_id=a.check_id, reason=a.reason.strip(), signed_by=who) for a in given.values()]
|
||||
# 这一期自己的说明(带实际的接受)进它的导入清单:版本页逐期显示「改写后的那一句」从这里取(第 5 节)。
|
||||
# 快照冻结的说明在多期时另按各期最弱的结论合并(2.8),只剩本期时就是它
|
||||
@@ -2603,7 +2607,8 @@ async def commit_staging(session: AsyncSession, staging: ImportStaging, *, trial
|
||||
file={"name": file_name, "size": file_size, "raw_sha256": raw_sha},
|
||||
recipe_meta={"id": recipe_id, "sha256": recipe_sha, "origin": origin, "canonical": canonical},
|
||||
checks=checks_full, overrides=overrides, waivers=waivers, confirmed=confirmed,
|
||||
notes=notes if union_info is None else period_notes, ai=ai, signed_by=who, edits=edits)
|
||||
notes=notes if union_info is None else period_notes, ai=ai, signed_by=who, edits=edits,
|
||||
signer_verified=who_verified)
|
||||
|
||||
async def schema_cache_for(view: table_versions.SourceView, info: table_versions.PublishInfo) -> dict[str, Any]:
|
||||
from app.core import artifact_store
|
||||
@@ -2663,7 +2668,7 @@ async def commit_staging(session: AsyncSession, staging: ImportStaging, *, trial
|
||||
"table_hashes": dict(union_report.get("table_hashes") or {}), "union_ver": recipe_types.UNION_VER},
|
||||
parts=ordered, report=union_report, label_sets=list((plan or {}).get("label_sets") or []),
|
||||
gaps=list((plan or {}).get("gaps") or []), replaced=(plan or {}).get("replaces"), removed=None,
|
||||
notes=notes, signed_by=who)
|
||||
notes=notes, signed_by=who, signer_verified=who_verified)
|
||||
smid = await artifact_store.put_json(doc, kind="snapshot_manifest",
|
||||
meta={"source_id": source_id, "snapshot_id": info.snapshot_id})
|
||||
cache["import_manifests"] = [mid if iid is None else by_imp[iid].info.manifest_artifact
|
||||
|
||||
@@ -110,6 +110,16 @@ def load_manifest(artifact_id: str | None) -> dict[str, Any] | None:
|
||||
return doc if isinstance(doc, dict) else None
|
||||
|
||||
|
||||
def _signer_verified(artifact_id: str | None) -> bool:
|
||||
"""导入清单里记下的「署名是否认证」;没有清单(简单导入)、读不出来的照实算未认证。"""
|
||||
try:
|
||||
doc = load_manifest(artifact_id)
|
||||
except ValueError:
|
||||
return False
|
||||
signer = (doc or {}).get("signed_by")
|
||||
return bool(signer.get("verified")) if isinstance(signer, dict) else False
|
||||
|
||||
|
||||
def _rows_of(report: dict[str, Any] | None) -> dict[str, int]:
|
||||
"""构建回执里各表的行数(执行器回执、期 1 的解析回执都是 tables: [{name, rows}])。"""
|
||||
out: dict[str, int] = {}
|
||||
@@ -394,7 +404,7 @@ def columns_doc(report: dict[str, Any], periods: list[str]) -> dict[str, dict[st
|
||||
def manifest_doc(*, source_id: str, snapshot_id: str, action: str, recipe: dict[str, Any],
|
||||
union: dict[str, Any], parts: list[Part | dict[str, Any]], report: dict[str, Any],
|
||||
label_sets: list[Any], gaps: list[dict[str, str]], replaced: Any, removed: Any,
|
||||
notes: SchemaNotes, signed_by: str | None) -> dict[str, Any]:
|
||||
notes: SchemaNotes, signed_by: str | None, signer_verified: bool = False) -> dict[str, Any]:
|
||||
"""快照清单(2.9)。parts 按统计期排序,与 report.part_rows 同序;本期写成 dict(导入记录还没落库)。"""
|
||||
part_rows = report.get("part_rows") or []
|
||||
keys = []
|
||||
@@ -422,7 +432,8 @@ def manifest_doc(*, source_id: str, snapshot_id: str, action: str, recipe: dict[
|
||||
"checks": copy.deepcopy(report.get("checks") or []),
|
||||
"notes": {"templates": dict(notes.templates),
|
||||
"rendered": {t: {"comment": n.comment, "columns": dict(n.columns)} for t, n in notes.tables.items()}},
|
||||
"signed_by": {"name": signed_by, "verified": False},
|
||||
# 是否认证照实记(05-已知遗留 (c),同导入清单)
|
||||
"signed_by": {"name": signed_by, "verified": bool(signer_verified and signed_by)},
|
||||
"created_at": utcnow().isoformat(),
|
||||
}
|
||||
|
||||
@@ -684,8 +695,10 @@ async def _current(session: AsyncSession, source: DataSource) -> _Current:
|
||||
mode=snap.mode or "replace", recipe=recipe)
|
||||
|
||||
|
||||
def _revoked_record(reason: str, signed_by: str | None) -> dict[str, Any]:
|
||||
return {"at": utcnow().isoformat(), "reason": reason, "signed_by": signed_by or None, "signed_by_verified": False}
|
||||
def _revoked_record(reason: str, signed_by: str | None, signer_verified: bool = False) -> dict[str, Any]:
|
||||
"""作废接受的记录。是否认证照实记(05-已知遗留 (c)):开了登录、署名是登录的人时为真。"""
|
||||
return {"at": utcnow().isoformat(), "reason": reason, "signed_by": signed_by or None,
|
||||
"signed_by_verified": bool(signer_verified and signed_by)}
|
||||
|
||||
|
||||
async def rollback_target(session: AsyncSession, source: DataSource, import_id: str) -> SourceSnapshot | None:
|
||||
@@ -739,7 +752,8 @@ async def revoke_plan(session: AsyncSession, source: DataSource, imp: TableImpor
|
||||
|
||||
|
||||
async def _rebuild_without(session: AsyncSession, cur: _Current, imp: TableImport, *, expected_current: str | None,
|
||||
kind: str, reason: str, signed_by: str | None, revoke: bool) -> tuple[str, bool]:
|
||||
kind: str, reason: str, signed_by: str | None, revoke: bool,
|
||||
signer_verified: bool = False) -> tuple[str, bool]:
|
||||
"""从当前版本去掉一期、生成(或复用、复活)新快照(7.4)。配方和导入模式不变。返回 (快照 id, 是否复用)。
|
||||
|
||||
revoke=True 时同一个事务里写 table_imports.revoked(7.5):复用路径在调 activate_snapshot 之前改好(随它的提交
|
||||
@@ -758,7 +772,7 @@ async def _rebuild_without(session: AsyncSession, cur: _Current, imp: TableImpor
|
||||
sid = table_versions.snapshot_id(source_id, keep, recipe_types.RECIPE_ENGINE_VER, mode="accumulate",
|
||||
recipe_sha=target_sha)
|
||||
imp_id = imp.id
|
||||
revoked = _revoked_record(reason, signed_by) if revoke else None
|
||||
revoked = _revoked_record(reason, signed_by, signer_verified) if revoke else None
|
||||
activation = {"kind": kind, "import_id": imp_id, "reason": reason, "signed_by": signed_by}
|
||||
|
||||
existing = await session.get(SourceSnapshot, sid)
|
||||
@@ -871,7 +885,7 @@ async def _rebuild_without(session: AsyncSession, cur: _Current, imp: TableImpor
|
||||
"table_hashes": dict((info.union_report or report_json or {}).get("table_hashes") or {}),
|
||||
"union_ver": recipe_types.UNION_VER},
|
||||
parts=parts, report=info.union_report or report_json or {}, label_sets=label_sets, gaps=gaps,
|
||||
replaced=None, removed=removed, notes=notes, signed_by=signed_by)
|
||||
replaced=None, removed=removed, notes=notes, signed_by=signed_by, signer_verified=signer_verified)
|
||||
cache["snapshot_manifest"] = await artifact_store.put_json(
|
||||
doc, kind="snapshot_manifest", meta={"source_id": source_id, "snapshot_id": info.snapshot_id})
|
||||
return cache
|
||||
@@ -931,7 +945,7 @@ def _check_base(cur: _Current, expected_current: str | None) -> None:
|
||||
|
||||
|
||||
async def remove_period(session: AsyncSession, source: DataSource, import_id: str, *, expected_current: str | None,
|
||||
reason: str, signed_by: str | None) -> dict[str, Any]:
|
||||
reason: str, signed_by: str | None, signer_verified: bool = False) -> dict[str, Any]:
|
||||
"""POST …/imports/{id}/remove(7.4)。"""
|
||||
imp = await session.get(TableImport, import_id)
|
||||
if imp is None or imp.source_id != source.id:
|
||||
@@ -947,13 +961,15 @@ async def remove_period(session: AsyncSession, source: DataSource, import_id: st
|
||||
if len(cur.imports) < 2:
|
||||
raise ImportRefused(409, "last_period", _LAST_PERIOD)
|
||||
sid, reused = await _rebuild_without(session, cur, imp, expected_current=expected_current, kind="remove_period",
|
||||
reason=reason, signed_by=signed_by, revoke=False)
|
||||
reason=reason, signed_by=signed_by, revoke=False,
|
||||
signer_verified=signer_verified)
|
||||
return {"snapshot_id": sid, "removed_import_id": import_id, "reused": reused}
|
||||
|
||||
|
||||
async def revoke_acceptance(session: AsyncSession, source: DataSource, import_id: str, *,
|
||||
expected_current: str | None, expected_target: str | None,
|
||||
ack_mask_lost: list[str] | None, reason: str, signed_by: str | None) -> dict[str, Any]:
|
||||
ack_mask_lost: list[str] | None, reason: str, signed_by: str | None,
|
||||
signer_verified: bool = False) -> dict[str, Any]:
|
||||
"""POST …/imports/{id}/revoke-acceptance(7.5)。累积模式(至少两期)= 移除这一期;否则回滚到第 5 节定义的目标。"""
|
||||
imp = await session.get(TableImport, import_id)
|
||||
if imp is None or imp.source_id != source.id:
|
||||
@@ -968,7 +984,7 @@ async def revoke_acceptance(session: AsyncSession, source: DataSource, import_id
|
||||
if _accumulating(cur):
|
||||
sid, _reused = await _rebuild_without(session, cur, imp, expected_current=expected_current,
|
||||
kind="revoke_acceptance", reason=reason, signed_by=signed_by,
|
||||
revoke=True)
|
||||
revoke=True, signer_verified=signer_verified)
|
||||
return {"snapshot_id": sid, "action": "remove_period"}
|
||||
target = await rollback_target(session, source, imp.id)
|
||||
if target is None:
|
||||
@@ -976,7 +992,7 @@ async def revoke_acceptance(session: AsyncSession, source: DataSource, import_id
|
||||
if target.id != expected_target:
|
||||
raise ImportRefused(409, "revoke_target_changed", _TARGET_CHANGED)
|
||||
target_id = target.id
|
||||
imp.revoked = _revoked_record(reason, signed_by)
|
||||
imp.revoked = _revoked_record(reason, signed_by, signer_verified)
|
||||
try:
|
||||
await table_versions.activate_snapshot(
|
||||
session, source, target_id, expected_current=expected_current, kind="revoke_acceptance", reason=reason,
|
||||
@@ -1049,6 +1065,8 @@ async def import_records(session: AsyncSession, source: DataSource, imps: list[T
|
||||
# 按配方导入才有(简单导入为空):配方、统计期、署名,接受的条数
|
||||
"recipe_id": imp.recipe_id, "period_start": imp.period_start, "period_end": imp.period_end,
|
||||
"signed_by": imp.signed_by, "overrides": len(imp.overrides or []), "waivers": len(imp.waivers or []),
|
||||
# 署名是不是认证过的身份:按这一期导入清单里记下的(05-已知遗留 (c);旧清单写的是 False,照记下的说,不改写)
|
||||
"signed_by_verified": _signer_verified(imp.manifest_artifact),
|
||||
# 期 3(7.6)
|
||||
"acceptances": _acceptance_rows(imp), "revoked": imp.revoked, "manifest_artifact": imp.manifest_artifact,
|
||||
"recipe_seq": seqs.get(imp.recipe_id) if imp.recipe_id else None, "in_current": in_current,
|
||||
|
||||
@@ -2130,7 +2130,7 @@ class RawPurge:
|
||||
|
||||
|
||||
async def purge_import_raw(
|
||||
session: AsyncSession, imp: TableImport, *, reason: str, signed_by: str | None
|
||||
session: AsyncSession, imp: TableImport, *, reason: str, signed_by: str | None, signer_verified: bool = False
|
||||
) -> RawPurge:
|
||||
"""清除一次导入的原件(提交)。按两元组解包得到 (是否删了文件, 一并标成已清除的其他导入记录),
|
||||
discarded_stagings 是一并放弃的暂存区。
|
||||
@@ -2160,7 +2160,9 @@ async def purge_import_raw(
|
||||
now = utcnow()
|
||||
record = {
|
||||
"at": now.isoformat(), "reason": reason,
|
||||
"signed_by": (signed_by or "").strip() or None, "signed_by_verified": False,
|
||||
# 是否认证照实记(05-已知遗留 (c)):开了登录、署名是登录的人时为真
|
||||
"signed_by": (signed_by or "").strip() or None,
|
||||
"signed_by_verified": bool(signer_verified and (signed_by or "").strip()),
|
||||
}
|
||||
imp.raw_state, imp.purged = "purged", record
|
||||
for other in others:
|
||||
|
||||
Reference in New Issue
Block a user