Test dynamic Command Code model discovery
This commit is contained in:
+2
-1
@@ -25,11 +25,12 @@
|
||||
"LICENSE"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "npm run typecheck && tsx tests/test-pure-functions.ts && tsx tests/test-oauth.ts && tsx tests/test-abort.ts && tsx tests/test-stream.ts && node tests/test-pi-local.mjs",
|
||||
"test": "npm run typecheck && tsx tests/test-pure-functions.ts && tsx tests/test-models.ts && tsx tests/test-oauth.ts && tsx tests/test-abort.ts && tsx tests/test-stream.ts && node tests/test-pi-local.mjs",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"format:check": "prettier --check '**/*.{ts,mjs,json,md}'",
|
||||
"format": "prettier --write '**/*.{ts,mjs,json,md}'",
|
||||
"test:unit": "tsx tests/test-pure-functions.ts",
|
||||
"test:models": "tsx tests/test-models.ts",
|
||||
"test:oauth": "tsx tests/test-oauth.ts",
|
||||
"test:abort": "tsx tests/test-abort.ts",
|
||||
"test:stream": "tsx tests/test-stream.ts",
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import assert from "node:assert/strict"
|
||||
import { describe, it } from "node:test"
|
||||
|
||||
import { commandCodeModelsFromApiResponse } from "../src/models.ts"
|
||||
|
||||
describe("commandCodeModelsFromApiResponse()", () => {
|
||||
it("converts the Provider API model list to pi models", () => {
|
||||
const models = commandCodeModelsFromApiResponse({
|
||||
object: "list",
|
||||
data: [
|
||||
{
|
||||
id: "Qwen/Qwen3.7-Max",
|
||||
object: "model",
|
||||
created: 1779824324,
|
||||
owned_by: "command-code",
|
||||
name: "Qwen 3.7 Max",
|
||||
context_length: 1_000_000,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
assert.deepEqual(models, [
|
||||
{
|
||||
id: "Qwen/Qwen3.7-Max",
|
||||
name: "Qwen 3.7 Max (CC)",
|
||||
reasoning: true,
|
||||
contextWindow: 1_000_000,
|
||||
maxTokens: 65_536,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("rejects unexpected API shapes", () => {
|
||||
assert.throws(() => commandCodeModelsFromApiResponse({ object: "list", data: [{}] }))
|
||||
})
|
||||
})
|
||||
+57
-3
@@ -56,10 +56,40 @@ if (piCheck.error) {
|
||||
}
|
||||
|
||||
let requestCount = 0
|
||||
let modelListRequestCount = 0
|
||||
let lastRequestBody
|
||||
let lastRequestHeaders = {}
|
||||
|
||||
const server = createServer((req, res) => {
|
||||
if (req.method === "GET" && req.url === "/provider/v1/models") {
|
||||
modelListRequestCount += 1
|
||||
res.writeHead(200, { "Content-Type": "application/json; charset=utf-8" })
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
object: "list",
|
||||
data: [
|
||||
{
|
||||
id: TEST_MODEL,
|
||||
object: "model",
|
||||
created: 1779824324,
|
||||
owned_by: "command-code",
|
||||
name: "DeepSeek V4 Flash",
|
||||
context_length: 1_000_000,
|
||||
},
|
||||
{
|
||||
id: "Qwen/Qwen3.7-Max",
|
||||
object: "model",
|
||||
created: 1779824324,
|
||||
owned_by: "command-code",
|
||||
name: "Qwen 3.7 Max",
|
||||
context_length: 1_000_000,
|
||||
},
|
||||
],
|
||||
}),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (req.method !== "POST" || req.url !== "/alpha/generate") {
|
||||
res.writeHead(404)
|
||||
res.end("Not found")
|
||||
@@ -114,6 +144,7 @@ let tempHome
|
||||
const env = {
|
||||
...process.env,
|
||||
COMMANDCODE_API_BASE: apiBase,
|
||||
COMMANDCODE_MODELS_URL: `${apiBase}/provider/v1/models`,
|
||||
}
|
||||
|
||||
if (hasLivePiAuth()) {
|
||||
@@ -161,7 +192,17 @@ function runPi(args, timeoutMs = 30_000) {
|
||||
async function runRpcQuery(timeoutMs = 30_000) {
|
||||
const child = spawn(
|
||||
PI_BIN,
|
||||
["--mode", "rpc", "-e", EXT_PATH, "--provider", "commandcode", "--model", TEST_MODEL],
|
||||
[
|
||||
"--no-extensions",
|
||||
"--mode",
|
||||
"rpc",
|
||||
"-e",
|
||||
EXT_PATH,
|
||||
"--provider",
|
||||
"commandcode",
|
||||
"--model",
|
||||
TEST_MODEL,
|
||||
],
|
||||
{
|
||||
cwd: PROJECT_DIR,
|
||||
env,
|
||||
@@ -250,15 +291,28 @@ async function runRpcQuery(timeoutMs = 30_000) {
|
||||
|
||||
try {
|
||||
console.log("[pi-local] list models through real extension")
|
||||
const list = await runPi(["-e", EXT_PATH, "--list-models"], 20_000)
|
||||
modelListRequestCount = 0
|
||||
const list = await runPi(["--no-extensions", "-e", EXT_PATH, "--list-models"], 20_000)
|
||||
assert.equal(list.code, 0, list.stderr)
|
||||
assert.match(list.stdout, /commandcode/)
|
||||
assert.match(list.stdout, /deepseek\/deepseek-v4-flash/)
|
||||
assert.match(list.stdout, /Qwen\/Qwen3\.7-Max/)
|
||||
assert.equal(modelListRequestCount, 1)
|
||||
|
||||
console.log("[pi-local] print mode through real extension and mock API")
|
||||
requestCount = 0
|
||||
const print = await runPi(
|
||||
["-e", EXT_PATH, "-p", "say mock token", "--provider", "commandcode", "--model", TEST_MODEL],
|
||||
[
|
||||
"--no-extensions",
|
||||
"-e",
|
||||
EXT_PATH,
|
||||
"-p",
|
||||
"say mock token",
|
||||
"--provider",
|
||||
"commandcode",
|
||||
"--model",
|
||||
TEST_MODEL,
|
||||
],
|
||||
30_000,
|
||||
)
|
||||
assert.equal(print.code, 0, print.stderr)
|
||||
|
||||
Reference in New Issue
Block a user