fix(tools): clear every type error under packages/tools/test

`claude-memory.ts` moved to src/ and five files in test/ kept importing
`./claude-memory`; the Mastra and AI-SDK fixtures drifted behind their
installed types. Together these left `bunx tsc --noEmit` unusable for the
package.

- repoint the five `./claude-memory` imports at `../src/claude-memory`
- add the `state` property Mastra now requires on ProcessInputArgs and
  ProcessOutputResultArgs (35 fixtures)
- add `totalTokens` to the two LanguageModelV2Usage fixtures and drop the
  `rawCall` property the type no longer has
- iterate with `.entries()` instead of indexing, which was tripping
  noUncheckedIndexedAccess once the files started resolving
- pass containerTag/customId through options in test-supermemory.ts, matching
  the current `withSupermemory` signature
- exclude test/chatapp: a standalone Next.js demo with its own package.json,
  lockfile and tsconfig that has no business in this package's program

Repointing the import also made test/claude-memory.test.ts loadable again, and
it turned out to be a live-API suite: gate it behind SUPERMEMORY_API_KEY the
same way the other integration suites are, so `vitest run` no longer collects
a dozen 401s.
This commit is contained in:
rajashidattapy 2026-08-20 00:27:14 +05:30 • committed by rishibalanagu0108
parent d42e71f8bb
commit 5db9ceaba2
10 changed files with 85 additions and 28 deletions

View file

@ -10,7 +10,9 @@ const openai = new OpenAI({
})
// Wrap OpenAI client with supermemory
const openaiWithSupermemory = withSupermemory(openai, "test_user_123", {
const openaiWithSupermemory = withSupermemory(openai, {
containerTag: "test_user_123",
customId: "test_user_123_chat",
verbose: true, // Enable logging to see what's happening
mode: "full", // Search both profile and query memories
addMemory: "always", // Auto-save conversations as memories

View file

@ -5,7 +5,10 @@
*/
import Anthropic from "@anthropic-ai/sdk"
import { createClaudeMemoryTool } from "./claude-memory"
import {
createClaudeMemoryTool,
type MemoryCommand,
} from "../src/claude-memory"
import "dotenv/config"
/**
@ -36,7 +39,7 @@ async function chatWithMemoryTool() {
})
// Conversation messages
const messages: Anthropic.Messages.MessageParam[] = [
const messages: Anthropic.Beta.Messages.BetaMessageParam[] = [
{
role: "user",
content:
@ -44,7 +47,7 @@ async function chatWithMemoryTool() {
},
]
console.log("💬 User:", messages[0].content)
console.log("💬 User:", messages[0]?.content)
console.log("\n🔄 Sending to Claude with memory tool...")
try {
@ -65,20 +68,21 @@ async function chatWithMemoryTool() {
console.log("📥 Claude responded:")
// Process the response
const toolResults: Anthropic.Messages.ToolResultBlockParam[] = []
const toolResults: Anthropic.Beta.Messages.BetaToolResultBlockParam[] = []
for (const block of response.content) {
if (block.type === "text") {
console.log("💭", block.text)
} else if (block.type === "tool_use" && block.name === "memory") {
const command = block.input as MemoryCommand
console.log("🔧 Claude is using memory tool:")
console.log(" Command:", block.input.command)
console.log(" Path:", block.input.path)
console.log(" Command:", command.command)
console.log(" Path:", command.path)
// Handle the memory tool call
const memoryResult = await memoryTool.handleCommand(block.input as any)
const memoryResult = await memoryTool.handleCommand(command)
const toolResult: Anthropic.Messages.ToolResultBlockParam = {
const toolResult: Anthropic.Beta.Messages.BetaToolResultBlockParam = {
type: "tool_result",
tool_use_id: block.id,
content: memoryResult.success
@ -137,14 +141,13 @@ async function chatWithMemoryTool() {
if (block.type === "text") {
console.log("💭", block.text)
} else if (block.type === "tool_use" && block.name === "memory") {
const command = block.input as MemoryCommand
console.log("🔧 Claude is using memory tool again:")
console.log(" Command:", block.input.command)
console.log(" Path:", block.input.path)
console.log(" Command:", command.command)
console.log(" Path:", command.path)
// Handle additional memory tool calls
const memoryResult = await memoryTool.handleCommand(
block.input as any,
)
const memoryResult = await memoryTool.handleCommand(command)
console.log(
"📊 Memory operation result:",
memoryResult.success ? "✅ Success" : "❌ Failed",
@ -237,7 +240,7 @@ async function testMemoryOperations() {
command: {
command: "view" as const,
path: "/memories/project-notes.txt",
view_range: [4, 8],
view_range: [4, 8] as [number, number],
},
},
]

View file

@ -6,7 +6,10 @@
* 2. Anthropic SDK integration
*/
import { createClaudeMemoryTool, type MemoryCommand } from "./claude-memory"
import {
createClaudeMemoryTool,
type MemoryCommand,
} from "../src/claude-memory"
// =====================================================
// Example 1: Direct TypeScript/fetch Integration
@ -66,8 +69,7 @@ export async function directFetchExample() {
]
// Execute each command
for (let i = 0; i < commands.length; i++) {
const command = commands[i]
for (const [i, command] of commands.entries()) {
console.log(
`\n📝 Step ${i + 1}: ${command.command.toUpperCase()} ${command.path}`,
)

View file

@ -4,7 +4,10 @@
* This shows actual tool call handling based on real Claude API responses
*/
import { createClaudeMemoryTool, type MemoryCommand } from "./claude-memory"
import {
createClaudeMemoryTool,
type MemoryCommand,
} from "../src/claude-memory"
// =====================================================
// Real Claude API Integration

View file

@ -1,5 +1,8 @@
import { describe, it, expect, beforeEach } from "vitest"
import { createClaudeMemoryTool, type MemoryCommand } from "./claude-memory"
import {
createClaudeMemoryTool,
type MemoryCommand,
} from "../src/claude-memory"
import "dotenv/config"
// Test configuration
@ -9,6 +12,10 @@ const TEST_CONFIG = {
namespace: "test-claude-memory",
}
// Same gate the other integration suites use: these hit the live API, so they
// only run when a key is present. Without one every request comes back 401.
const shouldRunIntegration = !!process.env.SUPERMEMORY_API_KEY
describe("Claude Memory Tool", () => {
let memoryTool: ReturnType<typeof createClaudeMemoryTool>
@ -60,7 +67,7 @@ describe("Claude Memory Tool", () => {
})
})
describe("File operations", () => {
describe.skipIf(!shouldRunIntegration)("File operations", () => {
const testFilePath = "/memories/test-file.txt"
const testContent = "Hello, World!\nThis is a test file.\nLine 3 here."
@ -217,7 +224,7 @@ describe("Claude Memory Tool", () => {
})
})
describe("Directory operations", () => {
describe.skipIf(!shouldRunIntegration)("Directory operations", () => {
it("should list empty directory", async () => {
const result = await memoryTool.handleCommand({
command: "view",
@ -261,7 +268,7 @@ describe("Claude Memory Tool", () => {
})
})
describe("Error handling", () => {
describe.skipIf(!shouldRunIntegration)("Error handling", () => {
it("should handle missing file", async () => {
const result = await memoryTool.handleCommand({
command: "view",

View file

@ -121,6 +121,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList,
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args)
@ -153,6 +154,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList,
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args)
@ -191,6 +193,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList,
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args)
@ -232,6 +235,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList: createIntegrationMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args1)
@ -245,6 +249,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList: createIntegrationMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args2)
@ -279,6 +284,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList,
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args)
@ -310,6 +316,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList: createIntegrationMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processOutputResult(args)
@ -342,6 +349,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList: createIntegrationMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processOutputResult(args)
@ -378,6 +386,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList: createIntegrationMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
requestContext,
}
@ -411,6 +420,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList,
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await input.processInput(inputArgs)
@ -424,6 +434,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList: createIntegrationMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await output.processOutputResult(outputArgs)
@ -464,6 +475,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList,
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await inputProcessor.processInput(args)
@ -528,6 +540,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList,
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args)
@ -552,6 +565,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList: createIntegrationMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args)
@ -585,6 +599,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList,
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
const result = await processor.processInput(args)
@ -609,6 +624,7 @@ describe.skipIf(!shouldRunIntegration)(
messageList: createIntegrationMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await expect(processor.processOutputResult(args)).resolves.toBeDefined()

View file

@ -180,6 +180,7 @@ describe("SupermemoryInputProcessor", () => {
messageList,
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args)
@ -214,6 +215,7 @@ describe("SupermemoryInputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args1)
@ -225,6 +227,7 @@ describe("SupermemoryInputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args2)
@ -255,6 +258,7 @@ describe("SupermemoryInputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args1)
@ -266,6 +270,7 @@ describe("SupermemoryInputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args2)
@ -287,6 +292,7 @@ describe("SupermemoryInputProcessor", () => {
messageList,
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
const result = await processor.processInput(args)
@ -313,6 +319,7 @@ describe("SupermemoryInputProcessor", () => {
messageList,
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
const result = await processor.processInput(args)
@ -339,6 +346,7 @@ describe("SupermemoryInputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args)
@ -367,6 +375,7 @@ describe("SupermemoryInputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
requestContext,
}
@ -409,6 +418,7 @@ describe("SupermemoryInputProcessor", () => {
messageList,
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processInput(args)
@ -475,6 +485,7 @@ describe("SupermemoryOutputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processOutputResult(args)
@ -509,6 +520,7 @@ describe("SupermemoryOutputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processOutputResult(args)
@ -536,6 +548,7 @@ describe("SupermemoryOutputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processOutputResult(args)
@ -568,6 +581,7 @@ describe("SupermemoryOutputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
requestContext,
}
@ -599,6 +613,7 @@ describe("SupermemoryOutputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processOutputResult(args)
@ -632,6 +647,7 @@ describe("SupermemoryOutputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processOutputResult(args)
@ -682,6 +698,7 @@ describe("SupermemoryOutputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processOutputResult(args)
@ -708,6 +725,7 @@ describe("SupermemoryOutputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
// Should not throw
@ -727,6 +745,7 @@ describe("SupermemoryOutputProcessor", () => {
messageList: createMockMessageList(),
abort: vi.fn() as never,
retryCount: 0,
state: {},
}
await processor.processOutputResult(args)

View file

@ -4,7 +4,10 @@
* Run with: bun run src/test-memory-tool.ts
*/
import { createClaudeMemoryTool, type MemoryCommand } from "./claude-memory"
import {
createClaudeMemoryTool,
type MemoryCommand,
} from "../src/claude-memory"
import "dotenv/config"
async function testMemoryTool() {
@ -139,8 +142,7 @@ async function testMemoryTool() {
let passed = 0
let failed = 0
for (let i = 0; i < testCases.length; i++) {
const testCase = testCases[i]
for (const [i, testCase] of testCases.entries()) {
console.log(`\\n🔄 Test ${i + 1}/${testCases.length}: ${testCase.name}`)
try {

View file

@ -532,8 +532,8 @@ describe("Unit: withSupermemory", () => {
usage: {
inputTokens: 1,
outputTokens: 1,
totalTokens: 2,
},
rawCall: { rawPrompt: [], rawSettings: {} },
warnings: [],
})
@ -592,8 +592,8 @@ describe("Unit: withSupermemory", () => {
usage: {
inputTokens: 1,
outputTokens: 1,
totalTokens: 2,
},
rawCall: { rawPrompt: [], rawSettings: {} },
warnings: [],
})

View file

@ -1,5 +1,8 @@
{
"extends": "@total-typescript/tsconfig/bundler/dom/library-monorepo",
// test/chatapp is a standalone Next.js demo with its own package.json,
// lockfile and tsconfig; it is not part of this package's program.
"exclude": ["node_modules", "test/chatapp"],
"compilerOptions": {
"baseUrl": ".",
"paths": {