- Add missing test case for lan environment detection - Simplify detectEnvironment() to match spec exactly - Remove extra logic (version number detection, ft_ prefix check) - Update test expectations to match simplified implementation behavior - All tests now pass with spec-compliant implementation
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
export type ApkEnvironment = 'dev' | 'sandbox' | 'product' | 'other';
|
|
|
|
export interface ParsedApkMetadata {
|
|
environment: ApkEnvironment;
|
|
commit: string | null;
|
|
isValid: boolean;
|
|
}
|
|
|
|
// Environment mapping based on filename patterns
|
|
const ENVIRONMENT_MAP: Record<string, ApkEnvironment> = {
|
|
'timeshift': 'dev',
|
|
'lan': 'dev',
|
|
'dev': 'dev',
|
|
'sandbox': 'sandbox',
|
|
};
|
|
|
|
export function detectEnvironment(filename: string): ApkEnvironment {
|
|
// Pattern: ft_[environment]_version_commit.apk
|
|
// Extract the environment segment between first and second underscores
|
|
const match = filename.match(/^ft_([^_]+)_/);
|
|
|
|
if (!match) {
|
|
// No environment suffix, default to product
|
|
return 'product';
|
|
}
|
|
|
|
const env = match[1].toLowerCase();
|
|
return ENVIRONMENT_MAP[env] || 'other';
|
|
}
|
|
|
|
export function parseApkFilename(filename: string): ParsedApkMetadata {
|
|
const environment = detectEnvironment(filename);
|
|
const commitMatch = filename.match(/([a-f0-9]{7,})\.apk$/);
|
|
const commit = commitMatch ? commitMatch[1] : null;
|
|
const isValid = commit !== null;
|
|
|
|
return {
|
|
environment,
|
|
commit,
|
|
isValid,
|
|
};
|
|
}
|