mirror of https://github.com/openclaw/openclaw.git
refactor: share backup invalid config fixture
This commit is contained in:
parent
5cc751386d
commit
5a255809b9
|
|
@ -41,6 +41,31 @@ describe("backup commands", () => {
|
||||||
await tempHome.restore();
|
await tempHome.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function withInvalidWorkspaceBackupConfig<T>(
|
||||||
|
fn: (runtime: {
|
||||||
|
log: ReturnType<typeof vi.fn>;
|
||||||
|
error: ReturnType<typeof vi.fn>;
|
||||||
|
exit: ReturnType<typeof vi.fn>;
|
||||||
|
}) => Promise<T>,
|
||||||
|
) {
|
||||||
|
const stateDir = path.join(tempHome.home, ".openclaw");
|
||||||
|
const configPath = path.join(tempHome.home, "custom-config.json");
|
||||||
|
process.env.OPENCLAW_CONFIG_PATH = configPath;
|
||||||
|
await fs.writeFile(path.join(stateDir, "openclaw.json"), JSON.stringify({}), "utf8");
|
||||||
|
await fs.writeFile(configPath, '{"agents": { defaults: { workspace: ', "utf8");
|
||||||
|
const runtime = {
|
||||||
|
log: vi.fn(),
|
||||||
|
error: vi.fn(),
|
||||||
|
exit: vi.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await fn(runtime);
|
||||||
|
} finally {
|
||||||
|
delete process.env.OPENCLAW_CONFIG_PATH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
it("collapses default config, credentials, and workspace into the state backup root", async () => {
|
it("collapses default config, credentials, and workspace into the state backup root", async () => {
|
||||||
const stateDir = path.join(tempHome.home, ".openclaw");
|
const stateDir = path.join(tempHome.home, ".openclaw");
|
||||||
await fs.writeFile(path.join(stateDir, "openclaw.json"), JSON.stringify({}), "utf8");
|
await fs.writeFile(path.join(stateDir, "openclaw.json"), JSON.stringify({}), "utf8");
|
||||||
|
|
@ -336,41 +361,15 @@ describe("backup commands", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails fast when config is invalid and workspace backup is enabled", async () => {
|
it("fails fast when config is invalid and workspace backup is enabled", async () => {
|
||||||
const stateDir = path.join(tempHome.home, ".openclaw");
|
await withInvalidWorkspaceBackupConfig(async (runtime) => {
|
||||||
const configPath = path.join(tempHome.home, "custom-config.json");
|
|
||||||
process.env.OPENCLAW_CONFIG_PATH = configPath;
|
|
||||||
await fs.writeFile(path.join(stateDir, "openclaw.json"), JSON.stringify({}), "utf8");
|
|
||||||
await fs.writeFile(configPath, '{"agents": { defaults: { workspace: ', "utf8");
|
|
||||||
|
|
||||||
const runtime = {
|
|
||||||
log: vi.fn(),
|
|
||||||
error: vi.fn(),
|
|
||||||
exit: vi.fn(),
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
await expect(backupCreateCommand(runtime, { dryRun: true })).rejects.toThrow(
|
await expect(backupCreateCommand(runtime, { dryRun: true })).rejects.toThrow(
|
||||||
/--no-include-workspace/i,
|
/--no-include-workspace/i,
|
||||||
);
|
);
|
||||||
} finally {
|
});
|
||||||
delete process.env.OPENCLAW_CONFIG_PATH;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows explicit partial backups when config is invalid", async () => {
|
it("allows explicit partial backups when config is invalid", async () => {
|
||||||
const stateDir = path.join(tempHome.home, ".openclaw");
|
await withInvalidWorkspaceBackupConfig(async (runtime) => {
|
||||||
const configPath = path.join(tempHome.home, "custom-config.json");
|
|
||||||
process.env.OPENCLAW_CONFIG_PATH = configPath;
|
|
||||||
await fs.writeFile(path.join(stateDir, "openclaw.json"), JSON.stringify({}), "utf8");
|
|
||||||
await fs.writeFile(configPath, '{"agents": { defaults: { workspace: ', "utf8");
|
|
||||||
|
|
||||||
const runtime = {
|
|
||||||
log: vi.fn(),
|
|
||||||
error: vi.fn(),
|
|
||||||
exit: vi.fn(),
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await backupCreateCommand(runtime, {
|
const result = await backupCreateCommand(runtime, {
|
||||||
dryRun: true,
|
dryRun: true,
|
||||||
includeWorkspace: false,
|
includeWorkspace: false,
|
||||||
|
|
@ -378,9 +377,7 @@ describe("backup commands", () => {
|
||||||
|
|
||||||
expect(result.includeWorkspace).toBe(false);
|
expect(result.includeWorkspace).toBe(false);
|
||||||
expect(result.assets.some((asset) => asset.kind === "workspace")).toBe(false);
|
expect(result.assets.some((asset) => asset.kind === "workspace")).toBe(false);
|
||||||
} finally {
|
});
|
||||||
delete process.env.OPENCLAW_CONFIG_PATH;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("backs up only the active config file when --only-config is requested", async () => {
|
it("backs up only the active config file when --only-config is requested", async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue