fix: stop partial replies for whatsapp/telegram surfaces

This commit is contained in:
Peter Steinberger
2025-12-09 01:40:51 +01:00
parent e44ed2681f
commit 5bfecc6152
6 changed files with 107 additions and 88 deletions

View File

@@ -5,8 +5,8 @@ import {
detectRuntime,
isAtLeast,
parseSemver,
runtimeSatisfies,
type RuntimeDetails,
runtimeSatisfies,
} from "./runtime-guard.js";
describe("runtime-guard", () => {
@@ -17,9 +17,24 @@ describe("runtime-guard", () => {
});
it("compares versions correctly", () => {
expect(isAtLeast({ major: 22, minor: 0, patch: 0 }, { major: 22, minor: 0, patch: 0 })).toBe(true);
expect(isAtLeast({ major: 22, minor: 1, patch: 0 }, { major: 22, minor: 0, patch: 0 })).toBe(true);
expect(isAtLeast({ major: 21, minor: 9, patch: 0 }, { major: 22, minor: 0, patch: 0 })).toBe(false);
expect(
isAtLeast(
{ major: 22, minor: 0, patch: 0 },
{ major: 22, minor: 0, patch: 0 },
),
).toBe(true);
expect(
isAtLeast(
{ major: 22, minor: 1, patch: 0 },
{ major: 22, minor: 0, patch: 0 },
),
).toBe(true);
expect(
isAtLeast(
{ major: 21, minor: 9, patch: 0 },
{ major: 22, minor: 0, patch: 0 },
),
).toBe(false);
});
it("validates runtime thresholds", () => {
@@ -49,7 +64,9 @@ describe("runtime-guard", () => {
pathEnv: "/usr/bin",
};
expect(() => assertSupportedRuntime(runtime, details)).toThrow("exit");
expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("requires Node"));
expect(runtime.error).toHaveBeenCalledWith(
expect.stringContaining("requires Node"),
);
});
it("returns silently when runtime meets requirements", () => {
@@ -68,4 +85,3 @@ describe("runtime-guard", () => {
expect(runtime.exit).not.toHaveBeenCalled();
});
});

View File

@@ -43,10 +43,16 @@ export function isAtLeast(version: Semver | null, minimum: Semver): boolean {
export function detectRuntime(): RuntimeDetails {
const isBun = Boolean(process.versions?.bun);
const kind: RuntimeKind = isBun ? "bun" : process.versions?.node ? "node" : "unknown";
const kind: RuntimeKind = isBun
? "bun"
: process.versions?.node
? "node"
: "unknown";
const bunVersion =
(globalThis as { Bun?: { version?: string } })?.Bun?.version ?? null;
const version = isBun
? process.versions?.bun ?? (globalThis as any)?.Bun?.version ?? null
: process.versions?.node ?? null;
? (process.versions?.bun ?? bunVersion)
: (process.versions?.node ?? null);
return {
kind,
@@ -70,7 +76,10 @@ export function assertSupportedRuntime(
if (runtimeSatisfies(details)) return;
const versionLabel = details.version ?? "unknown";
const runtimeLabel = details.kind === "unknown" ? "unknown runtime" : `${details.kind} ${versionLabel}`;
const runtimeLabel =
details.kind === "unknown"
? "unknown runtime"
: `${details.kind} ${versionLabel}`;
const execLabel = details.execPath ?? "unknown";
runtime.error(
@@ -87,4 +96,3 @@ export function assertSupportedRuntime(
);
runtime.exit(1);
}