mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
test: prune low-value theme and icon artifact samples
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
isPlausiblePluginIconSvg,
|
||||
isPluginIconThemeRegistration,
|
||||
parsePluginIconThemeArtifact
|
||||
} from './plugin-icon-theme-artifact'
|
||||
@@ -16,28 +15,6 @@ describe('plugin icon theme artifacts', () => {
|
||||
parse({ schemaVersion: 1, folderNames, folderNamesExpanded: folderNames })
|
||||
).toThrow(/mappings/)
|
||||
})
|
||||
|
||||
it.each([
|
||||
['a case-only duplicate', { schemaVersion: 1, fileExtensions: { ts: 'a.svg', TS: 'b.svg' } }],
|
||||
['an unknown slot', { schemaVersion: 1, icons: { 'sidebar.search': 'a.svg' } }],
|
||||
['a path in a file name', { schemaVersion: 1, fileNames: { 'a/b': 'a.svg' } }],
|
||||
['a path in a folder name', { schemaVersion: 1, folderNames: { 'a\\b': 'a.svg' } }],
|
||||
[
|
||||
'a case-only duplicate folder',
|
||||
{ schemaVersion: 1, folderNamesExpanded: { src: 'a.svg', Src: 'b.svg' } }
|
||||
],
|
||||
['an escaping icon path', { schemaVersion: 1, icons: { file: '../a.svg' } }]
|
||||
])('rejects %s', (_label, value) => {
|
||||
expect(() => parse(value)).toThrow()
|
||||
})
|
||||
|
||||
it('skips unknown slots at runtime', () => {
|
||||
expect(
|
||||
parsePluginIconThemeArtifact(
|
||||
JSON.stringify({ schemaVersion: 1, icons: { file: 'f.svg', 'sidebar.search': 'a.svg' } })
|
||||
).icons
|
||||
).toEqual({ file: 'f.svg' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('plugin icon theme artifact prototype keys', () => {
|
||||
@@ -81,14 +58,6 @@ describe('isPluginIconThemeRegistration', () => {
|
||||
folderNamesExpanded: {}
|
||||
}
|
||||
|
||||
it.each([
|
||||
['an index past the SVG list', { constructor: 1 }],
|
||||
['a negative index', { constructor: -1 }],
|
||||
['a fractional index', { constructor: 0.5 }]
|
||||
])('rejects %s', (_label, fileNames) => {
|
||||
expect(isPluginIconThemeRegistration({ ...base, fileNames })).toBe(false)
|
||||
})
|
||||
|
||||
it('checks the range of an own __proto__ index too', () => {
|
||||
const fileNames = JSON.parse('{"__proto__":5}')
|
||||
expect(isPluginIconThemeRegistration({ ...base, fileNames })).toBe(false)
|
||||
@@ -96,22 +65,4 @@ describe('isPluginIconThemeRegistration', () => {
|
||||
isPluginIconThemeRegistration({ ...base, fileNames: JSON.parse('{"__proto__":0}') })
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('checks folder indexes too', () => {
|
||||
expect(
|
||||
isPluginIconThemeRegistration({ ...base, fileNames: {}, folderNamesExpanded: { src: 1 } })
|
||||
).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isPlausiblePluginIconSvg', () => {
|
||||
it.each([
|
||||
['an SVG', '<svg viewBox="0 0 1 1"/>', true],
|
||||
['an XML declaration and comment first', '<?xml version="1.0"?><!-- c --><svg/>', true],
|
||||
['a DOCTYPE', '<!DOCTYPE svg><svg/>', false],
|
||||
['an entity declaration', '<svg><!ENTITY x "y"></svg>', false],
|
||||
['HTML', '<html></html>', false]
|
||||
])('accepts %s: %s', (_label, svg, expected) => {
|
||||
expect(isPlausiblePluginIconSvg(svg)).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,39 +1,10 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parsePluginAppThemeArtifact } from './plugin-theme-artifact'
|
||||
import { parsePluginTerminalThemeArtifact } from './plugin-terminal-theme-artifact'
|
||||
|
||||
const parseApp = (value: unknown) => () =>
|
||||
parsePluginAppThemeArtifact(JSON.stringify(value), 'strict')
|
||||
|
||||
describe('plugin app theme artifacts', () => {
|
||||
it.each([
|
||||
['a private token', { base: 'dark', tokens: { '--internal-gap': '#000' } }],
|
||||
['a URL', { base: 'dark', tokens: { '--background': 'url(x)' } }],
|
||||
['a var() chain', { base: 'dark', tokens: { '--background': 'var(--a)' } }],
|
||||
['declaration syntax', { base: 'dark', tokens: { '--background': '#000; color: red' } }],
|
||||
['no tokens', { base: 'dark', tokens: {} }],
|
||||
[
|
||||
'transparent',
|
||||
{ base: 'dark', tokens: { '--background': 'transparent', '--foreground': '#fff' } }
|
||||
],
|
||||
['an unknown key', { base: 'dark', tokens: { '--border': '#000' }, extra: 1 }]
|
||||
])('rejects %s', (_label, value) => {
|
||||
expect(parseApp(value)).toThrow()
|
||||
})
|
||||
|
||||
it('skips unknown tokens and keys at runtime so newer themes still load', () => {
|
||||
const theme = parsePluginAppThemeArtifact(
|
||||
JSON.stringify({
|
||||
schemaVersion: 1,
|
||||
base: 'dark',
|
||||
tokens: { '--background': '#000', '--foreground': '#fff', '--future': '#123' },
|
||||
future: true
|
||||
})
|
||||
)
|
||||
expect(theme.tokens).not.toHaveProperty('--future')
|
||||
expect(parseApp({ schemaVersion: 2, base: 'dark', tokens: {} })).toThrow()
|
||||
})
|
||||
|
||||
it('reads a background image, strict for authors and never fatal at runtime', () => {
|
||||
const base = { base: 'dark', tokens: { '--background': '#000', '--foreground': '#fff' } }
|
||||
const background = { path: 'images/dusk.webp', opacity: 0.35, size: 'tile' }
|
||||
@@ -73,28 +44,3 @@ describe('plugin app theme artifacts', () => {
|
||||
).toEqual([{ scope: ['keyword'], settings: { foreground: '#ff79c6' } }])
|
||||
})
|
||||
})
|
||||
|
||||
describe('plugin terminal theme artifacts', () => {
|
||||
const terminal = { background: '#000000', foreground: '#ffffff', green: '#00ff00' }
|
||||
|
||||
it('skips unknown slots at runtime', () => {
|
||||
expect(
|
||||
parsePluginTerminalThemeArtifact(
|
||||
JSON.stringify({ schemaVersion: 1, terminal: { ...terminal, glow: '#000000' } })
|
||||
)
|
||||
).toEqual({ mode: 'unknown', terminal })
|
||||
})
|
||||
|
||||
it.each([
|
||||
['an unknown slot', { ...terminal, glow: '#000000' }],
|
||||
['an invalid color', { ...terminal, red: 'red; x' }],
|
||||
['no ANSI color', { background: '#000000', foreground: '#ffffff' }]
|
||||
])('rejects %s', (_label, colors) => {
|
||||
expect(() =>
|
||||
parsePluginTerminalThemeArtifact(
|
||||
JSON.stringify({ schemaVersion: 1, terminal: colors }),
|
||||
'strict'
|
||||
)
|
||||
).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user