Detect and validate app runtime from uploaded archives.
Reject zip uploads when the selected runtime does not match archive contents, and re-validate before Kaniko builds to fail fast instead of producing the wrong Dockerfile. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -22,6 +22,30 @@ export interface ClassifiedError {
|
||||
backendMessage?: string;
|
||||
}
|
||||
|
||||
export interface RuntimeMismatchPayload {
|
||||
configured: string;
|
||||
detected: string;
|
||||
signals?: string[];
|
||||
}
|
||||
|
||||
/** Reads structured runtime mismatch fields from a 400 upload response. */
|
||||
export function readRuntimeMismatch(err: unknown): RuntimeMismatchPayload | null {
|
||||
if (!axios.isAxiosError(err) || err.response?.status !== 400) return null;
|
||||
const data = err.response.data;
|
||||
if (!data || typeof data !== 'object') return null;
|
||||
const body = data as Record<string, unknown>;
|
||||
if (typeof body.configured === 'string' && typeof body.detected === 'string') {
|
||||
return {
|
||||
configured: body.configured,
|
||||
detected: body.detected,
|
||||
signals: Array.isArray(body.signals)
|
||||
? body.signals.filter((s): s is string => typeof s === 'string')
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Flattens NestJS-style `message: string | string[]` into one string. */
|
||||
function readBackendMessage(data: unknown): string | undefined {
|
||||
if (!data || typeof data !== 'object') return undefined;
|
||||
|
||||
Reference in New Issue
Block a user