Files
archy/neode-ui/vite-aiui-native.test.ts

37 lines
1.8 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { execFileSync } from 'node:child_process'
import { nativeSourceMetadata } from './vite-aiui-native'
vi.mock('node:child_process', async importOriginal => {
const actual = await importOriginal<typeof import('node:child_process')>()
const execFileSync = vi.fn()
return { ...actual, execFileSync, default: { ...actual, execFileSync } }
})
beforeEach(() => { vi.clearAllMocks(); vi.stubEnv('ARCHY_SOURCE_REVISION', undefined) })
afterEach(() => vi.unstubAllEnvs())
describe('native AIUI build provenance', () => {
it('builds a container receipt without requiring Git when CI provides the full revision', () => {
const revision = '0123456789abcdef0123456789abcdef01234567'
vi.stubEnv('ARCHY_SOURCE_REVISION', revision)
vi.mocked(execFileSync).mockImplementation(() => { throw new Error('spawnSync git ENOENT') })
expect(nativeSourceMetadata('/archive')).toEqual({ sourceCommit: revision, sourceDirty: false })
expect(execFileSync).not.toHaveBeenCalled()
})
it.each(['', 'main', 'abc123', 'z'.repeat(40)])('rejects an invalid archive revision: %s', revision => {
vi.stubEnv('ARCHY_SOURCE_REVISION', revision)
expect(() => nativeSourceMetadata('/archive')).toThrow('full 40-character')
expect(execFileSync).not.toHaveBeenCalled()
})
it('still reports the actual checkout and dirty state for local previews', () => {
vi.mocked(execFileSync).mockReturnValueOnce('0123456789abcdef0123456789abcdef01234567\n').mockReturnValueOnce(' M src/App.vue\n')
expect(nativeSourceMetadata('/checkout')).toEqual({
sourceCommit: '0123456789abcdef0123456789abcdef01234567', sourceDirty: true,
})
expect(execFileSync).toHaveBeenCalledWith('git', ['-C', '/checkout', 'rev-parse', 'HEAD'], { encoding: 'utf8' })
})
})