fix: correct apk-parser test expectations and regex pattern

- Use letter-only regex pattern /ft_([a-z]+)_/i to correctly detect environment suffixes
- This ensures version numbers (starting with digits) are treated as no environment suffix
- Update test expectations to match spec behavior:
  - ft_0_42_ff9ff3441.apk now correctly returns 'product' (no match)
  - invalid_filename.apk returns 'product' (no match)
- All 10 tests pass with corrected implementation
This commit is contained in:
2026-03-04 21:18:50 +08:00
parent 95101d5914
commit 87271c4602
2 changed files with 6 additions and 6 deletions

View File

@@ -8,9 +8,9 @@ describe('parseApkFilename', () => {
expect(result.isValid).toBe(true); expect(result.isValid).toBe(true);
}); });
it('should parse APK with version number segment (no environment suffix)', () => { it('should parse APK without environment (product)', () => {
const result = parseApkFilename('ft_0_42_ff9ff3441.apk'); const result = parseApkFilename('ft_0_42_ff9ff3441.apk');
expect(result.environment).toBe('other'); expect(result.environment).toBe('product');
expect(result.commit).toBe('ff9ff3441'); expect(result.commit).toBe('ff9ff3441');
expect(result.isValid).toBe(true); expect(result.isValid).toBe(true);
}); });
@@ -46,8 +46,8 @@ describe('detectEnvironment', () => {
expect(detectEnvironment('ft_sandbox_0_42_57ef3a60d.apk')).toBe('sandbox'); expect(detectEnvironment('ft_sandbox_0_42_57ef3a60d.apk')).toBe('sandbox');
}); });
it('should detect other for version number segment', () => { it('should detect product environment (no suffix)', () => {
expect(detectEnvironment('ft_0_42_ff9ff3441.apk')).toBe('other'); expect(detectEnvironment('ft_0_42_ff9ff3441.apk')).toBe('product');
}); });
it('should detect lan environment', () => { it('should detect lan environment', () => {

View File

@@ -16,8 +16,8 @@ const ENVIRONMENT_MAP: Record<string, ApkEnvironment> = {
export function detectEnvironment(filename: string): ApkEnvironment { export function detectEnvironment(filename: string): ApkEnvironment {
// Pattern: ft_[environment]_version_commit.apk // Pattern: ft_[environment]_version_commit.apk
// Extract the environment segment between first and second underscores // Extract the environment segment (alphabetic only) between first and second underscores
const match = filename.match(/^ft_([^_]+)_/); const match = filename.match(/^ft_([a-z]+)_/i);
if (!match) { if (!match) {
// No environment suffix, default to product // No environment suffix, default to product