mirror of
https://github.com/crowetic/nc-talk-ai.git
synced 2026-09-07 15:42:31 +00:00
Talk AI is a multi-bot AI assistant manager for Nextcloud Talk: per-bot prompts and models, agentic tool calling (MCP + built-in tools), RAG over Nextcloud files, room-document search, vision and speech-to-text attachments, persistent bot wikis, approval workflows, rate limiting, and multi-provider LLM support (any OpenAI-compatible endpoint). Developed within EDUC - the European Digital UniverCity (https://educalliance.eu), where it runs as the 'EDUC AI' assistant on the alliance-wide Nextcloud portal. This public repository is the upstream point of truth; deployment-specific tools plug in via the tool-provider extension point (docs/TOOL_PROVIDERS.md). License: AGPL-3.0-or-later.
98 lines
2.6 KiB
PHP
98 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\EducAI\Tests\Unit\Jobs;
|
|
|
|
use OCA\EducAI\Db\WikiRoot;
|
|
use OCA\EducAI\Db\WikiRootMapper;
|
|
use OCA\EducAI\Jobs\SyncWikiRootIndexJob;
|
|
use OCA\EducAI\Service\WikiService;
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
use OCP\Files\Folder;
|
|
use OCP\Files\IRootFolder;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class SyncWikiRootIndexJobTest extends TestCase {
|
|
public function testRunSyncsRootAndMarksSuccess(): void {
|
|
$root = $this->createRoot();
|
|
$folder = $this->createMock(Folder::class);
|
|
|
|
$rootMapper = $this->createMock(WikiRootMapper::class);
|
|
$rootMapper->expects($this->once())
|
|
->method('findById')
|
|
->with(7)
|
|
->willReturn($root);
|
|
$rootMapper->expects($this->once())
|
|
->method('update')
|
|
->willReturnCallback(function (WikiRoot $updated): WikiRoot {
|
|
$this->assertNotNull($updated->getLastSyncedAt());
|
|
$this->assertNull($updated->getLastError());
|
|
return $updated;
|
|
});
|
|
|
|
$rootFolder = $this->createMock(IRootFolder::class);
|
|
$rootFolder->expects($this->once())
|
|
->method('getById')
|
|
->with(1234)
|
|
->willReturn([$folder]);
|
|
|
|
$wikiService = $this->createMock(WikiService::class);
|
|
$wikiService->expects($this->once())
|
|
->method('syncIndexForRoot')
|
|
->with($folder)
|
|
->willReturn(['count' => 2]);
|
|
|
|
$job = new SyncWikiRootIndexJob(
|
|
$this->createMock(ITimeFactory::class),
|
|
$rootMapper,
|
|
$rootFolder,
|
|
$wikiService,
|
|
$this->createMock(LoggerInterface::class)
|
|
);
|
|
|
|
$job->run(['root_id' => 7]);
|
|
}
|
|
|
|
public function testRunStoresFailureWhenRootFolderCannotBeLoaded(): void {
|
|
$root = $this->createRoot();
|
|
|
|
$rootMapper = $this->createMock(WikiRootMapper::class);
|
|
$rootMapper->method('findById')->willReturn($root);
|
|
$rootMapper->expects($this->once())
|
|
->method('update')
|
|
->willReturnCallback(function (WikiRoot $updated): WikiRoot {
|
|
$this->assertNotSame('', $updated->getLastError());
|
|
$this->assertNull($updated->getLastSyncedAt());
|
|
return $updated;
|
|
});
|
|
|
|
$rootFolder = $this->createMock(IRootFolder::class);
|
|
$rootFolder->method('getById')->with(1234)->willReturn([]);
|
|
|
|
$wikiService = $this->createMock(WikiService::class);
|
|
$wikiService->expects($this->never())
|
|
->method('syncIndexForRoot');
|
|
|
|
$job = new SyncWikiRootIndexJob(
|
|
$this->createMock(ITimeFactory::class),
|
|
$rootMapper,
|
|
$rootFolder,
|
|
$wikiService,
|
|
$this->createMock(LoggerInterface::class)
|
|
);
|
|
|
|
$job->run(['root_id' => 7]);
|
|
}
|
|
|
|
private function createRoot(): WikiRoot {
|
|
$root = new WikiRoot();
|
|
$root->setId(7);
|
|
$root->setRootNodeId(1234);
|
|
$root->setRootPath('/alice/files/wiki');
|
|
$root->setActive(true);
|
|
return $root;
|
|
}
|
|
}
|