okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221merge f-split-fr (owner app UI fixes, rounds 1-5) into f-split-int8820fa433

main
2.7 KiB39 linesraw
1import test from 'node:test';
2import assert from 'node:assert/strict';
3import { build } from 'esbuild';
4
5const built = await build({ stdin: { contents: "export * from './src/lib/download-eta';", resolveDir: process.cwd() }, bundle: true, write: false, format: 'esm', platform: 'node', loader: { '.json': 'json' }, external: ['react'] });
6const src = built.outputFiles[0].text.replace(/from\s*["']react["']/, 'from "data:text/javascript,export const useRef=()=>({current:null}),useEffect=()=>{},useState=v=>[v,()=>{}]"');
7const { etaMinutes, etaLabel, installProgress } = await import(`data:text/javascript;base64,${Buffer.from(src).toString('base64')}`);
8
9test('the time left comes from the recent rate, and says nothing until there is one', () => {
10  assert.equal(etaMinutes([{ at: 0, done: 1 }], 50), null);
11  assert.equal(etaMinutes([{ at: 0, done: 1 }, { at: 5000, done: 3 }], 50), null, 'under ten seconds of samples');
12  assert.equal(etaMinutes([{ at: 0, done: 1 }, { at: 20000, done: 1 }], 50), null, 'nothing moved');
13  assert.equal(etaMinutes([{ at: 0, done: 0 }, { at: 20000, done: 10 }], 60), 2, '0.5 GB/s, 60 GB left: 120 s');
14  assert.equal(etaMinutes([{ at: 0, done: 0 }, { at: 60000, done: 1 }], 0.1), 1, 'never below one minute');
15});
16
17test('the label is minutes, and hours past an hour and a half', () => {
18  assert.equal(etaLabel(null), '');
19  assert.equal(etaLabel(3), 'About 3 min left');
20  assert.equal(etaLabel(125), 'About 2 h 5 min left');
21  assert.equal(etaLabel(120), 'About 2 h left');
22});
23
24test('one count over all the parts of the job: the model files and, when there is one, the engine', () => {
25  const model = { kind: 'model', done_gb: 30, total_gb: 60, state: 'downloading' };
26  const engine = { kind: 'engine', done_gb: 0.3, total_gb: 0.7, state: 'downloading' };
27  const both = installProgress({ parts: [model, engine], download: { done_gb: 0, total_gb: 1 } });
28  assert.equal(both.total_gb, 60.7);
29  assert.ok(Math.abs(both.done_gb - 30.3) < 1e-9);
30  assert.equal(both.percent, 49);
31  assert.ok(Math.abs(both.remaining_gb - 30.4) < 1e-9);
32  const modelOnly = installProgress({ parts: [model] });
33  assert.equal(modelOnly.total_gb, 60);
34  assert.equal(installProgress({ parts: [model, { ...engine, state: 'skipped' }, { kind: 'engine', state: 'current', total_gb: 1, done_gb: 1 }] }).total_gb, 60, 'a part that is skipped or already current is not downloaded');
35  // no parts: the job's own combined figures
36  assert.deepEqual(installProgress({ download: { done_gb: 5, total_gb: 50, percent: 10 } }), { done_gb: 5, total_gb: 50, remaining_gb: 45, percent: 10, file: undefined });
37  assert.equal(installProgress({}), undefined);
38  assert.equal(installProgress(undefined), undefined);
39});