mirror of
https://github.com/thedotmack/claude-mem.git
synced 2026-09-20 04:23:02 +08:00
14447b9ee9
Night-ship rebase of #3717 by @rodboev onto latest main. Treats the stdin reader's malformed-EOF and incomplete-timeout diagnostics as non-blocking so UserPromptSubmit fails open. Supersedes #3717. Refs #3699 / #3605.
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
|
|
import { describe, it, expect, afterEach } from 'bun:test';
|
|
|
|
import { readJsonFromStdin } from '../../src/cli/stdin-reader.js';
|
|
import { installFakeStdin, restoreStdin } from '../fake-stdin.js';
|
|
|
|
afterEach(() => {
|
|
restoreStdin();
|
|
});
|
|
|
|
describe('readJsonFromStdin — onEnd contract (#2089)', () => {
|
|
it('resolves with parsed JSON when stdin yields a complete object', async () => {
|
|
installFakeStdin('{"hello":"world"}');
|
|
const result = await readJsonFromStdin();
|
|
expect(result).toEqual({ hello: 'world' });
|
|
});
|
|
|
|
it('resolves with undefined when stdin closes empty', async () => {
|
|
installFakeStdin('');
|
|
const result = await readJsonFromStdin();
|
|
expect(result).toBeUndefined();
|
|
});
|
|
|
|
it('rejects when stdin closes with non-empty but unparseable bytes', async () => {
|
|
installFakeStdin('{"truncated":');
|
|
await expect(readJsonFromStdin()).rejects.toThrow(/Malformed JSON at stdin EOF/);
|
|
});
|
|
|
|
it('rejects when stdin closes with junk that is clearly not JSON', async () => {
|
|
installFakeStdin('not json at all');
|
|
await expect(readJsonFromStdin()).rejects.toThrow(/Malformed JSON at stdin EOF/);
|
|
});
|
|
});
|