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>
This commit is contained in:
@@ -19,3 +19,11 @@ Custom label mapping: `confirmed` = AFK-agent-ready (bugs); `approved-enhancemen
|
||||
### Domain docs
|
||||
|
||||
Single-context repo — `CONTEXT.md` + `docs/adr/` at the root. See `docs/agents/domain.md`.
|
||||
|
||||
## Memory
|
||||
|
||||
This project uses MemPalace. At the start of every session, call
|
||||
`mempalace_status` to load the palace protocol. Before answering
|
||||
questions about people, past work, or prior decisions in this
|
||||
project, call `mempalace_search` or `mempalace_kg_query` first —
|
||||
do not guess from context alone.
|
||||
|
||||
@@ -28,9 +28,8 @@ const {
|
||||
getCodexSkillAdapterHeader,
|
||||
} = require('../bin/install.js');
|
||||
|
||||
function makeTmp(prefix) {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), `gsd-2256-${prefix}-`));
|
||||
}
|
||||
const { createTempDir } = require('./helpers.cjs');
|
||||
const makeTmp = (prefix) => createTempDir(`gsd-2256-${prefix}-`);
|
||||
|
||||
function writeJson(p, obj) {
|
||||
fs.mkdirSync(path.dirname(p), { recursive: true });
|
||||
|
||||
@@ -39,39 +39,7 @@ const installModule = require('../bin/install.js');
|
||||
|
||||
const isWindows = process.platform === 'win32';
|
||||
const { installSdkIfNeeded } = installModule;
|
||||
const { createTempDir, cleanup } = require('./helpers.cjs');
|
||||
|
||||
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;
|
||||
}
|
||||
// Re-throw any captured exception AFTER restoring console so callers don't
|
||||
// have to destructure-and-assert on `threw` (and a future regression that
|
||||
// crashes before printing won't falsely pass `!hasReady`). (#2775
|
||||
// CodeRabbit follow-up)
|
||||
if (threw) throw threw;
|
||||
// strip ANSI for matching
|
||||
const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
|
||||
return {
|
||||
stdout: stdout.map(strip).join('\n'),
|
||||
stderr: stderr.map(strip).join('\n'),
|
||||
};
|
||||
}
|
||||
const { createTempDir, cleanup, captureConsole } = require('./helpers.cjs');
|
||||
|
||||
describe('bug #2775: installSdkIfNeeded must verify gsd-sdk on PATH before reporting ready',
|
||||
{ skip: isWindows ? 'POSIX-only: asserts ~/.local/bin shebang shim with mode 0o755; Windows uses gsd-sdk.cmd + PATHEXT + registry Path' : false },
|
||||
|
||||
@@ -35,9 +35,8 @@ const {
|
||||
install,
|
||||
} = require('../bin/install.js');
|
||||
|
||||
function makeTmp(prefix) {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), `gsd-2794-${prefix}-`));
|
||||
}
|
||||
const { createTempDir } = require('./helpers.cjs');
|
||||
const makeTmp = (prefix) => createTempDir(`gsd-2794-${prefix}-`);
|
||||
|
||||
function writeJson(p, obj) {
|
||||
fs.mkdirSync(path.dirname(p), { recursive: true });
|
||||
|
||||
@@ -29,37 +29,10 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const { installSdkIfNeeded } = require('../bin/install.js');
|
||||
const { createTempDir, cleanup } = require('./helpers.cjs');
|
||||
const { createTempDir, cleanup, captureConsole } = 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 #2829: local-mode install must materialize gsd-sdk on PATH',
|
||||
{ skip: isWindows ? 'POSIX-only: asserts ~/.local/bin shebang shim; Windows uses gsd-sdk.cmd + USERPROFILE + PATHEXT' : false },
|
||||
() => {
|
||||
|
||||
@@ -26,37 +26,10 @@ const path = require('path');
|
||||
const os = require('os');
|
||||
|
||||
const { installSdkIfNeeded } = require('../bin/install.js');
|
||||
const { createTempDir, cleanup } = require('./helpers.cjs');
|
||||
const { createTempDir, cleanup, captureConsole } = 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 },
|
||||
() => {
|
||||
|
||||
@@ -50,6 +50,7 @@ const cp = require('node:child_process');
|
||||
|
||||
const ROOT = path.join(__dirname, '..');
|
||||
const installModule = require(path.join(ROOT, 'bin', 'install.js'));
|
||||
const { captureConsole } = require('./helpers.cjs');
|
||||
|
||||
const isWindows = process.platform === 'win32';
|
||||
|
||||
@@ -254,27 +255,6 @@ describe('bug #3211-D: installSdkIfNeeded — Windows _npx false-positive', () =
|
||||
let savedEnv;
|
||||
let origExecSync;
|
||||
|
||||
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') };
|
||||
}
|
||||
|
||||
function makeSdkDir(root) {
|
||||
const dir = path.join(root, 'sdk');
|
||||
fs.mkdirSync(path.join(dir, 'dist'), { recursive: true });
|
||||
|
||||
@@ -36,6 +36,7 @@ const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
|
||||
const installModule = require('../bin/install.js');
|
||||
const { captureConsole } = require('./helpers.cjs');
|
||||
|
||||
const isWindows = process.platform === 'win32';
|
||||
|
||||
@@ -49,33 +50,6 @@ const {
|
||||
// ---------------------------------------------------------------------------
|
||||
// Console capture helper (no ANSI)
|
||||
// ---------------------------------------------------------------------------
|
||||
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'),
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Shared fixture helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -39,13 +39,10 @@ const { install } = require('../bin/install.js');
|
||||
|
||||
// ─── helpers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function makeTmpDir(prefix) {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
||||
}
|
||||
const { createTempDir, cleanup } = require('./helpers.cjs');
|
||||
const makeTmpDir = createTempDir;
|
||||
|
||||
function rmTmpDir(dir) {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
const rmTmpDir = cleanup;
|
||||
|
||||
/**
|
||||
* Silence console output during install to avoid noise in test output.
|
||||
|
||||
@@ -19,37 +19,10 @@ 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 } = require('./helpers.cjs');
|
||||
const { createTempDir, cleanup, captureConsole } = 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 #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 },
|
||||
() => {
|
||||
|
||||
@@ -42,11 +42,9 @@ const WORKFLOW_PATH = path.join(
|
||||
// ─── Helper: create outer git repo with a nested workstream subdir ─────────
|
||||
|
||||
// On Windows the runtime emits forward slashes (git's convention) while
|
||||
// path.join produces backslashes — normalize both sides before any
|
||||
// equality comparison against the handler's git_worktree_root.
|
||||
function normalizePath(p) {
|
||||
return p == null ? p : p.split(path.sep).join('/');
|
||||
}
|
||||
// path.join produces backslashes — normalize both sides via the shared
|
||||
// toPosixPath helper before any equality comparison.
|
||||
const { toPosixPath: normalizePath } = require('./helpers.cjs');
|
||||
|
||||
function createOuterRepoWithSubdir(prefix = 'bug-3491-') {
|
||||
const outer = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
||||
|
||||
@@ -20,9 +20,8 @@ const SDK_SHARED_DIR = path.join(REPO_ROOT, 'sdk', 'shared');
|
||||
|
||||
const { install } = require('../bin/install.js');
|
||||
|
||||
function makeTmpDir() {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-3571-'));
|
||||
}
|
||||
const { createTempDir } = require('./helpers.cjs');
|
||||
const makeTmpDir = () => createTempDir('gsd-3571-');
|
||||
|
||||
function silenceConsole(fn) {
|
||||
const original = {
|
||||
|
||||
@@ -36,9 +36,8 @@ const {
|
||||
} = require('../get-shit-done/bin/lib/model-profiles.cjs');
|
||||
const { isValidConfigKey } = require('../get-shit-done/bin/lib/config-schema.cjs');
|
||||
|
||||
function makeTmp(prefix) {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), `gsd-3023-${prefix}-`));
|
||||
}
|
||||
const { createTempDir } = require('./helpers.cjs');
|
||||
const makeTmp = (prefix) => createTempDir(`gsd-3023-${prefix}-`);
|
||||
|
||||
function writeConfig(projectDir, config) {
|
||||
const planningDir = path.join(projectDir, '.planning');
|
||||
|
||||
@@ -60,9 +60,8 @@ const {
|
||||
} = require('../get-shit-done/bin/lib/model-profiles.cjs');
|
||||
const { isValidConfigKey } = require('../get-shit-done/bin/lib/config-schema.cjs');
|
||||
|
||||
function makeTmp(prefix) {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), `gsd-3024-${prefix}-`));
|
||||
}
|
||||
const { createTempDir } = require('./helpers.cjs');
|
||||
const makeTmp = (prefix) => createTempDir(`gsd-3024-${prefix}-`);
|
||||
function writeConfig(dir, config) {
|
||||
const planningDir = path.join(dir, '.planning');
|
||||
fs.mkdirSync(planningDir, { recursive: true });
|
||||
|
||||
@@ -48,9 +48,8 @@ const {
|
||||
* Create a fresh real-fs scratch dir per test so no two faults share
|
||||
* state. Returns the directory; caller must clean up.
|
||||
*/
|
||||
function mkScratch(name) {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), `fs-fault-${name}-`));
|
||||
}
|
||||
const { createTempDir } = require('./helpers.cjs');
|
||||
const mkScratch = (name) => createTempDir(`fs-fault-${name}-`);
|
||||
|
||||
/**
|
||||
* Enumerate orphan tmp files left behind by platformWriteSync. The
|
||||
|
||||
@@ -175,4 +175,52 @@ function isUsageOutput(text) {
|
||||
return /Usage:\s*gsd-tools/.test(text) && /Commands:/.test(text);
|
||||
}
|
||||
|
||||
module.exports = { runGsdTools, createTempDir, createTempProject, createTempGitProject, cleanup, parseFrontmatter, isUsageOutput, TOOLS_PATH };
|
||||
/**
|
||||
* Run `fn` with console.log/warn/error captured, returning {stdout, stderr}
|
||||
* with ANSI colors stripped. Re-throws any exception fn threw AFTER restoring
|
||||
* the real console so the caller's assertion path sees the failure (without
|
||||
* this, a fn that crashes before printing would falsely pass !hasReady-style
|
||||
* assertions). #2775 CR follow-up established this exact contract.
|
||||
*
|
||||
* Previously duplicated in bug-2775, bug-2829, bug-3033, bug-3211, bug-3231,
|
||||
* bug-3359, and installer-migration-install-integration.
|
||||
*/
|
||||
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'),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize platform path separators to POSIX forward slashes. Use for
|
||||
* cross-platform path comparisons in test assertions where the runtime
|
||||
* emits the platform-native separator (\ on Windows) but the test
|
||||
* fixture or expected literal is POSIX. Returns the input unchanged if
|
||||
* null/undefined so it composes safely with optional chaining.
|
||||
*/
|
||||
function toPosixPath(p) {
|
||||
return p == null ? p : p.split(path.sep).join('/');
|
||||
}
|
||||
|
||||
module.exports = { runGsdTools, createTempDir, createTempProject, createTempGitProject, cleanup, parseFrontmatter, isUsageOutput, captureConsole, toPosixPath, TOOLS_PATH };
|
||||
|
||||
@@ -27,9 +27,8 @@ before(async () => {
|
||||
|
||||
// ── Fixture helpers ─────────────────────────────────────────────────────────
|
||||
|
||||
function makeTmp() {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-parity-'));
|
||||
}
|
||||
const { createTempDir } = require('./helpers.cjs');
|
||||
const makeTmp = () => createTempDir('gsd-parity-');
|
||||
|
||||
function writeConfig(dir, content) {
|
||||
fs.mkdirSync(path.join(dir, '.planning'), { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user