fix(release): extend OTA sync trigger timeout

This commit is contained in:
DIYgod
2026-05-29 16:09:17 +08:00
parent 0fb64b5fb8
commit e551882bb3
3 changed files with 31 additions and 2 deletions
+16 -1
View File
@@ -11,7 +11,21 @@ import { pathToFileURL } from "node:url"
* }} TriggerOtaSyncOptions
*/
const DEFAULT_TIMEOUT_MS = 10_000
const DEFAULT_TIMEOUT_MS = 120_000
export function readOtaSyncTimeoutMs(value) {
if (!value) {
return DEFAULT_TIMEOUT_MS
}
const timeoutMs = Number(value)
if (!Number.isInteger(timeoutMs) || timeoutMs <= 0) {
throw new TypeError("OTA sync timeout must be a positive integer")
}
return timeoutMs
}
/**
* @param {TriggerOtaSyncOptions} options
@@ -81,6 +95,7 @@ async function main() {
baseUrl: process.env.OTA_BASE_URL ?? "",
token: process.env.OTA_SYNC_TOKEN ?? "",
headerName: process.env.OTA_SYNC_TOKEN_HEADER ?? "",
timeoutMs: readOtaSyncTimeoutMs(process.env.OTA_SYNC_TIMEOUT_MS),
})
console.info("Triggered OTA sync successfully")
+8
View File
@@ -25,6 +25,14 @@ afterEach(async () => {
})
describe("triggerOtaSync", () => {
it("reads a configurable OTA sync timeout", async () => {
const { readOtaSyncTimeoutMs } = await import("./trigger-ota-sync.mjs")
expect(readOtaSyncTimeoutMs()).toBe(120_000)
expect(readOtaSyncTimeoutMs("30000")).toBe(30_000)
expect(() => readOtaSyncTimeoutMs("0")).toThrow("OTA sync timeout must be a positive integer")
})
it("POSTs to /internal/sync with the configured auth header", async () => {
const requests: Array<{ method?: string; url?: string; headerValue?: string }> = []
const headerName = "x-ota-sync-token"