Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

Attributes.test.ts

46 lines1.2 KB

1import { assert, describe, it } from "@effect/vitest";
2​
3import { compactTraceAttributes, normalizeModelMetricLabel } from "./Attributes.ts";
4​
5describe("Attributes", () => {
6 it("normalizes circular arrays, maps, and sets without recursing forever", () => {
7 const array: Array<unknown> = ["alpha"];
8 array.push(array);
9​
10 const map = new Map<string, unknown>();
11 map.set("self", map);
12​
13 const set = new Set<unknown>();
14 set.add(set);
15​
16 assert.deepStrictEqual(
17 compactTraceAttributes({
18 array,
19 map,
20 set,
21 }),
22 {
23 array: ["alpha", "[Circular]"],
24 map: { self: "[Circular]" },
25 set: ["[Circular]"],
26 },
27 );
28 });
29​
30 it("normalizes invalid dates without throwing", () => {
31 assert.deepStrictEqual(
32 compactTraceAttributes({
33 invalidDate: new Date("not-a-real-date"),
34 }),
35 {
36 invalidDate: "Invalid Date",
37 },
38 );
39 });
40​
41 it("groups GPT-family models under a shared metric label", () => {
42 assert.strictEqual(normalizeModelMetricLabel("gpt-4o"), "gpt");
43 assert.strictEqual(normalizeModelMetricLabel("gpt-5.4"), "gpt");
44 assert.strictEqual(normalizeModelMetricLabel("claude-sonnet-4"), "claude");
45 });
46});