-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-real-user-matching.js
More file actions
executable file
Β·290 lines (232 loc) Β· 10.1 KB
/
debug-real-user-matching.js
File metadata and controls
executable file
Β·290 lines (232 loc) Β· 10.1 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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/usr/bin/env node
/**
* Debug script to test why real users aren't showing up in candidate matching
*/
const BASE_URL = 'http://localhost:3000';
async function makeRequest(endpoint, options = {}) {
try {
const response = await fetch(`${BASE_URL}${endpoint}`, {
headers: {
'Content-Type': 'application/json',
...options.headers,
},
...options,
});
const data = await response.json();
return { success: response.ok, data, status: response.status };
} catch (error) {
return { success: false, error: error.message };
}
}
async function checkRealUsers() {
console.log('π Step 1: Checking Real Users in Database...');
console.log('=' .repeat(60));
const result = await makeRequest('/api/debug/check-real-users');
if (!result.success) {
console.log('β Failed to check real users:', result.error);
return null;
}
const { summary, users, usersWithSkills, topSkills, sampleUserSkills } = result.data;
console.log('π Database Summary:');
console.log(` β’ Total Users: ${summary.totalUsers}`);
console.log(` β’ Users with Skills: ${summary.usersWithSkills}`);
console.log(` β’ Total User Skills: ${summary.totalUserSkills}`);
console.log(` β’ Unique Skills: ${summary.uniqueSkills}`);
if (summary.usersWithSkills === 0) {
console.log('\\nβ No users with skills found!');
console.log(' This explains why no candidates are showing up.');
return null;
}
console.log('\\nπ₯ Users with Skills:');
usersWithSkills.forEach((user, index) => {
console.log(` ${index + 1}. ${user.name} (${user.email})`);
console.log(` Skills: ${user.skills.map(s => `${s.name} (${s.proficiencyScore}%)`).join(', ')}`);
});
console.log('\\nπ― Top Skills in Database:');
topSkills.slice(0, 10).forEach((skill, index) => {
console.log(` ${index + 1}. ${skill.skillName}: ${skill.userCount} users (avg: ${skill.avgProficiency}%)`);
});
return { users: usersWithSkills, skills: topSkills };
}
async function checkJobs() {
console.log('\\nπ Step 2: Checking Available Jobs...');
console.log('=' .repeat(60));
const result = await makeRequest('/api/debug/jobs');
if (!result.success) {
console.log('β Failed to check jobs:', result.error);
return null;
}
const { summary, jobs } = result.data;
console.log('π Jobs Summary:');
console.log(` β’ Total Jobs: ${summary.totalJobs}`);
console.log(` β’ Active Jobs: ${summary.activeJobs}`);
if (jobs.length === 0) {
console.log('\\nβ No jobs found!');
console.log(' Need jobs to test candidate matching.');
return null;
}
console.log('\\nπ Available Jobs:');
jobs.forEach((job, index) => {
console.log(` ${index + 1}. ${job.title} (${job.status})`);
console.log(` Required Skills: ${job.requiredSkills?.map(s => s.name || s).join(', ') || 'None'}`);
console.log(` Preferred Skills: ${job.preferredSkills?.map(s => s.name || s).join(', ') || 'None'}`);
});
return jobs;
}
async function testCandidateMatchingWithJob(job) {
console.log(`\\nπ― Step 3: Testing Candidate Matching for "${job.title}"...`);
console.log('=' .repeat(60));
// Test with very low minimum match score to catch all candidates
const result = await makeRequest(`/api/debug/candidate-matching?jobId=${job.id}&limit=20`);
if (!result.success) {
console.log('β Candidate matching failed:', result.data?.error || result.error);
return false;
}
const { candidates, summary } = result.data.data;
console.log('π Matching Results:');
console.log(` β’ Total Candidates in DB: ${summary.totalCandidates}`);
console.log(` β’ Matched Candidates: ${summary.matchedCandidates}`);
console.log(` β’ Average Match Score: ${summary.averageMatchScore}%`);
console.log(` β’ Top Match Score: ${summary.topMatchScore}%`);
if (candidates.length === 0) {
console.log('\\nβ No candidates matched!');
console.log(' This is the problem - real users should appear here.');
return false;
}
console.log('\\nπ Matched Candidates:');
candidates.forEach((candidate, index) => {
console.log(` ${index + 1}. ${candidate.candidate.name} (${candidate.match.score}% match)`);
console.log(` Email: ${candidate.candidate.email}`);
console.log(` Skills: ${candidate.candidate.skills.map(s => s.name).join(', ')}`);
console.log(` Matching Skills: ${candidate.match.matchingSkills.map(s => s.name).join(', ')}`);
console.log(` Skill Gaps: ${candidate.match.skillGaps.map(s => s.name).join(', ')}`);
console.log(` Overall Fit: ${candidate.match.overallFit}`);
console.log('');
});
return true;
}
async function testDirectMatchAPI() {
console.log('\\nπ§ Step 4: Testing Direct Match API...');
console.log('=' .repeat(60));
// Test with skills that should match the real user
const testJobDescription = `
We are looking for a developer with experience in:
- TypeScript development
- React framework
- Modern web development
- Team collaboration
`;
const result = await makeRequest('/api/match', {
method: 'POST',
body: JSON.stringify({
jobDescription: testJobDescription,
limit: 10,
minMatchScore: 1 // Very low threshold to catch all candidates
})
});
if (!result.success) {
console.log('β Direct match API failed:', result.data?.error || result.error);
return false;
}
const { candidates, summary } = result.data.data;
console.log('π Direct Match Results:');
console.log(` β’ Total Candidates: ${summary.totalCandidates}`);
console.log(` β’ Matched Candidates: ${summary.matchedCandidates}`);
console.log(` β’ Average Match Score: ${summary.averageMatchScore}%`);
if (candidates.length === 0) {
console.log('\\nβ No candidates found via direct match API!');
return false;
}
console.log('\\nπ Direct Match Candidates:');
candidates.forEach((candidate, index) => {
console.log(` ${index + 1}. ${candidate.candidate.name} (${candidate.match.score}% match)`);
console.log(` Skills: ${candidate.candidate.skills.map(s => s.name).join(', ')}`);
});
return true;
}
async function testCandidateService() {
console.log('\\nβοΈ Step 5: Testing Candidate Service Directly...');
console.log('=' .repeat(60));
// Test the candidate service with a simple query
const result = await makeRequest('/api/recruiter/jobs');
if (!result.success) {
console.log('β Failed to get jobs for service test:', result.error);
return false;
}
if (!result.data.data || result.data.data.length === 0) {
console.log('β No jobs available for service test');
return false;
}
const firstJob = result.data.data[0];
console.log(`Testing with job: "${firstJob.title}"`);
// Test the candidates endpoint for this job
const candidatesResult = await makeRequest(`/api/recruiter/jobs/${firstJob.id}/candidates?limit=20&minMatchScore=1`);
if (!candidatesResult.success) {
console.log('β Candidates endpoint failed:', candidatesResult.data?.error || candidatesResult.error);
return false;
}
const candidatesData = candidatesResult.data;
console.log('π Candidates Endpoint Results:');
console.log(` β’ Success: ${candidatesData.success}`);
console.log(` β’ Candidates Found: ${candidatesData.data?.length || 0}`);
console.log(` β’ Total Candidates: ${candidatesData.summary?.totalCandidates || 0}`);
if (candidatesData.data && candidatesData.data.length > 0) {
console.log('\\nπ Found Candidates:');
candidatesData.data.forEach((candidate, index) => {
console.log(` ${index + 1}. ${candidate.candidate.name} (${candidate.match.score}% match)`);
});
return true;
} else {
console.log('\\nβ No candidates found via service endpoint');
return false;
}
}
async function runDebug() {
console.log('π Debugging Real User Matching Issue');
console.log('=' .repeat(70));
console.log('Expected: User with skills (Gemini team, TypeScript, React) should appear');
console.log('=' .repeat(70));
// Step 1: Check if real users exist
const userData = await checkRealUsers();
if (!userData) {
console.log('\\nπ΄ ISSUE FOUND: No users with skills in database');
console.log(' β’ Check if user skills were properly stored during AI interview');
console.log(' β’ Verify user_skills table has data');
return;
}
// Step 2: Check if jobs exist
const jobs = await checkJobs();
if (!jobs) {
console.log('\\nπ΄ ISSUE FOUND: No jobs available for matching');
console.log(' β’ Create a job posting first');
return;
}
// Step 3: Test candidate matching with first job
const matchingWorked = await testCandidateMatchingWithJob(jobs[0]);
// Step 4: Test direct match API
const directMatchWorked = await testDirectMatchAPI();
// Step 5: Test candidate service endpoint
const serviceWorked = await testCandidateService();
console.log('\\nπ Debug Summary');
console.log('=' .repeat(70));
console.log(`β
Users with skills found: ${userData ? 'YES' : 'NO'}`);
console.log(`β
Jobs available: ${jobs ? 'YES' : 'NO'}`);
console.log(`β
Candidate matching works: ${matchingWorked ? 'YES' : 'NO'}`);
console.log(`β
Direct match API works: ${directMatchWorked ? 'YES' : 'NO'}`);
console.log(`β
Service endpoint works: ${serviceWorked ? 'YES' : 'NO'}`);
if (userData && jobs && !matchingWorked) {
console.log('\\nπ΄ ISSUE IDENTIFIED:');
console.log(' β’ Users and jobs exist, but matching is not working');
console.log(' β’ Possible causes:');
console.log(' - Minimum match score too high');
console.log(' - Skill name matching issues');
console.log(' - Database query problems');
console.log(' - Caching issues');
}
if (userData && jobs && matchingWorked) {
console.log('\\nβ
SYSTEM WORKING:');
console.log(' β’ Real users should be appearing in recruiter interface');
console.log(' β’ Check recruiter dashboard and job candidate pages');
}
}
runDebug().catch(console.error);