Add unfencing operation for markdown text elements in safe outputs#13718
Add unfencing operation for markdown text elements in safe outputs#13718
Conversation
- Created helper file pkg/workflow/markdown_unfencing.go with UnfenceMarkdown function - Added comprehensive Go tests in pkg/workflow/markdown_unfencing_test.go (26 test cases) - Created JavaScript implementation actions/setup/js/markdown_unfencing.cjs - Added comprehensive JavaScript tests in markdown_unfencing.test.cjs (31 test cases) - Integrated unfencing into log_parser_shared.cjs to handle text elements - All tests passing and code formatted Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
- Integrated unfenceMarkdown into safe_output_type_validator.cjs for all markdown fields - Added 13 new Go test cases for fence length matching and real-world examples - Added 13 new JavaScript test cases for fence length matching and real-world examples - Total tests: 45 Go tests, 44 JavaScript tests (89 total) - All tests passing Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done in commit 4df0437: ✅ More than 3 backticks support - Already implemented and now extensively tested. The implementation dynamically counts fence characters and validates that the closing fence has at least as many characters as the opening (e.g., 4 backticks must close with 4+, but 4 backticks won't match 3 backtick closing). ✅ Applied to all safe output markdown strings - Added ✅ Added more tests - Added 26 new test cases:
All tests passing ✓ |
There was a problem hiding this comment.
Pull request overview
This pull request adds automatic detection and removal of outer markdown code fences from agent responses to address cases where agents accidentally wrap entire markdown content in code fence delimiters (```markdown\n...\n```).
Changes:
- Implements
UnfenceMarkdown()function in both Go and JavaScript with identical behavior - Integrates unfencing into safe output validation before sanitization
- Integrates unfencing into log parsing at all text content extraction points
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/markdown_unfencing.go |
Go implementation with fence detection, validation, and removal logic |
pkg/workflow/markdown_unfencing_test.go |
Comprehensive Go test suite with 45 test cases covering edge cases and real-world scenarios |
actions/setup/js/markdown_unfencing.cjs |
JavaScript implementation equivalent to Go version |
actions/setup/js/markdown_unfencing.test.cjs |
JavaScript test suite with 44 test cases mirroring Go tests |
actions/setup/js/safe_output_type_validator.cjs |
Integrates unfencing before sanitization for markdown fields |
actions/setup/js/log_parser_shared.cjs |
Integrates unfencing at three text extraction points in log parsing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,246 @@ | |||
| import { describe, it, expect } from "vitest"; | |||
There was a problem hiding this comment.
The beforeEach function is used but not imported from 'vitest'. This will cause a runtime error when the tests are executed. The import statement on line 1 should include beforeEach in the destructured imports.
| import { describe, it, expect } from "vitest"; | |
| import { describe, it, expect, beforeEach } from "vitest"; |
| // Apply unfencing to remove accidental outer markdown fences before sanitization | ||
| let processedValue = unfenceMarkdown(value); | ||
| const sanitized = sanitizeContent(processedValue, { | ||
| maxLength: validation.maxLength || MAX_BODY_LENGTH, | ||
| allowedAliases: options?.allowedAliases || [], | ||
| }); |
There was a problem hiding this comment.
While the unfenceMarkdown function itself has comprehensive test coverage, there are no integration tests verifying that it's correctly applied before sanitization in the safe output validation flow. Consider adding a test case that validates an item with a markdown field wrapped in fences to ensure the integration works as expected.
Agents occasionally wrap entire markdown responses in code fences (
\``markdown\n...\n````), causing the fence delimiters to appear in collected safe outputs. This adds detection and removal of outer fences when the entire text element is wrapped.Implementation
Go (
pkg/workflow/markdown_unfencing.go)UnfenceMarkdown()detects and strips outer fences starting withmarkdown/mdlanguage tagsJavaScript (
actions/setup/js/markdown_unfencing.cjs)log_parser_shared.cjsat all text content extraction pointssafe_output_type_validator.cjsfor all sanitized markdown fieldsBehavior
Detection criteria:
\``(markdown|md)or~~~(markdown|md)` (case-insensitive)\``or~~~`) with length >= opening fence lengthTesting
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.