Files
sundynix-agentix/sundynix-shared/blob/minio_e2e_test.go
T
Blizzard ec9431bfa4 fix(report): 报告源/产物落 MinIO,去掉 gateway↔mcp-go 本地盘耦合
多机/容器化第一时间断裂的隐患(ARCHITECTURE_REVIEW §7 #1):此前报告
源(reportStore)与 .docx 产物(reportExport/reportRender)都写 mcp-go
本地 SUNDYNIX_REPORTS_DIR,gateway 再按同一路径 c.File 回流——mcp-go
与 gateway 不共享磁盘即断。

- blob 包从 gateway/internal 提到 sundynix-shared/blob,gateway 与 mcp-go
  共用同一 MinIO;新增 PutBytes/GetBytes 走二进制(.docx)。
- mcp-go 注入 blob:report 源/产物优先 Put 到对象存储(键 reports/<id>.{json,docx}),
  导出结果返回 minio://<key>;MinIO 未就绪回退本地盘(单机降级,getSource 兼容旧本地报告)。
- gateway ExportReport 识别 minio:// → GetBytes 流式下载,否则 c.File 本地降级。
- 测试:mcp 本地回落往返单测 + shared/blob 真 MinIO 二进制往返(BLOB_TEST_ENDPOINT 门控)。
  四模块 build 绿,受影响测试全过。
- 附带:go mod tidy 引入 genproto 拆包冲突,四模块统一钉单体 genproto 新版解决
  (注:勿 go work sync,会剪掉 indirect require 回落旧版重现冲突)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 13:29:31 +08:00

46 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package blob
import (
"bytes"
"context"
"os"
"testing"
)
// 真 MinIO 端到端:验证二进制对象(.docx 场景)Put/Get 字节级往返一致。
// 设 BLOB_TEST_ENDPOINT(如 localhost:9000)启用;缺省跳过,不拖累 CI。
// BLOB_TEST_{ACCESS,SECRET,BUCKET} 可覆盖,默认 minioadmin/minioadmin/sundynix-docs。
func TestBlob_BinaryRoundTrip_RealMinIO(t *testing.T) {
ep := os.Getenv("BLOB_TEST_ENDPOINT")
if ep == "" {
t.Skip("设 BLOB_TEST_ENDPOINT 启用真 MinIO 端到端测试")
}
envOr := func(k, d string) string {
if v := os.Getenv(k); v != "" {
return v
}
return d
}
s := Open(ep, envOr("BLOB_TEST_ACCESS", "minioadmin"),
envOr("BLOB_TEST_SECRET", "minioadmin"), envOr("BLOB_TEST_BUCKET", "sundynix-docs"))
if !s.Ready() {
t.Fatal("MinIO 应连上(Ready")
}
ctx := context.Background()
key := "reports/blob-e2e-test.docx"
defer func() { _ = s.Delete(ctx, key) }()
// 含 NUL 与非 UTF8 字节,模拟真实 .docx(zip)二进制。
want := []byte("PK\x03\x04\x00\x01\x02\xff\xfe\x00binary-docx-body")
if err := s.PutBytes(ctx, key, want, "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); err != nil {
t.Fatalf("PutBytes: %v", err)
}
got, err := s.GetBytes(ctx, key)
if err != nil {
t.Fatalf("GetBytes: %v", err)
}
if !bytes.Equal(got, want) {
t.Fatalf("字节不一致:\n got=%q\nwant=%q", got, want)
}
}