Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Accept epoch timestamps sent as strings in expiresAt (#1929)

Regan Bell3608d36f912b
diff --git a/src/api/expiry.ts b/src/api/expiry.ts
index 058f3b544..8554f72c4 100644
--- a/src/api/expiry.ts
+++ b/src/api/expiry.ts
@@ -7,12 +7,13 @@ export type InboundExpiry = { ok: true; value?: number } | { ok: false; message:
export function normalizeInboundExpiresAt(value: unknown, field = "expiresAt"): InboundExpiry {
if (value === undefined) return { ok: true };
+ const raw = typeof value === "string" && /^\s*\d+\s*$/.test(value) ? Number(value) : value;
let ms: number;
- if (typeof value === "number") {
- if (!Number.isFinite(value)) return bad(field);
- ms = value < SECONDS_VS_MS_CUTOFF ? value * 1000 : value;
- } else if (typeof value === "string") {
- const trimmed = value.trim();
+ if (typeof raw === "number") {
+ if (!Number.isFinite(raw)) return bad(field);
+ ms = raw < SECONDS_VS_MS_CUTOFF ? raw * 1000 : raw;
+ } else if (typeof raw === "string") {
+ const trimmed = raw.trim();
if (!trimmed) return bad(field);
ms = Date.parse(trimmed);
} else {
diff --git a/test/inbound-expiry.test.ts b/test/inbound-expiry.test.ts
new file mode 100644
index 000000000..5c7051593
--- /dev/null
+++ b/test/inbound-expiry.test.ts
@@ -0,0 +1,15 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { normalizeInboundExpiresAt } from "../src/api/expiry.ts";
+
+test("expiresAt accepts epoch seconds and milliseconds sent as digit strings", () => {
+ assert.deepEqual(normalizeInboundExpiresAt("1790000000"), { ok: true, value: 1_790_000_000_000 });
+ assert.deepEqual(normalizeInboundExpiresAt(" 1790000000000 "), { ok: true, value: 1_790_000_000_000 });
+ assert.deepEqual(normalizeInboundExpiresAt(1_790_000_000), { ok: true, value: 1_790_000_000_000 });
+ assert.deepEqual(normalizeInboundExpiresAt("2026-09-21T12:00:00Z"), {
+ ok: true,
+ value: Date.UTC(2026, 8, 21, 12),
+ });
+ assert.equal(normalizeInboundExpiresAt("").ok, false);
+ assert.equal(normalizeInboundExpiresAt("12").ok, false);
+});