Skip to content

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

Open
rajarshidattapy wants to merge 2 commits into
supermemoryai:mainfrom
rajarshidattapy:fix/tools-test-typecheck
Open

fix(tools): clear every type error under packages/tools/test#1570
rajarshidattapy wants to merge 2 commits into
supermemoryai:mainfrom
rajarshidattapy:fix/tools-test-typecheck

Conversation

@rajarshidattapy

@rajarshidattapy rajarshidattapy commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #1545 — with a correction to its error inventory, see the last section.

What was broken

claude-memory.ts lives in packages/tools/src/, but five files under test/ still imported ./claude-memory, and the Mastra and AI-SDK fixtures had drifted behind their installed types.

Changes

  • Dangling imports (5 files, not 1). anthropic-example.ts, claude-memory-examples.ts, claude-memory-real-example.ts, claude-memory.test.ts and test-memory-tool.ts all imported ./claude-memory; all five now point at ../src/claude-memory.
  • Mastra fixtures (35). ProcessInputArgs / ProcessOutputResultArgs gained a required state; added it to every fixture in test/mastra/{unit,integration}.test.ts.
  • AI-SDK usage fixtures (2). Added totalTokens to the LanguageModelV2Usage literals — and removed rawCall, which surfaced as the next error once the usage type resolved: it is no longer part of the doGenerate result.
  • Index-access errors. test-memory-tool.ts and claude-memory-examples.ts looped with for (let i…) + arr[i], which noUncheckedIndexedAccess rejects. Now for (const [i, x] of arr.entries()). These were masked behind the unresolved import.
  • test-supermemory.ts. Called withSupermemory(client, containerTag, options); the signature is (client, options) with containerTag/customId inside options.
  • anthropic-example.ts. Typed the conversation with the beta message types it actually uses, narrowed block.input once through MemoryCommand (which also removes an as any), and made view_range a tuple rather than number[].
  • tsconfig.json. Excluded test/chatapp — a standalone Next.js demo with its own package.json, lockfile and tsconfig.json. It was contributing 56 JSX errors to this package's program, which is not something this package should be compiling.

Repointing the import also made test/claude-memory.test.ts loadable for the first time in a while, and it turned out to be a live-API suite: vitest run went from silently failing to collect it to reporting a dozen 401s. It is now gated behind SUPERMEMORY_API_KEY via describe.skipIf, matching test/mastra/integration.test.ts and test/with-supermemory/integration.test.ts. Its two offline path-validation tests still run.

Verification

cd packages/tools && bunx tsc --noEmit:

before after
test/** 110 0
src/** 36 36
total 146 36

bunx vitest run: 2 failed files / 90 passed → 1 failed file / 92 passed / 43 skipped. The remaining failure is src/tools.test.ts, which throws at module load when SUPERMEMORY_API_KEY is unset — pre-existing on main and a separate problem from type-checking. biome ci --changed exits 0.

Correction to the issue

The issue reports 31 errors, all in test/, with src/ clean. On main the actual count is 146, and src/ is not clean — it has 36:

29  src/ai-sdk.ts
 3  src/openai/tools.ts
 2  src/shared/cache.ts
 1  src/voltagent/middleware.ts
 1  src/openai/middleware.ts

Those are left alone here deliberately. The src/ai-sdk.ts and src/openai/tools.ts ones are a dual-zod install, not a code defect: packages/tools resolves its own zod@4.3.6, while the hoisted ai@5.0.148 resolves zod@3.25.76 from the root, so FlexibleSchema expects zod 3's ZodType and gets zod 4 objects. Fixing that means a root-level dependency or overrides change with monorepo-wide blast radius — worth its own PR rather than being smuggled into a test-fixture cleanup. src/shared/cache.ts (lru-cache v11 generic constraint) and the two middleware ones are ordinary typing fixes, also separate.

So check-types for @supermemory/tools is not green after this PR — but everything the issue names, and everything else under test/, is fixed.

`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.
if (block.type === "text") {
console.log("💭", block.text)
} else if (block.type === "tool_use" && block.name === "memory") {
const command = block.input as MemoryCommand

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line also uses a type assertion (block.input as MemoryCommand) instead of a type annotation. The style guide rule 'Use type annotations instead of assertions for object literals' discourages unnecessary type assertions. Consider narrowing the type via a type guard or using a typed helper function instead of a bare as cast.

Spotted by Graphite (based on custom rule: TypeScript style guide (Google))

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Replace the bare `block.input as MemoryCommand` assertions in the
Anthropic example with an isMemoryCommand type guard, so unexpected
tool input is skipped instead of silently mistyped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@supermemory/tools fails check-types: 31 errors in test/, including an import of a file that no longer exists

1 participant