mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-18 05:20:48 +00:00
refactor(lanes-tests): share table-driven assertions
This commit is contained in:
@@ -5,40 +5,52 @@ import { resolveGlobalLane, resolveSessionLane } from "./lanes.js";
|
||||
describe("resolveGlobalLane", () => {
|
||||
it("defaults to main lane when no lane is provided", () => {
|
||||
expect(resolveGlobalLane()).toBe(CommandLane.Main);
|
||||
expect(resolveGlobalLane("")).toBe(CommandLane.Main);
|
||||
expect(resolveGlobalLane(" ")).toBe(CommandLane.Main);
|
||||
for (const lane of ["", " "]) {
|
||||
expect(resolveGlobalLane(lane)).toBe(CommandLane.Main);
|
||||
}
|
||||
});
|
||||
|
||||
it("maps cron lane to nested lane to prevent deadlocks", () => {
|
||||
// When cron jobs trigger nested agent runs, the outer execution holds
|
||||
// the cron lane slot. Inner work must use a separate lane to avoid
|
||||
// deadlock. See: https://github.com/openclaw/openclaw/issues/44805
|
||||
expect(resolveGlobalLane("cron")).toBe(CommandLane.Nested);
|
||||
expect(resolveGlobalLane(" cron ")).toBe(CommandLane.Nested);
|
||||
for (const lane of ["cron", " cron "]) {
|
||||
expect(resolveGlobalLane(lane)).toBe(CommandLane.Nested);
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves other lanes as-is", () => {
|
||||
expect(resolveGlobalLane("main")).toBe(CommandLane.Main);
|
||||
expect(resolveGlobalLane("subagent")).toBe(CommandLane.Subagent);
|
||||
expect(resolveGlobalLane("nested")).toBe(CommandLane.Nested);
|
||||
expect(resolveGlobalLane("custom-lane")).toBe("custom-lane");
|
||||
expect(resolveGlobalLane(" custom ")).toBe("custom");
|
||||
for (const [lane, expected] of [
|
||||
["main", CommandLane.Main],
|
||||
["subagent", CommandLane.Subagent],
|
||||
["nested", CommandLane.Nested],
|
||||
["custom-lane", "custom-lane"],
|
||||
[" custom ", "custom"],
|
||||
] as const) {
|
||||
expect(resolveGlobalLane(lane)).toBe(expected);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveSessionLane", () => {
|
||||
it("defaults to main lane and prefixes with session:", () => {
|
||||
expect(resolveSessionLane("")).toBe("session:main");
|
||||
expect(resolveSessionLane(" ")).toBe("session:main");
|
||||
for (const lane of ["", " "]) {
|
||||
expect(resolveSessionLane(lane)).toBe("session:main");
|
||||
}
|
||||
});
|
||||
|
||||
it("adds session: prefix if not present", () => {
|
||||
expect(resolveSessionLane("abc123")).toBe("session:abc123");
|
||||
expect(resolveSessionLane(" xyz ")).toBe("session:xyz");
|
||||
for (const [lane, expected] of [
|
||||
["abc123", "session:abc123"],
|
||||
[" xyz ", "session:xyz"],
|
||||
] as const) {
|
||||
expect(resolveSessionLane(lane)).toBe(expected);
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves existing session: prefix", () => {
|
||||
expect(resolveSessionLane("session:abc")).toBe("session:abc");
|
||||
expect(resolveSessionLane("session:main")).toBe("session:main");
|
||||
for (const lane of ["session:abc", "session:main"]) {
|
||||
expect(resolveSessionLane(lane)).toBe(lane);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user