aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy Scherzinger <info@andy-scherzinger.de>2024-12-18 20:08:28 +0100
committerGitHub <noreply@github.com>2024-12-18 20:08:28 +0100
commita60f71bd939eeb94012d608736c0e96e72b20e95 (patch)
tree0125bc6590660551ac768a6e2019fb2e8efedb2c /tests
parentd2923aa30f9a6f1829d53fa000454ad3fdeb2bf3 (diff)
parent75e64e294229fdee5d3005e1c9a930f45f159195 (diff)
downloadnextcloud-server-a60f71bd939eeb94012d608736c0e96e72b20e95.tar.gz
nextcloud-server-a60f71bd939eeb94012d608736c0e96e72b20e95.zip
Merge pull request #49727 from nextcloud/feat/make-tasks-types-toggleable
Feat: make taskprocessing task types toggleable
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/TaskProcessing/TaskProcessingTest.php65
1 files changed, 58 insertions, 7 deletions
diff --git a/tests/lib/TaskProcessing/TaskProcessingTest.php b/tests/lib/TaskProcessing/TaskProcessingTest.php
index 00e1da4acb5..1088faa1126 100644
--- a/tests/lib/TaskProcessing/TaskProcessingTest.php
+++ b/tests/lib/TaskProcessing/TaskProcessingTest.php
@@ -187,6 +187,8 @@ class SuccessfulSyncProvider implements IProvider, ISynchronousProvider {
}
}
+
+
class FailingSyncProvider implements IProvider, ISynchronousProvider {
public const ERROR_MESSAGE = 'Failure';
public function getId(): string {
@@ -396,6 +398,7 @@ class TaskProcessingTest extends \Test\TestCase {
private IJobList $jobList;
private IUserMountCache $userMountCache;
private IRootFolder $rootFolder;
+ private IConfig $config;
public const TEST_USER = 'testuser';
@@ -442,11 +445,6 @@ class TaskProcessingTest extends \Test\TestCase {
$this->jobList->expects($this->any())->method('add')->willReturnCallback(function () {
});
- $config = $this->createMock(IConfig::class);
- $config->method('getAppValue')
- ->with('core', 'ai.textprocessing_provider_preferences', '')
- ->willReturn('');
-
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$text2imageManager = new \OC\TextToImage\Manager(
@@ -460,9 +458,9 @@ class TaskProcessingTest extends \Test\TestCase {
);
$this->userMountCache = $this->createMock(IUserMountCache::class);
-
+ $this->config = \OC::$server->get(IConfig::class);
$this->manager = new Manager(
- \OC::$server->get(IConfig::class),
+ $this->config,
$this->coordinator,
$this->serverContainer,
\OC::$server->get(LoggerInterface::class),
@@ -492,7 +490,24 @@ class TaskProcessingTest extends \Test\TestCase {
$this->manager->scheduleTask(new Task(TextToText::ID, ['input' => 'Hello'], 'test', null));
}
+ public function testProviderShouldBeRegisteredAndTaskTypeDisabled(): void {
+ $this->registrationContext->expects($this->any())->method('getTaskProcessingProviders')->willReturn([
+ new ServiceRegistration('test', SuccessfulSyncProvider::class)
+ ]);
+ $taskProcessingTypeSettings = [
+ TextToText::ID => false,
+ ];
+ $this->config->setAppValue('core', 'ai.taskprocessing_type_preferences', json_encode($taskProcessingTypeSettings));
+ self::assertCount(0, $this->manager->getAvailableTaskTypes());
+ self::assertCount(1, $this->manager->getAvailableTaskTypes(true));
+ self::assertTrue($this->manager->hasProviders());
+ self::expectException(\OCP\TaskProcessing\Exception\PreConditionNotMetException::class);
+ $this->manager->scheduleTask(new Task(TextToText::ID, ['input' => 'Hello'], 'test', null));
+ }
+
+
public function testProviderShouldBeRegisteredAndTaskFailValidation(): void {
+ $this->config->setAppValue('core', 'ai.taskprocessing_type_preferences', '');
$this->registrationContext->expects($this->any())->method('getTaskProcessingProviders')->willReturn([
new ServiceRegistration('test', BrokenSyncProvider::class)
]);
@@ -630,6 +645,42 @@ class TaskProcessingTest extends \Test\TestCase {
self::assertEquals(1, $task->getProgress());
}
+ public function testTaskTypeExplicitlyEnabled(): void {
+ $this->registrationContext->expects($this->any())->method('getTaskProcessingProviders')->willReturn([
+ new ServiceRegistration('test', SuccessfulSyncProvider::class)
+ ]);
+
+ $taskProcessingTypeSettings = [
+ TextToText::ID => true,
+ ];
+ $this->config->setAppValue('core', 'ai.taskprocessing_type_preferences', json_encode($taskProcessingTypeSettings));
+
+ self::assertCount(1, $this->manager->getAvailableTaskTypes());
+
+ self::assertTrue($this->manager->hasProviders());
+ $task = new Task(TextToText::ID, ['input' => 'Hello'], 'test', null);
+ self::assertNull($task->getId());
+ self::assertEquals(Task::STATUS_UNKNOWN, $task->getStatus());
+ $this->manager->scheduleTask($task);
+ self::assertNotNull($task->getId());
+ self::assertEquals(Task::STATUS_SCHEDULED, $task->getStatus());
+
+ $this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new IsInstanceOf(TaskSuccessfulEvent::class));
+
+ $backgroundJob = new \OC\TaskProcessing\SynchronousBackgroundJob(
+ \OCP\Server::get(ITimeFactory::class),
+ $this->manager,
+ $this->jobList,
+ \OCP\Server::get(LoggerInterface::class),
+ );
+ $backgroundJob->start($this->jobList);
+
+ $task = $this->manager->getTask($task->getId());
+ self::assertEquals(Task::STATUS_SUCCESSFUL, $task->getStatus(), 'Status is ' . $task->getStatus() . ' with error message: ' . $task->getErrorMessage());
+ self::assertEquals(['output' => 'Hello'], $task->getOutput());
+ self::assertEquals(1, $task->getProgress());
+ }
+
public function testAsyncProviderWithFilesShouldBeRegisteredAndRunReturningRawFileData(): void {
$this->registrationContext->expects($this->any())->method('getTaskProcessingTaskTypes')->willReturn([
new ServiceRegistration('test', AudioToImage::class)