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: trueenabled in your localota.config.json). - Point both platforms in
ota.config.jsonathttp://127.0.0.1:18787/check. - On Android (both physical USB devices and emulators), map port
18787to your host machine:
adb reverse tcp:18787 tcp:18787- On iOS Simulator, ensure
App_Resources/iOS/Info.plistincludesNSAppTransportSecurity -> NSAllowsLocalNetworking = truefor 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:
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-22. Serve the packed release locally
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 1Launch 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().sourcereports'ota'.updates.getBootInfo().releaseIdreports'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:
# 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 4Every fault leaves the active release untouched and wipes partial files from staging/.
