fix(kill-switch): handle non-semver extension versions well

This change makes the extension convert non-semver versions to semver
versions so the kill switch logic can correctly compare the extension
version with the affected versions range set in kill switches.

It does so by only allowing version numbers to have 3 parts, and
stripping further sub-versioning. In the canary version, version numbers
consist of 4 parts (the latest version number followed by a dot and the
number of commits made since that release). Thus, this fixes an issue in
the kill switch logic for the canary channel.

Fixed: twpowertools:189
Change-Id: Iee62f75c38e73b39786a0fc05de6e827edd4c8a2
diff --git a/src/common/extUtils.js b/src/common/extUtils.js
index 39cf196..591d810 100644
--- a/src/common/extUtils.js
+++ b/src/common/extUtils.js
@@ -14,6 +14,13 @@
   return manifest?.version;
 }
 
+// Returns a semver-compatible extension version
+export function getSemVerExtVersion() {
+  const version = getExtVersion();
+  if (!(typeof version === 'string')) return null;
+  return version.match(/^[^.]*(?:\.[^.]*){0,2}/)?.[0] ?? null;
+}
+
 // Get a URL to a document which is part of the extension documentation (using
 // |ref| as the Git ref).
 export function getDocURLWithRef(doc, ref) {
diff --git a/src/killSwitch/index.js b/src/killSwitch/index.js
index a1083b1..6be6589 100644
--- a/src/killSwitch/index.js
+++ b/src/killSwitch/index.js
@@ -1,7 +1,7 @@
 import {compareLoose} from 'semver';
 
 import actionApi from '../common/actionApi.js';
-import {getExtVersion} from '../common/extUtils.js';
+import {getSemVerExtVersion} from '../common/extUtils.js';
 
 import * as commonPb from './api_proto/common_pb.js';
 import {KillSwitchServicePromiseClient} from './api_proto/kill_switch_grpc_web_pb.js';
@@ -51,8 +51,10 @@
     this.client.getKillSwitchOverview(request)
         .then(res => {
           let killSwitches = res.getKillSwitchesList();
-          let currentVersion = getExtVersion();
-          if (currentVersion === '0') currentVersion = '0.0.0';
+          let currentVersion = getSemVerExtVersion();
+          if (currentVersion === '0' || currentVersion === null) {
+            currentVersion = '0.0.0';
+          }
 
           let forceDisabledFeaturesSet = new Set();
           for (let killSwitch of killSwitches) {