Files
get-shit-done/tests/pick-flag.test.cjs
Tom Boucher 2703422be8 refactor(tests): standardize to node:assert/strict and t.after() per CONTRIBUTING.md (#1675)
* refactor(tests): standardize to node:assert/strict and t.after() per CONTRIBUTING.md

- Replace require('node:assert') with require('node:assert/strict') across
  all 73 test files to enforce strict equality (no type coercion)
- Replace try/finally cleanup blocks with t.after() hooks in core.test.cjs
  and hooks-opt-in.test.cjs per the test lifecycle standards
- Utility functions in codex-config and security-scan retain try/finally
  as that is appropriate for per-function resource guards, not lifecycle hooks

Closes #1674

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

* perf(tests): add --test-concurrency=4 to test runner for parallel file execution

Node.js --test-concurrency controls how many test files run as parallel child
processes. Set to 4 by default, configurable via TEST_CONCURRENCY env var.
Fixes tests at a known level rather than inheriting os.availableParallelism()
which varies across CI environments.

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

* fix(security): allowlist verify.test.cjs in prompt-injection scanner

tests/verify.test.cjs uses <human>...</human> as GSD phase task-type
XML (meaning "a human should verify this step"), which matches the
scanner's fake-message-boundary pattern for LLM APIs. This is a
false positive — add it to the allowlist alongside the other test files
that legitimately contain injection-adjacent patterns.

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

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-04 14:29:03 -04:00

59 lines
2.4 KiB
JavaScript

/**
* GSD Tools Tests - --pick flag
*
* Regression tests for the --pick CLI flag that extracts a single field
* from JSON output, replacing the need for jq as an external dependency.
*/
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const { runGsdTools } = require('./helpers.cjs');
// ─── --pick flag ─────────────────────────────────────────────────────────────
describe('--pick flag', () => {
test('extracts a top-level field from JSON output', () => {
const result = runGsdTools('generate-slug "hello world" --pick slug');
assert.strictEqual(result.success, true);
assert.strictEqual(result.output, 'hello-world');
});
test('extracts a top-level field using array args', () => {
const result = runGsdTools(['generate-slug', 'hello world', '--pick', 'slug']);
assert.strictEqual(result.success, true);
assert.strictEqual(result.output, 'hello-world');
});
test('returns empty string for missing field', () => {
const result = runGsdTools('generate-slug "test" --pick nonexistent');
assert.strictEqual(result.success, true);
assert.strictEqual(result.output, '');
});
test('errors when --pick has no value', () => {
const result = runGsdTools('generate-slug "test" --pick');
assert.strictEqual(result.success, false);
assert.match(result.error, /Missing value for --pick/);
});
test('errors when --pick value starts with --', () => {
const result = runGsdTools(['generate-slug', 'test', '--pick', '--raw']);
assert.strictEqual(result.success, false);
assert.match(result.error, /Missing value for --pick/);
});
test('does not collide with frontmatter --field flag', () => {
// frontmatter subcommand uses --field internally; --pick should not interfere
const result = runGsdTools('generate-slug "test-value" --pick slug');
assert.strictEqual(result.success, true);
assert.strictEqual(result.output, 'test-value');
});
test('works with current-timestamp command', () => {
const result = runGsdTools('current-timestamp --pick timestamp');
assert.strictEqual(result.success, true);
assert.ok(result.output.length > 0, 'timestamp should not be empty');
assert.match(result.output, /^\d{4}-\d{2}-\d{2}T/);
});
});