Unify assistance link duration parsing with hour floor and stderr hints
This commit is contained in:
1 parent
c094980ae5
commit
0296c2bff2
4 files changed
+133
-39
No files matched your search
+19
-7
@@ -119,7 +119,7 @@ describe("option helpers", () => {
|
||||
expect(splitOption(true)).toBeUndefined();
|
||||
});
|
||||
|
||||
test("parseDelegationExpireHours parses days, hours, and limits to 1..168", () => {
|
||||
test("parseDelegationExpireHours parses days, hours, rounds down with stderr notice, and clamps to 1..168", () => {
|
||||
expect(parseDelegationExpireHours(undefined)).toBe(24);
|
||||
expect(parseDelegationExpireHours("7d")).toBe(168);
|
||||
expect(parseDelegationExpireHours("1d")).toBe(24);
|
||||
@@ -128,13 +128,20 @@ describe("option helpers", () => {
|
||||
expect(parseDelegationExpireHours("168")).toBe(168);
|
||||
expect(parseDelegationExpireHours(168)).toBe(168);
|
||||
expect(parseDelegationExpireHours("86400")).toBe(24);
|
||||
expect(parseDelegationExpireHours("7200s")).toBe(2);
|
||||
|
||||
expect(() => parseDelegationExpireHours("8d")).toThrow("1 到 168 小时(最大 7 天)");
|
||||
expect(() => parseDelegationExpireHours("0h")).toThrow("1 到 168 小时(最大 7 天)");
|
||||
expect(() => parseDelegationExpireHours("invalid")).toThrow("Must be a valid duration");
|
||||
// Floor fractional hours and clamp minimum to 1h
|
||||
expect(parseDelegationExpireHours("90m")).toBe(1);
|
||||
expect(parseDelegationExpireHours("1.5h")).toBe(1);
|
||||
expect(parseDelegationExpireHours("30m")).toBe(1);
|
||||
expect(parseDelegationExpireHours("1800s")).toBe(1);
|
||||
|
||||
expect(() => parseDelegationExpireHours("8d")).toThrow("最多为 7 天 (168h)");
|
||||
expect(() => parseDelegationExpireHours("0h")).toThrow("必须为大于 0 的有效时长");
|
||||
expect(() => parseDelegationExpireHours("invalid")).toThrow("必须为有效时长格式");
|
||||
});
|
||||
|
||||
test("parseHoseExpireSeconds parses days, hours, minutes, and raw seconds", () => {
|
||||
test("parseHoseExpireSeconds parses days, hours, minutes, raw seconds, and converts unitless small numbers to hours", () => {
|
||||
expect(parseHoseExpireSeconds(undefined)).toBe(7200);
|
||||
expect(parseHoseExpireSeconds("7200")).toBe(7200);
|
||||
expect(parseHoseExpireSeconds(7200)).toBe(7200);
|
||||
@@ -142,8 +149,13 @@ describe("option helpers", () => {
|
||||
expect(parseHoseExpireSeconds("7d")).toBe(604800);
|
||||
expect(parseHoseExpireSeconds("30m")).toBe(1800);
|
||||
|
||||
expect(() => parseHoseExpireSeconds("0s")).toThrow("Must be a positive number of seconds");
|
||||
expect(() => parseHoseExpireSeconds("invalid")).toThrow("Must be a valid duration");
|
||||
// Unitless small numbers (<= 168) convert to hours automatically
|
||||
expect(parseHoseExpireSeconds(2)).toBe(7200);
|
||||
expect(parseHoseExpireSeconds("2")).toBe(7200);
|
||||
expect(parseHoseExpireSeconds("24")).toBe(86400);
|
||||
|
||||
expect(() => parseHoseExpireSeconds("0s")).toThrow("必须为大于 0 的有效时长");
|
||||
expect(() => parseHoseExpireSeconds("invalid")).toThrow("必须为有效时长");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user