Resolve canonical AI targets at their current canvas owner
This commit is contained in:
@@ -177,6 +177,12 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
|
||||
after.Versions[id] = before.Versions[id] + 1
|
||||
participants[id] = true
|
||||
}
|
||||
for id := range before.Canvases {
|
||||
if _, active := after.Canvases[id]; !active {
|
||||
after.Versions[id] = before.Versions[id] + 1
|
||||
participants[id] = true
|
||||
}
|
||||
}
|
||||
if e = validateCanvasModel(after); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
@@ -211,7 +217,14 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
|
||||
command := func(board, target, model string, incarnation int64) (response, string) {
|
||||
next += 2
|
||||
key := modelTestID(next)
|
||||
return response{"protocol_version": 2, "request_id": key, "operation_id": modelTestID(next + 1), "target_incarnation": incarnation, "expected_versions": read().Versions, "node_id": target, "model_id": model, "prompt": "Generate", "parameters": response{}, "propagate": false}, key
|
||||
return response{"protocol_version": 2, "request_id": key, "operation_id": modelTestID(next + 1), "target_incarnation": incarnation, "expected_versions": func() map[string]int64 {
|
||||
model := read()
|
||||
versions := map[string]int64{}
|
||||
for id := range model.Canvases {
|
||||
versions[id] = model.Versions[id]
|
||||
}
|
||||
return versions
|
||||
}(), "node_id": target, "model_id": model, "prompt": "Generate", "parameters": response{}, "propagate": false}, key
|
||||
}
|
||||
start := func(board, target, model string, incarnation int64) response {
|
||||
input, key := command(board, target, model, incarnation)
|
||||
@@ -377,10 +390,32 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
|
||||
model.Canvases[child] = modelCanvas{ID: child, Parent: &modelParent{CanvasID: root, EntryElementID: frame}}
|
||||
model.Elements[imageID]["ownerCanvasId"] = child
|
||||
})
|
||||
state, e = s.finishCanvasStep(ctx, *moving, moving.Plan.Steps[0], "wrong owner", "", true)
|
||||
if e != nil || state != "cancelled" {
|
||||
t.Fatalf("moved target accepted old output %s %v", state, e)
|
||||
busyInput, busyKey := command(child, imageID, "image", 1)
|
||||
busy := call("POST", base(child)+"/ai/runs", busyInput, 409, read().Versions[child], busyKey)
|
||||
if busy["error"] != "node_busy" {
|
||||
t.Fatal("owner move admitted a duplicate paid task")
|
||||
}
|
||||
beforeMovedOutput := read()
|
||||
state, e = s.finishCanvasStepOutput(ctx, *moving, moving.Plan.Steps[0], codex.CanvasOutput{Kind: "image", Image: &codex.CanvasImage{MIME: "image/png", Data: pngBytes.Bytes()}}, "", true)
|
||||
if e != nil || state != "succeeded" {
|
||||
t.Fatalf("owner-only move rejected output %s %v", state, e)
|
||||
}
|
||||
afterMovedOutput := read()
|
||||
if afterMovedOutput.Elements[imageID]["ownerCanvasId"] != child || afterMovedOutput.Versions[root] != beforeMovedOutput.Versions[root] || afterMovedOutput.Versions[child] != beforeMovedOutput.Versions[child]+1 || afterMovedOutput.Elements[imageID]["geometry"].(map[string]any)["width"] != float64(10000) {
|
||||
t.Fatal("relocated result rewrote ownership, geometry or the origin version")
|
||||
}
|
||||
movedStatus := call("GET", base(root)+"/ai/runs/"+moving.ID, nil, 200, 0, "")
|
||||
foundRelocation := false
|
||||
for _, value := range movedStatus["events"].([]any) {
|
||||
event := value.(map[string]any)
|
||||
if event["type"] == "step.applied" {
|
||||
foundRelocation = event["board_id"] == child && event["origin_board_id"] == root && event["canonical_root"] == root && event["model"].(map[string]any)["complete"] == true
|
||||
}
|
||||
}
|
||||
if !foundRelocation || movedStatus["applied_versions"].(map[string]any)[child] != float64(afterMovedOutput.Versions[child]) {
|
||||
t.Fatal("moved output lost current-owner version or canonical context")
|
||||
}
|
||||
|
||||
if e = s.completeCanvasRun(ctx, *moving, nil); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
@@ -430,4 +465,53 @@ func TestCanonicalAIAdmissionAndLifecycle(t *testing.T) {
|
||||
if read().Elements[imageID]["ownerCanvasId"] != child {
|
||||
t.Fatal("child result moved its target back")
|
||||
}
|
||||
queuedMove := start(child, imageID, "image", 1)
|
||||
mutate(func(model *canvasModel) {
|
||||
model.Elements[imageID]["ownerCanvasId"] = root
|
||||
delete(model.Canvases, child)
|
||||
})
|
||||
execute(queuedMove["run_id"].(string))
|
||||
archivedRoute := base(child) + "/ai/runs/" + queuedMove["run_id"].(string)
|
||||
archivedResult := call("GET", archivedRoute, nil, 200, 0, "")
|
||||
if archivedResult["status"] != "succeeded" || read().Elements[imageID]["ownerCanvasId"] != root {
|
||||
t.Fatal("queued move or archived admission route stopped the run")
|
||||
}
|
||||
lateArchiveKey := modelTestID(6500)
|
||||
if result := call("POST", archivedRoute+"/cancel", response{"protocol_version": 2, "request_id": lateArchiveKey, "operation_id": modelTestID(6501)}, 200, 0, lateArchiveKey); result["run_status"] != "succeeded" {
|
||||
t.Fatal("archived route lost cancellation identity")
|
||||
}
|
||||
// Content changes still conflict after a move; explicit application targets the current owner.
|
||||
movedConflict := start(root, node, "text", 2)
|
||||
hooks <- func() {
|
||||
mutate(func(model *canvasModel) {
|
||||
model.Canvases[child] = modelCanvas{ID: child, Parent: &modelParent{CanvasID: root, EntryElementID: frame}}
|
||||
model.Elements[node]["ownerCanvasId"] = child
|
||||
model.Elements[node]["data"].(map[string]any)["text"] = "keep moved edit"
|
||||
})
|
||||
}
|
||||
execute(movedConflict["run_id"].(string))
|
||||
movedConflictPath := base(root) + "/ai/runs/" + movedConflict["run_id"].(string)
|
||||
conflictMovedResult := call("GET", movedConflictPath, nil, 200, 0, "")
|
||||
if conflictMovedResult["status"] != "conflict" || read().Elements[node]["data"].(map[string]any)["text"] != "keep moved edit" {
|
||||
t.Fatal("move allowed a content conflict overwrite")
|
||||
}
|
||||
movedOutput := conflictMovedResult["outputs"].([]any)[0].(map[string]any)["output"].(map[string]any)["output_id"].(string)
|
||||
movedApplyKey := modelTestID(6502)
|
||||
movedApplied := call("POST", movedConflictPath+"/apply", response{"protocol_version": 2, "request_id": movedApplyKey, "operation_id": modelTestID(6503), "node_id": node, "output_id": movedOutput, "target_incarnation": 2, "target_canvas_id": child}, 200, read().Versions[child], movedApplyKey)
|
||||
if movedApplied["board_id"] != child || movedApplied["origin_board_id"] != root || read().Elements[node]["ownerCanvasId"] != child {
|
||||
t.Fatal("explicit application wrote to the frozen owner")
|
||||
}
|
||||
doomed := start(child, node, "text", 2)
|
||||
mutate(func(model *canvasModel) {
|
||||
record := model.Elements[node]
|
||||
model.DeadRecords[node] = record
|
||||
model.Tombstones[node] = 2
|
||||
model.TombstoneOwners[node] = child
|
||||
delete(model.Elements, node)
|
||||
})
|
||||
execute(doomed["run_id"].(string))
|
||||
if result := call("GET", base(child)+"/ai/runs/"+doomed["run_id"].(string), nil, 200, 0, ""); result["status"] != "cancelled" {
|
||||
t.Fatal("deleting a moved target failed to revoke its old job")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user