Fix paste ownership, input bounds, and IPC validation
Supersedes #5745, #5746, and #5747.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
buildPullRequestFieldsPrompt,
|
||||
parseGeneratedPullRequestFields,
|
||||
@@ -17,6 +17,10 @@ const context: PullRequestDraftContext = {
|
||||
patch: 'diff --git a/src/file.ts b/src/file.ts\n+export const value = true'
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
describe('buildPullRequestFieldsPrompt', () => {
|
||||
it('asks for compact JSON and includes PR context', () => {
|
||||
const prompt = buildPullRequestFieldsPrompt(context, 'Use conventional PR titles.')
|
||||
@@ -57,6 +61,28 @@ describe('parseGeneratedPullRequestFields', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('parses CRLF fenced JSON output without full-string fence matching', () => {
|
||||
const matchSpy = vi.spyOn(String.prototype, 'match')
|
||||
const replaceSpy = vi.spyOn(String.prototype, 'replace')
|
||||
const fields = parseGeneratedPullRequestFields(
|
||||
'```JSON\r\n{"base":"main","title":"fix: add details.","body":"Summary","draft":true}\r\n```',
|
||||
context
|
||||
)
|
||||
|
||||
expect(fields.title).toBe('fix: add details')
|
||||
const usedFenceMatch = matchSpy.mock.calls.some(
|
||||
([pattern]) =>
|
||||
pattern instanceof RegExp &&
|
||||
pattern.source.startsWith('^```') &&
|
||||
pattern.source.includes('[\\s\\S]')
|
||||
)
|
||||
const usedCrlfReplace = replaceSpy.mock.calls.some(
|
||||
([pattern]) => pattern instanceof RegExp && pattern.source === '\\r\\n' && pattern.global
|
||||
)
|
||||
expect(usedFenceMatch).toBe(false)
|
||||
expect(usedCrlfReplace).toBe(false)
|
||||
})
|
||||
|
||||
it('falls back for missing optional values', () => {
|
||||
const fields = parseGeneratedPullRequestFields('{"title":""}', context)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user