docs: annotate Foundry source and deployment lifecycle in Chinese [skip ci]

This commit is contained in:
2026-11-16 17:52:11 +08:00
parent 30829eeb86
commit 1090591503
123 changed files with 1279 additions and 3 deletions
@@ -1,3 +1,4 @@
// Canonical 生命周期综合回归:使用真实 HTTP 与隔离 PostgreSQL,覆盖迁移屏障和增量写入持久化。
package platform
import (
@@ -15,6 +16,8 @@ import (
"testing"
)
// TestCanonicalModelMigrationAndIncrementalLifecycle 从旧 frame 分区迁移开始,逐步验证稳定身份、局部版本、墓碑和逻辑去重。
// 依赖 PLATFORM_TEST_DATABASE_URL;后续各段沿用前段版本,失败应在最早断言处定位。
func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
dsn := os.Getenv("PLATFORM_TEST_DATABASE_URL")
if dsn == "" {
@@ -58,6 +61,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
mux := http.NewServeMux()
Register(mux, db, map[string]string{project: "https://app.example.com/auth/callback"}, "https://api.example.com", nil)
base := "/projects/" + project + "/workspaces/" + workspace + "/materials/" + root + "/canvas"
// call 经完整认证路由发请求;read 则从模型表独立重建,避免只相信回执中的内存结果。
call := func(method, path string, input any, key string, status int) response {
t.Helper()
raw, _ := json.Marshal(input)
@@ -93,6 +97,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
}
return model
}
// GET 只返回迁移需求,不隐式分配身份;显式迁移成功后旧 HTTP/数据库快照写入都应被屏障拦住。
if call("GET", base+"/model", nil, "", 409)["error"] != "canonical_migration_required" {
t.Fatal("legacy read silently migrated")
}
@@ -136,6 +141,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
if _, err = db.ExecContext(ctx, `UPDATE materials SET canvas_document=$4,canvas_version=canvas_version+1 WHERE project=$1 AND workspace_id=$2 AND id=$3`, project, workspace, root, legacy); err == nil {
t.Fatal("database identity barrier allowed an old writer")
}
// 每个 edit 分配不同请求与逻辑操作 ID,预期版本由用例显式给出,避免辅助函数掩盖版本错误。
edit := func(n int, versions map[string]int64, changes ...modelChange) response {
t.Helper()
key := modelTestID(n)
@@ -164,6 +170,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
t.Fatal("missing receipt claimed zero writes")
}
// Move is a row owner update, retaining ElementId and incarnation.
// 元素移动只改 owner 与几何,不能删除再新建或改变 incarnation。
geometry := model.Elements[nodeID]["geometry"]
edit(1002, map[string]int64{root: 2, child: 2}, modelChange{Kind: "field", Target: modelTarget{ID: nodeID, Incarnation: 1}, Field: "ownerCanvasId", Before: modelJSON(child), After: modelJSON(root)}, modelChange{Kind: "field", Target: modelTarget{ID: nodeID, Incarnation: 1}, Field: "geometry", Before: modelJSON(geometry), After: modelJSON(map[string]any{"x": 150, "y": 260, "width": 240, "height": 72, "rotation": 0})})
model = read()
@@ -171,6 +178,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
t.Fatal("move recreated the element")
}
// Future component/envelope bytes survive editing another object and legacy projections.
// 不认识的组件/数据版本和 envelope 作为不透明 JSON 保留,不因生成兼容快照而丢失。
opaqueID := modelTestID(3000)
opaque := modelTestNode(opaqueID, root)
opaque["componentId"], opaque["dataVersion"], opaque["data"], opaque["futureEnvelope"] = "future.plugin", float64(9), map[string]any{"raw": []any{map[string]any{"keep": true}}}, map[string]any{"extension": "retained"}
@@ -184,6 +192,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
if model.Tombstones[nodeID] != 1 {
t.Fatal("delete did not persist its lifecycle tombstone")
}
// 恢复同 ID 需升级 incarnation,旧代回调得到确定拒绝且不得改动任何版本或旁观元素。
restored := modelTestNode(nodeID, root)
restored["componentId"] = "plain-text"
restored["incarnation"] = float64(2)
@@ -215,6 +224,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
t.Fatal("initial read has no explicit coverage")
}
// Negotiate the same authenticated canonical read as a streamed transfer.
// 相同授权入口协商 NDJSON,头部版本与真实模型一致,末尾必须存在 complete。
streamRequest := httptest.NewRequest("GET", base+"/model", nil)
streamRequest.Header.Set("Authorization", "Bearer "+token)
streamRequest.Header.Set("Accept", modelStreamType)
@@ -225,6 +235,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
t.Fatal("authenticated stream lost canonical snapshot coverage")
}
// An object created and removed inside one transaction still has a lifecycle fact.
// 同批创建又删除仍要留下墓碑和死记录,不能当作未发生而允许旧生命周期被再次接受。
ghostID := modelTestID(4000)
ghost := modelTestNode(ghostID, root)
edit(1008, map[string]int64{root: 6}, modelChange{Kind: "element", ID: ghostID, Before: modelJSON(nil), After: modelJSON(ghost)}, modelChange{Kind: "element", ID: ghostID, Before: modelJSON(ghost), After: modelJSON(nil)})
@@ -247,6 +258,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
t.Fatal("expected-account barrier was ignored")
}
// A new partition's entry, owning canvas and versions publish atomically.
// 新画布以期望版本零参与,入口节点和树关系同批创建;归档/恢复保留版本围栏。
newCanvas, newFrame := modelTestID(5000), modelTestID(5001)
frame := modelTestNode(newFrame, root)
frame["componentId"] = "frame"
@@ -269,6 +281,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
}
// A cross-scale entry move writes ownership, child binding and presentation units together.
// 跨缩放移动同时更改 owner、geometry、presentation 单位元数据和孩子 Parent,内部成员记录应不变。
innerCanvas, innerFrame, memberID := modelTestID(5100), modelTestID(5101), modelTestID(5102)
container := modelTestNode(innerFrame, root)
container["componentId"] = "frame"
@@ -312,6 +325,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
t.Fatal("scaled move inverse did not restore absent unit metadata and the original child binding")
}
// Several logical edits share one atomic request while retaining every deduplication identity.
// 多逻辑编辑共用一个事务和版本增量,但每个原操作 ID 都必须登记并禁止换请求键重放。
batchKey, firstLogical, secondLogical := modelTestID(1016), modelTestID(22001), modelTestID(22002)
batchVersion := model.Versions[innerCanvas]
batch := modelBatch{ProtocolVersion: 2, RequestID: batchKey, Expected: map[string]int64{innerCanvas: batchVersion}, Operations: []modelOperation{
@@ -336,6 +350,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
t.Fatal("a covered logical ID was executable under a new request key")
}
// A later failed condition cannot publish the earlier edit or consume its logical identity.
// 后一个 before 条件失败必须回滚先成功的内存前缀,也不能消费该前缀的逻辑操作 ID。
failedKey := modelTestID(1018)
batch.RequestID = failedKey
batch.Operations = []modelOperation{
@@ -355,6 +370,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
}
// A compacted wire projection retains prefix IDs with conditional no-ops, including in a child scope.
// 压缩后的 wire 批次用条件无操作保留前缀身份;只触及孩子版本且保留创建/删除生命周期事实。
projectedKey, guardLogical, effectLogical := modelTestID(1019), modelTestID(22005), modelTestID(22006)
projectedGhost := modelTestID(5200)
finalGhost := modelTestNode(projectedGhost, innerCanvas)
@@ -381,6 +397,7 @@ func TestCanonicalModelMigrationAndIncrementalLifecycle(t *testing.T) {
}
// A locally canceled incarnation was never sent; undo may first publish incarnation 2.
// 本地取消且从未发送的第一代没有服务端墓碑;首次发布第二代仍合法,旧代回调不可冒领。
locallyElidedID := modelTestID(5201)
locallyRestored := modelTestNode(locallyElidedID, innerCanvas)
locallyRestored["incarnation"] = float64(2)