fix: support same-service tribunal runtime

This commit is contained in:
Eyejoker
2026-03-31 14:01:31 +09:00
parent 236f7c2fea
commit 1c87616c44
9 changed files with 380 additions and 11 deletions

View File

@@ -3,12 +3,13 @@ import {
CODEX_REVIEW_SERVICE_ID,
normalizeServiceId,
} from './config.js';
import type { RoomRoleContext } from './types.js';
import type { PairedRoomRole, RoomRoleContext } from './types.js';
import type { EffectiveChannelLease } from './service-routing.js';
export function buildRoomRoleContext(
lease: EffectiveChannelLease,
serviceId: string,
preferredRole?: PairedRoomRole,
): RoomRoleContext | undefined {
const normalizedServiceId = normalizeServiceId(serviceId);
const reviewerServiceId = lease.reviewer_service_id
@@ -24,14 +25,20 @@ export function buildRoomRoleContext(
? normalizeServiceId(lease.arbiter_service_id)
: undefined;
// Check arbiter role first: if this service matches the arbiter_service_id,
// it takes the arbiter role (even if it also matches owner or reviewer)
const matches = {
owner: ownerServiceId === normalizedServiceId,
reviewer: reviewerServiceId === normalizedServiceId,
arbiter: arbiterServiceId === normalizedServiceId,
};
const role =
arbiterServiceId && arbiterServiceId === normalizedServiceId
preferredRole && matches[preferredRole]
? preferredRole
: matches.arbiter
? 'arbiter'
: ownerServiceId === normalizedServiceId
: matches.owner
? 'owner'
: reviewerServiceId === normalizedServiceId
: matches.reviewer
? 'reviewer'
: null;