chore: 初始化仓库,导入项目基线代码

Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、
Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。
今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
runny committed 2026-11-16 18:12:23 +08:00
commit 7ec21f35b0
5767 files changed
+1436788

No files matched your search

@@ -0,0 +1,64 @@
package handler
import (
"reflect"
"strings"
"testing"
"academy/internal/types"
)
// TestUpdateKBRequest_DoesNotAcceptVectorStoreID is the structural enforcement
// behind the vector_store_id immutability contract. The GORM `<-:create`
// tag on KnowledgeBase.VectorStoreID already blocks every ORM UPDATE path
// (verified by the repository-level sqlite immutability tests), but the
// service DTO must independently refuse to even *accept* the field —
// otherwise a future maintainer who adds it to UpdateKnowledgeBaseRequest
// or KnowledgeBaseConfig opens a path where the field is silently ignored
// by the ORM, which is worse than an explicit rejection.
//
// This test walks the request and config struct shapes and fails if either
// gains a VectorStoreID member, by name or by JSON tag.
func TestUpdateKBRequest_DoesNotAcceptVectorStoreID(t *testing.T) {
t.Run("UpdateKnowledgeBaseRequest", func(t *testing.T) {
assertNoVectorStoreIDField(t, reflect.TypeOf(UpdateKnowledgeBaseRequest{}))
})
t.Run("KnowledgeBaseConfig", func(t *testing.T) {
// Config carries chunking / extract / faq / wiki sub-configs and must
// not be extended with a VectorStoreID either (Config is passed
// straight into the service Update path).
assertNoVectorStoreIDField(t, reflect.TypeOf(types.KnowledgeBaseConfig{}))
})
}
// assertNoVectorStoreIDField walks the visible fields of t (including embedded
// anonymous structs) and reports any field named VectorStoreID or carrying
// a json tag of "vector_store_id".
func assertNoVectorStoreIDField(t *testing.T, typ reflect.Type) {
t.Helper()
var visit func(rt reflect.Type, path string)
visit = func(rt reflect.Type, path string) {
for rt.Kind() == reflect.Ptr {
rt = rt.Elem()
}
if rt.Kind() != reflect.Struct {
return
}
for i := 0; i < rt.NumField(); i++ {
f := rt.Field(i)
full := path + "." + f.Name
if f.Name == "VectorStoreID" {
t.Fatalf("%s declares VectorStoreID — vector_store_id is immutable post-create "+
"and must not be accepted by update DTOs", full)
}
if tag := strings.Split(f.Tag.Get("json"), ",")[0]; tag == "vector_store_id" {
t.Fatalf("%s carries json tag \"vector_store_id\" — the field is immutable "+
"post-create and must not be accepted by update DTOs", full)
}
if f.Anonymous {
visit(f.Type, full)
}
}
}
visit(typ, typ.Name())
}