[Bug]: the TypeScript SDK's Windows resolution paths are never exercised, and three of its tests fail on Windows

オープン
#616 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
github-actions, node.js, typescript
領域
devtools, testing

調査の方向性

Start with packages/code-sdk/test/cli-resolution.test.ts and the Windows-specific coverage in packages/code-sdk/test/cli-resolution-windows.test.ts; check how the latter is registered in test/vitest-suites.json. Run node scripts/run-vitest-suite.mjs windows on Windows and review the reported fixture failures in project-bin.test.ts and release-check.test.ts. Done means Windows resolution coverage runs and the SDK tests pass with the documented fixture and environment fixes.

索引モデルが issue の本文から書いたものです。

説明

Labels requested: cli, needs-triage

Product or interface

Source build or repository tooling — the TypeScript SDK @minimax-ai/code-sdk (0.1.0) that resolves and starts the mcode CLI on the host.

Version

  • Source: main @ 3c21163 (repository version 0.7.2), tag v0.7.2 = c6c7f28
  • SDK package: @minimax-ai/code-sdk 0.1.0
  • Node.js v24.18.0, pnpm 9.12.0

Platform

Windows

OS version and architecture

Windows 11 x64 (build 26200)

Issue area

Build / CI / source distribution

What happens

The SDK resolves the mcode executable on the host, and its resolution logic has distinct Windows branches — PATHEXT handling, .cmd / .bat launchers, the ; separator, the project-local node_modules/.bin layout with mcode.cmd. None of those branches run in CI, and two of them fail on Windows when they are run.

Two independent reasons:

  1. The suite never runs on Windows. In scripts/verify.mjs the SDK suite is declared as

    // The SDK cancels `mcode` with POSIX signals; Windows only supports a hard kill.
    { name: "test:code-sdk", script: "test:code-sdk", platforms: ["darwin", "linux"] },
    

    so the Windows host is excluded entirely. The comment explains the exclusion — the SDK cancels the child process with POSIX signals — but it excludes the whole suite, including the resolution tests that have nothing to do with cancellation.

  2. The files that do contain Windows branches are marked posixOnly. packages/code-sdk/test/exit-codes.test.ts:25, stream.test.ts:13, run.test.ts:10 and project-bin.test.ts carry win32 cases that are skipped, and packages/code-sdk/test/cli-resolution.test.ts:117 holds a win32 branch that is never reached because the suite does not run there.

Steps to reproduce
  1. Check the suite declaration: scripts/verify.mjs → test:code-sdk has platforms: ["darwin", "linux"].
  2. Run the suite on a Windows host: pnpm test:code-sdk.
  3. Observe two failures that the exclusion currently hides:
    • packages/code-sdk/test/project-bin.test.ts:103-128 — the test writes a PATH stub mcode.cmd containing only @echo off, and the SDK then reports MCodeNotFoundError. That is the SDK behaving correctly — the stub is not a usable launcher, because the SDK never starts a batch file through a shell, it reads the JS entry out of it. The fixture is wrong, not the SDK.
    • packages/code-sdk/test/release-check.test.ts:214-227 — the test runs spawnSync('npm', …), which fails with ENOENT on Windows because the executable is npm.cmd.

Expected and actual behavior

  • Expected: the Windows resolution paths of the SDK are exercised by the test suite, and the suite runs on the platform where the SDK resolves a Windows executable.
  • Actual: the Windows paths are untested, and the two failures above would show up as soon as the suite is enabled on Windows.

What I prepared

A branch that adds real Windows coverage for the resolution paths and registers it in the suite that already runs on the Windows leg:

test/code-sdk-windows-resolution (commits 38b69df → 6e1c4e9 → 0312fd6, based on main @ 3c21163)

  • new: packages/code-sdk/test/cli-resolution-windows.test.ts — 14 tests over 10 Windows branches: PATHEXT and extension matching, the no-execute-bit case, .cmd and .bat launchers resolved to their JS entry, the batch-file failure case, case-insensitive environment lookup, quote stripping, the mcode.cmd / mcode.ps1 name list, the installer and versioned layouts.
  • test/vitest-suites.json — the file is registered in the windows suite, because that is the only suite that runs on the Windows leg.
  • release/public-source.json — regenerated for the new file.

Evidence on Windows 11 x64, Node 24.18.0:

  • node scripts/run-vitest-suite.mjs windows → 19 of 19 passing, exit 0.
  • tsc --noEmit -p packages/code-sdk/tsconfig.check.json → exit 0.
  • Mutation check: five single mutations of the new tests turn 8, 7, 4, 1 and 1 of them red respectively, so the tests fail when the behaviour they describe is broken.

Enabling the SDK suite on Windows

The new file is registered in the windows suite, so it runs on the Windows leg without touching the CI design. Enabling the existing code-sdk suite on Windows as well needs three changes, which I have prepared but deliberately not applied, because the suite declaration is a CI-design decision:

--- a/scripts/verify.mjs
+++ b/scripts/verify.mjs
@@ -60,7 +60,7 @@ const steps = [
-  { name: "test:code-sdk", script: "test:code-sdk", platforms: ["darwin", "linux"] },
+  { name: "test:code-sdk", script: "test:code-sdk", platforms: ["darwin", "linux", "win32"] },

together with the two fixture corrections the Windows run exposes. The first one is the PATH stub for mcode.cmd, which has to name its JS entry because the SDK never starts a batch file through a shell:

--- a/packages/code-sdk/test/project-bin.test.ts
+++ b/packages/code-sdk/test/project-bin.test.ts
@@ -112,8 +112,14 @@ describe('project-local node_modules/.bin/mcode', () => {
-    writeFileSync(pathBin, process.platform === 'win32' ? '@echo off\r\n' : '#!/bin/sh\n');
-    chmodSync(pathBin, 0o755);
+    if (process.platform === 'win32') {
+      // The SDK never starts a batch file through a shell: the launcher must name its JS entry.
+      writeFileSync(pathBin, '"%~dp0\\mcode.mjs" %*\r\n');
+      copyFileSync(FAKE_MCODE, join(onPath, 'mcode.mjs'));
+    } else {
+      writeFileSync(pathBin, '#!/bin/sh\n');
+      chmodSync(pathBin, 0o755);
+    }

The second one is the npm invocation, which Node cannot start as npm on Windows:

--- a/packages/code-sdk/test/release-check.test.ts
+++ b/packages/code-sdk/test/release-check.test.ts
@@ -211,9 +211,11 @@ describe('directory publish guard', () => {
+    const npmCli = join(dirname(process.execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js');
     const publish = spawnSync(
-      'npm',
+      process.execPath,
      [
+        npmCli,

And the third one is the environment the release checks inherit. On Windows, environment variables are case-insensitive, and the test runner hands its worker every npm variable in upper case (NPM_CONFIG_USERCONFIG, NPM_EXECPATH). Node then de-duplicates the two spellings case-insensitively and keeps the upper-case one — so an inherited NPM_CONFIG_USERCONFIG shadows the isolated user config a test sets, and the npm_execpath decides which tool the Windows branch of resolveTool starts. The tests therefore build their environment explicitly:

--- a/packages/code-sdk/test/release-check.test.ts
+++ b/packages/code-sdk/test/release-check.test.ts
@@ -26,6 +26,30 @@ import { tempDir } from './helpers.js';
+/**
+ * The npm configuration is read from environment variables that Node resolves
+ * case-insensitively on Windows, and the test runner hands them to its
+ * worker in upper case, so an inherited `NPM_CONFIG_USERCONFIG` would shadow the isolated
+ * user config a test sets. `npm_execpath` also decides which tool the Windows branch of
+ * `resolveTool` starts, so the child names it explicitly.
+ */
+function isolatedEnv(extra: Record<string, string> = {}): NodeJS.ProcessEnv {
+  const env: NodeJS.ProcessEnv = {};
+  for (const [key, value] of Object.entries(process.env)) {
+    if (value === undefined) continue;
+    const lower = key.toLowerCase();
+    if (lower.startsWith('npm_config_') || lower === 'npm_execpath') continue;
+    env[key] = value;
+  }
+  return { ...env, ...extra };
+}

With all three applied, the SDK test directory passes on Windows: 85 passed, 10 skipped, 0 failed across the nine files; the code-sdk group on its own is 71 passed and 10 skipped. Before the two test fixes, three tests in that directory fail on Windows.

The mutation check also covers the intent of the registry test: with the scoped-registry guard removed from the script, the test turns red — it checks the behaviour, not an error code.

Limits

  • The ten tests that rely on POSIX signals stay posixOnly — cancelling a child process on Windows is a hard kill, and that is a separate question from resolution.
  • The ; versus delimiter branch in packages/code-sdk/src/**/cli-resolver.ts:129 is not observable on a real Windows host; I did not claim coverage for it.
  • packages/code-sdk/CONTRIBUTING.md:22 still points at the old suite recommendation and would need an update if the suite is enabled on Windows.

Before submitting

  • I have searched existing issues.
  • I have included my version and removed sensitive information.
主要言語
TypeScript
スター
2.3k
フォーク
315
平均マージ
3時間 54分
マージ済み PR(30日)
9

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

MiniMax-AI/minimax-code のほかの issue

MiniMax-AI/minimax-code の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。