24 lines
1.5 KiB
TypeScript
24 lines
1.5 KiB
TypeScript
// MCP calls: multi-line page text reaches the CLI whole (pitfall 100), long JSON output keeps its start.
|
|
import { describe, expect, test } from 'bun:test';
|
|
import { readFileSync } from 'node:fs';
|
|
import { clip, textToFile } from '../cli/mcp';
|
|
|
|
describe('mcp argv and output', () => {
|
|
test('a multi-line --text= becomes --from-text <file> with the whole text', () => {
|
|
const page = 'App Privacy\nData Types\nCrash Data\r\nUsed for App Functionality\nPublished a few seconds ago';
|
|
const argv = textToFile(['console', 'verify', 'apple-app-privacy', `--text=${page}`, '--json']);
|
|
expect(argv.slice(0, 4)).toEqual(['console', 'verify', 'apple-app-privacy', '--from-text']);
|
|
expect(argv.some(a => /[\r\n]/.test(a))).toBe(false);
|
|
expect(readFileSync(argv[4]!, 'utf8')).toBe(page);
|
|
expect(textToFile(['console', 'verify', 'x', '--text=one line'])).toEqual(['console', 'verify', 'x', '--text=one line']);
|
|
});
|
|
test('long JSON keeps its start, long text its end; both name the full file', () => {
|
|
const json = `{"startUrl":"https://example.com/start",${'"x":1,'.repeat(50)}"end":true}`;
|
|
const j = clip(json, true, 40);
|
|
expect(j.startsWith('{"startUrl":"https://example.com/start"')).toBe(true);
|
|
const file = /the whole output: (.+)\]$/.exec(j)![1]!;
|
|
expect(readFileSync(file, 'utf8')).toBe(json);
|
|
expect(clip('a'.repeat(100) + 'ERROR at the end', false, 20).endsWith('ERROR at the end')).toBe(true);
|
|
expect(clip('short', true, 40)).toBe('short');
|
|
});
|
|
});
|