fix(client): 插入事件未被宿主采纳时留下 warn(不再静默无操作)
宿主换掉/改名 `slash/input-insert-*` 或 CAS 拒绝这次插入时,两条路径原先只是静默返回 false (点击"什么都不发生")。现在补一条 `console.warn`,让这种上游变化在用户报障前就能从控制台认出来; 顺带给 `insertFileReference` 的"没人处理事件"补上单测(appendToDraft 那条同时改为断言 warn)。
This commit is contained in:
1 parent
8c3e00ec54
commit
315ad5d5ff
2 files changed
+28
-3
No files matched your search
@@ -227,7 +227,11 @@ export function appendToDraft(ctx: Context, sessionId: string, text: string): bo
|
||||
end: clipboardToDetect(before.occurrences, plan.end),
|
||||
},
|
||||
})
|
||||
return input.state.getSnapshot().draftRev !== before.draftRev
|
||||
if (input.state.getSnapshot().draftRev === before.draftRev) {
|
||||
console.warn('[dsh-better-sidebar] draft insert skipped: the composer did not apply the insert event')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
} catch (error) {
|
||||
console.warn('[dsh-better-sidebar] draft insert failed:', error)
|
||||
return false
|
||||
@@ -352,7 +356,11 @@ export function insertFileReference(ctx: Context, sessionId: string, relativePat
|
||||
end: at,
|
||||
},
|
||||
})
|
||||
return input.state.getSnapshot().draftRev !== before.draftRev
|
||||
if (input.state.getSnapshot().draftRev === before.draftRev) {
|
||||
console.warn('[dsh-better-sidebar] file-reference insert skipped: the composer did not apply the insert event')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
} catch (error) {
|
||||
console.warn('[dsh-better-sidebar] file-reference insert failed:', error)
|
||||
return false
|
||||
|
||||
@@ -328,7 +328,8 @@ describe('appendToDraft', () => {
|
||||
expect(composer.setDrafts).toEqual([])
|
||||
})
|
||||
|
||||
it('reports false — and leaves the draft alone — when no listener handled the event', () => {
|
||||
it('reports false — logs, and leaves the draft alone — when no listener handled the event', () => {
|
||||
const consoleWarn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
|
||||
const composer = fakeComposer({ draft: 'hi', draftRev: 2 })
|
||||
const ctx = {
|
||||
sessions: { scope: (): unknown => ({ emit: (): void => undefined }) },
|
||||
@@ -337,6 +338,8 @@ describe('appendToDraft', () => {
|
||||
expect(appendToDraft(ctx, 's1', 'X')).toBe(false)
|
||||
expect(composer.read().draft).toBe('hi')
|
||||
expect(composer.setDrafts).toEqual([])
|
||||
expect(consoleWarn).toHaveBeenCalledTimes(1)
|
||||
consoleWarn.mockRestore()
|
||||
})
|
||||
|
||||
it('returns false and logs when the draft carries no revision to address', () => {
|
||||
@@ -394,6 +397,20 @@ describe('insertFileReference', () => {
|
||||
expect(composer.setDrafts).toEqual([])
|
||||
})
|
||||
|
||||
it('reports false — logs, and leaves the draft alone — when no listener handled the event', () => {
|
||||
const consoleWarn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
|
||||
const composer = fakeComposer({ draft: 'hi', draftRev: 2 })
|
||||
const ctx = {
|
||||
sessions: { scope: (): unknown => ({ emit: (): void => undefined }) },
|
||||
get: (name: string): unknown => composer.ctx.get(name),
|
||||
} as unknown as Context
|
||||
expect(insertFileReference(ctx, 's1', 'notes/ENV.md')).toBe(false)
|
||||
expect(composer.read().draft).toBe('hi')
|
||||
expect(composer.setDrafts).toEqual([])
|
||||
expect(consoleWarn).toHaveBeenCalledTimes(1)
|
||||
consoleWarn.mockRestore()
|
||||
})
|
||||
|
||||
it('returns false without a revision to address', () => {
|
||||
const composer = fakeComposer({ draft: 'hi' })
|
||||
const ctx = {
|
||||
|
||||
Reference in new issue
Block a user