fix(tools): clear every type error under packages/tools/test - #1570
Open
rajarshidattapy wants to merge 2 commits into
Open
fix(tools): clear every type error under packages/tools/test#1570rajarshidattapy wants to merge 2 commits into
rajarshidattapy wants to merge 2 commits into
Conversation
`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 |
There was a problem hiding this comment.
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))
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1545 — with a correction to its error inventory, see the last section.
What was broken
claude-memory.tslives inpackages/tools/src/, but five files undertest/still imported./claude-memory, and the Mastra and AI-SDK fixtures had drifted behind their installed types.Changes
anthropic-example.ts,claude-memory-examples.ts,claude-memory-real-example.ts,claude-memory.test.tsandtest-memory-tool.tsall imported./claude-memory; all five now point at../src/claude-memory.ProcessInputArgs/ProcessOutputResultArgsgained a requiredstate; added it to every fixture intest/mastra/{unit,integration}.test.ts.totalTokensto theLanguageModelV2Usageliterals — and removedrawCall, which surfaced as the next error once the usage type resolved: it is no longer part of thedoGenerateresult.test-memory-tool.tsandclaude-memory-examples.tslooped withfor (let i…)+arr[i], whichnoUncheckedIndexedAccessrejects. Nowfor (const [i, x] of arr.entries()). These were masked behind the unresolved import.test-supermemory.ts. CalledwithSupermemory(client, containerTag, options); the signature is(client, options)withcontainerTag/customIdinside options.anthropic-example.ts. Typed the conversation with the beta message types it actually uses, narrowedblock.inputonce throughMemoryCommand(which also removes anas any), and madeview_rangea tuple rather thannumber[].tsconfig.json. Excludedtest/chatapp— a standalone Next.js demo with its ownpackage.json, lockfile andtsconfig.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.tsloadable for the first time in a while, and it turned out to be a live-API suite:vitest runwent from silently failing to collect it to reporting a dozen 401s. It is now gated behindSUPERMEMORY_API_KEYviadescribe.skipIf, matchingtest/mastra/integration.test.tsandtest/with-supermemory/integration.test.ts. Its two offline path-validation tests still run.Verification
cd packages/tools && bunx tsc --noEmit:test/**src/**bunx vitest run: 2 failed files / 90 passed → 1 failed file / 92 passed / 43 skipped. The remaining failure issrc/tools.test.ts, whichthrows at module load whenSUPERMEMORY_API_KEYis unset — pre-existing onmainand a separate problem from type-checking.biome ci --changedexits 0.Correction to the issue
The issue reports 31 errors, all in
test/, withsrc/clean. Onmainthe actual count is 146, andsrc/is not clean — it has 36:Those are left alone here deliberately. The
src/ai-sdk.tsandsrc/openai/tools.tsones are a dual-zod install, not a code defect:packages/toolsresolves its ownzod@4.3.6, while the hoistedai@5.0.148resolveszod@3.25.76from the root, soFlexibleSchemaexpects zod 3'sZodTypeand gets zod 4 objects. Fixing that means a root-level dependency oroverrideschange 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-typesfor@supermemory/toolsis not green after this PR — but everything the issue names, and everything else undertest/, is fixed.