Fix paste ownership, input bounds, and IPC validation
Supersedes #5745, #5746, and #5747.
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
formatSubmodulePushFailureDetail,
|
||||
isNoUpstreamError,
|
||||
normalizeGitErrorMessage
|
||||
} from './git-remote-error'
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
describe('normalizeGitErrorMessage', () => {
|
||||
it('keeps the submodule name when a recursive push is rejected', () => {
|
||||
const error = new Error(
|
||||
@@ -33,6 +37,22 @@ describe('normalizeGitErrorMessage', () => {
|
||||
'git config pull.rebase true (rebase), or git config pull.ff only (fast-forward only).'
|
||||
)
|
||||
})
|
||||
|
||||
it('uses the tail diagnostic from newline-heavy failures without line-array splitting', () => {
|
||||
const splitSpy = vi.spyOn(String.prototype, 'split')
|
||||
const error = new Error(
|
||||
`Command failed: git fetch\r\n${'remote: progress update\r\n'.repeat(10_000)}remote side closed connection\r\n`
|
||||
)
|
||||
|
||||
expect(normalizeGitErrorMessage(error, 'fetch')).toBe('remote side closed connection')
|
||||
|
||||
const usedLineSplit = splitSpy.mock.calls.some(
|
||||
([separator]) =>
|
||||
(typeof separator === 'string' && separator === '\n') ||
|
||||
(separator instanceof RegExp && separator.source === '\\r?\\n')
|
||||
)
|
||||
expect(usedLineSplit).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatSubmodulePushFailureDetail', () => {
|
||||
@@ -55,6 +75,20 @@ describe('formatSubmodulePushFailureDetail', () => {
|
||||
"Submodule 'vendor/tools' could not be pushed. Resolve the submodule push error, then try again."
|
||||
)
|
||||
})
|
||||
|
||||
it('checks newline-heavy output without full CRLF normalization', () => {
|
||||
const replaceSpy = vi.spyOn(String.prototype, 'replace')
|
||||
const message = `${'remote: progress\r\n'.repeat(10_000)}Unable to push submodule 'vendor/tools'\r\nfatal: failed to push all needed submodules\r\n`
|
||||
|
||||
expect(formatSubmodulePushFailureDetail(message)).toBe(
|
||||
"Submodule 'vendor/tools' could not be pushed. Resolve the submodule push error, then try again."
|
||||
)
|
||||
|
||||
const usedCrlfReplace = replaceSpy.mock.calls.some(
|
||||
([pattern]) => pattern instanceof RegExp && pattern.source === '\\r\\n'
|
||||
)
|
||||
expect(usedCrlfReplace).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isNoUpstreamError', () => {
|
||||
|
||||
Reference in New Issue
Block a user