* 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>
387 lines
18 KiB
JavaScript
387 lines
18 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Tests for bug #3706 (word-boundary anchoring) and #3718 (cross-shell portability).
|
|
*
|
|
* Root cause (#3706): grep -iE "UI|..." had no word-boundary anchoring, causing
|
|
* false-positives on "Requirements" (contains "ui"), "overview" ("view"), etc.
|
|
*
|
|
* Root cause (#3718): shell-based invocation (with locale env-var prefix) silently
|
|
* degrades on Windows PowerShell — the prefix is not recognised by pwsh.
|
|
*
|
|
* Fix (#3718, Approach A): gate logic moved to `bin/lib/ui-safety-gate.cjs` (Node.js).
|
|
* Reads phase text from STDIN (not argv) to avoid OS ARG_MAX limits.
|
|
* Invoked as: printf '%s' "$PHASE_SECTION" | node "${GSD_REPO_ROOT}/bin/lib/ui-safety-gate.cjs"
|
|
* Path anchored to repo root via `git rev-parse --show-toplevel`.
|
|
*
|
|
* Test strategy:
|
|
* 1. Import the helper module directly and assert correct results on the full fixture
|
|
* matrix (exercises the production code path).
|
|
* 2. Spawn the helper as a child process with shell:false and input on stdin to prove
|
|
* cross-shell portability — spawnSync with shell:false bypasses any host shell.
|
|
* 3. Assert the workflow .md files now invoke `node ... ui-safety-gate.cjs` via stdin
|
|
* rather than the old shell-based invocation (structural guard against regression).
|
|
*/
|
|
|
|
const { describe, test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { spawnSync } = require('node:child_process');
|
|
const os = require('node:os');
|
|
const { cleanup } = require('./helpers.cjs');
|
|
|
|
const HELPER_PATH = path.join(__dirname, '..', 'bin', 'lib', 'ui-safety-gate.cjs');
|
|
const PLAN_PHASE_PATH = path.join(__dirname, '..', 'gsd-core', 'workflows', 'plan-phase.md');
|
|
const AUTONOMOUS_PATH = path.join(__dirname, '..', 'gsd-core', 'workflows', 'autonomous.md');
|
|
|
|
const { checkUiPresence } = require(HELPER_PATH);
|
|
|
|
// ── Helper ────────────────────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* Mirrors the old `hasUiGate` helper for backwards-compatible assertions.
|
|
* Returns 0 (UI found) or 1 (not found), matching grep exit code semantics.
|
|
*/
|
|
function hasUiGate(text) {
|
|
return checkUiPresence(text).hasUI ? 0 : 1;
|
|
}
|
|
|
|
/**
|
|
* Spawn the helper with shell:false, passing input via stdin.
|
|
* Returns the spawnSync result object.
|
|
*/
|
|
function spawnGate(input) {
|
|
return spawnSync(process.execPath, [HELPER_PATH], {
|
|
shell: false,
|
|
encoding: 'utf-8',
|
|
input: input,
|
|
});
|
|
}
|
|
|
|
// ── Structural guard — workflow files now invoke Node via stdin ───────────────
|
|
|
|
describe('Workflow .md structural guard (#3718)', () => {
|
|
// allow-test-rule: source-text-is-the-product
|
|
// The UI safety gate invocation is embedded in workflow prose-as-code.
|
|
// These structural tests guard against regression where someone re-introduces
|
|
// the shell-based locale-prefix invocation that silently breaks on Windows PowerShell.
|
|
for (const [label, filePath] of [
|
|
['plan-phase.md', PLAN_PHASE_PATH],
|
|
['autonomous.md', AUTONOMOUS_PATH],
|
|
]) {
|
|
test(`${label} must invoke ui-safety-gate.cjs via stdin, anchored to the GSD install dir`, () => {
|
|
const content = fs.readFileSync(filePath, 'utf-8');
|
|
assert.ok(
|
|
content.includes('ui-safety-gate.cjs'),
|
|
`${label}: must reference ui-safety-gate.cjs for cross-shell portability (#3718)`
|
|
);
|
|
|
|
// Scope structural assertions to the gate invocation region so we test the
|
|
// gate's OWN resolution, not §1's unrelated RUNTIME_DIR usage for gsd-tools.
|
|
const gi = content.indexOf('ui-safety-gate.cjs');
|
|
const region = content.slice(Math.max(0, gi - 800), gi + 200);
|
|
|
|
// #448: the helper ships inside the GSD package, so it must be resolved
|
|
// against the GSD install dir (RUNTIME_DIR), NOT the consuming project's
|
|
// git root — otherwise the node call fails and the gate silently no-ops.
|
|
assert.ok(
|
|
region.includes('RUNTIME_DIR'),
|
|
`${label}: UI gate must resolve ui-safety-gate.cjs against RUNTIME_DIR (the GSD install dir), not the consuming project's git root (#448)`
|
|
);
|
|
assert.ok(
|
|
!region.includes('GSD_REPO_ROOT'),
|
|
`${label}: UI gate must NOT anchor the helper to GSD_REPO_ROOT (the consuming project's git root) — that silently no-ops in installed repos (#448)`
|
|
);
|
|
// Retain a git rev-parse --show-toplevel fallback when RUNTIME_DIR is unset (#3718).
|
|
assert.ok(
|
|
region.includes('git rev-parse --show-toplevel'),
|
|
`${label}: must retain a git rev-parse --show-toplevel fallback for the install-dir resolution`
|
|
);
|
|
// Confirm stdin pipe usage (printf or echo piped to node)
|
|
assert.ok(
|
|
content.includes('printf') || content.includes('echo'),
|
|
`${label}: must pipe phase section via stdin (printf/echo | node) to avoid ARG_MAX`
|
|
);
|
|
assert.ok(
|
|
!content.includes('LC_ALL=C grep'),
|
|
`${label}: must NOT contain LC_ALL=C grep — that silently fails on Windows PowerShell (#3718)`
|
|
);
|
|
});
|
|
}
|
|
});
|
|
|
|
// ── Cross-shell spawn test (#3718) ────────────────────────────────────────────
|
|
|
|
describe('Cross-shell portability — spawnSync with shell:false, stdin (#3718)', () => {
|
|
test('spawn with shell:false + stdin: UI input exits 0', () => {
|
|
const result = spawnGate('UI Refactor: migrate all screens');
|
|
assert.strictEqual(result.status, 0, `Expected exit 0 (UI found), got ${result.status}. stderr: ${result.stderr}`);
|
|
});
|
|
|
|
test('spawn with shell:false + stdin: non-UI input exits 1', () => {
|
|
const result = spawnGate('Requirements: backend REST API only');
|
|
assert.strictEqual(result.status, 1, `Expected exit 1 (no UI), got ${result.status}. stderr: ${result.stderr}`);
|
|
});
|
|
|
|
test('spawn with shell:false + stdin: empty input exits 1', () => {
|
|
const result = spawnGate('');
|
|
assert.strictEqual(result.status, 1, `Expected exit 1 (no UI for empty input), got ${result.status}. stderr: ${result.stderr}`);
|
|
});
|
|
|
|
test('spawn with shell:false + stdin: CRLF line endings handled correctly', () => {
|
|
const result = spawnGate('Deploy to the cloud platform\r\nand configure CI/CD.');
|
|
assert.strictEqual(result.status, 1, `CRLF "platform" must not trigger gate. stderr: ${result.stderr}`);
|
|
});
|
|
|
|
test('spawn with shell:false + stdin: multi-line input with UI token exits 0', () => {
|
|
const multiLine = 'Backend setup\nBuild the analytics dashboard\nand navigation component.';
|
|
const result = spawnGate(multiLine);
|
|
assert.strictEqual(result.status, 0, `Multi-line input with "dashboard" must exit 0. stderr: ${result.stderr}`);
|
|
});
|
|
|
|
test('spawn with shell:false + stdin: very large input (>100KB) is handled without error', () => {
|
|
// Verifies stdin transport does not hit ARG_MAX (argv transport fails above ~1MB on macOS).
|
|
// Fixture uses pure backend prose — no standalone UI tokens.
|
|
const largeInput = 'Backend service deployment and database migration step.\n'.repeat(3000);
|
|
const result = spawnGate(largeInput);
|
|
assert.strictEqual(result.status, 1, `Large non-UI input must exit 1, not crash. status: ${result.status}, stderr: ${result.stderr}`);
|
|
});
|
|
|
|
test('spawn with shell:false + stdin: large input with UI token exits 0', () => {
|
|
const largeUiInput = 'Backend infrastructure setup.\n'.repeat(2999) + 'Build the analytics dashboard.\n';
|
|
const result = spawnGate(largeUiInput);
|
|
assert.strictEqual(result.status, 0, `Large input ending with UI token must exit 0. stderr: ${result.stderr}`);
|
|
});
|
|
});
|
|
|
|
// ── Behavioral test matrix (via module import) ────────────────────────────────
|
|
|
|
/**
|
|
* Full fixture matrix — exercises the production checkUiPresence() function directly.
|
|
*/
|
|
function runBehavioralTests(label) {
|
|
describe(`${label} — UI gate behavioral matrix`, () => {
|
|
|
|
// ── False-positive tests (must NOT match) ──────────────────────────────
|
|
|
|
test('"Requirements" must NOT trigger UI gate (bug #3706 — "ui" substring)', () => {
|
|
const phaseSection =
|
|
'**Requirements**: The service must expose REST endpoints for authentication.\n' +
|
|
'All work is server-side. Database migrations and API contract only.';
|
|
assert.strictEqual(hasUiGate(phaseSection), 1, '"Requirements" must not match the UI gate');
|
|
});
|
|
|
|
test('"overview" must NOT trigger UI gate ("view" is a substring)', () => {
|
|
assert.strictEqual(hasUiGate('Overview of the data pipeline architecture and backend services.'), 1);
|
|
});
|
|
|
|
test('"performance" must NOT trigger UI gate ("form" is a substring)', () => {
|
|
assert.strictEqual(hasUiGate('Performance testing and benchmark analysis for the API layer.'), 1);
|
|
});
|
|
|
|
test('"platform" must NOT trigger UI gate ("form" is a substring)', () => {
|
|
assert.strictEqual(hasUiGate('Deploy to the cloud platform and configure CI/CD.'), 1);
|
|
});
|
|
|
|
test('"transform" must NOT trigger UI gate ("form" is a substring)', () => {
|
|
assert.strictEqual(hasUiGate('Transform raw event data and write to the warehouse.'), 1);
|
|
});
|
|
|
|
test('"review" must NOT trigger UI gate ("view" is a substring)', () => {
|
|
assert.strictEqual(hasUiGate('Code review checklist and PR approval workflow for the API.'), 1);
|
|
});
|
|
|
|
test('"build" must NOT trigger UI gate ("ui" at positions 2-3 of "build")', () => {
|
|
assert.strictEqual(hasUiGate('Build the backend service and run integration tests.'), 1);
|
|
});
|
|
|
|
test('"screening" must NOT trigger UI gate ("screen" is a substring)', () => {
|
|
assert.strictEqual(hasUiGate('Implement candidate screening criteria for the hiring pipeline.'), 1);
|
|
});
|
|
|
|
test('empty input does NOT trigger UI gate', () => {
|
|
assert.strictEqual(hasUiGate(''), 1);
|
|
});
|
|
|
|
test('whitespace-only input does NOT trigger UI gate', () => {
|
|
assert.strictEqual(hasUiGate(' \n \t '), 1);
|
|
});
|
|
|
|
test('compound "microfrontend" (no separator) does NOT trigger gate — documented behavior', () => {
|
|
assert.strictEqual(
|
|
hasUiGate('Build the microfrontend shell application.'), 1,
|
|
'"microfrontend" compound must NOT trigger gate'
|
|
);
|
|
});
|
|
|
|
// ── True-positive tests (must match) ──────────────────────────────────
|
|
|
|
test('standalone "UI" token DOES trigger UI gate', () => {
|
|
assert.strictEqual(hasUiGate('UI Refactor: migrate all screens to the new design system.'), 0);
|
|
});
|
|
|
|
test('standalone "view" token DOES trigger UI gate', () => {
|
|
assert.strictEqual(hasUiGate('Implement the user profile view controller and associated screen.'), 0);
|
|
});
|
|
|
|
test('standalone "form" token DOES trigger UI gate', () => {
|
|
assert.strictEqual(hasUiGate('Build a sign-up form with client-side validation.'), 0);
|
|
});
|
|
|
|
test('"dashboard" DOES trigger UI gate', () => {
|
|
assert.strictEqual(hasUiGate('Build the analytics dashboard and navigation component.'), 0);
|
|
});
|
|
|
|
test('lowercase "ui" token DOES trigger UI gate (case-insensitive)', () => {
|
|
assert.strictEqual(hasUiGate('Redesign the ui for mobile responsiveness.'), 0);
|
|
});
|
|
|
|
test('"non-UI" hyphenated form DOES trigger UI gate (hyphen is a word boundary)', () => {
|
|
assert.strictEqual(hasUiGate('This is a non-UI backend service with no visual elements.'), 0);
|
|
});
|
|
|
|
test('standalone "screen" token DOES trigger UI gate', () => {
|
|
assert.strictEqual(hasUiGate('Implement the loading screen and splash animation.'), 0);
|
|
});
|
|
|
|
test('hyphenated "micro-frontend" DOES trigger gate (word boundary on hyphen)', () => {
|
|
assert.strictEqual(hasUiGate('Build the micro-frontend shell application.'), 0);
|
|
});
|
|
|
|
// ── CRLF / edge case tests ─────────────────────────────────────────────
|
|
|
|
test('CRLF line endings: non-UI text does not trigger gate', () => {
|
|
assert.strictEqual(hasUiGate('Deploy to the cloud platform\r\nand configure CI/CD.'), 1);
|
|
});
|
|
|
|
test('CRLF line endings: UI token on second line triggers gate', () => {
|
|
assert.strictEqual(hasUiGate('Backend setup complete.\r\nBuild the analytics dashboard.'), 0);
|
|
});
|
|
|
|
test('leading/trailing whitespace does not affect token detection', () => {
|
|
assert.strictEqual(hasUiGate(' UI refactor phase '), 0);
|
|
});
|
|
});
|
|
}
|
|
|
|
runBehavioralTests('ui-safety-gate.cjs');
|
|
|
|
// ── Install-dir resolution from a consuming project (#448) ────────────────────
|
|
|
|
describe('UI gate resolves the helper against RUNTIME_DIR, not the consuming repo (#448)', () => {
|
|
const REPO_ROOT = path.join(__dirname, '..');
|
|
|
|
// Mirrors the §5.6 / §3a.5 resolution. The structural guard above forces the
|
|
// workflows to keep using this RUNTIME_DIR-anchored form; this proves the
|
|
// candidate path is correct and the helper is actually found + executed when
|
|
// the CWD is a consuming project that has no bin/lib of its own.
|
|
const GATE_SNIPPET = [
|
|
'_GSD_RT="${RUNTIME_DIR:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}"',
|
|
'UI_GATE_JS=$(for _c in "$_GSD_RT/gsd-core/bin/lib/ui-safety-gate.cjs" "$_GSD_RT/bin/lib/ui-safety-gate.cjs" "$_GSD_RT/.claude/bin/lib/ui-safety-gate.cjs" "$HOME/.claude/gsd-core/bin/lib/ui-safety-gate.cjs" "$HOME/.claude/bin/lib/ui-safety-gate.cjs"; do [ -f "$_c" ] && { echo "$_c"; break; }; done)',
|
|
'if [ -n "$UI_GATE_JS" ]; then printf \'%s\' "$PHASE_SECTION" | node "$UI_GATE_JS" >/dev/null 2>&1; HAS_UI=$?; else HAS_UI=0; fi',
|
|
'echo "$HAS_UI"',
|
|
].join('\n');
|
|
|
|
function runGateFrom(consumingDir, phaseSection) {
|
|
return spawnSync('bash', ['-c', GATE_SNIPPET], {
|
|
cwd: consumingDir,
|
|
encoding: 'utf-8',
|
|
env: { ...process.env, RUNTIME_DIR: REPO_ROOT, PHASE_SECTION: phaseSection },
|
|
});
|
|
}
|
|
|
|
test('UI text is detected (HAS_UI=0) from a project without bin/lib', () => {
|
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-consuming-'));
|
|
try {
|
|
const res = runGateFrom(tmp, 'UI Refactor: migrate all screens');
|
|
assert.strictEqual(res.status, 0, `bash failed: ${res.stderr}`);
|
|
assert.strictEqual(res.stdout.trim(), '0',
|
|
'helper must be found via RUNTIME_DIR and report UI present — not silently no-op');
|
|
} finally {
|
|
cleanup(tmp);
|
|
}
|
|
});
|
|
|
|
test('non-UI text returns HAS_UI=1 via the RUNTIME_DIR-resolved helper', () => {
|
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-consuming-'));
|
|
try {
|
|
const res = runGateFrom(tmp, 'Requirements: backend REST API only');
|
|
assert.strictEqual(res.stdout.trim(), '1');
|
|
} finally {
|
|
cleanup(tmp);
|
|
}
|
|
});
|
|
|
|
test('UI gate found via gsd-core/bin/lib/ in installed layout (no root bin/lib/)', () => {
|
|
// Regression for #448: installed RUNTIME_DIR has gsd-core/bin/lib/ but NOT root bin/lib/.
|
|
// The probe must find the helper at the installed path, not silently no-op to HAS_UI=0.
|
|
const fakeRuntime = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-installed-rt-'));
|
|
const consumingProject = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-consuming-'));
|
|
try {
|
|
const installedLibDir = path.join(fakeRuntime, 'gsd-core', 'bin', 'lib');
|
|
fs.mkdirSync(installedLibDir, { recursive: true });
|
|
fs.copyFileSync(
|
|
path.join(REPO_ROOT, 'gsd-core', 'bin', 'lib', 'ui-safety-gate.cjs'),
|
|
path.join(installedLibDir, 'ui-safety-gate.cjs')
|
|
);
|
|
|
|
const res = spawnSync('bash', ['-c', GATE_SNIPPET], {
|
|
cwd: consumingProject,
|
|
encoding: 'utf-8',
|
|
env: { ...process.env, RUNTIME_DIR: fakeRuntime, PHASE_SECTION: 'Build the analytics dashboard' },
|
|
});
|
|
assert.strictEqual(res.status, 0, `bash failed: ${res.stderr}`);
|
|
assert.strictEqual(res.stdout.trim(), '0',
|
|
'helper must be found via gsd-core/bin/lib/ in installed layout and report UI present');
|
|
} finally {
|
|
cleanup(fakeRuntime);
|
|
cleanup(consumingProject);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ── checkUiPresence() return value API ───────────────────────────────────────
|
|
|
|
describe('checkUiPresence() return value API', () => {
|
|
test('returns { hasUI: true, tokens: [...] } when UI found', () => {
|
|
const result = checkUiPresence('Build the dashboard and UI form');
|
|
assert.strictEqual(result.hasUI, true);
|
|
assert.ok(Array.isArray(result.tokens), 'tokens must be an array');
|
|
assert.ok(result.tokens.length > 0, 'tokens must be non-empty when hasUI is true');
|
|
assert.ok(result.tokens.includes('dashboard') || result.tokens.includes('ui') || result.tokens.includes('form'));
|
|
});
|
|
|
|
test('returns { hasUI: false, tokens: [] } when no UI found', () => {
|
|
const result = checkUiPresence('Requirements: backend REST API only');
|
|
assert.strictEqual(result.hasUI, false);
|
|
assert.deepStrictEqual(result.tokens, []);
|
|
});
|
|
|
|
test('tokens are lowercased', () => {
|
|
const result = checkUiPresence('UI Refactor');
|
|
assert.ok(result.tokens.every(t => t === t.toLowerCase()), 'All tokens must be lowercase');
|
|
});
|
|
|
|
test('tokens are deduplicated', () => {
|
|
const result = checkUiPresence('UI redesign and ui cleanup');
|
|
const uiCount = result.tokens.filter(t => t === 'ui').length;
|
|
assert.strictEqual(uiCount, 1, 'Duplicate tokens must be deduplicated');
|
|
});
|
|
|
|
test('non-string input returns { hasUI: false, tokens: [] }', () => {
|
|
assert.deepStrictEqual(checkUiPresence(null), { hasUI: false, tokens: [] });
|
|
assert.deepStrictEqual(checkUiPresence(undefined), { hasUI: false, tokens: [] });
|
|
assert.deepStrictEqual(checkUiPresence(42), { hasUI: false, tokens: [] });
|
|
});
|
|
|
|
test('multiple distinct UI tokens on same line are ALL captured', () => {
|
|
// "form" and "view" both appear as standalone words on one line.
|
|
// Prior exec()-based impl only captured the first match per line.
|
|
const result = checkUiPresence('Build a sign-up form with a view controller');
|
|
assert.strictEqual(result.hasUI, true, 'hasUI must be true');
|
|
assert.ok(result.tokens.includes('form'), `Expected "form" in tokens, got: ${JSON.stringify(result.tokens)}`);
|
|
assert.ok(result.tokens.includes('view'), `Expected "view" in tokens, got: ${JSON.stringify(result.tokens)}`);
|
|
});
|
|
});
|