implemented step 14 by Gemini
- added LLMpool, worker script
This commit is contained in:
72
tests/test_llmpool.php
Normal file
72
tests/test_llmpool.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
// Load configuration
|
||||
\App\Utils\Config::load(__DIR__ . '/../.env');
|
||||
|
||||
use App\Services\LLMpool;
|
||||
use App\Services\FileStorage;
|
||||
use App\Actions\ProjectActions;
|
||||
|
||||
echo "Testing LLMpool Worker (Step 14)..." . PHP_EOL . PHP_EOL;
|
||||
|
||||
$storage = new FileStorage();
|
||||
$projectActions = new ProjectActions();
|
||||
|
||||
// 1. Create a dummy project
|
||||
$userId = 'u_test_worker';
|
||||
$userData = [
|
||||
'user_id' => $userId,
|
||||
'created_at' => date('c'),
|
||||
'projects' => []
|
||||
];
|
||||
$storage->put("users/{$userId}.json", $userData);
|
||||
|
||||
$project = $projectActions->createProject($userId);
|
||||
$projectId = $project['project_id'];
|
||||
|
||||
// Mock some wizard data
|
||||
$project['wizard_data'] = [
|
||||
'business_category' => ['group' => 'gastro', 'subcategory' => 'cafe'],
|
||||
'identity' => ['business_name' => 'Kaviareň u Robota', 'tagline' => 'Káva s dušou'],
|
||||
'services' => ['items' => [['name' => 'Espresso', 'description' => 'Silná káva', 'price_from' => '2']]],
|
||||
'smart_answers' => ['terrace' => true]
|
||||
];
|
||||
$storage->put("projects/{$projectId}.json", $project);
|
||||
|
||||
// 2. Create a dummy task
|
||||
$taskId = 't_test_worker';
|
||||
$taskData = [
|
||||
'task_id' => $taskId,
|
||||
'project_id' => $projectId,
|
||||
'status' => 'queued',
|
||||
'attempt_count' => 0,
|
||||
'max_attempts' => 3,
|
||||
'created_at' => date('c'),
|
||||
'wizard_data' => $project['wizard_data']
|
||||
];
|
||||
$storage->put("llm/{$taskId}.json", $taskData);
|
||||
|
||||
echo "[INFO] Task created: $taskId for project $projectId" . PHP_EOL;
|
||||
|
||||
// 3. Run Worker
|
||||
$worker = new LLMpool();
|
||||
echo "[PROCESS] Running worker for task $taskId.json..." . PHP_EOL;
|
||||
|
||||
// Since we call real AI, it might take time
|
||||
$success = $worker->processTask($taskId . '.json');
|
||||
|
||||
if ($success) {
|
||||
echo "[SUCCESS] Worker finished successfully." . PHP_EOL;
|
||||
$updatedProject = $storage->get("projects/{$projectId}.json");
|
||||
echo "[INFO] Project status: " . $updatedProject['status'] . PHP_EOL;
|
||||
echo "[INFO] Generated content keys: " . implode(', ', array_keys($updatedProject['content']['generated'])) . PHP_EOL;
|
||||
} else {
|
||||
echo "[FAIL] Worker failed to process task." . PHP_EOL;
|
||||
$task = $storage->get("llm/{$taskId}.json");
|
||||
if ($task) {
|
||||
echo "[DEBUG] Task status: " . $task['status'] . PHP_EOL;
|
||||
echo "[DEBUG] Last error: " . ($task['last_error'] ?? 'N/A') . PHP_EOL;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user