test: consolidate UUID coverage and verify input boundaries (#33073)

* test: consolidate UUID coverage and exercise dotfile boundaries

* test: verify skill selector boundary and describe actual fixtures

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-10-24 00:28:32 -07:00
committed by GitHub
co-authored by OrcaWin
parent 6059a5f7fa
commit fe3cb24a04
5 changed files with 28 additions and 39 deletions
-29
View File
@@ -1,29 +0,0 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { createBrowserUuid } from './browser-uuid'
describe('createBrowserUuid', () => {
afterEach(() => {
vi.unstubAllGlobals()
})
it('uses native randomUUID when it is available', () => {
vi.stubGlobal('crypto', {
randomUUID: () => 'native-id'
})
expect(createBrowserUuid()).toBe('native-id')
})
it('falls back to getRandomValues when randomUUID is unavailable', () => {
vi.stubGlobal('crypto', {
getRandomValues: (bytes: Uint8Array) => {
for (let index = 0; index < bytes.length; index += 1) {
bytes[index] = index
}
return bytes
}
})
expect(createBrowserUuid()).toBe('00010203-0405-4607-8809-0a0b0c0d0e0f')
})
})
@@ -13,6 +13,12 @@ describe('agent skill sharing contract', () => {
})
it('rejects arbitrary source paths and more than 512 explicit selectors', () => {
expect(
AgentSkillShareRequestSchema.parse({
skillSelectors: Array.from({ length: 512 }, (_, index) => `skill-${index}`),
bundleName: 'team-skills'
}).skillSelectors
).toHaveLength(512)
expect(
AgentSkillShareRequestSchema.safeParse({
skillSelectors: ['alpha'],
+2 -2
View File
@@ -14,8 +14,8 @@ describe('hasBinaryFileExtension', () => {
it('rejects text files, dotfiles, and extensionless paths', () => {
expect(hasBinaryFileExtension('src/index.ts')).toBe(false)
expect(hasBinaryFileExtension('.gitignore')).toBe(false)
expect(hasBinaryFileExtension('scripts/.eslintrc')).toBe(false)
expect(hasBinaryFileExtension('.png')).toBe(false)
expect(hasBinaryFileExtension('scripts/.png')).toBe(false)
expect(hasBinaryFileExtension('Makefile')).toBe(false)
expect(hasBinaryFileExtension(undefined)).toBe(false)
})
+1 -1
View File
@@ -26,7 +26,7 @@ describe('collapseHomePath', () => {
})
describe('bundledSkillLocation', () => {
it('names the shared folder and agent folders, and tells a kept link from a kept copy', () => {
it('describes shared updates, kept agent links, and edited locations', () => {
expect(bundledSkillLocation(op({ kind: 'update' }), '/home/u')).toMatchObject({
displayPath: '~/.agents/skills/orca-cli',
place: { kind: 'shared' },
+19 -7
View File
@@ -1,25 +1,37 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { createUuidV4 } from './uuid-v4'
const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/
describe('createUuidV4', () => {
afterEach(() => vi.unstubAllGlobals())
afterEach(() => {
vi.unstubAllGlobals()
vi.restoreAllMocks()
})
it('uses the browser crypto fallback when randomUUID is unavailable', () => {
it('uses native randomUUID when it is available', () => {
vi.stubGlobal('crypto', {
randomUUID: () => 'native-id'
})
expect(createUuidV4()).toBe('native-id')
})
it('falls back to getRandomValues when randomUUID is unavailable', () => {
vi.stubGlobal('crypto', {
getRandomValues: (bytes: Uint8Array) => {
bytes.fill(0xab)
for (let index = 0; index < bytes.length; index += 1) {
bytes[index] = index
}
return bytes
}
})
expect(createUuidV4()).toMatch(UUID_V4)
expect(createUuidV4()).toBe('00010203-0405-4607-8809-0a0b0c0d0e0f')
})
it('still returns a UUID when Web Crypto is unavailable', () => {
vi.stubGlobal('crypto', undefined)
vi.spyOn(Math, 'random').mockReturnValue(255 / 256)
expect(createUuidV4()).toMatch(UUID_V4)
expect(createUuidV4()).toBe('ffffffff-ffff-4fff-bfff-ffffffffffff')
})
})