feat(quota): add live commandcode-quota dashboard and OMP auth fix
Fetches live account quota from Command Code alpha usage endpoints (whoami, billing/credits, billing/subscriptions, usage/summary) and renders a plain-text dashboard via ui.notify. - Graceful degradation: optional endpoint transport/timeout/parse failures degrade to null sections instead of aborting; only 401/403 are hard failures. 429 is transient, not fatal. - Overall deadline bounds the whole command to QUOTA_TIMEOUT_MS (per-request controllers are chained; post-deadline phases fail fast). - OMP auth: filter unresolved $COMMANDCODE_API_KEY placeholder and fall back to the host resolver via pickCommandCodeApiKey. - ZDR privacy header respected on quota requests. - Redaction reuses redactCommandCodeErrorText plus JSON-quoted credential fields; outer-catch errors are redacted too. - resetAt parsed from seconds, ms, numeric string, or ISO string. - 21 hermetic unit tests wired into npm test (test:quota).
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
mapFinishReason,
|
||||
messagesToCC,
|
||||
parseStreamEventLine,
|
||||
pickCommandCodeApiKey,
|
||||
projectSlugFromPath,
|
||||
textContent,
|
||||
toJsonSchema,
|
||||
@@ -106,6 +107,36 @@ describe("error redaction", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("pickCommandCodeApiKey()", () => {
|
||||
it("falls back to the host key for a placeholder registry value", () => {
|
||||
assert.equal(pickCommandCodeApiKey("$COMMANDCODE_API_KEY", "file-key"), "file-key")
|
||||
assert.equal(pickCommandCodeApiKey("COMMANDCODE_API_KEY", "file-key"), "file-key")
|
||||
})
|
||||
|
||||
it("returns undefined when only a placeholder is provided (no fallback)", () => {
|
||||
assert.equal(pickCommandCodeApiKey("$COMMANDCODE_API_KEY", undefined), undefined)
|
||||
})
|
||||
|
||||
it("prefers a real registry key over the host fallback", () => {
|
||||
assert.equal(pickCommandCodeApiKey("real-registry-key", "file-key"), "real-registry-key")
|
||||
})
|
||||
|
||||
it("falls back to the host key when the registry has none", () => {
|
||||
assert.equal(pickCommandCodeApiKey(undefined, "file-key"), "file-key")
|
||||
assert.equal(pickCommandCodeApiKey(undefined, undefined), undefined)
|
||||
})
|
||||
|
||||
it("falls back to the host key for empty or whitespace registry values", () => {
|
||||
assert.equal(pickCommandCodeApiKey("", "file-key"), "file-key")
|
||||
assert.equal(pickCommandCodeApiKey(" ", "file-key"), "file-key")
|
||||
assert.equal(pickCommandCodeApiKey(" ", undefined), undefined)
|
||||
})
|
||||
|
||||
it("trims a real registry key", () => {
|
||||
assert.equal(pickCommandCodeApiKey(" real-registry-key ", "file-key"), "real-registry-key")
|
||||
})
|
||||
})
|
||||
|
||||
describe("projectSlugFromPath()", () => {
|
||||
it("matches the official CLI-style slug from an absolute working directory", () => {
|
||||
assert.equal(
|
||||
@@ -359,7 +390,7 @@ describe("toJsonSchema()", () => {
|
||||
if (!outputProperties || typeof outputProperties !== "object") {
|
||||
throw new Error("expected object properties")
|
||||
}
|
||||
assert.ok(Object.prototype.hasOwnProperty.call(outputProperties, "__proto__"))
|
||||
assert.ok(Object.hasOwn(outputProperties, "__proto__"))
|
||||
assert.deepEqual(Object.getOwnPropertyDescriptor(outputProperties, "__proto__")?.value, {
|
||||
type: "string",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user