diff --git a/src/common.ts b/src/common.ts index 2f910f8..6363487 100644 --- a/src/common.ts +++ b/src/common.ts @@ -157,7 +157,7 @@ export function findMatchImage( extraMetas.hardwareVersionMin === i.hardwareVersionMin && extraMetas.hardwareVersionMax === i.hardwareVersionMax && i.modelId === extraMetas.modelId && - (!(i.manufacturerName && extraMetas.manufacturerName) || primitivesArrayEquals(i.manufacturerName, extraMetas.manufacturerName)), + (!i.manufacturerName || (extraMetas.manufacturerName && primitivesArrayEquals(i.manufacturerName, extraMetas.manufacturerName))), ); return [imageIndex, imageIndex === -1 ? undefined : imageList[imageIndex]]; diff --git a/tests/data.test.ts b/tests/data.test.ts index b6c431f..7fb962c 100644 --- a/tests/data.test.ts +++ b/tests/data.test.ts @@ -19,6 +19,7 @@ export const IMAGE_V13_1 = "ZLinky_router_v13.ota"; export const IMAGE_V13_2 = "ZLinky_router_v13_limited.ota"; export const IMAGE_V12_1 = "ZLinky_router_v12.ota"; export const IMAGE_V12_2 = "ZLinky_router_v12_limited.ota"; +export const IMAGE_V14_2_COPY = "ZLinky_router_v14_limited-copy.ota"; export const IMAGE_INVALID = "not-a-valid-file.ota"; export const IMAGE_TAR = "45856_00000006.tar.gz"; export const IMAGE_TAR_OTA = "Jasco_5_0_1_OnOff_45856_v6.ota"; @@ -171,6 +172,19 @@ export const IMAGE_V12_2_METAS = { sha512: "4e178e56c1559e11734c07abbb95110675df7738f3ca3e5dbc99393325295ff6c66bd63ba55c0ef6043a80608dbec2be7a1e845f31ffd94f1cb63f32f0d48c6e", otaHeaderString: "OM15081-RTR-LIMITED-JN5189-00000", }; +/** with manuf */ +export const IMAGE_V14_2_MANUF_METAS = { + fileName: IMAGE_V14_2_COPY, + fileVersion: 14, + fileSize: 249694, + originalUrl: undefined, + url: `${common.BASE_REPO_URL}${common.REPO_BRANCH}/images/${IMAGES_TEST_DIR}/${IMAGE_V14_2_COPY}`, + imageType: 2, + manufacturerCode: 4151, + sha512: "f851cbff7297ba6223a969ba8da5182f9ef199cf9c8459c8408432e48485c1a8f018f6e1703a42f40143cccd3bf460c0acd92117d899e507a36845f24e970595", + otaHeaderString: "OM15081-RTR-LIMITED-JN5189-00000", + manufacturerName: ["lixee"], +}; /** obviously bogus, just for mocking */ export const IMAGE_INVALID_METAS = { fileName: IMAGE_INVALID, diff --git a/tests/ghw_check_ota_pr.test.ts b/tests/ghw_check_ota_pr.test.ts index aa7d9bf..faeb659 100644 --- a/tests/ghw_check_ota_pr.test.ts +++ b/tests/ghw_check_ota_pr.test.ts @@ -22,6 +22,8 @@ import { IMAGE_V14_1, IMAGE_V14_1_METAS, IMAGE_V14_2, + IMAGE_V14_2_COPY, + IMAGE_V14_2_MANUF_METAS, IMAGE_V14_2_METAS, PREV_IMAGES_TEST_DIR_PATH, getAdjustedContent, @@ -449,6 +451,21 @@ Text after end tag`); ]); }); + it("success without extra metas with matching type-manuf present", async () => { + filePaths = [useImage(IMAGE_V14_2_COPY), useImage(IMAGE_V14_2)]; + const newContext = withBody(`\`\`\`json [{"fileName": "${IMAGE_V14_2_COPY}", "manufacturerName": ["lixee"]}] \`\`\``); + + // @ts-expect-error mock + await checkOtaPR(github, core, newContext); + + expect(readManifestSpy).toHaveBeenCalledWith(common.BASE_INDEX_MANIFEST_FILENAME); + expect(readManifestSpy).toHaveBeenCalledWith(common.PREV_INDEX_MANIFEST_FILENAME); + expect(addImageToBaseSpy).toHaveBeenCalledTimes(2); + expect(addImageToPrevSpy).toHaveBeenCalledTimes(0); + expect(writeManifestSpy).toHaveBeenCalledTimes(2); + expect(writeManifestSpy).toHaveBeenCalledWith(common.BASE_INDEX_MANIFEST_FILENAME, [IMAGE_V14_2_MANUF_METAS, IMAGE_V14_2_METAS]); + }); + it("success with newer than current but minFileVersion keeps both", async () => { filePaths = [useImage(IMAGE_V13_1), useImage(IMAGE_V14_1)]; const newContext = withBody( diff --git a/tests/images/ZLinky_router_v14_limited-copy.ota b/tests/images/ZLinky_router_v14_limited-copy.ota new file mode 100644 index 0000000..64b4568 Binary files /dev/null and b/tests/images/ZLinky_router_v14_limited-copy.ota differ