docs: annotate Foundry source and deployment lifecycle in Chinese [skip ci]
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Canonical 原子性数据库回归:需 PLATFORM_TEST_DATABASE_URL 指向隔离且已迁移测试库,未配置则跳过。
|
||||
package platform
|
||||
|
||||
import (
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// canonicalAtomicFixture 持有随机项目、真实路由与源快照,所有请求共用有效账户和独立工作区。
|
||||
type canonicalAtomicFixture struct {
|
||||
db *sql.DB
|
||||
mux *http.ServeMux
|
||||
@@ -23,6 +25,7 @@ type canonicalAtomicFixture struct {
|
||||
legacy json.RawMessage
|
||||
}
|
||||
|
||||
// newCanonicalAtomicFixture 建账户/会话/admin/旧图,并按外键关系注册数据清理;不自动执行迁移脚本。
|
||||
func newCanonicalAtomicFixture(t *testing.T) *canonicalAtomicFixture {
|
||||
t.Helper()
|
||||
dsn := os.Getenv("PLATFORM_TEST_DATABASE_URL")
|
||||
@@ -68,10 +71,12 @@ func newCanonicalAtomicFixture(t *testing.T) *canonicalAtomicFixture {
|
||||
return f
|
||||
}
|
||||
|
||||
// path 返回本 fixture 根的 canonical 入口,避免测试错用旧快照路径。
|
||||
func (f *canonicalAtomicFixture) path() string {
|
||||
return "/projects/" + f.project + "/workspaces/" + f.workspace + "/materials/" + f.root + "/canvas/model"
|
||||
}
|
||||
|
||||
// request 携带会话、预期账户及 v2 协商,并沿用传入 context 以测试数据库写入中途取消。
|
||||
func (f *canonicalAtomicFixture) request(ctx context.Context, method, path, key string, raw []byte) *httptest.ResponseRecorder {
|
||||
r := httptest.NewRequest(method, path, bytes.NewReader(raw)).WithContext(ctx)
|
||||
r.Header.Set("Authorization", "Bearer "+f.token)
|
||||
@@ -85,6 +90,7 @@ func (f *canonicalAtomicFixture) request(ctx context.Context, method, path, key
|
||||
return w
|
||||
}
|
||||
|
||||
// canonicalAtomicResponse 先断言实际 HTTP 状态,再解码响应,避免把错误 JSON 当作正常模型使用。
|
||||
func canonicalAtomicResponse(t *testing.T, w *httptest.ResponseRecorder, status int) response {
|
||||
t.Helper()
|
||||
if w.Code != status {
|
||||
@@ -97,6 +103,7 @@ func canonicalAtomicResponse(t *testing.T, w *httptest.ResponseRecorder, status
|
||||
return body
|
||||
}
|
||||
|
||||
// read 直接从权威模型表装配完整模型,检查 HTTP 应答外的持久化事实。
|
||||
func (f *canonicalAtomicFixture) read(t *testing.T) canvasModel {
|
||||
t.Helper()
|
||||
tx, err := f.db.BeginTx(context.Background(), nil)
|
||||
@@ -111,6 +118,7 @@ func (f *canonicalAtomicFixture) read(t *testing.T) canvasModel {
|
||||
return model
|
||||
}
|
||||
|
||||
// concurrent 同时放行多请求并按原索引收集,二十秒上下文限制等待,不以返回顺序猜赢家。
|
||||
func (f *canonicalAtomicFixture) concurrent(t *testing.T, path string, keys []string, bodies [][]byte) []*httptest.ResponseRecorder {
|
||||
t.Helper()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
@@ -139,6 +147,8 @@ func (f *canonicalAtomicFixture) concurrent(t *testing.T, path string, keys []st
|
||||
return out
|
||||
}
|
||||
|
||||
// TestCanonicalConcurrentMigrationAndOwnershipWrites 验证同键迁移/编辑只执行一次,不同条件所有权写只有一个赢家。
|
||||
// 成功和冲突都必须有可查询冻结回执,未涉及元素和树不得被部分改写。
|
||||
func TestCanonicalConcurrentMigrationAndOwnershipWrites(t *testing.T) {
|
||||
f := newCanonicalAtomicFixture(t)
|
||||
ctx := context.Background()
|
||||
@@ -176,6 +186,7 @@ func TestCanonicalConcurrentMigrationAndOwnershipWrites(t *testing.T) {
|
||||
if before.Versions[child] != 2 || before.Versions[f.root] != 2 || modelString(before.Elements[ids["a"]]["data"].(map[string]any)["title"]) != "renamed" {
|
||||
t.Fatal("concurrent edit executed more than once")
|
||||
}
|
||||
// 两请求共享同一版本向量,各移动不同节点但都移动其连接,验证条件写竞争而非简单串行重放。
|
||||
var batches []modelBatch
|
||||
var keys []string
|
||||
var bodies [][]byte
|
||||
@@ -223,6 +234,8 @@ func TestCanonicalConcurrentMigrationAndOwnershipWrites(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestCanonicalMigrationLateCancellationRollsBack 用独占表锁卡住后期身份映射 INSERT,观察确实到达后才取消请求。
|
||||
// 所有模型/关系/新素材和旧版本应回滚,随后同原请求能安全重试且只分配一次最终身份映射。
|
||||
func TestCanonicalMigrationLateCancellationRollsBack(t *testing.T) {
|
||||
f := newCanonicalAtomicFixture(t)
|
||||
ctx, stop := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
@@ -247,6 +260,7 @@ func TestCanonicalMigrationLateCancellationRollsBack(t *testing.T) {
|
||||
go func() { done <- f.request(requestContext, "POST", f.path()+"/migrate", key, modelJSON(input)) }()
|
||||
// Observe the actual late INSERT blocked behind this transaction. A timer
|
||||
// alone cannot prove migration reached canonical/material/subgraph writes.
|
||||
// 查询 pg_stat_activity/pg_blocking_pids 证明是目标后期写被阻塞,不用单纯 sleep 推断执行进度。
|
||||
ticker := time.NewTicker(10 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
observed := false
|
||||
@@ -299,6 +313,8 @@ func TestCanonicalMigrationLateCancellationRollsBack(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestCanonicalMigrationPermissionVersionAndRunGuards 检查 viewer、陈旧版本及 queued/running AI 阻止身份屏障。
|
||||
// 原拒绝键在版本或任务状态改变后仍冻结,新的请求键才能在条件满足后执行迁移。
|
||||
func TestCanonicalMigrationPermissionVersionAndRunGuards(t *testing.T) {
|
||||
f := newCanonicalAtomicFixture(t)
|
||||
ctx := context.Background()
|
||||
|
||||
Reference in New Issue
Block a user