Skip to content

Local testing workflow ​

Before wiring any hosted backend, you can verify the complete download, cryptographic verification, cold-start activation, fault-rejection and offline crash-rollback loop locally with ota-ns serve.

Prerequisites ​

  • Built release binary on iOS Simulator or Android device/emulator (allowInsecureHttp: true enabled in your local ota.config.json).
  • Point both platforms in ota.config.json at http://127.0.0.1:18787/check.
  • On Android (both physical USB devices and emulators), map port 18787 to your host machine:
sh
adb reverse tcp:18787 tcp:18787
  • On iOS Simulator, ensure App_Resources/iOS/Info.plist includes NSAppTransportSecurity -> NSAllowsLocalNetworking = true for local testing only.

1. Pack a local OTA update ​

Edit a visible label or validation rule in TypeScript, prepare the release Webpack bundle, and pack it:

sh
ns prepare ios --release --env.production

npx ota-ns pack \
  --platform ios \
  --project . \
  --baseline ./ota.baseline.ios.json \
  --release-id ota-local-2 \
  --private-key ~/.ota-keys/dev.private.pem \
  --key-id dev \
  --out /tmp/ota-local-2

2. Serve the packed release locally ​

sh
npx ota-ns serve \
  --bundle /tmp/ota-local-2 \
  --private-key ~/.ota-keys/dev.private.pem \
  --key-id dev \
  --port 18787 \
  --mode update \
  --directive-seq 1

Launch the installed release binary once. updates.checkAndStage() downloads all files into staging/ota-local-2, verifies Ed25519 and SHA-256, and promotes the directory into releases/ota-local-2.

3. Cold-restart offline ​

Stop ota-ns serve (Ctrl+C), force-quit the app, and launch it again with no server running:

  • updates.getBootInfo().source reports 'ota'.
  • updates.getBootInfo().releaseId reports 'ota-local-2'.
  • Calling updates.markReady() confirms the release locally without network access.

4. Exercise fault injection modes ​

Restart ota-ns serve with a new --directive-seq and test every defensive gate:

sh
# Rejects before download with OtaError(SIGNATURE_INVALID)
npx ota-ns serve --bundle /tmp/ota-local-3 --private-key ... --key-id dev --mode bad-directive-sig --directive-seq 2

# Rejects during streaming verification with OtaError(HASH_MISMATCH)
npx ota-ns serve --bundle /tmp/ota-local-3 --private-key ... --key-id dev --mode tampered-file --directive-seq 3

# Aborts TCP socket mid-transfer with OtaError(DOWNLOAD_FAILED)
npx ota-ns serve --bundle /tmp/ota-local-3 --private-key ... --key-id dev --mode drop-mid-download --directive-seq 4

Every fault leaves the active release untouched and wipes partial files from staging/.