* fix: recurse test discovery so subdir test suites actually run
scripts/run-tests.cjs discovered tests with a flat readdirSync(testDir),
silently excluding tests/observability/ (4 files), tests/dispatch/ (1) and
tests/installer-migrations/ (1) — 94 passing tests — from `npm test` and all
CI lanes. Walk the tree recursively (relative subpaths preserved), classify
suites by basename, and add a fail-on-zero-executed guard for suite/default
runs (escape hatch GSD_ALLOW_EMPTY_SUITE=1) while preserving the empty
--files/--files-from path the CI inert lane relies on.
Unit suite 735 -> 741 files; surfaces ADR-227's observability/dispatch seam.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* test: retire 5 verified-worthless tests
Adversarial verification confirmed these 5 prove nothing — their coverage is
provided more strictly elsewhere:
- enh-2790 'has a name: field' spot-checks (command-contract enforces /^gsd[:-]/)
- command-routing-hub duplicate construct + duplicate ERROR_KINDS assertions
- no-cjs-sdk-handsync-tooling (guarded files that never existed on main; bug-190
covers the real retired SDK artifacts)
- runtime-artifact-layout cline edge case (subsumed by the explicit-global test
and bug-782-cline-skills-emission)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* test: add ADR-218 release version-validation coverage
ADR-218 (reject leading-zero versions like 1.01.0; npm duplicate pre-check) had
zero tests — the logic lived only in release.yml bash. Add a test that extracts
the actual rejection regexes from the workflow and exercises them against a
boundary table (leading-zero/malformed rejected, valid accepted) plus structural
wiring assertions. Goes red if the regex is reverted to [0-9]+.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* test: redesign weak tests into behavioral, deterministic assertions
Per the ADR test audit, rewrite 27 weak test files (test-only, no source
changes) so each can go red for the defect it guards:
- kill pass-always assert.ok(true) placeholders (research-cli, worktree-baseref,
bug-260 security guard, eslint-rules x24, clusters '|| true')
- replace source-text grep with behavioral calls (install Kilo, sh-hook-paths,
plan-review-convergence) and add a repo-layout governance test
- de-flake real-clock/Math.random coupling (phase last_updated, bug-3707 mtime,
context-utilization property, feat-3594)
- fix independence/shared-state violations (bug-492 singleton, issue-844 tmpRoot,
core reapStaleTempFiles, active-workstream TTY, feat-488 GSD_HOME)
- strengthen property/shape-only tests (research-provider/store classification +
collision) and unconditional plugin.json schema validation (issue-766)
Verified: all 28 files run together 1220 pass / 0 fail / 1 skip.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* chore: add no-tautological-assert lint rule, error in test suite
New custom ESLint rule (eslint-rules/no-tautological-assert.cjs) bans asserts
that can never fail: assert(true)/assert.ok(<always-truthy literal>),
'cond || true' inside an assert, and equality asserts comparing two identical
literals. Wired as error on tests/**; full sweep confirmed zero existing
violations so the suite stays green. Prevents the placeholder-assert regressions
the audit redesigns just removed. RuleTester coverage added (6 valid, 8 invalid).
Note: no-only-tests was already enforced via eslint-plugin-no-only-tests, so no
duplicate rule was added.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* chore: gate new allow-test-rule exemptions to require an issue ref
ADR-456 requires any allow-test-rule exemption added after the ADR to carry a
tracking issue number, but nothing enforced it. New ratchet gate
(scripts/lint-allow-test-rule-refs.cjs, wired into lint:ci) fails when a NEW
allow-test-rule comment lacks a #NNN/URL reference; the 323 existing untracked
exemptions are grandfathered in an allowlist that ratchets down as they gain
refs. Red-green verified (novel untracked offender fails; compliant passes).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* docs: add ADR test-audit evidence report (#1192)
Full risk-first qa-test-architect audit of the ADR portfolio (37 ADRs + 4
platform lenses, adversarial verification of retire verdicts) that drove the
P0 discovery fix, ADR-218 coverage, 5 retires, 27 redesigns, and the two new
lint gates. Filed as point-in-time evidence under docs/issueevidence/, named
for tracking issue #1192.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* test: replace pre-existing raw NUL byte with escape in feat-3594 fixture
feat-3594's null-byte parser fixture contained a literal NUL byte (pre-existing
on next at b10e5681 — confirmed: base blob has 1 NUL, this fix has 0), which
made git treat the file as binary and would break grep/editors. Switch to the
\x00 escape; the runtime string value (a real NUL in the parser input) is
unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* test: address adversarial-review findings
Codex adversarial pass over the branch:
- capability-registry drift test no longer mutates the committed generated
capability-registry.cjs in place (concurrency hazard) — uses in-memory
checkPipeline comparison instead.
- allow-test-rule ratchet now detects exemptions in ALL comment forms (block
/* */ too, matching no-source-grep) so a block comment can't bypass it;
one newly-surfaced pre-existing offender grandfathered (323->324).
- install.test Kilo case asserts on what install(false,'kilo') actually writes
rather than manually calling configureKiloPermissions (masked the call site).
- issue-766 drops the undeclared transitive ajv dep for explicit structural
assertions from the schema fixture.
- adr-218 test notes the hotfix leading-zero gap is tracked in #1186.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix: address code-review findings (subdir discovery, rule + test gaps)
xhigh code review surfaced 15 confirmed issues, all fixed:
- run-tests.cjs --files now resolves subdir tests by bare basename + handles
Windows backslash paths (ambiguous basenames error clearly).
- affected-tests-lib.cjs listTestFiles made recursive — the targeted CI lane was
silently dropping changed subdir tests (same false-green class the audit fixed).
- no-tautological-assert now catches 'true || cond' and empty []/{} equality.
- verify-test-quality: restore provenance-classification coverage, tighten the
writeFile circular-detection check, guard the module-level file read.
- sh-hook-paths: cover the global-install .sh delegation branch (#2045 guard).
- active-workstream null-guard runs deterministically (no longer skipped on TTY).
- adr-218 structural guards tightened (major/minor leading-zero; needs: membership).
- repo-layout AGENTS.md guard no longer false-alarms on equivalent refactors.
- cross-ai ordering guard fails red when the step is missing.
- issue-766 parses required fields from the schema fixture (auto-enforced).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* test: stub USERPROFILE alongside HOME in feat-488 (Windows parity)
The feat-488 redesign stubbed process.env.HOME but not USERPROFILE; os.homedir()
resolves from USERPROFILE on Windows, so the home stub was not hermetic there —
caught by windows-test-parity-guard (stubsHomeNoUserProfile). Save/set/restore
USERPROFILE symmetrically with HOME (delete-if-originally-undefined).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* chore: reconcile allow-test-rule allowlist after rebase onto next
Rebasing onto current next pulled in merged PR #1170, which added
inventory-headings-countfree.test.cjs (a baseline allow-test-rule exemption) and
deleted inventory-counts.test.cjs. Grandfather the former and prune the latter so
the ratchet matches the merged tree. No new debt from this PR.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
277 lines
11 KiB
JavaScript
277 lines
11 KiB
JavaScript
// Tests for gsd-tools effort sync command (#488)
|
|
// Verifies that effort frontmatter in installed agent files can be re-synced
|
|
// when effort config changes after initial install.
|
|
// allow-test-rule: structural-regression-guard — readFileSync asserts on installed agent .md files (the product under mutation) to verify dry-run safety and apply correctness; stderr.includes guards the CLI argument-rejection contract.
|
|
|
|
'use strict';
|
|
|
|
process.env.GSD_TEST_MODE = '1';
|
|
|
|
const { describe, test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const os = require('node:os');
|
|
const { spawnSync } = require('node:child_process');
|
|
|
|
const { cleanup } = require('./helpers.cjs');
|
|
|
|
const GSD_TOOLS = path.resolve(__dirname, '../gsd-core/bin/gsd-tools.cjs');
|
|
|
|
function runCli(args, env = {}) {
|
|
const result = spawnSync(process.execPath, [GSD_TOOLS, ...args], {
|
|
encoding: 'utf8',
|
|
env: { ...process.env, GSD_TEST_MODE: '1', ...env },
|
|
});
|
|
return result;
|
|
}
|
|
|
|
function makeTmpDir(prefix) {
|
|
return fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
}
|
|
|
|
// output() in core.cjs uses fs.writeSync(1, data) — intercept fd=1 writes.
|
|
// Pass raw=false so output() emits JSON (raw=true emits the plain rawValue string).
|
|
function captureOutput(fn) {
|
|
const origWriteSync = fs.writeSync;
|
|
let captured = '';
|
|
fs.writeSync = (fd, data) => {
|
|
if (fd === 1) captured += data;
|
|
else origWriteSync(fd, data);
|
|
};
|
|
try {
|
|
fn();
|
|
} finally {
|
|
fs.writeSync = origWriteSync;
|
|
}
|
|
return JSON.parse(captured);
|
|
}
|
|
|
|
function makeAgentsDir(tmpDir) {
|
|
const agentsDir = path.join(tmpDir, 'agents');
|
|
fs.mkdirSync(agentsDir, { recursive: true });
|
|
return agentsDir;
|
|
}
|
|
|
|
function writePlanningConfig(tmpDir, effortConfig) {
|
|
const planningDir = path.join(tmpDir, '.planning');
|
|
fs.mkdirSync(planningDir, { recursive: true });
|
|
fs.writeFileSync(path.join(planningDir, 'config.json'), JSON.stringify({ effort: effortConfig }));
|
|
}
|
|
|
|
const AGENT_WITH_EFFORT = `---
|
|
name: gsd-planner
|
|
description: Plans phases for GSD milestones
|
|
effort: medium
|
|
---
|
|
Body of the agent.
|
|
`;
|
|
|
|
const AGENT_WITHOUT_EFFORT = `---
|
|
name: gsd-executor
|
|
description: Executes GSD phase plans
|
|
---
|
|
Body of the agent.
|
|
`;
|
|
|
|
describe('feat-488: effort sync command', () => {
|
|
test('dry-run mode reports pending changes without writing files', () => {
|
|
const tmpDir = makeTmpDir('effort-sync-dry-');
|
|
const agentsDir = makeAgentsDir(tmpDir);
|
|
const agentPath = path.join(agentsDir, 'gsd-planner.md');
|
|
fs.writeFileSync(agentPath, AGENT_WITH_EFFORT);
|
|
writePlanningConfig(tmpDir, { default: 'high', agent_overrides: { 'gsd-planner': 'xhigh' } });
|
|
|
|
const { cmdEffortSync } = require('../gsd-core/bin/lib/commands.cjs');
|
|
const result = captureOutput(() =>
|
|
cmdEffortSync(tmpDir, false, { dryRun: true, configDir: tmpDir, runtime: 'claude' })
|
|
);
|
|
|
|
assert.equal(result.dry_run, true);
|
|
assert.equal(result.synced, 1, 'should report 1 pending change');
|
|
assert.equal(result.changes[0].agent, 'gsd-planner');
|
|
assert.equal(result.changes[0].from, 'medium');
|
|
assert.equal(result.changes[0].to, 'xhigh');
|
|
|
|
// dry-run must not modify the file
|
|
assert.ok(fs.readFileSync(agentPath, 'utf8').includes('effort: medium'), 'dry-run must not write file');
|
|
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('--apply mode rewrites effort: frontmatter to new config value', () => {
|
|
const tmpDir = makeTmpDir('effort-sync-apply-');
|
|
const agentsDir = makeAgentsDir(tmpDir);
|
|
const agentPath = path.join(agentsDir, 'gsd-planner.md');
|
|
fs.writeFileSync(agentPath, AGENT_WITH_EFFORT);
|
|
writePlanningConfig(tmpDir, { default: 'low', agent_overrides: { 'gsd-planner': 'xhigh' } });
|
|
|
|
const { cmdEffortSync } = require('../gsd-core/bin/lib/commands.cjs');
|
|
const result = captureOutput(() =>
|
|
cmdEffortSync(tmpDir, false, { dryRun: false, configDir: tmpDir, runtime: 'claude' })
|
|
);
|
|
|
|
assert.equal(result.dry_run, false);
|
|
assert.equal(result.synced, 1);
|
|
|
|
const updated = fs.readFileSync(agentPath, 'utf8');
|
|
assert.ok(updated.includes('effort: xhigh'), 'file must be updated to xhigh');
|
|
assert.ok(!updated.includes('effort: medium'), 'old effort value must be gone');
|
|
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('skips agents where effort: already matches config', () => {
|
|
const tmpDir = makeTmpDir('effort-sync-noop-');
|
|
const agentsDir = makeAgentsDir(tmpDir);
|
|
const agentPath = path.join(agentsDir, 'gsd-planner.md');
|
|
// Already has the correct value
|
|
fs.writeFileSync(agentPath, AGENT_WITH_EFFORT.replace('effort: medium', 'effort: xhigh'));
|
|
writePlanningConfig(tmpDir, { agent_overrides: { 'gsd-planner': 'xhigh' } });
|
|
|
|
const { cmdEffortSync } = require('../gsd-core/bin/lib/commands.cjs');
|
|
const result = captureOutput(() =>
|
|
cmdEffortSync(tmpDir, false, { dryRun: false, configDir: tmpDir, runtime: 'claude' })
|
|
);
|
|
|
|
assert.equal(result.synced, 0, 'nothing to sync when already matching');
|
|
assert.equal(result.skipped, 1);
|
|
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('injects effort: into agent files that lack the frontmatter key', () => {
|
|
const tmpDir = makeTmpDir('effort-sync-inject-');
|
|
const agentsDir = makeAgentsDir(tmpDir);
|
|
const agentPath = path.join(agentsDir, 'gsd-executor.md');
|
|
fs.writeFileSync(agentPath, AGENT_WITHOUT_EFFORT);
|
|
writePlanningConfig(tmpDir, { default: 'max' });
|
|
|
|
const { cmdEffortSync } = require('../gsd-core/bin/lib/commands.cjs');
|
|
const result = captureOutput(() =>
|
|
cmdEffortSync(tmpDir, false, { dryRun: false, configDir: tmpDir, runtime: 'claude' })
|
|
);
|
|
|
|
assert.equal(result.synced, 1, 'should inject effort into agent missing the key');
|
|
assert.equal(result.changes[0].from, null);
|
|
assert.equal(result.changes[0].to, 'max');
|
|
assert.ok(fs.readFileSync(agentPath, 'utf8').includes('effort: max'), 'effort must be injected');
|
|
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('non-claude runtime exits cleanly with informative reason field', () => {
|
|
const tmpDir = makeTmpDir('effort-sync-gemini-');
|
|
|
|
const { cmdEffortSync } = require('../gsd-core/bin/lib/commands.cjs');
|
|
const result = captureOutput(() =>
|
|
cmdEffortSync(tmpDir, false, { dryRun: true, runtime: 'gemini' })
|
|
);
|
|
|
|
assert.ok(result.reason, 'should include a reason message for unsupported runtime');
|
|
assert.equal(result.synced, 0);
|
|
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('home-default effort config gap: applies home-level effort when project config has no effort section', () => {
|
|
// The key #488 scenario: user changed ~/.gsd/defaults.json effort settings
|
|
// after install, but the project .planning/config.json has no effort section.
|
|
// cmdEffortSync must pick up the home config (via readGsdEffectiveEffortConfig),
|
|
// not fall back to 'high' (which loadConfig would return).
|
|
//
|
|
// readGsdEffectiveEffortConfig calls os.homedir() directly, and os.homedir()
|
|
// is live (respects process.env.HOME). We redirect HOME to an isolated
|
|
// tmpHome so the test is hermetic and can assert the real outcome.
|
|
const tmpHome = makeTmpDir('effort-sync-homecfg-');
|
|
const tmpDir = makeTmpDir('effort-sync-project-');
|
|
const agentsDir = makeAgentsDir(tmpDir);
|
|
const agentPath = path.join(agentsDir, 'gsd-planner.md');
|
|
fs.writeFileSync(agentPath, AGENT_WITH_EFFORT); // current: effort: medium
|
|
|
|
// Project has .planning/config.json with NO effort section
|
|
const planningDir = path.join(tmpDir, '.planning');
|
|
fs.mkdirSync(planningDir, { recursive: true });
|
|
fs.writeFileSync(path.join(planningDir, 'config.json'), JSON.stringify({ model_profile: 'balanced' }));
|
|
|
|
// Home defaults set effort.default = low
|
|
const gsdDir = path.join(tmpHome, '.gsd');
|
|
fs.mkdirSync(gsdDir, { recursive: true });
|
|
fs.writeFileSync(path.join(gsdDir, 'defaults.json'), JSON.stringify({ effort: { default: 'low' } }));
|
|
|
|
// Isolate HOME (and USERPROFILE for Windows parity) so
|
|
// readGsdEffectiveEffortConfig reads our fixture, not the
|
|
// developer's real ~/.gsd/defaults.json.
|
|
const origHome = process.env.HOME;
|
|
const origUserProfile = process.env.USERPROFILE;
|
|
process.env.HOME = tmpHome;
|
|
process.env.USERPROFILE = tmpHome;
|
|
|
|
const { cmdEffortSync } = require('../gsd-core/bin/lib/commands.cjs');
|
|
let result;
|
|
try {
|
|
result = captureOutput(() =>
|
|
cmdEffortSync(tmpDir, false, { dryRun: false, configDir: tmpDir, runtime: 'claude' })
|
|
);
|
|
} finally {
|
|
if (origHome === undefined) {
|
|
delete process.env.HOME;
|
|
} else {
|
|
process.env.HOME = origHome;
|
|
}
|
|
if (origUserProfile === undefined) {
|
|
delete process.env.USERPROFILE;
|
|
} else {
|
|
process.env.USERPROFILE = origUserProfile;
|
|
}
|
|
}
|
|
|
|
// With home effort.default = 'low' and the agent currently at 'medium',
|
|
// cmdEffortSync must sync exactly 1 agent and set it to 'low'.
|
|
assert.equal(result.synced, 1, 'should sync 1 agent whose effort differs from home default');
|
|
assert.equal(result.changes[0].agent, 'gsd-planner');
|
|
assert.equal(result.changes[0].from, 'medium');
|
|
assert.equal(result.changes[0].to, 'low', 'effort must be updated to the home-default value');
|
|
assert.ok(
|
|
fs.readFileSync(agentPath, 'utf8').includes('effort: low'),
|
|
'agent file must be rewritten with the home-default effort value'
|
|
);
|
|
|
|
cleanup(tmpHome);
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('CLI dispatcher: positional args after effort sync are rejected', () => {
|
|
const result = runCli(['effort', 'sync', 'unexpected-arg']);
|
|
assert.notEqual(result.status, 0, 'should exit non-zero on unexpected positional arg');
|
|
assert.ok(
|
|
result.stderr.includes('positional') || result.stderr.includes('unexpected-arg'),
|
|
`stderr should mention the bad arg; got: ${result.stderr}`
|
|
);
|
|
});
|
|
|
|
test('CLI dispatcher: effort sync --apply routes through gsd-tools correctly', () => {
|
|
const tmpDir = makeTmpDir('effort-sync-cli-');
|
|
const agentsDir = makeAgentsDir(tmpDir);
|
|
const agentPath = path.join(agentsDir, 'gsd-planner.md');
|
|
fs.writeFileSync(agentPath, AGENT_WITH_EFFORT);
|
|
writePlanningConfig(tmpDir, { agent_overrides: { 'gsd-planner': 'xhigh' } });
|
|
|
|
const result = runCli(
|
|
['--cwd', tmpDir, 'effort', 'sync', '--apply', '--config-dir', tmpDir],
|
|
);
|
|
|
|
assert.equal(result.status, 0, `CLI exited non-zero: ${result.stderr}`);
|
|
// gsd-tools may print a startup banner before the JSON payload — parse from the first `{`.
|
|
const jsonStart = result.stdout.indexOf('{');
|
|
const output = JSON.parse(result.stdout.slice(jsonStart));
|
|
assert.equal(output.synced, 1);
|
|
assert.ok(
|
|
fs.readFileSync(agentPath, 'utf8').includes('effort: xhigh'),
|
|
'CLI --apply must write the updated effort value'
|
|
);
|
|
|
|
cleanup(tmpDir);
|
|
});
|
|
});
|