refactor: centralize paired room role normalization (#193)
This commit is contained in:
@@ -10,7 +10,7 @@ import { z } from 'zod';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { CronExpressionParser } from 'cron-parser';
|
||||
import { EJCLAW_ENV } from 'ejclaw-runners-shared';
|
||||
import { EJCLAW_ENV, normalizePairedRoomRole } from 'ejclaw-runners-shared';
|
||||
import {
|
||||
buildCiWatchPrompt,
|
||||
DEFAULT_WATCH_CI_CONTEXT_MODE,
|
||||
@@ -51,11 +51,7 @@ function currentAgentType(): 'claude-code' | 'codex' {
|
||||
}
|
||||
|
||||
function currentRoomRole(): 'owner' | 'reviewer' | 'arbiter' | undefined {
|
||||
return roomRole === 'owner' ||
|
||||
roomRole === 'reviewer' ||
|
||||
roomRole === 'arbiter'
|
||||
? roomRole
|
||||
: undefined;
|
||||
return normalizePairedRoomRole(roomRole);
|
||||
}
|
||||
|
||||
function writeIpcFile(dir: string, data: object): string {
|
||||
|
||||
@@ -3,6 +3,13 @@ export {
|
||||
type RoomRoleContext,
|
||||
} from './room-role-context.js';
|
||||
export { EJCLAW_ENV, type EjclawEnvName } from './ejclaw-env.js';
|
||||
export {
|
||||
isPairedRoomRole,
|
||||
normalizePairedRoomRole,
|
||||
normalizePairedRoomRoleOrNull,
|
||||
PAIRED_ROOM_ROLES,
|
||||
type PairedRoomRole,
|
||||
} from './paired-room-role.js';
|
||||
export {
|
||||
extractMarkdownImageAttachments,
|
||||
extractMediaAttachments,
|
||||
|
||||
19
runners/shared/src/paired-room-role.ts
Normal file
19
runners/shared/src/paired-room-role.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export const PAIRED_ROOM_ROLES = ['owner', 'reviewer', 'arbiter'] as const;
|
||||
|
||||
export type PairedRoomRole = (typeof PAIRED_ROOM_ROLES)[number];
|
||||
|
||||
export function isPairedRoomRole(value: unknown): value is PairedRoomRole {
|
||||
return value === 'owner' || value === 'reviewer' || value === 'arbiter';
|
||||
}
|
||||
|
||||
export function normalizePairedRoomRole(
|
||||
value: unknown,
|
||||
): PairedRoomRole | undefined {
|
||||
return isPairedRoomRole(value) ? value : undefined;
|
||||
}
|
||||
|
||||
export function normalizePairedRoomRoleOrNull(
|
||||
value: unknown,
|
||||
): PairedRoomRole | null {
|
||||
return normalizePairedRoomRole(value) ?? null;
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { PairedRoomRole } from './paired-room-role.js';
|
||||
import type { RunnerAgentType } from './reviewer-runtime-policy.js';
|
||||
|
||||
export interface RoomRoleContext {
|
||||
serviceId: string;
|
||||
role: 'owner' | 'reviewer' | 'arbiter';
|
||||
role: PairedRoomRole;
|
||||
ownerServiceId: string;
|
||||
reviewerServiceId: string;
|
||||
ownerAgentType?: RunnerAgentType;
|
||||
|
||||
26
runners/shared/test/paired-room-role.test.ts
Normal file
26
runners/shared/test/paired-room-role.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
PAIRED_ROOM_ROLES,
|
||||
isPairedRoomRole,
|
||||
normalizePairedRoomRole,
|
||||
normalizePairedRoomRoleOrNull,
|
||||
} from '../src/paired-room-role.js';
|
||||
|
||||
describe('paired room role helpers', () => {
|
||||
it('defines the supported paired roles', () => {
|
||||
expect(PAIRED_ROOM_ROLES).toEqual(['owner', 'reviewer', 'arbiter']);
|
||||
});
|
||||
|
||||
it('recognizes valid paired room roles', () => {
|
||||
expect(isPairedRoomRole('owner')).toBe(true);
|
||||
expect(isPairedRoomRole('reviewer')).toBe(true);
|
||||
expect(isPairedRoomRole('arbiter')).toBe(true);
|
||||
});
|
||||
|
||||
it('normalizes unknown values consistently', () => {
|
||||
expect(normalizePairedRoomRole('main')).toBeUndefined();
|
||||
expect(normalizePairedRoomRole(null)).toBeUndefined();
|
||||
expect(normalizePairedRoomRoleOrNull('main')).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user