feat(companion): validate event wait helper input names
This commit is contained in:
@@ -343,6 +343,15 @@ describe('CompanionRuntimeClient', () => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('waitForEvent validates eventName input', () => {
|
||||
const client = new CompanionRuntimeClient({
|
||||
url: 'ws://127.0.0.1:1',
|
||||
});
|
||||
|
||||
expect(() => client.waitForEvent('')).toThrow('eventName must be a non-empty string');
|
||||
expect(() => client.waitForEvent(' ')).toThrow('eventName must be a non-empty string');
|
||||
});
|
||||
|
||||
it('waitForEvent supports AbortSignal cancellation', async () => {
|
||||
const client = new CompanionRuntimeClient({
|
||||
url: 'ws://127.0.0.1:1',
|
||||
@@ -573,6 +582,9 @@ describe('CompanionRuntimeClient', () => {
|
||||
expect(() => client.waitForAnyEvent([])).toThrow(
|
||||
'eventNames must contain at least one event name',
|
||||
);
|
||||
expect(() => client.waitForAnyEvent(['agent.stream', ' '])).toThrow(
|
||||
'eventNames must not contain empty values',
|
||||
);
|
||||
});
|
||||
|
||||
it('connects and performs node registration + capability discovery', async () => {
|
||||
|
||||
@@ -437,6 +437,9 @@ export class CompanionRuntimeClient {
|
||||
signal?: AbortSignal;
|
||||
},
|
||||
): Promise<TData> {
|
||||
if (eventName.trim().length === 0) {
|
||||
throw new Error('eventName must be a non-empty string');
|
||||
}
|
||||
const timeoutMs = options?.timeoutMs ?? this.requestTimeoutMs;
|
||||
const predicate = options?.predicate;
|
||||
const signal = options?.signal;
|
||||
@@ -502,6 +505,9 @@ export class CompanionRuntimeClient {
|
||||
if (eventNames.length === 0) {
|
||||
throw new Error('eventNames must contain at least one event name');
|
||||
}
|
||||
if (eventNames.some((eventName) => eventName.trim().length === 0)) {
|
||||
throw new Error('eventNames must not contain empty values');
|
||||
}
|
||||
const eventNameSet = new Set(eventNames);
|
||||
const timeoutMs = options?.timeoutMs ?? this.requestTimeoutMs;
|
||||
const predicate = options?.predicate;
|
||||
|
||||
Reference in New Issue
Block a user