2026-01-14 01:08:15 +00:00
import { describe , expect , it } from "vitest" ;
import { isCloudCodeAssistFormatError } from "./pi-embedded-helpers.js" ;
import { DEFAULT_AGENTS_FILENAME } from "./workspace.js" ;
2026-01-14 14:31:43 +00:00
const _makeFile = ( overrides : Partial < WorkspaceBootstrapFile > ) : WorkspaceBootstrapFile = > ( {
2026-01-14 01:08:15 +00:00
name : DEFAULT_AGENTS_FILENAME ,
path : "/tmp/AGENTS.md" ,
content : "" ,
missing : false ,
. . . overrides ,
} ) ;
describe ( "isCloudCodeAssistFormatError" , ( ) = > {
it ( "matches format errors" , ( ) = > {
const samples = [
"INVALID_REQUEST_ERROR: string should match pattern" ,
"messages.1.content.1.tool_use.id" ,
"tool_use.id should match pattern" ,
"invalid request format" ,
] ;
for ( const sample of samples ) {
expect ( isCloudCodeAssistFormatError ( sample ) ) . toBe ( true ) ;
}
} ) ;
it ( "ignores unrelated errors" , ( ) = > {
expect ( isCloudCodeAssistFormatError ( "rate limit exceeded" ) ) . toBe ( false ) ;
2026-01-18 15:19:25 +00:00
expect (
isCloudCodeAssistFormatError (
2026-01-18 18:43:31 +00:00
'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"}}' ,
2026-01-18 15:19:25 +00:00
) ,
) . toBe ( false ) ;
2026-01-14 01:08:15 +00:00
} ) ;
} ) ;