diff --git a/lib/Lifecycle/MeetingTransitionGuard.php b/lib/Lifecycle/MeetingTransitionGuard.php index 3cc3b80bc..716a2d597 100644 --- a/lib/Lifecycle/MeetingTransitionGuard.php +++ b/lib/Lifecycle/MeetingTransitionGuard.php @@ -4,7 +4,7 @@ * Meeting Transition Guard * * Guards the meeting lifecycle's open transition by reading the declaratively - * computed quorumMet field instead of invoking QuorumService. + * computed quorumMet field from the Meeting schema. * * @category Lifecycle * @package OCA\Decidesk\Lifecycle @@ -15,7 +15,7 @@ * * @link https://conduction.nl * - * @spec openspec/changes/spec/tasks.md#task-1 + * @spec openspec/changes/archive/2026-05-11-quorum-guard-rewrite/tasks.md#task-1 * * SPDX-FileCopyrightText: 2026 Conduction B.V. * SPDX-License-Identifier: EUPL-1.2 @@ -28,11 +28,10 @@ /** * Guard for meeting lifecycle transitions. * - * Chain spec 2 of 3: reads quorumMet from the declarative Meeting schema - * (computed by x-openregister-calculations in chain spec 1) rather than - * calling QuorumService. + * Reads quorumMet from the declarative Meeting schema + * (computed by x-openregister-calculations). * - * @spec openspec/changes/spec/tasks.md#task-1 + * @spec openspec/changes/archive/2026-05-11-quorum-guard-rewrite/tasks.md#task-1 */ class MeetingTransitionGuard { @@ -46,7 +45,7 @@ class MeetingTransitionGuard * * @param array $meeting Meeting object array (already loaded by the caller) * - * @spec openspec/changes/spec/tasks.md#task-1 + * @spec openspec/changes/archive/2026-05-11-quorum-guard-rewrite/tasks.md#task-1 * * @return bool True when quorum is met or no quorum is required, false otherwise */ diff --git a/lib/Service/QuorumService.php b/lib/Service/QuorumService.php deleted file mode 100644 index fd931413f..000000000 --- a/lib/Service/QuorumService.php +++ /dev/null @@ -1,168 +0,0 @@ - - * @copyright 2026 Conduction B.V. - * @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * - * @version GIT: - * - * @link https://conduction.nl - * - * @spec openspec/changes/p2-meeting-management-core-t1/tasks.md#task-3.1 - */ - -declare(strict_types=1); - -namespace OCA\Decidesk\Service; - -use Psr\Container\ContainerInterface; -use Psr\Log\LoggerInterface; - -/** - * Service for managing quorum calculations and validation. - * - * @spec openspec/changes/p2-meeting-management-core-t1/tasks.md#task-3.1 - */ -class QuorumService -{ - /** - * Constructor for QuorumService. - * - * @param ContainerInterface $container The DI container - * @param LoggerInterface $logger The logger - * - * @spec openspec/changes/p2-meeting-management-core-t1/tasks.md#task-3.1 - */ - public function __construct( - private readonly ContainerInterface $container, - private readonly LoggerInterface $logger, - ) { - }//end __construct() - - /** - * Calculate quorum status for a meeting. - * - * Supports two quorum rule formats: - * - "fixed:N" — requires exactly N participants - * - "percentage:N" — requires N% of total members - * - * @param string $meetingId UUID of the meeting - * - * @spec openspec/changes/p2-meeting-management-core-t1/tasks.md#task-3.2 - * - * @return array{quorumRequired: int|null, presentCount: int, percentage: float, met: bool} - */ - public function calculateQuorum(string $meetingId): array - { - try { - $objectService = $this->container->get('OCA\OpenRegister\Service\ObjectService'); - - $meeting = $objectService->find(id: $meetingId); - if ($meeting === null) { - return [ - 'quorumRequired' => null, - 'presentCount' => 0, - 'percentage' => 0.0, - 'met' => false, - ]; - } - - $meetingObj = $meeting->jsonSerialize(); - $quorumRule = $meetingObj['quorumRequired'] ?? null; - - if ($quorumRule === null) { - return [ - 'quorumRequired' => null, - 'presentCount' => 0, - 'percentage' => 0.0, - 'met' => true, - ]; - } - - $governanceBodyId = $meetingObj['governanceBody'] ?? null; - if ($governanceBodyId === null) { - return [ - 'quorumRequired' => $quorumRule, - 'presentCount' => 0, - 'percentage' => 0.0, - 'met' => false, - ]; - } - - $body = $objectService->find(id: $governanceBodyId); - if ($body === null) { - return [ - 'quorumRequired' => $quorumRule, - 'presentCount' => 0, - 'percentage' => 0.0, - 'met' => false, - ]; - } - - $members = $objectService->findObjects( - register: 'decidesk', - schema: 'Participant', - params: [ - 'governanceBody' => $governanceBodyId, - '_limit' => 1000, - ] - ); - - $presentCount = 0; - foreach ($members['results'] ?? [] as $member) { - if (($member['attendanceStatus'] ?? null) === 'present') { - $presentCount++; - } - } - - $totalMembers = count($members['results'] ?? []); - $percentage = 0.0; - if ($totalMembers > 0) { - $percentage = ($presentCount / $totalMembers) * 100; - } - - $met = ($presentCount >= $quorumRule); - - return [ - 'quorumRequired' => $quorumRule, - 'presentCount' => $presentCount, - 'percentage' => round($percentage, 2), - 'met' => $met, - ]; - } catch (\Throwable $e) { - $this->logger->error( - 'Decidesk: quorum calculation failed', - ['id' => $meetingId, 'exception' => $e->getMessage()] - ); - return [ - 'quorumRequired' => null, - 'presentCount' => 0, - 'percentage' => 0.0, - 'met' => false, - ]; - }//end try - }//end calculateQuorum() - - /** - * Validate whether quorum is met for a meeting. - * - * @param string $meetingId UUID of the meeting - * - * @spec openspec/changes/p2-meeting-management-core-t1/tasks.md#task-3.2 - * - * @return bool True if quorum is met or not required, false otherwise - */ - public function validateQuorum(string $meetingId): bool - { - $quorum = $this->calculateQuorum(meetingId: $meetingId); - return $quorum['met']; - }//end validateQuorum() -}//end class diff --git a/task-audit.json b/task-audit.json deleted file mode 100644 index d4559b677..000000000 --- a/task-audit.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "spec": "openspec/changes/quorum-schema-declaration", - "verified": [ - { - "task": "1", - "file": "lib/Settings/decidesk_register.json", - "ok": true, - "note": "Engine spike decision recorded in tasks.md; spike block was not written to register (live occ unavailable in build container). Proceeding on assumption engine supports cross-schema aggregations." - }, - { - "task": "2", - "file": "lib/Settings/decidesk_register.json", - "ok": true, - "note": "x-openregister-aggregations added to Meeting: totalParticipantCount, presentParticipantCount." - }, - { - "task": "3", - "file": "lib/Settings/decidesk_register.json", - "ok": true, - "note": "x-openregister-calculations added to Meeting: quorumPercentage, quorumMet with materialise:true." - }, - { - "task": "4", - "file": "lib/Settings/decidesk_register.json", - "ok": true, - "note": "Meeting version bumped from 0.1.0 to 0.2.0 (spec expected 0.4.0 baseline but development branch is at 0.1.0; earlier meeting management specs have not yet merged)." - }, - { - "task": "5", - "file": "tests/Integration/Meeting/QuorumDeclarativeTest.php", - "ok": true, - "note": "Three test cases: testQuorumMetWithRequiredAndPresent, testQuorumNotMetBelowRequired, testQuorumMetWhenNotRequired. All skip cleanly via markTestSkipped when OR engine is unavailable. phpunit exits 0." - }, - { - "task": "6", - "file": "lib/Settings/decidesk_register.json", - "ok": true, - "note": "materialise:true retained; live refresh check deferred to live OR environment per tasks.md note." - }, - { - "task": "7", - "file": "tests/Integration/Meeting/QuorumDeclarativeTest.php", - "ok": true, - "note": "License @license EUPL-1.2 + @copyright 2026 Conduction B.V. + @spec tags all present." - }, - { - "task": "8", - "file": "lib/Settings/decidesk_register.json", - "ok": true, - "note": "composer check:strict ALL CHECKS PASSED. phpunit 149 tests, 33 skipped (3 integration + 30 pre-existing). No new QuorumService hits." - }, - { - "task": "9", - "file": "openspec/architecture/adr-000-data-model.md", - "ok": true, - "note": "Meeting section updated with derived fields table for quorumPercentage, quorumMet, totalParticipantCount, presentParticipantCount." - } - ], - "stubs": [], - "missing_routes": [] -} diff --git a/tests/Unit/Lifecycle/MeetingTransitionGuardTest.php b/tests/Unit/Lifecycle/MeetingTransitionGuardTest.php index 5e88dc392..8bfaaf73c 100644 --- a/tests/Unit/Lifecycle/MeetingTransitionGuardTest.php +++ b/tests/Unit/Lifecycle/MeetingTransitionGuardTest.php @@ -12,7 +12,7 @@ * * @link https://conduction.nl * - * @spec openspec/changes/spec/tasks.md#task-4 + * @spec openspec/changes/archive/2026-05-11-quorum-guard-rewrite/tasks.md#task-4 * * SPDX-FileCopyrightText: 2026 Conduction B.V. * SPDX-License-Identifier: EUPL-1.2 @@ -29,9 +29,9 @@ * Tests for MeetingTransitionGuard.isOpenAllowed. * * Verifies that the guard reads the declarative quorumMet field - * rather than calling QuorumService. + * from the Meeting schema (computed by x-openregister-calculations). * - * @spec openspec/changes/spec/tasks.md#task-4 + * @spec openspec/changes/archive/2026-05-11-quorum-guard-rewrite/tasks.md#task-4 */ class MeetingTransitionGuardTest extends TestCase { @@ -58,7 +58,7 @@ protected function setUp(): void /** * Meeting with quorumMet = true allows the open transition. * - * @spec openspec/changes/spec/tasks.md#task-4 + * @spec openspec/changes/archive/2026-05-11-quorum-guard-rewrite/tasks.md#task-4 * * @return void */ @@ -78,7 +78,7 @@ public function testOpenAllowedWhenQuorumMet(): void /** * Meeting with quorumMet = false blocks the open transition. * - * @spec openspec/changes/spec/tasks.md#task-4 + * @spec openspec/changes/archive/2026-05-11-quorum-guard-rewrite/tasks.md#task-4 * * @return void */ @@ -101,7 +101,7 @@ public function testOpenBlockedWhenQuorumNotMet(): void * When no quorum rule is configured, the x-openregister-calculations * expression sets quorumMet = true. The guard honours that signal. * - * @spec openspec/changes/spec/tasks.md#task-4 + * @spec openspec/changes/archive/2026-05-11-quorum-guard-rewrite/tasks.md#task-4 * * @return void */ @@ -121,7 +121,7 @@ public function testOpenAllowedWhenNoQuorumRequired(): void /** * Meeting without quorumMet key defaults to false (safe default). * - * @spec openspec/changes/spec/tasks.md#task-4 + * @spec openspec/changes/archive/2026-05-11-quorum-guard-rewrite/tasks.md#task-4 * * @return void */ diff --git a/tests/Unit/Service/QuorumServiceTest.php b/tests/Unit/Service/QuorumServiceTest.php deleted file mode 100644 index 389abfb6a..000000000 --- a/tests/Unit/Service/QuorumServiceTest.php +++ /dev/null @@ -1,191 +0,0 @@ - - * @copyright 2026 Conduction B.V. - * @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * - * @version GIT: - * - * @link https://conduction.nl - * - * @spec openspec/changes/p2-meeting-management-core-t1/tasks.md#task-3.1 - */ - -declare(strict_types=1); - -namespace OCA\Decidesk\Tests\Unit\Service; - -use OCA\Decidesk\Service\QuorumService; -use OCA\OpenRegister\Service\ObjectService; -use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; -use Psr\Container\ContainerInterface; -use Psr\Log\LoggerInterface; - -/** - * Tests for QuorumService. - * - * @spec openspec/changes/p2-meeting-management-core-t1/tasks.md#task-3.1 - */ -class QuorumServiceTest extends TestCase -{ - - /** - * Service under test. - * - * @var QuorumService - */ - private QuorumService $service; - - /** - * Mock DI container. - * - * @var ContainerInterface&MockObject - */ - private ContainerInterface&MockObject $container; - - /** - * Mock logger. - * - * @var LoggerInterface&MockObject - */ - private LoggerInterface&MockObject $logger; - - /** - * Mock ObjectService from OpenRegister. - * - * @var ObjectService&MockObject - */ - private ObjectService&MockObject $objectService; - - /** - * Set up test fixtures. - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->objectService = $this->createMock(originalClassName: ObjectService::class); - $this->container = $this->createMock(originalClassName: ContainerInterface::class); - $this->logger = $this->createMock(originalClassName: LoggerInterface::class); - - $this->container->method('get') - ->with('OCA\OpenRegister\Service\ObjectService') - ->willReturn($this->objectService); - - $this->service = new QuorumService( - container: $this->container, - logger: $this->logger, - ); - - }//end setUp() - - /** - * Test quorum calculation with fixed count requirement. - * - * @spec openspec/changes/p2-meeting-management-core-t1/tasks.md#task-3.2 - * - * @return void - */ - public function testCalculateQuorumWithFixedCount(): void - { - $meetingId = '550e8400-e29b-41d4-a716-446655440000'; - $quorumRequired = 5; - - $this->objectService->method('find') - ->willReturnCallback(function($args) use ($meetingId) { - if ($args === $meetingId) { - $mock = $this->createMock(originalClassName: 'OCA\OpenRegister\Db\ObjectEntity'); - $mock->method('jsonSerialize') - ->willReturn([ - 'id' => $meetingId, - 'title' => 'Test Meeting', - 'quorumRequired' => 5, - 'governanceBody' => 'body-id-123', - ]); - return $mock; - } - return null; - }); - - $result = $this->service->calculateQuorum($meetingId); - - $this->assertIsArray($result); - $this->assertEquals(5, $result['quorumRequired']); - }//end testCalculateQuorumWithFixedCount() - - /** - * Test quorum validation returns true when met. - * - * @spec openspec/changes/p2-meeting-management-core-t1/tasks.md#task-3.3 - * - * @return void - */ - public function testValidateQuorumReturnsTrue(): void - { - $meetingId = '550e8400-e29b-41d4-a716-446655440000'; - - $this->objectService->method('find') - ->willReturnCallback(function($id) { - if ($id === '550e8400-e29b-41d4-a716-446655440000') { - $mock = $this->createMock(originalClassName: 'OCA\OpenRegister\Db\ObjectEntity'); - $mock->method('jsonSerialize') - ->willReturn([ - 'quorumRequired' => 3, - 'governanceBody' => 'body-id', - ]); - return $mock; - } - - if ($id === 'body-id') { - $mock = $this->createMock(originalClassName: 'OCA\OpenRegister\Db\ObjectEntity'); - $mock->method('jsonSerialize')->willReturn(['id' => 'body-id']); - return $mock; - } - - return null; - }); - - $this->objectService->method('findObjects') - ->willReturn([ - 'results' => [ - ['attendanceStatus' => 'present'], - ['attendanceStatus' => 'present'], - ['attendanceStatus' => 'present'], - ], - ]); - - $result = $this->service->validateQuorum($meetingId); - - $this->assertTrue($result); - }//end testValidateQuorumReturnsTrue() - - /** - * Test calculation handles missing meeting gracefully. - * - * @spec openspec/changes/p2-meeting-management-core-t1/tasks.md#task-3.2 - * - * @return void - */ - public function testCalculateQuorumWithMissingMeeting(): void - { - $meetingId = 'nonexistent-id'; - - $this->objectService->method('find') - ->willReturn(null); - - $result = $this->service->calculateQuorum($meetingId); - - $this->assertFalse($result['met']); - $this->assertEquals(0, $result['presentCount']); - }//end testCalculateQuorumWithMissingMeeting() - -}//end class