Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions packages/agentstack/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,29 @@ describe("AgentStack coordinator", () => {
expect(listener).toHaveBeenCalledWith(expect.objectContaining({ type: "delegation.granted" }));
});

it("rejects unknown agents and invalid DIDs", () => {
const stack = new AgentStack();
expect(() => stack.createTask({ ownerDid: "nope", sourceApp: "x", title: "t" })).toThrow();
const task = stack.createTask({ ownerDid: owner, sourceApp: "x", title: "t" });
expect(() => stack.assignTask(task.id, agentDid("ghost"))).toThrow(/Unknown agent/);
});

it("filters tasks in snapshots", () => {
const stack = new AgentStack();
stack.createTask({ ownerDid: owner, sourceApp: "x", title: "a" });
it("rejects unknown agents and invalid DIDs", () => {
const stack = new AgentStack();
expect(() => stack.createTask({ ownerDid: "nope", sourceApp: "x", title: "t" })).toThrow();
const task = stack.createTask({ ownerDid: owner, sourceApp: "x", title: "t" });
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" });
stack.createTask({ ownerDid: userDid("999"), sourceApp: "x", title: "b" });
expect(stack.listTasks({ ownerDid: owner })).toHaveLength(1);
expect(stack.snapshot().tasks).toHaveLength(2);
Expand Down
17 changes: 10 additions & 7 deletions packages/agentstack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,16 @@ export class AgentStack {
return this.agents.get(did);
}

createTask(input: CreateTaskInput): DidTask {
if (!parseDid(input.ownerDid)) {
throw new Error(`Invalid owner DID: ${input.ownerDid}`);
}
const ts = this.now();
const task: DidTask = {
id: this.nextId("task"),
createTask(input: CreateTaskInput): DidTask {
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"),
ownerDid: input.ownerDid,
assigneeDid: input.assigneeDid,
sourceApp: input.sourceApp,
Expand Down
Loading