-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(core): auto-inject manifest into FileLoader/ContextLoader getters #5857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
killagu
wants to merge
1
commit into
next
Choose a base branch
from
feat/manifest-complete-coverage
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import path from 'node:path'; | ||
|
|
||
| import { describe, it, afterAll } from 'vitest'; | ||
|
|
||
| import { createApp, getFilepath, type Application } from '../helper.js'; | ||
|
|
||
| describe('ManifestStore coverage: FileLoader getter auto-injects manifest', () => { | ||
| let app: Application; | ||
|
|
||
| afterAll(() => app?.close()); | ||
|
|
||
| it('should collect fileDiscovery when plugin uses app.loader.FileLoader', async () => { | ||
| app = createApp('middleware-override'); | ||
| await app.loader.loadPlugin(); | ||
| await app.loader.loadConfig(); | ||
| await app.loader.loadCustomApp(); | ||
| await app.loader.loadMiddleware(); | ||
| await app.loader.loadController(); | ||
| await app.loader.loadRouter(); | ||
|
|
||
| const manifest = app.loader.generateManifest(); | ||
|
|
||
| // resolveCache should contain resolved files (extend files, router, configs, boot hooks) | ||
| assert.ok(Object.keys(manifest.resolveCache).length > 0, 'resolveCache should have entries'); | ||
|
|
||
| // fileDiscovery should contain directory scans from middleware, controller loading | ||
| assert.ok(Object.keys(manifest.fileDiscovery).length > 0, 'fileDiscovery should have entries'); | ||
|
|
||
| // All resolveCache keys should be relative paths | ||
| for (const key of Object.keys(manifest.resolveCache)) { | ||
| assert.ok(!path.isAbsolute(key), `resolveCache key should be relative: ${key}`); | ||
| const value = manifest.resolveCache[key]; | ||
| if (value !== null) { | ||
| assert.ok(!path.isAbsolute(value), `resolveCache value should be relative: ${value}`); | ||
| } | ||
| } | ||
|
|
||
| // All fileDiscovery keys should be relative paths | ||
| for (const key of Object.keys(manifest.fileDiscovery)) { | ||
| assert.ok(!path.isAbsolute(key), `fileDiscovery key should be relative: ${key}`); | ||
| } | ||
| }); | ||
|
|
||
| it('should auto-inject manifest into FileLoader created via app.loader.FileLoader', async () => { | ||
| const testApp = createApp('context-loader'); | ||
| await testApp.loader.loadPlugin(); | ||
| await testApp.loader.loadConfig(); | ||
| await testApp.loader.loadCustomApp(); | ||
|
|
||
| // Use app.loader.FileLoader (the getter) to create a loader like plugins do | ||
| const CustomLoader = testApp.loader.FileLoader; | ||
| const target = {}; | ||
| const directory = getFilepath('context-loader/app/service'); | ||
| const loader = new CustomLoader({ | ||
| directory, | ||
| target, | ||
| inject: testApp, | ||
| }); | ||
| await loader.load(); | ||
|
|
||
| // Generate manifest and verify fileDiscovery captured the directory scan | ||
| const manifest = testApp.loader.generateManifest(); | ||
| const relDir = path.relative(testApp.loader.options.baseDir, directory).replaceAll(path.sep, '/'); | ||
|
|
||
| assert.ok( | ||
| relDir in manifest.fileDiscovery, | ||
| `fileDiscovery should contain '${relDir}', got keys: ${Object.keys(manifest.fileDiscovery).join(', ')}`, | ||
| ); | ||
| assert.ok(Array.isArray(manifest.fileDiscovery[relDir])); | ||
| assert.ok(manifest.fileDiscovery[relDir].length > 0, 'fileDiscovery should have files'); | ||
|
|
||
| await testApp.close(); | ||
| }); | ||
|
|
||
| it('should auto-inject manifest into ContextLoader created via app.loader.ContextLoader', async () => { | ||
| const testApp = createApp('context-loader'); | ||
| await testApp.loader.loadPlugin(); | ||
| await testApp.loader.loadConfig(); | ||
| await testApp.loader.loadCustomApp(); | ||
|
|
||
| // Use app.loader.ContextLoader (the getter) | ||
| const CustomContextLoader = testApp.loader.ContextLoader; | ||
| const directory = getFilepath('context-loader/app/service'); | ||
| const loader = new CustomContextLoader({ | ||
| directory, | ||
| property: 'testService', | ||
| inject: testApp, | ||
| }); | ||
| await loader.load(); | ||
|
|
||
| // Generate manifest and verify fileDiscovery captured the directory scan | ||
| const manifest = testApp.loader.generateManifest(); | ||
| const relDir = path.relative(testApp.loader.options.baseDir, directory).replaceAll(path.sep, '/'); | ||
|
|
||
| assert.ok( | ||
| relDir in manifest.fileDiscovery, | ||
| `fileDiscovery should contain '${relDir}', got keys: ${Object.keys(manifest.fileDiscovery).join(', ')}`, | ||
| ); | ||
|
|
||
| await testApp.close(); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard inferred manifest shape before assigning it
At Line 97,
options.inject.loader?.manifestis assigned without validating it is a real manifest store. Ifinjectcontains an unrelatedloader.manifestvalue,parse()will later fail when callingglobFiles(...).Proposed fix
🤖 Prompt for AI Agents