mirror of
https://github.com/stablyai/orca.git
synced 2026-10-17 08:03:14 +00:00
fix: parse large ssh host alias lists
This commit is contained in:
@@ -172,6 +172,18 @@ Host staging stage *.example.com
|
||||
])
|
||||
})
|
||||
|
||||
it('parses generated configs with very large multi-alias Host lines', () => {
|
||||
const aliases = Array.from({ length: 125_000 }, (_, index) => `host-${index}`)
|
||||
const hosts = parseSshConfig(`
|
||||
Host ${aliases.join(' ')}
|
||||
HostName shared.example.com
|
||||
`)
|
||||
|
||||
expect(hosts).toHaveLength(aliases.length)
|
||||
expect(hosts[0]).toEqual({ host: 'host-0', hostname: 'shared.example.com' })
|
||||
expect(hosts.at(-1)).toEqual({ host: 'host-124999', hostname: 'shared.example.com' })
|
||||
})
|
||||
|
||||
it('applies identity agent settings to every concrete alias on a multi-pattern Host line', () => {
|
||||
const config = `
|
||||
Host staging stage
|
||||
|
||||
@@ -44,7 +44,7 @@ export function parseSshConfig(content: string): SshConfigHost[] {
|
||||
|
||||
if (key === 'host') {
|
||||
if (current.length > 0) {
|
||||
hosts.push(...current)
|
||||
appendSshConfigHosts(hosts, current)
|
||||
}
|
||||
|
||||
const patterns = splitHostPatterns(value)
|
||||
@@ -62,7 +62,7 @@ export function parseSshConfig(content: string): SshConfigHost[] {
|
||||
|
||||
if (key === 'match') {
|
||||
if (current.length > 0) {
|
||||
hosts.push(...current)
|
||||
appendSshConfigHosts(hosts, current)
|
||||
}
|
||||
current = []
|
||||
continue
|
||||
@@ -122,11 +122,19 @@ export function parseSshConfig(content: string): SshConfigHost[] {
|
||||
}
|
||||
|
||||
if (current.length > 0) {
|
||||
hosts.push(...current)
|
||||
appendSshConfigHosts(hosts, current)
|
||||
}
|
||||
return hosts
|
||||
}
|
||||
|
||||
function appendSshConfigHosts(target: SshConfigHost[], entries: SshConfigHost[]): void {
|
||||
// Why: generated SSH configs can contain very large Host alias lists; spreading
|
||||
// those entries into push() can exceed V8's argument limit.
|
||||
for (const entry of entries) {
|
||||
target.push(entry)
|
||||
}
|
||||
}
|
||||
|
||||
function splitHostPatterns(input: string): string[] {
|
||||
const patterns: string[] = []
|
||||
let current = ''
|
||||
|
||||
Reference in New Issue
Block a user