Some checks failed
CI / node 22.19 (push) Has been skipped
CI / node 26 (push) Has been skipped
CI / python 3.10 / keyless SDK (push) Has been skipped
CI / python runtime / release-shaped Linux x64 (push) Has been skipped
CI / windows node 24 / wine blocking (push) Has been skipped
CI / wine apt cache (push) Successful in 58s
CI / serial / linux (push) Has been skipped
Deploy documentation / build (push) Failing after 2m46s
Deploy documentation / deploy (push) Has been skipped
E2E (real DeepSeek API) / e2e (push) Failing after 1m18s
Sandbox / sandbox e2e (bwrap, ubuntu-latest) (push) Failing after 1m18s
Landlock Run / Matrix (push) Successful in 13s
Release (vendor) / Pack npm tarballs (push) Failing after 3m43s
Release (dsh) / Pack npm tarballs (push) Failing after 1m53s
Sandbox / sandbox e2e (landlock, ubuntu-24.04) (push) Failing after 1m51s
Release (vendor) / Publish to npm (push) Has been skipped
Release (dsh) / Publish to npm (push) Has been skipped
CI / node 24 / static (push) Has been cancelled
CI / node 24 / coverage (push) Has been cancelled
CI / node 24 / snapshots and artifacts (push) Has been cancelled
CI / windows node 24 / native complete (push) Has been cancelled
CI / serial / linux (self-hosted standby) (push) Has been cancelled
CI / serial / macos (push) Has been cancelled
CI / serial / windows (self-hosted standby) (push) Has been cancelled
CI / larger-runner-benchmark (16, linux, dsh-ubuntu-24-04-16core, typecheck) (push) Has been cancelled
CI / larger-runner-benchmark (16, windows, dsh-windows-2025-16core, production-site) (push) Has been cancelled
CI / larger-runner-benchmark (32, linux, dsh-ubuntu-24-04-32core, typecheck) (push) Has been cancelled
CI / larger-runner-benchmark (32, windows, dsh-windows-2025-32core, production-site) (push) Has been cancelled
CI / larger-runner-benchmark (4, linux, dsh-ubuntu-24-04-4core, typecheck) (push) Has been cancelled
CI / larger-runner-benchmark (4, windows, dsh-windows-2025-4core, production-site) (push) Has been cancelled
CI / larger-runner-benchmark (64, linux, dsh-ubuntu-24-04-64core, typecheck) (push) Has been cancelled
CI / larger-runner-benchmark (64, windows, dsh-windows-2025-64core, production-site) (push) Has been cancelled
CI / larger-runner-benchmark (8, linux, dsh-ubuntu-24-04-8core, typecheck) (push) Has been cancelled
CI / larger-runner-benchmark (8, windows, dsh-windows-2025-8core, production-site) (push) Has been cancelled
CI / larger-runner-benchmark (96, linux, dsh-ubuntu-24-04-96core, typecheck) (push) Has been cancelled
CI / larger-runner-benchmark (96, windows, dsh-windows-2025-96core, production-site) (push) Has been cancelled
CI / consolidated-runner-benchmark (16, linux, dsh-ubuntu-24-04-16core, 16) (push) Has been cancelled
CI / consolidated-runner-benchmark (16, windows, dsh-windows-2025-16core, 2) (push) Has been cancelled
CI / consolidated-runner-benchmark (32, linux, dsh-ubuntu-24-04-32core, 32) (push) Has been cancelled
CI / consolidated-runner-benchmark (32, windows, dsh-windows-2025-32core, 2) (push) Has been cancelled
CI / consolidated-runner-benchmark (4, linux, dsh-ubuntu-24-04-4core, 4) (push) Has been cancelled
CI / consolidated-runner-benchmark (4, windows, dsh-windows-2025-4core, 2) (push) Has been cancelled
CI / consolidated-runner-benchmark (64, linux, dsh-ubuntu-24-04-64core, 32) (push) Has been cancelled
CI / consolidated-runner-benchmark (64, windows, dsh-windows-2025-64core, 2) (push) Has been cancelled
CI / consolidated-runner-benchmark (8, linux, dsh-ubuntu-24-04-8core, 8) (push) Has been cancelled
CI / consolidated-runner-benchmark (8, windows, dsh-windows-2025-8core, 2) (push) Has been cancelled
CI / consolidated-runner-benchmark (96, linux, dsh-ubuntu-24-04-96core, 32) (push) Has been cancelled
CI / consolidated-runner-benchmark (96, windows, dsh-windows-2025-96core, 2) (push) Has been cancelled
CI / all checks passed (push) Has been cancelled
Sandbox / sandbox e2e (seatbelt, macos-latest) (push) Has been cancelled
Sandbox / sandbox e2e (landlock, ubuntu-24.04-arm) (push) Has been cancelled
Landlock Run / ${{ matrix.platform }} (push) Has been cancelled
Landlock Run / darwin (no platform package — degradation proof) (push) Has been cancelled
120 lines
4.3 KiB
TypeScript
120 lines
4.3 KiB
TypeScript
/** The `web-search-searxng` settings section layered over the composition entry. */
|
|
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { Context } from '@deepseek-ai/cordis'
|
|
import type { Fiber } from '@deepseek-ai/cordis'
|
|
import { SettingsProvider } from '@deepseek-ai/dsh-settings'
|
|
import type { SettingsNamespace } from '@deepseek-ai/dsh-settings'
|
|
import WebRuntime from '@deepseek-ai/dsh-web'
|
|
import * as searxngPlugin from '@deepseek-ai/dsh-web-search-searxng'
|
|
import { SEARXNG_SETTINGS_NAMESPACE } from '@deepseek-ai/dsh-web-search-searxng'
|
|
|
|
/** The smallest real provider: one in-memory document, always writable. */
|
|
class MemorySettings extends SettingsProvider {
|
|
doc: Record<string, unknown> = {}
|
|
|
|
get writable(): boolean {
|
|
return true
|
|
}
|
|
|
|
protected load(): Promise<Record<string, unknown>> {
|
|
return Promise.resolve(structuredClone(this.doc))
|
|
}
|
|
|
|
protected persist(ns: SettingsNamespace, section: Record<string, unknown>): Promise<void> {
|
|
this.doc = { ...this.doc, [ns]: structuredClone(section) }
|
|
return Promise.resolve()
|
|
}
|
|
}
|
|
|
|
function jsonResponse(body: unknown): Response {
|
|
return new Response(JSON.stringify(body), {
|
|
status: 200,
|
|
headers: { 'content-type': 'application/json' },
|
|
})
|
|
}
|
|
|
|
/** The smallest SearXNG-shaped answer the provider accepts — enough to observe the request. */
|
|
const ONE_RESULT = {
|
|
results: [{ url: 'https://a.test', title: 'A', content: 'snip' }],
|
|
}
|
|
|
|
async function boot(): Promise<{ ctx: Context; settingsFiber: Fiber; pluginFiber: Fiber }> {
|
|
const ctx = new Context()
|
|
await ctx.plugin(WebRuntime, {})
|
|
const settingsFiber = ctx.plugin(MemorySettings)
|
|
await settingsFiber.await()
|
|
const pluginFiber = ctx.plugin(searxngPlugin, { baseURL: 'https://search.entry.test' })
|
|
await pluginFiber.await()
|
|
return { ctx, settingsFiber, pluginFiber }
|
|
}
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
/**
|
|
* Run one search and answer the endpoint it reached. A fresh `Response` per
|
|
* call because a body can only be read once, and the call history is cleared
|
|
* because repeated `spyOn` returns the same spy.
|
|
* @param ctx - context whose `ctx.web` serves the search.
|
|
* @returns the URL the provider fetched.
|
|
*/
|
|
async function searchOnce(ctx: Context): Promise<string> {
|
|
const fetchSpy = vi.spyOn(globalThis, 'fetch')
|
|
.mockImplementation(() => Promise.resolve(jsonResponse(ONE_RESULT)))
|
|
fetchSpy.mockClear()
|
|
await ctx.web.search({ query: 'anything' })
|
|
return String((fetchSpy.mock.calls.at(-1)?.[0] as URL | string | undefined) ?? '')
|
|
}
|
|
|
|
describe('web-search-searxng settings section', () => {
|
|
it('serves a stored endpoint to the next search without re-registering the provider', async () => {
|
|
const bench = await boot()
|
|
expect(await searchOnce(bench.ctx)).toContain('https://search.entry.test')
|
|
|
|
await bench.ctx.settings.update(SEARXNG_SETTINGS_NAMESPACE, {
|
|
baseURL: 'https://search.stored.test',
|
|
})
|
|
|
|
expect(await searchOnce(bench.ctx)).toContain('https://search.stored.test')
|
|
await bench.ctx.fiber.dispose()
|
|
})
|
|
|
|
it('applies a stored language and time range to the next request', async () => {
|
|
const bench = await boot()
|
|
await bench.ctx.settings.update(SEARXNG_SETTINGS_NAMESPACE, {
|
|
baseURL: 'https://search.entry.test',
|
|
language: 'de',
|
|
timeRange: 'week',
|
|
})
|
|
|
|
const url = new URL(await searchOnce(bench.ctx))
|
|
expect(url.searchParams.get('language')).toBe('de')
|
|
expect(url.searchParams.get('time_range')).toBe('week')
|
|
await bench.ctx.fiber.dispose()
|
|
})
|
|
|
|
it('falls back to the composition entry when the settings provider detaches', async () => {
|
|
const bench = await boot()
|
|
await bench.ctx.settings.update(SEARXNG_SETTINGS_NAMESPACE, {
|
|
baseURL: 'https://search.stored.test',
|
|
})
|
|
expect(await searchOnce(bench.ctx)).toContain('https://search.stored.test')
|
|
|
|
await bench.settingsFiber.dispose()
|
|
|
|
expect(await searchOnce(bench.ctx)).toContain('https://search.entry.test')
|
|
await bench.ctx.fiber.dispose()
|
|
})
|
|
|
|
it('releases the namespace when the plugin unloads', async () => {
|
|
const bench = await boot()
|
|
expect(bench.ctx.settings.describe().map(row => String(row.ns))).toContain('web-search-searxng')
|
|
|
|
await bench.pluginFiber.dispose()
|
|
|
|
expect(bench.ctx.settings.describe().map(row => String(row.ns))).not.toContain('web-search-searxng')
|
|
await bench.ctx.fiber.dispose()
|
|
})
|
|
}) |