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
+22 -1
View File
@@ -1,3 +1,4 @@
// 模型/协议纯回归:用内存对象与 recorder 验证身份、原子变更或流传输契约,不访问真实数据库。
package platform
import (
@@ -17,15 +18,24 @@ const modelLegacyFrame = `{"id":"f","type":"frame","position":{"x":100,"y":200},
//go:embed testdata/foundry-model-operation-v2.json
var canonicalFrontendFixture []byte
// modelJSON 将测试值统一编码为 before/after 原始 JSON。
func modelJSON(value any) json.RawMessage { raw, _ := json.Marshal(value); return raw }
func modelTestID(n int) string { return fmt.Sprintf("90000000-0000-4000-8000-%012d", n) }
// modelTestID 生成确定 UUID,便于跨回归复用可预期的请求/操作/资源身份。
func modelTestID(n int) string { return fmt.Sprintf("90000000-0000-4000-8000-%012d", n) }
// modelTestAllocator 返回有独立计数器的分配器,让迁移身份分配可重复断言。
func modelTestAllocator() func() string {
next := 0
return func() string { next++; return modelTestID(next) }
}
// modelTestNode 构造最小有效 v1 text 节点,其嵌套 data/geometry 每次独立创建。
func modelTestNode(id, owner string) map[string]any {
return map[string]any{"id": id, "incarnation": float64(1), "ownerCanvasId": owner, "componentId": "text", "dataVersion": float64(1), "structure": "node", "data": map[string]any{"title": id, "text": "preserved"}, "geometry": map[string]any{"x": float64(0), "y": float64(0), "width": float64(260), "height": float64(200), "rotation": float64(0)}}
}
// modelTestDocument 提供版本一根画布和一个 a 节点的最小完整模型。
func modelTestDocument() canvasModel {
model := emptyModel(modelRootID)
model.Canvases[modelRootID] = modelCanvas{ID: modelRootID}
@@ -34,6 +44,7 @@ func modelTestDocument() canvasModel {
return model
}
// TestCanonicalFramesRetainRotationAcrossOwnerChanges 检查 canonical frame 跨 owner 后保留旋转、兼容投影和无关 AI patch 不抹角度,同时旧快照写契约仍拒绝旋转 frame。
func TestCanonicalFramesRetainRotationAcrossOwnerChanges(t *testing.T) {
model := modelTestDocument()
frame := modelTestNode("f", modelRootID)
@@ -97,6 +108,7 @@ func TestCanonicalFramesRetainRotationAcrossOwnerChanges(t *testing.T) {
}
}
// TestCanonicalMigrationResolvesCanvasLocalIdentitiesAndPorts 用父子同名节点证明迁移分配不同全局身份,并将端口边解析为真实子节点、推进版本屏障且保留输入快照。
func TestCanonicalMigrationResolvesCanvasLocalIdentitiesAndPorts(t *testing.T) {
root := `{"schema_version":2,"nodes":[{"id":"a","type":"plainText","position":{"x":0,"y":0},"width":240,"height":72,"data":{"kind":"plain-text","title":"parent","text":""}},{"id":"f","type":"frame","position":{"x":100,"y":200},"width":640,"height":400,"data":{"kind":"frame","title":"F","text":"","subgraph":{"boardId":"` + modelChildID + `"},"ports":[{"id":"p","nodeId":"a","handle":"right","direction":"output"}]}}],"edges":[{"id":"e","source":"f","sourceHandle":"port:p","target":"a","targetHandle":"left"}],"viewport":{"x":0,"y":0,"zoom":1}}`
child := `{"schema_version":2,"nodes":[{"id":"a","type":"plainText","position":{"x":10,"y":20},"width":240,"height":72,"data":{"kind":"plain-text","title":"child","text":""}}],"edges":[],"viewport":{"x":0,"y":0,"zoom":1}}`
@@ -133,6 +145,8 @@ func TestCanonicalMigrationResolvesCanvasLocalIdentitiesAndPorts(t *testing.T) {
}
}
}
// TestCanonicalMigrationTurnsImplicitFramesIntoOwningCanvases 验证旧 frameId 分区成为新画布,成员几何改为 owner 局部坐标且 data 中不再存第二份 frameId 所有权。
func TestCanonicalMigrationTurnsImplicitFramesIntoOwningCanvases(t *testing.T) {
root := `{"schema_version":1,"nodes":[` + modelLegacyFrame + `,{"id":"a","type":"plainText","position":{"x":150,"y":260},"width":240,"height":72,"data":{"kind":"plain-text","title":"a","text":"","frameId":"f"}}],"edges":[],"viewport":{"x":0,"y":0,"zoom":1}}`
result, err := migrateCanvasModel(modelRootID, map[string]canvasSnapshot{modelRootID: {BoardID: modelRootID, Version: 1, Document: json.RawMessage(root)}}, nil, modelTestAllocator())
@@ -156,6 +170,8 @@ func TestCanonicalMigrationTurnsImplicitFramesIntoOwningCanvases(t *testing.T) {
t.Fatal("second ownership fact leaked into canonical data")
}
}
// TestCanonicalOperationsPreserveOpaquePayloadAndStableMoveIdentity 移动已知元素 owner 时保留 ID,触及新旧画布,并原样保留未知组件数据及 envelope,输入模型不被修改。
func TestCanonicalOperationsPreserveOpaquePayloadAndStableMoveIdentity(t *testing.T) {
model := modelTestDocument()
frame := modelTestNode("f", modelRootID)
@@ -180,6 +196,8 @@ func TestCanonicalOperationsPreserveOpaquePayloadAndStableMoveIdentity(t *testin
t.Fatal("opaque payload or old snapshot was mutated")
}
}
// TestCanonicalDeleteRestoreRejectsOldIncarnation 删除产生墓碑,恢复升级 incarnation;旧代异步字段编辑不能命中新一代同 ID 元素。
func TestCanonicalDeleteRestoreRejectsOldIncarnation(t *testing.T) {
model := modelTestDocument()
deleted, _, err := applyModelOperations(model, []modelOperation{{ID: modelTestID(1), Changes: []modelChange{{Kind: "element", ID: "a", Before: modelJSON(model.Elements["a"]), After: modelJSON(nil)}}}})
@@ -200,6 +218,8 @@ func TestCanonicalDeleteRestoreRejectsOldIncarnation(t *testing.T) {
t.Fatal("old callback claimed the restored incarnation")
}
}
// TestCanonicalValidationRejectsPartialChangesAndWrongEdgeOwner 第二个变更失败时输入不变;另构造跨父子的连接却归孩子所有,要求最终模型校验拒绝。
func TestCanonicalValidationRejectsPartialChangesAndWrongEdgeOwner(t *testing.T) {
model := modelTestDocument()
before := modelJSON(model)
@@ -222,6 +242,7 @@ func TestCanonicalValidationRejectsPartialChangesAndWrongEdgeOwner(t *testing.T)
}
}
// TestCanonicalFrontendProtocolFixture 读取嵌入的前端协议样本,验证请求 envelope 与 reducer 兼容,且仅改变预期标题和一次版本。
func TestCanonicalFrontendProtocolFixture(t *testing.T) {
var input modelBatch
decoder := json.NewDecoder(bytes.NewReader(canonicalFrontendFixture))