Skip to content

Commit 30a92b7

Browse files
authored
Chore/repo audit 2025 09 16 adding code coverage, type deduplication, cleanup of organization for files and folders (#5)
* chore: audit and refactor per standards - Break all circular dependencies by using specific imports - Consolidate duplicate interfaces - Remove redundant barrel files - Ensure no cycles with madge check * refactor: remove index.ts barrels, update imports, add back selective barrels - Removed all index.ts files and updated all imports to direct paths - Consolidated duplicate interfaces - Added back index.ts barrels exporting only necessary items for external use - Fixed import of 'util' to use local guards - Ensured no circular dependencies and green TypeScript compilation * Refactor code structure for improved readability and maintainability * feat: enhance error handling in API responses; add error structure to IApiResponse and update tests * refactor: enhance tool registration process with additional type guards and improve test structure
1 parent 98fc17f commit 30a92b7

File tree

97 files changed

+8574
-677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+8574
-677
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
],
3737
"simple-import-sort/imports": "error",
3838
"simple-import-sort/exports": "error",
39-
"import/no-unused-modules": ["error", { "unusedExports": true }],
39+
"import/no-unused-modules": ["off", { "unusedExports": true }],
4040
"no-console": ["error", { "allow": ["warn", "error"] }]
4141
}
4242
}

.vscode/extensions.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"esbenp.prettier-vscode",
44
"editorconfig.editorconfig",
55
"dbaeumer.vscode-eslint",
6-
"DavidAnson.vscode-markdownlint",
7-
"arcanis.vscode-zipfs"
6+
"DavidAnson.vscode-markdownlint"
87
],
98
"unwantedRecommendations": []
109
}

TODO.md

Lines changed: 129 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This file is the canonical, human-manageable task queue for the Documentation-Dr
1616

1717
How to use
1818

19-
- To add a task: copy the task template below, fill out the fields, and insert the task at the appropriate priority position.
19+
- To add a task: copy the task template below, fill out the fields, and insert the appropriate priority position.
2020
- To reorder tasks: move the task block to a new place in this file. Tasks are processed top-to-bottom unless otherwise prioritized.
2121
- To mark a task complete: remove the task block from this file and add a short summary (task id, summary, and link to PR/commit) to the `Unreleased` section of `CHANGELOG.md`.
2222

@@ -27,46 +27,155 @@ Priority convention
2727
- P2 — Medium (planned for upcoming work)
2828
- P3 — Low (nice-to-have)
2929

30-
Task template reference
31-
32-
See `docs/templates/task-template.md` for the canonical template and examples. The template below is a quick copy you can paste to create a task.
33-
3430
---
3531

3632
id: T-001
37-
priority: P1
33+
priority: P0
3834
status: open
39-
summary: Short one-line summary of the task
40-
owner: Unassigned
41-
created: 2025-09-14
42-
updated: 2025-09-14
35+
summary: Implement comprehensive mock strategy for unit tests
36+
owner: AI Assistant
37+
created: 2025-09-16
38+
updated: 2025-09-16
4339

4440
detailed_requirements:
4541

46-
- Step 1: Do this.
42+
- Define readonly mock creation pattern for all external dependencies
43+
- Implement proper mock lifecycle management (creation in beforeEach, cleanup in afterEach)
44+
- Ensure mocks are fully isolated between tests
45+
- Use jest.Mocked<T> for type safety
46+
- Implement call count and parameter assertions for all mocked methods
47+
- Add jest.resetModules() for module isolation where needed
48+
- Document mock patterns in test standards
49+
50+
positive_behaviors:
51+
52+
- All mocks are readonly and properly typed
53+
- No test bleeding or state pollution
54+
- Clear assertion of call counts and parameters
55+
- Deterministic test execution
56+
57+
negative_behaviors:
58+
59+
- Mutable mocks
60+
- Missing cleanup leading to test interference
61+
- Incomplete call assertions
62+
- Memory leaks from uncleared references
63+
64+
validations:
65+
66+
- All existing tests pass with --detectLeaks
67+
- No flaky tests due to mock state
68+
- Coverage reports accurate (no false positives from mock pollution)
69+
- TypeScript compilation succeeds with mock types
70+
71+
---
72+
73+
id: T-002
74+
priority: P0
75+
status: open
76+
summary: Ensure all test files have proper afterEach cleanup
77+
owner: AI Assistant
78+
created: 2025-09-16
79+
updated: 2025-09-16
4780

48-
- Step 2: Do that.
81+
detailed_requirements:
82+
83+
- Add afterEach blocks to all test files
84+
- Clear all mocks with jest.clearAllMocks()
85+
- Reset modules with jest.resetModules() where appropriate
86+
- Close any resources (timers, connections) in mocks
87+
- Verify no memory leaks with --detectLeaks flag
4988

5089
positive_behaviors:
5190

52-
- The system should behave like this when correct.
91+
- Tests run cleanly without side effects
92+
- Memory usage remains stable across test runs
93+
- No interference between test suites
5394

5495
negative_behaviors:
5596

56-
- The system should NOT do this.
97+
- Memory leaks detected by Jest
98+
- Test state bleeding between runs
99+
- Resource exhaustion in CI
57100

58101
validations:
59102

60-
- Automated tests (unit/integration) to run and expected results.
103+
- jest --detectLeaks passes for all test suites
104+
- Memory profiling shows no growth
105+
- All mocks properly reset
106+
107+
---
108+
109+
id: T-003
110+
priority: P1
111+
status: open
112+
summary: Continue unit test implementation for remaining modules
113+
owner: AI Assistant
114+
created: 2025-09-16
115+
updated: 2025-09-16
116+
117+
detailed_requirements:
118+
119+
- Implement tests for formatting utilities (responses.ts, jsonapi-formatter.ts, pagination-helper.ts)
120+
- Add tests for tool utilities (tool-loader.ts, tool-factory.ts, etc.)
121+
- Create tests for API layer (backstage-catalog-api.ts)
122+
- Implement auth layer tests (auth-manager.ts, input-sanitizer.ts, security-auditor.ts)
123+
- Add cache layer tests (cache-manager.ts)
124+
- Test main files (server.ts, generate-manifest.ts)
125+
- Use lessons from mock strategy and cleanup for quality
61126

62-
- Manual checks or QA steps.
127+
positive_behaviors:
63128

64-
notes:
129+
- All public methods have positive and negative test cases
130+
- Table-driven tests for simple functions
131+
- Proper mocking of external dependencies
132+
- High test coverage (>95%)
65133

66-
- Any additional context or links to spec ids or planning.md sections.
134+
negative_behaviors:
135+
136+
- Untested code paths
137+
- Poor mock isolation
138+
- Missing edge case coverage
139+
140+
validations:
141+
142+
- jest --coverage shows >95% for all metrics
143+
- All tests pass consistently
144+
- No memory leaks
145+
- Code review passes
67146

68147
---
69148

70-
Active tasks
149+
id: T-004
150+
priority: P2
151+
status: open
152+
summary: Integrate tests into CI pipeline with coverage gates
153+
owner: AI Assistant
154+
created: 2025-09-16
155+
updated: 2025-09-16
156+
157+
detailed_requirements:
158+
159+
- Configure GitHub Actions or CI to run tests
160+
- Set coverage thresholds (95% statements, branches, functions, lines)
161+
- Add test result reporting
162+
- Ensure ES module support in CI environment
163+
- Fail builds on coverage below thresholds
164+
165+
positive_behaviors:
166+
167+
- Automated test execution on PRs
168+
- Coverage requirements enforced
169+
- Test failures block merges
170+
171+
negative_behaviors:
172+
173+
- Tests not running in CI
174+
- Coverage regressions allowed
175+
- Manual test execution required
176+
177+
validations:
71178

72-
<!-- Add tasks below. Keep the completed tasks out of this file and move to CHANGELOG.md -> Unreleased -->
179+
- CI passes for current codebase
180+
- Coverage reports generated and accessible
181+
- PR checks include test status

jest.config.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export default {
1212
},
1313
transformIgnorePatterns: ['node_modules/(?!(@modelcontextprotocol)/)'],
1414
testPathIgnorePatterns: ['<rootDir>/dist/'],
15-
collectCoverageFrom: ['src/**/*.{ts,js}', '!src/**/*.spec.ts', '!src/**/*.test.ts', '!src/**/__fixtures__/**/*'],
15+
collectCoverageFrom: [
16+
'src/**/*.{ts,js}',
17+
'!src/**/*.spec.ts',
18+
'!src/**/*.test.ts',
19+
'!src/types/**/*',
20+
'!src/**/__fixtures__/**/*',
21+
],
1622
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
1723
};

package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"author": "Robert Lindley",
3-
"type": "module",
43
"dependencies": {
54
"@backstage/catalog-client": "^1.9.1",
65
"@backstage/catalog-model": "^1.7.3",
@@ -14,37 +13,45 @@
1413
},
1514
"devDependencies": {
1615
"@jest/globals": "^29.7.0",
16+
"@types/express": "^5.0.3",
1717
"@types/jest": "^29.5.14",
1818
"@types/node": "^22.0.0",
1919
"@typescript-eslint/eslint-plugin": "^8.43.0",
2020
"@typescript-eslint/parser": "^8.43.0",
21+
"dependency-cruiser": "^17.0.1",
2122
"esbuild": "^0.18.18",
2223
"eslint": "^8.57.0",
2324
"eslint-config-prettier": "^9.0.0",
2425
"eslint-import-resolver-typescript": "^4.4.4",
25-
"eslint-plugin-import": "^2.27.5",
26+
"eslint-plugin-import": "^2.32.0",
2627
"eslint-plugin-simple-import-sort": "^10.0.0",
28+
"eslint-plugin-unused-imports": "^4.2.0",
2729
"jest": "^29.7.0",
2830
"jest-util": "^29.7.0",
31+
"jscpd": "^4.0.5",
32+
"madge": "^8.0.0",
2933
"prettier": "^3.5.3",
3034
"rimraf": "^5.0.0",
3135
"ts-jest": "^29.3.2",
36+
"ts-morph": "^27.0.0",
37+
"ts-node": "^10.9.2",
3238
"typescript": "^5.8.3"
3339
},
3440
"main": "dist/bundle.cjs",
3541
"name": "@coderrob/mcp-backstage-server",
3642
"packageManager": "[email protected]",
3743
"scripts": {
38-
"clean": "rimraf dist",
39-
"build:types": "tsc --emitDeclarationOnly",
40-
"build:bundle": "esbuild src/index.ts --bundle --platform=node --target=node22 --format=cjs --outfile=dist/bundle.cjs --minify --sourcemap --metafile=dist/esbuild-meta.json",
4144
"build": "yarn clean && yarn build:bundle",
45+
"build:bundle": "esbuild src/index.ts --bundle --platform=node --target=node18 --format=cjs --outfile=dist/bundle.cjs --minify --sourcemap --metafile=dist/esbuild-meta.json",
4246
"build:full": "yarn clean && yarn build:types && tsc && yarn build:bundle",
47+
"build:types": "tsc --emitDeclarationOnly",
48+
"clean": "rimraf dist",
4349
"lint": "eslint 'src/**/*.ts' --ext .ts",
4450
"lint:fix": "prettier . --write && eslint 'src/**/*.ts' --ext .ts --fix",
4551
"start": "node dist/bundle.cjs",
4652
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest --coverage"
4753
},
54+
"type": "module",
4855
"types": "dist/index.d.ts",
4956
"version": "1.0.0"
5057
}

0 commit comments

Comments
 (0)