MCPcopy Create free account
hub / github.com/TestSprite/testsprite-cli / readCodeFileGuarded

Function readCodeFileGuarded

src/commands/test.ts:850–878  ·  view source on GitHub ↗

* Read the code body with a `stat`-first size guard so an oversize * artifact is rejected BEFORE we load + decode the whole thing into * memory. `readCodeFile` was the original sole-source — now wraps the * guard so the same VALIDATION_ERROR / PAYLOAD_TOO_LARGE shapes the * tests assert on still

(path: string)

Source from the content-addressed store, hash-verified

848 * tests assert on still flow through.
849 */
850function readCodeFileGuarded(path: string): string {
851 const absolute = resolveAbsolute(path);
852 let stat;
853 try {
854 stat = statSync(absolute);
855 } catch (err) {
856 const code = (err as NodeJS.ErrnoException).code;
857 if (code === 'ENOENT') {
858 throw localValidationError('code-file', `file does not exist: ${path}`);
859 }
860 if (code === 'EACCES') {
861 throw localValidationError('code-file', `permission denied reading ${path}`);
862 }
863 const reason = err instanceof Error ? err.message : 'unknown error';
864 throw localValidationError('code-file', `cannot stat ${path}: ${reason}`);
865 }
866 if (stat.size > MAX_INLINE_CODE_BYTES) {
867 throw ApiError.fromEnvelope({
868 error: {
869 code: 'PAYLOAD_TOO_LARGE',
870 message: `Inline code exceeds the 350 KB CLI cap (${stat.size} bytes).`,
871 nextAction: 'Upload via the Portal, or split into smaller tests.',
872 requestId: 'local',
873 details: { field: 'code-file', sizeBytes: stat.size, maxBytes: MAX_INLINE_CODE_BYTES },
874 },
875 });
876 }
877 return readCodeFile(absolute);
878}
879
880function readCodeFile(path: string): string {
881 try {

Callers 2

runCreateFunction · 0.85
runCodePutFunction · 0.85

Calls 4

resolveAbsoluteFunction · 0.85
readCodeFileFunction · 0.85
fromEnvelopeMethod · 0.80
localValidationErrorFunction · 0.70

Tested by

no test coverage detected