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
1 change: 0 additions & 1 deletion src/commands/thread/ask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const threadAskCommand: Command = {
...(name ? { name } : {}),
...(context.length > 0 ? { context } : {}),
});
await api.messagesPost({ workspaceId, threadId: thread.id, prompt });
const url = await threadConsoleUrl(config, api, thread);

if (noWait) {
Expand Down
53 changes: 53 additions & 0 deletions test/thread-ask.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { after, before, beforeEach, describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { threadAskCommand } from '../src/commands/thread/ask';
import { mockConfig } from './helpers/config';

type Sent = { method: string; url: string; body: unknown };

const thread = {
id: 'thrd_1',
workspaceId: 'ws_1',
name: '',
_html_url: 'https://console.example.test/acme/threads/thrd_1',
};

describe('thread ask', () => {
const originalFetch = globalThis.fetch;
const originalWrite = process.stdout.write;
let sent: Sent[] = [];

before(() => {
process.stdout.write = ((): boolean => true) as typeof process.stdout.write;
});

beforeEach(() => {
delete process.env.POLYLANE_API_KEY;
sent = [];
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
const url = String(input);
sent.push({ method: String(init?.method ?? 'GET'), url, body: init?.body ? JSON.parse(String(init.body)) : undefined });
if (url.endsWith('/v1/threads')) {
return Response.json({ success: true, error: null, result: thread }, { status: 201 });
}
return Response.json({ success: true, error: null, result: {} }, { status: 202 });
}) as typeof fetch;
});

after(() => {
globalThis.fetch = originalFetch;
process.stdout.write = originalWrite;
});

it('sends the prompt once, inside the thread create call', async () => {
const config = mockConfig({ apiKey: 'test-key', apiKeySource: 'flag', workspaceId: 'ws_1' });
await threadAskCommand.execute(config, {}, { _: ['hello', 'there'], noWait: true });
assert.deepEqual(sent, [
{
method: 'POST',
url: 'https://api.example.test/v1/threads',
body: { workspaceId: 'ws_1', prompt: 'hello there', visibility: 'workspace' },
},
]);
});
});
Loading