* fix(desktop): allow reading recent .fig files for thumbnails
The recent-files thumbnail loader stats a .fig file, opens it, and seeks
and reads its thumbnail entry, but the desktop capability granted none of
those fs commands, so the WebView rejected the first call ("fs.stat not
allowed") and no thumbnail ever loaded. Grant stat and open with the same
path scope as read-file, plus the handle commands they lead to.
A native spec runs the loader's command sequence on a real .fig file.
* test(desktop): check the bytes the recent-file thumbnail read returns
The native spec discarded the read result, so a read returning nothing would pass. Assert the zip signature and the byte count the fs plugin appends, through a bytes variant of the native invoke helper.
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import { strict as assert } from 'node:assert'
|
|
import { join } from 'node:path'
|
|
|
|
import { invokeNative, invokeNativeBytes } from '#tests/helpers/tauri/invoke'
|
|
|
|
const fixture = join(process.cwd(), 'tests', 'fixtures', 'gold-preview.fig')
|
|
// A .fig file is a zip archive.
|
|
const ZIP_SIGNATURE = [0x50, 0x4b, 0x03, 0x04]
|
|
|
|
describe('recent file thumbnails', () => {
|
|
it('reads a .fig file the way the thumbnail loader does', async () => {
|
|
const info = await invokeNative<{ size: number }>('plugin:fs|stat', { path: fixture })
|
|
assert.ok(info.size > 0, 'stat returned no size')
|
|
|
|
const rid = await invokeNative<number>('plugin:fs|open', {
|
|
path: fixture,
|
|
options: { read: true }
|
|
})
|
|
try {
|
|
const handle = await invokeNative<{ size: number }>('plugin:fs|fstat', { rid })
|
|
assert.equal(handle.size, info.size)
|
|
await invokeNative('plugin:fs|seek', { rid, offset: 0, whence: 0 })
|
|
// The plugin appends the byte count as a big-endian u64 after the data.
|
|
const read = await invokeNativeBytes('plugin:fs|read', { rid, len: ZIP_SIGNATURE.length })
|
|
assert.deepEqual(read.slice(0, -8), ZIP_SIGNATURE)
|
|
assert.equal(read.at(-1), ZIP_SIGNATURE.length)
|
|
} finally {
|
|
await invokeNative('plugin:resources|close', { rid })
|
|
}
|
|
})
|
|
})
|