mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-08-29 04:26:38 +00:00
test(api): align migrated client contracts
This commit is contained in:
@@ -37,6 +37,11 @@ export type * from './types.ts'
|
||||
|
||||
const settingsNamespaceRequestSchema = z.object({ ns: z.string().min(1) })
|
||||
|
||||
/** Read abort state afresh after an awaited provider or opener call. */
|
||||
function isAborted(signal: AbortSignal): boolean {
|
||||
return signal.aborted
|
||||
}
|
||||
|
||||
/** Native document-opening policy. */
|
||||
export interface Config {
|
||||
/** Override platform desktop-opener detection. */
|
||||
@@ -185,23 +190,23 @@ export class SettingsController extends TypertRemoteService {
|
||||
@Remote
|
||||
async openSettingsDocument(signal: AbortSignal): Promise<SettingsDocumentOpenValue> {
|
||||
const settings = this.provider()
|
||||
if (signal.aborted) throw cancelled('settings document open was aborted')
|
||||
if (isAborted(signal)) throw cancelled('settings document open was aborted')
|
||||
let path: string | undefined
|
||||
try {
|
||||
path = await settings.prepareDocument()
|
||||
} catch (error: unknown) {
|
||||
if (signal.aborted) throw cancelled('settings document preparation was aborted')
|
||||
if (isAborted(signal)) throw cancelled('settings document preparation was aborted')
|
||||
throw internal(`settings document preparation failed: ${messageOf(error)}`)
|
||||
}
|
||||
if (path === undefined) {
|
||||
throw internal('settings provider has no local document to open')
|
||||
}
|
||||
if (signal.aborted) throw cancelled('settings document open was aborted')
|
||||
if (isAborted(signal)) throw cancelled('settings document open was aborted')
|
||||
try {
|
||||
await this.openTextFile(path, signal)
|
||||
return { opened: true }
|
||||
} catch (error: unknown) {
|
||||
if (signal.aborted) throw cancelled('settings document open was aborted')
|
||||
if (isAborted(signal)) throw cancelled('settings document open was aborted')
|
||||
throw internal(`path open failed: ${messageOf(error)}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,13 +263,15 @@ describe('the settings Remote namespace a configuration page calls', () => {
|
||||
|
||||
it('preserves settings-document absence, failure, and cancellation', async () => {
|
||||
const absent = await boot()
|
||||
await expect(absent.controller.openSettingsDocument(new AbortController().signal))
|
||||
.rejects.toMatchObject({ failure: { code: 'internal', message: expect.stringContaining('no local document') } })
|
||||
const missingDocument = absent.controller.openSettingsDocument(new AbortController().signal)
|
||||
await expect(missingDocument).rejects.toMatchObject({ failure: { code: 'internal' } })
|
||||
await expect(missingDocument).rejects.toThrow('no local document')
|
||||
|
||||
const failed = await boot(DocumentSettings)
|
||||
vi.spyOn(failed.ctx.settings, 'prepareDocument').mockRejectedValue(new Error('read failed'))
|
||||
await expect(failed.controller.openSettingsDocument(new AbortController().signal))
|
||||
.rejects.toMatchObject({ failure: { code: 'internal', message: expect.stringContaining('read failed') } })
|
||||
const failedRead = failed.controller.openSettingsDocument(new AbortController().signal)
|
||||
await expect(failedRead).rejects.toMatchObject({ failure: { code: 'internal' } })
|
||||
await expect(failedRead).rejects.toThrow('read failed')
|
||||
|
||||
const cancelled = new AbortController()
|
||||
cancelled.abort(new Error('cancelled'))
|
||||
@@ -412,7 +414,7 @@ describe('the settings Remote namespace a configuration page calls', () => {
|
||||
['unexpected preset failure', 'internal'],
|
||||
] as const)('maps Agent preset resolution failure %#', async (error, code) => {
|
||||
const ctx = new Context()
|
||||
ctx.provide('agentPresets', { resolve: () => Promise.reject(error) } as never)
|
||||
ctx.provide('agentPresets', { resolve: async () => { throw error } } as never)
|
||||
const controller = new SettingsController(ctx)
|
||||
|
||||
await expect(controller.openAgentPresetDirectory('mine', new AbortController().signal))
|
||||
|
||||
Reference in New Issue
Block a user