From bc8b26d5f80a2bff2c94fa5d5570b06c965be7b4 Mon Sep 17 00:00:00 2001 From: Chris Cuellar <58723+ChrisC@users.noreply.github.com> Date: Tue, 28 Nov 2023 22:12:28 -0800 Subject: [PATCH 1/7] set log message default to quiet --- scripts/update-bcd.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/update-bcd.ts b/scripts/update-bcd.ts index 31314231f..a406fa603 100644 --- a/scripts/update-bcd.ts +++ b/scripts/update-bcd.ts @@ -363,7 +363,12 @@ const reason = ( message: ReasonMessageFactory, args: Omit = {}, ): ReasonFactory => { - return (value) => ({message: message(value), skip: true, ...args}); + return (value) => ({ + message: message(value), + skip: true, + quiet: true, + ...args, + }); }; const isReasonFactory = ( @@ -975,9 +980,9 @@ export const update = ( if (!statements?.length) { return reason( ({browser, path}) => - `${path} skipped for ${browser}: no reason identified`, + `${path} skipped for ${browser}: no known reason identified. Possible intervention required.`, { - quiet: true, + quiet: false, }, ); } From e4944b9db88c8fd03d72e48eda24ad2ce79662ef Mon Sep 17 00:00:00 2001 From: Chris Cuellar <58723+ChrisC@users.noreply.github.com> Date: Tue, 28 Nov 2023 22:20:52 -0800 Subject: [PATCH 2/7] adds helper to detect contradictions --- scripts/update-bcd.test.ts | 120 +++++++++++++++++++++++++++++++++++++ scripts/update-bcd.ts | 66 +++++++++++++++++++- 2 files changed, 183 insertions(+), 3 deletions(-) diff --git a/scripts/update-bcd.test.ts b/scripts/update-bcd.test.ts index 891381c40..f1c9b8f88 100644 --- a/scripts/update-bcd.test.ts +++ b/scripts/update-bcd.test.ts @@ -19,6 +19,7 @@ import { findEntry, getSupportMap, getSupportMatrix, + hasSupportMatrixContradictions, inferSupportStatements, splitRange, update, @@ -821,6 +822,125 @@ describe("BCD updater", () => { }); }); + describe("hasSupportMatrixContradictions", () => { + it("detects contradictions with nonexistent support statements", () => { + assert.isTrue( + hasSupportMatrixContradictions(new Map([["80", true]]), { + version_added: null, + }), + ); + + assert.isTrue( + hasSupportMatrixContradictions(new Map([["80", true]]), undefined), + ); + }); + + it("skips null support claims", () => { + assert.isFalse( + hasSupportMatrixContradictions(new Map([["80", null]]), { + version_added: "≤80", + }), + ); + + assert.isFalse( + hasSupportMatrixContradictions( + new Map([ + ["79", false], + ["80", true], + ["81", true], + ["82", null], + ]), + { + version_added: "≤80", + }, + ), + "skips new null test result", + ); + }); + + it("detects contradictions in statements with boolean values", () => { + assert.isFalse( + hasSupportMatrixContradictions(new Map([["80", false]]), { + version_added: false, + }), + "skips generic false statements", + ); + // TODO: verify this is the result that we want + assert.isFalse( + hasSupportMatrixContradictions(new Map([["80", true]]), { + version_added: true, + }), + "skips generic true statements", + ); + + assert.isTrue( + hasSupportMatrixContradictions( + new Map([ + ["80", false], + ["81", true], + ]), + {version_added: false}, + ), + ); + }); + + it("detects contradictions in statements with string values", () => { + assert.isTrue( + hasSupportMatrixContradictions( + new Map([ + ["79", false], + ["80", false], + ["81", true], + ]), + { + version_added: "≤80", + }, + ), + ); + + assert.isFalse( + hasSupportMatrixContradictions( + new Map([ + ["79", false], + ["80", false], + ["81", true], + ]), + { + version_added: "81", + }, + ), + ); + + assert.isFalse( + hasSupportMatrixContradictions( + new Map([ + ["79", false], + ["80", true], + ["81", true], + ]), + { + version_added: "≤80", + }, + ), + ); + + assert.isTrue( + hasSupportMatrixContradictions( + new Map([ + ["79", false], + ["80", true], + ["81", true], + ["82", false], + ]), + { + version_added: "≤80", + }, + ), + "detects possible support removal", + ); + }); + }); + describe("update", () => { const supportMatrix = getSupportMatrix(reports, bcd.browsers, overrides); let bcdCopy; diff --git a/scripts/update-bcd.ts b/scripts/update-bcd.ts index a406fa603..b15804f0c 100644 --- a/scripts/update-bcd.ts +++ b/scripts/update-bcd.ts @@ -684,6 +684,42 @@ const skipCurrentBeforeSupport = skip("currentBeforeSupport", ({ } }); +export const hasSupportMatrixContradictions = ( + versionMap: BrowserSupportMap, + simpleStatement?: SimpleSupportStatement, +) => { + if (!simpleStatement || simpleStatement.version_added === null) { + return true; + } + + const contradictions: string[] = []; + for (const [version, supportAssertion] of versionMap.entries()) { + if (supportAssertion === null) { + continue; + } + + if (typeof simpleStatement.version_added === "boolean") { + if (simpleStatement.version_added !== supportAssertion) { + contradictions.push(version); + } + } + + if (typeof simpleStatement.version_added === "string") { + const simpleAdded = simpleStatement.version_added.replace("≤", ""); + if (compareVersions(version, simpleAdded, "<") && supportAssertion) { + contradictions.push(version); + } + if ( + compareVersions(version, simpleAdded, ">=") && + supportAssertion === false + ) { + contradictions.push(version); + } + } + } + return contradictions.length > 0; +}; + const persistInferredRange = provideStatements( "inferredRange", ({ @@ -924,6 +960,19 @@ export const update = ( } }), skipBrowserMismatch(options.browser), + provideAllStatements, + provideDefaultStatements, + skip("supportMatrixMatchesDefaultStatements", ({ + shared: {versionMap}, + defaultStatements: [simpleStatement], + }) => { + if (!hasSupportMatrixContradictions(versionMap, simpleStatement)) { + return reason( + ({path, browser}) => + `$${path} skipped for ${browser} because support matrix matches current BCD support data`, + ); + } + }), provide("inferredStatements", ({shared: {versionMap}}) => inferSupportStatements(versionMap), ), @@ -936,8 +985,6 @@ export const update = ( } }), skipReleaseMismatch(options.release), - provideAllStatements, - provideDefaultStatements, skip("zeroDefaultStatements", ({ inferredStatements: [inferredStatement], defaultStatements, @@ -976,8 +1023,21 @@ export const update = ( persistAddedOver, persistRemoved, clearNonExact(options.exactOnly), - skip("noStatement", ({statements}) => { + skip("noStatement", ({ + statements, + defaultStatements: [simpleStatement], + shared: {versionMap}, + }) => { if (!statements?.length) { + if (hasSupportMatrixContradictions(versionMap, simpleStatement)) { + return reason( + ({browser, path}) => + `${path} skipped for ${browser} with unresolved differences between support matrix and BCD data. Possible intervention required.`, + { + quiet: false, + }, + ); + } return reason( ({browser, path}) => `${path} skipped for ${browser}: no known reason identified. Possible intervention required.`, From ace7e41def04a6539fd9cb378d0c13c5046f3a33 Mon Sep 17 00:00:00 2001 From: Chris Cuellar <58723+ChrisC@users.noreply.github.com> Date: Wed, 29 Nov 2023 13:59:44 -0800 Subject: [PATCH 3/7] adds check for "preview" statement --- scripts/update-bcd.test.ts | 13 +++++++++++++ scripts/update-bcd.ts | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/scripts/update-bcd.test.ts b/scripts/update-bcd.test.ts index f1c9b8f88..995161f5f 100644 --- a/scripts/update-bcd.test.ts +++ b/scripts/update-bcd.test.ts @@ -938,6 +938,19 @@ describe("BCD updater", () => { ), "detects possible support removal", ); + + assert.isTrue( + hasSupportMatrixContradictions( + new Map([ + ["79", false], + ["80", true], + ["81", true], + ]), + { + version_added: "preview", + }, + ), + ); }); }); diff --git a/scripts/update-bcd.ts b/scripts/update-bcd.ts index b15804f0c..a00d155e8 100644 --- a/scripts/update-bcd.ts +++ b/scripts/update-bcd.ts @@ -692,6 +692,10 @@ export const hasSupportMatrixContradictions = ( return true; } + if (simpleStatement.version_added === "preview") { + return true; + } + const contradictions: string[] = []; for (const [version, supportAssertion] of versionMap.entries()) { if (supportAssertion === null) { From 846fb2e6e59fb432191673577eb6d067504c1a08 Mon Sep 17 00:00:00 2001 From: Chris Cuellar <58723+ChrisC@users.noreply.github.com> Date: Mon, 4 Dec 2023 15:08:19 -0800 Subject: [PATCH 4/7] catches specific version_added updates over generic support statements --- scripts/update-bcd.test.ts | 14 +++++++++++--- scripts/update-bcd.ts | 4 +++- unittest/bcd.test.ts | 3 +++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/update-bcd.test.ts b/scripts/update-bcd.test.ts index 995161f5f..37043f834 100644 --- a/scripts/update-bcd.test.ts +++ b/scripts/update-bcd.test.ts @@ -286,6 +286,11 @@ const reports: Report[] = [ exposure: "Window", result: false, }, + { + name: "api.unspecifiedVersionAPI", + exposure: "Window", + result: true, + }, { name: "css.properties.font-family", exposure: "Window", @@ -865,12 +870,12 @@ describe("BCD updater", () => { }), "skips generic false statements", ); - // TODO: verify this is the result that we want - assert.isFalse( + + assert.isTrue( hasSupportMatrixContradictions(new Map([["80", true]]), { version_added: true, }), - "skips generic true statements", + "catches specific support updates over generic true statements", ); assert.isTrue( @@ -1083,6 +1088,9 @@ describe("BCD updater", () => { SuperNewInterface: { __compat: {support: {chrome: {version_added: "100"}}}, }, + unspecifiedVersionAPI: { + __compat: {support: {chrome: {version_added: "≤85"}}}, + }, }, browsers: { chrome: {name: "Chrome", releases: {82: {}, 83: {}, 84: {}, 85: {}}}, diff --git a/scripts/update-bcd.ts b/scripts/update-bcd.ts index a00d155e8..596a2a85d 100644 --- a/scripts/update-bcd.ts +++ b/scripts/update-bcd.ts @@ -703,7 +703,9 @@ export const hasSupportMatrixContradictions = ( } if (typeof simpleStatement.version_added === "boolean") { - if (simpleStatement.version_added !== supportAssertion) { + if (!simpleStatement.version_added && !supportAssertion) { + continue; + } else { contradictions.push(version); } } diff --git a/unittest/bcd.test.ts b/unittest/bcd.test.ts index db453aa07..075f1dd18 100644 --- a/unittest/bcd.test.ts +++ b/unittest/bcd.test.ts @@ -116,6 +116,9 @@ export default { SuperNewInterface: { __compat: {support: {chrome: {version_added: "100"}}}, }, + unspecifiedVersionAPI: { + __compat: {support: {chrome: {version_added: true}}}, + }, }, browsers: { chrome: {name: "Chrome", releases: {82: {}, 83: {}, 84: {}, 85: {}}}, From 09eb95aa75a7a3c4e9a33d5e9ffd7506da4e7b18 Mon Sep 17 00:00:00 2001 From: Chris Cuellar <58723+ChrisC@users.noreply.github.com> Date: Mon, 4 Dec 2023 15:13:10 -0800 Subject: [PATCH 5/7] walks back edits to "normal" update unit test --- scripts/update-bcd.test.ts | 8 -------- unittest/bcd.test.ts | 3 --- 2 files changed, 11 deletions(-) diff --git a/scripts/update-bcd.test.ts b/scripts/update-bcd.test.ts index 37043f834..89640d132 100644 --- a/scripts/update-bcd.test.ts +++ b/scripts/update-bcd.test.ts @@ -286,11 +286,6 @@ const reports: Report[] = [ exposure: "Window", result: false, }, - { - name: "api.unspecifiedVersionAPI", - exposure: "Window", - result: true, - }, { name: "css.properties.font-family", exposure: "Window", @@ -1088,9 +1083,6 @@ describe("BCD updater", () => { SuperNewInterface: { __compat: {support: {chrome: {version_added: "100"}}}, }, - unspecifiedVersionAPI: { - __compat: {support: {chrome: {version_added: "≤85"}}}, - }, }, browsers: { chrome: {name: "Chrome", releases: {82: {}, 83: {}, 84: {}, 85: {}}}, diff --git a/unittest/bcd.test.ts b/unittest/bcd.test.ts index 075f1dd18..db453aa07 100644 --- a/unittest/bcd.test.ts +++ b/unittest/bcd.test.ts @@ -116,9 +116,6 @@ export default { SuperNewInterface: { __compat: {support: {chrome: {version_added: "100"}}}, }, - unspecifiedVersionAPI: { - __compat: {support: {chrome: {version_added: true}}}, - }, }, browsers: { chrome: {name: "Chrome", releases: {82: {}, 83: {}, 84: {}, 85: {}}}, From 388dc62e75d5f9ab04fdbeb8a974c941a303c47e Mon Sep 17 00:00:00 2001 From: Chris Cuellar <58723+ChrisC@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:18:37 -0800 Subject: [PATCH 6/7] stops using "contradictions" terminology --- scripts/update-bcd.test.ts | 30 ++++++++++++++---------------- scripts/update-bcd.ts | 6 +++--- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/scripts/update-bcd.test.ts b/scripts/update-bcd.test.ts index 89640d132..4b9eeffff 100644 --- a/scripts/update-bcd.test.ts +++ b/scripts/update-bcd.test.ts @@ -19,7 +19,7 @@ import { findEntry, getSupportMap, getSupportMatrix, - hasSupportMatrixContradictions, + hasSupportUpdates, inferSupportStatements, splitRange, update, @@ -822,28 +822,26 @@ describe("BCD updater", () => { }); }); - describe("hasSupportMatrixContradictions", () => { + describe("hasSupportUpdates", () => { it("detects contradictions with nonexistent support statements", () => { assert.isTrue( - hasSupportMatrixContradictions(new Map([["80", true]]), { + hasSupportUpdates(new Map([["80", true]]), { version_added: null, }), ); - assert.isTrue( - hasSupportMatrixContradictions(new Map([["80", true]]), undefined), - ); + assert.isTrue(hasSupportUpdates(new Map([["80", true]]), undefined)); }); it("skips null support claims", () => { assert.isFalse( - hasSupportMatrixContradictions(new Map([["80", null]]), { + hasSupportUpdates(new Map([["80", null]]), { version_added: "≤80", }), ); assert.isFalse( - hasSupportMatrixContradictions( + hasSupportUpdates( new Map([ ["79", false], ["80", true], @@ -860,21 +858,21 @@ describe("BCD updater", () => { it("detects contradictions in statements with boolean values", () => { assert.isFalse( - hasSupportMatrixContradictions(new Map([["80", false]]), { + hasSupportUpdates(new Map([["80", false]]), { version_added: false, }), "skips generic false statements", ); assert.isTrue( - hasSupportMatrixContradictions(new Map([["80", true]]), { + hasSupportUpdates(new Map([["80", true]]), { version_added: true, }), "catches specific support updates over generic true statements", ); assert.isTrue( - hasSupportMatrixContradictions( + hasSupportUpdates( new Map([ ["80", false], ["81", true], @@ -886,7 +884,7 @@ describe("BCD updater", () => { it("detects contradictions in statements with string values", () => { assert.isTrue( - hasSupportMatrixContradictions( + hasSupportUpdates( new Map([ ["79", false], ["80", false], @@ -899,7 +897,7 @@ describe("BCD updater", () => { ); assert.isFalse( - hasSupportMatrixContradictions( + hasSupportUpdates( new Map([ ["79", false], ["80", false], @@ -912,7 +910,7 @@ describe("BCD updater", () => { ); assert.isFalse( - hasSupportMatrixContradictions( + hasSupportUpdates( new Map([ ["79", false], ["80", true], @@ -925,7 +923,7 @@ describe("BCD updater", () => { ); assert.isTrue( - hasSupportMatrixContradictions( + hasSupportUpdates( new Map([ ["79", false], ["80", true], @@ -940,7 +938,7 @@ describe("BCD updater", () => { ); assert.isTrue( - hasSupportMatrixContradictions( + hasSupportUpdates( new Map([ ["79", false], ["80", true], diff --git a/scripts/update-bcd.ts b/scripts/update-bcd.ts index 596a2a85d..33e515b66 100644 --- a/scripts/update-bcd.ts +++ b/scripts/update-bcd.ts @@ -684,7 +684,7 @@ const skipCurrentBeforeSupport = skip("currentBeforeSupport", ({ } }); -export const hasSupportMatrixContradictions = ( +export const hasSupportUpdates = ( versionMap: BrowserSupportMap, simpleStatement?: SimpleSupportStatement, ) => { @@ -972,7 +972,7 @@ export const update = ( shared: {versionMap}, defaultStatements: [simpleStatement], }) => { - if (!hasSupportMatrixContradictions(versionMap, simpleStatement)) { + if (!hasSupportUpdates(versionMap, simpleStatement)) { return reason( ({path, browser}) => `$${path} skipped for ${browser} because support matrix matches current BCD support data`, @@ -1035,7 +1035,7 @@ export const update = ( shared: {versionMap}, }) => { if (!statements?.length) { - if (hasSupportMatrixContradictions(versionMap, simpleStatement)) { + if (hasSupportUpdates(versionMap, simpleStatement)) { return reason( ({browser, path}) => `${path} skipped for ${browser} with unresolved differences between support matrix and BCD data. Possible intervention required.`, From 1a15d198a36f6f6df4cd8f1f3d928474937e78ef Mon Sep 17 00:00:00 2001 From: Chris Cuellar <58723+ChrisC@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:35:56 -0800 Subject: [PATCH 7/7] fixes logic for handling "preview" statements --- scripts/update-bcd.test.ts | 20 +++++++++++++++++--- scripts/update-bcd.ts | 34 +++++++++++++++++----------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/scripts/update-bcd.test.ts b/scripts/update-bcd.test.ts index 4b9eeffff..a52d57757 100644 --- a/scripts/update-bcd.test.ts +++ b/scripts/update-bcd.test.ts @@ -823,7 +823,7 @@ describe("BCD updater", () => { }); describe("hasSupportUpdates", () => { - it("detects contradictions with nonexistent support statements", () => { + it("detects updates with nonexistent support statements", () => { assert.isTrue( hasSupportUpdates(new Map([["80", true]]), { version_added: null, @@ -856,7 +856,7 @@ describe("BCD updater", () => { ); }); - it("detects contradictions in statements with boolean values", () => { + it("detects updates in statements with boolean values", () => { assert.isFalse( hasSupportUpdates(new Map([["80", false]]), { version_added: false, @@ -882,7 +882,7 @@ describe("BCD updater", () => { ); }); - it("detects contradictions in statements with string values", () => { + it("detects updates in statements with string values", () => { assert.isTrue( hasSupportUpdates( new Map([ @@ -950,6 +950,20 @@ describe("BCD updater", () => { ), ); }); + + it("detects updates for preview statements", () => { + assert.isTrue( + hasSupportUpdates(new Map([["81", true]]), { + version_added: "preview", + }), + ); + + assert.isFalse( + hasSupportUpdates(new Map([["81", false]]), { + version_added: "preview", + }), + ); + }); }); describe("update", () => { diff --git a/scripts/update-bcd.ts b/scripts/update-bcd.ts index 33e515b66..5334551ef 100644 --- a/scripts/update-bcd.ts +++ b/scripts/update-bcd.ts @@ -692,38 +692,38 @@ export const hasSupportUpdates = ( return true; } - if (simpleStatement.version_added === "preview") { - return true; - } - - const contradictions: string[] = []; - for (const [version, supportAssertion] of versionMap.entries()) { - if (supportAssertion === null) { + const updates: string[] = []; + for (const [version, hasSupport] of versionMap.entries()) { + if (hasSupport === null) { continue; } if (typeof simpleStatement.version_added === "boolean") { - if (!simpleStatement.version_added && !supportAssertion) { + if (!simpleStatement.version_added && !hasSupport) { continue; } else { - contradictions.push(version); + updates.push(version); } } if (typeof simpleStatement.version_added === "string") { + if (simpleStatement.version_added === "preview") { + if (hasSupport) { + updates.push(version); + } + continue; + } + const simpleAdded = simpleStatement.version_added.replace("≤", ""); - if (compareVersions(version, simpleAdded, "<") && supportAssertion) { - contradictions.push(version); + if (compareVersions(version, simpleAdded, "<") && hasSupport) { + updates.push(version); } - if ( - compareVersions(version, simpleAdded, ">=") && - supportAssertion === false - ) { - contradictions.push(version); + if (compareVersions(version, simpleAdded, ">=") && !hasSupport) { + updates.push(version); } } } - return contradictions.length > 0; + return updates.length > 0; }; const persistInferredRange = provideStatements(