forked from aiurda/devcontext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_test_entities.js
More file actions
209 lines (189 loc) · 6.32 KB
/
check_test_entities.js
File metadata and controls
209 lines (189 loc) · 6.32 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
/**
* Script to check code entities in the database for our new test files
*
* This script queries the code_entities table and displays information about
* all entities created from our new test files.
*/
import { executeQuery } from "./src/db.js";
// Files to check
const TEST_FILES = [
"test_files/test_simple.js",
"test_files/test_class.js",
"test_files/test_complex.js",
];
/**
* Get code entities for a file path
*
* @param {string} filePath - Path to the file
* @returns {Promise<Array>} - Array of code entities
*/
async function getCodeEntities(filePath) {
const query = `
SELECT
entity_id,
entity_type,
name,
importance_score,
content_hash,
summary,
last_modified_at,
last_accessed_at,
parent_entity_id
FROM code_entities
WHERE file_path = ?
ORDER BY entity_type, name
`;
const result = await executeQuery(query, [filePath]);
return result.rows || [];
}
/**
* Display entity information in a formatted way
*
* @param {Array} entities - Array of code entities
* @param {string} filePath - Path to the file
*/
function displayEntities(entities, filePath) {
console.log(`\n=== Entities for ${filePath} ===`);
if (entities.length === 0) {
console.log("No entities found for this file");
return;
}
console.log(`Found ${entities.length} entities:`);
// Group entities by type
const fileEntities = entities.filter((e) => e.entity_type === "file");
const classEntities = entities.filter((e) => e.entity_type === "class");
const functionEntities = entities.filter((e) => e.entity_type === "function");
const methodEntities = entities.filter((e) => e.entity_type === "method");
const otherEntities = entities.filter(
(e) => !["file", "class", "function", "method"].includes(e.entity_type)
);
// Display file entities
if (fileEntities.length > 0) {
console.log("\nFile Entities:");
fileEntities.forEach((entity) => {
console.log(` ID: ${entity.entity_id}`);
console.log(` Name: ${entity.name}`);
console.log(` Importance Score: ${entity.importance_score}`);
console.log(` Content Hash: ${entity.content_hash}`);
console.log(` Summary: ${entity.summary || "N/A"}`);
console.log(` Last Modified: ${entity.last_modified_at}`);
});
}
// Display class entities
if (classEntities.length > 0) {
console.log("\nClass Entities:");
classEntities.forEach((entity, index) => {
console.log(`\n ${index + 1}. Class: ${entity.name}`);
console.log(` ID: ${entity.entity_id}`);
console.log(` Parent ID: ${entity.parent_entity_id || "N/A"}`);
console.log(` Importance Score: ${entity.importance_score}`);
console.log(
` Summary: ${
entity.summary
? entity.summary.length > 60
? entity.summary.substring(0, 60) + "..."
: entity.summary
: "N/A"
}`
);
});
}
// Display function entities
if (functionEntities.length > 0) {
console.log("\nFunction Entities:");
functionEntities.forEach((entity, index) => {
console.log(`\n ${index + 1}. Function: ${entity.name}`);
console.log(` ID: ${entity.entity_id}`);
console.log(` Parent ID: ${entity.parent_entity_id || "N/A"}`);
console.log(` Importance Score: ${entity.importance_score}`);
console.log(
` Summary: ${
entity.summary
? entity.summary.length > 60
? entity.summary.substring(0, 60) + "..."
: entity.summary
: "N/A"
}`
);
});
}
// Display method entities
if (methodEntities.length > 0) {
console.log("\nMethod Entities:");
methodEntities.forEach((entity, index) => {
console.log(`\n ${index + 1}. Method: ${entity.name}`);
console.log(` ID: ${entity.entity_id}`);
console.log(` Parent ID: ${entity.parent_entity_id || "N/A"}`);
console.log(` Importance Score: ${entity.importance_score}`);
console.log(
` Summary: ${
entity.summary
? entity.summary.length > 60
? entity.summary.substring(0, 60) + "..."
: entity.summary
: "N/A"
}`
);
});
}
// Display other entities
if (otherEntities.length > 0) {
console.log("\nOther Entities:");
otherEntities.forEach((entity, index) => {
console.log(`\n ${index + 1}. ${entity.entity_type}: ${entity.name}`);
console.log(` ID: ${entity.entity_id}`);
console.log(` Parent ID: ${entity.parent_entity_id || "N/A"}`);
console.log(` Importance Score: ${entity.importance_score}`);
console.log(
` Summary: ${
entity.summary
? entity.summary.length > 60
? entity.summary.substring(0, 60) + "..."
: entity.summary
: "N/A"
}`
);
});
}
// Calculate importance score statistics
if (entities.length > 0) {
const scores = entities.map((e) => parseFloat(e.importance_score) || 0);
const avg = scores.reduce((sum, score) => sum + score, 0) / scores.length;
const max = Math.max(...scores);
const min = Math.min(...scores);
console.log("\nImportance Score Statistics:");
console.log(` Average: ${avg.toFixed(2)}`);
console.log(` Maximum: ${max.toFixed(2)}`);
console.log(` Minimum: ${min.toFixed(2)}`);
}
// Count entity types
console.log("\nEntity Type Distribution:");
console.log(` Files: ${fileEntities.length}`);
console.log(` Classes: ${classEntities.length}`);
console.log(` Functions: ${functionEntities.length}`);
console.log(` Methods: ${methodEntities.length}`);
console.log(` Other: ${otherEntities.length}`);
}
/**
* Main function to run the script
*/
async function main() {
try {
console.log("Checking code entities for new test files...");
for (const filePath of TEST_FILES) {
try {
const entities = await getCodeEntities(filePath);
displayEntities(entities, filePath);
} catch (error) {
console.error(`Error checking entities for ${filePath}:`, error);
}
}
console.log("\nCheck completed.");
} catch (error) {
console.error("Error running the check:", error);
}
}
// Run the script
main().catch((error) => {
console.error("Unhandled error:", error);
});