测试DSML

This commit is contained in:
CJACK
2026-04-27 00:21:26 +08:00
parent 645fce41c8
commit 40d5e3ebb5
50 changed files with 1112 additions and 265 deletions

View File

@@ -49,6 +49,29 @@ test('parseToolCalls parses XML markup tool call', () => {
assert.deepEqual(calls[0].input, { path: 'README.MD' });
});
test('parseToolCalls parses DSML shell as XML-compatible tool call', () => {
const payload = '<|DSML|tool_calls><|DSML|invoke name="read_file"><|DSML|parameter name="path">README.MD</|DSML|parameter></|DSML|invoke></|DSML|tool_calls>';
const calls = parseToolCalls(payload, ['read_file']);
assert.equal(calls.length, 1);
assert.equal(calls[0].name, 'read_file');
assert.deepEqual(calls[0].input, { path: 'README.MD' });
});
test('parseToolCalls keeps canonical XML examples inside DSML CDATA', () => {
const content = '<tool_calls><invoke name="demo"><parameter name="value">x</parameter></invoke></tool_calls>';
const payload = `<|DSML|tool_calls><|DSML|invoke name="write_file"><|DSML|parameter name="path">notes.md</|DSML|parameter><|DSML|parameter name="content"><![CDATA[${content}]]></|DSML|parameter></|DSML|invoke></|DSML|tool_calls>`;
const calls = parseToolCalls(payload, ['write_file']);
assert.equal(calls.length, 1);
assert.equal(calls[0].name, 'write_file');
assert.deepEqual(calls[0].input, { path: 'notes.md', content });
});
test('parseToolCalls rejects mixed DSML and XML tool tags', () => {
const payload = '<|DSML|tool_calls><invoke name="read_file"><|DSML|parameter name="path">README.MD</|DSML|parameter></invoke></|DSML|tool_calls>';
const calls = parseToolCalls(payload, ['read_file']);
assert.equal(calls.length, 0);
});
test('parseToolCalls ignores JSON tool_calls payload (XML-only)', () => {
const payload = JSON.stringify({
tool_calls: [{ name: 'read_file', input: { path: 'README.MD' } }],
@@ -98,6 +121,22 @@ test('sieve emits tool_calls when XML tag spans multiple chunks', () => {
assert.equal(finalCalls[0].name, 'read_file');
});
test('sieve emits tool_calls when DSML tag spans multiple chunks', () => {
const events = runSieve(
[
'<|DSML|tool',
'_calls><|DSML|invoke name="read_file">',
'<|DSML|parameter name="path">README.MD</|DSML|parameter></|DSML|invoke></|DSML|tool_calls>',
],
['read_file'],
);
const leakedText = collectText(events);
const finalCalls = events.filter((evt) => evt.type === 'tool_calls').flatMap((evt) => evt.calls || []);
assert.equal(leakedText, '');
assert.equal(finalCalls.length, 1);
assert.equal(finalCalls[0].name, 'read_file');
});
test('sieve keeps long XML tool calls buffered until the closing tag arrives', () => {
const longContent = 'x'.repeat(4096);
const splitAt = longContent.length / 2;

View File

@@ -0,0 +1,58 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
cd "$ROOT_DIR"
source "${ROOT_DIR}/scripts/release-targets.sh"
OUT_DIR="${ROOT_DIR}/.tmp/cross-build"
build_one() {
local goos="$1" goarch="$2" goarm="$3" label="$4"
local out
out="${OUT_DIR}/${label}/ds2api"
if [[ "$goos" == "windows" ]]; then
out="${out}.exe"
fi
echo "[cross-build] ${label}"
mkdir -p "$(dirname "$out")"
if [[ "$goarm" == "-" ]]; then
CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" \
go build -buildvcs=false -trimpath -o "$out" ./cmd/ds2api
else
CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" GOARM="$goarm" \
go build -buildvcs=false -trimpath -o "$out" ./cmd/ds2api
fi
}
if [[ "${1:-}" == "--build-one" ]]; then
shift
build_one "$@"
exit 0
fi
jobs="${CROSS_BUILD_JOBS:-}"
if [[ -z "$jobs" ]]; then
if command -v nproc >/dev/null 2>&1; then
jobs="$(nproc)"
elif command -v sysctl >/dev/null 2>&1; then
jobs="$(sysctl -n hw.ncpu)"
else
jobs="2"
fi
fi
rm -rf "$OUT_DIR"
mkdir -p "$OUT_DIR"
if [[ "$jobs" -le 1 ]]; then
for target in "${DS2API_RELEASE_TARGETS[@]}"; do
read -r goos goarch goarm label <<< "$target"
build_one "$goos" "$goarch" "$goarm" "$label"
done
else
printf '%s\n' "${DS2API_RELEASE_TARGETS[@]}" \
| xargs -L 1 -P "$jobs" bash "${ROOT_DIR}/tests/scripts/check-cross-build.sh" --build-one
fi