fix sync reliability and runtime handling

This commit is contained in:
Alex Getman
2026-08-12 13:48:10 +03:00
parent 70387a94ad
commit 99a22e11bd
13 changed files with 289 additions and 132 deletions
+4
View File
@@ -31,4 +31,8 @@ describe("loadConfig", () => {
const config = loadConfig({ BOT_MODE: "http-only", ENABLE_FDS_SLEEP_DETAILS: "false" });
expect(config.ENABLE_FDS_SLEEP_DETAILS).toBe(false);
});
test("rejects an invalid timezone", () => {
expect(() => loadConfig({ BOT_MODE: "http-only", TZ: "not/a-timezone" })).toThrow(ConfigurationError);
});
});
+7 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test";
import { esc, minutes, stepBar } from "../src/bot/formatting.js";
import { epoch, esc, minutes, stepBar } from "../src/bot/formatting.js";
describe("bot formatting", () => {
test("escapes Telegram HTML and formats health values", () => {
@@ -7,4 +7,10 @@ describe("bot formatting", () => {
expect(minutes(396)).toBe("6 h 36 min");
expect(stepBar(5000)).toContain("50%");
});
test("formats timestamps in the configured timezone", () => {
const timestamp = Date.parse("2026-08-12T00:00:00Z") / 1000;
expect(epoch(timestamp, false, "en", "UTC")).toContain("00:00");
expect(epoch(timestamp, false, "en", "Europe/Moscow")).toContain("03:00");
});
});
+10 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test";
import { mkdtempSync, rmSync } from "node:fs";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { withExclusiveFileLock } from "../src/storage/secure-files.js";
@@ -11,4 +11,13 @@ describe("file locks", () => {
await expect(withExclusiveFileLock(path, async () => "second")).resolves.toBe("second");
rmSync(directory, { recursive: true, force: true });
});
test("reclaims a lock whose owner process is gone", async () => {
const directory = mkdtempSync(join(process.env.TMPDIR ?? "/tmp", "miband-lock-stale-"));
const path = join(directory, "sync.lock");
mkdirSync(`${path}.d`);
writeFileSync(join(`${path}.d`, "owner"), "pid=2147483647 time=0\n");
await expect(withExclusiveFileLock(path, async () => "reclaimed")).resolves.toBe("reclaimed");
rmSync(directory, { recursive: true, force: true });
});
});