-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_alifullstack_parser.js
More file actions
267 lines (224 loc) Β· 8.58 KB
/
test_alifullstack_parser.js
File metadata and controls
267 lines (224 loc) Β· 8.58 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/**
* Integration test for AliFullStackMarkdownParser to verify terminal command handling
*/
const fs = require("fs");
const path = require("path");
// Test content that simulates what would come from AI
const testContent = `
Let me help you check the current directory structure.
<run_terminal_cmd>ls -la</run_terminal_cmd>
I can see the files now. Let me also check if there are any backend processes running.
<alifullstack-run-backend-terminal-cmd>ps aux | grep node</alifullstack-run-backend-terminal-cmd>
And let me check the frontend build status.
<alifullstack-run-frontend-terminal-cmd>npm run build-status</alifullstack-run-frontend-terminal-cmd>
All commands executed successfully. The directory structure looks good.
`;
// Simulate the parseCustomTags function logic
function testParseCustomTags(content) {
console.log("π§ͺ Testing AliFullStackMarkdownParser parseCustomTags function...\n");
const customTagNames = [
"alifullstack-write",
"alifullstack-rename",
"alifullstack-delete",
"alifullstack-add-dependency",
"alifullstack-execute-sql",
"alifullstack-add-integration",
"alifullstack-output",
"alifullstack-problem-report",
"alifullstack-chat-summary",
"alifullstack-edit",
"alifullstack-codebase-context",
"think",
"alifullstack-command",
"alifullstack-run-backend-terminal-cmd",
"alifullstack-run-frontend-terminal-cmd",
"run_terminal_cmd",
];
const tagPattern = new RegExp(
`<(${customTagNames.join("|")})\\s*([^>]*)>([\\s\\S]*?)<\\/\\1>`,
"gs",
);
const contentPieces = [];
let lastIndex = 0;
let match;
console.log("π Parsing content with terminal command tags...\n");
while ((match = tagPattern.exec(content)) !== null) {
const [fullMatch, tag, attributesStr, tagContent] = match;
const startIndex = match.index;
// Add markdown content before this tag
if (startIndex > lastIndex) {
const markdownContent = content.substring(lastIndex, startIndex);
if (markdownContent.trim()) {
contentPieces.push({
type: "markdown",
content: markdownContent.trim(),
});
}
}
// Parse attributes
const attributes = {};
const attrPattern = /(\w+)="([^"]*)"/g;
let attrMatch;
while ((attrMatch = attrPattern.exec(attributesStr)) !== null) {
attributes[attrMatch[1]] = attrMatch[2];
}
// Add the tag info
contentPieces.push({
type: "custom-tag",
tagInfo: {
tag,
attributes,
content: tagContent.trim(),
fullMatch,
inProgress: false,
},
});
lastIndex = startIndex + fullMatch.length;
}
// Add remaining markdown content
if (lastIndex < content.length) {
const remainingContent = content.substring(lastIndex);
if (remainingContent.trim()) {
contentPieces.push({
type: "markdown",
content: remainingContent.trim(),
});
}
}
return contentPieces;
}
// Simulate the renderCustomTag function logic
function testRenderCustomTag(tagInfo) {
const { tag, attributes, content, inProgress } = tagInfo;
switch (tag) {
case "think":
return `<AliFullStackThink>${content}</AliFullStackThink>`;
case "alifullstack-write":
return `<AliFullStackWrite path="${attributes.path}">${content}</AliFullStackWrite>`;
case "alifullstack-rename":
return `<AliFullStackRename from="${attributes.from}" to="${attributes.to}">${content}</AliFullStackRename>`;
case "alifullstack-delete":
return `<AliFullStackDelete path="${attributes.path}">${content}</AliFullStackDelete>`;
case "alifullstack-add-dependency":
return `<AliFullStackAddDependency packages="${attributes.packages}">${content}</AliFullStackAddDependency>`;
case "alifullstack-execute-sql":
return `<AliFullStackExecuteSql description="${attributes.description}">${content}</AliFullStackExecuteSql>`;
case "alifullstack-add-integration":
return `<AliFullStackAddIntegration provider="${attributes.provider}">${content}</AliFullStackAddIntegration>`;
case "alifullstack-edit":
return `<AliFullStackEdit path="${attributes.path}">${content}</AliFullStackEdit>`;
case "alifullstack-codebase-context":
return `<AliFullStackCodebaseContext files="${attributes.files}">${content}</AliFullStackCodebaseContext>`;
case "alifullstack-output":
return `<AliFullStackOutput type="${attributes.type}">${content}</AliFullStackOutput>`;
case "alifullstack-problem-report":
return `<AliFullStackProblemSummary summary="${attributes.summary}">${content}</AliFullStackProblemSummary>`;
case "alifullstack-chat-summary":
return null;
case "alifullstack-command":
return null;
case "run_terminal_cmd":
return null; // Should return null (not render)
case "alifullstack-run-backend-terminal-cmd":
return null; // Should return null (not render)
case "alifullstack-run-frontend-terminal-cmd":
return null; // Should return null (not render)
default:
return null;
}
}
// Main test function
function runIntegrationTest() {
console.log("π AliFullStackMarkdownParser Integration Test\n");
console.log("=".repeat(60));
// Test 1: Parse the content
console.log("π TEST 1: Content Parsing");
console.log("-".repeat(40));
const contentPieces = testParseCustomTags(testContent);
console.log(`β
Content parsed into ${contentPieces.length} pieces:`);
contentPieces.forEach((piece, index) => {
if (piece.type === "markdown") {
console.log(
` ${index + 1}. [MARKDOWN]: "${piece.content.substring(0, 60)}${piece.content.length > 60 ? "..." : ""}"`,
);
} else {
console.log(
` ${index + 1}. [${piece.tagInfo.tag.toUpperCase()} TAG]: ${piece.tagInfo.content}`,
);
}
});
// Test 2: Render simulation
console.log("\nπ TEST 2: Render Simulation");
console.log("-".repeat(40));
const terminalTags = contentPieces.filter((p) => p.type === "custom-tag");
const terminalCommandTags = terminalTags.filter(
(p) =>
p.tagInfo.tag === "run_terminal_cmd" ||
p.tagInfo.tag === "alifullstack-run-backend-terminal-cmd" ||
p.tagInfo.tag === "alifullstack-run-frontend-terminal-cmd",
);
console.log(
`β
Found ${terminalCommandTags.length} terminal command tags to render:`,
);
let allReturnNull = true;
terminalCommandTags.forEach((piece, index) => {
const rendered = testRenderCustomTag(piece.tagInfo);
console.log(
` ${index + 1}. <${piece.tagInfo.tag}> renders as: ${rendered}`,
);
if (rendered !== null) {
allReturnNull = false;
}
});
// Test 3: Verify markdown content is preserved
console.log("\nπ TEST 3: Markdown Content Preservation");
console.log("-".repeat(40));
const markdownPieces = contentPieces.filter((p) => p.type === "markdown");
console.log(`β
Found ${markdownPieces.length} markdown sections:`);
markdownPieces.forEach((piece, index) => {
console.log(
` ${index + 1}. "${piece.content.substring(0, 80)}${piece.content.length > 80 ? "..." : ""}"`,
);
});
// Summary
console.log("\n" + "=".repeat(60));
console.log("π INTEGRATION TEST SUMMARY");
console.log("-".repeat(40));
const parsingSuccess = contentPieces.length === 7; // Should have 4 markdown + 3 terminal tags
const renderingSuccess = allReturnNull; // All terminal tags should return null
const markdownPreserved = markdownPieces.length === 4; // Should have 4 markdown sections
console.log(`β
Content Parsing: ${parsingSuccess ? "PASS" : "FAIL"}`);
console.log(
`β
Terminal Tag Rendering: ${renderingSuccess ? "PASS" : "FAIL"}`,
);
console.log(
`β
Markdown Preservation: ${markdownPreserved ? "PASS" : "FAIL"}`,
);
const allTestsPassed =
parsingSuccess && renderingSuccess && markdownPreserved;
console.log(
`\nOverall Result: ${allTestsPassed ? "β
ALL TESTS PASSED" : "β SOME TESTS FAILED"}`,
);
if (allTestsPassed) {
console.log(
"\nπ SUCCESS: AliFullStackMarkdownParser correctly handles terminal commands!",
);
console.log(" - Terminal command tags are parsed correctly");
console.log(" - Tags return null (not rendered in UI)");
console.log(" - Markdown content is preserved");
console.log(" - Commands will execute silently in terminals");
} else {
console.log("\nβ οΈ WARNING: Some tests failed. Check the implementation.");
}
console.log("=".repeat(60));
return allTestsPassed;
}
// Run the integration test
if (require.main === module) {
runIntegrationTest();
}
module.exports = {
testParseCustomTags,
testRenderCustomTag,
runIntegrationTest,
};