mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-11 11:47:43 +08:00
feat: Implement admin settings UI, enhance admin authentication with password hashing, and add new streaming runtime logic for Claude and OpenAI adapters with extensive compatibility tests.
This commit is contained in:
60
api/compat/js_compat_test.js
Normal file
60
api/compat/js_compat_test.js
Normal file
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const chatStream = require('../chat-stream');
|
||||
const { parseToolCalls } = require('../helpers/stream-tool-sieve');
|
||||
|
||||
const { parseChunkForContent, estimateTokens } = chatStream.__test;
|
||||
|
||||
const compatRoot = path.resolve(__dirname, '../../tests/compat');
|
||||
|
||||
function readJSON(filePath) {
|
||||
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
}
|
||||
|
||||
test('js compat: sse fixtures', () => {
|
||||
const fixtureDir = path.join(compatRoot, 'fixtures', 'sse_chunks');
|
||||
const expectedDir = path.join(compatRoot, 'expected');
|
||||
const files = fs.readdirSync(fixtureDir).filter((f) => f.endsWith('.json')).sort();
|
||||
assert.ok(files.length > 0);
|
||||
|
||||
for (const file of files) {
|
||||
const name = file.replace(/\.json$/i, '');
|
||||
const fixture = readJSON(path.join(fixtureDir, file));
|
||||
const expected = readJSON(path.join(expectedDir, `sse_${name}.json`));
|
||||
const got = parseChunkForContent(fixture.chunk, Boolean(fixture.thinking_enabled), fixture.current_type || 'text');
|
||||
assert.deepEqual(got.parts, expected.parts, `${name}: parts mismatch`);
|
||||
assert.equal(got.finished, expected.finished, `${name}: finished mismatch`);
|
||||
assert.equal(got.newType, expected.new_type, `${name}: newType mismatch`);
|
||||
}
|
||||
});
|
||||
|
||||
test('js compat: toolcall fixtures', () => {
|
||||
const fixtureDir = path.join(compatRoot, 'fixtures', 'toolcalls');
|
||||
const expectedDir = path.join(compatRoot, 'expected');
|
||||
const files = fs.readdirSync(fixtureDir).filter((f) => f.endsWith('.json')).sort();
|
||||
assert.ok(files.length > 0);
|
||||
|
||||
for (const file of files) {
|
||||
const name = file.replace(/\.json$/i, '');
|
||||
const fixture = readJSON(path.join(fixtureDir, file));
|
||||
const expected = readJSON(path.join(expectedDir, `toolcalls_${name}.json`));
|
||||
const got = parseToolCalls(fixture.text, fixture.tool_names || []);
|
||||
assert.deepEqual(got, expected.calls, `${name}: calls mismatch`);
|
||||
}
|
||||
});
|
||||
|
||||
test('js compat: token fixtures', () => {
|
||||
const fixture = readJSON(path.join(compatRoot, 'fixtures', 'token_cases.json'));
|
||||
const expected = readJSON(path.join(compatRoot, 'expected', 'token_cases.json'));
|
||||
const expectedByName = new Map(expected.cases.map((c) => [c.name, c.tokens]));
|
||||
for (const c of fixture.cases) {
|
||||
assert.ok(expectedByName.has(c.name), `missing expected case: ${c.name}`);
|
||||
const got = estimateTokens(c.text);
|
||||
assert.equal(got, expectedByName.get(c.name), `${c.name}: tokens mismatch`);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user