- Added LinkedIn jobs parsing strategy to support job extraction from LinkedIn. - Updated job search parser to include new site strategy and improved argument parsing for max pages and exclusion of rejected results. - Enhanced README documentation to reflect new features and usage examples. - Refactored existing strategies for consistency and improved error handling.
81 lines
2.5 KiB
JavaScript
81 lines
2.5 KiB
JavaScript
const fs = require("fs");
|
|
const assert = require("assert");
|
|
const { analyzeSinglePost, checkOllamaStatus } = require("../ai-analyzer");
|
|
|
|
console.log("AI Analyzer logic tests");
|
|
|
|
const testData = JSON.parse(
|
|
fs.readFileSync(__dirname + "/test-data.json", "utf-8")
|
|
);
|
|
const aiResults = testData.positive;
|
|
const context = "job layoffs and workforce reduction";
|
|
const model = process.env.OLLAMA_MODEL || "mistral"; // Use OLLAMA_MODEL from env or default to mistral
|
|
|
|
(async () => {
|
|
// Check if Ollama is available
|
|
const ollamaAvailable = await checkOllamaStatus(model);
|
|
if (!ollamaAvailable) {
|
|
console.log("SKIP: Ollama not available - skipping AI analyzer tests");
|
|
console.log("PASS: AI analyzer tests skipped (Ollama not running)");
|
|
return;
|
|
}
|
|
|
|
console.log(`Testing AI analyzer with ${aiResults.length} posts...`);
|
|
|
|
for (let i = 0; i < aiResults.length; i++) {
|
|
const post = aiResults[i];
|
|
console.log(`Testing post ${i + 1}: "${post.text.substring(0, 50)}..."`);
|
|
|
|
const aiOutput = await analyzeSinglePost(post.text, context, model);
|
|
|
|
// Test that the function returns the expected structure
|
|
assert(
|
|
typeof aiOutput === "object" && aiOutput !== null,
|
|
`Post ${i} output is not an object`
|
|
);
|
|
|
|
assert(
|
|
typeof aiOutput.isRelevant === "boolean",
|
|
`Post ${i} isRelevant is not a boolean: ${typeof aiOutput.isRelevant}`
|
|
);
|
|
|
|
assert(
|
|
typeof aiOutput.confidence === "number",
|
|
`Post ${i} confidence is not a number: ${typeof aiOutput.confidence}`
|
|
);
|
|
|
|
assert(
|
|
typeof aiOutput.reasoning === "string",
|
|
`Post ${i} reasoning is not a string: ${typeof aiOutput.reasoning}`
|
|
);
|
|
|
|
// Test that confidence is within valid range
|
|
assert(
|
|
aiOutput.confidence >= 0 && aiOutput.confidence <= 1,
|
|
`Post ${i} confidence out of range: ${aiOutput.confidence} (should be 0-1)`
|
|
);
|
|
|
|
// Test that reasoning exists and is not empty
|
|
assert(
|
|
aiOutput.reasoning && aiOutput.reasoning.length > 0,
|
|
`Post ${i} missing or empty reasoning`
|
|
);
|
|
|
|
// Test that relevance is a boolean value
|
|
assert(
|
|
aiOutput.isRelevant === true || aiOutput.isRelevant === false,
|
|
`Post ${i} isRelevant is not a valid boolean: ${aiOutput.isRelevant}`
|
|
);
|
|
|
|
console.log(
|
|
` ✓ Post ${i + 1}: relevant=${aiOutput.isRelevant}, confidence=${
|
|
aiOutput.confidence
|
|
}`
|
|
);
|
|
}
|
|
|
|
console.log(
|
|
"PASS: AI analyzer returns valid structure and values for all test posts."
|
|
);
|
|
})();
|