test: scope post-attach sentinel env

This commit is contained in:
Shakker
2026-06-24 04:19:31 +01:00
parent 7b9f4aefa2
commit c2d102b6ee
+19 -14
View File
@@ -563,15 +563,19 @@ describe("startGatewayPostAttachRuntime", () => {
it("skips heavy restart sentinel refresh when no sentinel file exists", async () => {
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-no-sentinel-"));
vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
hoisted.refreshLatestUpdateRestartSentinel.mockClear();
try {
await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => {
hoisted.refreshLatestUpdateRestartSentinel.mockClear();
const result = await testing.refreshLatestUpdateRestartSentinelIfPresent();
const result = await testing.refreshLatestUpdateRestartSentinelIfPresent();
expect(result).toBeNull();
expect(hoisted.refreshLatestUpdateRestartSentinel).not.toHaveBeenCalled();
closeOpenClawStateDatabaseForTest();
fs.rmSync(stateDir, { recursive: true, force: true });
expect(result).toBeNull();
expect(hoisted.refreshLatestUpdateRestartSentinel).not.toHaveBeenCalled();
});
} finally {
closeOpenClawStateDatabaseForTest();
fs.rmSync(stateDir, { recursive: true, force: true });
}
});
it("refreshes the restart sentinel when the sentinel row exists", async () => {
@@ -585,15 +589,16 @@ describe("startGatewayPostAttachRuntime", () => {
},
{ OPENCLAW_STATE_DIR: stateDir } as NodeJS.ProcessEnv,
);
vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
const sentinel = { kind: "update", status: "ok", ts: 1 } as const;
hoisted.refreshLatestUpdateRestartSentinel.mockClear();
hoisted.refreshLatestUpdateRestartSentinel.mockResolvedValue(sentinel);
await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => {
const sentinel = { kind: "update", status: "ok", ts: 1 } as const;
hoisted.refreshLatestUpdateRestartSentinel.mockClear();
hoisted.refreshLatestUpdateRestartSentinel.mockResolvedValue(sentinel);
const result = await testing.refreshLatestUpdateRestartSentinelIfPresent();
const result = await testing.refreshLatestUpdateRestartSentinelIfPresent();
expect(result).toBe(sentinel);
expect(hoisted.refreshLatestUpdateRestartSentinel).toHaveBeenCalledOnce();
expect(result).toBe(sentinel);
expect(hoisted.refreshLatestUpdateRestartSentinel).toHaveBeenCalledOnce();
});
} finally {
closeOpenClawStateDatabaseForTest();
fs.rmSync(stateDir, { recursive: true, force: true });