moving
Some checks failed
Installer Smoke / installer-smoke (push) Has been cancelled

This commit is contained in:
Oleg Maslov
2026-09-02 10:10:29 +02:00
commit 0c3e2ead3b
3841 changed files with 970576 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
import { describe, expect, it } from 'vitest';
import { runUserPromptSubmit, userPromptSubmitHandler } from '../../src/hooks/user-prompt-submit.js';
import { makeHookCaptures, makeMockBridge } from './_test-helpers.js';
describe('user-prompt-submit handler', () => {
it('extracts prompt from payload.prompt or payload.user_message', () => {
expect(userPromptSubmitHandler.parse({ prompt: 'hi' }).prompt).toBe('hi');
expect(userPromptSubmitHandler.parse({ user_message: 'hello' }).prompt).toBe('hello');
expect(userPromptSubmitHandler.parse({}).prompt).toBe('');
});
it('saves a temporary frame containing the prompt', async () => {
const bridge = makeMockBridge();
const cap = makeHookCaptures();
await runUserPromptSubmit({
readStdin: async () => JSON.stringify({
prompt: 'How do I X?',
cwd: '/proj/foo',
session_id: 'sess-7',
}),
writeStdout: cap.writeStdout,
exit: cap.exit,
bridge,
});
expect(bridge.saveMemory).toHaveBeenCalledTimes(1);
const arg = bridge.saveMemory.mock.calls[0][0];
expect(arg).toMatchObject({
content: 'How do I X?',
importance: 'temporary',
scope: 'sess-7',
source: 'claude-code',
});
expect(cap.exits).toEqual([0]);
});
it('skips save when no prompt is present', async () => {
const bridge = makeMockBridge();
const cap = makeHookCaptures();
await runUserPromptSubmit({
readStdin: async () => '{}',
writeStdout: cap.writeStdout,
exit: cap.exit,
bridge,
});
expect(bridge.saveMemory).not.toHaveBeenCalled();
expect(cap.exits).toEqual([0]);
});
it('exits 0 even if saveMemory rejects', async () => {
const bridge = makeMockBridge({ saveMemoryThrows: new Error('cli down') });
const cap = makeHookCaptures();
await runUserPromptSubmit({
readStdin: async () => JSON.stringify({ prompt: 'x' }),
writeStdout: cap.writeStdout,
exit: cap.exit,
bridge,
});
expect(cap.exits).toEqual([0]);
});
});