* chore(#604): rename get-shit-done/ runtime directory to gsd-core/ Renames the installed runtime directory `get-shit-done/` to `gsd-core/` so the on-disk name matches the package (`@opengsd/gsd-core`), repo, and binary (`gsd-tools`). The npm package name and binary are unchanged; npx/npm consumers are unaffected. Mechanical (bulk, ~90% of the diff): - `git mv get-shit-done gsd-core` - Swept path/identifier references across the repo via `perl -pe 's/get-shit-done(?!-\w)/gsd-core/g'`. The negative lookahead preserves the five legitimate slug variants that are NOT the directory: get-shit-done-{OLD,cc,classic,cli,redux} (old package/repo names). - Build/manifest wiring: package.json (bin, files, coverage globs), tsconfig.build.json (outDir), ~86 .gitignore build-output entries, stryker.config.mjs, scan-ignore files, install.js path strings. - Frozen (not rewritten): CHANGELOG.md history; translated docs (README.<locale>.md and docs/{ja-JP,ko-KR,pt-BR,zh-CN}/). New logic (review here): - src/installer-migrations/003-rename-get-shit-done-to-gsd-core.cts: a proper ADR-0008 installer migration. On upgrade it walks the legacy `~/.claude/get-shit-done/` tree, classifies each file via the prior install manifest, and emits remove-managed / backup-and-remove for managed files while PRESERVING unknown user-added files. Symlink-safe (skips a symlinked root and symlinked entries; bounds-checks every path under configDir). The framework rolls back on install failure. Emptied dirs may remain (framework has no recursive dir-removal primitive) — documented. - scripts/lint-legacy-dir-name.cjs: CI regression guard forbidding the bare `get-shit-done` directory token (split token to avoid self-match; case- insensitive; `(?!-\w)` lookahead allows the slug variants; allowlists CHANGELOG, translated docs, and `gsd-allow-legacy-name` marker lines). Wired into the lint-tests CI job. - Restored scripts/lint-package-identity-drift.cjs detection regexes (the mechanical sweep had wrongly rewritten the old-name patterns it exists to detect) and marked them as intentional legacy references. - TDD tests for the migration and the guard; do.md slash-command guard regex tightened so a `/gsd-core/bin` path segment is not mistaken for a command; changeset + docs/installer-migrations.md row added. Breaking: the installed runtime path moves `~/.claude/get-shit-done/` -> `~/.claude/gsd-core/`. Migration 003 removes the stale legacy dir's managed files (preserving user files) on upgrade. Users with custom hooks/configs hardcoding the old path must update them. Closes #604 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): unsweep pending changesets + allowlist injection-example docs CI fixes for the rename PR: - Do not sweep pending .changeset/*.md (ephemeral release-note fragments, like CHANGELOG); reverted those body edits so 5 pre-existing malformed fragments (missing type/pr) no longer enter the PR diff and trip docs-lint. Allowlisted .changeset/ in the legacy-name guard accordingly. - Allowlisted TEST-EXAMPLES.md and docs/explanation/security-model.md in prompt-injection-scan.sh: they contain intentional injection examples / security-model prose; the path-reference rewrites are kept. CodeQL alerts on this PR are pre-existing (alert lines unchanged by this PR; none in the new migration/guard) and are out of scope for the rename. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): resolve CodeQL alerts surfaced on this PR The rename diff touched files carrying pre-existing CodeQL findings; per the no-pre-existing-dismissal rule, fixing every surfaced alert rather than waving them off. All behavior-preserving: - scripts/ci-test-scope.cjs: build the config-path match from string .includes() instead of a RegExp over an arg-derived value (js/regex-injection). - src/profile-output.cts: escape backslashes before pipe-escaping desc/safeName so the table-cell escape is complete (js/incomplete-sanitization). - tests/{bug-2643,bug-2808,docs-parity-live-registry}: two-pass HTML-comment strip so a bare/unclosed `<!--` cannot survive (js/incomplete-multi-character-sanitization). - tests/inline-plan-threshold: drop the no-op `\s`->`\s` identity replace, keep the meaningful POSIX-class conversion (js/identity-replacement). Verified: build:lib green; the touched test files + ci-test-scope + profile-output suites pass; lint:legacy-name clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): correctly resolve remaining CodeQL alerts (regex-injection + sanitization) The prior commit's fixes for two alerts were ineffective: - ci-test-scope.cjs js/regex-injection: the alert is the CLI-arg-derived `file` reaching static regex `.test(file)` calls (not the config rule). Removed ALL regex over file/t — startsWith/includes/=== string checks + an isWindowsHint helper — so there is no regex sink for the tainted value. - js/incomplete-multi-character-sanitization (3 test files): a single `.replace(/<!--...-->/g,'')` can let `<!--` re-form. Replaced with a fixpoint loop (replace until stable) plus a final bare-opener strip. Verified: no regex over file/t remains; ci-test-scope + the 3 test suites pass; lint:legacy-name clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): make ci-test-scope + comment-strippers regex-free to clear CodeQL CodeQL flags the regex PATTERNS syntactically (regex-injection on the --files arg split; incomplete-multi-character-sanitization on the <!--...--> replace), so loop fixes do not satisfy it. Made these paths regex-free: - ci-test-scope.cjs splitFiles: char-by-char separator tokenizer (no /[,\\s]+/). - 3 test files: indexOf/slice HTML-comment stripper (no .replace(/<!--/)). Behavior preserved; ci-test-scope + the 3 suites pass; guard clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): unblock security base64 scan on the large rename diff The security job hit its 10m timeout: base64-scan.sh choked on the binary test fixture tests/feat-3594-parser-property-style.test.cjs (embedded NUL/ non-UTF8 bytes -> thousands of bogus blobs + "ignored null byte" warnings), and the ~800-file rename diff is slow to scan regardless. - scripts/base64-scan.sh: skip binary-by-content files (grep -Iq .) — they can't carry base64-obfuscated *text* and feeding NUL bytes through the per-line scanner is pathologically slow. collect_files already filtered binary *extensions*; this catches binary *content* in text extensions. - .github/workflows/security-scan.yml: raise the security job timeout 10m->30m to accommodate very large diffs (the scan itself is unchanged). Verified locally: scan skips the fixture, 0 "ignored null byte" warnings, 0 findings, exit 0. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): sweep get-shit-done refs introduced by merging next The branch was updated with next (#614/#384/#618 etc.), which reference the get-shit-done/ dir (still named that on next). Swept the stale references in the merged files to gsd-core so the rename stays consistent and lint:legacy-name passes: - commands/gsd/discuss-phase.md (runtime-launcher shim paths) - src/core.cts (getAgentsDir layout comments) - tests/bug-384-agents-runtime-aware.test.cjs (require path to runtime lib) Verified: guard 0 violations; build green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): exclude gsd-core/ path segments from bug-3683 command cross-ref invariant The #614 runtime-launcher shim added to discuss-phase.md references `${_GSD_RUNTIME_ROOT}/gsd-core/bin/...`. bug-3683's REF_PATTERN excluded path-y refs only via lookbehind, but `}` precedes `/gsd-core/` in the shim, so it mis-read the directory path as a dangling `/gsd-core` command ref (same class as the #604 bug-2954 fix). Added a trailing `(?![\w-]*\/)` so `/gsd-<x>/...` path segments are not treated as slash-command references. Verified locally on BOTH platforms before pushing: - mac (node 26) full suite: 0 failures - gsd-test-runner (linux, node22 image) full suite: 0 failures - bug-3683 + bug-2954 pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): lazily resolve findProjectRoot in gsd-tools (harden flaky CI) CI intermittently failed state.test's gsd-tools subprocess with "findProjectRoot is not a function" (flip-flopping across legs; not reproducible on mac full suite, gsd-test linux full suite, test:unit, or state.test x8). findProjectRoot is a re-export from core.cjs (sourced from project-root.cjs); binding it via destructure at module-load can be undefined under a load-ordering edge. Resolve it lazily at call time via a small wrapper so the lookup happens after core.cjs is fully initialized. Verified green on BOTH platforms before pushing: - mac (node 26) full suite: 0 failures - gsd-test-runner (linux, node22) full suite: 0 failures - state.test.cjs: 106/106; gsd-tools loads cleanly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): allowlist verification-patterns.md placeholder examples in secret scan The rename git-mv'd references/verification-patterns.md into gsd-core/, pulling it into the secret-scan diff. It documents stub/placeholder RED-FLAG env-var examples (illustrative Stripe test-key / database-URL / API-key placeholders) — not real credentials. Added it to .secretscanignore with the strict annotation, mirroring the existing gsd-core/workflows/plan-phase.md exception. Verified locally: secret-scan-lint --strict OK; secret-scan --diff origin/next exits 0 with 0 findings. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
259 lines
12 KiB
JavaScript
259 lines
12 KiB
JavaScript
'use strict';
|
|
|
|
process.env.GSD_TEST_MODE = '1';
|
|
|
|
/**
|
|
* Bug #3017: Codex SessionStart hook still emits bare `node` after #3002.
|
|
*
|
|
* PR #3002 fixed #2979 for settings.json-based managed JS hooks (Claude
|
|
* Code, Gemini, Antigravity) by routing through buildHookCommand() →
|
|
* resolveNodeRunner(), which emits the absolute Node binary path. But the
|
|
* Codex install path writes its SessionStart hook directly into a
|
|
* config.toml string, bypassing both helpers:
|
|
*
|
|
* command = "node ${updateCheckScript}"
|
|
*
|
|
* Under a GUI/minimal PATH (`/usr/bin:/bin:/usr/sbin:/sbin`) where node
|
|
* is not resolvable, the hook fails with `/bin/sh: node: command not
|
|
* found` (exit 127). The same failure mode #2979 was meant to fix —
|
|
* just on the codex toml branch instead of the settings.json branch.
|
|
*
|
|
* The fix exposes two pure helpers and tests them as typed records,
|
|
* not by grepping install.js content:
|
|
*
|
|
* buildCodexHookBlock(targetDir, { absoluteRunner }) → toml string
|
|
* - emits `command = "<absoluteRunner> <quoted hook path>"` so the
|
|
* hook resolves under minimal PATH.
|
|
* - returns null when absoluteRunner is null (caller skips with warn,
|
|
* matching settings.json branch behavior).
|
|
*
|
|
* rewriteLegacyCodexHookBlock(tomlContent, absoluteRunner) → { content, changed }
|
|
* - rewrites an existing bare-node managed-hook command on reinstall
|
|
* (matches the rewriteLegacyManagedNodeHookCommands shape from #3002).
|
|
*/
|
|
|
|
const { test, describe } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const path = require('node:path');
|
|
|
|
const INSTALL = require(path.join(__dirname, '..', 'bin', 'install.js'));
|
|
const projection = require(path.join(__dirname, '..', 'gsd-core', 'bin', 'lib', 'shell-command-projection.cjs'));
|
|
const { buildCodexHookBlock, rewriteLegacyCodexHookBlock, resolveNodeRunner } = INSTALL;
|
|
const { projectCodexHookTomlCommand } = projection;
|
|
|
|
/**
|
|
* Parse the toml hook block into a typed record so tests can assert on
|
|
* the structured shape (what's the runner, what's the hook path, what's
|
|
* the type) rather than substring-matching the toml text.
|
|
*/
|
|
function parseCodexHookBlock(block) {
|
|
if (!block) return { ok: false, reason: 'empty' };
|
|
// The block always carries the "# GSD Hooks" marker, the AoT tables,
|
|
// a type=command, and a command="<runner> <quoted-hook-path>" line.
|
|
const hasMarker = /^# GSD Hooks$/m.test(block);
|
|
const hasEvent = /^\[\[hooks\.SessionStart\]\]$/m.test(block);
|
|
const hasHandler = /^\[\[hooks\.SessionStart\.hooks\]\]$/m.test(block);
|
|
const typeMatch = block.match(/^type\s*=\s*"([^"]+)"$/m);
|
|
// command = "<runner> <hookpath>" — runner may itself be a quoted absolute path.
|
|
// Match the whole RHS as one toml double-quoted string, then split into runner + hookpath.
|
|
const cmdLine = block.match(/^command\s*=\s*"((?:[^"\\]|\\.)*)"$/m);
|
|
if (!cmdLine) return { ok: false, reason: 'no command line' };
|
|
const cmdValue = cmdLine[1];
|
|
// Inside the command value, the runner is either a quoted string (escaped \" in toml)
|
|
// or a bare token, followed by a space and the hook path (quoted).
|
|
// toml escapes interior " as \", so the cmdValue contains literal \" sequences.
|
|
const cmdParsed = cmdValue.match(/^(\\".+?\\"|node|bash|\S+)\s+\\"([^\\]+)\\"\s*$/);
|
|
return {
|
|
ok: true,
|
|
hasMarker,
|
|
hasEvent,
|
|
hasHandler,
|
|
type: typeMatch ? typeMatch[1] : null,
|
|
command: cmdValue,
|
|
runner: cmdParsed ? cmdParsed[1] : null,
|
|
hookPath: cmdParsed ? cmdParsed[2] : null,
|
|
};
|
|
}
|
|
|
|
// Strip the toml-escape (\") and JSON-quote (") layers from the parsed
|
|
// runner token to compare against the raw absolute path the caller
|
|
// supplied. parsed.runner round-trips through TWO escape layers:
|
|
// 1. JSON.stringify in resolveNodeRunner adds outer "..." quotes
|
|
// 2. toml escapes the interior " to \" inside the command field
|
|
// After both, parsed.runner ends in `\"` and starts with `\"`.
|
|
function unescapeRunner(token) {
|
|
if (!token) return token;
|
|
let t = token.replace(/^\\"/, '').replace(/\\"$/, '');
|
|
if (t.startsWith('"') && t.endsWith('"')) t = t.slice(1, -1);
|
|
return t;
|
|
}
|
|
|
|
describe('Bug #3017 / #3440: Codex hook projection seam', () => {
|
|
test('projectCodexHookTomlCommand renders escaped command value from shared projection module', () => {
|
|
const commandValue = projectCodexHookTomlCommand({
|
|
absoluteRunner: '"/usr/local/bin/node"',
|
|
scriptPath: '/tmp/codex-test/.codex/hooks/gsd-check-update.js',
|
|
platform: 'linux',
|
|
});
|
|
assert.equal(
|
|
commandValue,
|
|
'\\"/usr/local/bin/node\\" \\"/tmp/codex-test/.codex/hooks/gsd-check-update.js\\"',
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('Bug #3017: buildCodexHookBlock emits absolute node runner', () => {
|
|
test('exported as a function', () => {
|
|
assert.equal(typeof buildCodexHookBlock, 'function');
|
|
});
|
|
|
|
test('emits the EXACT absolute node runner the caller supplied (#3022 CR)', () => {
|
|
const targetDir = '/tmp/codex-test/.codex';
|
|
const expectedRunnerPath = '/usr/local/bin/node';
|
|
const absoluteRunner = `"${expectedRunnerPath}"`;
|
|
const block = buildCodexHookBlock(targetDir, { absoluteRunner });
|
|
const parsed = parseCodexHookBlock(block);
|
|
assert.equal(parsed.ok, true, `parse failed: ${block}`);
|
|
assert.equal(parsed.hasMarker, true, '# GSD Hooks marker present');
|
|
assert.equal(parsed.hasEvent, true, '[[hooks.SessionStart]] AoT entry present');
|
|
assert.equal(parsed.hasHandler, true, '[[hooks.SessionStart.hooks]] handler entry present');
|
|
assert.equal(parsed.type, 'command', 'handler is type=command');
|
|
// Strict: parsed runner must match the supplied absolute path EXACTLY
|
|
// (after stripping toml/JSON escape layers). A loose substring like
|
|
// '/node' would let an unrelated absolute token containing '/node'
|
|
// pass — e.g. '/Users/x/notnode/foo'.
|
|
assert.equal(unescapeRunner(parsed.runner), expectedRunnerPath,
|
|
`parsed runner must equal supplied absolute path: got ${parsed.runner}, want ${expectedRunnerPath}`);
|
|
// On Windows, path.resolve prepends the current drive letter ("D:") to
|
|
// the POSIX-shaped fixture path. Accept either form.
|
|
const expectedHookSuffix = '/tmp/codex-test/.codex/hooks/gsd-check-update.js';
|
|
assert.ok(
|
|
parsed.hookPath === expectedHookSuffix ||
|
|
parsed.hookPath.replace(/^[A-Za-z]:/, '') === expectedHookSuffix,
|
|
`hook path equality, got: ${parsed.hookPath}, want suffix: ${expectedHookSuffix}`,
|
|
);
|
|
});
|
|
|
|
test('returns null when absoluteRunner is null (caller skips registration)', () => {
|
|
const block = buildCodexHookBlock('/tmp/x/.codex', { absoluteRunner: null });
|
|
assert.equal(block, null,
|
|
'must return null on missing runner so caller can warn-and-skip instead of writing a broken hook');
|
|
});
|
|
|
|
test('integrates with resolveNodeRunner() in the live process — runner equals resolved node runner (#3022 CR)', () => {
|
|
const runner = resolveNodeRunner();
|
|
assert.ok(runner, 'resolveNodeRunner returns a usable value in this test env');
|
|
const block = buildCodexHookBlock('/tmp/x/.codex', { absoluteRunner: runner });
|
|
const parsed = parseCodexHookBlock(block);
|
|
assert.equal(parsed.ok, true);
|
|
// Strict canonical-runner equality: the parsed runner (after stripping
|
|
// toml + JSON escape layers) must be exactly the normalized runner that
|
|
// resolveNodeRunner selected. Homebrew Cellar execPath values intentionally
|
|
// normalize to the stable Homebrew symlink (#3181).
|
|
const expected = JSON.parse(runner);
|
|
assert.equal(unescapeRunner(parsed.runner), expected,
|
|
`parsed runner must equal resolveNodeRunner(), got: ${parsed.runner}, want: ${expected}`);
|
|
});
|
|
});
|
|
|
|
describe('Bug #3017: rewriteLegacyCodexHookBlock migrates bare-node on reinstall', () => {
|
|
test('exported as a function', () => {
|
|
assert.equal(typeof rewriteLegacyCodexHookBlock, 'function');
|
|
});
|
|
|
|
test('rewrites a bare-node managed-hook command to the absolute runner', () => {
|
|
const before = [
|
|
'[model]',
|
|
'name = "o3"',
|
|
'',
|
|
'# GSD Hooks',
|
|
'[[hooks.SessionStart]]',
|
|
'',
|
|
'[[hooks.SessionStart.hooks]]',
|
|
'type = "command"',
|
|
'command = "node /Users/x/.codex/hooks/gsd-check-update.js"',
|
|
'',
|
|
].join('\n');
|
|
const expectedRunnerPath = '/usr/local/bin/node';
|
|
const runner = `"${expectedRunnerPath}"`;
|
|
const result = rewriteLegacyCodexHookBlock(before, runner);
|
|
assert.equal(result.changed, true, 'must report change=true');
|
|
// The migrated command must use the EXACT absolute runner the caller
|
|
// supplied (#3022 CR — was previously asserting a loose '/node'
|
|
// substring which let unrelated absolute paths pass).
|
|
const parsed = parseCodexHookBlock(result.content);
|
|
assert.equal(parsed.ok, true);
|
|
assert.equal(unescapeRunner(parsed.runner), expectedRunnerPath,
|
|
`runner must equal supplied absolute path: ${parsed.runner}`);
|
|
assert.equal(parsed.hookPath, '/Users/x/.codex/hooks/gsd-check-update.js');
|
|
// Non-GSD content (the [model] block) must be preserved verbatim.
|
|
assert.ok(result.content.includes('[model]'));
|
|
assert.ok(result.content.includes('name = "o3"'));
|
|
});
|
|
|
|
test('decodes TOML-escaped quoted script paths before projection', () => {
|
|
const before = [
|
|
'# GSD Hooks',
|
|
'[[hooks.SessionStart]]',
|
|
'',
|
|
'[[hooks.SessionStart.hooks]]',
|
|
'type = "command"',
|
|
'command = "node \\"C:\\\\Users\\\\x\\\\.codex\\\\hooks\\\\gsd-check-update.js\\""',
|
|
'',
|
|
].join('\n');
|
|
const runner = '"/usr/local/bin/node"';
|
|
const result = rewriteLegacyCodexHookBlock(before, runner, { platform: 'win32' });
|
|
assert.equal(result.changed, true);
|
|
const parsed = parseCodexHookBlock(result.content);
|
|
assert.equal(parsed.ok, true, 'hook block must parse correctly');
|
|
const expected = projectCodexHookTomlCommand({
|
|
absoluteRunner: runner,
|
|
scriptPath: 'C:\\Users\\x\\.codex\\hooks\\gsd-check-update.js',
|
|
platform: 'win32',
|
|
});
|
|
assert.equal(parsed.command, expected,
|
|
'rewritten command must project from decoded Windows path (not TOML-escaped token text)');
|
|
assert.equal(unescapeRunner(parsed.runner), '/usr/local/bin/node',
|
|
'runner must equal supplied absolute path');
|
|
assert.equal(parsed.hookPath, 'C:/Users/x/.codex/hooks/gsd-check-update.js',
|
|
'hook path must equal decoded Windows path after projection normalization');
|
|
});
|
|
|
|
test('does NOT touch a managed-hook entry that already uses an absolute runner', () => {
|
|
const already = [
|
|
'# GSD Hooks',
|
|
'[[hooks.SessionStart]]',
|
|
'',
|
|
'[[hooks.SessionStart.hooks]]',
|
|
'type = "command"',
|
|
'command = "\\"/usr/local/bin/node\\" /Users/x/.codex/hooks/gsd-check-update.js"',
|
|
'',
|
|
].join('\n');
|
|
const result = rewriteLegacyCodexHookBlock(already, '"/usr/local/bin/node"');
|
|
assert.equal(result.changed, false);
|
|
assert.equal(result.content, already);
|
|
});
|
|
|
|
test('does NOT touch user-authored bare-node hooks (filename not in managed allowlist)', () => {
|
|
const userOwned = [
|
|
'[[hooks.SessionStart]]',
|
|
'',
|
|
'[[hooks.SessionStart.hooks]]',
|
|
'type = "command"',
|
|
'command = "node /home/me/my-custom-codex-hook.js"',
|
|
'',
|
|
].join('\n');
|
|
const result = rewriteLegacyCodexHookBlock(userOwned, '"/usr/local/bin/node"');
|
|
assert.equal(result.changed, false,
|
|
'user-authored hooks must be left alone; only managed gsd-* hooks are migrated');
|
|
assert.equal(result.content, userOwned);
|
|
});
|
|
|
|
test('returns content unchanged when absoluteRunner is null', () => {
|
|
const before = 'command = "node /path/to/gsd-check-update.js"';
|
|
const result = rewriteLegacyCodexHookBlock(before, null);
|
|
assert.equal(result.changed, false);
|
|
assert.equal(result.content, before);
|
|
});
|
|
});
|