Files
msd-core/tests/bug-3033-sdk-flag-wired.test.cjs
Tom Boucher 3a98ce83e5 fix(3597): windows parity batch — sdk/install/hook/worktree clusters (21 files)
Three parallel diagnostic agents (G: sdk/install path-sep, H: hook scripts,
I: worktree/workspace) characterised the remaining windows-22 failures on
23b52f1a. Patches by class:

CRLF in test parsers / file-content reads
  - bug-2136-sh-hook-version: shebang check split('\n') → split(/\r?\n/)
  - bug-3542-executor-git-stash-prohibition: strip \r from read content
    (git rewrites stashed text with CRLF on win autocrlf=true checkout)
  - workspace: BOM-strip + explicit \r strip in parseCommandFile (BOM at
    byte 0 defeats /^---/ anchor → fmMatch null → fm.name undefined)

Windows path-separator / 8.3-shortname normalization
  - bug-3491-nested-git-worktree: use fs.realpathSync.native to expand
    %TEMP% RUNNER~1 → runneradmin; normalize sep before path-equality
  - prune-orphaned-worktrees: normalize \\→/ before substring includes
    (git emits forward-slash in --porcelain on Windows even when
    path.join produced backslashes)
  - bug-3017-codex-hook-absolute-node: accept POSIX path OR path with
    drive-letter prefix in hookPath equality assertion
  - bug-3126-global-skills-base-runtime-path: use path.join for expected
    /xdg/<runtime> values (production calls path.join → \xdg\… on win32)

Test under-specified platform / forgot win32 env
  - bug-2979-hook-absolute-node: pass {platform:'linux'} to
    buildHookCommand + rewriteLegacyManagedNodeHookCommands so the
    POSIX-branch tests don't pick up the #3393 GitBash code path
  - bug-3288-model-catalog + bug-3571-config-manifest: also set
    USERPROFILE alongside HOME so os.homedir() on win32 redirects to
    the test fixture instead of the runner's real ~

External-cmd resolution
  - bug-2647-outer-tarball-sdk-dist: use npm.cmd + {shell:true} on win32
    so execFileSync resolves PATHEXT (literal `npm` is ENOENT)

ESM loader: tests/runtime-bridge-sync-smoke.test.cjs already migrated to
pathToFileURL in 23b52f1a (cluster E).

Explicit per-test/describe skip on win32 (with required string reasons
to satisfy no-unconditional-win32-skip guard)
  - feat-3347-graphify-auto-update-hook: 3 describes — harness spawns
    bash/kill/sleep + the hook itself is bash
  - feat-3595-fs-fault-injection: move \t and \n filenames into the
    POSIX-only branch (NTFS forbids 0x00–0x1F in filenames)
  - bug-2775/2829/3033/3231/3359: POSIX shim under ~/.local/bin with
    chmod 0o755 — not how Windows install works
  - bug-3211: single subtest where cp.execSync reassignment isn't
    picked up on win32 (POSIX coverage via the mock; live windows
    behavior covered by 3211-D which keeps running)
  - install-path-detection: parses sh-style export PATH= rc files;
    Windows has no rc files (registry Path)
  - worktree-safety-policy: single test using POSIX /repo/wt fixture
    paths that can't be expressed under win32 path.resolve

Validated: plex2 (ubuntu docker) 11224/0 pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 12:16:20 -04:00

200 lines
6.4 KiB
JavaScript

/**
* Regression test for #3033: --sdk flag parsed but never used.
*
* `hasSdk` was set in bin/install.js but never passed to `installSdkIfNeeded`,
* so `npx get-shit-done-cc@latest --sdk` produced a misleading "✓ GSD SDK ready"
* message while still silently skipping SDK deployment for local installs.
*
* Fix: `installSdkIfNeeded` now accepts `opts.forceSdk`. When true, the
* early-return for `isLocal=true` + missing dist is bypassed and the
* fail-fast diagnostic fires (same as a global install with missing dist),
* and when dist IS present the full shim-link path runs regardless of
* install mode.
*
* Tests here call `installSdkIfNeeded` directly with `forceSdk: true`
* and assert on filesystem state and console output — no source-grep.
*/
'use strict';
process.env.GSD_TEST_MODE = '1';
const { describe, test, beforeEach, afterEach } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const os = require('os');
const { installSdkIfNeeded } = require('../bin/install.js');
const { createTempDir, cleanup } = require('./helpers.cjs');
const isWindows = process.platform === 'win32';
function captureConsole(fn) {
const stdout = [];
const stderr = [];
const origLog = console.log;
const origWarn = console.warn;
const origError = console.error;
console.log = (...a) => stdout.push(a.join(' '));
console.warn = (...a) => stderr.push(a.join(' '));
console.error = (...a) => stderr.push(a.join(' '));
let threw = null;
try {
fn();
} catch (e) {
threw = e;
} finally {
console.log = origLog;
console.warn = origWarn;
console.error = origError;
}
if (threw) throw threw;
const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
return {
stdout: stdout.map(strip).join('\n'),
stderr: stderr.map(strip).join('\n'),
};
}
describe('bug #3033: --sdk flag (opts.forceSdk) must be wired into installSdkIfNeeded',
{ skip: isWindows ? 'POSIX-only: forces shebang gsd-sdk shim into ~/.local/bin and asserts mode 0o755' : false },
() => {
let tmpRoot;
let sdkDir;
let pathDir;
let homeDir;
let savedEnv;
beforeEach(() => {
tmpRoot = createTempDir('gsd-3033-');
sdkDir = path.join(tmpRoot, 'sdk');
pathDir = path.join(tmpRoot, 'somebin');
homeDir = path.join(tmpRoot, 'home');
fs.mkdirSync(pathDir, { recursive: true });
fs.mkdirSync(homeDir, { recursive: true });
savedEnv = { PATH: process.env.PATH, HOME: process.env.HOME };
process.env.PATH = pathDir;
process.env.HOME = homeDir;
});
afterEach(() => {
if (savedEnv.PATH == null) delete process.env.PATH;
else process.env.PATH = savedEnv.PATH;
if (savedEnv.HOME == null) delete process.env.HOME;
else process.env.HOME = savedEnv.HOME;
cleanup(tmpRoot);
});
test('forceSdk=true + isLocal=true + dist present: self-links gsd-sdk into PATH dir', () => {
// Stage a valid dist so the installer can proceed past the missing-dist gate.
fs.mkdirSync(path.join(sdkDir, 'dist'), { recursive: true });
fs.writeFileSync(
path.join(sdkDir, 'dist', 'cli.js'),
'#!/usr/bin/env node\nconsole.log("0.0.0-test");\n',
{ mode: 0o755 },
);
// Put ~/.local/bin on PATH so the shim-link step can succeed.
const localBin = path.join(homeDir, '.local', 'bin');
fs.mkdirSync(localBin, { recursive: true });
process.env.PATH = `${localBin}${path.delimiter}${pathDir}`;
const { stdout, stderr } = captureConsole(() => {
installSdkIfNeeded({ sdkDir, isLocal: true, forceSdk: true });
});
const combined = `${stdout}\n${stderr}`;
// Shim must be materialized on PATH.
const linkPath = path.join(localBin, 'gsd-sdk');
assert.ok(
fs.existsSync(linkPath),
`forceSdk=true must materialize gsd-sdk shim at ${linkPath}. Output:\n${combined}`,
);
// Must report "GSD SDK ready" — not the legacy "Skipping SDK check" message.
assert.ok(
/GSD SDK ready/.test(combined),
`forceSdk=true must print "GSD SDK ready" once shim is on PATH. Output:\n${combined}`,
);
assert.ok(
!/Skipping SDK check for local install/.test(combined),
`forceSdk=true must NOT print the local-skip message. Output:\n${combined}`,
);
});
test('forceSdk=true + isLocal=true + dist missing: fails fast instead of silently skipping', () => {
// No dist directory — simulate a broken/missing SDK.
fs.mkdirSync(sdkDir, { recursive: true });
// dist/cli.js intentionally absent.
let exitCode = null;
const origExit = process.exit;
process.exit = (code) => {
exitCode = code;
throw new Error(`process.exit(${code})`);
};
let threw = false;
try {
captureConsole(() => {
installSdkIfNeeded({ sdkDir, isLocal: true, forceSdk: true });
});
} catch {
threw = true;
} finally {
process.exit = origExit;
}
// With forceSdk=true the missing-dist early-return is bypassed and the
// fail-fast path fires, calling process.exit(1).
assert.ok(
threw && exitCode === 1,
`forceSdk=true with missing dist must call process.exit(1) — exitCode=${exitCode}, threw=${threw}`,
);
});
test('throwOnFailure=true converts missing SDK dist into catchable error', () => {
fs.mkdirSync(sdkDir, { recursive: true });
assert.throws(
() => captureConsole(() => {
installSdkIfNeeded({ sdkDir, isLocal: true, forceSdk: true, throwOnFailure: true });
}),
(error) => {
assert.equal(error.code, 'GSD_SDK_MISSING_DIST');
assert.equal(error.exitCode, 1);
return true;
}
);
});
test('forceSdk=false (default) + isLocal=true + dist missing: retains #2678 soft-skip', () => {
// Verify the #2678 contract is not broken for the default (no --sdk) path.
fs.mkdirSync(sdkDir, { recursive: true });
let exitCalled = false;
const origExit = process.exit;
process.exit = (code) => {
exitCalled = true;
throw new Error(`process.exit(${code}) — local install without --sdk must not exit`);
};
try {
captureConsole(() => {
installSdkIfNeeded({ sdkDir, isLocal: true });
});
} catch (e) {
if (!exitCalled) throw e;
} finally {
process.exit = origExit;
}
assert.strictEqual(
exitCalled,
false,
'isLocal=true without forceSdk must not call process.exit (preserves #2678 contract)',
);
});
});