|
| 1 | +// apps/pythinker-web/test/continue-turn.test.ts |
| 2 | +// |
| 3 | +// Failed-turn recovery parity with the reference client: the banner's |
| 4 | +// "Continue" button must submit a FIXED "Continue" prompt (i18n key |
| 5 | +// conversation.turnFailedResumeText) with no attachments — never a re-send of |
| 6 | +// the user's own last message, which would repeat its instructions and side |
| 7 | +// effects. |
| 8 | +import { mount } from '@vue/test-utils'; |
| 9 | +import { createI18n, type I18n } from 'vue-i18n'; |
| 10 | +import { defineComponent } from 'vue'; |
| 11 | +import { describe, expect, it, vi } from 'vitest'; |
| 12 | +import ChatPane from '../src/components/chat/ChatPane.vue'; |
| 13 | +import type { ChatTurn } from '../src/types'; |
| 14 | + |
| 15 | +vi.mock('markstream-vue', () => { |
| 16 | + const noop = (): void => undefined; |
| 17 | + return { |
| 18 | + MarkdownRender: defineComponent({ |
| 19 | + name: 'MarkdownRenderStub', |
| 20 | + props: ['content'], |
| 21 | + setup(props) { |
| 22 | + return () => String(props.content ?? ''); |
| 23 | + }, |
| 24 | + }), |
| 25 | + enableKatex: noop, |
| 26 | + enableMermaid: noop, |
| 27 | + setKaTeXWorker: noop, |
| 28 | + clearKaTeXWorker: noop, |
| 29 | + setMermaidWorker: noop, |
| 30 | + clearMermaidWorker: noop, |
| 31 | + }; |
| 32 | +}); |
| 33 | +vi.mock('markstream-vue/workers/katexRenderer.worker?worker&type=module', () => ({ |
| 34 | + default: class { |
| 35 | + terminate(): void {} |
| 36 | + }, |
| 37 | +})); |
| 38 | +vi.mock('markstream-vue/workers/mermaidParser.worker?worker&type=module', () => ({ |
| 39 | + default: class { |
| 40 | + terminate(): void {} |
| 41 | + }, |
| 42 | +})); |
| 43 | + |
| 44 | +const i18n = createI18n({ |
| 45 | + legacy: false, |
| 46 | + locale: 'en', |
| 47 | + messages: { |
| 48 | + en: { |
| 49 | + conversation: { |
| 50 | + turnFailed: 'Model request failed — this turn was interrupted', |
| 51 | + turnFailedMaxSteps: 'Step limit reached — this turn was interrupted', |
| 52 | + turnFailedResume: 'Continue', |
| 53 | + turnFailedResumeText: 'Continue', |
| 54 | + }, |
| 55 | + }, |
| 56 | + }, |
| 57 | +}); |
| 58 | + |
| 59 | +const turns: ChatTurn[] = [ |
| 60 | + { id: 'u1', role: 'user', no: 1, text: 'delete everything in /tmp' }, |
| 61 | + { |
| 62 | + id: 'a1', |
| 63 | + role: 'assistant', |
| 64 | + no: 2, |
| 65 | + text: '', |
| 66 | + tools: [{ id: 'tool_1', name: 'Bash', arg: '{}', status: 'error', output: ['boom'] }], |
| 67 | + }, |
| 68 | +]; |
| 69 | + |
| 70 | +function mountPane() { |
| 71 | + return mount(ChatPane, { |
| 72 | + props: { |
| 73 | + turns, |
| 74 | + turnActive: false, |
| 75 | + working: false, |
| 76 | + lastTurnReason: 'failed', |
| 77 | + turnErrorKind: 'error', |
| 78 | + }, |
| 79 | + global: { plugins: [i18n as I18n] }, |
| 80 | + }); |
| 81 | +} |
| 82 | + |
| 83 | +describe('failed-turn recovery (ChatPane)', () => { |
| 84 | + it('submits the fixed Continue prompt, not the last user message', async () => { |
| 85 | + const wrapper = mountPane(); |
| 86 | + vi.stubGlobal( |
| 87 | + 'ResizeObserver', |
| 88 | + class { |
| 89 | + observe(): void {} |
| 90 | + unobserve(): void {} |
| 91 | + disconnect(): void {} |
| 92 | + }, |
| 93 | + ); |
| 94 | + await wrapper.find('.turn-failed button').trigger('click'); |
| 95 | + const emitted = wrapper.emitted('continueTurn'); |
| 96 | + expect(emitted).toEqual([['Continue']]); |
| 97 | + // Guard against regression to the old resubmission behavior: the emitted |
| 98 | + // text must not be the user's prior prompt. |
| 99 | + expect(emitted![0]![0]).not.toBe('delete everything in /tmp'); |
| 100 | + vi.unstubAllGlobals(); |
| 101 | + }); |
| 102 | + |
| 103 | + it('renders the max-steps banner variant and still submits the fixed prompt', async () => { |
| 104 | + const wrapper = mount(ChatPane, { |
| 105 | + props: { |
| 106 | + turns, |
| 107 | + turnActive: false, |
| 108 | + working: false, |
| 109 | + lastTurnReason: 'failed', |
| 110 | + turnErrorKind: 'max_steps', |
| 111 | + }, |
| 112 | + global: { plugins: [i18n as I18n] }, |
| 113 | + }); |
| 114 | + vi.stubGlobal( |
| 115 | + 'ResizeObserver', |
| 116 | + class { |
| 117 | + observe(): void {} |
| 118 | + unobserve(): void {} |
| 119 | + disconnect(): void {} |
| 120 | + }, |
| 121 | + ); |
| 122 | + expect(wrapper.find('.tf-title').text()).toContain('Step limit reached'); |
| 123 | + await wrapper.find('.turn-failed button').trigger('click'); |
| 124 | + expect(wrapper.emitted('continueTurn')).toEqual([['Continue']]); |
| 125 | + vi.unstubAllGlobals(); |
| 126 | + }); |
| 127 | +}); |
0 commit comments