diff --git a/.github/workflows/integration-test-cron.yml b/.github/workflows/integration-test-cron.yml index 8e144d8..d457e56 100644 --- a/.github/workflows/integration-test-cron.yml +++ b/.github/workflows/integration-test-cron.yml @@ -217,6 +217,7 @@ jobs: cp example.env .env echo "NEXTCLOUD_URL=http://localhost:8080" >> .env python3 -u ./main_em.py > em_backend_logs 2>&1 & + echo $! > ../em_pid.txt # Save the embedding server process ID (PID) python3 -u ./main.py > backend_logs 2>&1 & echo $! > ../pid.txt # Save the process ID (PID) sleep 60 # Wait for the backend to get ready @@ -359,6 +360,13 @@ jobs: exit 1 fi + # Check if the embedding server is still alive + em_alive=$(ps -p $(cat em_pid.txt) -o cmd= | grep -c "main_em.py" || echo "0") + if [ "$em_alive" -eq 0 ]; then + echo "Error: Context Chat embedding server process is not running. Exiting." + exit 1 + fi + sleep 10 done diff --git a/.github/workflows/integration-test-file-listener.yml b/.github/workflows/integration-test-file-listener.yml index 4f4b7ad..2b44524 100644 --- a/.github/workflows/integration-test-file-listener.yml +++ b/.github/workflows/integration-test-file-listener.yml @@ -205,6 +205,7 @@ jobs: cp example.env .env echo "NEXTCLOUD_URL=http://localhost:8080" >> .env python3 -u ./main_em.py > em_backend_logs 2>&1 & + echo $! > ../em_pid.txt # Save the embedding server process ID (PID) python3 -u ./main.py > backend_logs 2>&1 & echo $! > ../pid.txt # Save the process ID (PID) sleep 60 # Wait for the backend to get ready @@ -350,6 +351,13 @@ jobs: exit 1 fi + # Check if the embedding server is still alive + em_alive=$(ps -p $(cat em_pid.txt) -o cmd= | grep -c "main_em.py" || echo "0") + if [ "$em_alive" -eq 0 ]; then + echo "Error: Context Chat embedding server process is not running. Exiting." + exit 1 + fi + sleep 10 done diff --git a/lib/Controller/QueueController.php b/lib/Controller/QueueController.php index 8161508..f35eaa1 100644 --- a/lib/Controller/QueueController.php +++ b/lib/Controller/QueueController.php @@ -18,7 +18,6 @@ use OCA\ContextChat\Db\QueueFile; use OCA\ContextChat\Db\QueueMapper; use OCA\ContextChat\Service\ProviderConfigService; -use OCA\ContextChat\Service\StorageService; use OCA\ContextChat\Type\Source; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\ApiRoute; diff --git a/tests/integration/ContentManagerTest.php b/tests/integration/ContentManagerTest.php index 55aff2a..2e6d8f8 100644 --- a/tests/integration/ContentManagerTest.php +++ b/tests/integration/ContentManagerTest.php @@ -24,11 +24,11 @@ use OCP\AppFramework\Services\IAppConfig; use OCP\BackgroundJob\IJobList; use OCP\EventDispatcher\IEventDispatcher; -use OCP\IServerContainer; use OCP\Server; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher; @@ -51,7 +51,7 @@ class ContentManagerTest extends TestCase { private IJobList $jobList; private IEventDispatcher $eventDispatcher; private SymfonyDispatcher $dispatcher; - private IServerContainer $serverContainer; + private ContainerInterface $serverContainer; // private bool $initCalled = false; private static string $providerClass = 'OCA\ContextChat\Tests\ContentProvider'; @@ -67,7 +67,7 @@ public function setUp(): void { // new dispatcher for each test $this->dispatcher = new SymfonyDispatcher(); - $this->serverContainer = Server::get(IServerContainer::class); + $this->serverContainer = Server::get(ContainerInterface::class); $this->eventDispatcher = new \OC\EventDispatcher\EventDispatcher( $this->dispatcher, $this->serverContainer, @@ -90,14 +90,24 @@ public function setUp(): void { // $this->overwriteService(ProviderConfigService::class, $this->providerConfig); // using this app's app id to pass the check that the app is enabled for the user - $providerObj = new ContentProvider(Application::APP_ID, 'test-provider', function () { - // $this->initCalled = true; - }); + $providerObj = new ContentProvider(Application::APP_ID, 'test-provider'); $providerClass = get_class($providerObj); - \OC::$server->registerService($providerClass, function () use ($providerObj) { - return $providerObj; - }); + // Register in the app container instead of the server container because since NC 36 + // registering `OCA\...` services directly in the core container is no longer supported, + // see https://github.com/nextcloud/server/pull/64172 + // A `\OC::$server->registerService()` here would never be seen by the `Server::get($providerClass)` + // lookup in registerContentProvider(). + // + // That lookup then falls back to reflection, which cannot build this class because its constructor + // takes scalars the container has no way to resolve. + // + // On PHP >= 8.4 the failure stays hidden (lazy ghosts defer the constructor, + // and the resolved value is discarded anyway). + \OC::$server->getAppContainerForService($providerClass) + ->registerService($providerClass, function () use ($providerObj) { + return $providerObj; + }); $this->contentManager = new ContentManager( $this->jobList, @@ -242,7 +252,6 @@ class ContentProvider implements IContentProvider { public function __construct( private string $appId, private string $providerId, - private $callback, ) { } @@ -259,6 +268,5 @@ public function getItemUrl(string $id): string { } public function triggerInitialImport(): void { - ($this->callback)(); } }