Download packages/test-support/client-runtime/src/settings-scope.ts from SaylorTwift/deepseek-harness: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/SaylorTwift/deepseek-harness/resolve/main/packages/test-support/client-runtime/src/settings-scope.ts
- Command line
-
hf download hf://SaylorTwift/deepseek-harness/packages/test-support/client-runtime/src/settings-scope.ts
-
curl -L -o settings-scope.ts https://huggingface.co/SaylorTwift/deepseek-harness/resolve/main/packages/test-support/client-runtime/src/settings-scope.ts
2.05 kB
| /** Test double for the client settings-scope seam. */ | |
| import { vi } from 'vitest' | |
| import type { | |
| SettingsScope, SettingsScopeSnapshot, | |
| } from '@deepseek-ai/dsh-client-ui-settings/client' | |
| /** Handle over one stubbed scope: the scope, its write spy, and publication controls. */ | |
| export interface StubSettingsScope<T> { | |
| /** The scope face handed to the service under test. */ | |
| scope: SettingsScope<T> | |
| /** Spy behind `scope.set`; resolves immediately. */ | |
| set: ReturnType<typeof vi.fn> | |
| /** Spy behind `scope.mutate`; resolves immediately. */ | |
| mutate: ReturnType<typeof vi.fn> | |
| /** Spy behind `scope.unset`; resolves immediately. */ | |
| unset: ReturnType<typeof vi.fn> | |
| /** @returns how many listeners are currently subscribed (disposal assertions). */ | |
| listenerCount(): number | |
| /** | |
| * Replace part of the snapshot and notify subscribers, as a Host | |
| * acceptance would. | |
| * @param next - snapshot fields to replace. | |
| */ | |
| publish(next: Partial<SettingsScopeSnapshot<T>>): void | |
| } | |
| /** | |
| * Build an in-memory settings scope for service specs: starts in the host | |
| * loading state, records writes, and lets the test publish Host acceptances. | |
| * @returns the stub handle. | |
| */ | |
| export function stubSettingsScope<T>(): StubSettingsScope<T> { | |
| let snapshot: SettingsScopeSnapshot<T> = { | |
| status: 'loading', value: undefined, base: undefined, user: undefined, | |
| revision: undefined, writable: false, mode: 'host', | |
| } | |
| const listeners = new Set<() => void>() | |
| const set = vi.fn(() => Promise.resolve()) | |
| const mutate = vi.fn(() => Promise.resolve()) | |
| const unset = vi.fn(() => Promise.resolve()) | |
| return { | |
| scope: { | |
| getSnapshot: () => snapshot, | |
| subscribe: (listener) => { | |
| listeners.add(listener) | |
| return () => { listeners.delete(listener) } | |
| }, | |
| mutate, | |
| set, | |
| unset, | |
| }, | |
| set, | |
| mutate, | |
| unset, | |
| listenerCount: () => listeners.size, | |
| publish: (next) => { | |
| snapshot = { ...snapshot, ...next } | |
| for (const listener of [...listeners]) listener() | |
| }, | |
| } | |
| } | |