fix: stabilize tests and logging
This commit is contained in:
@@ -5,7 +5,7 @@ import { isImageDimensionErrorMessage, parseImageDimensionError } from "./pi-emb
|
||||
describe("image dimension errors", () => {
|
||||
it("parses anthropic image dimension errors", () => {
|
||||
const raw =
|
||||
"400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.84.content.1.image.source.base64.data: At least one of the image dimensions exceed max allowed size for many-image requests: 2000 pixels\"}}";
|
||||
'400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.84.content.1.image.source.base64.data: At least one of the image dimensions exceed max allowed size for many-image requests: 2000 pixels"}}';
|
||||
const parsed = parseImageDimensionError(raw);
|
||||
expect(parsed).not.toBeNull();
|
||||
expect(parsed?.maxDimensionPx).toBe(2000);
|
||||
|
||||
@@ -25,7 +25,7 @@ describe("isCloudCodeAssistFormatError", () => {
|
||||
expect(isCloudCodeAssistFormatError("rate limit exceeded")).toBe(false);
|
||||
expect(
|
||||
isCloudCodeAssistFormatError(
|
||||
"400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.84.content.1.image.source.base64.data: At least one of the image dimensions exceed max allowed size for many-image requests: 2000 pixels\"}}",
|
||||
'400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.84.content.1.image.source.base64.data: At least one of the image dimensions exceed max allowed size for many-image requests: 2000 pixels"}}',
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
@@ -89,7 +89,6 @@ let runEmbeddedPiAgent: typeof import("./pi-embedded-runner.js").runEmbeddedPiAg
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.useRealTimers();
|
||||
vi.resetModules();
|
||||
({ runEmbeddedPiAgent } = await import("./pi-embedded-runner.js"));
|
||||
});
|
||||
|
||||
|
||||
@@ -91,7 +91,6 @@ let runEmbeddedPiAgent: typeof import("./pi-embedded-runner.js").runEmbeddedPiAg
|
||||
|
||||
beforeAll(async () => {
|
||||
vi.useRealTimers();
|
||||
vi.resetModules();
|
||||
mockPiAi();
|
||||
({ runEmbeddedPiAgent } = await import("./pi-embedded-runner.js"));
|
||||
}, 20_000);
|
||||
|
||||
@@ -41,7 +41,7 @@ describe("detectImageReferences", () => {
|
||||
expect(refs[0]?.raw).toBe("~/Pictures/vacation.png");
|
||||
expect(refs[0]?.type).toBe("path");
|
||||
// Resolved path should expand ~
|
||||
expect(refs[0]?.resolved).not.toContain("~");
|
||||
expect(refs[0]?.resolved?.startsWith("~")).toBe(false);
|
||||
});
|
||||
|
||||
it("detects multiple image references in a prompt", () => {
|
||||
|
||||
@@ -109,11 +109,7 @@ function buildMessagingSection(params: {
|
||||
];
|
||||
}
|
||||
|
||||
function buildDocsSection(params: {
|
||||
docsPath?: string;
|
||||
isMinimal: boolean;
|
||||
readToolName: string;
|
||||
}) {
|
||||
function buildDocsSection(params: { docsPath?: string; isMinimal: boolean; readToolName: string }) {
|
||||
const docsPath = params.docsPath?.trim();
|
||||
if (!docsPath || params.isMinimal) return [];
|
||||
return [
|
||||
|
||||
@@ -58,7 +58,12 @@ async function resizeImageBase64IfNeeded(params: {
|
||||
const height = meta?.height;
|
||||
const overBytes = buf.byteLength > params.maxBytes;
|
||||
const hasDimensions = typeof width === "number" && typeof height === "number";
|
||||
if (hasDimensions && !overBytes && width <= params.maxDimensionPx && height <= params.maxDimensionPx) {
|
||||
if (
|
||||
hasDimensions &&
|
||||
!overBytes &&
|
||||
width <= params.maxDimensionPx &&
|
||||
height <= params.maxDimensionPx
|
||||
) {
|
||||
return {
|
||||
base64: params.base64,
|
||||
mimeType: params.mimeType,
|
||||
@@ -67,7 +72,10 @@ async function resizeImageBase64IfNeeded(params: {
|
||||
height,
|
||||
};
|
||||
}
|
||||
if (hasDimensions && (width > params.maxDimensionPx || height > params.maxDimensionPx || overBytes)) {
|
||||
if (
|
||||
hasDimensions &&
|
||||
(width > params.maxDimensionPx || height > params.maxDimensionPx || overBytes)
|
||||
) {
|
||||
log.warn("Image exceeds limits; resizing", {
|
||||
label: params.label,
|
||||
width,
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { getChannelPlugin, normalizeChannelId } from "../../channels/plugins/index.js";
|
||||
import {
|
||||
getChannelPlugin,
|
||||
normalizeChannelId as normalizeAnyChannelId,
|
||||
} from "../../channels/plugins/index.js";
|
||||
import { normalizeChannelId as normalizeChatChannelId } from "../../channels/registry.js";
|
||||
import type { ClawdbotConfig } from "../../config/config.js";
|
||||
|
||||
const ANNOUNCE_SKIP_TOKEN = "ANNOUNCE_SKIP";
|
||||
@@ -21,7 +25,8 @@ export function resolveAnnounceTargetFromKey(sessionKey: string): AnnounceTarget
|
||||
const id = rest.join(":").trim();
|
||||
if (!id) return null;
|
||||
if (!channelRaw) return null;
|
||||
const normalizedChannel = normalizeChannelId(channelRaw);
|
||||
const normalizedChannel =
|
||||
normalizeAnyChannelId(channelRaw) ?? normalizeChatChannelId(channelRaw);
|
||||
const channel = normalizedChannel ?? channelRaw.toLowerCase();
|
||||
const kindTarget = (() => {
|
||||
if (!normalizedChannel) return id;
|
||||
|
||||
Reference in New Issue
Block a user