🧵 fix: Preserve Fenced Markdown Artifacts (#14121)
Some checks failed
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Has been cancelled
GitNexus Index / index (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Sync Helm Chart Tags / Ignore non-main push (push) Has been cancelled
Sync Helm Chart Tags / Sync chart tags (push) Has been cancelled
GitNexus Index / post-index (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled

* fix: Preserve fenced markdown artifacts

* fix: Satisfy artifact CI checks

* fix: Handle longer artifact fences in updates
This commit is contained in:
Danny Avila 2026-07-05 12:04:59 -04:00 committed by GitHub
parent a03c574bef
commit 8fcb77fe6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 350 additions and 60 deletions

View file

@ -136,6 +136,30 @@ ${ARTIFACT_END}`;
expect(result[0].end).toBe(artifactText.length);
});
test('should preserve markdown artifacts wrapped in longer fences with internal code blocks', () => {
const content = `# Title
\`\`\`bash
echo one
\`\`\`
Text between sections.
## Section B
\`\`\`bash
echo two
\`\`\``;
const artifactText = `${ARTIFACT_START}{identifier="git-cheatsheet" type="text/markdown" title="Git Cheatsheet"}
\`\`\`\`markdown
${content}
\`\`\`\`
${ARTIFACT_END}`;
const message = { text: `${artifactText}\ntrailer` };
const result = findAllArtifacts(message);
expect(result).toHaveLength(1);
expect(result[0].end).toBe(artifactText.length);
});
test('should preserve the first fallback close in an unclosed fence', () => {
const firstArtifact = `${ARTIFACT_START}{identifier="first" type="text/html" title="First"}
\`\`\`html
@ -245,6 +269,49 @@ ${ARTIFACT_END}`;
expect(result).toContain("console.log('inside');");
});
test('should replace markdown artifacts wrapped in longer fences with internal code blocks', () => {
const original = `# Notes
\`\`\`bash
echo one
\`\`\`
## More
\`\`\`bash
echo two
\`\`\``;
const updated = original.replace('## More', '## Updated');
const artifactText = `${ARTIFACT_START}{identifier="notes" type="text/markdown" title="Notes"}
\`\`\`\`markdown
${original}
\`\`\`\`
${ARTIFACT_END}`;
const message = { text: artifactText };
const artifacts = findAllArtifacts(message);
const result = replaceArtifactContent(artifactText, artifacts[0], original, updated);
expect(result).not.toBeNull();
expect(result).toContain('## Updated');
expect(result).toContain('```bash');
expect(result).toContain('````markdown');
});
test('should normalize editor trailing newlines before longer closing fences', () => {
const original = '# Notes';
const artifactText = `${ARTIFACT_START}{identifier="notes" type="text/markdown" title="Notes"}
\`\`\`\`markdown
${original}
\`\`\`\`
${ARTIFACT_END}`;
const message = { text: artifactText };
const artifacts = findAllArtifacts(message);
const result = replaceArtifactContent(artifactText, artifacts[0], original, `${original}\n`);
expect(result).toBe(artifactText);
});
test('should replace unclosed artifacts with internal markers in fenced content', () => {
const original = `before
\`\`\`markdown