Files
lobehub__lobehub/packages/sdk/scripts/generate-sdk.test.ts
Rdmclin2 e869088121 ✨ feat(sdk): add @lobehub/sdk generated from the OpenAPI spec (#17980)
* ✨ feat(sdk): add @lobehub/sdk generated from the OpenAPI spec

Resource-style TypeScript SDK (lobehub.agents.list()) generated from
packages/openapi/openapi.yml via @hey-api/openapi-ts: instantiable LobeHub
root class, 14 resource groups, inlined HTTP runtime (zero npm deps), and a
byte-level drift check (bun scripts/generate-sdk.ts --check) that runs in
local tests and the release workflow only — regular PR CI is not gated.
Publishing is automated by release-sdk.yml on canary pushes touching
packages/sdk/** (plus manual dispatch), versioned 1.0.<UTC timestamp>.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* 🐛 fix(sdk): rename misleading messages.deleteAll to deleteMany

DELETE /api/v1/messages requires a non-empty messageIds array — it deletes
a selected batch, not all messages.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* 🔨 chore(sdk): make .mjs output deterministic and document SSE streaming

fixedExtension: true pins tsdown output to .mjs/.d.mts regardless of
package.json type, matching the exports the release workflow writes.
README documents parseAs: 'stream' for responses.create with stream: true.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* 🐛 fix(sdk): preserve per-call HeadersInit values on write methods

The generated write methods spread options.headers into an object literal,
which drops Headers instances and corrupts tuple arrays. generate-sdk.ts now
rewrites the spread to the client's mergeHeaders (normalizing tuple arrays
via new Headers) in both generate and --check modes, with a regression test
covering both HeadersInit shapes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* 🐛 fix(sdk): normalize HeadersInit at the root and keep form-data Content-Type deletion

Follow-ups to the header-spread rewrite: (1) mergeHeaders itself now
normalizes tuple-array HeadersInit (client defaults and read-method calls
previously degraded to numeric keys); (2) write methods merge into a plain
object instead of a Headers instance, so the 'Content-Type': null sentinel
on form-data methods survives to the final client merge and can delete a
client-default Content-Type. Regression tests cover both paths.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* 🐛 fix(sdk): satisfy repo-wide type-check for generator script and upload test

Resolve the defineConfig thenable before spreading/passing to createClient,
and drop fields not present in the files.create body schema from the
form-data regression test. The package tsconfig only covers src/**, so these
scripts/test typings were first caught by the repo-wide type-check in CI.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-06 18:23:39 -07:00

30 lines
1.1 KiB
TypeScript

import { execSync } from 'node:child_process';
import path from 'node:path';
import { describe, it } from 'vitest';
const PKG_ROOT = path.join(__dirname, '..');
describe('generate-sdk', () => {
it('src/generated stays in sync with openapi.yml', () => {
// Runs the generator in --check mode as a subprocess (the same command the
// release workflow uses), so committed output failing to match the spec
// fails this test with the generator's own diagnostics. This package is
// deliberately NOT in the CI package whitelist — the test runs locally and
// in the manual release workflow only, never gating regular PRs.
try {
execSync('bun scripts/generate-sdk.ts --check', {
cwd: PKG_ROOT,
encoding: 'utf8',
stdio: 'pipe',
});
} catch (error) {
const execError = error as { stderr?: string; stdout?: string };
throw new Error(
`src/generated is out of date. Run \`bun generate\` in packages/sdk and commit the result.\n${execError.stderr ?? ''}${execError.stdout ?? ''}`,
{ cause: error },
);
}
}, 120_000);
});