test: remove all explicit any types from test files#169
Conversation
Replace the 47 `@typescript-eslint/no-explicit-any` warnings (all in the branch and memory command tests) with real types: - Mock method calls use vitest's `Mock` type instead of `as any` - Node global stubs cast to the property's own type (`as typeof process.exit`) instead of `any` - Typed fixtures (`ProjectConfig[]`, `(c: ProjectConfig) => ...`) eslint now reports 0 no-explicit-any; full lint (vitest + eslint) passes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
WalkthroughAcross six test files for branch (create, delete, list, merge, switch) and memory commands, all ChangesMock Typing Upgrade
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Greptile SummaryThis PR replaces all 47
Confidence Score: 5/5All changes are confined to test files; production source is untouched, and the substitutions are mechanical casts with no behavioral difference at runtime. Every changed line is a type annotation swap in test-only files. The Mock cast correctly represents vitest's mock API, typeof process.exit and typeof process.stderr.write accurately describe the stub shapes, and ProjectConfig is the exact interface already used by the production config module. CI reports 516 tests passing with no new TypeScript errors. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Test file imports] --> B{Type used for mock}
B -->|Before| C["(fn as any).mockReturnValue(...)"]
B -->|After| D["(fn as Mock).mockReturnValue(...)"]
E[Node global stubs] --> F{Stub pattern}
F -->|Before| G["(process.exit as any) = (code?) => {...}"]
F -->|After| H["process.exit = (...) as typeof process.exit"]
I[Fixture arrays in switch.test.ts] --> J{Element type}
J -->|Before| K["saveCalls: any[] / (c: any) =>"]
J -->|After| L["saveCalls: ProjectConfig[] / (c: ProjectConfig) =>"]
D --> M[Mock from vitest]
H --> N[typeof process.exit / process.stderr.write]
L --> O[ProjectConfig from src/types.ts]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[Test file imports] --> B{Type used for mock}
B -->|Before| C["(fn as any).mockReturnValue(...)"]
B -->|After| D["(fn as Mock).mockReturnValue(...)"]
E[Node global stubs] --> F{Stub pattern}
F -->|Before| G["(process.exit as any) = (code?) => {...}"]
F -->|After| H["process.exit = (...) as typeof process.exit"]
I[Fixture arrays in switch.test.ts] --> J{Element type}
J -->|Before| K["saveCalls: any[] / (c: any) =>"]
J -->|After| L["saveCalls: ProjectConfig[] / (c: ProjectConfig) =>"]
D --> M[Mock from vitest]
H --> N[typeof process.exit / process.stderr.write]
L --> O[ProjectConfig from src/types.ts]
Reviews (1): Last reviewed commit: "test: remove all explicit any types from..." | Re-trigger Greptile |
jwfing
left a comment
There was a problem hiding this comment.
Review: test type-hygiene — remove explicit any from test files
Summary: A tightly-scoped, test-only refactor that replaces 47 @typescript-eslint/no-explicit-any casts in 6 test files with real types (as Mock, as typeof process.exit, ProjectConfig); no production code and no test logic/assertions change.
Requirements context
No matching spec/plan found under docs/specs/ (the repo's spec location — there is no docs/superpowers/). The three docs present cover the diagnose and db-migrations commands, unrelated to this lint-hygiene change. Assessed against the PR description and the repo's lint/test gates alone.
Verification performed
Ran the actual CI gates against the PR head in a clean workspace (npm ci):
npx eslint src/→ 0 problems (confirms theno-explicit-anywarnings are gone).npx vitest run src/commands/branch src/commands/memory→ 7 files, 38 tests passed.npx tsc --noEmit→ no errors in any touched test file (matches the PR's claim).- Grep confirms no leftover
as any/: anytype casts and noeslint-disableescape hatches were introduced (the onlyanysubstrings remaining are the English word inside test descriptions).
Findings
Critical — (none)
Suggestion — (none)
Information
- Software engineering — The choice of
as Mockovervi.mocked()(src/commands/branch/create.test.ts:73, and the analogous casts throughout) is the correct call and is well-justified in the PR body: these tests intentionally use minimal partialProjectConfigfixtures (e.g.create.test.ts:99-105omitsappkey/region/api_key/oss_host), andvi.mocked()would force complete fixtures.as MockkeepsmockReturnValuepermissive while still removingany. Worth noting only so a future reader doesn't "tighten" it back into churn. - Software engineering — In
src/commands/memory/memory.test.ts:58,73,82, the newopts?.body as string/(... ).mock.calls[0][1]?.bodyuses optional chaining on values that are guaranteed present right after the asserted mock call. It's harmless defensive typing and reads fine; no change needed. - Functionality — The
process.exit = ((code?) => {…}) as typeof process.exitandprocess.stderr.write = (() => true) as typeof process.stderr.writerewrites (create.test.ts:78-86,merge.test.ts:170-177) preserve the prior stub behavior exactly; casting to the property's own type keeps the stub shape-checked instead of untyped. Test behavior is unchanged and the suite confirms it.
Security — No security-relevant changes; test files only, no production code, no new inputs/secrets/deps.
Performance — No performance-relevant changes; type-level edits only.
Verdict
approved (informational). Zero Critical findings — clean, in-scope, gates verified. The explicit green-checkmark approval remains a separate human action.
Summary
Removes all 47
@typescript-eslint/no-explicit-anywarnings in the repo. Every one was confined to 6 test files (branchcommand tests +memorytest); productionsrc/code was alreadyany-free.The
anys fell into three patterns, each replaced with a real type:(getProjectConfig as any).mockReturnValue(...)(getProjectConfig as Mock).mockReturnValue(...)(process.exit as any) = (code?) => {...}process.exit = ((code?) => {...}) as typeof process.exitconst saveCalls: any[]/(c: any) =>ProjectConfig[]/(c: ProjectConfig) =>Notes
Mocktype (imported viatype Mock) instead ofany. The strictervi.mocked()was tried first, but it forces everygetProjectConfigmock to supply a completeProjectConfig; these tests deliberately use minimal partial fixtures, soas Mockkeeps them readable without reintroducingany.process.exit/process.stderr.write, casting to the property's own type (as typeof process.exit) keeps the assigned stub shape-checked rather than untyped.Verification
npx eslint src/→ 0no-explicit-any(0 other problems)npm run lint(full CI: vitest + eslint) → 516 passed, 13 skipped, cleantsc --noEmitintroduces no new errors in the touched files🤖 Generated with Claude Code
Summary by cubic
Remove all explicit
anyfrom test files, replacing them with real types to clear@typescript-eslint/no-explicit-anywarnings. No production code changes; ESLint is clean and tests pass.vitestMockfor mocked functions instead ofas any.process.exitastypeof process.exit,process.stderr.write).ProjectConfig; adjust tests to read typed request bodies in memory command tests.Written for commit 808a4c1. Summary will update on new commits.
Note
Remove explicit
anytype casts from test filesReplaces
as anycasts withas Mock(imported from vitest) when accessing mock methods on stubbed functions across branch and memory command test files. Also tightens typings for temporaryprocess.exitandprocess.stderr.writeoverrides usingtypeofcasts. No changes to test logic or assertions.Macroscope summarized 808a4c1.
Summary by CodeRabbit
Release Notes