Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"devDependencies": {
"@types/node": "^22.0.0",
"@types/node-forge": "^1.3.14",
"acp-kernel": "0.0.93",
"acp-kernel": "0.0.95",
"fzstd": "0.1.1",
"jsonc-parser": "^3.3.1",
"node-forge": "^1.4.0",
Expand Down
306 changes: 192 additions & 114 deletions tests/golden/wire-contract/bili.json

Large diffs are not rendered by default.

612 changes: 384 additions & 228 deletions tests/golden/wire-contract/kernel.json

Large diffs are not rendered by default.

306 changes: 192 additions & 114 deletions tests/golden/wire-contract/manifest-default.json

Large diffs are not rendered by default.

306 changes: 192 additions & 114 deletions tests/golden/wire-contract/manifest-optin.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions tests/preflight-compress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { listSessions } from "../src/session.ts";
// Scenario:
// 1. Request 1 on claude-big (400k window), upstream reports
// input_tokens=300000 → session.lastInputTokens = 300000.
// 2. Request 2 on claude-small (10k window) with a ~13k-token
// 2. Request 2 on claude-small (12k window) with a ~13k-token
// conversation: the payload itself overflows → preflight fires: the
// oldest compressible ranges are summarized (non-streaming JSON calls
// to the upstream) and folded into blocks; the rebuilt payload (recent
Expand Down Expand Up @@ -101,7 +101,7 @@ test("e2e: model switch to a smaller window → preflight compresses before forw
port: 0,
host: "127.0.0.1",
upstream: "http://127.0.0.1",
routes: { [`http://127.0.0.1:${upstreamPort}`]: { models: { "claude-big": { context: 400_000 }, "claude-small": { context: 10_600 } } } },
routes: { [`http://127.0.0.1:${upstreamPort}`]: { models: { "claude-big": { context: 400_000 }, "claude-small": { context: 12_000 } } } },
modelContextLimit: 400_000,
kernelConfig: defaultConfig(400_000),
// CCR is opt-in on every lane (#1207 owner decision): off unless a
Expand Down Expand Up @@ -296,7 +296,7 @@ test("e2e: fresh session (lastInputTokens=0) whose raw history overflows the win
port: 0,
host: "127.0.0.1",
upstream: "http://127.0.0.1",
routes: { [`http://127.0.0.1:${upstreamPort}`]: { models: { "claude-small": { context: 10_600 } } } },
routes: { [`http://127.0.0.1:${upstreamPort}`]: { models: { "claude-small": { context: 12_000 } } } },
modelContextLimit: 400_000,
kernelConfig: defaultConfig(400_000),
// CCR is opt-in on every lane (#1207 owner decision): off unless a
Expand All @@ -320,7 +320,7 @@ test("e2e: fresh session (lastInputTokens=0) whose raw history overflows the win
// No prior request: the session is brand new (lastInputTokens = 0),
// e.g. after a model switch rotated the session id and the client
// resends its full raw history. The ~13k-token history overflows the
// 10k window on the very first request — preflight must still fire
// 12k window on the very first request — preflight must still fire
// (payload-size trigger, not lastInputTokens).
const r = await fetch(`http://127.0.0.1:${proxyPort}/bili/http://127.0.0.1:${upstreamPort}/v1/messages`, {
method: "POST",
Expand Down
96 changes: 96 additions & 0 deletions tests/wire-schema-portable.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import assert from "node:assert/strict";
import test from "node:test";

import {
BILI_ACP_TOOLS_ANTHROPIC,
BILI_ACP_TOOLS_OPENAI,
BILI_ACP_TOOLS_RESPONSES,
BILI_ACP_TOOLS_GOOGLE,
} from "../src/compress-tool.js";

/**
* Provider portability contract (#1414 / kernel #447): Copilot Gemini rejects
* a request with `400 invalid_request_body` when any tool schema it carries
* uses (a) a union `type` array (e.g. `type: ["array", "string"]`) or (b) an
* `anyOf` alternative without an explicit scalar `type`. The kernel fix
* (acp-kernel #448, released 0.0.95) replaced both with explicit typed
* alternatives; this test walks Bili's full outgoing ACP tool surface across
* all four wire shapes so a schema regression fails here instead of in
* production traffic to Copilot Gemini.
*/

type SchemaNode = {
type?: string | string[];
properties?: Record<string, SchemaNode>;
items?: SchemaNode;
anyOf?: SchemaNode[];
[k: string]: unknown;
};

function* walk(node: SchemaNode, path: string): Generator<readonly [string, SchemaNode]> {
yield [path, node];
if (node.properties) {
for (const [k, sub] of Object.entries(node.properties))
yield* walk(sub, `${path}.properties.${k}`);
}
if (node.items) yield* walk(node.items, `${path}.items`);
if (node.anyOf) {
for (let i = 0; i < node.anyOf.length; i++)
yield* walk(node.anyOf[i]!, `${path}.anyOf[${i}]`);
}
}

function schemaOf(tool: {
input_schema?: unknown;
parameters?: unknown;
function?: { parameters?: unknown };
}): unknown {
return tool.input_schema ?? tool.parameters ?? tool.function?.parameters;
}

const surfaces: ReadonlyArray<readonly [string, ReadonlyArray<{ name?: string; function?: { name?: string } } | unknown>]> = [
["anthropic", BILI_ACP_TOOLS_ANTHROPIC as unknown as ReadonlyArray<unknown>],
["openai", BILI_ACP_TOOLS_OPENAI as unknown as ReadonlyArray<unknown>],
["responses", BILI_ACP_TOOLS_RESPONSES as unknown as ReadonlyArray<unknown>],
["google", BILI_ACP_TOOLS_GOOGLE as unknown as ReadonlyArray<unknown>],
];

for (const [wire, tools] of surfaces) {
test(`#1414: every ACP tool schema on the ${wire} wire is Copilot-Gemini portable`, () => {
assert.ok(tools.length > 0, `${wire} surface must not be empty`);
for (const tool of tools) {
const name =
(tool as { name?: string }).name ??
(tool as { function?: { name?: string } }).function?.name ??
"?";
const schema = schemaOf(tool as { input_schema?: unknown; parameters?: unknown }) as
| SchemaNode
| undefined;
assert.ok(schema, `${wire}/${name}: expected a schema (input_schema or parameters)`);
// Top level stays a plain object (Anthropic requirement).
assert.equal(
Array.isArray(schema.type) ? schema.type.join("|") : schema.type,
"object",
`${wire}/${name}: top-level schema must be a plain object type`,
);
for (const [path, node] of walk(schema, `${wire}/${name}`)) {
if (node.type !== undefined) {
assert.equal(
typeof node.type,
"string",
`${path}: union type arrays are not portable (${JSON.stringify(node.type)})`,
);
}
if (node.anyOf) {
for (let i = 0; i < node.anyOf.length; i++) {
const alt = node.anyOf[i]!;
assert.ok(
typeof alt.type === "string" && alt.type.length > 0,
`${path}.anyOf[${i}]: every alternative must declare an explicit scalar type`,
);
}
}
}
}
});
}
Loading