-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-plugin.ts
More file actions
110 lines (82 loc) · 3.09 KB
/
test-plugin.ts
File metadata and controls
110 lines (82 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* Test script for @codegraph/plugin-markdown
* Run with: npx tsx packages/plugin-markdown/test-plugin.ts
*/
import { parseMarkdownContent } from './src/index';
const testMarkdown = `---
name: test-skill
description: A test skill for verification
metadata:
openclaw:
emoji: "🧪"
requires:
bins: ["test-cli"]
---
# Test Skill Documentation
This is a test markdown file to verify the plugin works correctly.
## Installation
Install the CLI tool:
\`\`\`bash
npm install -g test-cli
\`\`\`
## Usage
Here's how to use it:
\`\`\`typescript
import { testFunction } from 'test-cli';
testFunction('hello');
\`\`\`
## Links
- See [Installation Guide](./install.md) for details
- Check the [API Reference](./api.md#functions)
- External: [Documentation](https://example.com/docs)
### Nested Section
This is a nested section under Links.
## Troubleshooting
If you encounter issues, check the logs.
`;
async function main() {
console.log('Testing @codegraph/plugin-markdown...\n');
try {
const result = await parseMarkdownContent(testMarkdown, '/test/SKILL.md');
console.log('=== Document ===');
console.log(` Path: ${result.document.path}`);
console.log(` Title: ${result.document.title}`);
console.log(` Frontmatter keys: ${Object.keys(result.document.frontmatter).join(', ')}`);
console.log(` Hash: ${result.document.hash}`);
console.log('\n=== Sections ===');
for (const section of result.sections) {
const indent = ' '.repeat(section.level);
console.log(`${indent}[H${section.level}] ${section.heading} (lines ${section.startLine}-${section.endLine})`);
}
console.log('\n=== Code Blocks ===');
for (const cb of result.codeBlocks) {
console.log(` [${cb.language}] line ${cb.startLine}: ${cb.content.slice(0, 40).replace(/\n/g, '\\n')}...`);
}
console.log('\n=== Links ===');
for (const link of result.links) {
const type = link.isInternal ? 'internal' : 'external';
const anchor = link.anchor ? `#${link.anchor}` : '';
console.log(` [${type}] "${link.text}" -> ${link.target}${anchor}`);
}
console.log('\n✅ Synthetic test passed!');
// Test with real file (opt-in via env var to avoid hardcoded paths)
const realFilePath = process.env['MARKDOWN_TEST_FILE'];
if (realFilePath) {
console.log('\n\n=== Testing with Real File ===');
const { parseMarkdownFile } = await import('./src/index');
const realResult = await parseMarkdownFile(realFilePath);
console.log(` Title: ${realResult.document.title}`);
console.log(` Frontmatter: ${JSON.stringify(realResult.document.frontmatter, null, 2)}`);
console.log(` Sections: ${realResult.sections.length}`);
console.log(` Code Blocks: ${realResult.codeBlocks.length}`);
console.log(` Links: ${realResult.links.length}`);
console.log('\n✅ Real file test passed!');
} else {
console.log('\n(Skipped real-file test — set MARKDOWN_TEST_FILE env var to a path to enable.)');
}
} catch (error) {
console.error('❌ Plugin test failed:', error);
process.exit(1);
}
}
main();