mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
test: remove icon projection samples and tray suite
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -4025,7 +4025,6 @@
|
||||
"src/main/text-generation/source-control-wsl-launch.test.ts": 482,
|
||||
"src/main/text-generation/source-control-wsl-prompt.test.ts": 2440,
|
||||
"src/main/tray/system-tray.test.ts": 556,
|
||||
"src/main/tray/tray-attention-icon.test.ts": 52,
|
||||
"src/main/tray/tray-dev-badge.test.ts": 51,
|
||||
"src/main/updater/updater-events.test.ts": 280,
|
||||
"src/main/updater/updater-linux-package-recovery-actions.test.ts": 2294,
|
||||
|
||||
@@ -46,62 +46,7 @@ function setup(
|
||||
const ENCODED = new Uint8Array([1, 2, 3])
|
||||
const ENCODED_URL = 'data:image/png;base64,AQID'
|
||||
|
||||
describe('RepoIconDataUrls without an encoder (orcad)', () => {
|
||||
it('passes a small fetched image through as a data URL', async () => {
|
||||
const bytes = pngHeader(64, 64)
|
||||
const { icons } = setup([repo('a', AVATAR)])
|
||||
const id = repoIconId(AVATAR)!
|
||||
|
||||
expect(await icons.read([id])).toEqual({
|
||||
icons: [{ id, dataUrl: `data:image/png;base64,${Buffer.from(bytes).toString('base64')}` }]
|
||||
})
|
||||
})
|
||||
|
||||
it('falls back for an upload too large to pass through', async () => {
|
||||
const icon = upload(pngHeader(64, 64, MAX_REPO_ICON_DATA_URL_BYTES))
|
||||
const { icons } = setup([repo('a', icon)])
|
||||
|
||||
expect((await icons.read([repoIconId(icon)!])).icons[0].dataUrl).toBeNull()
|
||||
})
|
||||
|
||||
it('answers null for an id no repo shows, in request order', async () => {
|
||||
const { icons, fetch } = setup([repo('a', AVATAR)])
|
||||
const id = repoIconId(AVATAR)!
|
||||
|
||||
const reply = await icons.read(['missing', id])
|
||||
|
||||
expect(reply.icons.map((icon) => [icon.id, icon.dataUrl === null])).toEqual([
|
||||
['missing', true],
|
||||
[id, false]
|
||||
])
|
||||
expect(fetch).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('RepoIconDataUrls.idsByRepo', () => {
|
||||
it('names each repo’s image by host and repo, the ids a read answers', async () => {
|
||||
const remote = { ...repo('a', AVATAR), connectionId: 'box' }
|
||||
const { icons } = setup([
|
||||
repo('a', AVATAR),
|
||||
remote,
|
||||
repo('glyph', { type: 'emoji', emoji: 'x' }),
|
||||
repo('none', null)
|
||||
])
|
||||
const id = repoIconId(AVATAR)!
|
||||
|
||||
expect(icons.idsByRepo()).toEqual({ 'local|a': id, 'ssh:box|a': id })
|
||||
expect((await icons.read([id])).icons[0].dataUrl).not.toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('RepoIconDataUrls with an encoder (desktop)', () => {
|
||||
it('re-encodes a large upload rather than dropping it', async () => {
|
||||
const icon = upload(pngHeader(1024, 1024, 300 * 1024))
|
||||
const { icons } = setup([repo('a', icon)], { encoder: () => ENCODED })
|
||||
|
||||
expect((await icons.read([repoIconId(icon)!])).icons[0].dataUrl).toBe(ENCODED_URL)
|
||||
})
|
||||
|
||||
it('steps down to 32 px when the 64 px PNG is over the cap', async () => {
|
||||
const huge = new Uint8Array(MAX_REPO_ICON_DATA_URL_BYTES)
|
||||
const encoder = vi.fn<RepoIconPngEncoder>((_bytes, edge) => (edge === 64 ? huge : ENCODED))
|
||||
@@ -111,13 +56,6 @@ describe('RepoIconDataUrls with an encoder (desktop)', () => {
|
||||
expect(encoder.mock.calls.map(([, edge]) => edge)).toEqual([64, 32])
|
||||
})
|
||||
|
||||
it('passes a small image the decoder cannot read through, as orcad would', async () => {
|
||||
const { icons } = setup([repo('a', AVATAR)], { encoder: () => null })
|
||||
expect((await icons.read([repoIconId(AVATAR)!])).icons[0].dataUrl).toMatch(
|
||||
/^data:image\/png;base64,/
|
||||
)
|
||||
})
|
||||
|
||||
it('falls back when neither encoding nor passthrough fits the cap', async () => {
|
||||
const icon = upload(pngHeader(64, 64, MAX_REPO_ICON_DATA_URL_BYTES))
|
||||
const huge = new Uint8Array(MAX_REPO_ICON_DATA_URL_BYTES)
|
||||
|
||||
@@ -79,13 +79,6 @@ describe('fetchRemoteRepoIcon', () => {
|
||||
expect(pulls).toBeLessThan(10)
|
||||
})
|
||||
|
||||
it('refuses a reply that is not a raster image', async () => {
|
||||
const svg = new Response('<svg/>', { headers: { 'content-type': 'image/svg+xml' } })
|
||||
expect(await fetchRemoteRepoIcon(AVATAR, async () => svg)).toBeNull()
|
||||
const missing = new Response('nope', { status: 404, headers: { 'content-type': 'image/png' } })
|
||||
expect(await fetchRemoteRepoIcon(AVATAR, async () => missing)).toBeNull()
|
||||
})
|
||||
|
||||
it('refuses non-https and credentialed sources', async () => {
|
||||
const fetch = vi.fn<RepoIconFetch>()
|
||||
expect(await fetchRemoteRepoIcon('http://github.com/a.png', fetch)).toBeNull()
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const createFromBitmapMock = vi.hoisted(() =>
|
||||
vi.fn((buffer: Buffer, options: { width: number; height: number }) => ({
|
||||
__image: true,
|
||||
buffer,
|
||||
...options
|
||||
}))
|
||||
)
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
nativeImage: { createFromBitmap: createFromBitmapMock }
|
||||
}))
|
||||
|
||||
import { composeTrayAttentionIcon, tintTrayTemplateForAttention } from './tray-attention-icon'
|
||||
|
||||
type FakeImage = {
|
||||
getSize: () => { width: number; height: number }
|
||||
toBitmap: () => Buffer
|
||||
}
|
||||
|
||||
function fakeBase(width: number, height: number): FakeImage {
|
||||
// Transparent base isolates pixels contributed by the attention dot/ring.
|
||||
return {
|
||||
getSize: () => ({ width, height }),
|
||||
toBitmap: () => Buffer.alloc(width * height * 4, 0)
|
||||
}
|
||||
}
|
||||
|
||||
// Electron bitmaps use BGRA; renderer attention token is amber-500 (#f59e0b).
|
||||
const AMBER = { b: 0x0b, g: 0x9e, r: 0xf5 }
|
||||
|
||||
describe('composeTrayAttentionIcon', () => {
|
||||
it('paints an amber dot in the top-right corner and leaves the rest untouched', () => {
|
||||
createFromBitmapMock.mockClear()
|
||||
const width = 16
|
||||
const height = 16
|
||||
composeTrayAttentionIcon(fakeBase(width, height) as never)
|
||||
const bitmap = createFromBitmapMock.mock.calls[0][0]
|
||||
|
||||
const pixel = (x: number, y: number): [number, number, number, number] => {
|
||||
const o = (y * width + x) * 4
|
||||
return [bitmap[o], bitmap[o + 1], bitmap[o + 2], bitmap[o + 3]]
|
||||
}
|
||||
|
||||
let amberCount = 0
|
||||
let sumX = 0
|
||||
let sumY = 0
|
||||
let paintedInBottomLeft = 0
|
||||
for (let y = 0; y < height; y++) {
|
||||
for (let x = 0; x < width; x++) {
|
||||
const [b, g, r, a] = pixel(x, y)
|
||||
if (b === AMBER.b && g === AMBER.g && r === AMBER.r && a === 0xff) {
|
||||
amberCount++
|
||||
sumX += x
|
||||
sumY += y
|
||||
}
|
||||
if (a !== 0 && x < width / 2 && y >= height / 2) {
|
||||
paintedInBottomLeft++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expect(amberCount).toBeGreaterThan(0)
|
||||
expect(sumX / amberCount).toBeGreaterThan(width / 2)
|
||||
expect(sumY / amberCount).toBeLessThan(height / 2)
|
||||
expect(paintedInBottomLeft).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('tintTrayTemplateForAttention', () => {
|
||||
it('keeps white edge pixels premultiplied-valid at partial alpha', () => {
|
||||
createFromBitmapMock.mockClear()
|
||||
const base = {
|
||||
getSize: () => ({ width: 1, height: 1 }),
|
||||
toBitmap: () => Buffer.from([0x00, 0x00, 0x00, 0x80])
|
||||
}
|
||||
|
||||
tintTrayTemplateForAttention(base as never, true)
|
||||
|
||||
// Premultiplied alpha requires 0x80 channels for half-covered white, not 0xff.
|
||||
expect(createFromBitmapMock.mock.calls[0][0]).toEqual(Buffer.from([0x80, 0x80, 0x80, 0x80]))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user