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 @@
// 旧快照 AI 生命周期数据库回归:需隔离 PLATFORM_TEST_DATABASE_URL,生成由 Unix 假 worker 固定,不调用真实模型。
package platform
import (
@@ -23,6 +24,7 @@ import (
"gitea.entroia.com/Zayden-Jung/foundry-core/internal/codex"
)
// TestCanvasAIJobLifecycle 通过真实准入/认领/写回验证几何并发、内容冲突、取消、租约恢复、图片和传播失败分支。
func TestCanvasAIJobLifecycle(t *testing.T) {
dsn := os.Getenv("PLATFORM_TEST_DATABASE_URL")
if dsn == "" {
@@ -78,6 +80,7 @@ func TestCanvasAIJobLifecycle(t *testing.T) {
if err := png.Encode(&pngOutput, image.NewRGBA(image.Rect(0, 0, 3, 2))); err != nil {
t.Fatal(err)
}
// hooks 在 worker 已接收任务但尚未返回时注入并发变更;busyNext/failNext 分别模拟未执行忙碌和生成失败。
var imageInputs atomic.Int32
var busyNext atomic.Bool
var failNext atomic.Bool
@@ -175,6 +178,7 @@ func TestCanvasAIJobLifecycle(t *testing.T) {
t.Errorf("concurrent fixture edit: %v", err)
}
}
// 同键准入只建一个任务,生成中拖动 x 应被保留,结果只更新文本并在最新版本上加一。
first := start(1, 1)
retry := start(1, 1)
if first["run_id"] != retry["run_id"] || first["canvas_version"] != float64(2) {
@@ -193,6 +197,7 @@ func TestCanvasAIJobLifecycle(t *testing.T) {
t.Fatal("result overwrote geometry/style or failed to update text")
}
firstPath := base + "/ai/runs/" + first["run_id"].(string)
// 以小事件页回放整个运行,检查 seq 严格单调且最终 run.completed 可恢复。
after := int64(0)
completed := false
for page := 0; page < 30; page++ {
@@ -218,6 +223,7 @@ func TestCanvasAIJobLifecycle(t *testing.T) {
if !completed {
t.Fatal("terminal event not replayable")
}
// 正文并发编辑产生 conflict,输出仍可查询;旧协议显式应用失败后允许按当前版本再试。
second := start(4, 3)
hooks <- func() { mutate("{nodes,0,data,text}", `"user edit"`) }
execute(second["run_id"].(string))
@@ -244,6 +250,7 @@ func TestCanvasAIJobLifecycle(t *testing.T) {
if calls.Load() != 2 {
t.Fatal("cancelled queued run invoked worker")
}
// 人工让运行租约过期,恢复流程必须标 execution_interrupted,不能再次调用未知是否执行的模型。
fourth := start(8, 7)
run, err := s.claimCanvasRun(ctx)
if err != nil || run == nil || run.ID != fourth["run_id"] {
@@ -262,6 +269,7 @@ func TestCanvasAIJobLifecycle(t *testing.T) {
if recovered["status"] != "failed" || recovered["error"] != "execution_interrupted" || calls.Load() != 2 {
t.Fatal("uncertain execution was retried or misreported")
}
// 删除再创建同名节点不能使旧 running 步复活,迟到输出必须保持 cancelled。
fifth := start(9, 8)
removedRun, err := s.claimCanvasRun(ctx)
if err != nil || removedRun == nil || removedRun.ID != fifth["run_id"] {
@@ -299,6 +307,7 @@ func TestCanvasAIJobLifecycle(t *testing.T) {
if len(active["runs"].([]any)) != 0 {
t.Fatal("terminal jobs returned as active")
}
// 图片输入先冻结为资产再装载,结果也存托管资产;节点原显示尺寸和可授权下载的原图都需保留。
imageDoc := call("GET", base, nil, 200, 0, "")["document"].(map[string]any)
imageDoc["nodes"] = append(imageDoc["nodes"].([]any), response{"id": "image-node", "type": "plainImage", "position": response{"x": 40, "y": 50}, "width": 240, "height": 160, "data": response{"kind": "plain-image", "title": "Image", "text": "", "src": "data:image/png;base64," + base64.StdEncoding.EncodeToString(pngOutput.Bytes())}})
call("PATCH", base, response{"document": imageDoc}, 200, 12, "")
@@ -336,6 +345,7 @@ func TestCanvasAIJobLifecycle(t *testing.T) {
t.Fatal("image inputs were not frozen/hydrated through authorized assets")
}
// 首前驱成功后让下游收到 codex_busy,只回队下游;恢复不重复上游付费调用或版本推进。
chainDoc := call("GET", base, nil, 200, 0, "")["document"].(map[string]any)
chainDoc["nodes"].([]any)[1].(map[string]any)["data"].(map[string]any)["ai"] = response{"enabled": true, "modelId": "fixture-model", "prompt": "Use upstream result", "parameters": response{}}
call("PATCH", base, response{"document": chainDoc}, 200, 18, "")
@@ -366,6 +376,7 @@ func TestCanvasAIJobLifecycle(t *testing.T) {
}
// Cancellation after worker admission must reject an otherwise successful late output.
// 生成中通过真实取消接口结束 run,随后即使假 worker 返回成功也不能再写回。
cancelRunning := start(22, 13)
cancelRunningPath := base + "/ai/runs/" + cancelRunning["run_id"].(string)
hooks <- func() {
@@ -377,6 +388,7 @@ func TestCanvasAIJobLifecycle(t *testing.T) {
}
// Permission is checked again inside the final write transaction.
// 生成返回前删除成员权限,最终事务重查应拒绝输出应用;恢复权限仅为读取测试结果。
revoked := start(23, 15)
hooks <- func() {
if _, err := db.ExecContext(ctx, `DELETE FROM workspace_members WHERE project=$1 AND workspace_id=$2 AND account_id=$3`, project, workspace, account); err != nil {
@@ -393,6 +405,7 @@ func TestCanvasAIJobLifecycle(t *testing.T) {
}
// A failed branch stops its dependents while its independent sibling finishes.
// 一支失败只跳过依赖者,独立兄弟仍可成功,run 汇总为 partially_succeeded。
branchSnapshot := aiPlanFixture([][2]string{{"a", "b"}, {"a", "c"}, {"b", "d"}}, nil, "")["board"]
var branchDoc any
if err := json.Unmarshal(branchSnapshot.Document, &branchDoc); err != nil {
@@ -412,6 +425,7 @@ func TestCanvasAIJobLifecycle(t *testing.T) {
t.Fatalf("partial failure lost independent branch: %+v %v", states, branchResult["status"])
}
// 含回边的图可以存储,但执行准入必须识别环,既不调用 worker 也不推进配置版本。
cyclic := call("GET", base, nil, 200, 0, "")
cyclicVersion := int64(cyclic["version"].(float64))
cyclicDoc := cyclic["document"].(map[string]any)