mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 07:11:25 +00:00
refactor(core): dedupe gateway runtime and config tests
This commit is contained in:
@@ -46,6 +46,25 @@ function setupSessionState(cfg: OpenClawConfig, env: NodeJS.ProcessEnv, homeDir:
|
||||
fs.mkdirSync(path.dirname(storePath), { recursive: true });
|
||||
}
|
||||
|
||||
function stateIntegrityText(): string {
|
||||
return vi
|
||||
.mocked(note)
|
||||
.mock.calls.filter((call) => call[1] === "State integrity")
|
||||
.map((call) => String(call[0]))
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
const OAUTH_PROMPT_MATCHER = expect.objectContaining({
|
||||
message: expect.stringContaining("Create OAuth dir at"),
|
||||
});
|
||||
|
||||
async function runStateIntegrity(cfg: OpenClawConfig) {
|
||||
setupSessionState(cfg, process.env, process.env.HOME ?? "");
|
||||
const confirmSkipInNonInteractive = vi.fn(async () => false);
|
||||
await noteStateIntegrity(cfg, { confirmSkipInNonInteractive });
|
||||
return confirmSkipInNonInteractive;
|
||||
}
|
||||
|
||||
describe("doctor state integrity oauth dir checks", () => {
|
||||
let envSnapshot: EnvSnapshot;
|
||||
let tempHome = "";
|
||||
@@ -68,23 +87,11 @@ describe("doctor state integrity oauth dir checks", () => {
|
||||
|
||||
it("does not prompt for oauth dir when no whatsapp/pairing config is active", async () => {
|
||||
const cfg: OpenClawConfig = {};
|
||||
setupSessionState(cfg, process.env, tempHome);
|
||||
const confirmSkipInNonInteractive = vi.fn(async () => false);
|
||||
|
||||
await noteStateIntegrity(cfg, { confirmSkipInNonInteractive });
|
||||
|
||||
expect(confirmSkipInNonInteractive).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
message: expect.stringContaining("Create OAuth dir at"),
|
||||
}),
|
||||
);
|
||||
const stateIntegrityText = vi
|
||||
.mocked(note)
|
||||
.mock.calls.filter((call) => call[1] === "State integrity")
|
||||
.map((call) => String(call[0]))
|
||||
.join("\n");
|
||||
expect(stateIntegrityText).toContain("OAuth dir not present");
|
||||
expect(stateIntegrityText).not.toContain("CRITICAL: OAuth dir missing");
|
||||
const confirmSkipInNonInteractive = await runStateIntegrity(cfg);
|
||||
expect(confirmSkipInNonInteractive).not.toHaveBeenCalledWith(OAUTH_PROMPT_MATCHER);
|
||||
const text = stateIntegrityText();
|
||||
expect(text).toContain("OAuth dir not present");
|
||||
expect(text).not.toContain("CRITICAL: OAuth dir missing");
|
||||
});
|
||||
|
||||
it("prompts for oauth dir when whatsapp is configured", async () => {
|
||||
@@ -93,22 +100,9 @@ describe("doctor state integrity oauth dir checks", () => {
|
||||
whatsapp: {},
|
||||
},
|
||||
};
|
||||
setupSessionState(cfg, process.env, tempHome);
|
||||
const confirmSkipInNonInteractive = vi.fn(async () => false);
|
||||
|
||||
await noteStateIntegrity(cfg, { confirmSkipInNonInteractive });
|
||||
|
||||
expect(confirmSkipInNonInteractive).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
message: expect.stringContaining("Create OAuth dir at"),
|
||||
}),
|
||||
);
|
||||
const stateIntegrityText = vi
|
||||
.mocked(note)
|
||||
.mock.calls.filter((call) => call[1] === "State integrity")
|
||||
.map((call) => String(call[0]))
|
||||
.join("\n");
|
||||
expect(stateIntegrityText).toContain("CRITICAL: OAuth dir missing");
|
||||
const confirmSkipInNonInteractive = await runStateIntegrity(cfg);
|
||||
expect(confirmSkipInNonInteractive).toHaveBeenCalledWith(OAUTH_PROMPT_MATCHER);
|
||||
expect(stateIntegrityText()).toContain("CRITICAL: OAuth dir missing");
|
||||
});
|
||||
|
||||
it("prompts for oauth dir when a channel dmPolicy is pairing", async () => {
|
||||
@@ -119,15 +113,15 @@ describe("doctor state integrity oauth dir checks", () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
setupSessionState(cfg, process.env, tempHome);
|
||||
const confirmSkipInNonInteractive = vi.fn(async () => false);
|
||||
const confirmSkipInNonInteractive = await runStateIntegrity(cfg);
|
||||
expect(confirmSkipInNonInteractive).toHaveBeenCalledWith(OAUTH_PROMPT_MATCHER);
|
||||
});
|
||||
|
||||
await noteStateIntegrity(cfg, { confirmSkipInNonInteractive });
|
||||
|
||||
expect(confirmSkipInNonInteractive).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
message: expect.stringContaining("Create OAuth dir at"),
|
||||
}),
|
||||
);
|
||||
it("prompts for oauth dir when OPENCLAW_OAUTH_DIR is explicitly configured", async () => {
|
||||
process.env.OPENCLAW_OAUTH_DIR = path.join(tempHome, ".oauth");
|
||||
const cfg: OpenClawConfig = {};
|
||||
const confirmSkipInNonInteractive = await runStateIntegrity(cfg);
|
||||
expect(confirmSkipInNonInteractive).toHaveBeenCalledWith(OAUTH_PROMPT_MATCHER);
|
||||
expect(stateIntegrityText()).toContain("CRITICAL: OAuth dir missing");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user