Files
llmapikey/tests/provisioning-client.test.js
tiennm99 d0fdcb4041 feat(keys): create minted OpenRouter keys in a configured workspace
Pass create-key workspace_id (from OPENROUTER_WORKSPACE_ID, defaulting to the
project workspace) so minted keys land in the intended workspace instead of the
management key's default. Rename key to non-PII llmapikey/gh-<id>.

- buildCreateKeyBody emits workspace_id only when set (omission keeps default).
- createKey threads workspaceId; mintAndPersist sources it from env.
- Test asserts workspace_id presence/omission; document the new env var.
2026-06-14 12:40:03 +07:00

58 lines
1.6 KiB
JavaScript

import assert from "node:assert/strict";
import { test } from "node:test";
import { buildCreateKeyBody } from "../lib/openrouter/create-key-request-body.js";
test("create-key body uses OpenRouter snake_case fields", () => {
const body = buildCreateKeyBody({
name: "llmapikey:12345",
limitUsd: 10,
resetPeriod: "daily",
includeByok: true,
expiresAt: "2026-09-11T00:00:00.000Z",
});
assert.deepEqual(body, {
name: "llmapikey:12345",
limit: 10,
limit_reset: "daily",
include_byok_in_limit: true,
expires_at: "2026-09-11T00:00:00.000Z",
});
});
test("create-key body includes workspace_id when given, omits it otherwise", () => {
const scoped = buildCreateKeyBody({
name: "llmapikey/gh-12345",
limitUsd: 10,
resetPeriod: "daily",
includeByok: true,
expiresAt: "2026-09-11T00:00:00.000Z",
workspaceId: "33179556-3ab3-40a4-af8b-211d322aa94e",
});
assert.equal(scoped.workspace_id, "33179556-3ab3-40a4-af8b-211d322aa94e");
const unscoped = buildCreateKeyBody({
name: "x",
limitUsd: 5,
resetPeriod: "daily",
includeByok: false,
expiresAt: "2026-01-01T00:00:00.000Z",
});
assert.ok(!("workspace_id" in unscoped));
});
test("create-key body has no camelCase leakage", () => {
const body = buildCreateKeyBody({
name: "x",
limitUsd: 5,
resetPeriod: "daily",
includeByok: false,
expiresAt: "2026-01-01T00:00:00.000Z",
});
const keys = Object.keys(body);
assert.ok(!keys.includes("limitReset"));
assert.ok(!keys.includes("includeByok"));
assert.ok(!keys.includes("expiresAt"));
});