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 AI 数据库集成回归:Unix 假 worker 只固定生成传输,权威模型、生命周期与回执均走真实事务。
package platform
import (
@@ -24,6 +25,7 @@ import (
"gitea.entroia.com/Zayden-Jung/foundry-core/internal/codex"
)
// TestCanonicalAIAdmissionAndLifecycle 需隔离 PLATFORM_TEST_DATABASE_URL,覆盖 owner 迁移、代数失效及 v2 确定拒绝恢复。
func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
dsn := os.Getenv("PLATFORM_TEST_DATABASE_URL")
if dsn == "" {
@@ -75,6 +77,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
if err = png.Encode(&pngBytes, image.NewRGBA(image.Rect(0, 0, 3, 2))); err != nil {
t.Fatal(err)
}
// worker 入口执行一次 hook,可精确在模型返回前注入内容、身份或所有权变化。
hooks := make(chan func(), 1)
var executions atomic.Int32
worker := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -156,6 +159,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
}
return model
}
// mutate 在持锁事务中改权威模型并同步投影,用于模拟其他客户端编辑,不绕过模型完整性校验。
mutate := func(edit func(*canvasModel)) {
t.Helper()
tx, e := db.BeginTx(ctx, nil)
@@ -214,6 +218,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
model.Elements["future"]["dataVersion"] = float64(12)
})
next := 6100
// 每次创建不同 request/operation ID,Expected 取全部活跃画布版本,排除已归档 scope。
command := func(board, target, model string, incarnation int64) (response, string) {
next += 2
key := modelTestID(next)
@@ -227,6 +232,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
}(), "node_id": target, "model_id": model, "prompt": "Generate", "parameters": response{}, "propagate": false}, key
}
start := func(board, target, model string, incarnation int64) response {
// 准入原响应可按相同键重放和查询;改 If-Match 或换键复用已准入逻辑操作必须拒绝。
input, key := command(board, target, model, incarnation)
return call("POST", base(board)+"/ai/runs", input, 202, read().Versions[board], key)
}
@@ -272,6 +278,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
t.Fatal("AI lost canonical fields, geometry or future records")
}
// A content conflict retains its output; explicit application is still a narrow canonical write.
// 内容冲突保留输出,显式应用仍是窄字段写;同键重放保留原模型/版本且可查询回执。
conflictRun := start(root, node, "text", 1)
hooks <- func() {
mutate(func(model *canvasModel) { model.Elements[node]["data"].(map[string]any)["text"] = "user edit" })
@@ -297,6 +304,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
}
call("POST", conflictPath+"/apply", applyInput, 409, expected+1, applyKey)
// Keep one unapplied old output, then replace the target incarnation atomically.
// 保存旧输出并让另一运行开始后升级 incarnation,旧完成回调与旧输出显式应用都不能冒领新一代。
stale := start(root, node, "text", 1)
hooks <- func() {
mutate(func(model *canvasModel) { model.Elements[node]["data"].(map[string]any)["text"] = "keep this" })
@@ -352,6 +360,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
t.Fatal("duplicate/cancelled/old execution called the model")
}
// Image output resolves a managed resource while retaining the element envelope.
// canonical 大几何与未知字段不受 legacy 限制回滚,图片输出成为可按权限下载的托管资产。
imageID := modelTestID(6300)
mutate(func(model *canvasModel) {
record := modelTestNode(imageID, root)
@@ -382,6 +391,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
if ok, e := s.startCanvasStep(ctx, *moving, moving.Plan.Steps[0]); e != nil || !ok {
t.Fatalf("start move %v", e)
}
// 运行中把目标换 owner,新 owner 准入仍应识别 node_busy;原任务成功只推进当前位置版本。
child, frame := modelTestID(6301), modelTestID(6302)
mutate(func(model *canvasModel) {
entry := modelTestNode(frame, root)
@@ -419,6 +429,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
if e = s.completeCanvasRun(ctx, *moving, nil); e != nil {
t.Fatal(e)
}
// 即使目标版本当前,祖先 read-set 陈旧也必须零效果拒绝;环境变化后原拒绝键不能重算。
staleInput, staleKey := command(child, imageID, "image", 1)
staleVersions := staleInput["expected_versions"].(map[string]int64)
staleVersions[root]-- // The target version is current; its ancestor context is not.
@@ -447,6 +458,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
delete(missingInput, "expected_versions")
call("POST", base(child)+"/ai/runs", missingInput, 400, read().Versions[child], missingKey)
// An explicit replan can reuse a logical operation after its known zero-effect rejection.
// 已知零效果允许显式新键重计划并复用逻辑操作;完成后再取消不得假装撤销成功结果。
replanned := response{}
for key, value := range staleInput {
replanned[key] = value
@@ -465,6 +477,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
if read().Elements[imageID]["ownerCanvasId"] != child {
t.Fatal("child result moved its target back")
}
// 排队期间换 owner 并归档原分区,run 的原 URL 仍可读取/取消,执行写入当前根 owner。
queuedMove := start(child, imageID, "image", 1)
mutate(func(model *canvasModel) {
model.Elements[imageID]["ownerCanvasId"] = root
@@ -481,6 +494,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
t.Fatal("archived route lost cancellation identity")
}
// Content changes still conflict after a move; explicit application targets the current owner.
// 换 owner 同时改正文仍产生冲突;用户显式应用须确认当前 owner,不能写回冻结来源画布。
movedConflict := start(root, node, "text", 2)
hooks <- func() {
mutate(func(model *canvasModel) {
@@ -501,6 +515,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
if movedApplied["board_id"] != child || movedApplied["origin_board_id"] != root || read().Elements[node]["ownerCanvasId"] != child {
t.Fatal("explicit application wrote to the frozen owner")
}
// 删除已移动目标并记录墓碑,应使原任务在调用 worker 之前取消。
doomed := start(child, node, "text", 2)
mutate(func(model *canvasModel) {
record := model.Elements[node]
@@ -522,6 +537,7 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
t.Fatal("deleting a moved target failed to revoke its old job")
}
// 换 owner 后把账户降为 viewer,执行前必须重新检查编辑资格且不增加模型调用次数。
revoked := start(root, imageID, "image", 1)
mutate(func(model *canvasModel) { model.Elements[imageID]["ownerCanvasId"] = child })
beforeRevoked := executions.Load()