Files
msd-core/tests/autonomous-ui-steps.test.cjs
Tom Boucher e690f1bc90 fix(3718): shell-free Node.js UI safety gate — fixes PowerShell silent-fail (#3718)
* fix(workflows): add word-boundary anchoring to UI safety gate grep

Replace unanchored grep -iE "UI |..." alternation with POSIX ERE
word-boundary-anchored form:

  LC_ALL=C grep -iE "(^|[^[:alnum:]])(UI|...)([^[:alnum:]]|$)"

Unanchored form matched 'ui' inside 'requirements', 'view' inside
'overview' and 'review', 'form' inside 'performance'/'platform'/
'transform' — producing HAS_UI=0 on 100% of standard roadmap phases
(every phase contains a **Requirements**: field).

Fix applied to both plan-phase.md:625 and autonomous.md:284.
LC_ALL=C added for POSIX locale portability on both BSD and GNU grep.

Closes #3706

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(workflows): add regression tests for UI safety gate false-positives (#3706)

- bug-3706-ui-safety-gate-false-positives.test.cjs: 36-test suite covering
  both plan-phase.md and autonomous.md gate behavior; verifies that
  Requirements/overview/performance/platform/transform/review/build/screening
  do NOT trigger the gate, while standalone UI/view/form/screen/dashboard/
  component/lowercase-ui/hyphenated-non-UI DO trigger it.

- autonomous-ui-steps.test.cjs: update stale assertion that checked for the
  old broken grep pattern; now asserts the word-boundary-anchored form.

Test strategy: extract the POSIX ERE pattern from the workflow file and
simulate grep match semantics in JS (no shell exec, no source-grep).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* chore(changeset): add Fixed fragment for PR #3718 (UI safety gate false-positives)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(workflows): document compound-token boundary contract; add comment to gate

Addresses adversarial review finding: word-boundary anchoring intentionally
does not match tokens embedded in compound alphanumeric words (e.g.
"microfrontend", "dashboardWidget", "uiSpec"). This is correct behavior —
gsd-roadmapper generates natural English prose, not camelCase compounds.
Hyphenated forms ("micro-frontend") and spaced forms are caught by the
anchored pattern (hyphen is [^[:alnum:]]).

Add inline comment in both workflow files explaining the pattern intent,
the false-positive prevention, and the compound-word contract.

Add 4 tests (2 per workflow) documenting the compound-word contract:
- "microfrontend" (compound) must NOT trigger gate (documented behavior)
- "micro-frontend" (hyphenated) MUST trigger gate (correct true-positive)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(3718): replace shell grep gate with shell-free Node.js helper

Moves UI safety gate logic from `LC_ALL=C grep -iE` (silently broken on
Windows PowerShell — locale env-var prefix not recognised by pwsh) to
`bin/lib/ui-safety-gate.cjs` (Node.js, reads via stdin to avoid ARG_MAX).

Path is anchored via `git rev-parse --show-toplevel` (GSD_REPO_ROOT) to
avoid CWD-sensitive failure when Claude Code executes from a subdirectory.

Word-boundary regex is identical to the original POSIX ERE pattern:
  (^|[^a-zA-Z0-9])(TOKEN)([^a-zA-Z0-9]|$)
Exit codes mirror grep: 0 = UI found, 1 = not found.

Tests: 51/51 pass — includes spawnSync shell:false + stdin cross-shell
portability tests and ARG_MAX large-input test.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(3706): address pr-review-toolkit + codex review findings

- Multi-token-per-line: use matchAll to capture all UI tokens
- Add test for multiple distinct tokens on same line
- Clarify ASCII vs POSIX [:alnum:] in word-boundary comment
- Correct misleading "path anchored" comment in plan-phase/autonomous workflows
- Remove UI_GATE_PATTERN from module.exports (internal implementation detail)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(state): restore ACQUIRE_LOCK_RETRY_ERRNOS in acquireStateLock (#3718)

Commit 473c279c removed ACQUIRE_LOCK_RETRY_ERRNOS and replaced the
correct `throw err` path with `return lockPath`, which silently
"succeeds" on any non-EEXIST error — allowing two concurrent processes
to both hold the lock simultaneously and causing lost updates.

This restores the set of recoverable transient errno codes (Docker
overlay-fs EINVAL/EIO/ENOENT, NFS ESTALE, POSIX EAGAIN/EINTR, Windows
EPERM/EBUSY) that should retry, and restores `throw err` for genuinely
fatal codes.  Equivalent to commit 47983914 on main.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 23:08:56 -04:00

150 lines
5.3 KiB
JavaScript

/**
* Tests that autonomous.md includes ui-phase and ui-review steps for frontend phases.
*
* Issue #1375: autonomous workflow skips ui-phase and ui-review for frontend phases.
* The per-phase execution loop should be: discuss -> ui-phase -> plan -> execute -> verify -> ui-review
* for phases with frontend indicators.
*/
const { describe, it, test, beforeEach } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const WORKFLOW_PATH = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'autonomous.md');
describe('autonomous workflow ui-phase and ui-review integration (#1375)', () => {
let content;
beforeEach(() => {
assert.ok(fs.existsSync(WORKFLOW_PATH), 'workflows/autonomous.md should exist');
content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
});
describe('step 3a.5 — UI design contract before planning', () => {
test('autonomous.md contains a UI design contract step between discuss and plan', () => {
assert.ok(
content.includes('3a.5'),
'should have step 3a.5 for UI design contract'
);
});
test('UI design contract step detects frontend indicators via shell-free Node gate (#3718)', () => {
// After #3718 fix: the gate is implemented in bin/lib/ui-safety-gate.cjs (Node.js)
// piped from stdin, path anchored via git rev-parse. This avoids silent failure
// on Windows PowerShell and ARG_MAX limits for large phase text.
assert.ok(
content.includes('ui-safety-gate.cjs'),
'should invoke shell-free Node gate for cross-platform portability (#3718)'
);
assert.ok(
content.includes('GSD_REPO_ROOT'),
'should anchor gate path to GSD_REPO_ROOT to avoid CWD-sensitive failure'
);
});
test('UI design contract step checks for existing UI-SPEC.md', () => {
assert.ok(
content.includes('UI-SPEC.md'),
'should check for existing UI-SPEC.md'
);
});
test('UI design contract step respects workflow.ui_phase config toggle', () => {
assert.ok(
content.includes('workflow.ui_phase'),
'should respect workflow.ui_phase config toggle'
);
});
test('UI design contract step invokes gsd:ui-phase skill', () => {
assert.ok(
content.includes('skill="gsd-ui-phase"'),
'should invoke gsd-ui-phase via Skill()'
);
});
test('UI design contract step appears before plan step (3b)', () => {
const uiPhasePos = content.indexOf('3a.5');
const planPos = content.indexOf('**3b. Plan**');
assert.ok(
uiPhasePos < planPos,
'step 3a.5 (UI design contract) should appear before step 3b (plan)'
);
});
});
describe('step 3d.5 — UI review after execution', () => {
test('autonomous.md contains a UI review step after execution', () => {
assert.ok(
content.includes('3d.5'),
'should have step 3d.5 for UI review'
);
});
test('UI review step checks for UI-SPEC existence before running', () => {
// The UI review should only run if a UI-SPEC was created/exists
const reviewSection = content.slice(content.indexOf('3d.5'));
assert.ok(
reviewSection.includes('UI_SPEC_FILE'),
'UI review step should check for UI-SPEC file existence'
);
});
test('UI review step respects workflow.ui_review config toggle', () => {
assert.ok(
content.includes('workflow.ui_review'),
'should respect workflow.ui_review config toggle'
);
});
test('UI review step invokes gsd:ui-review skill', () => {
assert.ok(
content.includes('skill="gsd-ui-review"'),
'should invoke gsd-ui-review via Skill()'
);
});
test('UI review is advisory (non-blocking)', () => {
const reviewSection = content.slice(content.indexOf('3d.5'));
assert.ok(
reviewSection.includes('advisory') || reviewSection.includes('non-blocking') || reviewSection.includes('regardless of score'),
'UI review should be advisory and not block phase progression'
);
});
test('UI review step appears after execution routing (3d)', () => {
const executeRouting = content.indexOf('**3d. Post-Execution Routing**');
const uiReviewPos = content.indexOf('3d.5');
assert.ok(
uiReviewPos > executeRouting,
'step 3d.5 (UI review) should appear after step 3d (post-execution routing)'
);
});
});
describe('success criteria updated', () => {
test('success criteria includes UI-aware flow', () => {
assert.ok(
content.includes('ui-phase') && content.includes('ui-review'),
'success criteria should reference ui-phase and ui-review'
);
});
test('success criteria mentions frontend phases get UI-SPEC before planning', () => {
assert.ok(
content.includes('Frontend phases') || content.includes('frontend phases'),
'success criteria should mention frontend phases'
);
});
test('success criteria notes UI review is advisory', () => {
const criteriaSection = content.slice(content.indexOf('<success_criteria>'));
assert.ok(
criteriaSection.includes('advisory') || criteriaSection.includes('non-blocking'),
'success criteria should note UI review is advisory/non-blocking'
);
});
});
});