Skip to content

test: remove all explicit any types from test files#169

Open
Fermionic-Lyu wants to merge 1 commit into
mainfrom
claude/zealous-curran-c2c910
Open

test: remove all explicit any types from test files#169
Fermionic-Lyu wants to merge 1 commit into
mainfrom
claude/zealous-curran-c2c910

Conversation

@Fermionic-Lyu

@Fermionic-Lyu Fermionic-Lyu commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary

Removes all 47 @typescript-eslint/no-explicit-any warnings in the repo. Every one was confined to 6 test files (branch command tests + memory test); production src/ code was already any-free.

The anys fell into three patterns, each replaced with a real type:

Pattern Before After
Mock method calls (getProjectConfig as any).mockReturnValue(...) (getProjectConfig as Mock).mockReturnValue(...)
Node global stubs (process.exit as any) = (code?) => {...} process.exit = ((code?) => {...}) as typeof process.exit
Typed fixtures const saveCalls: any[] / (c: any) => ProjectConfig[] / (c: ProjectConfig) =>

Notes

  • Uses vitest's real Mock type (imported via type Mock) instead of any. The stricter vi.mocked() was tried first, but it forces every getProjectConfig mock to supply a complete ProjectConfig; these tests deliberately use minimal partial fixtures, so as Mock keeps them readable without reintroducing any.
  • For 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/0 no-explicit-any (0 other problems)
  • npm run lint (full CI: vitest + eslint) → 516 passed, 13 skipped, clean
  • tsc --noEmit introduces no new errors in the touched files

🤖 Generated with Claude Code


Summary by cubic

Remove all explicit any from test files, replacing them with real types to clear @typescript-eslint/no-explicit-any warnings. No production code changes; ESLint is clean and tests pass.

  • Refactors
    • Use vitest Mock for mocked functions instead of as any.
    • Cast Node global stubs to their own types (e.g., process.exit as typeof process.exit, process.stderr.write).
    • Type fixtures and callbacks with ProjectConfig; adjust tests to read typed request bodies in memory command tests.

Written for commit 808a4c1. Summary will update on new commits.

Review in cubic

Note

Remove explicit any type casts from test files

Replaces as any casts with as Mock (imported from vitest) when accessing mock methods on stubbed functions across branch and memory command test files. Also tightens typings for temporary process.exit and process.stderr.write overrides using typeof casts. No changes to test logic or assertions.

Macroscope summarized 808a4c1.

Summary by CodeRabbit

Release Notes

  • Tests
    • Improved TypeScript type safety in test files by strengthening type assertions for mocked functions across branch and memory command tests.

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>
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Across six test files for branch (create, delete, list, merge, switch) and memory commands, all any casts on Vitest mock functions are replaced with the type Mock import. Process stub assignments in create and merge tests are updated to use typeof-based typings. No test logic, assertions, or production code change.

Changes

Mock Typing Upgrade

Layer / File(s) Summary
Branch command tests: Mock type casts
src/commands/branch/create.test.ts, src/commands/branch/delete.test.ts, src/commands/branch/list.test.ts, src/commands/branch/merge.test.ts, src/commands/branch/switch.test.ts
type Mock is added to Vitest imports in all five files. All any casts on getProjectConfig, runBranchSwitch, listBranchesApi, and mergeBranchDryRunApi mocks are replaced with Mock. In create.test.ts and merge.test.ts, process.exit and process.stderr.write stubs are updated to typeof-based typed assignments. saveCalls in switch.test.ts is typed as ProjectConfig[].
Memory command tests: Mock type casts and optional body access
src/commands/memory/memory.test.ts
type Mock is added to the Vitest import. All any casts on ossFetch mock accesses are replaced with Mock. Request body parsing in remember, recall, and list tests is updated to use opts?.body with a string cast.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • InsForge/CLI#164: Introduces src/commands/memory/memory.test.ts, the same file where ossFetch mock typing is updated in this PR.

Suggested reviewers

  • jwfing

Poem

🐇 A rabbit hopped through test-land one day,
Found any lurking — swept it away!
With Mock in paw and types held tight,
Each cast now gleams in TypeScript light.
No logic changed, just cleaner code —
A tidier warren, a tidier abode! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'test: remove all explicit any types from test files' accurately summarizes the main change: removing 47 explicit any type assertions from test files across six test modules.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/zealous-curran-c2c910

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown

Greptile Summary

This PR replaces all 47 @typescript-eslint/no-explicit-any occurrences across six test files with proper types: vitest's Mock for mocked function calls, typeof process.exit / typeof process.stderr.write for Node global stubs, and ProjectConfig for typed fixtures in switch.test.ts.

  • Mock casts: (fn as any).mockReturnValue(...)(fn as Mock).mockReturnValue(...) throughout all branch and memory test files, using vitest's type Mock import.
  • Process stubs: (process.exit as any) = ... is refactored to process.exit = (...) as typeof process.exit, and process.stderr.write is handled the same way, preserving type safety on the stub shape.
  • Fixture typing: saveCalls: any[] and (c: any) => in switch.test.ts are replaced with ProjectConfig[] and (c: ProjectConfig) =>, backed by a new import type { ProjectConfig } from ../../types.js.

Confidence Score: 5/5

All 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

Filename Overview
src/commands/branch/create.test.ts Replaces as any on getProjectConfig, runBranchSwitch mocks and process.exit/stderr.write stubs with Mock / typeof casts. No logic changes.
src/commands/branch/delete.test.ts Replaces as any on getProjectConfig and runBranchSwitch mocks with as Mock. No logic changes.
src/commands/branch/list.test.ts Replaces as any on getProjectConfig and listBranchesApi mocks with as Mock. No logic changes.
src/commands/branch/merge.test.ts Replaces as any on mergeBranchDryRunApi mock and process.exit/stderr.write stubs. No logic changes.
src/commands/branch/switch.test.ts Most substantive change: adds import type { ProjectConfig }, types saveCalls and the saveProjectConfig mock callback parameter with ProjectConfig, and replaces Mock casts throughout.
src/commands/memory/memory.test.ts Replaces as any on ossFetch mock calls with as Mock; adds optional chaining (opts?.body) before casting to string when accessing mock call arguments.

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]
Loading
%%{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]
Loading

Reviews (1): Last reviewed commit: "test: remove all explicit any types from..." | Re-trigger Greptile

@jwfing jwfing left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 the no-explicit-any warnings are gone).
  • npx vitest run src/commands/branch src/commands/memory7 files, 38 tests passed.
  • npx tsc --noEmitno errors in any touched test file (matches the PR's claim).
  • Grep confirms no leftover as any / : any type casts and no eslint-disable escape hatches were introduced (the only any substrings remaining are the English word inside test descriptions).

Findings

Critical — (none)

Suggestion — (none)

Information

  • Software engineering — The choice of as Mock over vi.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 partial ProjectConfig fixtures (e.g. create.test.ts:99-105 omits appkey/region/api_key/oss_host), and vi.mocked() would force complete fixtures. as Mock keeps mockReturnValue permissive while still removing any. 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 new opts?.body as string / (... ).mock.calls[0][1]?.body uses 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.exit and process.stderr.write = (() => true) as typeof process.stderr.write rewrites (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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 6 files

Re-trigger cubic

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.

2 participants