mirror of
http://192.168.0.88:13333/lywsvip/openclaw-zero-token.git
synced 2026-06-09 07:52:24 +08:00
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
187 lines
5.4 KiB
TypeScript
187 lines
5.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { OpenClawConfig } from "../config/config.js";
|
|
import { applyExclusiveSlotSelection } from "./slots.js";
|
|
import type { PluginKind } from "./types.js";
|
|
|
|
describe("applyExclusiveSlotSelection", () => {
|
|
const createMemoryConfig = (plugins?: OpenClawConfig["plugins"]): OpenClawConfig => ({
|
|
plugins: {
|
|
...plugins,
|
|
entries: {
|
|
...plugins?.entries,
|
|
memory: {
|
|
enabled: true,
|
|
...plugins?.entries?.memory,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
const runMemorySelection = (config: OpenClawConfig, selectedId = "memory") =>
|
|
applyExclusiveSlotSelection({
|
|
config,
|
|
selectedId,
|
|
selectedKind: "memory",
|
|
registry: {
|
|
plugins: [
|
|
{ id: "memory-core", kind: "memory" },
|
|
{ id: "memory", kind: "memory" },
|
|
],
|
|
},
|
|
});
|
|
|
|
function expectMemorySelectionState(
|
|
result: ReturnType<typeof applyExclusiveSlotSelection>,
|
|
params: {
|
|
changed: boolean;
|
|
selectedId?: string;
|
|
disabledCompetingPlugin?: boolean;
|
|
},
|
|
) {
|
|
expect(result.changed).toBe(params.changed);
|
|
if (params.selectedId) {
|
|
expect(result.config.plugins?.slots?.memory).toBe(params.selectedId);
|
|
}
|
|
if (params.disabledCompetingPlugin != null) {
|
|
expect(result.config.plugins?.entries?.["memory-core"]?.enabled).toBe(
|
|
params.disabledCompetingPlugin,
|
|
);
|
|
}
|
|
}
|
|
|
|
function expectSelectionWarnings(
|
|
warnings: string[],
|
|
params: {
|
|
contains?: readonly string[];
|
|
excludes?: readonly string[];
|
|
},
|
|
) {
|
|
if (params.contains?.length) {
|
|
expect(warnings).toEqual(expect.arrayContaining([...params.contains]));
|
|
}
|
|
for (const warning of params.excludes ?? []) {
|
|
expect(warnings).not.toEqual(expect.arrayContaining([warning]));
|
|
}
|
|
}
|
|
|
|
function expectUnchangedSelection(result: ReturnType<typeof applyExclusiveSlotSelection>) {
|
|
expect(result.changed).toBe(false);
|
|
expect(result.warnings).toHaveLength(0);
|
|
}
|
|
|
|
function buildSelectionRegistry(plugins: ReadonlyArray<{ id: string; kind?: PluginKind }>) {
|
|
return {
|
|
plugins: [...plugins],
|
|
};
|
|
}
|
|
|
|
function expectUnchangedSelectionCase(params: {
|
|
config: OpenClawConfig;
|
|
selectedId: string;
|
|
selectedKind?: PluginKind;
|
|
registry?: { plugins: ReadonlyArray<{ id: string; kind?: PluginKind }> };
|
|
}) {
|
|
const result = applyExclusiveSlotSelection({
|
|
config: params.config,
|
|
selectedId: params.selectedId,
|
|
...(params.selectedKind ? { selectedKind: params.selectedKind } : {}),
|
|
...(params.registry
|
|
? {
|
|
registry: buildSelectionRegistry(params.registry.plugins),
|
|
}
|
|
: {}),
|
|
});
|
|
|
|
expectUnchangedSelection(result);
|
|
expect(result.config).toBe(params.config);
|
|
}
|
|
|
|
function expectChangedSelectionCase(params: {
|
|
config: OpenClawConfig;
|
|
selectedId?: string;
|
|
expectedDisabled?: boolean;
|
|
warningChecks: {
|
|
contains?: readonly string[];
|
|
excludes?: readonly string[];
|
|
};
|
|
}) {
|
|
const result = runMemorySelection(params.config, params.selectedId);
|
|
|
|
expectMemorySelectionState(result, {
|
|
changed: true,
|
|
selectedId: params.selectedId ?? "memory",
|
|
...(params.expectedDisabled != null
|
|
? { disabledCompetingPlugin: params.expectedDisabled }
|
|
: {}),
|
|
});
|
|
expectSelectionWarnings(result.warnings, params.warningChecks);
|
|
}
|
|
|
|
it.each([
|
|
{
|
|
name: "selects the slot and disables other entries for the same kind",
|
|
config: createMemoryConfig({
|
|
slots: { memory: "memory-core" },
|
|
entries: { "memory-core": { enabled: true } },
|
|
}),
|
|
expectedDisabled: false,
|
|
warningChecks: {
|
|
contains: [
|
|
'Exclusive slot "memory" switched from "memory-core" to "memory".',
|
|
'Disabled other "memory" slot plugins: memory-core.',
|
|
],
|
|
},
|
|
},
|
|
{
|
|
name: "warns when the slot falls back to a default",
|
|
config: createMemoryConfig(),
|
|
warningChecks: {
|
|
contains: ['Exclusive slot "memory" switched from "memory-core" to "memory".'],
|
|
},
|
|
},
|
|
{
|
|
name: "keeps disabled competing plugins disabled without adding disable warnings",
|
|
config: createMemoryConfig({
|
|
entries: {
|
|
"memory-core": { enabled: false },
|
|
},
|
|
}),
|
|
expectedDisabled: false,
|
|
warningChecks: {
|
|
contains: ['Exclusive slot "memory" switched from "memory-core" to "memory".'],
|
|
excludes: ['Disabled other "memory" slot plugins: memory-core.'],
|
|
},
|
|
},
|
|
] as const)("$name", ({ config, expectedDisabled, warningChecks }) => {
|
|
expectChangedSelectionCase({
|
|
config,
|
|
...(expectedDisabled != null ? { expectedDisabled } : {}),
|
|
warningChecks,
|
|
});
|
|
});
|
|
|
|
it.each([
|
|
{
|
|
name: "does nothing when the slot already matches",
|
|
config: createMemoryConfig({
|
|
slots: { memory: "memory" },
|
|
}),
|
|
selectedId: "memory",
|
|
selectedKind: "memory",
|
|
registry: { plugins: [{ id: "memory", kind: "memory" }] },
|
|
},
|
|
{
|
|
name: "skips changes when no exclusive slot applies",
|
|
config: {} as OpenClawConfig,
|
|
selectedId: "custom",
|
|
},
|
|
] as const)("$name", ({ config, selectedId, selectedKind, registry }) => {
|
|
expectUnchangedSelectionCase({
|
|
config,
|
|
selectedId,
|
|
...(selectedKind ? { selectedKind } : {}),
|
|
...(registry ? { registry: buildSelectionRegistry(registry.plugins) } : {}),
|
|
});
|
|
});
|
|
});
|