fix(gui): harden multimodal image attachments
This commit is contained in:
@@ -8,6 +8,13 @@
|
||||
import { expect } from 'vitest'
|
||||
import { RegistryService } from 'cordis'
|
||||
import type { Context, Plugin } from 'cordis'
|
||||
import { AttachmentStore } from '@deepseek-ai/dsh-attachment'
|
||||
import type {
|
||||
ImageAttachmentLimits,
|
||||
ImageAttachmentRef,
|
||||
SaveImageAttachment,
|
||||
StoredImageAttachment,
|
||||
} from '@deepseek-ai/dsh-attachment'
|
||||
import InvariantService from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
declare global {
|
||||
@@ -78,6 +85,25 @@ export function usesManualInvariantTree(testPath: string): boolean {
|
||||
}
|
||||
|
||||
const ALL_COMPANION_TESTS = ['/scripts/test-invariants.spec.ts'] as const
|
||||
const ATTACHMENT_COMPANION = '../packages/attachment/attachment-local/src/invariant.ts'
|
||||
|
||||
class TestAttachmentStore extends AttachmentStore {
|
||||
readonly imageLimits: ImageAttachmentLimits = {
|
||||
maxImageBytes: 1,
|
||||
maxImagesPerMessage: 1,
|
||||
maxMessageImageBytes: 1,
|
||||
maxImagePixels: 1,
|
||||
mediaTypes: ['image/png'],
|
||||
}
|
||||
|
||||
saveImage(_input: SaveImageAttachment): Promise<ImageAttachmentRef> {
|
||||
return Promise.reject(new Error('test invariant attachment store does not save images'))
|
||||
}
|
||||
|
||||
readImage(_ref: ImageAttachmentRef): Promise<StoredImageAttachment> {
|
||||
return Promise.reject(new Error('test invariant attachment store does not read images'))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the package companions that an ordinary test root must register.
|
||||
@@ -115,6 +141,7 @@ function startInvariantHost(root: Context): InvariantHost {
|
||||
mount(InvariantService, { enabled: true })
|
||||
const testPath = expect.getState().testPath ?? ''
|
||||
const companionPaths = testInvariantCompanionPaths(testPath)
|
||||
if (companionPaths.includes(ATTACHMENT_COMPANION)) mount(TestAttachmentStore)
|
||||
for (const path of companionPaths) {
|
||||
const companion = testInvariantCompanions[path]
|
||||
if (companion === undefined) {
|
||||
|
||||
Reference in New Issue
Block a user