Fix an issue that could cause corrupted installs of EvenHub apps, and redirect corrupted installs into the update/reinstall

This commit is contained in:
James Babcock committed 2026-10-25 14:05:36 -07:00
1 parent 99f146529b
commit 247459bf99
7 files changed
+93 -7

No files matched your search

+24
View File
@@ -71,6 +71,30 @@ test('iOS installed apps launch, recover missing packages, and close before unin
assert.deepEqual(calls, [['launch', 'installed', 'test.app'], ['reinstall', 'test.app'], ['close', 'test.app'], ['uninstall', 'test.app']]);
});
test('iOS launch failures on a zeroed package fall back to the store page; other failures still report', async () => {
const calls = [], failures = [], app = { packageId: 'test.app', name: 'Test' };
let zeroed = true;
const modules = {
"../ui/input-monitor": load("app/ui/input-monitor.ts", {}),
'../apps/all-apps': { ALL_APPS: [{ appId: 'evenhub' }] },
'../apps/evenhub/installed-apps': { getInstalledEvenHubAppById: () => app,
discardZeroedEvenHubPackage: id => { calls.push(['discard', id]); return zeroed; } },
'../apps/evenhub/updates': { isInstalledPackagePresent: () => true },
'../apps/evenhub': { openEvenHubStoreForPackage: (_ctx, value) => calls.push(['reinstall', value.packageId]) },
'../apps/evenhub/manager': { launchInstalledPackage: async () => { calls.push(['launch']); throw new Error('Could not read the EHPK manifest.'); } },
};
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', { require: id => modules[id] ?? {} });
const host = Object.create(IosPreviewController.prototype);
host.buildAppContext = app => app; host.fail = error => failures.push(error.message); host.requestShellRender = () => {};
await host.launchApp('installed');
assert.deepEqual(calls, [['launch'], ['discard', 'test.app'], ['reinstall', 'test.app']]);
assert.deepEqual(failures, []);
calls.length = 0; zeroed = false;
await host.launchApp('installed');
assert.deepEqual(calls, [['launch'], ['discard', 'test.app']]);
assert.deepEqual(failures, ['Could not read the EHPK manifest.']);
});
test('iOS settings prompts honor password input and report cancellation', async () => {
const prompts = [], writes = [];
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', { require: id => id === '@nativescript/core' ? {
+32
View File
@@ -297,3 +297,35 @@ test('EvenHub assistant tools skip malformed names and schemas with a warning in
assert.match(warnings[4], /"union": parameters can't use oneOf, anyOf or allOf/);
h.session.close();
});
test('iOS binary downloads copy out of the response NSData, which bufferFromData does not retain', async () => {
const native = new Uint8Array([0x45, 0x48, 0x50, 0x4b, 1, 2, 3]);
const { downloadBinary } = loader({}, {
'@nativescript/core': { Http: { request: async () => ({ statusCode: 200, headers: {}, content: { toArrayBuffer: () => native.buffer } }) } },
'../util/http': { withUserAgent: headers => headers ?? {} },
})('app/native/binary-http.ios.ts');
const { bytes } = await downloadBinary('https://cdn.example/app.ehpk', 1000);
native.fill(0); // The released NSData's pages are reused or zeroed.
assert.deepEqual(Array.from(bytes), [0x45, 0x48, 0x50, 0x4b, 1, 2, 3]);
});
test('zeroed installed packages are discarded with their registry entry kept; real packages are left alone', () => {
const files = new Map(), deleted = [];
const installed = loader({}, {
fzstd: require('fzstd'),
'../../native/file-access': { readBinaryFile: path => files.get(path) ?? null, readTextFile() {}, writeBinaryFile() {},
appFilesDirPath: () => '/app', deletePathRecursively: path => { deleted.push(path); files.delete(path); } },
'../../native/settings-store': { getStringSetting: (_key, fallback) => fallback, setStringSetting() {} },
'../../native/icon-image': {}, '../../graphics/icons': {}, '../../graphics/image': {},
})('app/apps/evenhub/installed-apps.ts');
const path = installed.installedEvenHubPackagePath('test.app');
files.set(path, pack({ 'app.json': '{"package_id":"test.app"}' }));
assert.equal(installed.discardZeroedEvenHubPackage('test.app'), false);
files.set(path, new Uint8Array([...new Uint8Array(1000), 1]));
assert.equal(installed.discardZeroedEvenHubPackage('test.app'), false);
assert.equal(installed.discardZeroedEvenHubPackage('missing.app'), false);
assert.deepEqual(deleted, []);
files.set(path, new Uint8Array(4096));
assert.equal(installed.discardZeroedEvenHubPackage('test.app'), true);
assert.deepEqual(deleted, [path], 'only the EHPK goes; the icon and registry entry stay for Reinstall');
});