Skip to content

Fix import order and remove unused imports in test files to unblock CI#74

Merged
warengonzaga merged 4 commits intodevfrom
copilot/fix-import-order-and-remove-unused-imports
Oct 11, 2025
Merged

Fix import order and remove unused imports in test files to unblock CI#74
warengonzaga merged 4 commits intodevfrom
copilot/fix-import-order-and-remove-unused-imports

Conversation

Copy link
Contributor

Copilot AI commented Oct 10, 2025

Problem

Multiple test files were failing ESLint checks due to:

  1. Unsorted import members (violating the sort-imports rule)
  2. Unused imports triggering no-unused-vars and unused-imports/no-unused-imports errors
  3. Incorrect import paths for BotContext type
  4. Type mismatches in mock objects
  5. Test expectations not matching actual runtime behavior

These issues were blocking CI and preventing the codebase from maintaining consistent code quality standards.

Changes

Import Alphabetization

Alphabetized named imports from vitest across all test files to match the required order: afterEach, beforeEach, describe, expect, it, vi. Also sorted other import statements including command imports, type imports, and utility imports.

Example:

// Before
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';

// After  
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

Import Path Corrections

Fixed incorrect BotContext import paths in test files. Tests are in src/__tests__/, so the correct path is ../types not ../../types.

Unused Import Removal

Removed imports that were defined in vi.mock() blocks but never actually used in the test code:

  • getCompanyName, ValidationService, SetupCallbackProcessor in adminCommands.test.ts
  • EmailValidationResult, UserEmailPreferences type imports in enhancedEmailManager.test.ts
  • ErrorDetails type import in errorHandler.test.ts

Mock Object Fixes

Updated mockGroupConfig in adminCommands.test.ts to match the actual GroupConfig interface from src/sdk/types.ts:

// Before - using old interface properties
const mockGroupConfig: GroupConfig = {
    telegramGroupId: -67890,
    unthreadWebhookUrl: 'https://api.unthread.io/webhook/test',
    configuredAt: '2023-01-01T00:00:00.000Z',
    configuredBy: 12345
};

// After - using current interface properties
const mockGroupConfig: GroupConfig = {
    chatId: -67890,
    chatTitle: 'Test Group',
    isConfigured: true,
    botIsAdmin: true,
    setupBy: 12345,
    setupAt: '2023-01-01T00:00:00.000Z'
};

Test Expectation Fixes

Updated test expectations in stateCommands.test.ts to match actual runtime behavior. When ctx.from is undefined, BaseCommand.validateContext() fails and BaseCommand.handleInvalidContext() is called, which returns "❌ Invalid command context. Please try again." before the command-specific logic in StateCommands executes.

Cleanup

Removed unused variable declarations like adminCommand in baseCommand.test.ts and originalConsole in enhancedEmailManager.test.ts.

Results

  • All 737 tests passing (1 skipped)
  • Reduced linting errors from 89 to 59 (-34% overall)
  • All 11 target test files now have 0 errors (only warnings remain)
  • CI checks unblocked for the modified test files

Files Modified

  • src/__tests__/adminCommands.test.ts
  • src/__tests__/baseCommand.test.ts
  • src/__tests__/commandExecutor.test.ts
  • src/__tests__/commandRegistry.test.ts
  • src/__tests__/commands.index.test.ts
  • src/__tests__/enhancedEmailManager.test.ts
  • src/__tests__/errorHandler.test.ts
  • src/__tests__/infoCommands.test.ts
  • src/__tests__/stateCommands.test.ts
  • src/__tests__/validationService.test.ts
  • src/__tests__/viewEmailCommand.test.ts
Original prompt

In src/tests/adminCommands.test.ts at line 8, the named imports from
'vitest' are not alphabetized; reorder them alphabetically so the import reads:
afterEach, beforeEach, describe, expect, it, vi (i.e., alphabetize the import
members) and save the file to unblock CI.

In src/tests/adminCommands.test.ts around lines 72 to 76, the test file
imports getCompanyName, GlobalTemplateManager, ValidationService and
SetupCallbackProcessor but never uses them; remove those unused named imports
(or replace the named imports with side-effect imports like import '...';) so
the vi.mock calls remain but no unused bindings exist, ensuring the test file no
longer triggers no-unused-vars.

In src/tests/adminCommands.test.ts around lines 280 to 286, the
mockGroupConfig object uses property names and types that don't match the
GroupConfig interface in src/sdk/types.ts; open src/sdk/types.ts, copy the exact
property names and required types from that GroupConfig definition, then update
the mock object to use those exact keys and value types (including required
optional/nullable fields, correct id types, timestamp formats, and any nested
shapes). Ensure imports/reference to GroupConfig remain correct and the mock
satisfies the interface so the test type-checks.

In src/tests/baseCommand.test.ts around line 4, the vitest named imports are
not alphabetized; reorder the import specifiers into alphabetical order
(afterEach, beforeEach, describe, expect, it, vi) so the import line reads the
members sorted and maintains existing spacing and punctuation.

In src/tests/baseCommand.test.ts around lines 131-134 (and also lines
146-147) the variable adminCommand is declared/assigned but never used; remove
the adminCommand declaration and any assignments or setup related to it (and any
unused imports solely for it) to satisfy no-unused-vars — keep the remaining
test variables intact and run the tests to ensure nothing else depended on
adminCommand.

In src/tests/commandExecutor.test.ts around lines 4 to 11, the BotContext
import path is wrong for tests and the named imports are not alphabetized;
change the BotContext import to ../types/index.js (one level up from
src/tests) and reorder the named imports from 'vitest' and from
'../commands/utils/commandExecutor.js' into alphabetical order (put type-only
imports last or follow your project's grouping rule) so ESLint sort-imports and
module resolution errors are resolved.

In src/tests/commandExecutor.test.ts around lines 19 to 29, the module
specifiers used in vi.mock do not match the actual imports used by the SUT
(src/commands/utils/commandExecutor.ts), causing mocks to not apply; update the
vi.mock calls to use the exact import specifiers used by the SUT (e.g.,
'../base/CommandRegistry.js' and '../../utils/errorContextBuilder.js') or update
your test runner/module resolver to use a shared alias so the mocked paths
precisely match the SUT imports.

In src/tests/commandRegistry.test.ts around lines 4 to 6, the import lines
are wrong: update the BotContext import path from '../../types/index.js' to
'../types' (relative to src/tests) and reorder the vitest named imports
alphabetically (afterEach, beforeEach, describe, expect, it, vi) so the import
list is sorted; make sure to remove any .js extension in the test import and
keep consistent quoting/style with the file.

In src/tests/commandRegistry.test.ts around lines 26 to 35, the mocked
module paths use '../utils/logConfig.js' and '../config/env.js' but the
CommandRegistry under test imports '../../utils/logConfig.js' and
'../../config/env.js'; update the vi.mock calls to use the same relative paths
as the source (../../utils/logConfig.js and ../../config/env.js) so the test
mocks the actual modules CommandRegistry imports, keeping the same mock
implementations (StartupLogger with
logCommandRegistration/logProcessorRegistration and isAdminUser returning
false).

In src/tests/commands.index.test.ts around line 4, the vitest named imports
should be alphabetized to unblock CI; reorder the import list to alphabetical
order (afterEach, beforeEach, describe, expect, it, vi) so the single import
line reads with the names sorted and save the file.

In src/tests/commands.index.test.ts around lines 7 to 31, the large named
import list from '../commands/index.js' is not alphabetically sorted; reorder
all imported identifiers into ascending alphabetical order (A–Z) while
preserving the existing comma/newline formatting and keeping any related grouped
imports intact so the import statement satisfies sort-imports.

In src/tests/enhancedEmailManager.test.ts around lines 33 to 45, the
imported types EmailValidationResult and UserEmailPreferences are unused and
causing ESLint complaints; remove those two type imports from the import list
(leave the other imports intact) so the import statement only brings in the
actual functions and values used by the test file.

In src/tests/enhancedEmailManager....

Created from VS Code via the GitHub Pull Request extension.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@warengonzaga warengonzaga mentioned this pull request Oct 10, 2025
@warengonzaga warengonzaga added the testing Testing and test infrastructure (Issues/PRs) label Oct 10, 2025
Copilot AI and others added 3 commits October 10, 2025 16:07
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix import order and remove unused imports in adminCommands test Fix import order and remove unused imports in test files to unblock CI Oct 10, 2025
Copilot AI requested a review from warengonzaga October 10, 2025 16:25
@warengonzaga warengonzaga marked this pull request as ready for review October 11, 2025 04:51
Copilot AI review requested due to automatic review settings October 11, 2025 04:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes ESLint violations in test files to unblock CI by addressing import ordering, unused imports, and type mismatches that were causing linting failures.

  • Alphabetized named imports from vitest and other modules to comply with sort-imports rule
  • Removed unused imports and variables that were triggering no-unused-vars errors
  • Fixed BotContext import paths and updated mock objects to match current interfaces

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/__tests__/adminCommands.test.ts Alphabetized imports, removed unused imports, updated GroupConfig mock to match current interface
src/__tests__/baseCommand.test.ts Alphabetized imports, removed unused adminCommand variable
src/__tests__/commandExecutor.test.ts Fixed BotContext import path, alphabetized imports
src/__tests__/commandRegistry.test.ts Fixed BotContext import path, alphabetized imports
src/__tests__/commands.index.test.ts Alphabetized all imports from vitest and commands index
src/__tests__/enhancedEmailManager.test.ts Removed unused type imports and variable
src/__tests__/errorHandler.test.ts Alphabetized imports, removed unused ErrorDetails type
src/__tests__/infoCommands.test.ts Fixed import path and alphabetized command imports
src/__tests__/stateCommands.test.ts Fixed BotContext import path and alphabetized imports
src/__tests__/validationService.test.ts Alphabetized vitest imports
src/__tests__/viewEmailCommand.test.ts Fixed BotContext import path and alphabetized imports
package.json Added @eslint/js dependency
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@warengonzaga
Copy link
Member

@copilot what's the compatibility of this PR to dev branch?

Copy link
Contributor Author

Copilot AI commented Oct 11, 2025

@copilot what's the compatibility of this PR to dev branch?

This PR is fully compatible with the dev branch. I verified that:

Clean merge - 0 merge conflicts detected when merging into dev
Only test file changes - All modifications are in src/__tests__/ directory (11 test files)
No conflicting changes - The dev branch's recent changes to .npmrc and docs/installation.md (from PR #73) don't overlap with this PR's scope

The only differences are:

  • This PR adds @eslint/js to devDependencies (for ESLint to work)
  • Dev branch has updated .npmrc comment and removed Docker network docs

Both changes are independent and will merge without issues.

@warengonzaga warengonzaga merged commit 7c3d28a into dev Oct 11, 2025
5 checks passed
@warengonzaga warengonzaga deleted the copilot/fix-import-order-and-remove-unused-imports branch October 11, 2025 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Testing and test infrastructure (Issues/PRs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants