Skip to content

Commit 711e696

Browse files
Copilothotlong
andcommitted
fix: simplify randomUUID guard, tighten broker error check, add auth service assertion in test
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 18b3e84 commit 711e696

2 files changed

Lines changed: 7 additions & 13 deletions

File tree

packages/plugins/plugin-auth/src/auth-plugin.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ describe('AuthPlugin', () => {
171171
expect(mockContext.logger.warn).toHaveBeenCalledWith(
172172
expect.stringContaining('No HTTP server available')
173173
);
174+
// Auth service should still be registered from init()
175+
expect(mockContext.registerService).toHaveBeenCalledWith('auth', expect.anything());
174176
// Should NOT throw
175177
});
176178

packages/runtime/src/http-dispatcher.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import { CoreServiceName } from '@objectstack/spec/system';
55

66
/** Browser-safe UUID generator — prefers Web Crypto, falls back to RFC 4122 v4 */
77
function randomUUID(): string {
8-
const cryptoObj = typeof globalThis !== 'undefined' ? (globalThis as any).crypto : undefined;
9-
if (cryptoObj && typeof cryptoObj.randomUUID === 'function') {
10-
return cryptoObj.randomUUID();
8+
if (globalThis.crypto && typeof globalThis.crypto.randomUUID === 'function') {
9+
return globalThis.crypto.randomUUID();
1110
}
1211
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
1312
const r = (Math.random() * 16) | 0;
@@ -200,17 +199,10 @@ export class HttpDispatcher {
200199
const data = await broker.call('auth.login', body, { request: context.request });
201200
return { handled: true, response: { status: 200, body: data } };
202201
} catch (error: any) {
203-
// Only fall through to mock when the broker is truly unavailable.
204-
const msg = error?.message || '';
202+
// Only fall through to mock when the broker is truly unavailable
203+
// (ensureBroker throws statusCode 500 when kernel.broker is null)
205204
const statusCode = error?.statusCode ?? error?.status;
206-
const isBrokerUnavailable =
207-
msg.includes('not available') ||
208-
msg.includes('not found') ||
209-
msg.includes('not registered') ||
210-
statusCode === 503;
211-
212-
if (!isBrokerUnavailable) {
213-
// Propagate real auth failures so callers see the correct error
205+
if (statusCode !== 500 || !error?.message?.includes('Broker not available')) {
214206
throw error;
215207
}
216208
}

0 commit comments

Comments
 (0)