The model was reported as ready while the AI runtime was actually unreachable, and the Download action stayed visible afterwards. Distinguish model-downloaded from runtime-available in layaStatusPresentation, derive the Download action from the real combined state, and align Settings and ChannelList rendering on that single source of truth. Cover the combined status cases with tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
69 lines
2.9 KiB
JavaScript
69 lines
2.9 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { presentLayaStatus } = require('../public/js/services/layaStatusPresentation.js');
|
|
|
|
test('presents unknown-size downloads as indeterminate with downloaded bytes', () => {
|
|
const view = presentLayaStatus({
|
|
phase: 'downloading',
|
|
downloading: true,
|
|
progressPercent: null,
|
|
bytesDownloaded: 12 * 1024 * 1024,
|
|
totalBytes: null
|
|
});
|
|
assert.equal(view.progressIndeterminate, true);
|
|
assert.equal(view.progressPercent, null);
|
|
assert.equal(view.bytesDownloaded, 12 * 1024 * 1024);
|
|
assert.equal(view.showDownload, false);
|
|
assert.equal(view.showRemove, false);
|
|
});
|
|
|
|
test('presents known progress as a bounded percentage', () => {
|
|
const view = presentLayaStatus({ phase: 'downloading', downloading: true, progressPercent: 47.6 });
|
|
assert.equal(view.progressIndeterminate, false);
|
|
assert.equal(view.progressPercent, 48);
|
|
});
|
|
|
|
test('failed downloads expose retry, safe details and Standard fallback', () => {
|
|
const view = presentLayaStatus({
|
|
phase: 'failed',
|
|
modelPresent: false,
|
|
error: { message: 'Model download failed', detail: 'The optional Laya runtime is unavailable.' }
|
|
}, 'hybrid');
|
|
assert.equal(view.downloadLabel, 'Retry download');
|
|
assert.equal(view.showDownload, true);
|
|
assert.equal(view.showUseStandard, true);
|
|
assert.equal(view.errorMessage, 'Model download failed');
|
|
assert.equal(view.errorDetail, 'The optional Laya runtime is unavailable.');
|
|
});
|
|
|
|
test('ready models expose removal without download actions', () => {
|
|
const view = presentLayaStatus({ phase: 'ready', modelPresent: true, runtimeAvailable: true });
|
|
assert.equal(view.showRemove, true);
|
|
assert.equal(view.showDownload, false);
|
|
});
|
|
|
|
test('installed model with unavailable service is not reported ready', () => {
|
|
const view = presentLayaStatus({
|
|
phase: 'idle',
|
|
modelPresent: true,
|
|
runtimeAvailable: false,
|
|
sizeBytes: 10
|
|
}, 'hybrid');
|
|
assert.equal(view.ready, false);
|
|
assert.equal(view.statusLabel, 'Local AI service unavailable');
|
|
assert.equal(view.modelLabel, 'Model: Downloaded');
|
|
assert.equal(view.serviceLabel, 'Local AI service: Unavailable');
|
|
assert.equal(view.showDownload, false);
|
|
assert.equal(view.showRemove, true);
|
|
assert.equal(view.showCheckAgain, true);
|
|
assert.equal(view.showStartCommand, true);
|
|
assert.equal(view.availabilityMessage, 'The model is installed, but the Local AI service is not running. Standard channel matching is being used.');
|
|
});
|
|
|
|
test('missing model keeps download available', () => {
|
|
const view = presentLayaStatus({ phase: 'idle', modelPresent: false, runtimeAvailable: false });
|
|
assert.equal(view.showDownload, true);
|
|
assert.equal(view.showRemove, false);
|
|
assert.equal(view.showCheckAgain, false);
|
|
});
|