Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

👷 ci(desktop): retry stapler validate for the Computer Use helper (#20950)

Neko38689fef858b
diff --git a/apps/desktop/scripts/__tests__/computerUseHelper.test.mjs b/apps/desktop/scripts/__tests__/computerUseHelper.test.mjs
index b024114e45d..26ae491a30c 100644
--- a/apps/desktop/scripts/__tests__/computerUseHelper.test.mjs
+++ b/apps/desktop/scripts/__tests__/computerUseHelper.test.mjs
@@ -133,6 +133,46 @@ describe('Computer Use helper packaging', () => {
).toThrow(/expected 0.0.33/);
});
+ it('retries stapler validate when the ticket lookup loses its network connection', () => {
+ const appPath = '/x/LobeHub Computer Use.app';
+ const base = createExecute();
+ let staplerCalls = 0;
+ const execute = vi.fn((command, args) => {
+ if (command === 'xcrun' && ++staplerCalls < 3) {
+ return { status: 68, stderr: 'The network connection was lost.', stdout: '' };
+ }
+ return base(command, args);
+ });
+ const sleep = vi.fn();
+ const logger = { warn: vi.fn() };
+
+ verifyComputerUseHelper(appPath, { execute, logger, sleep, version: '0.0.33' });
+
+ expect(staplerCalls).toBe(3);
+ expect(sleep.mock.calls).toEqual([[5000], [15_000]]);
+ expect(logger.warn.mock.calls.map(([message]) => message)).toEqual([
+ expect.stringMatching(/attempt 1\/3\), retrying in 5s: .*exited with 68/),
+ expect.stringMatching(/attempt 2\/3\), retrying in 15s: .*exited with 68/),
+ ]);
+ });
+
+ it('fails when stapler validate keeps failing', () => {
+ const base = createExecute();
+ const execute = vi.fn((command, args) =>
+ command === 'xcrun'
+ ? { status: 68, stderr: 'The network connection was lost.', stdout: '' }
+ : base(command, args),
+ );
+ const sleep = vi.fn();
+ const logger = { warn: vi.fn() };
+
+ expect(() =>
+ verifyComputerUseHelper('/x/LobeHub Computer Use.app', { execute, logger, sleep }),
+ ).toThrow(/stapler validate .* exited with 68/);
+ expect(execute.mock.calls.filter(([command]) => command === 'xcrun')).toHaveLength(3);
+ expect(sleep).toHaveBeenCalledTimes(2);
+ });
+
it('copies the verified helper into Contents/Library/Helpers with ditto', async () => {
const execute = createExecute();
const appPath = path.join(cacheDir, 'LobeHub.app');
diff --git a/apps/desktop/scripts/computerUseHelper.mjs b/apps/desktop/scripts/computerUseHelper.mjs
index e3521b0a9a0..0906beaee36 100644
--- a/apps/desktop/scripts/computerUseHelper.mjs
+++ b/apps/desktop/scripts/computerUseHelper.mjs
@@ -63,6 +63,33 @@ const run = (execute, command, args) => {
return result;
};
+const STAPLER_VALIDATE_RETRY_DELAYS_MS = [5000, 15_000];
+
+const sleepSync = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
+
+/**
+ * `stapler validate` looks the ticket up in Apple's CloudKit service, and CI
+ * runners intermittently lose that connection (exit 68, NSURLErrorDomain).
+ * Retry before failing the build; a missing or invalid ticket fails every try.
+ */
+const validateStapledTicket = (execute, appPath, { logger, sleep }) => {
+ const attempts = STAPLER_VALIDATE_RETRY_DELAYS_MS.length + 1;
+ for (let attempt = 0; ; attempt++) {
+ try {
+ return run(execute, 'xcrun', ['stapler', 'validate', appPath]);
+ } catch (error) {
+ const delay = STAPLER_VALIDATE_RETRY_DELAYS_MS[attempt];
+ if (delay === undefined) throw error;
+ // Logged so a build that only passes on retry stays visible in CI output.
+ const reason = String(error.message).split('\n')[0].slice(0, 200);
+ logger.warn(
+ `⚠️ stapler validate failed (attempt ${attempt + 1}/${attempts}), retrying in ${delay / 1000}s: ${reason}`,
+ );
+ sleep(delay);
+ }
+ }
+};
+
const sha256 = (buffer) => createHash('sha256').update(buffer).digest('hex');
const download = async (fetchImpl, url) => {
@@ -76,7 +103,10 @@ const download = async (fetchImpl, url) => {
* Run before embedding and again after LobeHub.app is signed, which proves
* electron-builder left the helper's signature and ticket alone.
*/
-export const verifyComputerUseHelper = (appPath, { execute = spawnSync, version } = {}) => {
+export const verifyComputerUseHelper = (
+ appPath,
+ { execute = spawnSync, logger = console, sleep = sleepSync, version } = {},
+) => {
run(execute, 'codesign', ['--verify', '--strict', '--deep', '--verbose=2', appPath]);
// codesign prints the signing details on stderr.
@@ -89,7 +119,7 @@ export const verifyComputerUseHelper = (appPath, { execute = spawnSync, version
);
}
- run(execute, 'xcrun', ['stapler', 'validate', appPath]);
+ validateStapledTicket(execute, appPath, { logger, sleep });
if (version) {
const infoPlist = path.join(appPath, 'Contents', 'Info.plist');