Skip to content

feat(core): add auditable provider disagreement fixtures (#26) - #287

Merged
kbkb628 merged 2 commits into
helsome:mainfrom
yu1128-L:feat/finance-fact-reconciliation
Oct 3, 2026
Merged

kbkb628 merged 2 commits into
helsome:mainfrom
yu1128-L:feat/finance-fact-reconciliation

Conversation

@yu1128-L

@yu1128-L yu1128-L commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

改动说明

本 PR 为 #26 增加“至少 3 个真实或可复现 provider disagreement case 并可判定”这一验收项的基础:补齐 reconciliation result 的审计字段,并提供 4 个可复现的 disagreement fixtures 及其断言。

  • ReconciliationResult 新增 sourceCount 与 selectedReason,各分支都记录候选来源数量与最终选择原因;
  • 新增 reconciliation-fixtures.ts,包含 4 个可复现场景:
    • 修订版 vs 过期 EPS → material-conflict
    • 同一时点报价在绝对容差内 → within-tolerance
    • HKD / USD 语义未对齐 → incomparable
    • 单 provider → insufficient-sources
  • 新增 reconciliation-fixtures.test.ts:验证不静默平均、候选保留、状态与选择原因正确。

关联 Issue

Refs #26

测试报告(正式审核前必填)

环境

  • Bun:1.4.2
  • OS:Windows

实际执行命令与结果

bun test packages/core/src/reconciliation.test.ts packages/core/src/reconciliation-fixtures.test.ts packages/shared/src/providers/reconciliation.test.ts
→ 12 passed / 0 failed

bun run --filter '@finagent/core' typecheck
→ exit 0

已知失败 / Baseline(如有)

无。

  • 已提供实际测试命令与 pass/fail 结果
  • 已说明测试环境
  • 如果存在已知 baseline / 环境失败,已提供 main 对照或说明:无
  • 核心改动已有对应 focused test / smoke / integration 验证

UI 截图(仅可见 UI 变化时必填)

  • 本 PR 无可见 UI 变化(无需截图)

本 PR 为 core 数据层能力,不涉及可见 UI。

Scope / 后续

本 PR 只完成 #26 中可复现 disagreement case 与可审计结果这一部分。multi-provider 候选收集、Agent / report 显式表达数据源分歧、UI / evidence 查看各 provider 候选值等仍属 issue 后续工作,不声明 #26 整体完成。

@kbkb628 kbkb628 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我按仓库测试规范在本机独立复现并做了变异检查。行为层面零回归(下面有证据),但有两处建议改完再合。

实测(bun 1.4.2 / Windows,worktree 检出 43449a87)

命令 结果
bun test packages/core exit 0 — 58 pass / 0 fail
bun test --isolate(全仓) exit 0 — 1683 pass / 8 skip / 0 fail(183 文件)
bun test packages/shared/src/kernel exit 0 — 99 pass / 0 fail
bun run typecheck exit 0,5 个 workspace 全 0

行为保持:改动前后用同一组输入对比,所有分支的 state / discrepancy / selected / reason / policyVersion / candidates 逐字节相同(例如 "discrepancy":0.4900000000000002、"selected":{"provider":"longbridge",...} 完全一致)。:14-15 的选择逻辑只是把 providerPriority 的查找提成局部变量(纯 hoist),没有改变 tie-breaking、容差、舍入或顺序,也没有新增抛错路径。既有 reconciliation.test.ts 没有"侥幸通过":它只断言 state / selected.value / selected.provider / candidates.map(value),这些值都没变。

建议修改

1)测试 fixtures 被导出到了包的公共 API 上 —— packages/core/src/index.ts:604

export * from './reconciliation-fixtures.ts';

packages/core/package.json 的 main / types / exports["."] 全部指向 ./src/index.ts(没有 build 步骤、没有 dist),所以 src/index.ts 就是 @finagent/core 对外发布的入口 —— 这行等于把硬编码的测试数据放进了公共导出面。

仓库自己的先例恰好相反:packages/longbridge-tools/src/testing/(load-fixture.ts + fixtures/)就是 test-only 模块,故意不被该包 index 导出(grep 0 命中)。

修法:删掉这一行(fixtures 只被 reconciliation-fixtures.test.ts:3 使用,删了不影响测试),或者把它挪到 packages/core/src/testing/ 且不导出。

2)fixtures 号称 "auditable",但时间戳与自己声明的 period 矛盾

  • 场景 1(修订版 vs 过期 EPS):period: '2025Q4',但两个 asOf 是 2024-12-02 和 2025-01-01 —— 都在它所声称的期间之前;
  • 场景 2(同一时点报价):period: '2025-10-03',但 asOf 是 2025-08-26T08:00:00Z,早了约 38 天,与"同一时点"的描述不符;
  • 另外 FinancialFactCandidate 里没有 instrument / symbol 字段,所以一个 "provider disagreement" 无法归属到具体标的。

asOf 恰好不在可比性判定里(reconciliation.ts:10 只比较 period / currency / unit / adjustment),所以这些错时间戳不会造成误判 —— 但它们让"可审计"这个卖点站不住:一个过不了日期自检的 fixture,等于把错误的 provenance 固化成 ground truth。建议修正时间戳并补上标的字段(或在描述里说明为什么不需要)。

3)sourceCount 是必填新字段(低-中)

ReconciliationResult 现在要求 sourceCount: number。运行时是纯增量(仓库内唯一构造方就是 reconciliation.ts 自己,所以 typecheck 通过),但对外部构造/mock 这个类型的消费者是源码级破坏性变更,而 CONTRIBUTING §6 要求公共类型保持向后兼容。建议改成 sourceCount?: number,或在描述里明确说明这是有意的破坏性变更。

4)fixtures 缺少"假数据"标记(低)

reconciliation-fixtures.ts 用了真实品牌名(longbridge / refinitiv / polygon)配合理量级的数值,却没有任何 FAKE / SAMPLE / example 之类的标记。里面没有 secret,所以不算违反 redaction 规则,但容易被后来者误认成真实抓取的 provider 数据(模块自己的注释还写着"instead of relying on live provider data")。建议加显式标记,并考虑按 CONTRIBUTING 把 fixture 留在测试文件内。

测试质量(不阻塞,供参考)

变异检查:把 reconciliation.ts 回退到 pr-287^ 后 → 1 pass / 4 fail(reconciliation-fixtures.test.ts:18 的 expect(result.sourceCount).toBe(...) → Expected: 2 / Received: undefined);保留 sourceCount 但把 'per policy priority' 文案改掉 → 4 pass / 1 fail(:27 的 selectedReason 断言)。所以这两个新字段的行为确实被守住了。

但:

  • 循环里的用例都在 sourceCount 断言处短路,导致后面针对 decision / reason 的断言在变异下结构上不可达;
  • expect(values).not.toContain(mean) 对双元素 fixture 是恒真断言(两个不同数的均值不可能等于其中任一),抓不到"静默平均";
  • reconciliation.ts:19(未配置 providerPriority 的分支)没有任何用例覆盖 —— 四个 fixture 要么走早返回、要么显式设置了 priority;
  • 从未断言 result.selected.value,"不平均"只通过整数组相等间接体现;
  • 与既有 reconciliation.test.ts 在四类分类上有重复;本次真正新增的覆盖是 insufficient-sources、sourceCount、selectedReason、policyVersion 透传、整数组相等 —— 建议在描述里点明,免得看起来像重复劳动。

顺带

实际 parent 是 ba5dcdf,不是描述里的 2b5b88d3(#284 合并前的一个提交);#284 不碰 packages/core,无冲突、不需要 rebase。另外描述里 reconciliation.ts 的改动量按 git diff 是 +14/-5。

Address review feedback on helsome#287:
- move fixtures out of the public API surface: drop the index.ts
  re-export and relocate them to src/testing/ (test-only convention),
  re-adding the FAKE/SAMPLE banner so no one mistakes them for live data
- align fixture timestamps with the declared reporting periods and add an
  instrument field to attribute every candidate to a symbol
- make ReconciliationResult.sourceCount optional to avoid a breaking type
  change while every return path still populates it
- extend coverage: instrument attribution, no provider-priority branch,
  and non-averaging assertions via toContain on the selected value
@kbkb628
kbkb628 merged commit 3a17eca into helsome:main Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants