mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-13 22:37:29 +00:00
fix(agentstack): assignTask refuses tasks in a terminal status (#47)
This commit is contained in:
parent
a4cc229120
commit
90fffb124e
2 changed files with 332 additions and 309 deletions
|
|
@ -76,6 +76,26 @@ describe("AgentStack coordinator", () => {
|
|||
expect(() => stack.updateTaskStatus(task.id, "running")).toThrow(/cancelled/);
|
||||
});
|
||||
|
||||
it("refuses to assign a task that is already in a terminal status", () => {
|
||||
const stack = new AgentStack();
|
||||
stack.registerAgent(agent);
|
||||
const other: AgentProfile = { ...agent, did: agentDid("xyz") };
|
||||
stack.registerAgent(other);
|
||||
const task = stack.createTask({
|
||||
ownerDid: owner,
|
||||
sourceApp: "ugig.net",
|
||||
title: "Paid task",
|
||||
paymentIntentId: "pi_1",
|
||||
escrowId: "esc_1"
|
||||
});
|
||||
stack.assignTask(task.id, agent.did);
|
||||
stack.updateTaskStatus(task.id, "complete", { reputationEventId: "rep_1" });
|
||||
|
||||
expect(() => stack.assignTask(task.id, other.did)).toThrow(/already complete and cannot be assigned/);
|
||||
expect(stack.getTask(task.id)?.assigneeDid).toBe(agent.did);
|
||||
expect(stack.getTask(task.id)?.status).toBe("complete");
|
||||
});
|
||||
|
||||
it("records delegation grants and emits events", () => {
|
||||
const stack = new AgentStack();
|
||||
const listener = vi.fn();
|
||||
|
|
|
|||
|
|
@ -113,6 +113,9 @@ export class AgentStack {
|
|||
|
||||
assignTask(taskId: string, agentDidValue: string): DidTask {
|
||||
const task = this.requireTask(taskId);
|
||||
if (TERMINAL.has(task.status)) {
|
||||
throw new Error(`Task ${taskId} is already ${task.status} and cannot be assigned`);
|
||||
}
|
||||
if (!this.agents.has(agentDidValue)) {
|
||||
throw new Error(`Unknown agent: ${agentDidValue}`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue