(
req: Connect.IncomingMessage,
res: ServerResponse,
testDataPath: string,
log: Logger
)
| 104 | } |
| 105 | |
| 106 | async function handleAccept( |
| 107 | req: Connect.IncomingMessage, |
| 108 | res: ServerResponse, |
| 109 | testDataPath: string, |
| 110 | log: Logger |
| 111 | ): Promise<void> { |
| 112 | if (req.method !== 'POST') { |
| 113 | log.warn('[playground] /test-results/accept: wrong HTTP method'); |
| 114 | writeError(res, 405, 'Method not allowed'); |
| 115 | return; |
| 116 | } |
| 117 | if (!req.headers['content-length']) { |
| 118 | log.warn('[playground] /test-results/accept: missing content-length'); |
| 119 | writeError(res, 411, 'Length Required'); |
| 120 | return; |
| 121 | } |
| 122 | const bodyLength = Number.parseInt(req.headers['content-length']!, 10); |
| 123 | if (!Number.isFinite(bodyLength) || bodyLength > 10_000) { |
| 124 | log.warn(`[playground] /test-results/accept: invalid content-length ${req.headers['content-length']}`); |
| 125 | writeError(res, 413, 'Content Too Large'); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | const bodyText = await readBody(req, bodyLength); |
| 130 | let body: { newFile?: string; originalFile?: string }; |
| 131 | try { |
| 132 | body = JSON.parse(bodyText); |
| 133 | } catch { |
| 134 | log.warn('[playground] /test-results/accept: invalid JSON body'); |
| 135 | writeError(res, 400, 'Bad Request'); |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | if (typeof body.originalFile !== 'string' || typeof body.newFile !== 'string') { |
| 140 | log.warn('[playground] /test-results/accept: body missing originalFile/newFile'); |
| 141 | writeError(res, 400, 'Bad Request'); |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | let relativePath = removeLeadingSlash(body.newFile); |
| 146 | if (relativePath.startsWith('test-data/')) { |
| 147 | relativePath = relativePath.substring('test-data/'.length); |
| 148 | } |
| 149 | const newFile = path.normalize(path.resolve(testDataPath, relativePath)); |
| 150 | if (!newFile.startsWith(testDataPath)) { |
| 151 | log.warn(`[playground] /test-results/accept: rejected out-of-tree path ${newFile}`); |
| 152 | writeError(res, 400, 'Bad Request'); |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | await acceptOne(newFile); |
| 157 | writeJson(res, 200, 'OK', { message: 'Accepted' }); |
| 158 | } |
no test coverage detected