fix: append ssh include lines without spread

This commit is contained in:
Neil
2026-05-30 05:08:59 -07:00
parent 6b051e8aab
commit a23ba4f14e
2 changed files with 22 additions and 1 deletions
+9 -1
View File
@@ -64,7 +64,7 @@ function expandSshConfigFile(
for (const includeArg of includeArgs) {
for (const matchedPath of resolveIncludePaths(includeArg, context)) {
expandedLines.push(...expandSshConfigFile(matchedPath, context, nextStack))
appendExpandedLines(expandedLines, expandSshConfigFile(matchedPath, context, nextStack))
}
}
}
@@ -72,6 +72,14 @@ function expandSshConfigFile(
return expandedLines
}
function appendExpandedLines(target: string[], source: string[]): void {
// Why: valid include files can stay under the byte cap while still exceeding
// V8's argument limit if appended with `push(...source)`.
for (const line of source) {
target.push(line)
}
}
function readCachedFile(filePath: string, context: IncludeExpansionContext): string | null {
const cached = context.cache.get(filePath)
if (cached !== undefined) {
+13
View File
@@ -100,6 +100,19 @@ describe('loadUserSshConfig', () => {
expect(loadUserSshConfig().map((host) => host.host)).toEqual(['first', 'second'])
})
it('loads an include file with more lines than the JavaScript argument limit', () => {
const home = makeHome()
const manyCommentLines = Array.from({ length: 130_000 }, () => '#').join('\n')
writeFile(
home,
'.ssh/config',
'Include many-comments.conf\nHost after\n HostName after.example.com\n'
)
writeFile(home, '.ssh/many-comments.conf', manyCommentLines)
expect(loadUserSshConfig().map((host) => host.host)).toEqual(['after'])
})
it('supports relative includes, ${VAR}, and local % tokens', () => {
const home = makeHome()
process.env.ORCA_SSH_INCLUDE = 'from-env.conf'