fix(onebot): neutral get_file cache-miss message, drop fake test
Second adversarial pass: the previous 'unsupported' wording over-corrected — it mislabeled a genuinely-uncached image file_id as 'unsupported', mirroring the original defect. A double cache miss is runtime-indistinguishable between a group-file id and an evicted image/voice, so the message now states the cache miss neutrally and offers get_group_file_url as guidance only. The prior 'group-file id' test took the same code path as the cache-miss test (a fake test); consolidated into one honest assertion.
This commit is contained in:
2 files changed
+17
-17
No files matched your search
@@ -1043,7 +1043,11 @@ export const actions = [
|
||||
// 局限:群文件/普通文件的 file_id 无法在此解析——OneBot `get_file` 单参
|
||||
// 签名不含 group_id,而 SnowLuma 群文件下载需要 group 上下文(用
|
||||
// get_group_file_url / get_private_file_url)。故此处仅覆盖图片/语音,
|
||||
// 不为群文件伪造结果,且对群文件 file_id 给出可区分的错误信息。
|
||||
// 不为群文件伪造结果。
|
||||
// 注意:缓存双 miss 时无法在此区分"传入的是群文件 file_id"与"图片/语音
|
||||
// 确实未缓存(如进程重启丢失)"——run() 不解析 id 形态。故错误信息保持
|
||||
// 中性:先陈述"未命中缓存"的事实,再把群文件改用别的接口作为指引,
|
||||
// 而非武断断言"不支持"。(summary 仅进离线文档,调用方运行时只看到 wording。)
|
||||
defineAction({
|
||||
name: 'get_file',
|
||||
summary: '获取文件信息(仅图片/语音缓存;群文件请用 get_group_file_url)',
|
||||
@@ -1059,12 +1063,10 @@ export const actions = [
|
||||
if (image) return okResponse(image);
|
||||
const record = await ctx.getRecordInfo(fileId);
|
||||
if (record) return okResponse(record);
|
||||
// 与 NapCat 不同,本接口不解析群文件/普通文件 file_id(需 group 上下文)。
|
||||
// 区分"不支持此类 file_id"与"图片/语音确实未缓存",避免调用方误判。
|
||||
return failedResponse(
|
||||
RETCODE.ACTION_FAILED,
|
||||
'get_file resolves only image/voice file_id from the media cache; '
|
||||
+ 'group/normal file_id is unsupported here — use get_group_file_url or get_private_file_url',
|
||||
'file_id not found in the image/voice cache. get_file only resolves cached '
|
||||
+ 'image/voice ids; for group/normal files use get_group_file_url or get_private_file_url',
|
||||
);
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -662,22 +662,20 @@ describe('extended-actions / get_file', () => {
|
||||
expect(res).toMatchObject({ status: 'ok', data: recordInfo });
|
||||
});
|
||||
|
||||
it('fails when the id resolves to nothing cached', async () => {
|
||||
it('fails with a neutral cache-miss message that points to the group-file path', async () => {
|
||||
// A double cache miss is runtime-indistinguishable between "a group-file
|
||||
// file_id was passed (unsupported here)" and "the image/voice really isn't
|
||||
// cached" — run() does not parse the id's shape. So the error must stay
|
||||
// neutral: state the cache miss, then offer the group-file path as
|
||||
// guidance, without asserting "unsupported".
|
||||
const getImageInfo = vi.fn(async () => null);
|
||||
const getRecordInfo = vi.fn(async () => null);
|
||||
const res = await makeHandler(fakeCtx(fakeBridge(), { getImageInfo, getRecordInfo })).handle('get_file', { file_id: 'nope' });
|
||||
expect(res).toMatchObject({ status: 'failed', retcode: 100 });
|
||||
});
|
||||
|
||||
it('gives an unsupported-file_id message (not a misleading "not cached") for a group-file id', async () => {
|
||||
// A group-file file_id cannot be resolved here (no group context); the
|
||||
// error must say so rather than imply the file is merely uncached.
|
||||
const getImageInfo = vi.fn(async () => null);
|
||||
const getRecordInfo = vi.fn(async () => null);
|
||||
const res = await makeHandler(fakeCtx(fakeBridge(), { getImageInfo, getRecordInfo }))
|
||||
.handle('get_file', { file_id: '/abcdef-group-file-id' });
|
||||
expect(res.status).toBe('failed');
|
||||
expect((res as { wording?: string }).wording).toMatch(/unsupported|get_group_file_url/);
|
||||
const wording = (res as { wording?: string }).wording ?? '';
|
||||
expect(wording).toMatch(/not found in the image\/voice cache/);
|
||||
expect(wording).toMatch(/get_group_file_url/);
|
||||
expect(wording).not.toMatch(/unsupported/);
|
||||
});
|
||||
|
||||
it('rejects when neither file nor file_id is given', async () => {
|
||||
|
||||
Reference in new issue
Block a user