Show enabled models and current prices in the member console
Verify control plane / verify (push) Canceled after 0s
Verify control plane / verify (pull_request) Canceled after 0s

This commit is contained in:
WebUp Cloud committed 2026-11-08 08:57:24 +08:00
1 parent 572371d7af
commit 891e4896cc
6 files changed
+233 -4

No files matched your search

@@ -78,6 +78,76 @@ class ModelApiIntegrationTest {
assertTrue(encrypted.startsWith("v1:"));
}
@Test
void memberCatalogShowsOnlyEnabledModelsAndTheCurrentPriceVersion() throws Exception {
UUID enabledProvider = UUID.randomUUID(), disabledProvider = UUID.randomUUID();
for (UUID provider : List.of(enabledProvider, disabledProvider)) {
users
.db()
.update(
"INSERT INTO"
+ " ai_providers(id,name,base_url,api_type,encrypted_key,enabled,timeout_seconds)"
+ " VALUES (?,?, 'https://api.openai.com/v1','OPENAI','private-fixture',?,30)",
provider,
provider.equals(enabledProvider) ? "Visible provider" : "Disabled provider",
provider.equals(enabledProvider));
}
var settings =
json.createObjectNode()
.put("providerId", enabledProvider.toString())
.put("name", "Catalog model")
.put("modelId", "visible-model")
.put("contextLength", 8192)
.put("maxOutput", 1024)
.put("enabled", true)
.put("toolsEnabled", true)
.put("visionEnabled", true)
.put("inputPrice", 2)
.put("outputPrice", 8)
.put("cacheReadPrice", 1)
.put("cacheWritePrice", 3);
var visibleId =
json.readTree(
mvc.perform(
post("/api/admin/models")
.header("Authorization", "Bearer " + a)
.contentType(MediaType.APPLICATION_JSON)
.content(settings.toString()))
.andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString())
.path("id")
.asText();
for (var hidden :
List.of(
settings.deepCopy().put("modelId", "disabled-model").put("enabled", false),
settings.deepCopy().put("providerId", disabledProvider.toString()))) {
mvc.perform(
post("/api/admin/models")
.header("Authorization", "Bearer " + a)
.contentType(MediaType.APPLICATION_JSON)
.content(hidden.toString()))
.andExpect(status().isOk());
}
mvc.perform(
put("/api/admin/models/" + visibleId)
.header("Authorization", "Bearer " + a)
.contentType(MediaType.APPLICATION_JSON)
.content(settings.put("inputPrice", 5).toString()))
.andExpect(status().isOk());
mvc.perform(get("/api/models").header("Authorization", "Bearer " + u))
.andExpect(status().isOk())
.andExpect(jsonPath("$.length()").value(1))
.andExpect(jsonPath("$[0].provider_name").value("Visible provider"))
.andExpect(jsonPath("$[0].input_price").value(5))
.andExpect(jsonPath("$[0].cache_read_price").value(1))
.andExpect(jsonPath("$[0].price_effective_at").isNotEmpty())
.andExpect(jsonPath("$[0].encrypted_key").doesNotExist())
.andExpect(jsonPath("$[0].base_url").doesNotExist());
}
@Test
void ordinaryUsersCannotAdjustWallets() throws Exception {
mvc.perform(