Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/opencode/src/altimate/tools/training-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,11 @@ function parseMarkdownSections(markdown: string): MarkdownSection[] {
}

function slugify(text: string): string {
return text
const slug = text
.toLowerCase()
.replace(/[^a-z0-9\s-]/g, "")
.replace(/\s+/g, "-")
.replace(/^-+|-+$/g, "")
.slice(0, 64)
return slug || `entry-${Date.now()}`
}
18 changes: 18 additions & 0 deletions packages/opencode/test/altimate/training-import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,24 @@ describe("training_import: slugify edge cases", () => {
// Slugified name should strip special chars and use hyphens
expect(result.output).toContain("cte-best-practices-v20-updated")
})

test("handles pure non-ASCII headings with fallback", async () => {
setupMocks({
fileContent: [
"## \u65E5\u672C\u8A9E\u30B9\u30BF\u30A4\u30EB\u30AC\u30A4\u30C9",
"Use consistent naming.",
].join("\n"),
})

const tool = await TrainingImportTool.init()
const result = await tool.execute(
{ file_path: "japanese.md", kind: "standard", scope: "project", dry_run: true, max_entries: 20 },
ctx,
)
expect(result.metadata.count).toBe(1)
// Non-ASCII heading should produce a fallback slug, not an empty string
expect(result.output).toContain("entry-")
})
})

describe("training_import: error handling", () => {
Expand Down
Loading