okami.mom/strata

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

Niko1221Merge f-027-win (main 2d07d1c0b with the DeepSeek slab scoping 32 MB unified / 8 MB discrete plus automatic growth, the dq kernel arch choice, and the HIP-only guard for the gfx11 WMMA gemm call)f92cfa437

main
4.6 KiB71 linesraw
1import test from 'node:test';
2import { ROOMY_HOST } from './helpers/hardware.mjs';
3import assert from 'node:assert/strict';
4import { spawn } from 'node:child_process';
5import { existsSync, readFileSync } from 'node:fs';
6import { mkdtemp, rm } from 'node:fs/promises';
7import { createServer } from 'node:net';
8import { tmpdir } from 'node:os';
9import { join } from 'node:path';
10import { fileURLToPath, pathToFileURL } from 'node:url';
11
12/**
13 * Strata works without internet. The host is started with every non-loopback fetch failing (and logged), the way a PC with the cable
14 * pulled behaves. Starting, reading the screens' data and loading a model make no outside call. The update check is the one
15 * thing that reaches out, and only when it is asked for: opening Settings does not ask.
16 */
17const root = fileURLToPath(new URL('..', import.meta.url));
18const preload = pathToFileURL(fileURLToPath(new URL('./helpers/offline-preload.mjs', import.meta.url))).href;
19const delay = ms => new Promise(r => setTimeout(r, ms));
20async function freePort() { const s = createServer(); await new Promise(r => s.listen(0, '127.0.0.1', r)); const p = s.address().port; await new Promise(r => s.close(r)); return p; }
21
22async function startOfflineHost() {
23  const home = await mkdtemp(join(tmpdir(), 'strata-offline-'));
24  const log = join(home, 'net.log');
25  const port = await freePort();
26  let output = '';
27  const host = spawn(process.execPath, ['--import', preload, 'server/index.mjs'], {
28    cwd: root, stdio: ['ignore', 'pipe', 'pipe'],
29    env: { ...process.env, STRATA_HOME: home, STRATA_MODELS_DIR: join(home, 'models'), STRATA_PORT: String(port), STRATA_SHARE_PORT: String(await freePort()), STRATA_TUNNEL_PORT: String(await freePort()), STRATA_PACKAGED: '1', STRATA_COMPONENTS_DIR: join(home, 'components'), STRATA_NET_LOG: log, STRATA_NO_ACQUIRE: '1', STRATA_REAL_ENGINE: '0', STRATA_TEST_HARDWARE: ROOMY_HOST },
30  });
31  host.stdout.on('data', d => { output += d; }); host.stderr.on('data', d => { output += d; });
32  let up = false;
33  for (let i = 0; i < 150 && !up; i++) { try { up = (await fetch(`http://127.0.0.1:${port}/api/health`)).ok; } catch { await delay(100); } }
34  assert.ok(up, `host started\n${output}`);
35  const calls = () => (existsSync(log) ? readFileSync(log, 'utf8').split('\n').filter(Boolean) : []);
36  const get = async path => { const r = await fetch(`http://127.0.0.1:${port}${path}`); return { status: r.status, data: await r.json().catch(() => null) }; };
37  const post = async path => { const r = await fetch(`http://127.0.0.1:${port}${path}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' }); return { status: r.status, data: await r.json().catch(() => null) }; };
38  return { host, get, post, calls, stop: async () => { host.kill(); await new Promise(r => host.once('exit', r)); await rm(home, { recursive: true, force: true }).catch(() => {}); } };
39}
40
41test('with no internet the host starts, serves its screens and loads a model without one outside call', async t => {
42  const h = await startOfflineHost();
43  t.after(h.stop);
44  assert.deepEqual(h.calls(), [], 'nothing reached out while starting');
45  for (const path of ['/api/native', '/api/setup', '/api/models', '/api/engine', '/api/health']) {
46    const r = await h.get(path);
47    assert.equal(r.status, 200, `${path} answers`);
48  }
49  const install = await h.post('/api/models/qwen38-q4_k_m/install');
50  assert.equal(install.status, 200);
51  let installed = false;
52  for (let i = 0; i < 150 && !installed; i++) { installed = (await h.get('/api/models')).data.variants.find(v => v.id === 'qwen38-q4_k_m').state === 'installed'; if (!installed) await delay(100); }
53  assert.ok(installed, 'the model is on this computer');
54  const load = await h.post('/api/models/qwen38-q4_k_m/load');
55  assert.equal(load.status, 200, JSON.stringify(load.data));
56  assert.equal(load.data.loaded, 'qwen38-q4_k_m');
57  assert.deepEqual(h.calls(), [], 'opening the screens and loading a model made no outside call');
58});
59
60test('the update check reaches out only when it is asked for, and offline it answers in plain words', async t => {
61  const h = await startOfflineHost();
62  t.after(h.stop);
63  await h.get('/api/setup'); await h.get('/api/native'); await h.get('/api/models');
64  assert.equal(h.calls().length, 0, 'opening the screens does not check');
65  const checked = await h.get('/api/updates/check');
66  assert.equal(checked.status, 200);
67  assert.equal(h.calls().length, 1, 'one check, from the click');
68  assert.equal(checked.data.strata.status, 'error');
69  assert.equal(checked.data.strata.message, "No internet connection. Try again when you're online.");
70  assert.doesNotMatch(JSON.stringify(checked.data), /fetch failed/);
71});