Files
plugins/packages/sap-aicore/test/projection.test.js
T
caikn 0daf0c7421 sap-aicore 0.3.0: a new provider for SAP AI Core's GPT Responses and Claude Messages deployments (caikn, #651)
A new provider package, @magpie-community/opencode-sap-aicore-auth 0.3.0
(packages/sap-aicore). It signs in from a local SAP AI Core client-secret
credential file, discovers the account's running GPT (Responses) and Claude
(Messages, Bedrock) deployments per resource group, and sends requests only to
https://*.authentication.*.hana.ondemand.com (token) and
https://api.ai.*.hana.ondemand.com (inference). Image input is gated per model
on the catalog's inputTypes. Also: the root README row, a registry.json entry,
.DS_Store in .gitignore, and scripts/check.mjs accepts an empty static model
list for a package whose provider.models hook is a function with the same id
(npm and the loader are still required).

Reviewed at head b44b3e1b68889c2a12bcaa37ad5d546a398bdde0, with main 9bba5fed
merged in locally, on a Mac mini (macOS, Bun 1.4.2), no real SAP account:
- bun test packages/sap-aicore scripts: 351 pass, 0 fail.
- bun scripts/check.mjs: every package ok, sap-aicore included.
- The two tests that reached the network at e955194 now use inputs root()
  really rejects (/oauth, /v1), and a new test stubs fetch and checks that
  /oauth/token and /v2 are accepted and the token is posted to
  <authUrl>/oauth/token once. plugin.test.js fails on any unstubbed fetch.
- Whole package under a preload that records every non-loopback fetch, connect
  and DNS lookup: 0 attempts (the preload caught a deliberate fetch to
  example.invalid, so it does record).
- Broken by hand: putting the e955194 inputs back turns the test red through
  the new guard; making root() keep the given path turns the new
  /oauth/token + /v2 test red; letting root() accept any path turns 3 URL
  tests red.
- Not tried: a real SAP AI Core account (the author's run record covers one
  GPT and one Claude turn, plain and with a tool call; no image turn).

The first version goes out through the dist branch (npm doesn't have the name).
2026-11-04 22:19:43 +08:00

79 lines
3.4 KiB
JavaScript

import { test, afterEach, jest } from "bun:test"
import assert from "node:assert/strict"
import { projectModels } from "../src/discovery.js"
const cleanups = []
afterEach(async () => {
for (const fn of cleanups.splice(0).reverse()) await fn()
jest.useRealTimers()
})
function entry(modelName, extra = {}) {
return Object.freeze({
protocol: "responses",
canonicalID: modelName,
displayLabel: modelName,
apiNpm: "@ai-sdk/openai",
modelName,
deploymentID: "d-" + modelName,
deploymentURL: "https://api.ai.eu10.hana.ondemand.com/v2/inference/deployments/d-" + modelName,
configuredVersion: "latest",
activeVersion: "2026-09-03",
activeEvidence: "deployment-backend",
scenarioID: "foundation-models",
executableID: "azure-openai",
configurationID: "c-" + modelName,
routePolicy: Object.freeze({ path: "/responses", query: false }),
capabilities: Object.freeze({ text: true, functionTool: true, streaming: true }),
...extra,
})
}
test("projects a verified entry with context into the public catalog shape", () => {
const registry = { "gpt-6-astra": entry("gpt-6-astra", { metadata: Object.freeze({ contextLength: 1050000, retirementDate: "2027-01-01", inputTypes: Object.freeze(["text"]) }) }) }
assert.deepEqual(projectModels(registry), {
"gpt-6-astra": {
id: "gpt-6-astra",
name: "gpt-6-astra",
providerID: "sap-aicore",
api: { id: "gpt-6-astra", npm: "@ai-sdk/openai" },
capabilities: {
toolcall: true,
attachment: false,
input: { text: true, image: false, audio: false, video: false, pdf: false },
output: { text: true, image: false, audio: false, video: false, pdf: false },
},
limit: { context: 1050000 },
},
})
})
test("omits limit when context length is absent", () => {
const noMeta = projectModels({ "gpt-6.1-sol": entry("gpt-6.1-sol") })["gpt-6.1-sol"]
const retireOnly = projectModels({ "gpt-6.1-sol": entry("gpt-6.1-sol", { metadata: Object.freeze({ retirementDate: "2027-01-01" }) }) })["gpt-6.1-sol"]
assert.equal("limit" in noMeta, false)
assert.equal("limit" in retireOnly, false)
})
test("leaks no deployment, configuration, or provenance state", () => {
const model = projectModels({ "gpt-6-astra": entry("gpt-6-astra", { metadata: Object.freeze({ contextLength: 1050000, retirementDate: "2027-01-01" }) }) })["gpt-6-astra"]
for (const key of ["deploymentID", "deploymentURL", "configurationID", "configuredVersion", "activeVersion", "activeEvidence", "scenarioID", "executableID", "routePolicy", "metadata", "retirementDate"]) {
assert.equal(key in model, false, key)
}
assert.deepEqual(Object.keys(model.capabilities), ["toolcall", "attachment", "input", "output"])
})
test("each projection owns fresh objects isolated from the registry and prior calls", () => {
const source = entry("gpt-6-astra", { metadata: Object.freeze({ contextLength: 1050000 }) })
const registry = { "gpt-6-astra": source }
const first = projectModels(registry)
first["gpt-6-astra"].capabilities.toolcall = false
first["gpt-6-astra"].limit.context = 1
first["gpt-6-astra"].capabilities.input.text = false
const second = projectModels(registry)
assert.equal(second["gpt-6-astra"].capabilities.toolcall, true)
assert.equal(second["gpt-6-astra"].limit.context, 1050000)
assert.equal(second["gpt-6-astra"].capabilities.input.text, true)
assert.equal(source.capabilities.functionTool, true)
})