Skip to content

fix: 增强持仓导入解析(成本列、币种与全角数字) - #356

Open
wannT-1 wants to merge 8 commits into
helsome:mainfrom
wannT-1:cursor/portfolio-import-parsing-4254
Open

wannT-1 wants to merge 8 commits into
helsome:mainfrom
wannT-1:cursor/portfolio-import-parsing-4254

Conversation

@wannT-1

@wannT-1 wannT-1 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

改动说明

What: 增强 portfolio-import 解析,覆盖成本列、币种/会计数字、全角数字、零宽字符,以及 symbol 长度 1–6。

Why: 让 CSV / 持仓导入解析更稳健(more robust CSV/import parsing)。

  • 同时存在 Price 与成本列时,改用更具体的表头
  • 数值解析识别 HK$ / US$ / 人民币等货币符号与会计格式数字
  • 支持全角数字与零宽字符
  • symbol 长度允许 1–6

关联 Issue

无关联 Issue。本 PR 为导入解析健壮性修复。

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

环境

  • Bun:按验证命令执行(版本未在开 PR 时另行记录)
  • OS:未在开 PR 时另行记录

实际执行命令与结果

bun test --isolate packages/shared/src/portfolio-import packages/longbridge-tools/src/validator.test.ts
→ 119 pass

bun run --filter @finagent/shared typecheck
→ exit 0

已知失败 / Baseline(如有)

无已知失败。

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

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

  • 本 PR 无可见 UI 变化(无需截图)
  • 本 PR 有可见 UI 变化,已提供修改后的 UI 截图
  • 已提供 Before / After 对比截图(适用时)

无可见 UI 变化。

Scope / 后续

Note: 7 commits dated June 2026(共 7 个 commit,日期为 2026 年 6 月)。

wannT-1 and others added 7 commits June 3, 2026 10:18
左侧的 Price/价格列不再抢走同一行里的 Cost、Avg Cost 或成本。只有没有更具体的成本列时,Price 才继续作为成本兜底。

Co-authored-by: wannT-1 <wannT-1@users.noreply.github.com>
券商导出把 HK$、US$、¥ 或 USD 粘在数量和成本上时,不再整格判成无效数字。只剩货币符号、没有数字的格子仍然保持无效。

Co-authored-by: wannT-1 <wannT-1@users.noreply.github.com>
对账单里的 (180.50)、(HK$1,234.50) 和 1,234.56- 不再被当成无效成本。只有括号或货币符号、没有数字时仍然无效。

Co-authored-by: wannT-1 <wannT-1@users.noreply.github.com>
中文表格里的全角数字、全角逗号、全角小数点和全角美元符号不再让数量或成本变成缺失字段。

Co-authored-by: wannT-1 <wannT-1@users.noreply.github.com>
网页粘贴带上的零宽空格会让 Symbol 列表头匹配失败,整表变成没有代码的行。现在表头和数值会先去掉这些不可见字符。

Co-authored-by: wannT-1 <wannT-1@users.noreply.github.com>
7 位以上的代码(如 6005191.SH、TOOLONG.US)不再被当成可直接导入的标准符号。A 股 6 位代码仍然有效,校验注释里过时的 1–5 位说明也已改掉。

Co-authored-by: wannT-1 <wannT-1@users.noreply.github.com>
CLAUDE 和 API 参考里的 5 位上限会拒绝合法的 6 位 A 股代码(如 600519.SH)。文档改为与校验实现一致的 1–6 位。

Co-authored-by: wannT-1 <wannT-1@users.noreply.github.com>
Resolve conflicts from helsome#413 (trailing-percent confirmation) and helsome#414
(semicolon CSV) landing upstream:

- toFiniteNumber now runs the branch's normalisation pipeline
  (stripInvisible -> foldNumericWidth -> takeAccountingSign ->
  stripCurrencyAffixes) and feeds the result into upstream's
  stripNumericDecorations, so the trailing-% semantics added by helsome#413
  are preserved instead of reverting them.
- Symbol length is 1-6 upstream already, so the branch's 1-6 change and
  its docs were dropped rather than re-applied.
- Tests: kept this branch's currency / accounting-negative / fullwidth /
  zero-width cases and upstream's percent-confirmation cases.

packages/shared/src/portfolio-import: 125 pass, 0 fail.
@wannT-1

wannT-1 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Updated the branch against current main and consolidated the portfolio-import work into this PR.

What changed

  • Merged upstream/main (including fix(portfolio-import): 数量/成本尾随百分号改为需人工确认 #413's trailing-% confirmation and fix(portfolio-import): 支持分号分隔 CSV #414's semicolon CSV). Conflicts were in parsers.ts / parsers.test.ts only.

  • toFiniteNumber now runs this branch's normalisation pipeline and then hands the result to upstream's stripNumericDecorations:

    const accounting = takeAccountingSign(foldNumericWidth(stripInvisible(value)))
    const trimmed = stripCurrencyAffixes(accounting.text)
    const cleaned = stripNumericDecorations(trimmed)

    so fix(portfolio-import): 数量/成本尾随百分号改为需人工确认 #413's "a trailing % is never booked as 100 / 12.5" semantics are preserved rather than reverted, while the currency-affix / accounting-negative / fullwidth / zero-width handling from this branch still applies.

  • Dropped this branch's 1–6 symbol-length change and its docs: upstream already ships SYMBOL_REGEX = /^[A-Z0-9]{1,6}\.(US|HK|SG|SH|SZ|HAS)$/ in packages/longbridge-tools/src/validator.ts, so re-applying it would have been a no-op revert.

  • Tests: kept this branch's currency / accounting / fullwidth / zero-width cases and upstream's percent-confirmation cases.

Why the other three PRs were closed

#358, #359 and #360 are strict subsets of this one — measured on added source lines, 95% / 90% / 87% of their content is already contained here. Keeping four conflicting branches open over the same three functions only asks the maintainer to reconcile them by hand, so they are closed with a pointer to this PR instead.

Verification

bun test packages/shared/src/portfolio-import/   -> 125 pass, 0 fail
tsc --noEmit -p packages/shared/tsconfig.json    -> exit 0

mergeable_state is now clean.

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.

1 participant