mirror of
https://github.com/iflytek/skillhub.git
synced 2026-10-10 03:27:54 +00:00
test: restore passing unit suites
This commit is contained in:
parent
f6aaa6f587
commit
02c03946c9
5 changed files with 47 additions and 24 deletions
|
|
@ -64,9 +64,9 @@ class MeControllerTest {
|
|||
"Assist with code review",
|
||||
"ACTIVE",
|
||||
12L,
|
||||
3L,
|
||||
3,
|
||||
null,
|
||||
0L,
|
||||
0,
|
||||
"1.0.0",
|
||||
11L,
|
||||
"PUBLISHED",
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class NamespaceWorkflowContractTest {
|
|||
|
||||
mockMvc.perform(post("/api/web/namespaces")
|
||||
.with(csrf())
|
||||
.with(auth("owner-1"))
|
||||
.with(auth("owner-1", Set.of("SKILL_ADMIN")))
|
||||
.requestAttr("userId", "owner-1")
|
||||
.contentType(org.springframework.http.MediaType.APPLICATION_JSON)
|
||||
.content("{\"slug\":\"team-flow\",\"displayName\":\"Team Flow\",\"description\":\"workflow\"}"))
|
||||
|
|
@ -166,13 +166,17 @@ class NamespaceWorkflowContractTest {
|
|||
}
|
||||
|
||||
private RequestPostProcessor auth(String userId) {
|
||||
return auth(userId, Set.of());
|
||||
}
|
||||
|
||||
private RequestPostProcessor auth(String userId, Set<String> platformRoles) {
|
||||
PlatformPrincipal principal = new PlatformPrincipal(
|
||||
userId,
|
||||
userId,
|
||||
userId + "@example.com",
|
||||
"",
|
||||
"session",
|
||||
Set.of()
|
||||
platformRoles
|
||||
);
|
||||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
|
||||
principal,
|
||||
|
|
|
|||
30
web/src/features/skill/markdown-frontmatter.test.ts
Normal file
30
web/src/features/skill/markdown-frontmatter.test.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import { stripMarkdownFrontmatter } from './markdown-frontmatter'
|
||||
|
||||
describe('stripMarkdownFrontmatter', () => {
|
||||
it('removes yaml frontmatter from markdown content', () => {
|
||||
const markdown = `---
|
||||
name: demo
|
||||
description: sample
|
||||
---
|
||||
|
||||
# Title
|
||||
`
|
||||
|
||||
expect(stripMarkdownFrontmatter(markdown)).toBe('\n# Title\n')
|
||||
})
|
||||
|
||||
it('removes toml frontmatter from markdown content', () => {
|
||||
const markdown = `+++
|
||||
name = "demo"
|
||||
+++
|
||||
|
||||
Body`
|
||||
|
||||
expect(stripMarkdownFrontmatter(markdown)).toBe('\nBody')
|
||||
})
|
||||
|
||||
it('returns the original content when no frontmatter exists', () => {
|
||||
expect(stripMarkdownFrontmatter('# Title')).toBe('# Title')
|
||||
})
|
||||
})
|
||||
5
web/src/features/skill/markdown-frontmatter.ts
Normal file
5
web/src/features/skill/markdown-frontmatter.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
const FRONTMATTER_PATTERN = /^(---[\t ]*\r?\n[\s\S]*?\r?\n---[\t ]*(?:\r?\n|$)|\+\+\+[\t ]*\r?\n[\s\S]*?\r?\n\+\+\+[\t ]*(?:\r?\n|$))/
|
||||
|
||||
export function stripMarkdownFrontmatter(content: string) {
|
||||
return content.replace(FRONTMATTER_PATTERN, '')
|
||||
}
|
||||
|
|
@ -1,31 +1,14 @@
|
|||
import ReactMarkdown from 'react-markdown'
|
||||
import rehypeHighlight from 'rehype-highlight'
|
||||
import rehypeSanitize from 'rehype-sanitize'
|
||||
import remarkFrontmatter from 'remark-frontmatter'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
import type { Root } from 'mdast'
|
||||
import { visit } from 'unist-util-visit'
|
||||
import { stripMarkdownFrontmatter } from './markdown-frontmatter'
|
||||
|
||||
interface MarkdownRendererProps {
|
||||
content: string
|
||||
className?: string
|
||||
}
|
||||
|
||||
function remarkStripFrontmatter() {
|
||||
return (tree: Root) => {
|
||||
visit(tree, (node, index, parent) => {
|
||||
if (!parent || index === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
const nodeType = String(node.type)
|
||||
if (nodeType === 'yaml' || nodeType === 'toml') {
|
||||
parent.children.splice(index, 1)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function MarkdownRenderer({ content, className }: MarkdownRendererProps) {
|
||||
const containerClassName = [
|
||||
className,
|
||||
|
|
@ -33,11 +16,12 @@ export function MarkdownRenderer({ content, className }: MarkdownRendererProps)
|
|||
]
|
||||
.filter(Boolean)
|
||||
.join(' ')
|
||||
const normalizedContent = stripMarkdownFrontmatter(content)
|
||||
|
||||
return (
|
||||
<div className={containerClassName}>
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkFrontmatter, remarkStripFrontmatter, remarkGfm]}
|
||||
remarkPlugins={[remarkGfm]}
|
||||
rehypePlugins={[rehypeSanitize, rehypeHighlight]}
|
||||
components={{
|
||||
pre: ({ children }) => (
|
||||
|
|
@ -69,7 +53,7 @@ export function MarkdownRenderer({ content, className }: MarkdownRendererProps)
|
|||
),
|
||||
}}
|
||||
>
|
||||
{content}
|
||||
{normalizedContent}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue