forked from cflmy/deepseek-harness
test(cordis): cover rc.12 validation paths and fix serialized root access
This commit is contained in:
1 parent
1511a6ed44
commit
798d3586bb
9 files changed
+66
-25
No files matched your search
@@ -1,7 +1,7 @@
|
||||
/** Chromium acceptance of the shipped Web profile's actual Client plugin and module registries. */
|
||||
|
||||
import { Context, FiberState } from '@deepseek-ai/cordis'
|
||||
import type { Plugin, RegistryService } from '@deepseek-ai/cordis'
|
||||
import { FiberState } from '@deepseek-ai/cordis'
|
||||
import type { Context, Plugin, RegistryService } from '@deepseek-ai/cordis'
|
||||
import type { ClientModuleLoader, ClientModuleLoaderTarget } from '@deepseek-ai/dsh-client-modules/client'
|
||||
import { chromium } from 'playwright'
|
||||
import { hasExperimentalPackageReference } from '../../../scripts/experimental-package-policy.ts'
|
||||
@@ -73,7 +73,8 @@ it('activates the actual default Client registry without experimental packages',
|
||||
// Capture the first real root and immediately restore the registry method.
|
||||
prototype.plugin = function (...args: Parameters<RegistryService['plugin']>) {
|
||||
prototype.plugin = plugin
|
||||
observation.ctx = this.ctx[Context.root]
|
||||
// This init script runs in the page, where the test's `Context` import is unavailable.
|
||||
observation.ctx = this.ctx[Symbol.for('cordis.root') as typeof Context.root]
|
||||
return plugin.apply(this, args)
|
||||
}
|
||||
const modules = create(options)
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
en: c8aa4d3384ea1306
|
||||
zh: 5aa030587d5b634d
|
||||
/vendored-package-rescope/name-mapping:
|
||||
en: 50a68b9b3724eff8
|
||||
zh: 9facad930deeb014
|
||||
en: 8d86dcb4f884fb2e
|
||||
zh: 4886ccf670df1b01
|
||||
/vendored-package-rescope/what-the-rename-does-not-touch:
|
||||
en: 9bb7d09f8cccf695
|
||||
zh: 2a8f3f60ae5116f3
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ The Cordis framework and its foundation libraries are vendored under [`vendor/`]
|
||||
|
||||
| Directory | Upstream name | Published name | Upstream version | Role |
|
||||
|---|---|---|---|---|
|
||||
| `vendor/cordis/` | `cordis` | `@deepseek-ai/cordis` | 4.0.0-rc.11 | Framework core: `Context`, `Service`, `Fiber`, events |
|
||||
| `vendor/cordis/` | `cordis` | `@deepseek-ai/cordis` | 4.0.0-rc.12 | Framework core: `Context`, `Service`, `Fiber`, events |
|
||||
| `vendor/cosmokit/` | `cosmokit` | `@deepseek-ai/cosmokit` | 1.8.1 | Shared utilities the framework and Schemastery build on |
|
||||
| `vendor/schemastery/` | `schemastery` | `@deepseek-ai/schemastery` | 3.18.0 | Config schemas (`Schema`) behind every plugin's `Config` |
|
||||
| `vendor/loader/` | `@cordisjs/plugin-loader` | `@deepseek-ai/cordis-plugin-loader` | 1.0.0-rc.8 | `cordis.yml` loading, plugin resolution, repository cache |
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ Cordis 框架及其基础库以源码形式 vendored 在 [`vendor/`](../vendor/R
|
||||
|
||||
| 目录 | 上游名 | 发布名 | 上游版本 | 角色 |
|
||||
|---|---|---|---|---|
|
||||
| `vendor/cordis/` | `cordis` | `@deepseek-ai/cordis` | 4.0.0-rc.11 | 框架核心:`Context`、`Service`、`Fiber`、事件 |
|
||||
| `vendor/cordis/` | `cordis` | `@deepseek-ai/cordis` | 4.0.0-rc.12 | 框架核心:`Context`、`Service`、`Fiber`、事件 |
|
||||
| `vendor/cosmokit/` | `cosmokit` | `@deepseek-ai/cosmokit` | 1.8.1 | 框架与 Schemastery 共用的基础工具 |
|
||||
| `vendor/schemastery/` | `schemastery` | `@deepseek-ai/schemastery` | 3.18.0 | 配置 schema(`Schema`),每个插件的 `Config` 都基于它 |
|
||||
| `vendor/loader/` | `@cordisjs/plugin-loader` | `@deepseek-ai/cordis-plugin-loader` | 1.0.0-rc.8 | `cordis.yml` 装载、插件解析、repository 缓存 |
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
en: 546ad75e75ee931f
|
||||
zh: 16cd20c00e92e6f5
|
||||
/ctx-context-root-replaces-ctx-root-and-service-intercept-metadata-is-renamed/change:
|
||||
en: 73b1b7e0bdffb92b
|
||||
zh: 108e4d9d0d333c36
|
||||
en: 84337d9923efc3c6
|
||||
zh: e294b792081c7989
|
||||
/ctx-context-root-replaces-ctx-root-and-service-intercept-metadata-is-renamed/migration:
|
||||
en: 6080606517656f7e
|
||||
zh: 1e045b715c3c4946
|
||||
en: adec35b8052efcd3
|
||||
zh: 56c53d6089761976
|
||||
@@ -14,6 +14,7 @@ English | [中文](guide.zh.md)
|
||||
- `ctx.root` no longer exists. The root context is `ctx[Context.root]`; `Context.root` is a symbol exported on the `Context` class. Inside a plugin, reading `ctx.root` throws `cannot get property "root" without inject`.
|
||||
- `Service.config` becomes `Service.metadata`. A service declares its intercept type with `declare [Service.metadata]: T`.
|
||||
- `[Service.resolveConfig](base?, head?)` becomes `[Service.resolveIntercept]()`, which takes no arguments.
|
||||
- The global symbol `Symbol.for('cordis.metadata')` now keys `Service.metadata`. The method metadata that decorators such as `@Inject()` store moved to `symbols.decorator` (`Symbol.for('cordis.decorator')`).
|
||||
- A service's `Config.merge` hook is no longer called. Override `[Service.mergeIntercept](...values)` instead; it receives the values in increasing precedence.
|
||||
- Metadata a plugin declares in object-form `inject` now has the lowest precedence. Intercepts added with `ctx.intercept()` override it; previously the injected value overrode them.
|
||||
- A context created with `ctx.isolate(name)` no longer falls back to the enclosing plugin's injected `name`. Plugins started under it, and reads after its own provision is withdrawn, throw `cannot get property "<name>" without inject`.
|
||||
@@ -23,7 +24,8 @@ English | [中文](guide.zh.md)
|
||||
|
||||
1. Replace every `ctx.root` with `ctx[Context.root]`, importing `Context` as a value from `@deepseek-ai/cordis`. Plain JavaScript without the import can read `ctx[Symbol.for('cordis.root')]`.
|
||||
2. In service classes, rename `declare [Service.config]` to `declare [Service.metadata]` and calls of `[Service.resolveConfig]()` to `[Service.resolveIntercept]()`. Replace `base` and `head` arguments by declaring the base value in `inject` and adding the override with `ctx.intercept()`.
|
||||
3. Move a `Config.merge` implementation to a `[Service.mergeIntercept](...values)` method on the service class.
|
||||
4. Where a plugin relied on its `inject` metadata overriding an ancestor `ctx.intercept()`, set the value with `ctx.intercept()` at the plugin's context instead.
|
||||
5. Where code under `ctx.isolate(name)` needs the enclosing plugin's service, provide that service inside the isolated context or start the code from a context that is not isolated.
|
||||
6. Run your TypeScript build: references to `ctx.root`, `Service.config` and `Service.resolveConfig` fail to compile. Start the plugin and confirm that services resolve and logs keep their names.
|
||||
3. Where code reads or writes decorator method metadata through `symbols.metadata` or `Symbol.for('cordis.metadata')`, use `symbols.decorator` instead.
|
||||
4. Move a `Config.merge` implementation to a `[Service.mergeIntercept](...values)` method on the service class.
|
||||
5. Where a plugin relied on its `inject` metadata overriding an ancestor `ctx.intercept()`, set the value with `ctx.intercept()` at the plugin's context instead.
|
||||
6. Where code under `ctx.isolate(name)` needs the enclosing plugin's service, provide that service inside the isolated context or start the code from a context that is not isolated.
|
||||
7. Run your TypeScript build: references to `ctx.root`, `Service.config` and `Service.resolveConfig` fail to compile. Start the plugin and confirm that services resolve and logs keep their names.
|
||||
@@ -14,6 +14,7 @@ description: "Cordis 4.0.0-rc.12 用 ctx[Context.root] 取代 ctx.root,并重
|
||||
- `ctx.root` 不再存在。根上下文改为 `ctx[Context.root]`;`Context.root` 是 `Context` 类上导出的 symbol。在插件内读取 `ctx.root` 会抛出 `cannot get property "root" without inject`。
|
||||
- `Service.config` 改为 `Service.metadata`。服务用 `declare [Service.metadata]: T` 声明其拦截类型。
|
||||
- `[Service.resolveConfig](base?, head?)` 改为不带参数的 `[Service.resolveIntercept]()`。
|
||||
- 全局 symbol `Symbol.for('cordis.metadata')` 现在对应 `Service.metadata`。`@Inject()` 等装饰器存储的方法元数据改用 `symbols.decorator`(`Symbol.for('cordis.decorator')`)。
|
||||
- 服务的 `Config.merge` 钩子不再被调用。改为重写 `[Service.mergeIntercept](...values)`;它按优先级从低到高接收各个值。
|
||||
- 插件在对象形式的 `inject` 中声明的元数据现在优先级最低,用 `ctx.intercept()` 添加的拦截会覆盖它;此前是注入的值覆盖拦截。
|
||||
- 用 `ctx.isolate(name)` 创建的上下文不再回退到外层插件注入的 `name`。在其下启动的插件,以及在其自身提供撤回后的读取,都会抛出 `cannot get property "<name>" without inject`。
|
||||
@@ -23,7 +24,8 @@ description: "Cordis 4.0.0-rc.12 用 ctx[Context.root] 取代 ctx.root,并重
|
||||
|
||||
1. 将所有 `ctx.root` 替换为 `ctx[Context.root]`,并从 `@deepseek-ai/cordis` 以值的形式导入 `Context`。无法导入的纯 JavaScript 可以读取 `ctx[Symbol.for('cordis.root')]`。
|
||||
2. 在服务类中,将 `declare [Service.config]` 改为 `declare [Service.metadata]`,将对 `[Service.resolveConfig]()` 的调用改为 `[Service.resolveIntercept]()`。原来的 `base` 参数改为在 `inject` 中声明,`head` 参数改为用 `ctx.intercept()` 添加。
|
||||
3. 将 `Config.merge` 的实现移到服务类的 `[Service.mergeIntercept](...values)` 方法中。
|
||||
4. 如果插件依赖其 `inject` 元数据覆盖祖先的 `ctx.intercept()`,改为在该插件的上下文上用 `ctx.intercept()` 设置该值。
|
||||
5. 如果 `ctx.isolate(name)` 之下的代码需要外层插件的服务,在隔离的上下文中提供该服务,或从未隔离的上下文启动这段代码。
|
||||
6. 运行 TypeScript 构建:引用 `ctx.root`、`Service.config` 和 `Service.resolveConfig` 的代码会编译失败。启动插件,确认服务可以解析,日志名称保持不变。
|
||||
3. 如果代码通过 `symbols.metadata` 或 `Symbol.for('cordis.metadata')` 读写装饰器的方法元数据,改用 `symbols.decorator`。
|
||||
4. 将 `Config.merge` 的实现移到服务类的 `[Service.mergeIntercept](...values)` 方法中。
|
||||
5. 如果插件依赖其 `inject` 元数据覆盖祖先的 `ctx.intercept()`,改为在该插件的上下文上用 `ctx.intercept()` 设置该值。
|
||||
6. 如果 `ctx.isolate(name)` 之下的代码需要外层插件的服务,在隔离的上下文中提供该服务,或从未隔离的上下文启动这段代码。
|
||||
7. 运行 TypeScript 构建:引用 `ctx.root`、`Service.config` 和 `Service.resolveConfig` 的代码会编译失败。启动插件,确认服务可以解析,日志名称保持不变。
|
||||
@@ -319,8 +319,9 @@ const root = {
|
||||
inject() { return { dispose() {} }; },
|
||||
provide(name, value) { this[name] = value; return () => { delete this[name]; }; },
|
||||
};
|
||||
root.root = root;
|
||||
const cordis = { Context: { is(value) { return value?.__inspectorContext === true; } } };
|
||||
const rootKey = Symbol.for('cordis.root');
|
||||
root[rootKey] = root;
|
||||
const cordis = { Context: { root: rootKey, is(value) { return value?.__inspectorContext === true; } } };
|
||||
const plugin = registration.factory(specifier => {
|
||||
if (specifier === '@deepseek-ai/cordis') return cordis;
|
||||
throw new Error('Unexpected Client bundle dependency ' + specifier);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/** Cordis rc.12 root access, intercept metadata, isolation, disposal and event errors. */
|
||||
import { Context, FiberState, Service } from '@deepseek-ai/cordis'
|
||||
import { describe, expect, it, onTestFinished, vi } from 'vitest'
|
||||
import { Context, FiberState, Service, ValidationError } from '@deepseek-ai/cordis'
|
||||
import { describe, expect, it, onTestFinished } from 'vitest'
|
||||
|
||||
interface Metadata {
|
||||
a?: number
|
||||
@@ -87,6 +87,24 @@ describe('Cordis rc.12 core', () => {
|
||||
expect(results).toEqual(['outer', 'cannot get property "rc12View" without inject'])
|
||||
})
|
||||
|
||||
it('isolates a context pinned to its parent realm label from the injected view', async () => {
|
||||
const ctx = root()
|
||||
ctx.provide('rc12View', 'outer')
|
||||
let message = ''
|
||||
await ctx.inject(['rc12View'], async (owner) => {
|
||||
const pinned = owner.isolate('rc12View', owner[Context.isolate].rc12View)
|
||||
expect(() => pinned.rc12View).toThrow('cannot get property "rc12View" without inject')
|
||||
await pinned.plugin((child) => {
|
||||
try {
|
||||
void child.rc12View
|
||||
} catch (error) {
|
||||
message = error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
expect(message).toBe('cannot get property "rc12View" without inject')
|
||||
})
|
||||
|
||||
it('settles pending and failed fibers to DISPOSED', async () => {
|
||||
const ctx = root()
|
||||
const pending = ctx.inject(['rc12NeverProvided'], () => {})
|
||||
@@ -94,10 +112,9 @@ describe('Cordis rc.12 core', () => {
|
||||
await pending.dispose()
|
||||
expect(pending.state).toBe(FiberState.DISPOSED)
|
||||
|
||||
const error = vi.spyOn(ctx.logger('fiber'), 'error').mockImplementation(() => {})
|
||||
onTestFinished(() => { error.mockRestore() })
|
||||
const failed = ctx.plugin(() => { throw new Error('rc12 boom') })
|
||||
await expect(failed.await()).rejects.toThrow('rc12 boom')
|
||||
expect(ctx.logger.buffer.some(message => message.type === 'error' && message.args[0] instanceof Error && message.args[0].message === 'rc12 boom')).toBe(true)
|
||||
expect(failed.state).toBe(FiberState.FAILED)
|
||||
await failed.dispose()
|
||||
expect(failed.state).toBe(FiberState.DISPOSED)
|
||||
@@ -111,4 +128,22 @@ describe('Cordis rc.12 core', () => {
|
||||
await expect(ctx.parallel('rc12-parallel' as never)).rejects.toThrow('one or more listeners of event "rc12-parallel" failed')
|
||||
await expect(ctx.parallel(symbol as never)).rejects.toThrow('one or more listeners of event Symbol(rc12-symbol) failed')
|
||||
})
|
||||
|
||||
it('formats config validation paths with keyed segments', () => {
|
||||
const error = new ValidationError([{ message: 'bad', path: [{ key: 0 }, 'name'] }])
|
||||
expect(ValidationError.is(error)).toBe(true)
|
||||
expect(ValidationError.is(new TypeError('bad'))).toBe(false)
|
||||
expect(error.issues).toHaveLength(1)
|
||||
expect(error.message).toBe('invalid config:\n - bad (at 0.name)')
|
||||
expect(ValidationError.normalizePath([{ key: 'a' }, 1])).toEqual(['a', 1])
|
||||
expect(ValidationError.formatPath(undefined)).toBe('')
|
||||
expect(new ValidationError([{ message: 'bad', path: [] }]).message).toBe('invalid config:\n - bad')
|
||||
})
|
||||
|
||||
it('logs an AggregateError without members as itself', () => {
|
||||
const ctx = root()
|
||||
const aggregate = new AggregateError([], 'empty')
|
||||
ctx.logger.error(aggregate)
|
||||
expect(ctx.logger.buffer.at(-1)?.args[0]).toBe(aggregate)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user