## 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>
173 lines
5.7 KiB
JavaScript
173 lines
5.7 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, captureConsole } = require('./helpers.cjs');
|
|
|
|
const isWindows = process.platform === 'win32';
|
|
|
|
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)',
|
|
);
|
|
});
|
|
});
|