mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-09-09 04:02:35 +00:00
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import type { Context } from '@deepseek-ai/cordis'
|
|
import type { CredentialProvider, CredentialRecord } from '@deepseek-ai/dsh-credentials'
|
|
|
|
/** Mutable credential-record double for Connection authentication tests. */
|
|
export class RecordCredentials {
|
|
record: CredentialRecord | undefined
|
|
discardWrites = false
|
|
reads = 0
|
|
modifies = 0
|
|
|
|
readRecord(): Promise<CredentialRecord | undefined> {
|
|
this.reads += 1
|
|
return Promise.resolve(this.record)
|
|
}
|
|
|
|
async modifyRecord(
|
|
_key: unknown,
|
|
mutate: (current: CredentialRecord | undefined) => Promise<CredentialRecord | undefined>,
|
|
): Promise<CredentialRecord | undefined> {
|
|
this.modifies += 1
|
|
const next = await mutate(this.record)
|
|
if (this.discardWrites) return undefined
|
|
if (next !== undefined) this.record = next
|
|
return this.record
|
|
}
|
|
|
|
deleteRecord(): Promise<void> {
|
|
this.record = undefined
|
|
return Promise.resolve()
|
|
}
|
|
}
|
|
|
|
/** Provide the record operations Connection needs during authentication setup. */
|
|
export function provideBrowserCredentials(ctx: Context): void {
|
|
ctx.provide('credentials', new RecordCredentials() as unknown as CredentialProvider)
|
|
}
|