Files
msd-core/tests/bug-3359-stale-gsd-sdk-path-version.test.cjs
Tom Boucher 5292bc5477 refactor(3597): extract captureConsole + toPosixPath to helpers; dedup makeTmp wrappers; CLAUDE.md MemPalace
## Helper deduplication (16 files)

Two genuinely-duplicated test helpers extracted to tests/helpers.cjs:

- captureConsole(fn) → {stdout, stderr} with ANSI strip + exception
  re-throw after console restore (preserves the #2775 CR contract).
  Removed from 6 bug-N test files (bug-2775, bug-2829, bug-3033,
  bug-3211, bug-3231, bug-3359) where the implementation was either
  byte-identical or trivially-different. installer-migration-install-
  integration's captureConsole has a different signature ({value,
  output}) and stays as-is.

- toPosixPath(p) → p with path.sep → '/'. Returns input unchanged if
  null/undefined for safe optional-chain composition. Replaces the
  local normalizePath in bug-3491-nested-git-worktree (the
  prune-orphaned-worktrees inline normalizeSlashes was already swapped
  for canonicalPath in the cluster-J batch).

## makeTmp/mkScratch wrappers (8 files)

Reduced each local wrapper from a 3-line fs.mkdtempSync(path.join(
os.tmpdir(), ...)) block to a 1-line arrow delegating to
createTempDir (already in helpers.cjs). Bug-number prefix conventions
stay local for readability:

  - bug-2256, bug-2794, feat-3023, feat-3024 → `gsd-<bug>-${prefix}-`
  - bug-3288 → makeTmpDir = createTempDir (identity)
  - bug-3571 → 'gsd-3571-' (no parameter)
  - feat-3595 → mkScratch = `fs-fault-${name}-`
  - project-root-generator → 'gsd-parity-'

bug-3288 also collapsed local rmTmpDir into `cleanup` from helpers
(removes a separate inline rmSync site).

## CLAUDE.md — MemPalace protocol

Adds explicit instruction to call mempalace_status at session start
and mempalace_search / mempalace_kg_query before answering questions
about people, past work, or prior decisions in this project.

## Why this is a real consolidation

Initial survey suggested the bug-N test files could be parameterized
into one install-end-to-end.test.cjs — that turned out to oversell the
savings (~200 LOC on 2238) and to bury per-bug fixture context in a
table. The genuinely duplicated surface was the helpers themselves:
captureConsole copy-pasted ~6×, makeTmp variant copy-pasted ~8×.
Extracting them retires ~170 LOC of pure copy-paste without changing
any test semantics.

Validated: holodeck (ubuntu docker) 11232/0 pass; ratchet guard
still 7/7 at baseline.

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

147 lines
4.9 KiB
JavaScript

/**
* Regression test for bug #3359.
*
* `npx get-shit-done-cc@latest` can refresh runtime files while an older
* global `gsd-sdk` earlier on PATH remains the executable workflows call.
* The installer must not report SDK readiness when the resolved `gsd-sdk`
* version differs from the package/runtime version being installed.
*/
'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 { installSdkIfNeeded, readGsdSdkVersion } = require('../bin/install.js');
const cp = require('node:child_process');
const pkg = require('../package.json');
const { createTempDir, cleanup, captureConsole } = require('./helpers.cjs');
const isWindows = process.platform === 'win32';
describe('bug #3359: installer detects stale gsd-sdk earlier on PATH',
{ skip: isWindows ? 'POSIX-only: stages bare gsd-sdk shebang shims in a PATH dir; Windows uses .cmd + PATHEXT resolution' : false },
() => {
let tmpRoot;
let sdkDir;
let pathDir;
let homeDir;
let savedEnv;
beforeEach(() => {
tmpRoot = createTempDir('gsd-3359-');
sdkDir = path.join(tmpRoot, 'sdk');
pathDir = path.join(tmpRoot, 'global-bin');
homeDir = path.join(tmpRoot, 'home');
fs.mkdirSync(path.join(sdkDir, 'dist'), { recursive: true });
fs.writeFileSync(
path.join(sdkDir, 'dist', 'cli.js'),
'#!/usr/bin/env node\nconsole.log("sdk cli");\n',
{ mode: 0o755 },
);
fs.mkdirSync(pathDir, { recursive: true });
fs.mkdirSync(homeDir, { recursive: true });
savedEnv = {
PATH: process.env.PATH,
HOME: process.env.HOME,
SHELL: process.env.SHELL,
};
process.env.PATH = pathDir;
process.env.HOME = homeDir;
delete process.env.SHELL;
});
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;
if (savedEnv.SHELL == null) delete process.env.SHELL;
else process.env.SHELL = savedEnv.SHELL;
cleanup(tmpRoot);
});
test('does not print ready when resolved gsd-sdk version differs from installer package version', () => {
const staleSdk = path.join(pathDir, 'gsd-sdk');
fs.writeFileSync(
staleSdk,
'#!/bin/sh\nprintf "%s\\n" "gsd-sdk v0.0.1"\n',
{ mode: 0o755 },
);
const { stdout, stderr } = captureConsole(() => {
installSdkIfNeeded({ sdkDir });
});
const combined = `${stdout}\n${stderr}`;
assert.ok(
/version mismatch|different version|stale/i.test(combined),
`installer must warn that resolved gsd-sdk is stale. Output:\n${combined}`,
);
assert.ok(
combined.includes(staleSdk),
`warning must include resolved gsd-sdk path. Output:\n${combined}`,
);
assert.ok(
combined.includes('0.0.1') && combined.includes(pkg.version),
`warning must include detected and installer versions. Output:\n${combined}`,
);
assert.ok(
/npm install -g get-shit-done-cc@latest/.test(combined),
`warning must include global update remediation. Output:\n${combined}`,
);
assert.ok(
!/GSD SDK ready/.test(combined),
`installer must not report ready while PATH resolves a stale gsd-sdk. Output:\n${combined}`,
);
});
test('prints ready when no stale gsd-sdk is on PATH', () => {
const currentSdk = path.join(pathDir, 'gsd-sdk');
fs.writeFileSync(
currentSdk,
`#!/bin/sh\nprintf "%s\\n" "gsd-sdk v${pkg.version}"\n`,
{ mode: 0o755 },
);
const { stdout, stderr } = captureConsole(() => {
installSdkIfNeeded({ sdkDir });
});
const combined = `${stdout}\n${stderr}`;
assert.ok(
/GSD SDK ready/.test(combined),
`installer must report ready when no stale gsd-sdk exists. Output:\n${combined}`,
);
});
test('reads Windows cmd shim versions through cmd.exe', () => {
const originalSpawnSync = cp.spawnSync;
const platformDescriptor = Object.getOwnPropertyDescriptor(process, 'platform');
const calls = [];
cp.spawnSync = (command, args, options) => {
calls.push({ command, args, options });
return { status: 0, stdout: `gsd-sdk v${pkg.version}\n`, stderr: '' };
};
Object.defineProperty(process, 'platform', { value: 'win32' });
try {
assert.equal(readGsdSdkVersion('C:\\tools\\gsd-sdk.cmd'), pkg.version);
} finally {
cp.spawnSync = originalSpawnSync;
Object.defineProperty(process, 'platform', platformDescriptor);
}
assert.deepEqual(calls.map(({ command, args }) => ({ command, args })), [{
command: 'cmd.exe',
args: ['/c', 'C:\\tools\\gsd-sdk.cmd', '--version'],
}]);
assert.equal(calls[0].options.encoding, 'utf8');
assert.equal(calls[0].options.timeout, 2000);
});
});