Enforce AgentStack status jumps (#81)

This commit is contained in:
phucnguyen1707 2026-06-16 17:18:54 +07:00 • committed by GitHub
parent 82e1389b8d
commit e38688f16e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 5 deletions

View file

@ -76,6 +76,25 @@ describe("AgentStack coordinator", () => {
expect(() => stack.updateTaskStatus(task.id, "running")).toThrow(/cancelled/);
});
it("rejects status jumps outside the AgentStack lifecycle", () => {
const stack = new AgentStack();
stack.registerAgent(agent);
const pending = stack.createTask({ ownerDid: owner, sourceApp: "ugig.net", title: "Pending task" });
expect(() => stack.updateTaskStatus(pending.id, "running")).toThrow(/pending -> running/);
const queued = stack.createTask({
ownerDid: owner,
sourceApp: "ugig.net",
title: "Queued task",
assigneeDid: agent.did
});
expect(() => stack.updateTaskStatus(queued.id, "complete")).toThrow(/queued -> complete/);
const blocked = stack.updateTaskStatus(queued.id, "running");
expect(stack.updateTaskStatus(blocked.id, "blocked").status).toBe("blocked");
});
it("refuses to assign a task that is already in a terminal status", () => {
const stack = new AgentStack();
stack.registerAgent(agent);
@ -89,6 +108,7 @@ describe("AgentStack coordinator", () => {
escrowId: "esc_1"
});
stack.assignTask(task.id, agent.did);
stack.updateTaskStatus(task.id, "running");
stack.updateTaskStatus(task.id, "complete", { reputationEventId: "rep_1" });
expect(() => stack.assignTask(task.id, other.did)).toThrow(/already complete and cannot be assigned/);