mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-15 00:21:58 +00:00
合入第 2 波复核修复 S3、S7、S8、S10、P1:分析卡上写在验证什么的那句照实说是模板作者写的、分析步骤的编号写明是哪一层、证据面板的格写列名与总数按服务端渲染、注释归位、窄屏收起工具栏的改名图标
This commit is contained in:
@@ -1015,8 +1015,12 @@ async def _chain(seg: dict[str, Any], doc: dict[str, Any], sealed: _Sealed,
|
||||
# 分析结论的出处链
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
#: Agent 写的假设(hypothesis)旁边那句:它不是结论,只在证据面板显示(细案 01 §7.3)
|
||||
HYPOTHESIS_NOTE = "Agent 写的假设:说明这次在验证什么,不是分析结论,也不进报告正文"
|
||||
#: 「在验证什么」(hypothesis)旁边那句:它不是结论,只在证据面板显示(细案 01 §7.3)。谁写的照实说:Agent 现场做的
|
||||
#: (台账条目带 call_id)写「Agent 写的假设」,分析卡做的(带 item)是模板作者写的,写「分析卡上写的『在验证什么』」
|
||||
HYPOTHESIS_LABEL = "Agent 写的假设"
|
||||
HYPOTHESIS_NOTE = f"{HYPOTHESIS_LABEL}:说明这次在验证什么,不是分析结论,也不进报告正文"
|
||||
CARD_HYPOTHESIS_LABEL = "分析卡上写的『在验证什么』"
|
||||
CARD_HYPOTHESIS_NOTE = f"{CARD_HYPOTHESIS_LABEL}:模板作者写的那一句,不是分析结论,也不进报告正文"
|
||||
UNSEALED_ANALYSIS = "这份分析结论不属于封存范围内的任何事件(封存前的台账里没有它),不能作为证据展示"
|
||||
TAMPERED_ANALYSIS = "分析结论与哈希不一致,疑似被修改,不展示其中的判定和数"
|
||||
MISSING_ANALYSIS = "无法读取分析结论"
|
||||
@@ -1063,7 +1067,10 @@ def _catalog_alias_of(catalog: dict[str, Any], artifact: Any) -> str | None:
|
||||
|
||||
|
||||
def _analysis_cited(cite: dict[str, Any], result: dict[str, Any] | None) -> dict[str, Any]:
|
||||
"""这一处引用的是结论的哪一项:判定语(phrase)、具名标量(value:键、原值、换算)、结果表的一格(cell:行、列、原值)。"""
|
||||
"""这一处引用的是结论的哪一项:判定语(phrase)、具名标量(value:键、原值、换算)、结果表的一格(cell:行、列、原值)。
|
||||
|
||||
结果表的列写给人看:column 是稳定的列 id(share、delta……,引用里就是这么写的),column_label 是结果表记的列名
|
||||
(「占变化的比重」);页面照原样显示 column_label,不把列 id 当叫法。"""
|
||||
locator = cite.get("locator") or {}
|
||||
if cite.get("kind") == "cell":
|
||||
row, column = locator.get("row"), locator.get("column")
|
||||
@@ -1072,7 +1079,9 @@ def _analysis_cited(cite: dict[str, Any], result: dict[str, Any] | None) -> dict
|
||||
if table is not None:
|
||||
with contextlib.suppress(Exception):
|
||||
raw, column = locate_cell(table, row, column)
|
||||
return {"what": "cell", "row": row, "column": column, "raw": raw}
|
||||
labels = (table or {}).get("labels") if isinstance((table or {}).get("labels"), dict) else {}
|
||||
return {"what": "cell", "row": row, "column": column,
|
||||
"column_label": str(labels.get(column) or column) if column is not None else None, "raw": raw}
|
||||
if locator.get("key"):
|
||||
values = (result or {}).get("values") if isinstance((result or {}).get("values"), dict) else {}
|
||||
return {"what": "value", "key": locator["key"], "raw": values.get(locator["key"]),
|
||||
@@ -1104,11 +1113,13 @@ async def _analysis_chain(seg: dict[str, Any], cite: dict[str, Any], entry: dict
|
||||
"""分析结论的出处链(00-总方案 §3.3):判定 → 方法 → 计算 → 输入 → 复算 → 封存。
|
||||
|
||||
- 判定(analysis):判定语、判定标准、判定码和点名的段、附带说明、算不了的原因,这一处引用的是哪一项(判定语、具名标量、
|
||||
结果表的一格);Agent 写的假设另列,标成「Agent 写的假设」(HYPOTHESIS_NOTE)
|
||||
结果表的一格,列另写结果表记的列名 column_label);「在验证什么」另列,谁写的照实标:Agent 现场做的写「Agent 写的假设」
|
||||
(HYPOTHESIS_NOTE),分析卡做的写「分析卡上写的『在验证什么』」(CARD_HYPOTHESIS_NOTE,模板作者写的)
|
||||
- 方法(analysis_method):方法与版本、规范化后的参数、实际用的阈值(只列这个算子用到的)、现查的表范围(probes)
|
||||
- 计算(analysis_calc):结果表(前 table_top_k 段,加上被引用的那一行附近)、具名的数、关键数的代入式
|
||||
(evidence.analysis_formulas)
|
||||
- 输入(analysis_input,每份一步):落到报告目录的哪个 Q、用了哪些列和行、headline 那一格和结论里总数的闭合核对、
|
||||
- 输入(analysis_input,每份一步):落到报告目录的哪个 Q、用了哪些列和行、headline 那一格(值另由服务端渲染成 value_rendered,
|
||||
和闭合核对同一个写法)和结论里总数的闭合核对、
|
||||
下钻的上一层是哪个 A;后面接上每份输入快照的查询步骤(只认封存范围内交回过的,遮罩照查询步骤的办法)
|
||||
- 复算(analysis_recompute):按 sha256 取回封存的输入、用同一个函数复算,和封存的逐字段比(evidence.analysis_recheck);
|
||||
方法升过版、复算不了都照实写
|
||||
@@ -1154,7 +1165,11 @@ async def _analysis_chain(seg: dict[str, Any], cite: dict[str, Any], entry: dict
|
||||
phrase=result.get("phrase"), criterion=result.get("criterion"), verdict=verdict,
|
||||
caveats=[{k: c.get(k) for k in ("code", "text")} for c in result.get("caveats") or [] if isinstance(c, dict)])
|
||||
if isinstance(result.get("hypothesis"), str) and result["hypothesis"].strip():
|
||||
judged.update(hypothesis=result["hypothesis"], hypothesis_note=HYPOTHESIS_NOTE)
|
||||
# 谁写的照实说:分析卡(台账条目带 item)是模板作者写的,Agent 工具(带 call_id)是现场写的
|
||||
card = judged["origin"] == "card"
|
||||
judged.update(hypothesis=result["hypothesis"],
|
||||
hypothesis_label=CARD_HYPOTHESIS_LABEL if card else HYPOTHESIS_LABEL,
|
||||
hypothesis_note=CARD_HYPOTHESIS_NOTE if card else HYPOTHESIS_NOTE)
|
||||
settings = result.get("settings") if isinstance(result.get("settings"), dict) else {}
|
||||
method = {
|
||||
"step": "analysis_method", "alias": alias, "method": result.get("method"),
|
||||
@@ -1235,6 +1250,10 @@ async def _analysis_inputs(alias: str, result: dict[str, Any], catalog: dict[str
|
||||
"role_label": roles.get(role, role or "输入"), "artifact": artifact or None,
|
||||
**{k: item[k] for k in ("columns", "rows", "row", "column", "value") if k in item},
|
||||
}
|
||||
# 那一格的值由服务端渲染(render_cell:千分位、NULL 写「—」,和闭合核对里的字同一个写法),页面照原样显示
|
||||
if "value" in item:
|
||||
with contextlib.suppress(RenderError):
|
||||
step["value_rendered"] = render_cell(item.get("value"))
|
||||
if role == "parent":
|
||||
step["alias"] = _catalog_alias_of(catalog, artifact)
|
||||
parent, ok = _analysis_of(artifact)
|
||||
|
||||
@@ -259,7 +259,7 @@
|
||||
dCell: '快照里的值', dShown: '正文显示', dShownSame: '与按显示规则渲染的结果一致', dExpected: '按显示规则应为',
|
||||
dArtifact: '所在工件', dReport: '所在报告',
|
||||
dPhrase: '判定语', dCriterion: '判定标准', dMethod: '方法与版本', dAnalysis: '分析结论里的值', dRecheck: '复算',
|
||||
dAnalysisInputs: '输入', dHypothesis: 'Agent 写的假设', dCaveats: '附带说明',
|
||||
dAnalysisInputs: '输入', dHypothesis: 'Agent 写的假设', dCardHypothesis: '分析卡上写的『在验证什么』', dCaveats: '附带说明',
|
||||
recheckBy: '导出时服务端按封存的输入复算的结论;本页只核哈希,不在浏览器里重算统计',
|
||||
recheckNone: '导出时没有复算(结论未随文件附带)',
|
||||
analysisInput: (role, alias) => `${role}${alias ? ` · ${alias}` : ''}`,
|
||||
@@ -1212,7 +1212,7 @@
|
||||
async function verify(data, digest, shownSeal) {
|
||||
const out = {
|
||||
events: [], manifest: [], artifacts: [], chain: [], numbers: [], docs: [], meta: [], checked: new Map(), order: [],
|
||||
arts: new Map(), queryAliases: new Map(),
|
||||
arts: new Map(), queryAliases: new Map(), analysisEntries: new Map(),
|
||||
}
|
||||
const events = Array.isArray(data.events) ? data.events.filter(isObj) : []
|
||||
const meta = data.meta
|
||||
@@ -1373,6 +1373,15 @@
|
||||
for (const [id, refs] of byDoc) {
|
||||
if (refs.length && !out.queryAliases.has(id)) out.queryAliases.set(id, refs[0].alias)
|
||||
}
|
||||
// 工件 → 报告目录里这条分析结论的条目(item、call_id):谁做的那一行、「在验证什么」的说法照它认
|
||||
out.analysisEntries = new Map()
|
||||
for (const [id, refs] of byDoc) {
|
||||
for (const ref of refs) {
|
||||
const doc = trusted.get(ref.report)
|
||||
const entry = own(isObj(doc) ? doc.catalog : null, ref.alias)
|
||||
if (isObj(entry) && entry.kind === 'analysis' && !out.analysisEntries.has(id)) out.analysisEntries.set(id, entry)
|
||||
}
|
||||
}
|
||||
out.arts = arts
|
||||
out.chained = chained
|
||||
// 已核对的口径卡记着的输入 → 输入指向的查询快照。卡本身核过哈希(③ 通过),它记的引用和文档的证据目录
|
||||
@@ -1452,6 +1461,7 @@
|
||||
const loc = isObj(cite.locator) ? cite.locator : {}
|
||||
if (cite.kind === 'metric') return T.srcMetric(own(entry, 'name') || loc.metric || cite.ref || '')
|
||||
if (cite.kind === 'cell' && own(entry, 'kind') === 'analysis' && Number.isInteger(loc.row)) {
|
||||
// 结果表的格写列名:核对到结论之后换成结论记的列名(checkAnalysis 的 info.source),这里先照引用里的列 id 说
|
||||
return T.srcAnalysisCell(cite.alias, loc.row, String(loc.column ?? ''))
|
||||
}
|
||||
if (cite.kind === 'cell') {
|
||||
@@ -1564,6 +1574,9 @@
|
||||
const [raw, column, key] = locateCell(table, loc.row, loc.column)
|
||||
info.row = loc.row
|
||||
info.column = column
|
||||
// 出处面板写结果表记的列名(labels),不把列 id 当叫法;目录条目和文档引用里带的那份先认,没有再查这份结论
|
||||
info.columnLabel = analysisColumnLabel(table, column)
|
||||
info.source = T.srcAnalysisCell(cite.alias, loc.row, info.columnLabel)
|
||||
info.truth = cellValue(raw, columnKind(table, column))
|
||||
info.truthToken = tokenAt(tokensOf(art), ['table', 'rows', loc.row, key])
|
||||
if (typeof raw === 'string' && typeof info.truth === 'number') info.truthText = pyStrip(raw)
|
||||
@@ -1591,6 +1604,14 @@
|
||||
return checkShown(info, seg, () => renderCell(result.phrase, null, null, 'text', 1))
|
||||
}
|
||||
|
||||
/** 分析结论结果表的一格写给人看的列名:结论结果表记的 labels(「占变化的比重」),没起名字的列才写列 id。
|
||||
* 文档里的引用只记列 id(引用就这么写),列名照随文件附带的结论认 */
|
||||
function analysisColumnLabel(table, column) {
|
||||
const id = String(column ?? '')
|
||||
const labels = isObj(table.labels) ? table.labels : {}
|
||||
return own(labels, id) ? String(labels[id]) : id
|
||||
}
|
||||
|
||||
/** 口径卡的单位:服务端是 str(unit or ""),不是文字的本页不认 */
|
||||
function unitOf(unit) {
|
||||
if (!unit) return ''
|
||||
@@ -2032,12 +2053,17 @@
|
||||
return parts
|
||||
}
|
||||
|
||||
/** 数字详情里分析结论一节:判定语、判定标准、方法与版本、附带说明、Agent 写的假设、输入(各自的核对状态)、导出时服务端
|
||||
* 的复算结论。结论没随文件附带(遮罩、文件不在)时只写复算一句 */
|
||||
/** 数字详情里分析结论一节:判定语、判定标准、方法与版本、附带说明、「在验证什么」(谁写的照实标:Agent 写的假设 /
|
||||
* 分析卡上写的『在验证什么』,照报告目录里这条结论的条目认)、输入(各自的核对状态)、导出时服务端的复算结论。
|
||||
* 结论没随文件附带(遮罩、文件不在)时只写复算一句 */
|
||||
function analysisBlock(number) {
|
||||
const result = isObj(number.analysis) ? number.analysis : null
|
||||
const art = view.out.artifacts.find((a) => a.a.id === number.artifact)
|
||||
const recheck = art && isObj(art.a.recheck) ? art.a.recheck : null
|
||||
// 谁做的:报告目录里这条结论的条目(带 item 的是分析卡做的,带 call_id 的是 Agent 现场做的)。「在验证什么」的说法照它认,
|
||||
// 不把模板作者写的那一句标成 Agent 写的假设
|
||||
const entry = view.out.analysisEntries.get(number.artifact)
|
||||
const card = isObj(entry) ? !!entry.item && !entry.call_id : false
|
||||
const parts = []
|
||||
if (result) {
|
||||
parts.push(kv([
|
||||
@@ -2048,7 +2074,7 @@
|
||||
const caveats = (Array.isArray(result.caveats) ? result.caveats : []).filter(isObj).map((c) => String(c.text || ''))
|
||||
if (caveats.length) parts.push(h('p', { class: 'sub' }, T.dCaveats), h('ul', { class: 'items' }, caveats.map((c) => h('li', {}, c))))
|
||||
if (typeof result.hypothesis === 'string' && result.hypothesis.trim()) {
|
||||
parts.push(h('p', { class: 'sub' }, T.dHypothesis), h('p', {}, result.hypothesis))
|
||||
parts.push(h('p', { class: 'sub' }, card ? T.dCardHypothesis : T.dHypothesis), h('p', {}, result.hypothesis))
|
||||
}
|
||||
const inputs = (Array.isArray(result.inputs) ? result.inputs : []).filter((i) => isObj(i) && typeof i.artifact === 'string')
|
||||
if (inputs.length) {
|
||||
|
||||
@@ -1030,7 +1030,8 @@ _ANALYSIS_KEYS = ("node_id", "exec", "artifact", "call_id", "item", "op", "mode"
|
||||
def _analysis_entry(entry: dict[str, Any], alias: str, snaps: _Snapshots) -> dict[str, Any]:
|
||||
"""台账里的一条分析结论 → 写作目录的 A 条目:照抄台账的键,带上从工件取回、复验过哈希的整份结论(result,
|
||||
analysis.contract.catalog_result 读它)。取不回、哈希不符、形状不对的不带 result,记 unreadable(以编号开头的一句,引用
|
||||
它时照实说)。rows 是结果表的行数:依据 [[see:A1.r3]] 按它核对,存进报告文档的摘要里也留着。"""
|
||||
它时照实说)。rows 是结果表的行数:依据 [[see:A1.r3]] 按它核对,存进报告文档的摘要里也留着;labels 是结果表记的列名
|
||||
(列 id → 给人看的名字):证据面板、读屏的出处写「结果表第 1 行「占变化的比重」」,不把列 id 当叫法。"""
|
||||
out: dict[str, Any] = {"alias": alias, "kind": LEDGER_KIND, "eid": make_eid(LEDGER_KIND, entry.get("artifact"), {}),
|
||||
"locator": {}, **{k: entry[k] for k in _ANALYSIS_KEYS if k in entry}}
|
||||
result, why = snaps.analysis(alias, {"artifact": entry.get("artifact")})
|
||||
@@ -1039,8 +1040,11 @@ def _analysis_entry(entry: dict[str, Any], alias: str, snaps: _Snapshots) -> dic
|
||||
else:
|
||||
out["result"] = result
|
||||
table = result.get("table")
|
||||
if isinstance(table, dict) and isinstance(table.get("rows"), list):
|
||||
out["rows"] = len(table["rows"])
|
||||
if isinstance(table, dict):
|
||||
if isinstance(table.get("rows"), list):
|
||||
out["rows"] = len(table["rows"])
|
||||
if isinstance(table.get("labels"), dict) and table["labels"]:
|
||||
out["labels"] = {str(k): str(v) for k, v in table["labels"].items()}
|
||||
phrase = _clean(str((result or {}).get("phrase") or ""))
|
||||
name = method_label(out.get("op"), out.get("mode"))
|
||||
out["label"] = f"{name} · {phrase}" if phrase else name
|
||||
|
||||
@@ -462,9 +462,10 @@ async def run_supervisor(state: GraphState, ctx: NodeContext) -> dict[str, Any]:
|
||||
agent=name, call_id=cid, preview=content[:1500],
|
||||
duration_ms=int((time.perf_counter() - started) * 1000), **failure,
|
||||
**({"checks": checks} if checks else {}),
|
||||
# 判定的那一小段同 Agent 节点(event_view);编号是成员自己的分析容器里的,紧接着 _numbered 按它编
|
||||
# 判定的那一小段同 Agent 节点(event_view)。不带编号:成员自己的分析容器里的 A1 不是报告目录里的
|
||||
# A1(协作成员的结论还进不了台账),时间线上照它写「· A1」会和报告里点名的结论对不上
|
||||
**({"analysis_artifact": analysis["artifact"],
|
||||
"analysis": event_view(analysis["result"], scope.next_alias())} if analysis else {}))
|
||||
"analysis": event_view(analysis["result"])} if analysis else {}))
|
||||
if analysis is not None and analysis["result"].get("status") == "refused":
|
||||
ctx.emit(EventType.LOG, level="warn", code=ANALYSIS_REFUSED, agent=name, call_id=cid, tool=tname,
|
||||
reason_code=analysis["result"].get("reason_code"),
|
||||
|
||||
@@ -461,13 +461,15 @@
|
||||
}, v == null ? NONE : textOf(v))))))))
|
||||
}
|
||||
|
||||
/** 分析结论 · 判定:判定语、判定标准、判定码和点名的段、附带说明、算不了的原因、这一处引用的是哪一项、谁做的、Agent 写的假设 */
|
||||
/** 分析结论 · 判定:判定语、判定标准、判定码和点名的段、附带说明、算不了的原因、这一处引用的是哪一项、谁做的、
|
||||
* 「在验证什么」(谁写的照实标:Agent 写的假设 / 分析卡上写的『在验证什么』) */
|
||||
function analysisPart(step) {
|
||||
const body = []
|
||||
const verdict = isObj(step.verdict) ? step.verdict : null
|
||||
const cited = isObj(step.cited) ? step.cited : {}
|
||||
const citedText = cited.what === 'value' ? T.citedValue(cited.key) : cited.what === 'cell'
|
||||
? T.citedCell(Number(cited.row) || 0, String(cited.column ?? '')) : T.citedPhrase
|
||||
// 结果表的格写列名(服务端照结果表记的 labels 给),不把列 id 当叫法;老接口没给列名的照旧写 id
|
||||
? T.citedCell(Number(cited.row) || 0, String(cited.column_label || cited.column || '')) : T.citedPhrase
|
||||
body.push(kv([
|
||||
[T.dPhrase, String(step.phrase || NONE)],
|
||||
step.criterion ? [T.dCriterion, String(step.criterion)] : null,
|
||||
@@ -484,7 +486,9 @@
|
||||
h('ul', { style: 'margin:4px 0 0;padding-left:1.2em;font-size:13px' }, step.caveats.map((c) => h('li', {}, String(c.text || '')))))
|
||||
}
|
||||
if (step.hypothesis) {
|
||||
body.push(h('p', { class: 'sub' }, T.dHypothesis), h('p', { style: 'margin:4px 0 0;font-size:13px' }, String(step.hypothesis)))
|
||||
// 「在验证什么」:谁写的服务端照实给(Agent 写的假设 / 分析卡上写的『在验证什么』),这里照原样显示
|
||||
body.push(h('p', { class: 'sub' }, String(step.hypothesis_label || T.dHypothesis)),
|
||||
h('p', { style: 'margin:4px 0 0;font-size:13px' }, String(step.hypothesis)))
|
||||
if (step.hypothesis_note) body.push(muted(step.hypothesis_note))
|
||||
}
|
||||
if (step.note) body.push(waiting(step.note))
|
||||
@@ -558,7 +562,7 @@
|
||||
step.node_id ? [T.dNode, nodeLabel(step.node_id)] : null,
|
||||
Array.isArray(step.columns) && step.columns.length ? [T.dColumnsUsed, step.columns.join('、')] : null,
|
||||
rows ? [T.dRowsUsed, rows] : null,
|
||||
'value' in step ? [ratio ? T.dHeadlineRatio : T.dHeadline, `${step.column ? `第 ${Number(step.row) + 1} 行「${step.column}」 = ` : ''}${valueText(step.value)}`] : null,
|
||||
'value' in step ? [ratio ? T.dHeadlineRatio : T.dHeadline, `${step.column ? `第 ${Number(step.row) + 1} 行「${step.column}」 = ` : ''}${step.value_rendered ?? valueText(step.value)}`] : null,
|
||||
closure ? [T.dClosure, closed(closure.headline, closure.total)] : null,
|
||||
step.phrase ? [T.dPhrase, String(step.phrase)] : null,
|
||||
])]
|
||||
|
||||
@@ -100,6 +100,7 @@ def verdicts(bundle: dict[str, Any]) -> dict[str, Any]:
|
||||
|
||||
|
||||
def test_the_analysis_and_its_input_travel_with_the_file_and_verify():
|
||||
"""Agent 现场做的结论(台账条目带 call_id):那一句「在验证什么」标成「Agent 写的假设」。"""
|
||||
bundle, files, a = bundle_of()
|
||||
analysis_item = item(bundle, a)
|
||||
assert analysis_item["kind"] == ARTIFACT_KIND and "b64" in analysis_item and analysis_item["node_id"] == "an"
|
||||
|
||||
@@ -330,6 +330,8 @@ def test_the_doc_keeps_a_summary_and_reloads_the_result_from_the_artifact():
|
||||
doc = compose_doc("[[a:A1]],华东占 [[a:A1.top_share|pct]]。", catalog, loader=store.load)
|
||||
stored = doc["catalog"]["A1"]
|
||||
assert "result" not in stored and stored["artifact"] and stored["rows"] == 4 and stored["verdict"] == "driver"
|
||||
# 结果表记的列名(列 id → 给人看的名字)跟着摘要走:证据面板、读屏的出处写「结果表第 1 行「变化」」
|
||||
assert stored["labels"]["delta"] == "变化"
|
||||
# 文档里的摘要照样解析得了:结论按工件取回
|
||||
assert resolve_ref("a:A1", doc["catalog"], loader=store.load)["status"] == "resolved"
|
||||
assert verify_doc(doc, doc["catalog"], loader=store.load)["ok"]
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
真的 recompute:按 sha256 取回封存的输入快照、下钻的上一层结论,逐字段比。只有要它出错、升版的几处用 monkeypatch。
|
||||
|
||||
- 证据图:A1 条目带算子、判定;「派生自」的边 A1 → Q1
|
||||
- 片段接口:判定 → 方法 → 计算 → 输入(接查询步骤)→ 复算 → 封存;Agent 写的假设标出来;复算不了照实写,不让接口出错
|
||||
- 片段接口:判定 → 方法 → 计算 → 输入(接查询步骤)→ 复算 → 封存;「在验证什么」谁写的照实标(Agent 写的假设 / 分析卡上
|
||||
写的『在验证什么』);复算不了照实写,不让接口出错
|
||||
- 审计:分析判定、分析结论的叫法;分析说法核对的违规单列一行
|
||||
- 报告导出:数据块里有分析结论那几步;文档带「分析范围」的,正文后面渲染、编号点得开
|
||||
- 指标步骤带可比性:口径卡指标上的可比性结论(不进台账)照卡上记的 sha256 取回,点得开(判定 → … → 复算 → 封存)
|
||||
@@ -135,7 +136,9 @@ async def test_the_phrase_opens_judgment_method_calculation_inputs_recompute_and
|
||||
assert judged["verdict"] == {"code": "driver", "subjects": [["华东"]], "direction": "down"}
|
||||
assert judged["cited"] == {"what": "phrase"} and judged["render_ok"] is True and judged["eid_ok"] is True
|
||||
assert judged["origin"] == "card" and judged["item"] == "drop" and judged["label"] == "分析"
|
||||
assert judged["hypothesis"] == "华东拖累" and judged["hypothesis_note"].startswith("Agent 写的假设")
|
||||
# 分析卡做的:模板作者写的「在验证什么」,不标成 Agent 写的假设
|
||||
assert judged["hypothesis"] == "华东拖累" and judged["hypothesis_label"] == "分析卡上写的『在验证什么』"
|
||||
assert judged["hypothesis_note"].startswith("分析卡上写的『在验证什么』")
|
||||
assert {c["code"] for c in judged["caveats"]} == {"measure_unlabeled", "headline_basis", "comparability"}
|
||||
assert method["method"] == "decompose.additive@1" and method["method_label"] == "变化拆解(可加)"
|
||||
assert {s["key"]: s["label"] for s in method["settings"]}["main_share"] == "「主要来源」的占比"
|
||||
@@ -173,7 +176,8 @@ async def test_named_values_and_result_cells_point_at_what_they_cite(client):
|
||||
|
||||
cell = (await client.get(
|
||||
f"/api/runs/{made['run']}/evidence/segments/{seg_id(made['doc'], 'v:A1.r0.delta')}")).json()
|
||||
assert cell["chain"][0]["cited"] == {"what": "cell", "row": 0, "column": "delta", "raw": "-120"}
|
||||
assert cell["chain"][0]["cited"] == {"what": "cell", "row": 0, "column": "delta", "column_label": "变化",
|
||||
"raw": "-120"}
|
||||
assert cell["chain"][2]["table"]["highlight"] == {"cells": [[0, "delta"]]}
|
||||
assert cell["note"] == "该值由系统从分析结论的结果表中取出、按固定规则显示,未经模型转写"
|
||||
|
||||
@@ -216,7 +220,9 @@ async def test_a_result_cell_rerenders_the_way_it_was_composed(client, monkeypat
|
||||
body = (await client.get(f"/api/runs/{made['run']}/evidence/segments/{segment['id']}")).json()
|
||||
judged = body["chain"][0]
|
||||
assert judged["rendered"] == shown and judged["render_ok"] is True
|
||||
assert judged["cited"] == {"what": "cell", "row": 0, "column": by, "raw": snapshot["rows"][0][0]}
|
||||
# column_label 是结果表记的列名:维度列照输入快照里的列名(store、slot),不另起叫法
|
||||
assert judged["cited"] == {"what": "cell", "row": 0, "column": by, "column_label": by,
|
||||
"raw": snapshot["rows"][0][0]}
|
||||
# 导出页的数据块是同一条链
|
||||
data = data_block((await client.get(f"/api/runs/{made['run']}/report.html")).text)
|
||||
chain = data["chains"][data["refs"][segment["id"]]]
|
||||
@@ -307,9 +313,12 @@ def test_suspicious_name_hints_do_not_read_the_analysis_results(monkeypatch):
|
||||
|
||||
|
||||
async def test_agent_analyses_are_marked_as_such(client):
|
||||
"""Agent 现场做的:谁做的写 Agent,「在验证什么」照旧标「Agent 写的假设」(分析卡上那一句是模板作者写的,另说)"""
|
||||
made = await sealed_run(TEXT, item=None, call_id="call-9")
|
||||
body = (await client.get(f"/api/runs/{made['run']}/evidence/segments/{seg_id(made['doc'], 'a:A1')}")).json()
|
||||
assert body["chain"][0]["origin"] == "agent" and body["chain"][0]["call_id"] == "call-9"
|
||||
judged = body["chain"][0]
|
||||
assert judged["origin"] == "agent" and judged["call_id"] == "call-9"
|
||||
assert judged["hypothesis_label"] == "Agent 写的假设" and judged["hypothesis_note"].startswith("Agent 写的假设")
|
||||
|
||||
|
||||
async def test_headline_inputs_show_the_closure(client):
|
||||
@@ -329,6 +338,9 @@ async def test_headline_inputs_show_the_closure(client):
|
||||
assert inputs[1]["closure"] == {"mode": "additive", "total_key": "target_total", "total": "2,026",
|
||||
"headline": "2,026", "closed": True}
|
||||
assert [s["role_label"] for s in inputs[:2]] == ["基期总数", "本期总数"]
|
||||
# 那一格的值服务端渲染好了(render_cell:千分位),和闭合核对里的字同一个写法;页面照原样显示
|
||||
assert inputs[0]["value"] == "2220" and inputs[0]["value_rendered"] == "2,220"
|
||||
assert inputs[1]["value"] == "2026" and inputs[1]["value_rendered"] == "2,026"
|
||||
assert inputs[1]["query"] == "Q2" and inputs[1]["sealed"] is True and inputs[2]["query"] == "Q1"
|
||||
assert next(s for s in body["chain"] if s["step"] == "analysis_recompute")["status"] == "same"
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import app.bundle
|
||||
import app.report_export
|
||||
from app.main import app as asgi
|
||||
from tests.test_analysis_bundle import bundle_of, card_bundle
|
||||
from app.core import artifact_store
|
||||
from tests.test_analysis_evidence import SNAPSHOT, analyzed
|
||||
from tests.test_analysis_evidence_api import (
|
||||
LAST_WEEK, SCOPE, TEXT, THIS_WEEK, comparability_card, ratio_run, sealed_run, seg_id,
|
||||
)
|
||||
@@ -147,13 +149,15 @@ async def test_the_export_page_opens_the_analysis_steps_and_the_scope_numbers():
|
||||
"analysis_recompute", "analysis_seal"]
|
||||
assert opened["title"].startswith("判定「销售额下降")
|
||||
body = opened["body"]
|
||||
for text in ("判定标准一段占总变化的一半以上算主要来源", "Agent 写的假设华东拖累", "实际用的阈值", "「主要来源」的占比",
|
||||
# 分析卡做的结论(台账条目带 item):那一句是模板作者写的,照实写「分析卡上写的『在验证什么』」,不标成 Agent 写的假设
|
||||
for text in ("判定标准一段占总变化的一半以上算主要来源", "分析卡上写的『在验证什么』华东拖累", "实际用的阈值", "「主要来源」的占比",
|
||||
"华东的占比 = 华东的变化 ÷ 总变化 = -120 ÷ (-194) = 61.9%", "结果表(列出 4 行,共 4 行)",
|
||||
"复算一致:按封存的输入重新计算,结论逐项相同", "封存范围内的台账记过这份分析结论",
|
||||
"按运行当天现算的界 date('now', '-7 days') = 2026-10-14(现查 · 2026-10-21T09:00:00)",
|
||||
"orders.refund_date:这一列一个值都没有(现查", "orders.order_date:2025-01-01 至 2026-10-20(剖析"):
|
||||
assert text in body, text
|
||||
assert "结果表第 1 行「delta」" in out[cell]["body"]
|
||||
# 结果表的格写结果表记的列名(labels 的「变化」),不把列 id 当叫法
|
||||
assert "结果表第 1 行「变化」" in out[cell]["body"]
|
||||
assert out["scope:A1"]["steps"] == opened["steps"]
|
||||
|
||||
|
||||
@@ -168,12 +172,36 @@ async def test_the_export_page_speaks_of_the_overall_ratio_for_a_ratio_decomposi
|
||||
out = run_node(RUN_RUNTIME, RUNTIME, {"data": data, "segs": [
|
||||
{"seg": phrase, "kind": "analysis", "state": "deterministic", "text": made["result"]["phrase"]}]})
|
||||
body = out[phrase]["body"]
|
||||
for text in ("基期整体比率", "整体比率那一格", "整体比率 0.035 与各段分子之和 ÷ 分母之和 0.035 闭合",
|
||||
for text in ("基期整体比率", "整体比率那一格", "第 1 行「rate」 = 0.035",
|
||||
"整体比率 0.035 与各段分子之和 ÷ 分母之和 0.035 闭合",
|
||||
"整体比率 0.053 与各段分子之和 ÷ 分母之和 0.053 闭合"):
|
||||
assert text in body, text
|
||||
assert "各段之和 0.0" not in body
|
||||
|
||||
|
||||
async def test_the_export_page_writes_the_headline_cell_the_way_the_server_rendered_it():
|
||||
"""总数那一格的值由服务端渲染(render_cell:千分位),页面照原样显示:以前照原值写「2220」,同一节里闭合核对写
|
||||
「2,220」,一处引用里两个写法并排。"""
|
||||
totals = {"columns": ["gmv_base", "gmv"], "column_types": {"gmv_base": "number", "gmv": "number"},
|
||||
"rows": [[2220, 2026]], "sql": "SELECT 2220 AS gmv_base, 2026 AS gmv", "source": "shop",
|
||||
"truncated": False}
|
||||
t = artifact_store.content_hash(artifact_store.canonical_json(totals))
|
||||
q = artifact_store.content_hash(artifact_store.canonical_json(SNAPSHOT))
|
||||
result = await analyzed({"Q2": (SNAPSHOT, q), "Q5": (totals, t)}, headline=["Q5.r0.gmv_base", "Q5.r0.gmv"])
|
||||
made = await sealed_run("[[a:A1]]。", result=result, queries=[totals])
|
||||
async with AsyncClient(transport=ASGITransport(app=asgi), base_url="http://test") as client:
|
||||
html = (await client.get(f"/api/runs/{made['run']}/report.html")).text
|
||||
data = re.search(r'<script type="application/json" id="report-data">(.*?)</script>', html, re.S).group(1)
|
||||
phrase = seg_id(made["doc"], "a:A1")
|
||||
out = run_node(RUN_RUNTIME, RUNTIME, {"data": data, "segs": [
|
||||
{"seg": phrase, "kind": "analysis", "state": "deterministic", "text": made["result"]["phrase"]}]})
|
||||
body = out[phrase]["body"]
|
||||
for text in ("总数那一格第 1 行「gmv_base」 = 2,220", "总数那一格第 1 行「gmv」 = 2,026",
|
||||
"总数 2,220 与各段之和 2,220 闭合"):
|
||||
assert text in body, text
|
||||
assert "= 2220" not in body and "= 2026" not in body
|
||||
|
||||
|
||||
async def test_the_bundle_page_shows_the_analysis_detail_and_the_scope():
|
||||
bundle, _, _ = bundle_of(doc_extra=SCOPE)
|
||||
out = run_node(RUN_VERIFIER, VERIFIER, {"data": json.dumps(bundle), "seal": bundle["meta"]["manifest_hash"]})
|
||||
@@ -186,6 +214,8 @@ async def test_the_bundle_page_shows_the_analysis_detail_and_the_scope():
|
||||
# 方法写服务端带来的叫法和 id(和导出页同一个写法),不只写 id
|
||||
assert "判定语销售额下降 194(-8.7%)" in phrase and "方法与版本变化拆解(可加) · decompose.additive@1" in phrase
|
||||
assert "输入数据 · Q1" in phrase # 输入的角色写叫法,不写 data
|
||||
# 这份结论是分析卡做的(台账条目带 item):那一句「在验证什么」写「分析卡上写的『在验证什么』」,不标成 Agent 写的假设
|
||||
assert "分析卡上写的『在验证什么』" in phrase and "Agent 写的假设" not in phrase
|
||||
assert "复算一致:按封存的输入重新计算,结论逐项相同(导出时服务端按封存的输入复算的结论;本页只核哈希" in phrase
|
||||
value = next(text for text in out["opened"].values() if "具名的数「top_share」" in text)
|
||||
assert "引用的值0.618556701031" in value and "正文显示61.9%(与按显示规则渲染的结果一致)" in value
|
||||
|
||||
@@ -70,7 +70,7 @@ async def test_tool_end_carries_the_phrase_and_the_same_number_the_model_got(mon
|
||||
assert error["call_error"] == "unknown_column" and "analysis" not in error
|
||||
|
||||
|
||||
async def test_a_team_member_numbers_its_own_analyses(monkeypatch, shop):
|
||||
async def test_a_team_member_analysis_carries_no_number(monkeypatch, shop):
|
||||
Script(monkeypatch, [(TOOL, {"sql": SQL}), (DECOMPOSE, DECOMPOSE_ARGS)],
|
||||
route={"assignments": [{"agent": "分析员", "instruction": "拆一下销售额的变化"}], "done": False})
|
||||
nodes = [node("start", "input"),
|
||||
@@ -82,7 +82,10 @@ async def test_a_team_member_numbers_its_own_analyses(monkeypatch, shop):
|
||||
input_payload={})
|
||||
row = await wait(run.id)
|
||||
assert row.status == "succeeded", row.error
|
||||
[end] = [e for e in await events(row.id, "tool.end", "team") if e.get("analysis_artifact")]
|
||||
assert end["agent"] == "分析员"
|
||||
assert (end["analysis"]["alias"], end["analysis"]["op"], end["analysis"]["verdict"]) == ("A1", "decompose", "driver")
|
||||
ends = [e for e in await events(row.id, "tool.end", "team") if e.get("analysis_artifact")]
|
||||
assert [e["agent"] for e in ends] == ["分析员"]
|
||||
end = ends[0]
|
||||
# 不带编号:成员自己的分析容器里的 A1 不是报告目录里的 A1(协作成员的结论还进不了台账),报告目录另按整次运行的台账编
|
||||
assert end["analysis"]["alias"] is None
|
||||
assert (end["analysis"]["op"], end["analysis"]["verdict"]) == ("decompose", "driver")
|
||||
assert json.dumps(end["analysis"], ensure_ascii=False).count("下降是不是集中在某个地区") == 0, "Agent 写的假设不带"
|
||||
|
||||
Reference in New Issue
Block a user