From 86b59d4a177ca942e60ad21b4208732c42084c1f Mon Sep 17 00:00:00 2001 From: Shigma Date: Fri, 30 Oct 2026 14:00:01 +0800 Subject: [PATCH] test(cordis): load vendor HMR without its type declarations --- scripts/cordis-vendor-hmr-include.spec.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/cordis-vendor-hmr-include.spec.ts b/scripts/cordis-vendor-hmr-include.spec.ts index 8f960bc0a1..64f7447f69 100644 --- a/scripts/cordis-vendor-hmr-include.spec.ts +++ b/scripts/cordis-vendor-hmr-include.spec.ts @@ -3,13 +3,16 @@ import { mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' import { pathToFileURL } from 'node:url' -import { Context } from '@deepseek-ai/cordis' +import { Context, type Plugin } from '@deepseek-ai/cordis' import Loader from '@deepseek-ai/cordis-plugin-loader' import Include from '@deepseek-ai/cordis-plugin-include' import Timer from '@deepseek-ai/cordis-plugin-timer' -import Hmr from '@deepseek-ai/cordis-plugin-hmr' import { expect, it, onTestFinished, vi } from 'vitest' +// A literal import would add vendor HMR's `Context.hmr` declaration to the +// repository type program, where DSH HMR declares the same property. +const vendorHmr: string = '@deepseek-ai/cordis-plugin-hmr' + it('logs a rejected Include refresh instead of leaving it unhandled', async () => { const dir = realpathSync(mkdtempSync(join(tmpdir(), 'dsh-vendor-hmr-include-'))) const ctx = new Context() @@ -22,9 +25,10 @@ it('logs a rejected Include refresh instead of leaving it unhandled', async () = writeFileSync(file, '[]\n') const id = await ctx.loader.create({ name: 'cordis:include', config: { path: './nested.yml' } }) await ctx.loader.await() + const { default: Hmr } = await import(vendorHmr) as { default: Plugin } await ctx.plugin(Hmr, { root: [], ignored: [], debounce: 0 }) // The service keeps its chokidar watcher private; the test drives its change listener directly. - const watcher = Reflect.get(ctx.get('hmr')!, 'watcher') as { emit(event: 'change', path: string): boolean } + const watcher = Reflect.get(ctx.get('hmr') as object, 'watcher') as { emit(event: 'change', path: string): boolean } const include = ctx.loader.resolve(id).subtree as Include const failure = new Error('config file has 1 unsaved change(s)') const refresh = vi.spyOn(include, 'refresh').mockRejectedValue(failure)