mateclaw/mateclaw-server/src/test/java/vip/mate
倪程伟 fcb488c567
feat(workspace): chat-uploads 上传目录工作空间/Agent 感知化 (#422)
* feat(workspace): chat-uploads 上传目录工作空间/Agent 感知化 (#421)

把硬编码的 data/chat-uploads/{conversationId}/ 改为按工作空间/Agent 解析,
解析优先级:Agent workspaceBasePath → Workspace basePath → 可配置默认目录
(新配置 mateclaw.chat.upload.base-dir,默认 data/chat-uploads,保持现网零行为变化)。

- 新增 ChatUploadLocationResolver 中央解析器:写路径返回唯一根,读/清理
  路径返回候选根列表(工作空间根 + 默认根)做双重查找,保证迁移前旧附件
  仍可解析/清理;conversationId→ConversationEntity 查询带 5min 缓存。
- 新增 ChatUploadProperties + ChatUploadAutoConfiguration(启动建目录)。
- 复用 AgentGraphBuilder.resolveAgentBasePath(提升为 public)的优先级与
  安全规则(相对路径在 workspace 根下解析,绝对路径逃逸被拒)。
- 所有写入/读取点改为走 resolver;读取点走双重查找。
- 解决 Spring 循环依赖(resolver → agentService → ... → conversationService
  → resolver):resolver 的 AgentService 注入加 @Lazy。

向后兼容:默认目录不变;双重查找覆盖历史消息里的相对路径;
服务端点 URL 契约不变,前端无需改动。

测试:新增 ChatUploadLocationResolverTest(8 用例);修复受影响的现有测试构造。

* refactor(workspace): address review findings on chat-uploads resolver (#421)

应用 code review 的 4 项修复:

1. (correctness) ChatUploadLocationResolver 缓存新增 ConversationDeletedEvent
   监听器,删除会话时立即失效 conversationId→ConversationEntity 映射。
   否则备份恢复后用相同 id 重建会话,会继承最长 5 分钟的过期 workspace/agent
   映射,导致 cleanAttachmentFiles 走错(过期的)上传目录。复用既有
   @EventListener-on-bean 模式(与 AsyncTaskService / WorkspaceLookupCache 一致)。

2. 收紧 resolveWorkspaceScopedRoot 里 3 个过宽的 catch(Exception) →
   MateClawException + warn,让真正的 bug(NPE / DataAccessException)暴露
   而非被静默降级为 debug 日志。

3. 更新 ChatController.upload 过期注释:会话尚未创建时附件暂存默认目录,
   会话创建后读取走双重查找仍能命中。

4. 移除不可达分支(agentWorkspaceId != workspaceId)—— 会话的 agent 必然
   归属会话的 workspace(创建时强约束),直接用会话 workspace 即可,
   少一次冗余 DB 查询与一层推测性逻辑。

测试:ChatUploadLocationResolverTest (8) + ConversationServiceCleanAttachmentFilesTest (2) 全绿。
2026-06-26 14:20:54 +08:00
..
acp/client chore(test): backfill mateclaw-server/src/test/ that earlier PRIVATE_ITEMS pattern accidentally excluded 2026-05-12 17:38:08 +08:00
agent fix(agent): normalize replayed tool-call arguments to valid JSON (#410) 2026-06-26 11:19:19 +08:00
approval fix(workflow): activate approval notify + resolve→resume bridge (ISSUE #413 P0) (#414) 2026-06-25 09:54:55 +08:00
architecture feat(agent): loop-engineering robustness — goal continuation, plan re-plan, stall detection 2026-06-17 06:37:08 +08:00
auth feat(sso): 飞书 OAuth2 单点登录 (ISSUE #405 P0) (#419) 2026-06-26 10:00:31 +08:00
channel feat(workspace): chat-uploads 上传目录工作空间/Agent 感知化 (#422) 2026-06-26 14:20:54 +08:00
common feat(agent): deterministic Markdown normalization for final answers (#275) 2026-06-07 19:10:53 +08:00
config feat(security): gate Swagger/OpenAPI UI behind mateclaw.openapi.expose-ui flag 2026-06-24 10:42:46 +08:00
cron fix(tool): emit absolute download URLs for streaming-generated files (#164) 2026-06-07 15:03:48 +08:00
dashboard/service fix(dashboard): count tool calls from assistant.metadata, not role=tool rows 2026-05-24 22:58:02 +08:00
exception fix(exception): return 405 for HttpRequestMethodNotSupportedException 2026-06-19 06:20:59 +08:00
goal fix(goal): drop score gate, bill failed evaluator calls, fix Evaluator SPI + tool prompt + bootstrap cap 2026-06-03 21:19:27 +08:00
hook chore(test): backfill mateclaw-server/src/test/ that earlier PRIVATE_ITEMS pattern accidentally excluded 2026-05-12 17:38:08 +08:00
i18n chore(test): backfill mateclaw-server/src/test/ that earlier PRIVATE_ITEMS pattern accidentally excluded 2026-05-12 17:38:08 +08:00
llm feat(agent): retain image context across turns for follow-ups (#303) 2026-06-11 13:53:56 +08:00
memory feat(memory): bound always-on memory growth with injection budget, consolidation, and file ceilings 2026-06-17 11:04:19 +08:00
skill feat(skill): self-evolving skills — out-of-band reflection, curator consolidation, agent-authored skill files 2026-06-23 13:51:04 +08:00
stt chore(test): backfill mateclaw-server/src/test/ that earlier PRIVATE_ITEMS pattern accidentally excluded 2026-05-12 17:38:08 +08:00
system test(skill): end-to-end coverage for the lifecycle curator 2026-05-19 09:56:27 +08:00
task test(task): de-flake the submitOneShot enrolled-latch ordering test 2026-05-16 14:51:57 +08:00
tool feat(workspace): chat-uploads 上传目录工作空间/Agent 感知化 (#422) 2026-06-26 14:20:54 +08:00
trigger test(trigger): await async dispatch in ChannelMessageTriggerTest 2026-06-09 10:00:30 +08:00
wiki feat(wiki): configurable entity types, type legend filter & theme-aligned graph colors (#336) 2026-06-19 07:18:09 +08:00
workflow fix(workflow): activate approval notify + resolve→resume bridge (ISSUE #413 P0) (#414) 2026-06-25 09:54:55 +08:00
workspace feat(workspace): chat-uploads 上传目录工作空间/Agent 感知化 (#422) 2026-06-26 14:20:54 +08:00