mirror of
https://github.com/stablyai/orca.git
synced 2026-10-01 08:01:56 +00:00
fix: handle large comment markdown references (#3699)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import CommentMarkdown from './CommentMarkdown'
|
||||
import CommentMarkdown, { remarkGitHubReferences } from './CommentMarkdown'
|
||||
|
||||
describe('CommentMarkdown', () => {
|
||||
it('autolinks same-repo GitHub issue references when repo context is provided', () => {
|
||||
@@ -42,6 +42,33 @@ describe('CommentMarkdown', () => {
|
||||
expect(markup).not.toContain('href="https://github.com/stablyai/orca/issues/2317"')
|
||||
})
|
||||
|
||||
it('autolinks very large generated GitHub reference comments', () => {
|
||||
const referenceCount = 130_000
|
||||
const tree = {
|
||||
type: 'root',
|
||||
children: [
|
||||
{
|
||||
type: 'paragraph',
|
||||
children: [
|
||||
{
|
||||
type: 'text',
|
||||
value: Array.from({ length: referenceCount }, (_, index) => `#${index + 1}`).join(' ')
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const transform = remarkGitHubReferences({ owner: 'stablyai', repo: 'orca' })()
|
||||
|
||||
expect(() => transform(tree)).not.toThrow()
|
||||
expect(tree.children[0]?.children).toHaveLength(referenceCount * 2 - 1)
|
||||
expect(tree.children[0]?.children[0]).toMatchObject({
|
||||
type: 'link',
|
||||
url: 'https://github.com/stablyai/orca/issues/1'
|
||||
})
|
||||
})
|
||||
|
||||
it('contains long PR body markdown inside its available width', () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<CommentMarkdown
|
||||
|
||||
@@ -265,7 +265,11 @@ function transformGitHubReferenceChildren(
|
||||
const nextChildren: MarkdownNode[] = []
|
||||
for (const child of node.children) {
|
||||
if (child.type === 'text' && child.value !== undefined) {
|
||||
nextChildren.push(...splitGitHubReferenceText(child.value, defaultRepo))
|
||||
// Why: generated agent comments can contain thousands of issue refs;
|
||||
// appending iteratively avoids V8's argument-list limit.
|
||||
for (const part of splitGitHubReferenceText(child.value, defaultRepo)) {
|
||||
nextChildren.push(part)
|
||||
}
|
||||
} else {
|
||||
transformGitHubReferenceChildren(child, defaultRepo)
|
||||
nextChildren.push(child)
|
||||
|
||||
Reference in New Issue
Block a user