mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-14 02:29:33 +01:00
fix(discord): discard a thread created for a replaced parent channel, test the notify timeout, document the bridge invariants
- a thread creation that finishes after the parent channel changed is dropped, and a finished creation only clears its own pending entry - postJson takes an optional timeout, pinned by a test against a server that never answers - drop the flat discord-bridge.json fallback - add a Discord bridge section to architecture-invariants
This commit is contained in:
1 parent
1ab54b9e9b
commit
dc22519adb
5 files changed
+93
-47
No files matched your search
@@ -58,6 +58,19 @@ describe('runNotify', () => {
|
||||
expect((await runNotify({ message: 'x' }, ENV, '/w', fake(200, undefined, { ok: true }))).code).toBe(0);
|
||||
});
|
||||
|
||||
it('postJson gives up on a server that never answers, with status 0', async () => {
|
||||
const server = createServer(() => undefined);
|
||||
await new Promise<void>((r) => server.listen(0, '127.0.0.1', r));
|
||||
try {
|
||||
const { port } = server.address() as AddressInfo;
|
||||
const r = await postJson(`http://127.0.0.1:${port}`, '/x', {}, 100);
|
||||
expect(r.status).toBe(0);
|
||||
} finally {
|
||||
server.closeAllConnections();
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('treats a disabled bridge (409) as success that says so', async () => {
|
||||
const r = await runNotify({ message: 'x' }, ENV, '/work', fake(409));
|
||||
expect(r.code).toBe(0);
|
||||
|
||||
@@ -521,6 +521,26 @@ describe('DiscordBridge', () => {
|
||||
b.stop();
|
||||
});
|
||||
|
||||
it('drops a thread whose creation finished after the parent channel changed', async () => {
|
||||
let release!: () => void;
|
||||
const gate = new Promise<void>((r) => (release = r));
|
||||
const b = bridge({}, async (url) => {
|
||||
if (String(url).endsWith(`/channels/${PARENT}/threads`)) {
|
||||
await gate;
|
||||
return jsonRes({ id: THREAD });
|
||||
}
|
||||
return jsonRes({ id: 'msg' });
|
||||
});
|
||||
const first = b.notify(MSG);
|
||||
await new Promise((r) => setTimeout(r, 10));
|
||||
await writeDiscordConfig(dir, { ...CFG, parentChannelId: '777777777777777777' });
|
||||
await b.reload();
|
||||
release();
|
||||
expect(await first).toMatchObject({ ok: false });
|
||||
expect(await readThreadMap(dir)).toEqual({});
|
||||
b.stop();
|
||||
});
|
||||
|
||||
describe('sendTest', () => {
|
||||
it('posts with the config it is given and leaves the live config alone', async () => {
|
||||
const auth: string[] = [];
|
||||
|
||||
Reference in new issue
Block a user