+38
-77
@@ -7,8 +7,7 @@ type RunResult = { exitCode: number; stdout: string; stderr: string; signal: Nod
|
||||
|
||||
const LIVE = process.env.BIRD_LIVE === '1';
|
||||
|
||||
const authToken = (process.env.AUTH_TOKEN ?? process.env.TWITTER_AUTH_TOKEN ?? '').trim();
|
||||
const ct0 = (process.env.CT0 ?? process.env.TWITTER_CT0 ?? '').trim();
|
||||
const relayBaseUrl = (process.env.TWITTER_RELAY_BASE_URL ?? '').trim();
|
||||
|
||||
const CLI_PATH = path.resolve(process.cwd(), 'dist', 'cli.js');
|
||||
|
||||
@@ -27,8 +26,6 @@ function runBird(args: string[], options: { timeoutMs?: number } = {}): Promise<
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
env: {
|
||||
...process.env,
|
||||
AUTH_TOKEN: authToken,
|
||||
CT0: ct0,
|
||||
NODE_ENV: LIVE_NODE_ENV,
|
||||
},
|
||||
});
|
||||
@@ -72,7 +69,6 @@ const d = LIVE ? describe : describe.skip;
|
||||
|
||||
d('live CLI (Twitter/X)', () => {
|
||||
const timeoutArg = (process.env.BIRD_LIVE_TIMEOUT_MS ?? '20000').trim();
|
||||
const cookieTimeoutArg = (process.env.BIRD_LIVE_COOKIE_TIMEOUT_MS ?? '30000').trim();
|
||||
const baseArgs = ['--plain', '--timeout', timeoutArg, '--quote-depth', '0'];
|
||||
|
||||
let whoamiStdout = '';
|
||||
@@ -85,19 +81,16 @@ d('live CLI (Twitter/X)', () => {
|
||||
throw new Error(`Missing ${CLI_PATH}. Run: pnpm run build:dist`);
|
||||
}
|
||||
|
||||
if (!authToken || !ct0) {
|
||||
const check = await runBird([...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'check'], { timeoutMs: 45_000 });
|
||||
if (check.exitCode !== 0) {
|
||||
throw new Error(
|
||||
'Missing live credentials.\n' +
|
||||
'- Option A: set AUTH_TOKEN + CT0 (or TWITTER_AUTH_TOKEN/TWITTER_CT0)\n' +
|
||||
'- Option B: login to x.com in Safari/Chrome/Firefox for cookie extraction\n\n' +
|
||||
`bird check output:\n${check.stdout}\n${check.stderr}`,
|
||||
);
|
||||
}
|
||||
if (!relayBaseUrl) {
|
||||
throw new Error('Missing TWITTER_RELAY_BASE_URL for live tests.');
|
||||
}
|
||||
|
||||
const who = await runBird([...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'whoami'], { timeoutMs: 45_000 });
|
||||
const check = await runBird([...baseArgs, 'check'], { timeoutMs: 45_000 });
|
||||
if (check.exitCode !== 0) {
|
||||
throw new Error(`bird check failed:\n${check.stdout}\n${check.stderr}`);
|
||||
}
|
||||
|
||||
const who = await runBird([...baseArgs, 'whoami'], { timeoutMs: 45_000 });
|
||||
if (who.exitCode !== 0) {
|
||||
throw new Error(`whoami failed (exit ${who.exitCode}, signal ${who.signal ?? 'none'}):\n${who.stderr}`);
|
||||
}
|
||||
@@ -127,12 +120,9 @@ d('live CLI (Twitter/X)', () => {
|
||||
const searchQuery = (
|
||||
process.env.BIRD_LIVE_SEARCH_QUERY ?? `from:${handle} -filter:replies -filter:retweets`
|
||||
).trim();
|
||||
const search = await runBird(
|
||||
[...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'search', searchQuery, '-n', '25', '--json'],
|
||||
{
|
||||
timeoutMs: 45_000,
|
||||
},
|
||||
);
|
||||
const search = await runBird([...baseArgs, 'search', searchQuery, '-n', '25', '--json'], {
|
||||
timeoutMs: 45_000,
|
||||
});
|
||||
if (search.exitCode !== 0) {
|
||||
throw new Error(`search failed (exit ${search.exitCode}, signal ${search.signal ?? 'none'}):\n${search.stderr}`);
|
||||
}
|
||||
@@ -160,7 +150,7 @@ d('live CLI (Twitter/X)', () => {
|
||||
});
|
||||
|
||||
it('read returns tweet JSON', async () => {
|
||||
const read = await runBird([...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'read', tweetId, '--json'], {
|
||||
const read = await runBird([...baseArgs, 'read', tweetId, '--json'], {
|
||||
timeoutMs: 45_000,
|
||||
});
|
||||
expect(read.exitCode).toBe(0);
|
||||
@@ -170,7 +160,7 @@ d('live CLI (Twitter/X)', () => {
|
||||
});
|
||||
|
||||
it('tweet-id shorthand returns tweet JSON', async () => {
|
||||
const shorthand = await runBird([...baseArgs, '--cookie-timeout', cookieTimeoutArg, tweetId, '--json'], {
|
||||
const shorthand = await runBird([...baseArgs, tweetId, '--json'], {
|
||||
timeoutMs: 45_000,
|
||||
});
|
||||
expect(shorthand.exitCode).toBe(0);
|
||||
@@ -179,7 +169,7 @@ d('live CLI (Twitter/X)', () => {
|
||||
});
|
||||
|
||||
it('replies returns JSON array', async () => {
|
||||
const replies = await runBird([...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'replies', tweetId, '--json'], {
|
||||
const replies = await runBird([...baseArgs, 'replies', tweetId, '--json'], {
|
||||
timeoutMs: 45_000,
|
||||
});
|
||||
expect(replies.exitCode).toBe(0);
|
||||
@@ -188,7 +178,7 @@ d('live CLI (Twitter/X)', () => {
|
||||
});
|
||||
|
||||
it('thread returns JSON array', async () => {
|
||||
const thread = await runBird([...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'thread', tweetId, '--json'], {
|
||||
const thread = await runBird([...baseArgs, 'thread', tweetId, '--json'], {
|
||||
timeoutMs: 45_000,
|
||||
});
|
||||
expect(thread.exitCode).toBe(0);
|
||||
@@ -198,24 +188,18 @@ d('live CLI (Twitter/X)', () => {
|
||||
});
|
||||
|
||||
it('mentions returns JSON array', async () => {
|
||||
const mentions = await runBird(
|
||||
[...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'mentions', '-n', '10', '--json'],
|
||||
{
|
||||
timeoutMs: 45_000,
|
||||
},
|
||||
);
|
||||
const mentions = await runBird([...baseArgs, 'mentions', '-n', '10', '--json'], {
|
||||
timeoutMs: 45_000,
|
||||
});
|
||||
expect(mentions.exitCode).toBe(0);
|
||||
const mentionTweets = parseJson<Array<{ id?: string }>>(mentions.stdout);
|
||||
expect(Array.isArray(mentionTweets)).toBe(true);
|
||||
});
|
||||
|
||||
it('bookmarks returns JSON array', async () => {
|
||||
const bookmarks = await runBird(
|
||||
[...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'bookmarks', '-n', '10', '--json'],
|
||||
{
|
||||
timeoutMs: 45_000,
|
||||
},
|
||||
);
|
||||
const bookmarks = await runBird([...baseArgs, 'bookmarks', '-n', '10', '--json'], {
|
||||
timeoutMs: 45_000,
|
||||
});
|
||||
expect(bookmarks.exitCode).toBe(0);
|
||||
const bookmarkTweets = parseJson<Array<{ id?: string }>>(bookmarks.stdout);
|
||||
expect(Array.isArray(bookmarkTweets)).toBe(true);
|
||||
@@ -226,17 +210,16 @@ d('live CLI (Twitter/X)', () => {
|
||||
if (!folderId) {
|
||||
return;
|
||||
}
|
||||
const bookmarks = await runBird(
|
||||
[...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'bookmarks', '--folder-id', folderId, '-n', '10', '--json'],
|
||||
{ timeoutMs: 45_000 },
|
||||
);
|
||||
const bookmarks = await runBird([...baseArgs, 'bookmarks', '--folder-id', folderId, '-n', '10', '--json'], {
|
||||
timeoutMs: 45_000,
|
||||
});
|
||||
expect(bookmarks.exitCode).toBe(0);
|
||||
const bookmarkTweets = parseJson<Array<{ id?: string }>>(bookmarks.stdout);
|
||||
expect(Array.isArray(bookmarkTweets)).toBe(true);
|
||||
});
|
||||
|
||||
it('likes returns JSON array', async () => {
|
||||
const likes = await runBird([...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'likes', '-n', '10', '--json'], {
|
||||
const likes = await runBird([...baseArgs, 'likes', '-n', '10', '--json'], {
|
||||
timeoutMs: 45_000,
|
||||
});
|
||||
expect(likes.exitCode).toBe(0);
|
||||
@@ -245,24 +228,18 @@ d('live CLI (Twitter/X)', () => {
|
||||
});
|
||||
|
||||
it('following returns JSON array', async () => {
|
||||
const following = await runBird(
|
||||
[...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'following', '--user', userId, '-n', '10', '--json'],
|
||||
{
|
||||
timeoutMs: 45_000,
|
||||
},
|
||||
);
|
||||
const following = await runBird([...baseArgs, 'following', '--user', userId, '-n', '10', '--json'], {
|
||||
timeoutMs: 45_000,
|
||||
});
|
||||
expect(following.exitCode).toBe(0);
|
||||
const followingUsers = parseJson<Array<{ id?: string; username?: string }>>(following.stdout);
|
||||
expect(Array.isArray(followingUsers)).toBe(true);
|
||||
});
|
||||
|
||||
it('followers returns JSON array', async () => {
|
||||
const followers = await runBird(
|
||||
[...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'followers', '--user', userId, '-n', '10', '--json'],
|
||||
{
|
||||
timeoutMs: 45_000,
|
||||
},
|
||||
);
|
||||
const followers = await runBird([...baseArgs, 'followers', '--user', userId, '-n', '10', '--json'], {
|
||||
timeoutMs: 45_000,
|
||||
});
|
||||
expect(followers.exitCode).toBe(0);
|
||||
const followerUsers = parseJson<Array<{ id?: string; username?: string }>>(followers.stdout);
|
||||
expect(Array.isArray(followerUsers)).toBe(true);
|
||||
@@ -271,12 +248,9 @@ d('live CLI (Twitter/X)', () => {
|
||||
it('user-tweets returns JSON array', async () => {
|
||||
// Use a known active account for reliable testing (authenticated user may have no tweets)
|
||||
const testHandle = process.env.BIRD_LIVE_USER_TWEETS_HANDLE || 'X';
|
||||
const userTweets = await runBird(
|
||||
[...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'user-tweets', testHandle, '-n', '5', '--json'],
|
||||
{
|
||||
timeoutMs: 45_000,
|
||||
},
|
||||
);
|
||||
const userTweets = await runBird([...baseArgs, 'user-tweets', testHandle, '-n', '5', '--json'], {
|
||||
timeoutMs: 45_000,
|
||||
});
|
||||
expect(userTweets.exitCode).toBe(0);
|
||||
const tweets = parseJson<Array<{ id?: string; author?: { username?: string } }>>(userTweets.stdout);
|
||||
expect(Array.isArray(tweets)).toBe(true);
|
||||
@@ -289,20 +263,7 @@ d('live CLI (Twitter/X)', () => {
|
||||
const testHandle =
|
||||
process.env.BIRD_LIVE_USER_TWEETS_PAGED_HANDLE ?? process.env.BIRD_LIVE_USER_TWEETS_HANDLE ?? 'X';
|
||||
const userTweets = await runBird(
|
||||
[
|
||||
...baseArgs,
|
||||
'--cookie-timeout',
|
||||
cookieTimeoutArg,
|
||||
'user-tweets',
|
||||
testHandle,
|
||||
'-n',
|
||||
'50',
|
||||
'--max-pages',
|
||||
'3',
|
||||
'--delay',
|
||||
'0',
|
||||
'--json',
|
||||
],
|
||||
[...baseArgs, 'user-tweets', testHandle, '-n', '50', '--max-pages', '3', '--delay', '0', '--json'],
|
||||
{
|
||||
timeoutMs: 45_000,
|
||||
},
|
||||
@@ -315,7 +276,7 @@ d('live CLI (Twitter/X)', () => {
|
||||
});
|
||||
|
||||
it('query-ids returns JSON', async () => {
|
||||
const queryIds = await runBird([...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'query-ids', '--json'], {
|
||||
const queryIds = await runBird([...baseArgs, 'query-ids', '--json'], {
|
||||
timeoutMs: 60_000,
|
||||
});
|
||||
expect(queryIds.exitCode).toBe(0);
|
||||
@@ -340,7 +301,7 @@ d('live CLI (Twitter/X)', () => {
|
||||
// Skip unless explicitly provided - long-form tweets may be deleted/unavailable
|
||||
return;
|
||||
}
|
||||
const read = await runBird([...baseArgs, '--cookie-timeout', cookieTimeoutArg, 'read', longformTweetId, '--json'], {
|
||||
const read = await runBird([...baseArgs, 'read', longformTweetId, '--json'], {
|
||||
timeoutMs: 45_000,
|
||||
});
|
||||
expect(read.exitCode).toBe(0);
|
||||
|
||||
Reference in New Issue
Block a user