mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 04:59:34 +01:00
test(discord): the review items of #832 that go on top
A test pins the symlink and non-file branch of the reply store (a planted link or a folder at the metadata path is never replaced, and replies are still accepted), the @fileoverview names the file, its bounds, where the bridge claims and the four rules a reader has to keep, and a comment left from the #793 journal approach says store file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a9ed3f55c3
commit
d00a8d6cbf
2 files changed
+41
-3
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { mkdtemp, readFile, rm, writeFile, stat } from 'node:fs/promises';
|
||||
import { lstat, mkdir, mkdtemp, readFile, rm, symlink, writeFile, stat } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
|
||||
@@ -131,3 +131,21 @@ it('heals oversized regular metadata and persists replay protection across resta
|
||||
expect((await stat(path)).size).toBeLessThan(512 * 1024);
|
||||
expect(warn).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
it('never replaces a symlink or a folder at the metadata path, and still accepts replies', async () => {
|
||||
const path = join(dir, 'discord-reply-dedupe.json');
|
||||
const target = join(dir, 'target');
|
||||
await writeFile(target, 'keep');
|
||||
await symlink(target, path);
|
||||
const warn = vi.fn(),
|
||||
store = new DiscordReplyDedupe(dir, Date.now, warn);
|
||||
expect(await store.claim(guild, channel, message)).toBe(true);
|
||||
expect(await store.claim(guild, channel, message)).toBe(false);
|
||||
expect(await store.claim(guild, channel, '444444444444444444')).toBe(true);
|
||||
expect((await lstat(path)).isSymbolicLink()).toBe(true);
|
||||
expect(await readFile(target, 'utf8')).toBe('keep');
|
||||
expect(warn).toHaveBeenCalledTimes(1);
|
||||
await rm(path);
|
||||
await mkdir(path);
|
||||
expect(await new DiscordReplyDedupe(dir, Date.now, warn).claim(guild, channel, message)).toBe(true);
|
||||
expect((await lstat(path)).isDirectory()).toBe(true);
|
||||
});
|
||||
Reference in new issue
Block a user