appwrite/tests/e2e/Services/Advisor/AdvisorCustomServerTest.php

59 lines
1.5 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Tests\E2E\Services\Advisor;
test(insights): fix CI failures from nesting refactor Three breakages on the prior CI run: 1. PHPUnit 12 didn't propagate `@depends` data — chained tests got ArgumentCountError because they expected `array $data` but PHPUnit passed nothing. Convert all annotations to `#[Depends]` attributes, matching the modern style already used by the Migrations and VectorsDB suites. 2. `InsightsCustomConsoleTest` extends ProjectConsole, which doesn't set up a project API key. The trait's `serverHeaders()` hardcodes `x-appwrite-key`, so every Console test 401'd. Drop the Console class entirely — the manager Create endpoint is KEY-only by design, the Server class already exercises every code path, and a Console-side variant adds no real coverage. 3. `testCreateRequiresManagerScope` called `getNewKey()`, which lives on `ProjectCustom`. PHPStan flagged the call as undefined when the trait was analyzed against the (no-longer-existing) Console class. Move the test into `InsightsCustomServerTest.php` directly so it's only ever resolved against `ProjectCustom`. Plus PHP 8.4 + match-exhaustive cleanups PHPStan caught while I was in there: - `?array $headers = null` instead of `array $headers = null` on every helper (PHP 8.4 deprecates implicit-nullable params). - `?string $insightId = null` on `sampleInsight()`. - `parentResourceType` match collapsed to `tablesDB => 'tables'; databases/documentsDB/vectorsDB => 'collections'`. The earlier `$type` match already throws on unknown engine, so the fall-through default was unreachable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 08:20:54 +00:00
use Tests\E2E\Client;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideServer;
test(insights): fix CI failures from nesting refactor Three breakages on the prior CI run: 1. PHPUnit 12 didn't propagate `@depends` data — chained tests got ArgumentCountError because they expected `array $data` but PHPUnit passed nothing. Convert all annotations to `#[Depends]` attributes, matching the modern style already used by the Migrations and VectorsDB suites. 2. `InsightsCustomConsoleTest` extends ProjectConsole, which doesn't set up a project API key. The trait's `serverHeaders()` hardcodes `x-appwrite-key`, so every Console test 401'd. Drop the Console class entirely — the manager Create endpoint is KEY-only by design, the Server class already exercises every code path, and a Console-side variant adds no real coverage. 3. `testCreateRequiresManagerScope` called `getNewKey()`, which lives on `ProjectCustom`. PHPStan flagged the call as undefined when the trait was analyzed against the (no-longer-existing) Console class. Move the test into `InsightsCustomServerTest.php` directly so it's only ever resolved against `ProjectCustom`. Plus PHP 8.4 + match-exhaustive cleanups PHPStan caught while I was in there: - `?array $headers = null` instead of `array $headers = null` on every helper (PHP 8.4 deprecates implicit-nullable params). - `?string $insightId = null` on `sampleInsight()`. - `parentResourceType` match collapsed to `tablesDB => 'tables'; databases/documentsDB/vectorsDB => 'collections'`. The earlier `$type` match already throws on unknown engine, so the fall-through default was unreachable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 08:20:54 +00:00
use Utopia\Database\Helpers\ID;
class AdvisorCustomServerTest extends Scope
{
use AdvisorBase;
use ProjectCustom;
use SideServer;
test(insights): fix CI failures from nesting refactor Three breakages on the prior CI run: 1. PHPUnit 12 didn't propagate `@depends` data — chained tests got ArgumentCountError because they expected `array $data` but PHPUnit passed nothing. Convert all annotations to `#[Depends]` attributes, matching the modern style already used by the Migrations and VectorsDB suites. 2. `InsightsCustomConsoleTest` extends ProjectConsole, which doesn't set up a project API key. The trait's `serverHeaders()` hardcodes `x-appwrite-key`, so every Console test 401'd. Drop the Console class entirely — the manager Create endpoint is KEY-only by design, the Server class already exercises every code path, and a Console-side variant adds no real coverage. 3. `testCreateRequiresManagerScope` called `getNewKey()`, which lives on `ProjectCustom`. PHPStan flagged the call as undefined when the trait was analyzed against the (no-longer-existing) Console class. Move the test into `InsightsCustomServerTest.php` directly so it's only ever resolved against `ProjectCustom`. Plus PHP 8.4 + match-exhaustive cleanups PHPStan caught while I was in there: - `?array $headers = null` instead of `array $headers = null` on every helper (PHP 8.4 deprecates implicit-nullable params). - `?string $insightId = null` on `sampleInsight()`. - `parentResourceType` match collapsed to `tablesDB => 'tables'; databases/documentsDB/vectorsDB => 'collections'`. The earlier `$type` match already throws on unknown engine, so the fall-through default was unreachable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 08:20:54 +00:00
public function testReadWithAdvisorScopes(): void
test(insights): fix CI failures from nesting refactor Three breakages on the prior CI run: 1. PHPUnit 12 didn't propagate `@depends` data — chained tests got ArgumentCountError because they expected `array $data` but PHPUnit passed nothing. Convert all annotations to `#[Depends]` attributes, matching the modern style already used by the Migrations and VectorsDB suites. 2. `InsightsCustomConsoleTest` extends ProjectConsole, which doesn't set up a project API key. The trait's `serverHeaders()` hardcodes `x-appwrite-key`, so every Console test 401'd. Drop the Console class entirely — the manager Create endpoint is KEY-only by design, the Server class already exercises every code path, and a Console-side variant adds no real coverage. 3. `testCreateRequiresManagerScope` called `getNewKey()`, which lives on `ProjectCustom`. PHPStan flagged the call as undefined when the trait was analyzed against the (no-longer-existing) Console class. Move the test into `InsightsCustomServerTest.php` directly so it's only ever resolved against `ProjectCustom`. Plus PHP 8.4 + match-exhaustive cleanups PHPStan caught while I was in there: - `?array $headers = null` instead of `array $headers = null` on every helper (PHP 8.4 deprecates implicit-nullable params). - `?string $insightId = null` on `sampleInsight()`. - `parentResourceType` match collapsed to `tablesDB => 'tables'; databases/documentsDB/vectorsDB => 'collections'`. The earlier `$type` match already throws on unknown engine, so the fall-through default was unreachable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 08:20:54 +00:00
{
$projectId = $this->getProject()['$id'];
test(insights): fix CI failures from nesting refactor Three breakages on the prior CI run: 1. PHPUnit 12 didn't propagate `@depends` data — chained tests got ArgumentCountError because they expected `array $data` but PHPUnit passed nothing. Convert all annotations to `#[Depends]` attributes, matching the modern style already used by the Migrations and VectorsDB suites. 2. `InsightsCustomConsoleTest` extends ProjectConsole, which doesn't set up a project API key. The trait's `serverHeaders()` hardcodes `x-appwrite-key`, so every Console test 401'd. Drop the Console class entirely — the manager Create endpoint is KEY-only by design, the Server class already exercises every code path, and a Console-side variant adds no real coverage. 3. `testCreateRequiresManagerScope` called `getNewKey()`, which lives on `ProjectCustom`. PHPStan flagged the call as undefined when the trait was analyzed against the (no-longer-existing) Console class. Move the test into `InsightsCustomServerTest.php` directly so it's only ever resolved against `ProjectCustom`. Plus PHP 8.4 + match-exhaustive cleanups PHPStan caught while I was in there: - `?array $headers = null` instead of `array $headers = null` on every helper (PHP 8.4 deprecates implicit-nullable params). - `?string $insightId = null` on `sampleInsight()`. - `parentResourceType` match collapsed to `tablesDB => 'tables'; databases/documentsDB/vectorsDB => 'collections'`. The earlier `$type` match already throws on unknown engine, so the fall-through default was unreachable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 08:20:54 +00:00
$userKey = $this->getNewKey([
// Advisor read APIs are protected by the underlying report/insight resource scopes.
test(insights): fix CI failures from nesting refactor Three breakages on the prior CI run: 1. PHPUnit 12 didn't propagate `@depends` data — chained tests got ArgumentCountError because they expected `array $data` but PHPUnit passed nothing. Convert all annotations to `#[Depends]` attributes, matching the modern style already used by the Migrations and VectorsDB suites. 2. `InsightsCustomConsoleTest` extends ProjectConsole, which doesn't set up a project API key. The trait's `serverHeaders()` hardcodes `x-appwrite-key`, so every Console test 401'd. Drop the Console class entirely — the manager Create endpoint is KEY-only by design, the Server class already exercises every code path, and a Console-side variant adds no real coverage. 3. `testCreateRequiresManagerScope` called `getNewKey()`, which lives on `ProjectCustom`. PHPStan flagged the call as undefined when the trait was analyzed against the (no-longer-existing) Console class. Move the test into `InsightsCustomServerTest.php` directly so it's only ever resolved against `ProjectCustom`. Plus PHP 8.4 + match-exhaustive cleanups PHPStan caught while I was in there: - `?array $headers = null` instead of `array $headers = null` on every helper (PHP 8.4 deprecates implicit-nullable params). - `?string $insightId = null` on `sampleInsight()`. - `parentResourceType` match collapsed to `tablesDB => 'tables'; databases/documentsDB/vectorsDB => 'collections'`. The earlier `$type` match already throws on unknown engine, so the fall-through default was unreachable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 08:20:54 +00:00
'insights.read',
'reports.read',
test(insights): fix CI failures from nesting refactor Three breakages on the prior CI run: 1. PHPUnit 12 didn't propagate `@depends` data — chained tests got ArgumentCountError because they expected `array $data` but PHPUnit passed nothing. Convert all annotations to `#[Depends]` attributes, matching the modern style already used by the Migrations and VectorsDB suites. 2. `InsightsCustomConsoleTest` extends ProjectConsole, which doesn't set up a project API key. The trait's `serverHeaders()` hardcodes `x-appwrite-key`, so every Console test 401'd. Drop the Console class entirely — the manager Create endpoint is KEY-only by design, the Server class already exercises every code path, and a Console-side variant adds no real coverage. 3. `testCreateRequiresManagerScope` called `getNewKey()`, which lives on `ProjectCustom`. PHPStan flagged the call as undefined when the trait was analyzed against the (no-longer-existing) Console class. Move the test into `InsightsCustomServerTest.php` directly so it's only ever resolved against `ProjectCustom`. Plus PHP 8.4 + match-exhaustive cleanups PHPStan caught while I was in there: - `?array $headers = null` instead of `array $headers = null` on every helper (PHP 8.4 deprecates implicit-nullable params). - `?string $insightId = null` on `sampleInsight()`. - `parentResourceType` match collapsed to `tablesDB => 'tables'; databases/documentsDB/vectorsDB => 'collections'`. The earlier `$type` match already throws on unknown engine, so the fall-through default was unreachable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 08:20:54 +00:00
]);
$listed = $this->client->call(
Client::METHOD_GET,
'/reports',
[
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-key' => $userKey,
]
);
$this->assertSame(200, $listed['headers']['status-code']);
$create = $this->client->call(
test(insights): fix CI failures from nesting refactor Three breakages on the prior CI run: 1. PHPUnit 12 didn't propagate `@depends` data — chained tests got ArgumentCountError because they expected `array $data` but PHPUnit passed nothing. Convert all annotations to `#[Depends]` attributes, matching the modern style already used by the Migrations and VectorsDB suites. 2. `InsightsCustomConsoleTest` extends ProjectConsole, which doesn't set up a project API key. The trait's `serverHeaders()` hardcodes `x-appwrite-key`, so every Console test 401'd. Drop the Console class entirely — the manager Create endpoint is KEY-only by design, the Server class already exercises every code path, and a Console-side variant adds no real coverage. 3. `testCreateRequiresManagerScope` called `getNewKey()`, which lives on `ProjectCustom`. PHPStan flagged the call as undefined when the trait was analyzed against the (no-longer-existing) Console class. Move the test into `InsightsCustomServerTest.php` directly so it's only ever resolved against `ProjectCustom`. Plus PHP 8.4 + match-exhaustive cleanups PHPStan caught while I was in there: - `?array $headers = null` instead of `array $headers = null` on every helper (PHP 8.4 deprecates implicit-nullable params). - `?string $insightId = null` on `sampleInsight()`. - `parentResourceType` match collapsed to `tablesDB => 'tables'; databases/documentsDB/vectorsDB => 'collections'`. The earlier `$type` match already throws on unknown engine, so the fall-through default was unreachable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 08:20:54 +00:00
Client::METHOD_POST,
'/reports',
test(insights): fix CI failures from nesting refactor Three breakages on the prior CI run: 1. PHPUnit 12 didn't propagate `@depends` data — chained tests got ArgumentCountError because they expected `array $data` but PHPUnit passed nothing. Convert all annotations to `#[Depends]` attributes, matching the modern style already used by the Migrations and VectorsDB suites. 2. `InsightsCustomConsoleTest` extends ProjectConsole, which doesn't set up a project API key. The trait's `serverHeaders()` hardcodes `x-appwrite-key`, so every Console test 401'd. Drop the Console class entirely — the manager Create endpoint is KEY-only by design, the Server class already exercises every code path, and a Console-side variant adds no real coverage. 3. `testCreateRequiresManagerScope` called `getNewKey()`, which lives on `ProjectCustom`. PHPStan flagged the call as undefined when the trait was analyzed against the (no-longer-existing) Console class. Move the test into `InsightsCustomServerTest.php` directly so it's only ever resolved against `ProjectCustom`. Plus PHP 8.4 + match-exhaustive cleanups PHPStan caught while I was in there: - `?array $headers = null` instead of `array $headers = null` on every helper (PHP 8.4 deprecates implicit-nullable params). - `?string $insightId = null` on `sampleInsight()`. - `parentResourceType` match collapsed to `tablesDB => 'tables'; databases/documentsDB/vectorsDB => 'collections'`. The earlier `$type` match already throws on unknown engine, so the fall-through default was unreachable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 08:20:54 +00:00
[
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
test(insights): fix CI failures from nesting refactor Three breakages on the prior CI run: 1. PHPUnit 12 didn't propagate `@depends` data — chained tests got ArgumentCountError because they expected `array $data` but PHPUnit passed nothing. Convert all annotations to `#[Depends]` attributes, matching the modern style already used by the Migrations and VectorsDB suites. 2. `InsightsCustomConsoleTest` extends ProjectConsole, which doesn't set up a project API key. The trait's `serverHeaders()` hardcodes `x-appwrite-key`, so every Console test 401'd. Drop the Console class entirely — the manager Create endpoint is KEY-only by design, the Server class already exercises every code path, and a Console-side variant adds no real coverage. 3. `testCreateRequiresManagerScope` called `getNewKey()`, which lives on `ProjectCustom`. PHPStan flagged the call as undefined when the trait was analyzed against the (no-longer-existing) Console class. Move the test into `InsightsCustomServerTest.php` directly so it's only ever resolved against `ProjectCustom`. Plus PHP 8.4 + match-exhaustive cleanups PHPStan caught while I was in there: - `?array $headers = null` instead of `array $headers = null` on every helper (PHP 8.4 deprecates implicit-nullable params). - `?string $insightId = null` on `sampleInsight()`. - `parentResourceType` match collapsed to `tablesDB => 'tables'; databases/documentsDB/vectorsDB => 'collections'`. The earlier `$type` match already throws on unknown engine, so the fall-through default was unreachable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 08:20:54 +00:00
'x-appwrite-key' => $userKey,
],
[
'reportId' => ID::unique(),
'type' => 'audit',
'title' => 'Read-only check',
'targetType' => 'sites',
'target' => 'home',
]
test(insights): fix CI failures from nesting refactor Three breakages on the prior CI run: 1. PHPUnit 12 didn't propagate `@depends` data — chained tests got ArgumentCountError because they expected `array $data` but PHPUnit passed nothing. Convert all annotations to `#[Depends]` attributes, matching the modern style already used by the Migrations and VectorsDB suites. 2. `InsightsCustomConsoleTest` extends ProjectConsole, which doesn't set up a project API key. The trait's `serverHeaders()` hardcodes `x-appwrite-key`, so every Console test 401'd. Drop the Console class entirely — the manager Create endpoint is KEY-only by design, the Server class already exercises every code path, and a Console-side variant adds no real coverage. 3. `testCreateRequiresManagerScope` called `getNewKey()`, which lives on `ProjectCustom`. PHPStan flagged the call as undefined when the trait was analyzed against the (no-longer-existing) Console class. Move the test into `InsightsCustomServerTest.php` directly so it's only ever resolved against `ProjectCustom`. Plus PHP 8.4 + match-exhaustive cleanups PHPStan caught while I was in there: - `?array $headers = null` instead of `array $headers = null` on every helper (PHP 8.4 deprecates implicit-nullable params). - `?string $insightId = null` on `sampleInsight()`. - `parentResourceType` match collapsed to `tablesDB => 'tables'; databases/documentsDB/vectorsDB => 'collections'`. The earlier `$type` match already throws on unknown engine, so the fall-through default was unreachable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 08:20:54 +00:00
);
$this->assertSame(404, $create['headers']['status-code']);
test(insights): fix CI failures from nesting refactor Three breakages on the prior CI run: 1. PHPUnit 12 didn't propagate `@depends` data — chained tests got ArgumentCountError because they expected `array $data` but PHPUnit passed nothing. Convert all annotations to `#[Depends]` attributes, matching the modern style already used by the Migrations and VectorsDB suites. 2. `InsightsCustomConsoleTest` extends ProjectConsole, which doesn't set up a project API key. The trait's `serverHeaders()` hardcodes `x-appwrite-key`, so every Console test 401'd. Drop the Console class entirely — the manager Create endpoint is KEY-only by design, the Server class already exercises every code path, and a Console-side variant adds no real coverage. 3. `testCreateRequiresManagerScope` called `getNewKey()`, which lives on `ProjectCustom`. PHPStan flagged the call as undefined when the trait was analyzed against the (no-longer-existing) Console class. Move the test into `InsightsCustomServerTest.php` directly so it's only ever resolved against `ProjectCustom`. Plus PHP 8.4 + match-exhaustive cleanups PHPStan caught while I was in there: - `?array $headers = null` instead of `array $headers = null` on every helper (PHP 8.4 deprecates implicit-nullable params). - `?string $insightId = null` on `sampleInsight()`. - `parentResourceType` match collapsed to `tablesDB => 'tables'; databases/documentsDB/vectorsDB => 'collections'`. The earlier `$type` match already throws on unknown engine, so the fall-through default was unreachable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 08:20:54 +00:00
}
}