mirror of
http://192.168.0.88:13333/lywsvip/openclaw-zero-token.git
synced 2026-06-06 11:40:58 +08:00
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { createTypingStartGuard } from "./typing-start-guard.js";
|
|
|
|
describe("createTypingStartGuard", () => {
|
|
it("skips starts when sealed", async () => {
|
|
const start = vi.fn();
|
|
const guard = createTypingStartGuard({
|
|
isSealed: () => true,
|
|
});
|
|
|
|
const result = await guard.run(start);
|
|
expect(result).toBe("skipped");
|
|
expect(start).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("trips breaker after max consecutive failures", async () => {
|
|
const onStartError = vi.fn();
|
|
const onTrip = vi.fn();
|
|
const guard = createTypingStartGuard({
|
|
isSealed: () => false,
|
|
onStartError,
|
|
onTrip,
|
|
maxConsecutiveFailures: 2,
|
|
});
|
|
const start = vi.fn().mockRejectedValue(new Error("fail"));
|
|
|
|
const first = await guard.run(start);
|
|
const second = await guard.run(start);
|
|
const third = await guard.run(start);
|
|
|
|
expect(first).toBe("failed");
|
|
expect(second).toBe("tripped");
|
|
expect(third).toBe("skipped");
|
|
expect(onStartError).toHaveBeenCalledTimes(2);
|
|
expect(onTrip).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("resets breaker state", async () => {
|
|
const guard = createTypingStartGuard({
|
|
isSealed: () => false,
|
|
maxConsecutiveFailures: 1,
|
|
});
|
|
const failStart = vi.fn().mockRejectedValue(new Error("fail"));
|
|
const okStart = vi.fn().mockResolvedValue(undefined);
|
|
|
|
const trip = await guard.run(failStart);
|
|
expect(trip).toBe("tripped");
|
|
expect(guard.isTripped()).toBe(true);
|
|
|
|
guard.reset();
|
|
const started = await guard.run(okStart);
|
|
expect(started).toBe("started");
|
|
expect(guard.isTripped()).toBe(false);
|
|
});
|
|
|
|
it("rethrows start errors when configured", async () => {
|
|
const guard = createTypingStartGuard({
|
|
isSealed: () => false,
|
|
rethrowOnError: true,
|
|
});
|
|
const start = vi.fn().mockRejectedValue(new Error("boom"));
|
|
|
|
await expect(guard.run(start)).rejects.toThrow("boom");
|
|
});
|
|
});
|