* test(#2974): migrate 8 test files to typed-IR assertions Replaces raw stdout/stderr substring matching with structured-field assertions per CONTRIBUTING.md "Prohibited: Raw Text Matching on Test Outputs". Adds shared infrastructure for typed error emission so this pattern is the easy path going forward. Shared infrastructure: - core.cjs: ERROR_REASON frozen enum + setJsonErrorMode/getJsonErrorMode - gsd-tools.cjs: --json-errors CLI flag, parsed before subcommand dispatch - config.cjs: typed reasons at all 7 error sites - graphify.cjs: GRAPHIFY_REASON enum + reason/timeout_ms in execGraphify result - bin/install.js: pure buildSdkFailFastReport() IR builder + renderer - hooks/gsd-session-state.sh, gsd-phase-boundary.sh: emit Claude Code hookSpecificOutput JSON envelope with typed state_present/config_mode/ planning_modified/file_path fields (no-op when hooks.community is off) Test migrations (all pass, 171 tests across the 8 files): - bug-2649-sdk-fail-fast: assert on ir.reason / ir.context / ir.fix_command - bug-2687-config-read-warning-parity: assert.equal stderr === '' - bug-2796-arg-parsing-regression: assert on result.json.updated/.phase - bug-2838-summary-rescue: parse rescue footer, assert mtime invariant - bug-2943-config-get-context-window: parse JSON, assert ERROR_REASON.CONFIG_KEY_NOT_FOUND - graphify: assert reason === GRAPHIFY_REASON.ENOENT/TIMEOUT - hooks-opt-in: parse hookSpecificOutput, assert typed fields - security-scan: reclassified as source-text-is-the-product (scan label output and CI workflow YAML ARE the deployed contract) Verification: lint-no-source-grep clean (0 violations), full suite 6741/6741 pass. Closes #2974 * test(#2974): address CR feedback — typed code field, robust idempotency Two CodeRabbit findings on #3016 addressed: 1. tests/hooks-opt-in.test.cjs:355 (Minor, inline) — parsed.reason.includes('Conventional Commits') was still substring matching after the typed-IR migration. Fixed at the source: the gsd-validate-commit hook now emits a typed `code` field ('CONVENTIONAL_COMMITS_VIOLATION', 'COMMIT_SUBJECT_TOO_LONG') alongside the human-readable `reason`. Test asserts strictEqual on the code; the prose copy is no longer part of the test contract. 2. tests/bug-2838-summary-rescue-gitignored-planning.test.cjs:224-250 (Outside-diff) — mtimeMs alone can stay unchanged on coarse-grained filesystems (HFS+, FAT) when two rewrites land within the same timestamp tick, falsely passing the idempotency assertion. Replaced with a full snapshot (mtimeMs, ctimeMs, size, ino, sha256 of contents) compared via assert.deepStrictEqual — the hash catches any rewrite the timestamp would miss. Verification: 30/30 pass on the two affected files; lint-no-source-grep clean (0 violations across 368 test files).
This commit is contained in:
@@ -11,9 +11,12 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
// allow-test-rule: pending-migration-to-typed-ir [#2974]
|
||||
// Tracked in #2974 for migration to typed-IR assertions per CONTRIBUTING.md
|
||||
// "Prohibited: Raw Text Matching on Test Outputs". Do not copy this pattern.
|
||||
// Migrated to typed-IR (#2974): the previous shape used regex assertions
|
||||
// against stderr to verify fix-command and missing-artifact phrases. Now
|
||||
// the test calls buildSdkFailFastReport(sdkDir) directly and asserts on
|
||||
// the structured IR fields (reason, context, fix_command, missing_artifact,
|
||||
// attempted_nested_install). The renderer's text shape is now an
|
||||
// implementation detail.
|
||||
|
||||
const { test, describe, before } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
@@ -128,19 +131,11 @@ describe('installer SDK dist-missing fail-fast (#2649)', () => {
|
||||
test('missing dist in npx cache: fail fast, no nested npm install', () => {
|
||||
const { root, sdkDir } = makeTempSdk({ npxCache: true });
|
||||
try {
|
||||
// Behavioral check 1: installSdkIfNeeded exits 1 and never spawns nested npm.
|
||||
const result = runWithIntercepts(() => {
|
||||
installer.installSdkIfNeeded({ sdkDir });
|
||||
});
|
||||
|
||||
assert.strictEqual(result.exitCode, 1, 'must exit non-zero');
|
||||
|
||||
// (a) actionable upgrade path in error output
|
||||
assert.match(result.stderr, /npm i(nstall)? -g get-shit-done-cc@latest/,
|
||||
'error must mention the global-install upgrade path');
|
||||
assert.match(result.stderr, /sdk\/dist/,
|
||||
'error must name the missing artifact');
|
||||
|
||||
// (b) no nested `npm install` / `npm.cmd install` inside sdkDir
|
||||
const nestedInstall = result.spawnCalls.find((c) => {
|
||||
const argv = Array.isArray(c.argv) ? c.argv : [];
|
||||
const cwd = c.opts && c.opts.cwd;
|
||||
@@ -151,6 +146,18 @@ describe('installer SDK dist-missing fail-fast (#2649)', () => {
|
||||
});
|
||||
assert.strictEqual(nestedInstall, undefined,
|
||||
'must NOT spawn `npm install` inside the npx-cache sdk dir');
|
||||
|
||||
// Behavioral check 2: the structured fail-fast IR identifies the npx-cache
|
||||
// context, points at the right fix command, and asserts the no-nested-install
|
||||
// contract via a typed boolean (no stderr grepping).
|
||||
const ir = installer.buildSdkFailFastReport(sdkDir, path.join(sdkDir, 'dist', 'cli.js'));
|
||||
assert.strictEqual(ir.ok, false);
|
||||
assert.strictEqual(ir.reason, 'sdk_fail_fast');
|
||||
assert.strictEqual(ir.context, 'npx-cache');
|
||||
assert.strictEqual(ir.missing_artifact, 'sdk/dist');
|
||||
assert.strictEqual(ir.fix_command, 'npm install -g get-shit-done-cc@latest');
|
||||
assert.strictEqual(ir.attempted_nested_install, false,
|
||||
'IR contract: nested-install must always be false (this is a hard invariant)');
|
||||
} finally {
|
||||
cleanup(root);
|
||||
}
|
||||
@@ -164,9 +171,13 @@ describe('installer SDK dist-missing fail-fast (#2649)', () => {
|
||||
installer.installSdkIfNeeded({ sdkDir });
|
||||
});
|
||||
assert.strictEqual(result.exitCode, 1);
|
||||
// Dev clone path: suggest the local build, not the global upgrade.
|
||||
assert.match(result.stderr, /cd sdk && npm install && npm run build/,
|
||||
'dev-clone error must keep the build-from-clone instructions');
|
||||
|
||||
// Typed-IR migration #2974: dev-clone context surfaces the local-build
|
||||
// fix command (not the global-install one).
|
||||
const ir = installer.buildSdkFailFastReport(sdkDir, path.join(sdkDir, 'dist', 'cli.js'));
|
||||
assert.strictEqual(ir.context, 'dev-clone');
|
||||
assert.strictEqual(ir.fix_command, 'cd sdk && npm install && npm run build');
|
||||
assert.strictEqual(ir.attempted_nested_install, false);
|
||||
|
||||
const nestedInstall = result.spawnCalls.find((c) => {
|
||||
const argv = Array.isArray(c.argv) ? c.argv : [];
|
||||
|
||||
Reference in New Issue
Block a user