docs: annotate Foundry source and deployment lifecycle in Chinese [skip ci]
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// 跨画布连线数据库回归需要 PLATFORM_TEST_DATABASE_URL 指向隔离且已迁移测试库;未配置则跳过。
|
||||
package platform
|
||||
|
||||
import (
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestCanvasConnectionTransactions 在隔离 PostgreSQL 中走完整 HTTP 连线/撤销/重试链路,并验证拒绝请求与容量失败没有部分持久化。
|
||||
func TestCanvasConnectionTransactions(t *testing.T) {
|
||||
dsn := os.Getenv("PLATFORM_TEST_DATABASE_URL")
|
||||
if dsn == "" {
|
||||
@@ -69,6 +71,7 @@ func TestCanvasConnectionTransactions(t *testing.T) {
|
||||
Register(mux, db, map[string]string{project: "https://app.example.com/auth/callback"}, "https://api.example.com", nil)
|
||||
base := "/projects/" + project + "/workspaces/" + workspace + "/materials/"
|
||||
path := func(board string) string { return base + board + "/canvas" }
|
||||
// do 只组请求,call 再验证状态/解码;全部请求显式协商 v2,避免旧客户端丢失端口数据。
|
||||
do := func(method, url, token string, body any, version int64, key string) *httptest.ResponseRecorder {
|
||||
raw, _ := json.Marshal(body)
|
||||
r := httptest.NewRequest(method, url, bytes.NewReader(raw))
|
||||
@@ -97,6 +100,7 @@ func TestCanvasConnectionTransactions(t *testing.T) {
|
||||
return out
|
||||
}
|
||||
key := func(n int) string { return fmt.Sprintf("a0000000-0000-4000-8000-%012d", n) }
|
||||
// 每次从真实 GET 读取参与者当前版本,构造恰好覆盖端口链的 expected_versions。
|
||||
versions := func(ids ...string) map[string]int64 {
|
||||
t.Helper()
|
||||
out := map[string]int64{}
|
||||
@@ -128,6 +132,7 @@ func TestCanvasConnectionTransactions(t *testing.T) {
|
||||
command := func(source, node, target, targetNode, id string, ids ...string) response {
|
||||
return response{"source": response{"board_id": source, "node_id": node, "handle": "right"}, "target": response{"board_id": target, "node_id": targetNode, "handle": "left"}, "edge": response{"id": id, "data": response{"appearance": response{"color": "#123456", "width": 2}, "path": response{"type": "bezier-chain", "knots": []any{response{"id": "k", "position": response{"x": 200, "y": 300}, "in": response{"x": -20, "y": 0}, "out": response{"x": 20, "y": 0}, "mode": "symmetric"}}}}}, "expected_versions": versions(ids...)}
|
||||
}
|
||||
// 从嵌套叶节点连到根节点,需要中间与根两个端口;叶文档本身不得被投影逻辑改写。
|
||||
firstBody := command(leaf, "deep", root, "a", "external", root, left, leaf)
|
||||
beforeLeaf := call("GET", path(leaf), tokens[0], nil, 200, 0, "")["document"]
|
||||
first := call("POST", path(root)+"/connections", tokens[0], firstBody, 201, 0, key(4))
|
||||
@@ -152,6 +157,7 @@ func TestCanvasConnectionTransactions(t *testing.T) {
|
||||
if len(parent["document"].(map[string]any)["edges"].([]any)) != 2 {
|
||||
t.Fatal("existing edge lost")
|
||||
}
|
||||
// 撤销还原所有参与快照并移除新端口;再次执行应恢复同一稳定逻辑端点映射。
|
||||
undo := call("POST", path(root)+"/transactions/"+first["transaction_id"].(string)+"/undo", tokens[0], response{"expected_versions": versions(root, left, leaf)}, 200, 0, key(5))
|
||||
if len(undo["snapshots"].([]any)) != 3 {
|
||||
t.Fatal("undo did not restore complete chain")
|
||||
@@ -181,6 +187,7 @@ func TestCanvasConnectionTransactions(t *testing.T) {
|
||||
t.Fatal("input chain reused output ports")
|
||||
}
|
||||
// Missing/stale participant versions, bad endpoints and permission failures are atomic.
|
||||
// 收集拒绝前版本,随后缺版本、旧版本、非法端点及权限失败都必须保持整个向量不变。
|
||||
stable := versions(root, left, leaf)
|
||||
missing := command(leaf, "deep", root, "a", "missing", root, left)
|
||||
required := call("POST", path(root)+"/connections", tokens[0], missing, 428, 0, key(10))
|
||||
@@ -203,6 +210,7 @@ func TestCanvasConnectionTransactions(t *testing.T) {
|
||||
t.Fatal("rejected transaction partially changed versions")
|
||||
}
|
||||
// The actual nested mapping is resolvable by the same reader used by AI propagation.
|
||||
// 将真实保存的快照交给 AI reader,确认连接生成的端口链可解析回真实叶节点。
|
||||
graph := map[string]canvasSnapshot{}
|
||||
for _, board := range []string{root, left, leaf} {
|
||||
read := call("GET", path(board), tokens[0], nil, 200, 0, "")
|
||||
@@ -257,6 +265,7 @@ func TestCanvasConnectionTransactions(t *testing.T) {
|
||||
t.Fatal("capabilities omitted connection transaction")
|
||||
}
|
||||
// Four simultaneous retries create exactly one edge/receipt and advance versions once.
|
||||
// 四个同键请求同时放行,必须共用回执并让每个参与画布恰好递增一次。
|
||||
concurrent := command(left, "l2", root, "a", "concurrent", root, left)
|
||||
prior := versions(root, left)
|
||||
start := make(chan struct{})
|
||||
@@ -285,6 +294,7 @@ func TestCanvasConnectionTransactions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
// A full coordinator rejects the entire operation, including new leaf ports.
|
||||
// 填满协调者边数再建新端口链,最终容量拒绝必须回滚叶端口、版本和事务记录。
|
||||
snapshot := call("GET", path(root), tokens[0], nil, 200, 0, "")
|
||||
doc := snapshot["document"].(map[string]any)
|
||||
edges := []any{}
|
||||
|
||||
Reference in New Issue
Block a user