chore: migrate tests from tests-ui/ to colocate with source files (#7811)

## Summary

Migrates all unit tests from `tests-ui/` to colocate with their source
files in `src/`, improving discoverability and maintainability.

## Changes

- **What**: Relocated all unit tests to be adjacent to the code they
test, following the `<source>.test.ts` naming convention
- **Config**: Updated `vitest.config.ts` to remove `tests-ui` include
pattern and `@tests-ui` alias
- **Docs**: Moved testing documentation to `docs/testing/` with updated
paths and patterns

## Review Focus

- Migration patterns documented in
`temp/plans/migrate-tests-ui-to-src.md`
- Tests use `@/` path aliases instead of relative imports
- Shared fixtures placed in `__fixtures__/` directories

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-7811-chore-migrate-tests-from-tests-ui-to-colocate-with-source-files-2da6d73d36508147a4cce85365dee614)
by [Unito](https://www.unito.io)

---------

Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Alexander Brown
2026-01-05 16:32:24 -08:00
committed by GitHub
parent 832588c7a9
commit 10feb1fd5b
272 changed files with 483 additions and 1239 deletions

View File

@@ -0,0 +1,207 @@
import { describe, expect, it } from 'vitest'
import type { NodeId } from '@/platform/workflow/validation/schemas/workflowSchema'
import {
createNodeExecutionId,
createNodeLocatorId,
isNodeExecutionId,
isNodeLocatorId,
parseNodeExecutionId,
parseNodeLocatorId
} from '@/types/nodeIdentification'
import type { NodeLocatorId } from '@/types/nodeIdentification'
describe('nodeIdentification', () => {
describe('NodeLocatorId', () => {
const validUuid = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'
const validNodeId = '123'
const validNodeLocatorId = `${validUuid}:${validNodeId}` as NodeLocatorId
describe('isNodeLocatorId', () => {
it('should return true for valid NodeLocatorId', () => {
expect(isNodeLocatorId(validNodeLocatorId)).toBe(true)
expect(isNodeLocatorId(`${validUuid}:456`)).toBe(true)
expect(isNodeLocatorId(`${validUuid}:node_1`)).toBe(true)
// Simple node IDs (root graph)
expect(isNodeLocatorId('123')).toBe(true)
expect(isNodeLocatorId('node_1')).toBe(true)
expect(isNodeLocatorId('5')).toBe(true)
})
it('should return false for invalid formats', () => {
expect(isNodeLocatorId('123:456')).toBe(false) // No UUID in first part
expect(isNodeLocatorId('not-a-uuid:123')).toBe(false)
expect(isNodeLocatorId('')).toBe(false) // Empty string
expect(isNodeLocatorId(':123')).toBe(false) // Empty UUID
expect(isNodeLocatorId(`${validUuid}:`)).toBe(false) // Empty node ID
expect(isNodeLocatorId(`${validUuid}:123:456`)).toBe(false) // Too many parts
expect(isNodeLocatorId(123)).toBe(false) // Not a string
expect(isNodeLocatorId(null)).toBe(false)
expect(isNodeLocatorId(undefined)).toBe(false)
})
it('should validate UUID format correctly', () => {
// Valid UUID formats
expect(
isNodeLocatorId('00000000-0000-0000-0000-000000000000:123')
).toBe(true)
expect(
isNodeLocatorId('A1B2C3D4-E5F6-7890-ABCD-EF1234567890:123')
).toBe(true)
// Invalid UUID formats
expect(isNodeLocatorId('00000000-0000-0000-0000-00000000000:123')).toBe(
false
) // Too short
expect(
isNodeLocatorId('00000000-0000-0000-0000-0000000000000:123')
).toBe(false) // Too long
expect(
isNodeLocatorId('00000000_0000_0000_0000_000000000000:123')
).toBe(false) // Wrong separator
expect(
isNodeLocatorId('g0000000-0000-0000-0000-000000000000:123')
).toBe(false) // Invalid hex
})
})
describe('parseNodeLocatorId', () => {
it('should parse valid NodeLocatorId', () => {
const result = parseNodeLocatorId(validNodeLocatorId)
expect(result).toEqual({
subgraphUuid: validUuid,
localNodeId: 123
})
})
it('should handle string node IDs', () => {
const stringNodeId = `${validUuid}:node_1`
const result = parseNodeLocatorId(stringNodeId)
expect(result).toEqual({
subgraphUuid: validUuid,
localNodeId: 'node_1'
})
})
it('should handle simple node IDs (root graph)', () => {
const result = parseNodeLocatorId('123')
expect(result).toEqual({
subgraphUuid: null,
localNodeId: 123
})
const stringResult = parseNodeLocatorId('node_1')
expect(stringResult).toEqual({
subgraphUuid: null,
localNodeId: 'node_1'
})
})
it('should return null for invalid formats', () => {
expect(parseNodeLocatorId('123:456')).toBeNull() // No UUID in first part
expect(parseNodeLocatorId('')).toBeNull()
})
})
describe('createNodeLocatorId', () => {
it('should create NodeLocatorId from components', () => {
const result = createNodeLocatorId(validUuid, 123)
expect(result).toBe(validNodeLocatorId)
expect(isNodeLocatorId(result)).toBe(true)
})
it('should handle string node IDs', () => {
const result = createNodeLocatorId(validUuid, 'node_1')
expect(result).toBe(`${validUuid}:node_1`)
expect(isNodeLocatorId(result)).toBe(true)
})
})
})
describe('NodeExecutionId', () => {
describe('isNodeExecutionId', () => {
it('should return true for execution IDs', () => {
expect(isNodeExecutionId('123:456')).toBe(true)
expect(isNodeExecutionId('123:456:789')).toBe(true)
expect(isNodeExecutionId('node_1:node_2')).toBe(true)
})
it('should return false for non-execution IDs', () => {
expect(isNodeExecutionId('123')).toBe(false)
expect(isNodeExecutionId('node_1')).toBe(false)
expect(isNodeExecutionId('')).toBe(false)
expect(isNodeExecutionId(123)).toBe(false)
expect(isNodeExecutionId(null)).toBe(false)
expect(isNodeExecutionId(undefined)).toBe(false)
})
})
describe('parseNodeExecutionId', () => {
it('should parse execution IDs correctly', () => {
expect(parseNodeExecutionId('123:456')).toEqual([123, 456])
expect(parseNodeExecutionId('123:456:789')).toEqual([123, 456, 789])
expect(parseNodeExecutionId('node_1:node_2')).toEqual([
'node_1',
'node_2'
])
expect(parseNodeExecutionId('123:node_2:456')).toEqual([
123,
'node_2',
456
])
})
it('should return null for non-execution IDs', () => {
expect(parseNodeExecutionId('123')).toBeNull()
expect(parseNodeExecutionId('')).toBeNull()
})
})
describe('createNodeExecutionId', () => {
it('should create execution IDs from node arrays', () => {
expect(createNodeExecutionId([123, 456])).toBe('123:456')
expect(createNodeExecutionId([123, 456, 789])).toBe('123:456:789')
expect(createNodeExecutionId(['node_1', 'node_2'])).toBe(
'node_1:node_2'
)
expect(createNodeExecutionId([123, 'node_2', 456])).toBe(
'123:node_2:456'
)
})
it('should handle single node ID', () => {
const result = createNodeExecutionId([123])
expect(result).toBe('123')
// Single node IDs are not execution IDs
expect(isNodeExecutionId(result)).toBe(false)
})
it('should handle empty array', () => {
expect(createNodeExecutionId([])).toBe('')
})
})
})
describe('Integration tests', () => {
it('should round-trip NodeLocatorId correctly', () => {
const uuid = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'
const nodeId: NodeId = 123
const locatorId = createNodeLocatorId(uuid, nodeId)
const parsed = parseNodeLocatorId(locatorId)
expect(parsed).toBeTruthy()
expect(parsed!.subgraphUuid).toBe(uuid)
expect(parsed!.localNodeId).toBe(nodeId)
})
it('should round-trip NodeExecutionId correctly', () => {
const nodeIds: NodeId[] = [123, 'node_2', 456]
const executionId = createNodeExecutionId(nodeIds)
const parsed = parseNodeExecutionId(executionId)
expect(parsed).toEqual(nodeIds)
})
})
})

View File

@@ -0,0 +1,75 @@
import { describe, expect, it } from 'vitest'
import { NodeSourceType, getNodeSource } from '@/types/nodeSource'
describe('getNodeSource', () => {
it('should return UNKNOWN_NODE_SOURCE when python_module is undefined', () => {
const result = getNodeSource(undefined)
expect(result).toEqual({
type: NodeSourceType.Unknown,
className: 'comfy-unknown',
displayText: 'Unknown',
badgeText: '?'
})
})
it('should identify core nodes from nodes module', () => {
const result = getNodeSource('nodes.some_module')
expect(result).toEqual({
type: NodeSourceType.Core,
className: 'comfy-core',
displayText: 'Comfy Core',
badgeText: '🦊'
})
})
it('should identify core nodes from comfy_extras module', () => {
const result = getNodeSource('comfy_extras.some_module')
expect(result).toEqual({
type: NodeSourceType.Core,
className: 'comfy-core',
displayText: 'Comfy Core',
badgeText: '🦊'
})
})
it('should identify core nodes from comfy_api_nodes module', () => {
const result = getNodeSource('comfy_api_nodes.some_module')
expect(result).toEqual({
type: NodeSourceType.Core,
className: 'comfy-core',
displayText: 'Comfy Core',
badgeText: '🦊'
})
})
it('should identify custom nodes and format their names', () => {
const result = getNodeSource('custom_nodes.ComfyUI-Example')
expect(result).toEqual({
type: NodeSourceType.CustomNodes,
className: 'comfy-custom-nodes',
displayText: 'Example',
badgeText: 'Example'
})
})
it('should identify custom nodes with version and format their names', () => {
const result = getNodeSource('custom_nodes.ComfyUI-Example@1.0.0')
expect(result).toEqual({
type: NodeSourceType.CustomNodes,
className: 'comfy-custom-nodes',
displayText: 'Example',
badgeText: 'Example'
})
})
it('should return UNKNOWN_NODE_SOURCE for unrecognized modules', () => {
const result = getNodeSource('unknown_module.something')
expect(result).toEqual({
type: NodeSourceType.Unknown,
className: 'comfy-unknown',
displayText: 'Unknown',
badgeText: '?'
})
})
})