fix(protocol): enforce message element contracts end to end
Replace the open message bag with a validated discriminated union and preflight complete messages before uploads or sends. Return BAD_REQUEST for invalid or unsendable segments instead of dropping fields, sending partial content, or silently changing private messages.
This commit is contained in:
24 files changed
+1883
-417
No files matched your search
@@ -5,6 +5,7 @@
|
||||
// from blowing the line width.
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { MessageElementValidationError } from '@snowluma/protocol/element-manifest';
|
||||
import { OidbError } from '@snowluma/protocol/oidb-service';
|
||||
import { subscribeLogs, type LogEntry } from '@snowluma/common/logger';
|
||||
import { summarizeParams } from '@snowluma/common/log-summary';
|
||||
@@ -120,6 +121,25 @@ describe('ApiHandler dispatch logging', () => {
|
||||
expect(result).toMatchObject({ status: 'failed', retcode: 100, wording: 'permission denied' });
|
||||
});
|
||||
|
||||
it('maps typed outbound message-contract failures to BAD_REQUEST', async () => {
|
||||
const handler = createCompiledTestHandler(emptyContext(), [
|
||||
testAction('bad_message', async () => {
|
||||
throw new MessageElementValidationError(
|
||||
'UNKNOWN_TYPE',
|
||||
'unknown message segment type: surprise',
|
||||
'surprise',
|
||||
);
|
||||
}),
|
||||
], 12345);
|
||||
|
||||
const result = await handler.handle('bad_message', {});
|
||||
expect(result).toMatchObject({
|
||||
status: 'failed',
|
||||
retcode: 1400,
|
||||
wording: 'unknown message segment type: surprise',
|
||||
});
|
||||
});
|
||||
|
||||
it('surfaces the OidbError code + server message through error.message (no special-casing)', async () => {
|
||||
const handler = createCompiledTestHandler(emptyContext(), [
|
||||
testAction('oidb_boom', async () => { throw new OidbError(34, 'no permission', 0x11ec, 2); }),
|
||||
|
||||
Reference in new issue
Block a user