Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
96 changes: 96 additions & 0 deletions packages/core/src/tools/task-list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,102 @@ describe('TaskListTool', () => {
expect(String(result.llmContent)).toContain('owner must include');
});

// #9281: blank optional filters must behave like absent filters,
// matching how the tool's description/schema present them.
describe('blank filters are treated as absent (#9281)', () => {
it('treats an empty owner filter as no filter', async () => {
await createTask(TEAM, {
subject: 'Owned',
description: 'desc',
owner: 'alice',
});
await createTask(TEAM, {
subject: 'Unowned',
description: 'desc',
});

const invocation = tool.build({ owner: '' });
const result = await invocation.execute(new AbortController().signal);
expect(result.error).toBeUndefined();
expect(result.llmContent).toContain('Owned');
expect(result.llmContent).toContain('Unowned');
});

it('treats a whitespace-only owner filter as no filter', async () => {
await createTask(TEAM, {
subject: 'Owned',
description: 'desc',
owner: 'alice',
});

const invocation = tool.build({ owner: ' ' });
const result = await invocation.execute(new AbortController().signal);
expect(result.error).toBeUndefined();
expect(result.llmContent).toContain('Owned');
expect(invocation.getDescription()).toBe('List all tasks');
});

it('treats an empty blockedBy filter as no filter', async () => {
await createTask(TEAM, {
subject: 'Task A',
description: 'desc',
});

const invocation = tool.build({ blockedBy: '' });
const result = await invocation.execute(new AbortController().signal);
expect(result.error).toBeUndefined();
expect(result.llmContent).toContain('Task A');
});

it('treats a whitespace-only blockedBy filter as no filter', async () => {
await createTask(TEAM, {
subject: 'Task A',
description: 'desc',
});

const invocation = tool.build({ blockedBy: ' ' });
const result = await invocation.execute(new AbortController().signal);
expect(result.error).toBeUndefined();
expect(result.llmContent).toContain('Task A');
expect(invocation.getDescription()).toBe('List all tasks');
});

it('still filters precisely by a non-empty blockedBy', async () => {
const blocker = await createTask(TEAM, {
subject: 'Blocker',
description: 'desc',
});
const blocked = await createTask(TEAM, {
subject: 'Blocked',
description: 'desc',
});
await createTask(TEAM, {
subject: 'Free',
description: 'desc',
});
await updateTask(TEAM, blocked.id, { addBlockedBy: [blocker.id] });

const invocation = tool.build({ blockedBy: blocker.id });
const result = await invocation.execute(new AbortController().signal);
expect(result.error).toBeUndefined();
expect(result.llmContent).toContain('Blocked');
expect(result.llmContent).not.toContain('Blocker');
expect(result.llmContent).not.toContain('Free');

const formatted = tool.build({ blockedBy: ` #${blocker.id} ` });
const formattedResult = await formatted.execute(
new AbortController().signal,
);
expect(formattedResult.error).toBeUndefined();
expect(formattedResult.llmContent).toContain('Blocked');

const invalid = await tool
.build({ blockedBy: 'task-1' })
.execute(new AbortController().signal);
expect(invalid.error).toBeDefined();
});
});

it('returns TaskListResultDisplay', async () => {
await createTask(TEAM, {
subject: 'Task X',
Expand Down
28 changes: 23 additions & 5 deletions packages/core/src/tools/task-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ToolNames, ToolDisplayNames } from './tool-names.js';
import type { Config } from '../config/config.js';
import { getTeamName, resolveActiveTeamName } from '../agents/team/identity.js';
import { sanitizeName } from '../agents/team/teamHelpers.js';
import { listTasks } from '../agents/team/tasks.js';
import { assertValidTaskId, listTasks } from '../agents/team/tasks.js';

export interface TaskListParams {
status?: 'pending' | 'in_progress' | 'completed';
Expand All @@ -42,10 +42,10 @@ class TaskListInvocation extends BaseToolInvocation<
if (this.params.status) {
filters.push(`status=${this.params.status}`);
}
if (this.params.owner) {
if (this.params.owner?.trim()) {
filters.push(`owner=${this.params.owner}`);
}
if (this.params.blockedBy) {
if (this.params.blockedBy?.trim()) {
filters.push(`blockedBy=${this.params.blockedBy}`);
}
return filters.length > 0
Expand All @@ -66,8 +66,12 @@ class TaskListInvocation extends BaseToolInvocation<
};
}

// Blank (empty/whitespace-only) optional filters behave as absent:
// the schema marks them optional and `getDescription()` only shows
// truthy filter values, so a blank value must not activate a
// filter (#9281).
let ownerFilter: string | undefined;
if (this.params.owner !== undefined) {
if (this.params.owner !== undefined && this.params.owner.trim() !== '') {
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
ownerFilter = sanitizeName(this.params.owner);
if (!ownerFilter) {
const msg =
Expand All @@ -81,10 +85,24 @@ class TaskListInvocation extends BaseToolInvocation<
}
}

const blockedByFilter = this.params.blockedBy?.trim().replace(/^#/, '');
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
if (blockedByFilter) {
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
try {
assertValidTaskId(blockedByFilter);
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
return {
llmContent: msg,
returnDisplay: msg,
error: { message: msg },
};
}
}

const tasks = await listTasks(teamName, {
status: this.params.status,
owner: ownerFilter,
blockedBy: this.params.blockedBy,
blockedBy: blockedByFilter,
});

if (tasks.length === 0) {
Expand Down
Loading