mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
314bc6f231
1. Remove root-level shim files (errors.ts, logger.ts, registry.ts, types.ts, utils.ts, launcher.ts) — update all ~840 adapter imports to reference src/ directly 2. Consolidate interceptor: reuse shared DISGUISE_FN in tap interceptor instead of reimplementing 3. Unify error classification: single ClassifiedError type with icon/exitCode/hint lookup table, eliminating duplicated pattern matching between resolveExitCode and renderError 4. Simplify cascade probe: replace repetitive switch cases with PROBE_OPTIONS lookup map 12. Clean up synthesize.ts: remove deprecated snake_case field aliases (recommended_args, recommended_columns, recommendedColumnsLegacy) and unnecessary constant aliases Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { getRegistry } from '../../src/registry.js';
|
|
import './read.js';
|
|
|
|
describe('reddit read adapter', () => {
|
|
const command = getRegistry().get('reddit/read');
|
|
|
|
it('returns threaded rows from the browser-evaluated payload', async () => {
|
|
const page = {
|
|
goto: vi.fn().mockResolvedValue(undefined),
|
|
evaluate: vi.fn().mockResolvedValue([
|
|
{ type: 'POST', author: 'alice', score: 10, text: 'Title' },
|
|
{ type: 'L0', author: 'bob', score: 5, text: 'Comment' },
|
|
]),
|
|
} as any;
|
|
|
|
const result = await command!.func!(page, { 'post-id': 'abc123', limit: 5 });
|
|
|
|
expect(page.goto).toHaveBeenCalledWith('https://www.reddit.com');
|
|
expect(result).toEqual([
|
|
{ type: 'POST', author: 'alice', score: 10, text: 'Title' },
|
|
{ type: 'L0', author: 'bob', score: 5, text: 'Comment' },
|
|
]);
|
|
});
|
|
|
|
it('surfaces adapter-level API errors clearly', async () => {
|
|
const page = {
|
|
goto: vi.fn().mockResolvedValue(undefined),
|
|
evaluate: vi.fn().mockResolvedValue({ error: 'Reddit API returned HTTP 403' }),
|
|
} as any;
|
|
|
|
await expect(command!.func!(page, { 'post-id': 'abc123' })).rejects.toThrow('Reddit API returned HTTP 403');
|
|
});
|
|
});
|