@atbash/atbash-openclaw 0.1.19-dev.2 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.test.js +57 -4
- package/package.json +2 -2
package/dist/index.test.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// execution and honors `block: true` is outside what this package (or
|
|
7
7
|
// these tests) can verify — that half depends on the OpenClaw host, which
|
|
8
8
|
// isn't in this repo.
|
|
9
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
9
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
10
10
|
const fromConfig = vi.fn();
|
|
11
11
|
const handleBeforeToolCall = vi.fn();
|
|
12
12
|
const runBootProbe = vi.fn().mockResolvedValue(undefined);
|
|
@@ -26,12 +26,20 @@ async function registerAndCapture(opts) {
|
|
|
26
26
|
fromConfig.mockReturnValue({ auth: {}, auditToolCall: opts.auditToolCall });
|
|
27
27
|
handleBeforeToolCall.mockReset().mockResolvedValue(null);
|
|
28
28
|
const on = vi.fn();
|
|
29
|
+
const hasConfig = opts.enforceDecision !== undefined || opts.judgeTimeoutMs !== undefined;
|
|
29
30
|
const api = {
|
|
30
31
|
config: {
|
|
31
32
|
plugins: {
|
|
32
|
-
entries:
|
|
33
|
-
? {
|
|
34
|
-
|
|
33
|
+
entries: hasConfig
|
|
34
|
+
? {
|
|
35
|
+
"atbash-openclaw": {
|
|
36
|
+
config: {
|
|
37
|
+
...(opts.enforceDecision !== undefined && { enforceDecision: opts.enforceDecision }),
|
|
38
|
+
...(opts.judgeTimeoutMs !== undefined && { judgeTimeoutMs: opts.judgeTimeoutMs }),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
: {},
|
|
35
43
|
},
|
|
36
44
|
},
|
|
37
45
|
logger: { info: vi.fn(), warn: vi.fn() },
|
|
@@ -163,4 +171,49 @@ describe("OpenClaw before_tool_call hook", () => {
|
|
|
163
171
|
expect(result).toMatchObject({ block: true, allow: false });
|
|
164
172
|
expect(auditToolCall).not.toHaveBeenCalled();
|
|
165
173
|
});
|
|
174
|
+
describe("judgeTimeoutMs", () => {
|
|
175
|
+
afterEach(() => {
|
|
176
|
+
vi.useRealTimers();
|
|
177
|
+
});
|
|
178
|
+
it("judge timeout fails closed by default", async () => {
|
|
179
|
+
vi.useFakeTimers();
|
|
180
|
+
const auditToolCall = vi.fn().mockReturnValue(new Promise(() => { })); // never resolves
|
|
181
|
+
const handler = await registerAndCapture({ auditToolCall, judgeTimeoutMs: 5000 });
|
|
182
|
+
const resultPromise = handler({ toolName: "wire_transfer" }, {});
|
|
183
|
+
await vi.advanceTimersByTimeAsync(5001);
|
|
184
|
+
const result = (await resultPromise);
|
|
185
|
+
expect(result).toMatchObject({ block: true, allow: false });
|
|
186
|
+
expect(result.blockReason).toContain("timed out after 5000ms");
|
|
187
|
+
});
|
|
188
|
+
it("judge timeout respects enforceDecision:false and allows through", async () => {
|
|
189
|
+
vi.useFakeTimers();
|
|
190
|
+
const auditToolCall = vi.fn().mockReturnValue(new Promise(() => { }));
|
|
191
|
+
const handler = await registerAndCapture({ auditToolCall, judgeTimeoutMs: 5000, enforceDecision: false });
|
|
192
|
+
const resultPromise = handler({ toolName: "wire_transfer" }, {});
|
|
193
|
+
await vi.advanceTimersByTimeAsync(5001);
|
|
194
|
+
const result = await resultPromise;
|
|
195
|
+
expect(result).toEqual({ allow: true });
|
|
196
|
+
});
|
|
197
|
+
it("memory guard timeout fails closed by default", async () => {
|
|
198
|
+
vi.useFakeTimers();
|
|
199
|
+
const auditToolCall = vi.fn();
|
|
200
|
+
const handler = await registerAndCapture({ auditToolCall, judgeTimeoutMs: 5000 });
|
|
201
|
+
handleBeforeToolCall.mockReturnValue(new Promise(() => { })); // never resolves
|
|
202
|
+
const resultPromise = handler({ toolName: "write", params: { path: "CLAUDE.md" } }, {});
|
|
203
|
+
await vi.advanceTimersByTimeAsync(5001);
|
|
204
|
+
const result = (await resultPromise);
|
|
205
|
+
expect(result).toMatchObject({ block: true, allow: false });
|
|
206
|
+
expect(result.blockReason).toContain("timed out after 5000ms");
|
|
207
|
+
expect(auditToolCall).not.toHaveBeenCalled();
|
|
208
|
+
});
|
|
209
|
+
it("fast judge response is unaffected by the timeout", async () => {
|
|
210
|
+
vi.useFakeTimers();
|
|
211
|
+
const auditToolCall = vi.fn().mockResolvedValue({ verdict: "ALLOW", allow: true });
|
|
212
|
+
const handler = await registerAndCapture({ auditToolCall, judgeTimeoutMs: 5000 });
|
|
213
|
+
// advance a little but not past the timeout
|
|
214
|
+
await vi.advanceTimersByTimeAsync(100);
|
|
215
|
+
const result = await handler({ toolName: "wire_transfer" }, {});
|
|
216
|
+
expect(result).toEqual({ allow: true });
|
|
217
|
+
});
|
|
218
|
+
});
|
|
166
219
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atbash/atbash-openclaw",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "OpenClaw ATBASH tool-audit plugin. Thin adapter that maps OpenClaw's before_tool_call hook onto @atbash/sdk.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
]
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@atbash/sdk": "0.
|
|
44
|
+
"@atbash/sdk": "0.8.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "^25.7.0",
|