MCPcopy Create free account
hub / github.com/Noumena-Network/code / updateLatest

Function updateLatest

src/utils/nativeInstaller/installer.ts:483–608  ·  view source on GitHub ↗
(
  channelOrVersion: string,
  forceReinstall: boolean = false,
)

Source from the content-addressed store, hash-verified

481}
482
483async function updateLatest(
484 channelOrVersion: string,
485 forceReinstall: boolean = false,
486): Promise<{
487 success: boolean
488 latestVersion: string
489 lockFailed?: boolean
490 lockHolderPid?: number
491}> {
492 const startTime = Date.now()
493 let version = await getLatestVersion(channelOrVersion)
494 const { executable: executablePath } = getBaseDirectories()
495
496 logForDebugging(`Checking for native installer update to version ${version}`)
497
498 // Check if max version is set (server-side kill switch for auto-updates)
499 if (!forceReinstall) {
500 const maxVersion = await getMaxVersion()
501 if (maxVersion && gt(version, maxVersion)) {
502 logForDebugging(
503 `Native installer: maxVersion ${maxVersion} is set, capping update from ${version} to ${maxVersion}`,
504 )
505 // If we're already at or above maxVersion, skip the update entirely
506 if (gte(MACRO.VERSION, maxVersion)) {
507 logForDebugging(
508 `Native installer: current version ${MACRO.VERSION} is already at or above maxVersion ${maxVersion}, skipping update`,
509 )
510 logEvent('ncode_native_update_skipped_max_version', {
511 latency_ms: Date.now() - startTime,
512 max_version:
513 maxVersion as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
514 available_version:
515 version as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
516 })
517 return { success: true, latestVersion: version }
518 }
519 version = maxVersion
520 }
521 }
522
523 // Early exit: if we're already running this exact version AND both the version binary
524 // and executable exist and are valid. We need to proceed if the executable doesn't exist,
525 // is invalid (e.g., empty/corrupted from a failed install), or we're running via npx.
526 if (
527 !forceReinstall &&
528 version === MACRO.VERSION &&
529 (await versionIsAvailable(version)) &&
530 (await isPossibleNcodeBinary(executablePath))
531 ) {
532 logForDebugging(`Found ${version} at ${executablePath}, skipping install`)
533 logEvent('ncode_native_update_complete', {
534 latency_ms: Date.now() - startTime,
535 was_new_install: false,
536 was_force_reinstall: false,
537 was_already_running: true,
538 })
539 return { success: true, latestVersion: version }
540 }

Callers 1

installLatestImplFunction · 0.85

Calls 15

isEnvTruthyFunction · 0.90
getBaseDirectoriesFunction · 0.85
getMaxVersionFunction · 0.85
gtFunction · 0.85
gteFunction · 0.85
versionIsAvailableFunction · 0.85
isPossibleNcodeBinaryFunction · 0.85
shouldSkipVersionFunction · 0.85
performVersionUpdateFunction · 0.85
getVersionPathsFunction · 0.85
forceRemoveLockFunction · 0.85
tryWithVersionLockFunction · 0.85

Tested by

no test coverage detected