Skip to content

fix(portfolio-import): 草稿行全部带 issue 时仍静默创建空组合 - #244

Open
wxrbyte wants to merge 1 commit into
helsome:mainfrom
wxrbyte:codex/fix-import-confirm-empty-portfolio
Open

wxrbyte wants to merge 1 commit into
helsome:mainfrom
wxrbyte:codex/fix-import-confirm-empty-portfolio

Conversation

@wxrbyte

@wxrbyte wxrbyte commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Closes #243

问题

importConfirm 的 IMPORT_EMPTY 守卫作用在过滤前的 rows 上,而真正落库的是过滤后的 holdings:

if (rows.length === 0) { throw createCodeError('IMPORT_EMPTY', ...); }   // 守 rows
const holdings = rows.filter((row) => row.symbol && row.issues.length === 0).map(...);  // 落 holdings
return this.importRepository.create({ name, holdings });                // holdings 为空也创建

只要草稿有行守卫就放行;当每一行都还带着 issues 时 holdings 是空数组,于是持久化一条 0 持仓的组合并返回成功。UI 侧同样放行 —— ImportDraftReview 的确认按钮只在 draft.rows.length === 0 时禁用,所以用户在「每行都缺字段」的 CSV 上仍可点击确认,然后拿到一个空组合且没有任何提示。

改动

文件 改动
apps/electron/src/main/kernelHost.ts 守卫移到落库集合上:先算 importable,importable.length === 0 即抛 IMPORT_EMPTY;holdings 由同一个 importable 映射
packages/ui/src/components/portfolio/ImportDraftReview.tsx 确认按钮改为 `disabled={confirming
apps/electron/src/main/kernelHost.test.ts 新增:全部行带 issue 时 importConfirm 必须 reject IMPORT_EMPTY
packages/ui/src/components/portfolio/ImportDraftReview.test.tsx 新增两条:全部行带 issue → 按钮禁用;至少一行可导入 → 按钮仍可点

原 rows.length === 0 分支被新守卫覆盖(空 rows 必然导致空 importable),因此没有重复判断。

验证

bun test apps/electron/src/main/kernelHost.test.ts packages/ui/src/components/portfolio/ImportDraftReview.test.tsx
  • 修复前:20 pass / 2 fail
    • expect(promise).rejects.toMatchObject({ code: 'IMPORT_EMPTY' }) → Received promise that resolved: Promise { <resolved> }
    • 按钮 disabled → Expected: true, Received: false
  • 修复后:22 pass / 0 fail
  • bun run typecheck:@finagent/core、@finagent/i18n、@finagent/shared、@finagent/ui、@finagent/electron 全部 Exited with code 0

对合法导入(至少一行无 issue)行为完全不变:holdings 仍只包含无 issue 的行,name 与仓库层未改动。

重叠披露

apps/electron/src/main/kernelHost.ts 同时被 5 个 open PR 触及(#97、#64、#56、#53、#4)。已逐个拉取各 PR 的 patch 与改动块标题比对:

  • 没有一处改动 importConfirm 或 ImportDraftReview;
  • 其中最接近的是 feat: add safe local skill installation #4 的 @@ -2101,6 +2135,9 @@ —— 行号与本次改动相邻,但它改的是另一个方法里的 env: NodeJS.ProcessEnv 构造块(新增 FINAGENT_SKILLS_DIRS),与本次改动内容不相交。

若上述任一 PR 先合入,本分支按需 rebase。

importConfirm 的 IMPORT_EMPTY 守卫作用在过滤前的 rows 上,而真正落库的是
过滤掉 issues 后的 holdings:只要草稿有行就一定放行,holdings 为空时也会
创建一条 0 持仓的组合并返回成功。守卫改为作用在落库集合上;ImportDraftReview
的确认按钮同步改为「无可导入行即禁用」。

修复前 20 pass / 2 fail → 修复后 22 pass / 0 fail。

Closes helsome#243
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.

fix(portfolio-import): 草稿行全部带 issue 时仍静默创建空组合

1 participant