Skip to content

feat: route public badcases by label to workspaces (#582) - #597

Open
HaleyBG wants to merge 23 commits into
mainfrom
codex/issue-582-badcase-label-space-assignment
Open

HaleyBG wants to merge 23 commits into
mainfrom
codex/issue-582-badcase-label-space-assignment

Conversation

@HaleyBG

@HaleyBG HaleyBG commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

公共 badcase 按 label 划分工作空间 (#582)

让每个工作空间配置其接受的公共 badcase label,公共目录同步按 label 把一条公共 badcase 多对多分配到所有匹配空间,并让列表、Session、统计与自进化统一走同一空间边界。

变更概览

提交 内容
feat(db) 新增 workspace_bad_case_labels、workspace_bad_cases 关联表与 bad_cases.catalog_label 投影列;迁移 0033 按 origin 回填 direct_ingest/legacy_owner,并把存量 catalog 标签投影到 catalog_label
feat(api) GET/PUT /api/workspaces/{wid}/bad-case-labels:单事务锁定空间、全量替换规则、删除本空间 catalog_label 关联并按索引列重建历史
feat(sync) 目录同步页事务内 upsert 事实 → 删本页 legacy/catalog 关联 → 按规则重建 → 游标最后推进;新增 catalog_synced 列与 assigned/unassigned/invalid 计数
fix(ingest) 直接上报写 direct_ingest 关联、收敛 legacy、额度与 used 改按关联去重计数
refactor(api) WorkspaceReadScope.case_condition() 统一读边界,10 处读路径从 bad_cases.workspace_id 切到关联
feat(web) 空间管理新增「Badcase 类型」页签(位于「上报接入」与「归因 Skill」之间)+ V2 原型同步
docs architecture 双语、Agent Note、flow issue 措辞对齐与撞号修复
test(api) 关联边界跨栈测试 + fixture 回填幂等修复
fix(ci) 修复首轮 CI:SQLite savepoint 回滚、外部契约新增列、fixture/e2e 关联回填与页签数量
fix(review) 检视修复:归因进度按请求空间匹配报告;存量 label 与 origin 迁移回填;SQLite 替换写锁;PUT 的 items 必填

设计要点

  • bad_cases 保留单份公共事实(全局 bad_case_id 主键),可见性由 workspace_bad_cases(workspace_id, bad_case_id, assignment_source) 关联决定。
  • assignment_source 三态:legacy_owner(迁移回填)/ direct_ingest(凭据上报)/ catalog_label(label 命中)。同空间同 case 可同时有直接上报与 label 两种关联,读取 DISTINCT 去重。
  • bad_cases.catalog_label 是 meta_data.label 验证后的查询投影,非第二事实源;统计与重建只查列、不在 SQL 解析 JSON。
  • label 契约:1–128 字符、无首尾空白、区分大小写精确匹配;缺失/非法/未配置 label 保留事实但不进任何空间。
  • 所有空间读路径统一经 WorkspaceReadScope.case_condition();bad_cases.workspace_id 仅保留直接上报归属。已持久化候选/报告/运行快照不反查实时关联。

检视

  • 结构化检视记录:plans/2026-11-25-pr597-review.md(D1/D2/D3/D4/D6/D8 已在本 PR 修复并补测试;D5 同步写放大与 D7 计数口径作为取舍保留)。

验证

  • 契约:pnpm contract:check 通过;类型/文档/流程门禁(typecheck / typecheck:web / lint:docs / verify:flow)通过。
  • 后端测试:tests/workspaces、tests/m6-16-bad-case-catalog-sync、tests/m8-02-session-latest-ten、tests/m8-03-workspace-overview、tests/ingest 全绿。
  • 前端测试:vitest(Badcase 类型页签 + 管理页导航)。

关联

  • 设计文档:plans/fullstack-design/17-workspace-bad-case-label-routing.md
  • 实施计划:plans/superpowers/plans/2026-11-24-issue-582-badcase-label-routing.md
  • Agent Note:.agents/notes/implemented/feature/2026-11-24-workspace-bad-case-label-routing.md

冒烟与视觉对比(2026-11-25)

在 PR head 94c018b9(之后的检视修复未改动 UI 代码,最终 head bf7f0912 视觉一致)的本地 SQLite demo corpus 上运行真实浏览器冒烟:独立 Smoke Labels 空间 + 两条 catalog_label 公共 badcase(code-review / tool-use),headless Chrome 1440×960,11 个场景全部通过,未发现需要修复的产品缺陷。证据 release:pr-597-smoke-evidence-20261125(截图、smoke-report.html、report-data.json、zip;不提交代码仓)。

Before · main 744f4f57

工作空间管理只有 5 个页签,没有「Badcase 类型」。

before: main 744f4f57 workspace admin

After · PR head 94c018b9(UI 与最终 head bf7f0912 相同)

新增「Badcase 类型」页签;保存规则后提示「历史数据已重新划分」,历史公共 badcase 立即回填(已关联 1 条)。

after: PR head 94c018b9 badcase labels tab

与 V2 原型 HTML 同场景对照

同 viewport、同数据(code-review / 已关联 1 条)下,页签顺序、面板层级、标题与说明、chip 样式、保存按钮与计数文案一致;差异仅来自原型外壳的品牌/演示账号。

prototype: V2 HTML badcase labels panel

场景矩阵

# 场景 结果
01 未配置 label:空态提示 + 保存禁用 PASS
02 首尾空白 label:行内校验拒绝 PASS
03 添加 label 后出现未保存提示 PASS
04 保存后回填 1 条历史公共 badcase PASS
05 刷新后配置与关联数持久化 PASS
06 第二个 label 保存后回填 2 条 PASS
07 两条 label 命中用例同时进入概览列表 PASS
08 移除 tool-use 后仅保留 code-review 可见 PASS
09 只读成员可见配置、无保存/输入/移除控件 PASS
10 实现页面与原型同场景截图对照 PASS

端到端可见性证据:保存两个 label 后概览两条用例;移除 tool-use 后仅剩 code-review;只读成员视图。

…se-label-space-assignment

# Conflicts:
#	apps/api/app/db/crud/bad_case_catalog_sync.py
#	apps/api/tests/m6-16-bad-case-catalog-sync/test_migration.py
#	docs/architecture.i18n.yaml
…se-label-space-assignment

# Conflicts:
#	docs/architecture.i18n.yaml
@ZTGolem ZTGolem added this to the Bugfix 问题修复 milestone Nov 25, 2026
- open the SQLite transaction before nested savepoints so a failed catalog page rolls back fact and cursor together
- declare catalog_label/catalog_synced in the external contract and accept MySQL TINYINT(1) for booleans
- backfill legacy associations in fixtures, corpus seeds and e2e helpers
- refresh the OpenAPI path list and the workspace admin e2e tab count
- mark bugfix-58 in-progress and close bugfix-56 in the flow tree
- analysis_progress matches probe reports by the requesting workspaces instead of the legacy case owner
- migration 0033 projects existing catalog labels, marks them synced, and maps report/catalog origins to direct_ingest/legacy_owner idempotently
- mirror the origin-aware backfill in fixtures and cover the data migration
- take the SQLite write lock during label replacement
- require items on the label replacement request and regenerate contracts
- add the structured review record with dispositions
…se-label-space-assignment

# Conflicts:
#	.agents/flow/issues/bugfix-explicit-skill-conclusion.i18n.yaml
- start the SQLite transaction inside commit_page with a no-op UPDATE so begin_nested cannot commit the page unit, without making every transaction eagerly hold a read snapshot
- renumber the new label and sync-type-title issues to bugfix-60/61 to avoid ids introduced on main
- mark the portable backend issue done after #604 closed
- refresh the review record's issue references
…se-label-space-assignment

# Conflicts:
#	.agents/flow/issues/bugfix-bad-case-sync-type-title.i18n.yaml

This branch has not been deployed

No deployments
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