

























@@ -1,3 +1,4 @@
1+import fs from "node:fs";
12import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
23import type { DoctorPrompter } from "../commands/doctor-prompter.js";
34import {
@@ -81,6 +82,10 @@ describe("doctor health contributions", () => {
8182mocks.note.mockReset();
8283});
838485+afterEach(() => {
86+vi.restoreAllMocks();
87+});
88+8489it("runs release configured plugin install repair before plugin registry and final config writes", () => {
8590const ids = resolveDoctorHealthContributions().map((entry) => entry.id);
8691@@ -188,11 +193,12 @@ describe("doctor health contributions", () => {
188193).toBe(false);
189194});
190195191-describe("allowConfigSizeDrop during update", () => {
196+describe("config size drops during update", () => {
192197beforeEach(() => {
193198mocks.replaceConfigFile.mockReset();
194199mocks.replaceConfigFile.mockResolvedValue(undefined);
195200mocks.applyWizardMetadata.mockImplementation((cfg: unknown) => cfg);
201+vi.spyOn(fs, "existsSync").mockReturnValue(false);
196202});
197203198204function buildWriteConfigCtx(env: Record<string, string | undefined>) {
@@ -218,7 +224,7 @@ describe("doctor health contributions", () => {
218224(entry) => entry.id === "doctor:write-config",
219225)!;
220226221-it("disables allowConfigSizeDrop when OPENCLAW_UPDATE_IN_PROGRESS=1", async () => {
227+it("allows config size drops when OPENCLAW_UPDATE_IN_PROGRESS=1", async () => {
222228const ctx = buildWriteConfigCtx({
223229OPENCLAW_UPDATE_IN_PROGRESS: "1",
224230OPENCLAW_UPDATE_PARENT_SUPPORTS_DOCTOR_CONFIG_WRITE: "1",
@@ -227,12 +233,26 @@ describe("doctor health contributions", () => {
227233expect(mocks.replaceConfigFile).toHaveBeenCalledWith(
228234expect.objectContaining({
229235writeOptions: expect.objectContaining({
230-allowConfigSizeDrop: false,
236+allowConfigSizeDrop: true,
231237}),
232238}),
233239);
234240});
235241242+it("points update-time config rewrites at the pre-update backup", async () => {
243+vi.mocked(fs.existsSync).mockImplementation((value) => String(value).endsWith(".pre-update"));
244+const ctx = buildWriteConfigCtx({
245+OPENCLAW_UPDATE_IN_PROGRESS: "1",
246+OPENCLAW_UPDATE_PARENT_SUPPORTS_DOCTOR_CONFIG_WRITE: "1",
247+});
248+249+await writeConfigContribution.run(ctx);
250+251+expect(ctx.runtime.log).toHaveBeenCalledWith(
252+"Update changed config; pre-update backup: /tmp/fake-openclaw.json.pre-update",
253+);
254+});
255+236256it("allows allowConfigSizeDrop when not in update", async () => {
237257const ctx = buildWriteConfigCtx({});
238258await writeConfigContribution.run(ctx);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。