* 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>
328 lines
16 KiB
JavaScript
328 lines
16 KiB
JavaScript
/**
|
|
* Tests for legacy artifact cleanup seam (issue #607).
|
|
*
|
|
* Covers planLegacyCleanup and applyLegacyCleanup from
|
|
* gsd-core/bin/lib/legacy-cleanup.cjs using real temp dirs so the
|
|
* filesystem logic is exercised end-to-end without touching live config dirs.
|
|
*
|
|
* These tests read files they create themselves in OS temp directories —
|
|
* not repo source files. The fs reads are test-input reads, not source-grep.
|
|
* // allow-test-rule: integration-test-input
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const { describe, test, beforeEach, afterEach } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const os = require('node:os');
|
|
const path = require('node:path');
|
|
|
|
const { planLegacyCleanup, applyLegacyCleanup } = require(
|
|
path.join(__dirname, '..', 'gsd-core', 'bin', 'lib', 'legacy-cleanup.cjs')
|
|
);
|
|
const { MANAGED_HOOKS } = require(
|
|
path.join(__dirname, '..', 'hooks', 'managed-hooks-registry.cjs')
|
|
);
|
|
const { cleanup } = require('./helpers.cjs');
|
|
|
|
// Assembled the same way the implementation does so this file also avoids the
|
|
// bare literal (correctness: the test content strings below DO contain it,
|
|
// which is fine — tests may reference the signal string directly).
|
|
const OLD_PACKAGE_SIGNAL = 'gsd-core' + '-cc';
|
|
|
|
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
|
|
function mkTmpDir() {
|
|
return fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-607-'));
|
|
}
|
|
|
|
function writeFile(filePath, content) {
|
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
fs.writeFileSync(filePath, content, 'utf8');
|
|
}
|
|
|
|
// ─── Suite ───────────────────────────────────────────────────────────────────
|
|
|
|
describe('issue-607 legacy-cleanup: planLegacyCleanup', () => {
|
|
let tmpRoot;
|
|
let configDir;
|
|
let homeDir;
|
|
|
|
beforeEach(() => {
|
|
tmpRoot = mkTmpDir();
|
|
configDir = path.join(tmpRoot, 'config');
|
|
homeDir = path.join(tmpRoot, 'home');
|
|
fs.mkdirSync(configDir, { recursive: true });
|
|
fs.mkdirSync(homeDir, { recursive: true });
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpRoot);
|
|
});
|
|
|
|
// ── content-references-old-package ─────────────────────────────────────────
|
|
|
|
test('flags a hook file in hooks/ whose content contains the old package signal', () => {
|
|
const hookFile = path.join(configDir, 'hooks', 'gsd-check-update-worker.js');
|
|
writeFile(hookFile, '// installed via ' + OLD_PACKAGE_SIGNAL + '\nconsole.log("hello");');
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
|
|
const entry = plan.find((p) => p.path === hookFile);
|
|
assert.ok(entry, 'expected hookFile to appear in plan');
|
|
assert.equal(entry.reason, 'content-references-old-package');
|
|
});
|
|
|
|
test('does NOT flag a file whose content does not reference the old package', () => {
|
|
const hookFile = path.join(configDir, 'hooks', 'gsd-check-update-worker.js');
|
|
writeFile(hookFile, '// installed via @opengsd/gsd-core\nconsole.log("ok");');
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
const entry = plan.find((p) => p.path === hookFile);
|
|
assert.equal(entry, undefined, 'clean hook must not appear in plan');
|
|
});
|
|
|
|
// ── data-loss regression: user custom hooks must be preserved ──────────────
|
|
|
|
test('regression #607 (data-loss): user custom gsd-*.js with NO old-package content must NOT appear in plan', () => {
|
|
// Previously the orphaned-hook-by-name rule would flag any gsd-*.js not in
|
|
// MANAGED_HOOKS — deleting user-authored hooks. This is the key regression test.
|
|
const userHook = path.join(configDir, 'hooks', 'gsd-my-custom.js');
|
|
writeFile(userHook, '// my custom hook — does not reference the old package');
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
const entry = plan.find((p) => p.path === userHook);
|
|
assert.equal(entry, undefined, 'user custom gsd-*.js with no old-package content must NOT be in plan');
|
|
});
|
|
|
|
test('regression #607 (data-loss): user custom gsd-*.sh with NO old-package content must NOT appear in plan', () => {
|
|
const userHook = path.join(configDir, 'hooks', 'gsd-my-custom.sh');
|
|
writeFile(userHook, '#!/bin/sh\n# my custom shell hook, clean');
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
const entry = plan.find((p) => p.path === userHook);
|
|
assert.equal(entry, undefined, 'user custom gsd-*.sh with no old-package content must NOT be in plan');
|
|
});
|
|
|
|
// ── self-deletion regression: gsd-core/ subtree must NOT be scanned ──
|
|
|
|
test('regression #607 (self-deletion): a code file under gsd-core/bin/lib/ containing old-package signal must NOT be flagged', () => {
|
|
// The subtree 'gsd-core' is no longer scanned — the current package's
|
|
// own infra lives there and would falsely match if scanned.
|
|
const libFile = path.join(configDir, 'gsd-core', 'bin', 'lib', 'legacy-cleanup.cjs');
|
|
writeFile(libFile, "'use strict';\nconst SIG = 'gsd-core' + '-cc';\nmodule.exports = {};");
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
const entry = plan.find((p) => p.path === libFile);
|
|
assert.equal(entry, undefined, 'code file in gsd-core/ subtree must NOT appear in plan (subtree not scanned)');
|
|
});
|
|
|
|
// ── issue-607 regression: markdown files must never be flagged ─────────────
|
|
|
|
test('regression #607: CHANGELOG.md containing old-package signal must NOT be flagged', () => {
|
|
// Markdown docs legitimately cite the old package name in historical context.
|
|
const changelogFile = path.join(configDir, 'gsd-core', 'CHANGELOG.md');
|
|
writeFile(changelogFile, '# Changelog\n\nMigrated from ' + OLD_PACKAGE_SIGNAL + ' to @opengsd/gsd-core.');
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
|
|
const entry = plan.find((p) => p.path === changelogFile);
|
|
assert.equal(entry, undefined, 'CHANGELOG.md must never appear in plan even if it cites the old package name');
|
|
});
|
|
|
|
test('regression #607: a workflow .md file containing old-package signal must NOT be flagged', () => {
|
|
const workflowMd = path.join(configDir, 'gsd-core', 'workflows', 'update.md');
|
|
writeFile(workflowMd, '# Update workflow\n\nPreviously required ' + OLD_PACKAGE_SIGNAL + ' to be installed.');
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
|
|
const entry = plan.find((p) => p.path === workflowMd);
|
|
assert.equal(entry, undefined, 'workflow .md must never appear in plan even if it cites the old package name');
|
|
});
|
|
|
|
// ── dev-preferences exclusion ──────────────────────────────────────────────
|
|
|
|
test('NEVER flags dev-preferences.md even if its content contains old-package signal', () => {
|
|
// Place dev-preferences.md inside a GSD-managed subtree
|
|
const devPrefs = path.join(configDir, 'hooks', 'dev-preferences.md');
|
|
writeFile(devPrefs, '# My prefs\n\nI used to use ' + OLD_PACKAGE_SIGNAL);
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
const entry = plan.find((p) => p.path === devPrefs);
|
|
assert.equal(entry, undefined, 'dev-preferences.md must never appear in plan');
|
|
});
|
|
|
|
test('NEVER flags a file under a dev-preferences/ directory', () => {
|
|
const dpFile = path.join(configDir, 'hooks', 'dev-preferences', 'notes.md');
|
|
writeFile(dpFile, 'old notes referencing ' + OLD_PACKAGE_SIGNAL);
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
const entry = plan.find((p) => p.path === dpFile);
|
|
assert.equal(entry, undefined, 'file under dev-preferences/ dir must never appear in plan');
|
|
});
|
|
|
|
// ── legacy-shared-cache ────────────────────────────────────────────────────
|
|
|
|
test('flags the legacy shared cache when it exists with reason legacy-shared-cache', () => {
|
|
const cachePath = path.join(homeDir, '.cache', 'gsd', 'gsd-update-check.json');
|
|
writeFile(cachePath, JSON.stringify({ update_available: false }));
|
|
|
|
const plan = planLegacyCleanup([], { homeDir });
|
|
|
|
const entry = plan.find((p) => p.path === cachePath);
|
|
assert.ok(entry, 'expected legacy cache to appear in plan');
|
|
assert.equal(entry.reason, 'legacy-shared-cache');
|
|
});
|
|
|
|
test('does NOT flag the legacy shared cache when it is absent', () => {
|
|
// homeDir exists but cache file was never written
|
|
const plan = planLegacyCleanup([], { homeDir });
|
|
const cachePath = path.join(homeDir, '.cache', 'gsd', 'gsd-update-check.json');
|
|
const entry = plan.find((p) => p.path === cachePath);
|
|
assert.equal(entry, undefined, 'absent cache must not appear in plan');
|
|
});
|
|
|
|
// ── deduplication and sort ─────────────────────────────────────────────────
|
|
|
|
test('de-duplicates candidates when two configDirs share same absolute path (same dir listed twice)', () => {
|
|
const signalFile = path.join(configDir, 'hooks', 'gsd-old-feature.sh');
|
|
writeFile(signalFile, '# ' + OLD_PACKAGE_SIGNAL);
|
|
|
|
const plan = planLegacyCleanup([configDir, configDir], { homeDir });
|
|
const entries = plan.filter((p) => p.path === signalFile);
|
|
assert.equal(entries.length, 1, 'same path must appear only once');
|
|
});
|
|
|
|
test('plan entries are sorted by path', () => {
|
|
writeFile(path.join(configDir, 'hooks', 'gsd-zzz-last.js'), '// ' + OLD_PACKAGE_SIGNAL);
|
|
writeFile(path.join(configDir, 'hooks', 'gsd-aaa-first.js'), '// ' + OLD_PACKAGE_SIGNAL);
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
const paths = plan.map((p) => p.path);
|
|
const sorted = [...paths].sort();
|
|
assert.deepEqual(paths, sorted, 'plan must be sorted by path');
|
|
});
|
|
|
|
// ── only content-references-old-package and legacy-shared-cache reasons ────
|
|
|
|
test('plan entries only ever have reason content-references-old-package or legacy-shared-cache', () => {
|
|
writeFile(path.join(configDir, 'hooks', 'gsd-worker.js'), '// ' + OLD_PACKAGE_SIGNAL);
|
|
const cachePath = path.join(homeDir, '.cache', 'gsd', 'gsd-update-check.json');
|
|
writeFile(cachePath, '{}');
|
|
// User custom hook — should NOT appear
|
|
writeFile(path.join(configDir, 'hooks', 'gsd-my-custom.js'), '// user hook, clean');
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
const validReasons = new Set(['content-references-old-package', 'legacy-shared-cache']);
|
|
for (const entry of plan) {
|
|
assert.ok(validReasons.has(entry.reason), `unexpected reason: ${entry.reason}`);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('issue-607 legacy-cleanup: applyLegacyCleanup', () => {
|
|
let tmpRoot;
|
|
let configDir;
|
|
let homeDir;
|
|
|
|
beforeEach(() => {
|
|
tmpRoot = mkTmpDir();
|
|
configDir = path.join(tmpRoot, 'config');
|
|
homeDir = path.join(tmpRoot, 'home');
|
|
fs.mkdirSync(configDir, { recursive: true });
|
|
fs.mkdirSync(homeDir, { recursive: true });
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpRoot);
|
|
});
|
|
|
|
// ── dry-run ────────────────────────────────────────────────────────────────
|
|
|
|
test('dryRun:true removes nothing and returns dryRun:true + all paths in skipped', () => {
|
|
// Use a content-signal hook (only way to get a plan entry now)
|
|
const signalHook = path.join(configDir, 'hooks', 'gsd-check-update-worker.js');
|
|
writeFile(signalHook, '// ' + OLD_PACKAGE_SIGNAL);
|
|
const cacheFile = path.join(homeDir, '.cache', 'gsd', 'gsd-update-check.json');
|
|
writeFile(cacheFile, '{}');
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
assert.ok(plan.length > 0, 'precondition: plan must be non-empty');
|
|
|
|
const logMessages = [];
|
|
const mockLogger = { log: (msg) => logMessages.push(msg) };
|
|
|
|
const result = applyLegacyCleanup(plan, { dryRun: true, logger: mockLogger });
|
|
|
|
assert.equal(result.dryRun, true);
|
|
assert.equal(result.removed.length, 0, 'dryRun must remove nothing');
|
|
assert.equal(result.skipped.length, plan.length, 'all plan entries must be in skipped');
|
|
assert.deepEqual(result.skipped.sort(), plan.map((p) => p.path).sort());
|
|
|
|
// All flagged files must still exist
|
|
for (const item of plan) {
|
|
assert.ok(fs.existsSync(item.path), `${item.path} must still exist after dry-run`);
|
|
}
|
|
|
|
// Logger must have been called for each item
|
|
assert.equal(logMessages.length, plan.length, 'logger must be called once per plan item');
|
|
for (const msg of logMessages) {
|
|
assert.ok(msg.startsWith('[dry-run] would remove:'), `log message format unexpected: ${msg}`);
|
|
}
|
|
});
|
|
|
|
// ── real apply ────────────────────────────────────────────────────────────
|
|
|
|
test('apply removes flagged files and returns them in removed[]', () => {
|
|
// Content-signal hook — flagged and must be removed
|
|
const signalHook = path.join(configDir, 'hooks', 'gsd-check-update-worker.js');
|
|
writeFile(signalHook, '// ' + OLD_PACKAGE_SIGNAL);
|
|
const cacheFile = path.join(homeDir, '.cache', 'gsd', 'gsd-update-check.json');
|
|
writeFile(cacheFile, '{}');
|
|
|
|
// User custom hook — clean content, must NOT be in plan and must survive
|
|
const userHook = path.join(configDir, 'hooks', 'gsd-my-custom.js');
|
|
writeFile(userHook, '// user hook, no old package ref');
|
|
|
|
// Managed hook with clean content — must NOT be in plan and must survive
|
|
const managedHook = path.join(configDir, 'hooks', MANAGED_HOOKS[0]);
|
|
writeFile(managedHook, '// @opengsd/gsd-core only');
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
assert.ok(plan.length > 0, 'precondition: plan must be non-empty');
|
|
// Verify clean files not in plan
|
|
assert.equal(plan.find((p) => p.path === userHook), undefined, 'user hook must not be in plan');
|
|
assert.equal(plan.find((p) => p.path === managedHook), undefined, 'managed hook must not be in plan');
|
|
|
|
const result = applyLegacyCleanup(plan);
|
|
|
|
assert.equal(result.dryRun, false);
|
|
assert.deepEqual(result.removed.sort(), plan.map((p) => p.path).sort());
|
|
assert.equal(result.errors.length, 0, 'no errors expected');
|
|
|
|
// Flagged files must be gone
|
|
for (const item of plan) {
|
|
assert.equal(fs.existsSync(item.path), false, `${item.path} must have been removed`);
|
|
}
|
|
|
|
// Clean (non-flagged) files must still exist
|
|
assert.ok(fs.existsSync(userHook), 'user custom hook must be preserved');
|
|
assert.ok(fs.existsSync(managedHook), 'managed hook must be preserved');
|
|
});
|
|
|
|
test('apply does not touch dev-preferences.md even if it somehow entered the plan (invariant)', () => {
|
|
// planLegacyCleanup never adds dev-prefs; this test confirms that invariant.
|
|
const devPrefs = path.join(configDir, 'hooks', 'dev-preferences.md');
|
|
writeFile(devPrefs, '# prefs\n' + OLD_PACKAGE_SIGNAL + ' was used here');
|
|
|
|
const plan = planLegacyCleanup([configDir], { homeDir });
|
|
const inPlan = plan.find((p) => p.path === devPrefs);
|
|
assert.equal(inPlan, undefined, 'planLegacyCleanup must never include dev-preferences.md');
|
|
|
|
// Since dev-prefs is not in the plan, applying the plan cannot remove it.
|
|
applyLegacyCleanup(plan);
|
|
assert.ok(fs.existsSync(devPrefs), 'dev-preferences.md must survive apply');
|
|
});
|
|
});
|