Skip to content

fix(cli): build SDK before native release artifacts#3795

Closed
caio-pizzol wants to merge 1 commit into
mainfrom
caio-pizzol/ci-release-sdk-build
Closed

fix(cli): build SDK before native release artifacts#3795
caio-pizzol wants to merge 1 commit into
mainfrom
caio-pizzol/ci-release-sdk-build

Conversation

@caio-pizzol

Copy link
Copy Markdown
Contributor

The CLI native release build now prepares the Node SDK before Bun compiles CLI binaries. doc.preset.* imports SDK preset code, so a fresh release checkout needs generated SDK sources and the SDK dist package before bun build --compile.

  • Adds SDK artifact generation and Node SDK build to the CLI runtime prep helper.
  • Keeps the existing packaged SuperDoc runtime prep in the same release path.
  • Verified with the focused CLI script test and a host native CLI build.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@caio-pizzol
caio-pizzol marked this pull request as ready for review July 5, 2026 10:13
@caio-pizzol
caio-pizzol requested a review from a team as a code owner July 5, 2026 10:13

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7e541dc0db

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

* @returns {void}
*/
export function ensureNodeSdkBuild(run = runCommand) {
run('pnpm', ['--prefix', sdkWorkspaceRoot, 'run', 'generate'], 'Generate SDK artifacts for CLI runtime');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid running full SDK generation in CLI prep

When any CLI lifecycle script that calls ensure-superdoc-build runs (for example pretest, prebuild, prebuild:native, or pretypecheck in apps/cli/package.json), this invokes the SDK workspace's mutating generate script. That generator writes tracked outputs outside the CLI path, including apps/mcp/src/generated/*, packages/sdk/langs/browser/src/*, and prompt/dispatch artifacts under packages/sdk/tools, so a routine CLI build or test can dirty the checkout or silently update unrelated MCP/browser/Python SDK artifacts whenever the contract or prompt inputs drift. Please use a non-mutating currentness check or a Node-SDK-only generation/prep step here.

Useful? React with 👍 / 👎.

@superdoc-bot superdoc-bot Bot closed this in d3b1f0c Jul 5, 2026
@superdoc-bot

superdoc-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

This pull request landed on main as d3b1f0c.

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. SDK tools dir not prepared 🐞 Bug ≡ Correctness
Description
ensureNodeSdkBuild builds the Node SDK dist but never creates the package-level tools/ directory
that the SDK presets read at runtime; doc.preset.* can throw TOOLS_ASSET_NOT_FOUND on clean
checkouts/native binaries. This breaks CLI preset operations because the SDK resolves tool JSON
relative to @superdoc-dev/sdk’s package root, while codegen writes tools to packages/sdk/tools
instead.
Code

apps/cli/scripts/ensure-superdoc-build.js[R31-34]

+export function ensureNodeSdkBuild(run = runCommand) {
+  run('pnpm', ['--prefix', sdkWorkspaceRoot, 'run', 'generate'], 'Generate SDK artifacts for CLI runtime');
+  run('pnpm', ['--prefix', nodeSdkRoot, 'run', 'build'], 'Build Node SDK for CLI runtime');
+}
Relevance

⭐⭐⭐ High

Team has accepted multiple fixes for missing SDK tools assets/TOOLS_ASSET_NOT_FOUND failures in SDK
packaging/runtime.

PR-#2656
PR-#3541

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The CLI’s preset operations call into @superdoc-dev/sdk, whose legacy preset reads tool JSON from
a tools/ directory located at the SDK package root and throws TOOLS_ASSET_NOT_FOUND if the files
aren’t present. Codegen writes those JSON files under packages/sdk/tools, and the only declared
mechanism to place them under the Node SDK package root is prepack/postpack, which
ensureNodeSdkBuild does not run.

apps/cli/scripts/ensure-superdoc-build.js[31-34]
apps/cli/src/lib/preset-ops.ts[24-33]
apps/cli/src/lib/preset-ops.ts[46-57]
packages/sdk/langs/node/src/presets/legacy.ts[34-36]
packages/sdk/langs/node/src/presets/legacy.ts[68-87]
packages/sdk/langs/node/package.json[22-28]
packages/sdk/codegen/src/generate-intent-tools.mjs[5-8]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`ensureNodeSdkBuild()` runs SDK generation and `@superdoc-dev/sdk` build, but it does not ensure that `packages/sdk/langs/node/tools/` exists. At runtime, the Node SDK preset loaders resolve tool artifacts via `.../tools/*.json` relative to the SDK package root and throw `TOOLS_ASSET_NOT_FOUND` if they are missing. In a clean checkout / release build environment, codegen writes tools to `packages/sdk/tools` (workspace root), not to the Node SDK package’s `tools/` directory.

### Issue Context
- CLI preset operations (`doc.preset.*`) execute the Node SDK preset machinery in-process via `@superdoc-dev/sdk`.
- The Node SDK preset code reads JSON artifacts from `<sdk package root>/tools`.
- The Node SDK package has `prepack/postpack` scripts that *are* responsible for copying/symlinking tools into the package root, but `ensureNodeSdkBuild()` does not run them.

### Fix Focus Areas
- apps/cli/scripts/ensure-superdoc-build.js[31-34]

### Suggested fix
After `pnpm --prefix packages/sdk run generate`, add a step that makes the Node SDK package’s `tools/` directory available before building/compiling the CLI, for example:
- Run the Node SDK’s `postpack` script to create the symlink: `pnpm --prefix packages/sdk/langs/node run postpack` (creates `tools -> ../../tools`).
 - If you need portability beyond *nix, replace `ln -s` in `postpack` with a Node-based symlink/copy script.
- Alternatively, add a small Node script invoked from `ensureNodeSdkBuild()` that ensures `packages/sdk/langs/node/tools` exists (symlink or copy) and points at `packages/sdk/tools`.

Make sure this step runs **before** `bun build --compile` so preset commands can load tool catalogs in the compiled binary.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. OS-dependent path assertions 🐞 Bug ☼ Reliability
Description
The new ensureNodeSdkBuild test hard-codes POSIX fragments ("/packages/sdk"), but production code
uses path.join(...) for --prefix, which yields platform-specific separators. This will fail on
Windows (and is fragile across path normalization differences).
Code

apps/cli/scripts/tests/ensure-superdoc-build.test.ts[R41-50]

+    expect(calls).toEqual([
+      {
+        command: 'pnpm',
+        args: ['--prefix', expect.stringContaining('/packages/sdk'), 'run', 'generate'],
+        label: 'Generate SDK artifacts for CLI runtime',
+      },
+      {
+        command: 'pnpm',
+        args: ['--prefix', expect.stringContaining('/packages/sdk/langs/node'), 'run', 'build'],
+        label: 'Build Node SDK for CLI runtime',
Relevance

⭐⭐ Medium

No prior review evidence on Windows-safe path assertions in CLI tests; pattern not found in history.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Implementation constructs absolute paths using path.join, which is OS-dependent, while the tests
expect POSIX separators in the --prefix values.

apps/cli/scripts/ensure-superdoc-build.js[5-8]
apps/cli/scripts/tests/ensure-superdoc-build.test.ts[41-50]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The test for `ensureNodeSdkBuild()` asserts that `--prefix` arguments contain strings like `'/packages/sdk'`, but the implementation builds those paths via `path.join(repoRoot, ...)`, which will produce `\packages\sdk` on Windows.

### Issue Context
This is a unit test fragility that can break Windows CI/local runs even though the code is correct.

### Fix Focus Areas
- apps/cli/scripts/__tests__/ensure-superdoc-build.test.ts[41-50]

### Suggested fix
Update assertions to be separator-agnostic, e.g.:
- Import `node:path` in the test and assert against `path.join('packages','sdk')` and `path.join('packages','sdk','langs','node')`.
- Or normalize both sides: `expect(path.normalize(args[1])).toContain(path.normalize('/packages/sdk'))`.
- Or use a regex that accepts both separators: `/[\\/]packages[\\/]sdk/`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment on lines +31 to +34
export function ensureNodeSdkBuild(run = runCommand) {
run('pnpm', ['--prefix', sdkWorkspaceRoot, 'run', 'generate'], 'Generate SDK artifacts for CLI runtime');
run('pnpm', ['--prefix', nodeSdkRoot, 'run', 'build'], 'Build Node SDK for CLI runtime');
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Sdk tools dir not prepared 🐞 Bug ≡ Correctness

ensureNodeSdkBuild builds the Node SDK dist but never creates the package-level tools/ directory
that the SDK presets read at runtime; doc.preset.* can throw TOOLS_ASSET_NOT_FOUND on clean
checkouts/native binaries. This breaks CLI preset operations because the SDK resolves tool JSON
relative to @superdoc-dev/sdk’s package root, while codegen writes tools to packages/sdk/tools
instead.
Agent Prompt
### Issue description
`ensureNodeSdkBuild()` runs SDK generation and `@superdoc-dev/sdk` build, but it does not ensure that `packages/sdk/langs/node/tools/` exists. At runtime, the Node SDK preset loaders resolve tool artifacts via `.../tools/*.json` relative to the SDK package root and throw `TOOLS_ASSET_NOT_FOUND` if they are missing. In a clean checkout / release build environment, codegen writes tools to `packages/sdk/tools` (workspace root), not to the Node SDK package’s `tools/` directory.

### Issue Context
- CLI preset operations (`doc.preset.*`) execute the Node SDK preset machinery in-process via `@superdoc-dev/sdk`.
- The Node SDK preset code reads JSON artifacts from `<sdk package root>/tools`.
- The Node SDK package has `prepack/postpack` scripts that *are* responsible for copying/symlinking tools into the package root, but `ensureNodeSdkBuild()` does not run them.

### Fix Focus Areas
- apps/cli/scripts/ensure-superdoc-build.js[31-34]

### Suggested fix
After `pnpm --prefix packages/sdk run generate`, add a step that makes the Node SDK package’s `tools/` directory available before building/compiling the CLI, for example:
- Run the Node SDK’s `postpack` script to create the symlink: `pnpm --prefix packages/sdk/langs/node run postpack` (creates `tools -> ../../tools`).
  - If you need portability beyond *nix, replace `ln -s` in `postpack` with a Node-based symlink/copy script.
- Alternatively, add a small Node script invoked from `ensureNodeSdkBuild()` that ensures `packages/sdk/langs/node/tools` exists (symlink or copy) and points at `packages/sdk/tools`.

Make sure this step runs **before** `bun build --compile` so preset commands can load tool catalogs in the compiled binary.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +41 to +50
expect(calls).toEqual([
{
command: 'pnpm',
args: ['--prefix', expect.stringContaining('/packages/sdk'), 'run', 'generate'],
label: 'Generate SDK artifacts for CLI runtime',
},
{
command: 'pnpm',
args: ['--prefix', expect.stringContaining('/packages/sdk/langs/node'), 'run', 'build'],
label: 'Build Node SDK for CLI runtime',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

2. Os-dependent path assertions 🐞 Bug ☼ Reliability

The new ensureNodeSdkBuild test hard-codes POSIX fragments ("/packages/sdk"), but production code
uses path.join(...) for --prefix, which yields platform-specific separators. This will fail on
Windows (and is fragile across path normalization differences).
Agent Prompt
### Issue description
The test for `ensureNodeSdkBuild()` asserts that `--prefix` arguments contain strings like `'/packages/sdk'`, but the implementation builds those paths via `path.join(repoRoot, ...)`, which will produce `\packages\sdk` on Windows.

### Issue Context
This is a unit test fragility that can break Windows CI/local runs even though the code is correct.

### Fix Focus Areas
- apps/cli/scripts/__tests__/ensure-superdoc-build.test.ts[41-50]

### Suggested fix
Update assertions to be separator-agnostic, e.g.:
- Import `node:path` in the test and assert against `path.join('packages','sdk')` and `path.join('packages','sdk','langs','node')`.
- Or normalize both sides: `expect(path.normalize(args[1])).toContain(path.normalize('/packages/sdk'))`.
- Or use a regex that accepts both separators: `/[\\/]packages[\\/]sdk/`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@superdoc-bot

superdoc-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in superdoc-cli v0.21.0

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in superdoc-sdk v1.20.0

@superdoc-bot

superdoc-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in @superdoc-dev/mcp v0.16.0

The release is available on GitHub release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants