Reject unknown task assignees

This commit is contained in:
phucnguyen1707 2026-06-16 11:31:31 +07:00
parent 82e1389b8d
commit 662b805ffb
2 changed files with 33 additions and 17 deletions

View file

@ -116,6 +116,19 @@ describe("AgentStack coordinator", () => {
expect(() => stack.assignTask(task.id, agentDid("ghost"))).toThrow(/Unknown agent/);
});
it("rejects tasks preassigned to unknown agents", () => {
const stack = new AgentStack();
expect(() =>
stack.createTask({
ownerDid: owner,
sourceApp: "ugig.net",
title: "Ghost assignment",
assigneeDid: agentDid("ghost")
})
).toThrow(/Unknown agent/);
expect(stack.listTasks({ assigneeDid: agentDid("ghost") })).toHaveLength(0);
});
it("filters tasks in snapshots", () => {
const stack = new AgentStack();
stack.createTask({ ownerDid: owner, sourceApp: "x", title: "a" });

View file

@ -87,6 +87,9 @@ export class AgentStack {
if (!parseDid(input.ownerDid)) {
throw new Error(`Invalid owner DID: ${input.ownerDid}`);
}
if (input.assigneeDid && !this.agents.has(input.assigneeDid)) {
throw new Error(`Unknown agent: ${input.assigneeDid}`);
}
const ts = this.now();
const task: DidTask = {
id: this.nextId("task"),