Files
msd-core/tests/windows-robustness.test.cjs
Tom Boucher 79002a00cb chore(#518): rename npm package + bin to @opengsd/gsd-core (#519)
* chore: rename npm package + bin to @opengsd/gsd-core (functional)

- package.json: name @opengsd/get-shit-done-redux → @opengsd/gsd-core,
  bin key get-shit-done-redux → gsd-core, repository/homepage/bugs URLs
- package-lock.json: regenerated (npm install --package-lock-only)
- tests/**, scripts/**, bin/**, .github/**, agents/**, commands/**,
  get-shit-done/bin/**, get-shit-done/workflows/**:
  applied the 4-rule replacement (scoped npm ref, GitHub repo path,
  bin/clone invocations) per #505 single-source refactor

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* docs: sweep live references to @opengsd/gsd-core

Update all live documentation (README.md + translations, docs/**,
CONTRIBUTING.md, VERSIONING.md, SECURITY.md, CONTEXT.md,
docs/CANARY.md) to reflect the renamed package and repository.

Rules applied:
- @opengsd/get-shit-done-redux → @opengsd/gsd-core (scoped npm name)
- open-gsd/get-shit-done-redux → open-gsd/gsd-core (GitHub repo)
- GSD-redux/get-shit-done-redux → open-gsd/gsd-core (stale badge org)
- bare bin/clone refs → gsd-core

CHANGELOG.md, docs/adr/**, docs/RELEASE-*.md, docs/research/**,
and .changeset/** are preserved byte-identical.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix: add negative lookbehind to slash-command regex in bug-2954 test

The extractSlashReferences regex matched /gsd-core inside npm package
URLs (@opengsd/gsd-core), producing a false /gsd:core command reference.
Adding a negative lookbehind (?<![a-z]) excludes matches preceded by a
letter, so only standalone /gsd-<cmd> and /gsd:<cmd> tokens are found.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* chore(#518): add changeset for package rename

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* test(#518): update package-identity expectations to the renamed coordinates

The rebase regenerated the seam to @opengsd/gsd-core (bin gsd-core, repo
open-gsd/gsd-core). The #498 seam tests assert deriveIdentity against the REAL
package.json, so their expected literals must follow the rename. The drift-lint
unit test is left as-is — its SEAM is a self-consistent fixture and its
stale-literal detection cases would shift if altered; the live-repo scan in it
already passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-30 17:25:02 -04:00

209 lines
7.2 KiB
JavaScript

// allow-test-rule: source-text-is-the-product
// Reads .md/.json/.yml product files whose deployed text IS what the
// runtime loads — testing text content tests the deployed contract.
/**
* Windows Robustness Tests
*
* Validates that workflow files, hooks, and core functions handle
* Windows/cross-platform edge cases correctly:
*
* 1. Workflow shell robustness: informational commands guarded with || true
* 2. Glob loops guarded with [ -e "$var" ] || continue
* 3. Hook stdin timeout patterns present in all JS hooks
* 4. findProjectRoot detects .git at same level as .planning/
* 5. @file: handoff present in all workflows that call init
*
* Regression tests for: https://github.com/open-gsd/gsd-core/issues/1343
*/
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const WORKFLOWS_DIR = path.join(__dirname, '..', 'get-shit-done', 'workflows');
const HOOKS_DIR = path.join(__dirname, '..', 'hooks');
/**
* Extract bash code blocks from a markdown file.
* Returns array of { lineNumber, code } objects.
*/
function extractBashBlocks(content) {
const blocks = [];
const lines = content.split('\n');
let inBlock = false;
let blockStart = 0;
let blockLines = [];
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (line.trim().startsWith('```bash')) {
inBlock = true;
blockStart = i + 1;
blockLines = [];
} else if (inBlock && line.trim() === '```') {
inBlock = false;
blocks.push({ lineNumber: blockStart, code: blockLines.join('\n') });
} else if (inBlock) {
blockLines.push(line);
}
}
return blocks;
}
/**
* Check if a line is an informational command that can return non-zero on
* "no results" and should be guarded with || true.
*
* Matches: ls, grep, find, cat on optional files — commands at end of line
* with 2>/dev/null that are NOT already guarded.
*/
function findUnguardedInfoCommands(code) {
const issues = [];
const lines = code.split('\n');
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
// Skip comments, empty lines, and lines that are already guarded
if (!line || line.startsWith('#')) continue;
if (line.includes('|| true') || line.includes('|| echo') || line.includes('|| continue')) continue;
// Lines ending with 2>/dev/null that use informational commands
if (line.endsWith('2>/dev/null')) {
// Check if this is an informational command (ls, grep, find, cat on optional files)
if (/^(ls|grep|find|cat)\s/.test(line) ||
/\|\s*(ls|grep|find)\s/.test(line)) {
issues.push({ line: i + 1, content: line });
}
}
}
return issues;
}
// ─── Workflow Shell Robustness ────────────────────────────────────────────────
describe('workflow shell robustness', () => {
const workflowFiles = fs.readdirSync(WORKFLOWS_DIR)
.filter(f => f.endsWith('.md'));
// Key workflow files that must have || true guards on informational commands
const criticalWorkflows = [
'resume-project.md',
'progress.md',
'transition.md',
'verify-phase.md',
'verify-work.md',
'discuss-phase.md',
'plan-phase.md',
'execute-plan.md',
'cleanup.md',
];
for (const wf of criticalWorkflows) {
test(`${wf}: informational commands are guarded with || true`, () => {
const filePath = path.join(WORKFLOWS_DIR, wf);
if (!fs.existsSync(filePath)) return; // skip if workflow doesn't exist
const content = fs.readFileSync(filePath, 'utf-8');
const blocks = extractBashBlocks(content);
const allIssues = [];
for (const block of blocks) {
const issues = findUnguardedInfoCommands(block.code);
for (const issue of issues) {
allIssues.push(`Line ~${block.lineNumber + issue.line}: ${issue.content}`);
}
}
assert.strictEqual(
allIssues.length, 0,
`${wf} has unguarded informational commands that may fail on Windows:\n ${allIssues.join('\n ')}`
);
});
}
test('glob loops in resume-project.md have existence guard', () => {
const content = fs.readFileSync(path.join(WORKFLOWS_DIR, 'resume-project.md'), 'utf-8');
const blocks = extractBashBlocks(content);
for (const block of blocks) {
// Look for `for ... in .planning/` glob loops
const forLoopMatch = block.code.match(/for\s+\w+\s+in\s+\.planning\/[^;]+;\s*do/);
if (forLoopMatch) {
// The loop body should contain [ -e "$var" ] || continue
assert.ok(
block.code.includes('|| continue'),
`Glob loop at line ~${block.lineNumber} missing existence guard ([ -e "$var" ] || continue):\n${forLoopMatch[0]}`
);
}
}
});
});
// ─── Hook Stdin Timeout ──────────────────────────────────────────────────────
describe('hook stdin timeout patterns', () => {
test('all JS hooks have stdin timeout guard', () => {
if (!fs.existsSync(HOOKS_DIR)) return;
const hookFiles = fs.readdirSync(HOOKS_DIR)
.filter(f => f.endsWith('.js'));
for (const hook of hookFiles) {
const content = fs.readFileSync(path.join(HOOKS_DIR, hook), 'utf-8');
// Hooks that read stdin must have a timeout
if (content.includes('process.stdin')) {
assert.ok(
content.includes('setTimeout') || content.includes('stdinTimeout'),
`${hook} reads stdin but lacks a timeout guard — will hang on Windows if stdin pipe doesn't close`
);
}
}
});
test('no JS hooks use synchronous readFileSync on /dev/stdin', () => {
if (!fs.existsSync(HOOKS_DIR)) return;
const hookFiles = fs.readdirSync(HOOKS_DIR)
.filter(f => f.endsWith('.js'));
for (const hook of hookFiles) {
const content = fs.readFileSync(path.join(HOOKS_DIR, hook), 'utf-8');
assert.ok(
!content.includes("readFileSync('/dev/stdin')") &&
!content.includes('readFileSync("/dev/stdin")'),
`${hook} uses readFileSync('/dev/stdin') which hangs on Windows — use async process.stdin with timeout instead`
);
}
});
});
// ─── @file: Handoff ─────────────────────────────────────────────────────────
describe('@file: handoff in workflows', () => {
test('all workflows calling gsd-tools init have @file: handler', () => {
const workflowFiles = fs.readdirSync(WORKFLOWS_DIR)
.filter(f => f.endsWith('.md'));
const missing = [];
for (const wf of workflowFiles) {
const content = fs.readFileSync(path.join(WORKFLOWS_DIR, wf), 'utf-8');
// Check if this workflow calls gsd-tools.cjs init
if (/INIT=\$\(node.*gsd-tools.*\binit\b/.test(content)) {
// Must have @file: handler
if (!content.includes('@file:')) {
missing.push(wf);
}
}
}
assert.strictEqual(
missing.length, 0,
`Workflows calling gsd-tools init without @file: handler (large output will be truncated):\n ${missing.join('\n ')}`
);
});
});