Skip to content

Commit fd7e029

Browse files
committed
fix: 修复 ZIP 根目录调试/超时截图未加载的问题(MXU结构)
- 兼容 ZIP 根目录下的 on_error/ 和 vision/ 截图资源, - 避免超时截图和错误截图在解压前被错误过滤。 - 补充 Web ZIP 提取和 Node ZIP 输入的回归测试。
1 parent cfab562 commit fd7e029

4 files changed

Lines changed: 59 additions & 4 deletions

File tree

packages/maa-log-tools/src/__tests__/nodeInput.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,22 @@ describe('node input focus selectors', () => {
9494
expect(extracted?.content).not.toContain('OldHistory')
9595
expect(extracted?.textFiles.map((file) => file.name)).toContain('notes.txt')
9696
})
97+
98+
it('collects root-level zip screenshots for on_error and wait_freezes', () => {
99+
const zipData = zipSync({
100+
'maa.log': strToU8(`${makeTimestampedLine('2026-04-16 14:55:00.000', 'AutoCollectStart')}\n`),
101+
'on_error/2026.04.16-14.57.56.745_AutoCollectRoute1AssertLocation.png': strToU8('fake-png'),
102+
'vision/2026.04.16-14.57.58.456_AutoCollectRoute1_wait_freezes.jpg': strToU8('fake-jpg'),
103+
})
104+
105+
const extracted = extractZipContentFromNodeBuffer(zipData, 'logs.zip')
106+
107+
expect(extracted).not.toBeNull()
108+
expect(extracted?.errorImages.get('2026.04.16-14.57.56.745_AutoCollectRoute1AssertLocation')).toBe(
109+
'zip:logs.zip#on_error/2026.04.16-14.57.56.745_AutoCollectRoute1AssertLocation.png',
110+
)
111+
expect(extracted?.waitFreezesImages.get('2026.04.16-14.57.58.456_AutoCollectRoute1_wait_freezes')).toBe(
112+
'zip:logs.zip#vision/2026.04.16-14.57.58.456_AutoCollectRoute1_wait_freezes.jpg',
113+
)
114+
})
97115
})

packages/maa-log-tools/src/nodeInput.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ const isNeededZipEntry = (entryPath: string): boolean => {
145145
const name = lower.slice(lower.lastIndexOf('/') + 1)
146146
if (isSearchTextFile(lower)) return true
147147
if (isCoreLogName(name)) return true
148-
if (lower.includes('/on_error/') && lower.endsWith('.png')) return true
149-
if (lower.includes('/vision/') && lower.endsWith('.jpg')) return true
148+
if ((lower.includes('/on_error/') || lower.startsWith('on_error/')) && lower.endsWith('.png')) return true
149+
if ((lower.includes('/vision/') || lower.startsWith('vision/')) && lower.endsWith('.jpg')) return true
150150
return false
151151
}
152152

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { afterEach, describe, expect, it, vi } from 'vitest'
2+
import { strToU8, zipSync } from 'fflate'
3+
4+
vi.mock('@tauri-apps/api/core', () => ({
5+
invoke: vi.fn(),
6+
}))
7+
8+
import { extractZipContent } from '../zipExtractor'
9+
10+
describe('extractZipContent', () => {
11+
afterEach(() => {
12+
vi.restoreAllMocks()
13+
})
14+
15+
it('loads root-level debug images from zip archives', async () => {
16+
const zipData = zipSync({
17+
'maa.log': strToU8('[2026-04-16 14:55:00.000][INF][Px1][Tx1][test] AutoCollectStart\n'),
18+
'on_error/2026.04.16-14.57.56.745_AutoCollectRoute1AssertLocation.png': strToU8('fake-png'),
19+
'vision/2026.04.16-14.57.57.123_AutoCollectRoute1_123456789.jpg': strToU8('fake-jpg'),
20+
'vision/2026.04.16-14.57.58.456_AutoCollectRoute1_wait_freezes.jpg': strToU8('fake-jpg'),
21+
})
22+
23+
const createObjectUrl = vi.spyOn(URL, 'createObjectURL').mockImplementation(() => {
24+
return `blob:mock-${Math.random().toString(36).slice(2)}`
25+
})
26+
vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => {})
27+
28+
const result = await extractZipContent(new File([zipData], 'root-images.zip'))
29+
30+
expect(result).not.toBeNull()
31+
expect(result?.content).toContain('AutoCollectStart')
32+
expect(result?.errorImages.has('2026.04.16-14.57.56.745_AutoCollectRoute1AssertLocation')).toBe(true)
33+
expect(result?.visionImages.has('2026.04.16-14.57.57.123_AutoCollectRoute1_123456789')).toBe(true)
34+
expect(result?.waitFreezesImages.has('2026.04.16-14.57.58.456_AutoCollectRoute1_wait_freezes')).toBe(true)
35+
expect(createObjectUrl).toHaveBeenCalledTimes(3)
36+
})
37+
})

src/utils/zipExtractor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ function isNeededFile(path: string): boolean {
3333
if (isSearchTextFile(lower)) return true
3434
if (isPrimaryLogFileName(name)) return true
3535
// on_error 截图
36-
if (lower.includes('/on_error/') && lower.endsWith('.png')) return true
36+
if ((lower.includes('/on_error/') || lower.startsWith('on_error/')) && lower.endsWith('.png')) return true
3737
// vision 调试截图
38-
if (lower.includes('/vision/') && lower.endsWith('.jpg')) return true
38+
if ((lower.includes('/vision/') || lower.startsWith('vision/')) && lower.endsWith('.jpg')) return true
3939
return false
4040
}
4141

0 commit comments

Comments
 (0)