test: add unit tests and remove dead code

- Add vitest with 98 tests across 6 test files covering:
  - cosy.ts: URL builders, mode detection, model name mapping
  - thinking-parser.ts: ThinkingTagParser with all tag variants and chunked streaming
  - transform.ts: getContentText, transformTools, transformMessagesForQoder
  - pat.ts: isPatRefresh, encodePatRefresh/decodePatRefresh roundtrip
  - qoder-encoding.ts: custom encoding correctness and edge cases
  - models.ts: static model definitions integrity checks

- Remove dead code:
  - QODER_CN_DIRECT_BASE_URL (unused export in cosy.ts)
  - THINKING_START_TAG / THINKING_END_TAG (unused constants in thinking-parser.ts)

- Add test/test:watch scripts to package.json
This commit is contained in:
Simon Shi
2026-06-27 20:03:05 +08:00
parent 2d6e1c660b
commit c83fa0b8f3
10 changed files with 2220 additions and 9 deletions
+1 -4
View File
@@ -5,9 +5,6 @@ import type {
ThinkingContent,
} from "@earendil-works/pi-ai";
export const THINKING_START_TAG = "<thinking>";
export const THINKING_END_TAG = "</thinking>";
const THINKING_TAG_VARIANTS: Array<{ open: string; close: string }> = [
{ open: "<thinking>", close: "</thinking>" },
{ open: "<think>", close: "</think>" },
@@ -38,7 +35,7 @@ export class ThinkingTagParser {
private thinkingBlockIndex: number | null = null;
private textBlockIndex: number | null = null;
private lastTextBlockIndex: number | null = null;
private activeEndTag: string = THINKING_END_TAG;
private activeEndTag: string = THINKING_TAG_VARIANTS[0].close;
constructor(
private output: AssistantMessage,