























@@ -1,6 +1,7 @@
11import fs from "node:fs";
22import { describe, expect, it, vi } from "vitest";
33import {
4+readAllowFromFileWithExists,
45readAllowFromFileSyncWithExists,
56resolveAllowFromAccountId,
67resolveAllowFromFilePath,
@@ -73,6 +74,52 @@ describe("allow-from store file keys", () => {
7374});
74757576describe("allow-from store file reads", () => {
77+it("rethrows unexpected async read errors after a successful stat", async () => {
78+const error = fsError("permission denied", "EACCES");
79+const statSpy = vi.spyOn(fs.promises, "stat").mockResolvedValue({
80+mtimeMs: 1,
81+size: 2,
82+} as fs.Stats);
83+const readSpy = vi.spyOn(fs.promises, "readFile").mockRejectedValue(error);
84+85+try {
86+await expect(
87+readAllowFromFileWithExists({
88+cacheNamespace: "test-async-read-error",
89+filePath: "/tmp/openclaw-allowFrom.json",
90+normalizeStore: () => [],
91+}),
92+).rejects.toBe(error);
93+} finally {
94+readSpy.mockRestore();
95+statSpy.mockRestore();
96+}
97+});
98+99+it("rethrows unexpected sync read errors after a successful stat", () => {
100+const error = fsError("permission denied", "EACCES");
101+const statSpy = vi.spyOn(fs, "statSync").mockReturnValue({
102+mtimeMs: 1,
103+size: 2,
104+} as fs.Stats);
105+const readSpy = vi.spyOn(fs, "readFileSync").mockImplementation(() => {
106+throw error;
107+});
108+109+try {
110+expect(() =>
111+readAllowFromFileSyncWithExists({
112+cacheNamespace: "test-sync-read-error",
113+filePath: "/tmp/openclaw-allowFrom.json",
114+normalizeStore: () => [],
115+}),
116+).toThrow(error);
117+} finally {
118+readSpy.mockRestore();
119+statSpy.mockRestore();
120+}
121+});
122+76123it("rethrows unexpected sync stat errors", () => {
77124const error = fsError("permission denied", "EACCES");
78125const statSpy = vi.spyOn(fs, "statSync").mockImplementation(() => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。