@letta-ai/letta-code 0.23.10 → 0.23.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letta-ai/letta-code",
3
- "version": "0.23.10",
3
+ "version": "0.23.11",
4
4
  "description": "Letta Code is a CLI tool for interacting with stateful Letta agents from the terminal.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -70,6 +70,7 @@
70
70
  "lint": "bunx --bun @biomejs/biome@2.2.5 check src",
71
71
  "fix": "bunx --bun @biomejs/biome@2.2.5 check --write src",
72
72
  "typecheck": "tsc --noEmit",
73
+ "check:test-mock-isolation": "bun run scripts/check-test-mock-isolation.js",
73
74
  "check": "bun run scripts/check.js",
74
75
  "dev": "LETTA_DEBUG=${LETTA_DEBUG:-1} LETTA_RESPONSES_WS=${LETTA_RESPONSES_WS:-1} bun --loader:.md=text --loader:.mdx=text --loader:.txt=text run src/index.ts",
75
76
  "build": "node scripts/postinstall-patches.js && bun run build.js",
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import { readdirSync, readFileSync } from "node:fs";
4
+ import { join, relative } from "node:path";
5
+
6
+ const rootDir = process.cwd();
7
+ const testsDir = join(rootDir, "src", "tests");
8
+
9
+ function collectTestFiles(dir) {
10
+ const entries = readdirSync(dir, { withFileTypes: true });
11
+ const files = [];
12
+
13
+ for (const entry of entries) {
14
+ const fullPath = join(dir, entry.name);
15
+ if (entry.isDirectory()) {
16
+ files.push(...collectTestFiles(fullPath));
17
+ continue;
18
+ }
19
+ if (
20
+ entry.isFile() &&
21
+ (entry.name.endsWith(".test.ts") || entry.name.endsWith(".test.tsx"))
22
+ ) {
23
+ files.push(fullPath);
24
+ }
25
+ }
26
+
27
+ return files;
28
+ }
29
+
30
+ const mockModulePattern = /\bmock\.module\s*\(\s*(["'`])([^"'`]+)\1/g;
31
+ const restoreHookPattern =
32
+ /\bafter(?:All|Each)\s*\(\s*(?:async\s*)?(?:\([^)]*\)|[A-Za-z_$][\w$]*)\s*=>[\s\S]*?\bmock\.restore\s*\(/m;
33
+ const restoreHookFunctionPattern =
34
+ /\bafter(?:All|Each)\s*\(\s*function\b[\s\S]*?\bmock\.restore\s*\(/m;
35
+
36
+ const failures = [];
37
+
38
+ for (const filePath of collectTestFiles(testsDir)) {
39
+ const sourceText = readFileSync(filePath, "utf8");
40
+ const mockedModules = Array.from(
41
+ sourceText.matchAll(mockModulePattern),
42
+ (match) => match[2] ?? "<dynamic module>",
43
+ );
44
+
45
+ if (mockedModules.length === 0) continue;
46
+
47
+ const hasRestoreHook =
48
+ restoreHookPattern.test(sourceText) ||
49
+ restoreHookFunctionPattern.test(sourceText);
50
+ if (hasRestoreHook) continue;
51
+
52
+ failures.push({
53
+ filePath,
54
+ mockedModules,
55
+ });
56
+ }
57
+
58
+ if (failures.length > 0) {
59
+ console.error(
60
+ "❌ Found test files that call mock.module() without a top-level afterEach/afterAll hook that calls mock.restore().\n",
61
+ );
62
+
63
+ for (const failure of failures) {
64
+ const relPath = relative(rootDir, failure.filePath);
65
+ console.error(`- ${relPath}`);
66
+ console.error(` mocked modules: ${failure.mockedModules.join(", ")}`);
67
+ }
68
+
69
+ console.error(
70
+ "\nWhy this fails: Bun module mocks are process-global and can leak across files in the shared module cache.",
71
+ );
72
+ console.error(
73
+ "Add a top-level afterEach(() => { mock.restore(); }) or afterAll(() => { mock.restore(); }) hook, or remove the module mock in favor of dependency injection.",
74
+ );
75
+ process.exit(1);
76
+ }
77
+
78
+ console.log("✅ No unguarded mock.module() usage found.");
package/scripts/check.js CHANGED
@@ -7,6 +7,19 @@ console.log("🔍 Running lint and type checks...\n");
7
7
 
8
8
  let failed = false;
9
9
 
10
+ // Run test mock isolation check
11
+ console.log("🧪 Checking Bun module mock isolation...");
12
+ try {
13
+ await $`bun run check:test-mock-isolation`;
14
+ console.log("✅ Mock isolation check passed\n");
15
+ } catch (error) {
16
+ console.error("❌ Mock isolation check failed\n");
17
+ console.error(
18
+ "Add a top-level mock.restore() teardown hook to any test file using mock.module(), or remove the module mock.\n",
19
+ );
20
+ failed = true;
21
+ }
22
+
10
23
  // Run lint
11
24
  console.log("📝 Running Biome linter...");
12
25
  try {