refactor: clean up code formatting and update package dependencies

- Removed unnecessary blank lines and improved formatting for better readability in index.ts and converters.ts.
- Updated package-lock.json to downgrade several dependencies for compatibility, including @protobufjs/eventemitter, @protobufjs/fetch, and others.
- Enhanced error message in core.ts to clarify configuration options for the Command Code API key.
- Added a test to ensure the correct handling of environment variable values in test-stream.ts.
This commit is contained in:
wh.huajieyu
2026-05-28 06:23:28 -04:00
parent c2497ed098
commit e78875f532
6 changed files with 67 additions and 37 deletions
+4 -4
View File
@@ -177,10 +177,10 @@ try {
assert.equal(print.code, 0, print.stderr)
assert.match(print.stdout, /mock-omp-ok/)
assert.equal(requestCount, 1)
assert.ok(
typeof lastRequestHeaders.authorization === "string" &&
lastRequestHeaders.authorization.startsWith("Bearer "),
"should send a bearer Authorization header",
assert.equal(
lastRequestHeaders.authorization,
"Bearer mock-key",
"should send the resolved env-var value, not the literal var name",
)
assert.equal(lastRequestBody?.params?.model, TEST_MODEL)
assert.equal(typeof lastRequestBody?.params?.system, "string")
+21
View File
@@ -54,6 +54,27 @@ describe("streamCommandCode — auth", () => {
assert.equal(server.requestCount(), 0)
})
it("ignores the literal env-var name and falls back to env", async () => {
server.mockResponse({
type: "success",
events: [JSON.stringify({ type: "finish", finishReason: "stop" })],
})
const { streamCommandCode } = createTestDeps({
apiBase: server.baseUrl(),
env: { COMMANDCODE_API_KEY: "env-key" },
})
await collectEvents(
streamCommandCode(makeModel(), makeContext(), { apiKey: "COMMANDCODE_API_KEY" }),
)
assert.equal(
server.lastRequestHeaders().authorization,
"Bearer env-key",
"should resolve from env, not send the literal var name as the token",
)
})
it("uses options.apiKey in the Authorization header", async () => {
server.mockResponse({
type: "success",