Skip to content
Merged
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
52 changes: 52 additions & 0 deletions src/__tests__/tasks.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,58 @@ describe('tasks command integration', () => {
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('"status": "completed"'));
});

it('creates multiple tasks and waits for all concurrently', async () => {
const dir = mkdtempSync(join(tmpdir(), 'linkup-tasks-integration-'));
const taskFile = join(dir, 'tasks.json');
const firstInput = { outputType: 'sourcedAnswer', query: 'first' } as const;
const secondInput = { outputType: 'sourcedAnswer', query: 'second' } as const;
writeFileSync(
taskFile,
JSON.stringify([
{ input: firstInput, type: 'search' },
{ input: secondInput, type: 'search' },
]),
);

const fakeClient = createFakeClient();
fakeClient.createTasks.mockResolvedValue([
makeTask({ id: 'task-a', input: firstInput }),
makeTask({ id: 'task-b', input: secondInput }),
]);

const calledIds: string[] = [];
let releaseAll!: () => void;
const bothCalled = new Promise<void>(resolve => {
releaseAll = resolve;
});
fakeClient.getTask.mockImplementation((id: string) => {
calledIds.push(id);
if (calledIds.length === 2) {
releaseAll();
}
return bothCalled.then(() =>
makeTask({
id,
output: { answer: id, sources: [] },
status: 'completed',
updatedAt: '2026-01-01T00:00:01.000Z',
}),
);
});

mockGlobals(fakeClient);
const { logSpy } = captureConsole();
await run(['node', 'linkup', '--json', 'tasks', 'create', '--file', taskFile, '--wait']);

expect(fakeClient.getTask).toHaveBeenCalledTimes(2);
expect(fakeClient.getTask).toHaveBeenCalledWith('task-a');
expect(fakeClient.getTask).toHaveBeenCalledWith('task-b');

const [output] = logSpy.mock.calls[0];
const tasks = JSON.parse(output);
expect(tasks.map((task: { id: string }) => task.id)).toEqual(['task-a', 'task-b']);
});

it('maps list filters and sorting to sdk params', async () => {
const fakeClient = createFakeClient();
fakeClient.listTasks.mockResolvedValue({
Expand Down
20 changes: 17 additions & 3 deletions src/commands/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
import { resolveGlobals } from '../client';
import { exitWithError, printLines } from '../output/errors';
import { formatJson } from '../output/json';
import { startSpinner } from '../output/spinner';
import { formatTaskErrorLine } from '../output/task-errors';
import {
formatTask,
Expand All @@ -24,6 +25,7 @@ import {
createPollIntervalOption,
createTimeoutOption,
type PollTaskResult,
pollTask,
printTimeoutHint,
waitForTask,
} from './async-task';
Expand Down Expand Up @@ -183,9 +185,21 @@ async function runTasksCreate(options: TaskCreateCommandOptions, command: Comman
const tasks = await client.createTasks(requests);

if (options.wait) {
const results = [];
for (const task of tasks) {
results.push(await waitForGenericTask(task.id, options, id => client.getTask(id), json));
const stopSpinner = json ? () => {} : startSpinner(`Waiting for ${tasks.length} task(s)...`);
let results: PollTaskResult<Task>[];
try {
results = await Promise.all(
tasks.map(task =>
pollTask({
getTask: id => client.getTask(id),
id: task.id,
intervalMs: options.pollInterval * 1000,
timeoutMs: options.timeout * 1000,
}),
),
);
} finally {
stopSpinner();
}

if (json) {
Expand Down