CodeSampleX

Exemple

electron-updater 6.8.9: MacUpdater

Échantillon vérifié pour npm electron-updater 6.8.9: MacUpdater. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:bea781697a415d37e46834fd058d738c57d77a061911e718de5e9847c319116b

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-26

Cas

HOW
Objectif
verify MacUpdater in pkg:npm/electron-updater@6.8.9
Paquets
Symboles
  • MacUpdater
Créé
2026-08-26T10:52:53Z

Contrat

  1. MacUpdater is exported as a class extending AppUpdater from electron-updater
  2. MacUpdater.filterFilesForArch selects arm64 target files on arm64 architecture
  3. MacUpdater.filterFilesForArch excludes arm64 files on x64 architecture
  4. MacUpdater.filterFilesForArch falls back to universal/x64 files on arm64 when no arm64 build is present
  5. MacUpdater initializes with configurable publish options and app adapter defaults
  6. MacUpdater supports configuring autoDownload, allowPrerelease, and update channel
  7. MacUpdater forwards error events from the underlying native autoUpdater
  8. MacUpdater tracks squirrelDownloadedUpdate and handles quitAndInstall workflow

Fichiers

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

Télécharger l’artefact source (tar.gz)

Code source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify MacUpdater in pkg:npm/electron-updater@6.8.9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/electron-updater@6.8.9
Demonstrate these symbols/APIs:
  - MacUpdater

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:c176a792597af1bb1b1ecce0ea3c5beb0c09d969f40d99cdd6e7717bbfb1c761","contract":["MacUpdater is exported as a class extending AppUpdater from electron-updater","MacUpdater.filterFilesForArch selects arm64 target files on arm64 architecture","MacUpdater.filterFilesForArch excludes arm64 files on x64 architecture","MacUpdater.filterFilesForArch falls back to universal/x64 files on arm64 when no arm64 build is present","MacUpdater initializes with configurable publish options and app adapter defaults","MacUpdater supports configuring autoDownload, allowPrerelease, and update channel","MacUpdater forwards error events from the underlying native autoUpdater","MacUpdater tracks squirrelDownloadedUpdate and handles quitAndInstall workflow"],"goal":"verify MacUpdater in pkg:npm/electron-updater@6.8.9","kind":"HOW","packages":["pkg:npm/electron-updater@6.8.9"],"schemaVersion":1,"symbols":["MacUpdater"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/electron-updater@6.8.9"],"schemaVersion":1,"subject":"pkg:npm/electron-updater@6.8.9","symbols":["MacUpdater"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-electron-updater-mac-updater",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-electron-updater-mac-updater",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "electron-updater": "6.8.9"
      }
    },
    "node_modules/argparse": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
      "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
      "license": "Python-2.0"
    },
    "node_modules/builder-util-runtime": {
      "version": "9.7.0",
      "resolved": "https://registry.npmjs.org/builder-util-runtime/-/builder-util-runtime-9.7.0.tgz",
      "integrity": "sha512-g/kR520giAFYkSXTzcmF3kqQq7wi8F6N6SzeDgZrqTBN+VHdmgWOyTdD1yD7AATDId/yXLvuP34CxW46/BwCdw==",
      "license": "MIT",
      "dependencies": {
        "debug": "^4.3.4",
        "sax": "^1.2.4"
      },
      "engines": {
        "node": ">=12.0.0"
      }
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/electron-updater": {
      "version": "6.8.9",
      "resolved": "https://registry.npmjs.org/electron-updater/-/electron-updater-6.8.9.tgz",
      "integrity": "sha512-ZhVxM9iGONUpZGI1FxdMRgJjUFXi7AYGVa5PwKlO1tV1/4zDxQmfKpXOHVztKrd6L9rLcFjERvi1Mf2vxyTkig==",
      "license": "MIT",
      "dependencies": {
        "builder-util-runtime": "9.7.0",
        "fs-extra": "^10.1.0",
        "js-yaml": "^4.1.0",
        "lazy-val": "^1.0.5",
        "lodash.escaperegexp": "^4.1.2",
        "lodash.isequal": "^4.5.0",
        "semver": "~7.7.3",
        "tiny-typed-emitter": "^2.1.0"
      }
    },
    "node_modules/fs-extra": {
      "version": "10.1.0",
      "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz",
      "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==",
      "license": "MIT",
      "dependencies": {
        "graceful-fs": "^4.2.0",
        "jsonfile": "^6.0.1",
        "universalify": "^2.0.0"
      },
      "engines": {
        "node": ">=12"
      }
    },
    "node_modules/graceful-fs": {
      "version": "4.2.11",
      "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
      "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
      "license": "ISC"
    },
    "node_modules/js-yaml": {
      "version": "4.3.1",
      "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.1.tgz",
      "integrity": "sha512-CY6crGq313MX8GkwvB7tzgp99vjQxY1++5y10/BKN/GUfHqWaOGQMNZkBvqSzsZKWk/ijwHlWzzkLulsGHhjWQ==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/puzrin"
        },
        {
          "type": "github",
          "url": "https://github.com/sponsors/nodeca"
        }
      ],
      "license": "MIT",
      "dependencies": {
        "argparse": "^2.0.1"
      },
      "bin": {
        "js-yaml": "bin/js-yaml.js"
      }
    },
    "node_modules/jsonfile": {
      "version": "6.2.1",
      "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.1.tgz",
      "integrity": "sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q==",
      "license": "MIT",
      "dependencies": {
        "universalify": "^2.0.0"
      },
      "optionalDependencies": {
        "graceful-fs": "^4.1.6"
      }
    },
    "node_modules/lazy-val": {
      "version": "1.0.5",
      "resolved": "https://registry.npmjs.org/lazy-val/-/lazy-val-1.0.5.tgz",
      "integrity": "sha512-0/BnGCCfyUMkBpeDgWihanIAF9JmZhHBgUhEqzvf+adhNGLoP6TaiI5oF8oyb3I45P+PcnrqihSf01M0l0G5+Q==",
      "license": "MIT"
    },
    "node_modules/lodash.escaperegexp": {
      "version": "4.1.2",
      "resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz",
      "integrity": "sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw==",
      "license": "MIT"
    },
    "node_modules/lodash.isequal": {
      "version": "4.5.0",
      "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
      "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==",
      "deprecated": "This package is deprecated. Use require('node:util').isDeepStrictEqual instead.",
      "license": "MIT"
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    },
    "node_modules/sax": {
      "version": "1.6.1",
      "resolved": "https://registry.npmjs.org/sax/-/sax-1.6.1.tgz",
      "integrity": "sha512-42tBVwLWnaQvW5zc4HbZrTuWccECCZfBi92FDuwtqxasH+JbPB3/FOKb1m222K42R4WxuxzzMsTswfzgtSu64Q==",
      "license": "BlueOak-1.0.0",
      "engines": {
        "node": ">=11.0.0"
      }
    },
    "node_modules/semver": {
      "version": "7.7.4",
      "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz",
      "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==",
      "license": "ISC",
      "bin": {
        "semver": "bin/semver.js"
      },
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/tiny-typed-emitter": {
      "version": "2.1.0",
      "resolved": "https://registry.npmjs.org/tiny-typed-emitter/-/tiny-typed-emitter-2.1.0.tgz",
      "integrity": "sha512-qVtvMxeXbVej0cQWKqVSSAHmKZEHAvxdF8HEUBFWts8h+xEo5m/lEiPakuyZ3BnCBjOD8i24kzNOiOLLgsSxhA==",
      "license": "MIT"
    },
    "node_modules/universalify": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
      "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==",
      "license": "MIT",
      "engines": {
        "node": ">= 10.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-electron-updater-mac-updater",
  "version": "1.0.0",
  "private": true,
  "license": "MIT-0",
  "main": "src/index.js",
  "dependencies": {
    "electron-updater": "6.8.9"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify MacUpdater in pkg:npm/electron-updater@6.8.9",
  "kind": "HOW",
  "packages": [
    "pkg:npm/electron-updater@6.8.9"
  ],
  "symbols": [
    "MacUpdater"
  ]
}
src/index.js
const { MacUpdater, AppUpdater } = require('electron-updater');

/**
 * Creates a MacUpdater instance with optional publish configuration and app adapter.
 *
 * @param {object} [options] - Publish options (e.g. provider, url).
 * @param {object} [appAdapter] - Custom app adapter implementing AppAdapter interface.
 * @returns {MacUpdater} The MacUpdater instance.
 */
function createMacUpdater(options, appAdapter) {
  return new MacUpdater(options, appAdapter);
}

/**
 * Filters update files to target the appropriate macOS architecture.
 *
 * @param {Array<{url: URL, info: {url: string}}>} files - Array of resolved update file info objects.
 * @param {boolean} isArm64Mac - Whether the host machine is Apple Silicon (arm64).
 * @returns {Array<{url: URL, info: {url: string}}>} Filtered update file info objects.
 */
function filterFilesForMacArch(files, isArm64Mac) {
  return MacUpdater.filterFilesForArch(files, isArm64Mac);
}

/**
 * Applies custom configuration options to a MacUpdater instance.
 *
 * @param {MacUpdater} updater - The MacUpdater instance.
 * @param {object} [config] - Options for autoDownload, allowPrerelease, channel, etc.
 * @returns {MacUpdater} The configured updater.
 */
function configureMacUpdater(updater, config = {}) {
  if (typeof config.autoDownload === 'boolean') {
    updater.autoDownload = config.autoDownload;
  }
  if (typeof config.autoInstallOnAppQuit === 'boolean') {
    updater.autoInstallOnAppQuit = config.autoInstallOnAppQuit;
  }
  if (typeof config.allowPrerelease === 'boolean') {
    updater.allowPrerelease = config.allowPrerelease;
  }
  if (typeof config.allowDowngrade === 'boolean') {
    updater.allowDowngrade = config.allowDowngrade;
  }
  if (typeof config.channel === 'string') {
    updater.channel = config.channel;
  }
  return updater;
}

module.exports = {
  MacUpdater,
  AppUpdater,
  createMacUpdater,
  filterFilesForMacArch,
  configureMacUpdater
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import { EventEmitter } from 'node:events';

const require = createRequire(import.meta.url);

// Set up mock electron module in require cache before loading electron-updater
class MockNativeUpdater extends EventEmitter {
  constructor() {
    super();
    this.feedUrl = null;
    this.checkCalled = false;
    this.quitAndInstallCalled = false;
  }
  setFeedURL(options) {
    this.feedUrl = options;
  }
  checkForUpdates() {
    this.checkCalled = true;
  }
  quitAndInstall() {
    this.quitAndInstallCalled = true;
  }
}

const mockNativeUpdater = new MockNativeUpdater();
let appQuitCalled = false;
let appRelaunchCalled = false;

const mockAppAdapter = {
  version: '1.0.0',
  name: 'test-app',
  isPackaged: true,
  appUpdateConfigPath: '/mock/path/app-update.yml',
  userDataPath: '/mock/path/userData',
  baseCachePath: '/mock/path/cache',
  whenReady: async () => {},
  relaunch: () => { appRelaunchCalled = true; },
  quit: () => { appQuitCalled = true; },
  onQuit: (_handler) => {}
};

const mockElectron = {
  autoUpdater: mockNativeUpdater,
  app: {
    getVersion: () => '1.0.0',
    getName: () => 'test-app',
    isPackaged: true,
    getAppPath: () => '/mock/path',
    getPath: (name) => `/mock/path/${name}`,
    whenReady: async () => {},
    on: () => {},
    once: () => {},
    removeListener: () => {},
    relaunch: () => { appRelaunchCalled = true; },
    quit: () => { appQuitCalled = true; }
  }
};

const Module = require('module');
const originalResolveFilename = Module._resolveFilename;
Module._resolveFilename = function(request, parent, isMain, options) {
  if (request === 'electron') {
    return 'electron';
  }
  return originalResolveFilename.call(this, request, parent, isMain, options);
};

require.cache['electron'] = {
  id: 'electron',
  filename: 'electron',
  loaded: true,
  exports: mockElectron
};

const electronUpdater = require('electron-updater');
const {
  MacUpdater,
  AppUpdater,
  createMacUpdater,
  filterFilesForMacArch,
  configureMacUpdater
} = require('../src/index.js');

// 1. MacUpdater is exported as a class extending AppUpdater from electron-updater
assert.equal(typeof MacUpdater, 'function', 'MacUpdater must be a constructor function/class');
assert.ok(MacUpdater.prototype instanceof AppUpdater, 'MacUpdater must extend AppUpdater');
assert.strictEqual(MacUpdater, electronUpdater.MacUpdater, 'MacUpdater export must match electron-updater.MacUpdater');

// 2. MacUpdater.filterFilesForArch selects arm64 target files on arm64 architecture
const multiArchFiles = [
  { url: new URL('https://example.com/download/app-1.0.0-mac-x64.zip'), info: { url: 'app-1.0.0-mac-x64.zip' } },
  { url: new URL('https://example.com/download/app-1.0.0-mac-arm64.zip'), info: { url: 'app-1.0.0-mac-arm64.zip' } },
  { url: new URL('https://example.com/download/app-1.0.0-mac-universal.zip'), info: { url: 'app-1.0.0-mac-universal.zip' } }
];

const arm64Selection = filterFilesForMacArch(multiArchFiles, true);
assert.equal(arm64Selection.length, 1, 'filterFilesForArch must select exactly 1 file on arm64 when arm64 build exists');
assert.equal(arm64Selection[0].info.url, 'app-1.0.0-mac-arm64.zip', 'arm64 selection must pick the arm64 zip artifact');

// 3. MacUpdater.filterFilesForArch excludes arm64 files on x64 architecture
const x64Selection = filterFilesForMacArch(multiArchFiles, false);
assert.equal(x64Selection.length, 2, 'filterFilesForArch must keep non-arm64 files on x64 architecture');
assert.deepEqual(
  x64Selection.map((f) => f.info.url),
  ['app-1.0.0-mac-x64.zip', 'app-1.0.0-mac-universal.zip'],
  'x64 selection must include x64 and universal files while excluding arm64'
);

// 4. MacUpdater.filterFilesForArch falls back to universal/x64 files on arm64 when no arm64 build is present
const nonArm64Files = [
  { url: new URL('https://example.com/download/app-1.0.0-mac-x64.zip'), info: { url: 'app-1.0.0-mac-x64.zip' } },
  { url: new URL('https://example.com/download/app-1.0.0-mac-universal.zip'), info: { url: 'app-1.0.0-mac-universal.zip' } }
];
const fallbackSelection = filterFilesForMacArch(nonArm64Files, true);
assert.equal(fallbackSelection.length, 2, 'filterFilesForArch must fall back to all available files when arm64 is absent');
assert.deepEqual(
  fallbackSelection.map((f) => f.info.url),
  ['app-1.0.0-mac-x64.zip', 'app-1.0.0-mac-universal.zip'],
  'arm64 fallback must return non-arm64 files'
);

// 5. MacUpdater initializes with configurable publish options and app adapter defaults
const updater = createMacUpdater({ provider: 'generic', url: 'https://example.com/updates' }, mockAppAdapter);
assert.equal(updater.autoDownload, true, 'autoDownload must default to true');
assert.equal(updater.autoInstallOnAppQuit, true, 'autoInstallOnAppQuit must default to true');
assert.equal(updater.allowPrerelease, false, 'allowPrerelease must default to false');
assert.equal(updater.allowDowngrade, false, 'allowDowngrade must default to false');
assert.equal(updater.currentVersion.version, '1.0.0', 'currentVersion must match app adapter version');

// 6. MacUpdater supports configuring autoDownload, allowPrerelease, and update channel
configureMacUpdater(updater, {
  autoDownload: false,
  autoInstallOnAppQuit: false,
  allowPrerelease: true,
  allowDowngrade: true,
  channel: 'beta'
});
assert.equal(updater.autoDownload, false, 'autoDownload must be configurable to false');
assert.equal(updater.autoInstallOnAppQuit, false, 'autoInstallOnAppQuit must be configurable to false');
assert.equal(updater.allowPrerelease, true, 'allowPrerelease must be configurable to true');
assert.equal(updater.allowDowngrade, true, 'allowDowngrade must be configurable to true');
assert.equal(updater.channel, 'beta', 'channel must be configurable to beta');

// 7. MacUpdater forwards error events from the underlying native autoUpdater
let capturedError = null;
updater.on('error', (err) => {
  capturedError = err;
});
const testError = new Error('Simulated Squirrel.Mac failure');
mockNativeUpdater.emit('error', testError);
assert.strictEqual(capturedError, testError, 'MacUpdater must propagate native updater error event');

// 8. MacUpdater tracks squirrelDownloadedUpdate and handles quitAndInstall workflow
mockNativeUpdater.emit('update-downloaded');
updater.quitAndInstall();
assert.equal(mockNativeUpdater.quitAndInstallCalled, true, 'quitAndInstall must call native updater quitAndInstall when downloaded');

console.log('Contract tests passed successfully.');

Seeder d'origine

anonyme