mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-08-28 05:25:25 +00:00
* Fix MCP startup transport compatibility * Preserve CLI flags in MCP startup fix * Harden MCP transport error handling * Harden transport security and improve type safety Transport hardening: - Add MAX_BUFFER_SIZE (10 MB) cap to prevent OOM from oversized Content-Length or unbounded newline-delimited input - Replace recursive readNewlineMessage with iterative loop to prevent stack overflow from consecutive empty lines - Tighten looksLikeContentLength to require 14+ bytes before matching - Add closed-state guard and error handling to send() - Simplify processReadBuffer loop to break on error - Fix loose equality (==) to strict (===) - Widen constructor param types to ReadableStream/WritableStream Type safety: - Constrain createLazyAction generics so export name is validated against the module's actual exports at compile time - Use proper type guard instead of lint suppression - Fix test tsconfig type errors Regression tests for all hardening fixes (13 tests passing). --------- Co-authored-by: Gergo Magyar <gergomagyar@icloud.com>
21 lines
758 B
TypeScript
21 lines
758 B
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { createLazyAction } from '../../src/cli/lazy-action.js';
|
|
|
|
describe('createLazyAction', () => {
|
|
it('does not import target module until invoked', async () => {
|
|
const loader = vi.fn(async () => ({
|
|
run: vi.fn(async () => 'ok'),
|
|
}));
|
|
|
|
const action = createLazyAction(loader, 'run');
|
|
|
|
expect(loader).not.toHaveBeenCalled();
|
|
await expect(action('arg-1')).resolves.toBeUndefined();
|
|
expect(loader).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('throws a clear error when export is not a function', async () => {
|
|
const action = createLazyAction(async () => ({ notAFunction: 'string-value' }), 'notAFunction');
|
|
await expect(action()).rejects.toThrow('notAFunction');
|
|
});
|
|
});
|