Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/bridges/slack/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,40 @@ describe('bridge-slack adapter', () => {
expect(socket.closed).toBe(true);
});

it('falls back to the current time for malformed Slack timestamps', async () => {
vi.useFakeTimers().setSystemTime(new Date('2026-05-22T12:00:00.000Z'));
const fetchMock = vi.fn(async () => new Response(JSON.stringify({
ok: true,
url: 'wss://slack.example/socket',
}), { status: 200 }));
vi.stubGlobal('fetch', fetchMock);
vi.stubGlobal('WebSocket', FakeSocket);

const onMessage = vi.fn();
await adapter.subscribe(subscribeCtx(), ['C-allowed'], onMessage, {});

await FakeSocket.instances[0]?.onmessage?.({
data: JSON.stringify({
envelope_id: 'env-bad-ts',
type: 'events_api',
payload: {
event: {
type: 'message',
channel: 'C-allowed',
user: 'U123',
text: 'bad timestamp',
event_ts: '.000200',
ts: '.000200',
},
},
}),
});

expect(onMessage).toHaveBeenCalledWith(expect.objectContaining({
timestamp: '2026-05-22T12:00:00.000Z',
}));
});

it('redacts Slack tokens from API errors', async () => {
vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify({
ok: false,
Expand Down
5 changes: 3 additions & 2 deletions packages/bridges/slack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ function renderUsername(msg: BridgeMessage): string {
}

function slackTimestamp(value: string): string {
if (!/^\d+(?:\.\d+)?$/.test(value)) return new Date().toISOString();
const seconds = Number(value.split('.')[0]);
if (!Number.isFinite(seconds)) return new Date().toISOString();
return new Date(seconds * 1000).toISOString();
const date = new Date(seconds * 1000);
return Number.isNaN(date.getTime()) ? new Date().toISOString() : date.toISOString();
}

function websocketConstructor(): SlackWebSocketConstructor {
Expand Down
Loading