Files
leleka/engine/strata/apps/host/tests/web-offline.test.mjs
T
Pavlo RatushnyiandClaude Sonnet 5.5 87e2633afe engine/strata: bring the Strata subtree to upstream 41cf05a0 (engine 0.1.50) with the local patches re-applied
Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree
(570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base =
the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main).

Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR
experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details,
conflict table and left-out files are in docs/upstream.md.

Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61),
docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out.

scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run").
Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR
macros on. No GPU run, no quality gate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:49:15 +01:00

49 lines
3.4 KiB
JavaScript

/** With no internet the assistant gets plain words from the web tools, not "fetch failed", and can go on without them. */
import test from 'node:test';
import assert from 'node:assert/strict';
import { mkdtempSync, mkdirSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { createDuckDuckGoSearch, UNREACHABLE_MESSAGE } from '../server/web-search-ddg.mjs';
import { plainToolError, withPlain } from '../server/agent/events.mjs';
import { startScriptedWorker } from './helpers/scripted-worker.mjs';
import { createAgentBridge } from '../server/agent/agent-bridge.mjs';
import { resolveHarness } from '../server/agent/harness-runtime.mjs';
const HARNESS = process.env.STRATA_HARNESS_DIR;
const skip = !HARNESS || !resolveHarness({ env: process.env }).ok ? 'STRATA_HARNESS_DIR is not set to a built Harness' : false;
test('search with no internet: one readable sentence that tells the model to go on without it', async () => {
let t = 5_000_000; // a pretend clock that moves when the search waits, as in web-search.test.mjs
const offline = createDuckDuckGoSearch({ fetch: async () => { throw new TypeError('fetch failed'); }, now: () => t, sleep: async ms => { t += ms; }, random: () => 0.5 });
const error = await offline.search({ query: 'heat pumps' }).catch(e => e);
assert.equal(error.message, UNREACHABLE_MESSAGE);
assert.match(error.message, /could not reach the internet/);
assert.match(error.message, /go on with what you know/);
assert.doesNotMatch(error.message, /fetch failed|ENOTFOUND|TypeError/);
});
test('opening a page with no internet: the card says so in plain words and keeps the technical text behind Details', () => {
for (const raw of ['Error: web fetch failed: fetch failed', 'Error: getaddrinfo ENOTFOUND example.com', 'Error: connect ECONNREFUSED 93.184.216.34:443']) {
const text = withPlain(raw);
assert.match(text, /^That web page could not be opened\. Check the address and your internet connection\./, raw);
assert.match(text, /Details: /);
}
assert.equal(plainToolError(UNREACHABLE_MESSAGE), null, 'the search sentence is already plain and is left as it is');
});
test('real Harness: the model gets the plain sentence when the search cannot reach the internet', { skip }, async t => {
const worker = await startScriptedWorker({ chunkDelayMs: 5 });
const dir = mkdtempSync(join(tmpdir(), 'strata-weboff-'));
const ws = join(dir, 'ws'); mkdirSync(ws, { recursive: true });
const bridge = createAgentBridge({ dataDir: dir, localInstances: () => [{ id: 'i', label: 'S', baseUrl: worker.url, modelId: 'scripted-model', context: 32768 }], connections: () => [], env: process.env, startTimeoutMs: 90_000, searchMock: 'offline' });
t.after(async () => { await bridge.close(); await worker.close(); try { rmSync(dir, { recursive: true, force: true, maxRetries: 3 }); } catch { /* best effort */ } });
const frames = [];
await bridge.runTurn({ chatId: 'off1', message: 'SCRIPT:call web_search {"queries":["heat pumps"]}', workspacePath: ws, mode: 'bypass', onFrame: f => frames.push(f) });
const card = frames.filter(f => f.type === 'agent-tool' && f.tool.name === 'web_search').at(-1).tool;
assert.equal(card.state, 'error');
assert.match(card.result, /could not reach the internet/);
assert.doesNotMatch(card.result, /fetch failed/);
assert.equal(frames.at(-1).type, 'done', 'the turn ends normally');
});