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>
This commit is contained in:
Tom Boucher
2026-04-04 14:29:03 -04:00
committed by GitHub
parent 9bf9fc295d
commit 2703422be8
75 changed files with 112 additions and 119 deletions

View File

@@ -6,7 +6,7 @@
*/
const { test, describe, beforeEach, afterEach } = require('node:test');
const assert = require('node:assert');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const os = require('os');
@@ -139,22 +139,19 @@ describe('loadConfig', () => {
assert.strictEqual(config.commit_docs, false);
});
test('warns on unknown config keys to stderr (#1535)', () => {
test('warns on unknown config keys to stderr (#1535)', (t) => {
writeConfig({ model_profile: 'quality', active_project: 'my-project', custom_flag: true });
const origWrite = process.stderr.write;
let stderrOutput = '';
process.stderr.write = (chunk) => { stderrOutput += chunk; };
try {
const config = loadConfig(tmpDir);
// Known key still loads correctly
assert.strictEqual(config.model_profile, 'quality');
// Warning emitted for unknown keys
assert.ok(stderrOutput.includes('active_project'), 'should warn about active_project');
assert.ok(stderrOutput.includes('custom_flag'), 'should warn about custom_flag');
assert.ok(stderrOutput.includes('ignored'), 'should mention keys will be ignored');
} finally {
process.stderr.write = origWrite;
}
t.after(() => { process.stderr.write = origWrite; });
const config = loadConfig(tmpDir);
// Known key still loads correctly
assert.strictEqual(config.model_profile, 'quality');
// Warning emitted for unknown keys
assert.ok(stderrOutput.includes('active_project'), 'should warn about active_project');
assert.ok(stderrOutput.includes('custom_flag'), 'should warn about custom_flag');
assert.ok(stderrOutput.includes('ignored'), 'should mention keys will be ignored');
});
test('known config keys are derived from VALID_CONFIG_KEYS (not hardcoded)', () => {
@@ -181,17 +178,14 @@ describe('loadConfig', () => {
}
});
test('does not warn when all config keys are known', () => {
test('does not warn when all config keys are known', (t) => {
writeConfig({ model_profile: 'balanced', workflow: { research: false }, git: { branching_strategy: 'per-phase' } });
const origWrite = process.stderr.write;
let stderrOutput = '';
process.stderr.write = (chunk) => { stderrOutput += chunk; };
try {
loadConfig(tmpDir);
assert.strictEqual(stderrOutput, '', 'should not emit any warnings for valid config');
} finally {
process.stderr.write = origWrite;
}
t.after(() => { process.stderr.write = origWrite; });
loadConfig(tmpDir);
assert.strictEqual(stderrOutput, '', 'should not emit any warnings for valid config');
});
});