Skip to content

The agent that grows with you

fix(desktop): a stable-branded channel build runs with stable's userData

ethernet5fbe2afc141f
diff --git a/apps/desktop/electron-builder.config.cjs b/apps/desktop/electron-builder.config.cjs
index 80ee67df6b7..217667abe1f 100644
--- a/apps/desktop/electron-builder.config.cjs
+++ b/apps/desktop/electron-builder.config.cjs
@@ -25,7 +25,8 @@ const {
artifactNamePascal,
windowsExecutableName,
channel,
- msixAppIdWithOrg
+ msixAppIdWithOrg,
+ token
} = require('./product-identity.cjs')
// `storeMsix` is optional on the identity type but guaranteed present when
@@ -102,7 +103,8 @@ module.exports = {
name: appNamePascal,
// Electron bootstrap reads package.productName before main.ts. Keep the
// shipped stable default, but isolate nonstable userData from first access.
- ...(channelRequest || appNamePascal !== artifactNamePascal ? { productName: displayName } : {}),
+ // A stable-branded channel has no token and keeps stable's userData.
+ ...((channelRequest && token) || appNamePascal !== artifactNamePascal ? { productName: displayName } : {}),
desktopName: appId
},
directories: {
diff --git a/apps/desktop/electron/channel-build-version.test.ts b/apps/desktop/electron/channel-build-version.test.ts
index 7f5160f8985..bed3876e8f0 100644
--- a/apps/desktop/electron/channel-build-version.test.ts
+++ b/apps/desktop/electron/channel-build-version.test.ts
@@ -153,6 +153,54 @@ test('channel packaging reuses admitted identity and rejects unsupported or unsa
}, /identity/)
})
+test('a channel that copies the stable identity packages and runs as the regular app', (): void => {
+ process.env.HERMES_DESKTOP_VARIANT = 'bundled'
+
+ for (const file of ['../product-identity.cjs', '../electron-builder.config.cjs']) {
+ delete require.cache[require.resolve(file)]
+ }
+
+ const stable: PackagingFacts = {
+ identity: require('../product-identity.cjs'),
+ config: require('../electron-builder.config.cjs')
+ }
+
+ const { identity: official } = stable
+
+ const branded: PackagingFacts = load({
+ ...request(),
+ identity: {
+ token: 'ab12cd34ef56ab78',
+ displayName: official.displayName,
+ appId: official.appId,
+ appNamePascal: official.appNamePascal,
+ artifactNamePascal: official.artifactNamePascal,
+ cliName: official.cliName,
+ windowsExecutableName: official.windowsExecutableName,
+ msixAppIdWithOrg: official.msixAppIdWithOrg
+ }
+ })
+
+ // A token would make the runtime pin a userData dir that installed stable doesn't use.
+ assert.equal(branded.identity.token, undefined)
+ assert.equal(branded.identity.appId, official.appId)
+ assert.equal(branded.config.extraMetadata?.productName, stable.config.extraMetadata?.productName)
+ assert.equal(branded.config.extraMetadata?.name, stable.config.extraMetadata?.name)
+ assert.equal(branded.config.artifactName, stable.config.artifactName)
+
+ assert.equal(
+ applyDesktopIdentity(
+ {
+ getPath: (): string => assert.fail('stable userData must not be relocated'),
+ setPath: (): void => assert.fail('stable userData must not be relocated'),
+ setName: (): void => assert.fail('stable name must not change')
+ },
+ branded.identity
+ ),
+ null
+ )
+})
+
test('channel stamps verify the real checkout and retain source version and native ownership', async (): Promise<void> => {
const {
resolveStamp,
diff --git a/apps/desktop/product-identity.cjs b/apps/desktop/product-identity.cjs
index 1a0afddcb21..5e2353eb46f 100644
--- a/apps/desktop/product-identity.cjs
+++ b/apps/desktop/product-identity.cjs
@@ -89,6 +89,21 @@ const identity = {
const { channelBuildRequest } = require('../../scripts/msix-shared.mjs')
const request = channelBuildRequest()
-module.exports = request
- ? Object.freeze({ ...request.identity, store: false, light: false, channel: request.channel })
- : identity
+
+// A channel created with --branding stable copies stable's identity, so it IS
+// the regular app. It must also run like one: a token would make the runtime
+// pin a userData dir and single-instance lock that installed stable doesn't use.
+// The updater reads the token from the stamped request, not from this export.
+const officialChannel =
+ request !== null &&
+ ['appId', 'displayName', 'appNamePascal', 'artifactNamePascal', 'windowsExecutableName', 'cliName', 'msixAppIdWithOrg'].every(
+ key => request.identity[key] === identity[key]
+ )
+
+module.exports = !request
+ ? identity
+ : Object.freeze(
+ officialChannel
+ ? { ...identity, channel: request.channel }
+ : { ...request.identity, store: false, light: false, channel: request.channel }
+ )