

























@@ -467,26 +467,62 @@ describe("models list/status", () => {
467467expect(Array.from(loaded.availableKeys ?? [])).toEqual(["openai/gpt-4.1-mini"]);
468468});
469469470-it("modelsListCommand persists using the source snapshot config when provided", async () => {
471-modelRegistryState.models = [OPENAI_MODEL];
472-modelRegistryState.available = [OPENAI_MODEL];
470+it("modelsListCommand lists source snapshot provider models without persisting models.json", async () => {
471+modelRegistryState.models = [];
472+modelRegistryState.available = [];
473473const sourceConfig = {
474-models: { providers: { openai: { apiKey: "$OPENAI_API_KEY" } } }, // pragma: allowlist secret
474+models: {
475+providers: {
476+"custom-proxy": {
477+baseUrl: "https://custom.example/v1",
478+models: [
479+{
480+id: "custom-model",
481+name: "Custom Model",
482+input: ["text"],
483+contextWindow: 128000,
484+},
485+],
486+},
487+},
488+},
475489};
476490const resolvedConfig = {
477-models: { providers: { openai: { apiKey: "sk-resolved-runtime-value" } } }, // pragma: allowlist secret
491+models: {
492+providers: {
493+"custom-proxy": {
494+baseUrl: "https://custom.example/v1",
495+apiKey: "sk-resolved-runtime-value", // pragma: allowlist secret
496+models: [
497+{
498+id: "custom-model",
499+name: "Custom Model",
500+input: ["text"],
501+contextWindow: 128000,
502+},
503+],
504+},
505+},
506+},
478507};
479508readConfigFileSnapshotForWrite.mockResolvedValue({
480509snapshot: { valid: true, resolved: resolvedConfig, sourceConfig },
481510writeOptions: {},
482511});
483-setDefaultModel("openai/gpt-4.1-mini");
512+getRuntimeConfig.mockReturnValue(resolvedConfig);
484513const runtime = makeRuntime();
485514486-await modelsListCommand({ all: true, json: true }, runtime);
515+await modelsListCommand({ all: true, provider: "custom-proxy", json: true }, runtime);
487516488-expect(ensureOpenClawModelsJson).toHaveBeenCalled();
489-expect(ensureOpenClawModelsJson.mock.calls[0]?.[0]).toEqual(sourceConfig);
517+expect(ensureOpenClawModelsJson).not.toHaveBeenCalled();
518+const payload = parseJsonLog(runtime);
519+expect(payload.models).toEqual([
520+expect.objectContaining({
521+key: "custom-proxy/custom-model",
522+name: "Custom Model",
523+missing: false,
524+}),
525+]);
490526});
491527492528it("toModelRow does not crash without cfg/authStore when availability is undefined", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。