36 lines
1.7 KiB
TypeScript
36 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
import { createEngine } from "../../src/engine/engine";
|
||
import { capabilityCount, capabilityIds, getCapabilityMeta } from "../../src/engine/registry";
|
||
import { isKnownErrorCode } from "../../src/engine/error-codes";
|
||
import { capabilityDomains, registerAll } from "../../src/capabilities/register-all";
|
||
import "../../src/capabilities/index";
|
||
|
||
describe("registerAll 显式注册入口", () => {
|
||
it("副作用入口已注册全量包内能力,registerAll 全量幂等", async () => {
|
||
// 包内 capabilities/index 注册 719 个 id(909 快照 = 包内 + 宿主浏览器能力)
|
||
const before = capabilityCount();
|
||
expect(before).toBeGreaterThan(700);
|
||
const engine = await registerAll(createEngine());
|
||
expect(engine).toBeDefined();
|
||
expect(capabilityCount()).toBe(before);
|
||
});
|
||
|
||
it("按子集注册:只拉起指定域,未知域报错", async () => {
|
||
expect(capabilityDomains).toContain("excelCom");
|
||
await expect(registerAll(createEngine(), ["excelCom", "no-such-domain"])).rejects.toThrow("未知能力域");
|
||
await registerAll(createEngine(), ["files"]);
|
||
expect(getCapabilityMeta).toBeDefined();
|
||
});
|
||
|
||
it("meta(任务 4.1):老能力允许缺省;已声明 meta 的能力错误码必须在稳定清单内", () => {
|
||
// 全量注册后的每个 meta,其 errorCodes 都必须落在 RUNTIME_ERROR_CODES 清单内
|
||
for (const id of capabilityIds()) {
|
||
const meta = getCapabilityMeta(id);
|
||
if (!meta) continue;
|
||
for (const code of meta.errorCodes ?? []) {
|
||
expect(isKnownErrorCode(code), `${id} 的错误码 ${code} 未登记 error-codes.ts`).toBe(true);
|
||
}
|
||
}
|
||
});
|
||
});
|