mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-14 02:29:33 +01:00
fix(discord): show the real reason a thread fails, keep the gateway across a save, refund the rate limit for a refused file
This commit is contained in:
1 parent
a698729fb6
commit
d044e49635
4 files changed
+54
-10
No files matched your search
@@ -582,7 +582,20 @@ describe('DiscordBridge', () => {
|
||||
it('names a thread that Discord answers without an id, instead of reporting an old result', async () => {
|
||||
const b = bridge({}, async (url) => (String(url).endsWith('/threads') ? jsonRes({}) : jsonRes({ id: 'msg' })));
|
||||
const r = await b.notify(MSG);
|
||||
expect(r).toMatchObject({ ok: false });
|
||||
expect(r).toMatchObject({ ok: false, error: 'Discord did not return a thread' });
|
||||
b.stop();
|
||||
});
|
||||
|
||||
it('keeps the gateway session across a save that changes neither the switch nor the token', async () => {
|
||||
const b = bridge();
|
||||
await b.reload();
|
||||
const first = (b as unknown as { gateway: unknown }).gateway;
|
||||
expect(first).not.toBeNull();
|
||||
await b.reload();
|
||||
expect((b as unknown as { gateway: unknown }).gateway).toBe(first);
|
||||
await writeDiscordConfig(dir, { ...CFG, token: 'another-token' });
|
||||
await b.reload();
|
||||
expect((b as unknown as { gateway: unknown }).gateway).not.toBe(first);
|
||||
b.stop();
|
||||
});
|
||||
|
||||
@@ -692,8 +705,9 @@ describe('DiscordBridge', () => {
|
||||
await vi.waitFor(() => expect(posts.some((p) => p.path.endsWith('/threads'))).toBe(true));
|
||||
await b.sessionDeleted('s1');
|
||||
release();
|
||||
await first;
|
||||
const out = await first;
|
||||
expect(posts).toContainEqual({ path: `/channels/${THREAD}`, method: 'PATCH', body: { archived: true } });
|
||||
expect(out).toMatchObject({ ok: false, error: 'The tab was closed' });
|
||||
expect(await readThreadMap(dir)).toEqual({});
|
||||
b.stop();
|
||||
});
|
||||
|
||||
@@ -216,6 +216,17 @@ describe('POST /api/sessions/:id/discord-notify', () => {
|
||||
bridge.stop();
|
||||
});
|
||||
|
||||
it('does not spend rate-limit tokens on a request refused for its file', async () => {
|
||||
const { app, bridge } = await harness();
|
||||
await app.inject({ method: 'PUT', url: '/api/discord', payload: FULL });
|
||||
for (let i = 0; i < 8; i++) {
|
||||
const bad = await app.inject({ method: 'POST', url, payload: { message: 'x', file: 'no-such-file.txt' } });
|
||||
expect(bad.statusCode).toBe(400);
|
||||
}
|
||||
expect((await app.inject({ method: 'POST', url, payload: { message: 'still allowed' } })).statusCode).toBe(200);
|
||||
bridge.stop();
|
||||
});
|
||||
|
||||
it('rejects an empty or oversized message', async () => {
|
||||
const { app } = await harness();
|
||||
const url = `/api/sessions/test-session-1/discord-notify`;
|
||||
|
||||
Reference in new issue
Block a user