mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 00:02:31 +00:00
* add safe fork upstream sync setting * fix fork sync review feedback * Review safe fork sync setting * Fix local preflight env typing * Fix onboarding flow SSR test tooltip provider --------- Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
91 lines
2.9 KiB
TypeScript
91 lines
2.9 KiB
TypeScript
/**
|
|
* Shared test utilities for git-handler tests.
|
|
*
|
|
* Why: oxlint max-lines (300) requires splitting large test suites.
|
|
* This module exports the mock dispatcher factory and git helpers
|
|
* so multiple test files can reuse them without duplication.
|
|
*/
|
|
import { vi } from 'vitest'
|
|
import { execFileSync } from 'child_process'
|
|
import type { RelayDispatcher } from './dispatcher'
|
|
|
|
// Why: declare an explicit type so the inferred return type of
|
|
// createMockDispatcher doesn't transitively reference `@vitest/spy`'s
|
|
// internal `Procedure` type (from `vi.fn(...)`). Without this annotation,
|
|
// TS2883 fires under `pnpm run tc:node` because the generated .d.ts would
|
|
// need to name a type that isn't portably resolvable from this module.
|
|
export type MockDispatcher = {
|
|
onRequest: (
|
|
method: string,
|
|
handler: (
|
|
params: Record<string, unknown>,
|
|
context: { isStale: () => boolean; signal?: AbortSignal }
|
|
) => Promise<unknown>
|
|
) => void
|
|
onNotification: (method: string, handler: (params: Record<string, unknown>) => void) => void
|
|
notify: (method: string, params?: Record<string, unknown>) => void
|
|
_requestHandlers: Map<
|
|
string,
|
|
(
|
|
params: Record<string, unknown>,
|
|
context: { isStale: () => boolean; signal?: AbortSignal }
|
|
) => Promise<unknown>
|
|
>
|
|
callRequest(
|
|
method: string,
|
|
params?: Record<string, unknown>,
|
|
context?: { isStale: () => boolean; signal?: AbortSignal }
|
|
): Promise<unknown>
|
|
}
|
|
|
|
export function createMockDispatcher(): MockDispatcher {
|
|
const requestHandlers = new Map<
|
|
string,
|
|
(
|
|
params: Record<string, unknown>,
|
|
context: { isStale: () => boolean; signal?: AbortSignal }
|
|
) => Promise<unknown>
|
|
>()
|
|
|
|
return {
|
|
onRequest: vi.fn(
|
|
(
|
|
method: string,
|
|
handler: (
|
|
params: Record<string, unknown>,
|
|
context: { isStale: () => boolean; signal?: AbortSignal }
|
|
) => Promise<unknown>
|
|
) => {
|
|
requestHandlers.set(method, handler)
|
|
}
|
|
),
|
|
onNotification: vi.fn(),
|
|
notify: vi.fn(),
|
|
_requestHandlers: requestHandlers,
|
|
async callRequest(
|
|
method: string,
|
|
params: Record<string, unknown> = {},
|
|
context: { isStale: () => boolean; signal?: AbortSignal } = { isStale: () => false }
|
|
) {
|
|
const handler = requestHandlers.get(method)
|
|
if (!handler) {
|
|
throw new Error(`No handler for ${method}`)
|
|
}
|
|
return handler(params, context)
|
|
}
|
|
}
|
|
}
|
|
|
|
export function gitInit(dir: string): void {
|
|
execFileSync('git', ['init'], { cwd: dir, stdio: 'pipe' })
|
|
execFileSync('git', ['config', 'user.email', 'test@test.com'], { cwd: dir, stdio: 'pipe' })
|
|
execFileSync('git', ['config', 'user.name', 'Test'], { cwd: dir, stdio: 'pipe' })
|
|
}
|
|
|
|
export function gitCommit(dir: string, message: string): void {
|
|
execFileSync('git', ['add', '.'], { cwd: dir, stdio: 'pipe' })
|
|
execFileSync('git', ['commit', '-m', message, '--allow-empty'], { cwd: dir, stdio: 'pipe' })
|
|
}
|
|
|
|
export type { RelayDispatcher }
|