Files
leleka/engine/strata/apps/host/tests/connect-urls.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

52 lines
2.9 KiB
JavaScript

// Connect an app: Anthropic-style apps get the server root (they add /v1/messages themselves), OpenAI-style apps keep /v1,
// and the host accepts /v1/v1/messages as the same request for people who pasted the old address.
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import http from 'node:http';
import { build } from 'esbuild';
import { apiPath } from '../server/api-paths.mjs';
import { createLocalShare } from '../server/local-share.mjs';
const bundled = await build({ entryPoints: ['src/lib/connect-urls.ts'], bundle: true, write: false, format: 'esm', platform: 'node' });
const { serverRoot, appBaseUrl } = await import(`data:text/javascript;base64,${Buffer.from(bundled.outputFiles[0].text).toString('base64')}`);
test('the Anthropic tab shows the address without /v1, the other tabs keep it', () => {
const base = 'http://127.0.0.1:8792/v1';
assert.equal(appBaseUrl(base, 'anthropic'), 'http://127.0.0.1:8792');
assert.equal(appBaseUrl(base, 'openai'), base);
assert.equal(appBaseUrl(base, 'responses'), base);
assert.equal(serverRoot('https://abc.trycloudflare.com/v1/'), 'https://abc.trycloudflare.com');
assert.equal(serverRoot('http://192.168.1.5:8792'), 'http://192.168.1.5:8792');
assert.equal(serverRoot('http://host/api/v1'), 'http://host/api');
});
test('the Connect dialog gives the Anthropic tab the root address and says why in plain words', async () => {
const screen = await readFile('src/screens/Serving.tsx', 'utf8');
assert.match(screen, /appBaseUrl\(serving\.baseUrl, protocol\)/);
assert.match(screen, /ANTHROPIC_BASE_URL/);
});
test('/v1/v1/messages is read as /v1/messages, and nothing else is aliased', () => {
assert.equal(apiPath('/v1/v1/messages'), '/v1/messages');
assert.equal(apiPath('/v1/v1/messages/'), '/v1/messages');
assert.equal(apiPath('/v1/v1/messages/count_tokens'), '/v1/messages/count_tokens');
assert.equal(apiPath('/v1/messages'), '/v1/messages');
for (const other of ['/v1/v1/chat/completions', '/v1/v1/models', '/v1/v1/responses', '/v1/v1/v1/messages']) assert.equal(apiPath(other), other);
});
test('the shared (key-protected) listener serves /v1/v1/messages as /v1/messages', async () => {
const seen = [];
const share = createLocalShare({ handle: async (req, res, path) => { seen.push(path); res.writeHead(200); res.end('ok'); }, hasKey: () => true, host: '127.0.0.1', port: 0 });
const { url } = await share.start();
try {
const root = url.replace(/\/v1$/, '');
for (const path of ['/v1/messages', '/v1/v1/messages']) {
const res = await fetch(root + path, { method: 'POST', body: '{}' });
assert.equal(res.status, 200, path);
}
assert.deepEqual(seen, ['/v1/messages', '/v1/messages']);
assert.equal((await fetch(root + '/v1/v1/chat/completions', { method: 'POST', body: '{}' })).status, 404);
} finally { await share.stop(); }
});