mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:40:44 +00:00
test(gateway): preserve startup model allowlist
This commit is contained in:
@@ -226,6 +226,126 @@ describe("gateway startup config recovery", () => {
|
||||
expect(log.info).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("preserves empty model allowlist entries through startup auto-enable writes", async () => {
|
||||
const sourceConfig = {
|
||||
agents: {
|
||||
defaults: {
|
||||
model: { primary: "dos-ai/dos-ai" },
|
||||
models: {
|
||||
"dos-ai/dos-ai": {},
|
||||
"dos-ai/dos-auto": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
gateway: { mode: "local" },
|
||||
models: {
|
||||
mode: "replace",
|
||||
providers: {
|
||||
"dos-ai": {
|
||||
baseUrl: "https://dos.example.test/v1",
|
||||
apiKey: "test-key",
|
||||
api: "openai-completions",
|
||||
models: [
|
||||
{ id: "dos-ai", name: "DOS AI" },
|
||||
{ id: "dos-auto", name: "DOS Auto" },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const autoEnabledConfig = {
|
||||
...sourceConfig,
|
||||
channels: {
|
||||
telegram: { enabled: true },
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const initialSnapshot = {
|
||||
...buildTestConfigSnapshot({
|
||||
path: configPath,
|
||||
exists: true,
|
||||
raw: `${JSON.stringify(sourceConfig)}\n`,
|
||||
parsed: sourceConfig,
|
||||
valid: true,
|
||||
config: sourceConfig,
|
||||
issues: [],
|
||||
legacyIssues: [],
|
||||
}),
|
||||
sourceConfig,
|
||||
resolved: sourceConfig,
|
||||
runtimeConfig: sourceConfig,
|
||||
config: sourceConfig,
|
||||
} satisfies ConfigFileSnapshot;
|
||||
const postWriteSnapshot = {
|
||||
...buildTestConfigSnapshot({
|
||||
path: configPath,
|
||||
exists: true,
|
||||
raw: `${JSON.stringify(autoEnabledConfig)}\n`,
|
||||
parsed: autoEnabledConfig,
|
||||
valid: true,
|
||||
config: autoEnabledConfig,
|
||||
issues: [],
|
||||
legacyIssues: [],
|
||||
}),
|
||||
sourceConfig: autoEnabledConfig,
|
||||
resolved: autoEnabledConfig,
|
||||
runtimeConfig: autoEnabledConfig,
|
||||
config: autoEnabledConfig,
|
||||
} satisfies ConfigFileSnapshot;
|
||||
vi.mocked(configIo.readConfigFileSnapshotWithPluginMetadata)
|
||||
.mockResolvedValueOnce({
|
||||
snapshot: initialSnapshot,
|
||||
pluginMetadataSnapshot,
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
snapshot: postWriteSnapshot,
|
||||
pluginMetadataSnapshot,
|
||||
});
|
||||
applyPluginAutoEnable.mockReturnValueOnce({
|
||||
config: autoEnabledConfig,
|
||||
changes: ["Telegram configured, enabled automatically."],
|
||||
autoEnabledReasons: {},
|
||||
});
|
||||
const log = { info: vi.fn(), warn: vi.fn() };
|
||||
|
||||
await expect(
|
||||
loadGatewayStartupConfigSnapshot({
|
||||
minimalTestGateway: false,
|
||||
log,
|
||||
}),
|
||||
).resolves.toEqual({
|
||||
snapshot: postWriteSnapshot,
|
||||
wroteConfig: true,
|
||||
pluginMetadataSnapshot,
|
||||
});
|
||||
|
||||
expect(applyPluginAutoEnable).toHaveBeenCalledWith({
|
||||
config: sourceConfig,
|
||||
env: process.env,
|
||||
manifestRegistry: pluginManifestRegistry,
|
||||
});
|
||||
expect(configMutate.replaceConfigFile).toHaveBeenCalledWith({
|
||||
nextConfig: expect.objectContaining({
|
||||
agents: expect.objectContaining({
|
||||
defaults: expect.objectContaining({
|
||||
models: {
|
||||
"dos-ai/dos-ai": {},
|
||||
"dos-ai/dos-auto": {},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
afterWrite: { mode: "auto" },
|
||||
});
|
||||
expect(postWriteSnapshot.sourceConfig.agents?.defaults?.models).toEqual({
|
||||
"dos-ai/dos-ai": {},
|
||||
"dos-ai/dos-auto": {},
|
||||
});
|
||||
expect(postWriteSnapshot.config.agents?.defaults?.models).toEqual({
|
||||
"dos-ai/dos-ai": {},
|
||||
"dos-ai/dos-auto": {},
|
||||
});
|
||||
});
|
||||
|
||||
it("restores last-known-good config before startup validation", async () => {
|
||||
const invalidSnapshot = buildSnapshot({ valid: false, raw: "{ invalid json" });
|
||||
const recoveredSnapshot = buildSnapshot({
|
||||
|
||||
Reference in New Issue
Block a user