codex-genesis-harness 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/.codebase/ARCHITECTURE_REVIEW_COMPLETE.md +216 -216
  2. package/.codebase/CURRENT_STATE.md +9 -7
  3. package/.codebase/FILE_NAMING_CLARIFICATION.md +161 -161
  4. package/.codebase/HARNESS_COMPLETENESS_AUDIT.md +613 -613
  5. package/.codebase/IMPLEMENTATION_COMPLETE.md +429 -429
  6. package/.codebase/IMPLEMENTATION_HANDOFF.md +351 -351
  7. package/.codebase/IMPROVEMENTS_SUMMARY.md +419 -419
  8. package/.codebase/PHASE3_SKILLS_NAMING_COMPLETE.md +292 -292
  9. package/.codebase/PHASE_DEPENDENCY_MAP.md +486 -486
  10. package/.codebase/QUICK_START_SPEC_IMPACT.md +456 -456
  11. package/.codebase/README.md +139 -139
  12. package/.codebase/RECOVERY_POINTS.md +438 -438
  13. package/.codebase/state.json +37 -0
  14. package/.codex/skills/genesis-api-sync/SKILL.md +354 -354
  15. package/.codex/skills/genesis-api-sync/checklists/api-sync-checklist.md +101 -101
  16. package/.codex/skills/genesis-api-sync/templates/api-change-template.md +257 -257
  17. package/.codex/skills/genesis-debug-guide/SKILL.md +479 -479
  18. package/.codex/skills/genesis-debug-guide/checklists/flaky-test-investigation.md +339 -339
  19. package/.codex/skills/genesis-debug-guide/checklists/production-bug-debug.md +210 -210
  20. package/.codex/skills/genesis-debug-guide/checklists/test-failure-debug.md +158 -158
  21. package/.codex/skills/genesis-debug-guide/observability/debug-commands.md +365 -365
  22. package/.codex/skills/genesis-debug-guide/playbooks/unit-test-failures.md +289 -289
  23. package/.codex/skills/genesis-debug-guide/templates/debug-investigation-log.md +288 -288
  24. package/.codex/skills/genesis-docs-automation/SKILL.md +1003 -1003
  25. package/.codex/skills/genesis-docs-automation/checklists/docs-validation.md +359 -359
  26. package/.codex/skills/genesis-docs-automation/checklists/spec-alignment.md +312 -312
  27. package/.codex/skills/genesis-docs-automation/observability/docs-tracking.md +382 -382
  28. package/.codex/skills/genesis-docs-automation/playbooks/auto-update-flow.md +851 -851
  29. package/.codex/skills/genesis-docs-automation/playbooks/changelog-generation.md +491 -491
  30. package/.codex/skills/genesis-docs-automation/templates/changelog-entry-template.md +187 -187
  31. package/.codex/skills/genesis-docs-automation/templates/handoff-template.md +297 -297
  32. package/.codex/skills/genesis-harness/SKILL.md +1427 -1418
  33. package/.codex/skills/genesis-harness/agents/openai.yaml +7 -7
  34. package/.codex/skills/genesis-harness/checklists/bug-fix-qa.md +169 -169
  35. package/.codex/skills/genesis-harness/checklists/new-feature-qa.md +157 -157
  36. package/.codex/skills/genesis-harness/checklists/refactor-qa.md +216 -216
  37. package/.codex/skills/genesis-harness/checklists/requirements-validation.md +211 -211
  38. package/.codex/skills/genesis-harness/references/planning-schema.md +35 -35
  39. package/.codex/skills/genesis-harness/references/quality-rubric.md +21 -21
  40. package/.codex/skills/genesis-harness/references/research-rubric.md +41 -41
  41. package/.codex/skills/genesis-harness/references/workflows.md +33 -33
  42. package/.codex/skills/genesis-harness/resources/agents-template.md +27 -27
  43. package/.codex/skills/genesis-harness/resources/api-docs-template.md +32 -32
  44. package/.codex/skills/genesis-harness/resources/architecture-template.md +30 -30
  45. package/.codex/skills/genesis-harness/resources/audit-template.md +26 -26
  46. package/.codex/skills/genesis-harness/resources/bug-template.md +34 -34
  47. package/.codex/skills/genesis-harness/resources/change-impact-matrix-template.md +204 -204
  48. package/.codex/skills/genesis-harness/resources/check-template.md +21 -21
  49. package/.codex/skills/genesis-harness/resources/conventions-template.md +42 -42
  50. package/.codex/skills/genesis-harness/resources/decision-template.md +33 -33
  51. package/.codex/skills/genesis-harness/resources/design-template.md +26 -26
  52. package/.codex/skills/genesis-harness/resources/escalation-template.md +21 -21
  53. package/.codex/skills/genesis-harness/resources/feature-template.md +49 -49
  54. package/.codex/skills/genesis-harness/resources/foundation-phase-template.md +131 -131
  55. package/.codex/skills/genesis-harness/resources/integrations-template.md +32 -32
  56. package/.codex/skills/genesis-harness/resources/journeys-template.md +13 -13
  57. package/.codex/skills/genesis-harness/resources/lessons-learned-template.md +12 -12
  58. package/.codex/skills/genesis-harness/resources/observability-template.md +34 -34
  59. package/.codex/skills/genesis-harness/resources/phase-00-foundation-template.md +76 -76
  60. package/.codex/skills/genesis-harness/resources/phase-template.md +34 -34
  61. package/.codex/skills/genesis-harness/resources/pitfalls-template.md +22 -22
  62. package/.codex/skills/genesis-harness/resources/planning-tree-template.md +39 -39
  63. package/.codex/skills/genesis-harness/resources/post-implementation-guide.md +347 -347
  64. package/.codex/skills/genesis-harness/resources/project-template.md +38 -38
  65. package/.codex/skills/genesis-harness/resources/quality-score-template.md +11 -11
  66. package/.codex/skills/genesis-harness/resources/requirements-template.md +26 -26
  67. package/.codex/skills/genesis-harness/resources/research-template.md +26 -26
  68. package/.codex/skills/genesis-harness/resources/review-template.md +22 -22
  69. package/.codex/skills/genesis-harness/resources/spec-changelog-template.md +6 -6
  70. package/.codex/skills/genesis-harness/resources/stack-template.md +33 -33
  71. package/.codex/skills/genesis-harness/resources/verification-template.md +26 -26
  72. package/.codex/skills/genesis-harness/scripts/check-architecture-boundaries.sh +0 -0
  73. package/.codex/skills/genesis-harness/scripts/check-docs-sync.sh +0 -0
  74. package/.codex/skills/genesis-harness/scripts/check-no-debug-logs.sh +0 -0
  75. package/.codex/skills/genesis-harness/scripts/check-required-planning-files.sh +0 -0
  76. package/.codex/skills/genesis-harness/scripts/check-spec-changelog.sh +0 -0
  77. package/.codex/skills/genesis-harness/scripts/check-task-tracking.sh +0 -0
  78. package/.codex/skills/genesis-harness/scripts/compact-context.sh +0 -0
  79. package/.codex/skills/genesis-harness/scripts/create-adr.sh +0 -0
  80. package/.codex/skills/genesis-harness/scripts/create-bug.sh +0 -0
  81. package/.codex/skills/genesis-harness/scripts/create-feature.sh +0 -0
  82. package/.codex/skills/genesis-harness/scripts/detect-stack.sh +0 -0
  83. package/.codex/skills/genesis-harness/scripts/init-planning.sh +0 -0
  84. package/.codex/skills/genesis-harness/scripts/list-changed-files.sh +0 -0
  85. package/.codex/skills/genesis-harness/scripts/offload-log.sh +0 -0
  86. package/.codex/skills/genesis-harness/scripts/run-verification.sh +0 -0
  87. package/.codex/skills/genesis-harness/scripts/run-verify-loop.sh +0 -0
  88. package/.codex/skills/genesis-harness/scripts/update-state.sh +0 -0
  89. package/.codex/skills/genesis-mvp-planning/SKILL.md +114 -0
  90. package/.codex/skills/genesis-mvp-planning/agents/openai.yaml +6 -0
  91. package/.codex/skills/genesis-mvp-planning/checklists/mvp-readiness.md +18 -0
  92. package/.codex/skills/genesis-mvp-planning/examples/5-phase-roadmap-example.md +43 -0
  93. package/.codex/skills/genesis-mvp-planning/templates/phase-1-core.md +17 -0
  94. package/.codex/skills/genesis-mvp-planning/templates/phase-2-auth.md +17 -0
  95. package/.codex/skills/genesis-mvp-planning/templates/phase-3-features.md +17 -0
  96. package/.codex/skills/genesis-mvp-planning/templates/phase-4-integrations.md +17 -0
  97. package/.codex/skills/genesis-mvp-planning/templates/phase-5-readiness.md +17 -0
  98. package/.codex/skills/genesis-new-design/agents/openai.yaml +3 -3
  99. package/.codex/skills/genesis-observability-automation/checklists/.gitkeep +0 -0
  100. package/.codex/skills/genesis-observability-automation/observability/.gitkeep +0 -0
  101. package/.codex/skills/genesis-observability-automation/playbooks/.gitkeep +0 -0
  102. package/.codex/skills/genesis-observability-automation/templates/.gitkeep +0 -0
  103. package/.codex/skills/genesis-release-orchestration/SKILL.md +653 -653
  104. package/.codex/skills/genesis-release-orchestration/checklists/post-deployment-verification.md +274 -274
  105. package/.codex/skills/genesis-release-orchestration/checklists/pre-release-validation.md +220 -220
  106. package/.codex/skills/genesis-release-orchestration/observability/release-tracking.md +253 -253
  107. package/.codex/skills/genesis-release-orchestration/playbooks/canary-deployment-orchestration.md +472 -472
  108. package/.codex/skills/genesis-release-orchestration/playbooks/semantic-versioning-automation.md +494 -494
  109. package/.codex/skills/genesis-release-orchestration/templates/deployment-strategy-template.md +303 -303
  110. package/.codex/skills/genesis-release-orchestration/templates/release-runbook-template.md +420 -420
  111. package/.codex/skills/genesis-research-first/SKILL.md +237 -237
  112. package/.codex/skills/genesis-research-first/templates/.gitkeep +0 -0
  113. package/.codex/skills/genesis-spec-propagation/SKILL.md +534 -534
  114. package/.codex/skills/genesis-spec-propagation/checklists/phase-update-verification.md +384 -384
  115. package/.codex/skills/genesis-spec-propagation/checklists/spec-change-detection.md +257 -257
  116. package/.codex/skills/genesis-spec-propagation/observability/propagation-tracking.md +373 -373
  117. package/.codex/skills/genesis-spec-propagation/playbooks/breaking-change-propagation.md +692 -692
  118. package/.codex/skills/genesis-spec-propagation/playbooks/feature-change-propagation.md +434 -434
  119. package/.codex/skills/genesis-spec-propagation/templates/migration-guide-template.md +407 -407
  120. package/.codex/skills/genesis-state-machine/SKILL.md +34 -0
  121. package/.codex/skills/genesis-upgrade-design/agents/openai.yaml +3 -3
  122. package/.codex/skills/spec-impact-engine/SKILL.md +504 -504
  123. package/.codex/skills/spec-impact-engine/detect-spec-changes.sh +0 -0
  124. package/.codex-plugin/plugin.json +24 -24
  125. package/CHANGELOG.md +42 -0
  126. package/LICENSE +22 -22
  127. package/README.EN.md +784 -719
  128. package/README.VI.md +776 -712
  129. package/README.md +113 -253
  130. package/VERSION +2 -2
  131. package/bin/genesis-harness.js +90 -87
  132. package/package.json +68 -43
  133. package/scripts/README.md +342 -342
  134. package/scripts/compact-context.sh +0 -0
  135. package/scripts/contract_integrity_gate.js +83 -0
  136. package/scripts/detect-changes.sh +0 -0
  137. package/scripts/healing_telemetry.js +118 -0
  138. package/scripts/install.sh +4 -1
  139. package/scripts/offload-log.sh +0 -0
  140. package/scripts/prompt_sentinel.js +84 -0
  141. package/scripts/run-evals.sh +1 -0
  142. package/scripts/run-verify-loop.sh +11 -0
  143. package/scripts/spec_visual_sync.js +157 -0
  144. package/scripts/test_generator.js +142 -0
  145. package/scripts/transition_state.sh +67 -0
  146. package/scripts/uninstall.sh +1 -0
  147. package/scripts/validation_gates.sh +85 -0
  148. package/scripts/verify.sh +5 -0
  149. package/tests/unit/contract_integrity_gate.test.js +74 -0
  150. package/tests/unit/healing_telemetry.test.js +58 -0
  151. package/tests/unit/prompt_sentinel.test.js +50 -0
  152. package/tests/unit/spec_visual_sync.test.js +77 -0
  153. package/tests/unit/test_generator.test.js +62 -0
@@ -0,0 +1,67 @@
1
+ #!/bin/bash
2
+
3
+ if [ -z "$1" ]; then
4
+ echo "Usage: bash scripts/transition_state.sh <NEW_STATE> [Reason]"
5
+ exit 1
6
+ fi
7
+
8
+ NEW_STATE=$1
9
+ REASON=${2:-"State transition"}
10
+ STATE_FILE=".codebase/state.json"
11
+ CURRENT_STATE_MD=".codebase/CURRENT_STATE.md"
12
+
13
+ if [ ! -f "$STATE_FILE" ]; then
14
+ echo "Error: $STATE_FILE not found."
15
+ exit 1
16
+ fi
17
+
18
+ if [ "$NEW_STATE" == "COMPLETED" ]; then
19
+ if [ -f "scripts/validation_gates.sh" ]; then
20
+ echo "Running Validation Gates before transitioning to COMPLETED..."
21
+ if ! bash scripts/validation_gates.sh; then
22
+ echo "Transition blocked by Validation Gates."
23
+ exit 1
24
+ fi
25
+ fi
26
+ fi
27
+
28
+ node -e "
29
+ const fs = require('fs');
30
+ const file = '$STATE_FILE';
31
+ const newState = '$NEW_STATE';
32
+ const reason = '$REASON';
33
+
34
+ const allowed = {
35
+ 'INIT': ['REQUIREMENTS_GATHERING', 'PLANNING'],
36
+ 'REQUIREMENTS_GATHERING': ['PLANNING'],
37
+ 'PLANNING': ['IMPLEMENTATION'],
38
+ 'IMPLEMENTATION': ['VERIFICATION', 'PLANNING'],
39
+ 'VERIFICATION': ['COMPLETED', 'IMPLEMENTATION'],
40
+ 'COMPLETED': ['INIT', 'REQUIREMENTS_GATHERING']
41
+ };
42
+
43
+ let data = JSON.parse(fs.readFileSync(file, 'utf8'));
44
+ const current = data.current_state || 'INIT';
45
+
46
+ if (allowed[current] && allowed[current].includes(newState)) {
47
+ data.history = data.history || [];
48
+ data.history.push({ from: current, to: newState, reason: reason, timestamp: new Date().toISOString() });
49
+ data.current_state = newState;
50
+ fs.writeFileSync(file, JSON.stringify(data, null, 2));
51
+ console.log('Transition successful: ' + current + ' -> ' + newState);
52
+ } else {
53
+ console.error('Invalid transition from ' + current + ' to ' + newState);
54
+ process.exit(1);
55
+ }
56
+ "
57
+
58
+ if [ $? -eq 0 ]; then
59
+ echo "# Current State: $NEW_STATE" > "$CURRENT_STATE_MD"
60
+ echo "Last updated: $(date)" >> "$CURRENT_STATE_MD"
61
+ echo "" >> "$CURRENT_STATE_MD"
62
+ echo "## Reason" >> "$CURRENT_STATE_MD"
63
+ echo "$REASON" >> "$CURRENT_STATE_MD"
64
+ exit 0
65
+ else
66
+ exit 1
67
+ fi
@@ -7,6 +7,7 @@ skill_names=(
7
7
  genesis-upgrade-design
8
8
  genesis-architecture
9
9
  genesis-planning
10
+ genesis-mvp-planning
10
11
  genesis-codebase-map
11
12
  genesis-design-spec
12
13
  genesis-api-contract
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ echo "====================================="
5
+ echo " RUNNING VALIDATION GATES "
6
+ echo "====================================="
7
+
8
+ repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
9
+ FAILURES=0
10
+
11
+ fail() {
12
+ echo "❌ VALIDATION FAILED: $*" >&2
13
+ FAILURES=$((FAILURES + 1))
14
+ }
15
+
16
+ echo "1. Checking for leftover debug logs and TODOs..."
17
+ # Exclude node_modules, .git, .codex, scripts, .codebase, bin, and md files
18
+ EXCLUDES="--exclude-dir=node_modules --exclude-dir=.git --exclude-dir=.codex --exclude-dir=scripts --exclude-dir=.codebase --exclude-dir=bin --exclude=*.md"
19
+
20
+ # We check for TODO, FIXME, console.log, print( (python)
21
+ # Using grep recursively
22
+ if grep -rn $EXCLUDES -E 'TODO|FIXME|console\.log|print\(' "$repo_root" | grep -v 'validation_gates.sh'; then
23
+ fail "Found unresolved TODOs or leftover debug logs in codebase!"
24
+ else
25
+ echo "✅ Codebase cleanliness gate passed."
26
+ fi
27
+
28
+ echo "2. Verifying Harness Integrity..."
29
+ if [ -f "$repo_root/scripts/verify.sh" ]; then
30
+ if bash "$repo_root/scripts/verify.sh" > /dev/null 2>&1; then
31
+ echo "✅ Harness Integrity gate passed."
32
+ else
33
+ fail "verify.sh failed. Core files or templates are missing."
34
+ fi
35
+ fi
36
+
37
+ echo "3. Checking for Documentation Drift (Alignment with Code changes)..."
38
+ if [ -d "$repo_root/.git" ]; then
39
+ # Get list of modified files in git
40
+ CHANGED_FILES=$(git diff --name-only HEAD 2>/dev/null || true)
41
+
42
+ if [ -n "$CHANGED_FILES" ]; then
43
+ # API Drift: code under src/ modified, but API contracts not updated
44
+ if echo "$CHANGED_FILES" | grep -qE "src/.*api|src/.*endpoint|src/.*route" && ! echo "$CHANGED_FILES" | grep -qE "contracts/api/|.codebase/API_CONTRACTS.md|.planning/API_DOCS.md"; then
45
+ echo "⚠️ WARNING: You changed API code under src/ but did not update API_CONTRACTS.md, API_DOCS.md or contracts/api/!"
46
+ fi
47
+
48
+ # Database Drift: models or schemas modified, but DOMAIN_MODELS.md not updated
49
+ if echo "$CHANGED_FILES" | grep -qE "model|schema|db" && ! echo "$CHANGED_FILES" | grep -qE ".codebase/DOMAIN_MODELS.md"; then
50
+ echo "⚠️ WARNING: You changed database/model files but did not update DOMAIN_MODELS.md!"
51
+ fi
52
+
53
+ # Test Drift: test files modified, but TEST_MATRIX.md not updated
54
+ if echo "$CHANGED_FILES" | grep -qE "tests/|playwright/" && ! echo "$CHANGED_FILES" | grep -qE ".codebase/TEST_MATRIX.md"; then
55
+ echo "⚠️ WARNING: You changed test files but did not update TEST_MATRIX.md!"
56
+ fi
57
+
58
+ # Dependency Drift: package.json dependencies modified, but DEPENDENCY_GRAPH.md not updated
59
+ if echo "$CHANGED_FILES" | grep -q "package.json" && ! echo "$CHANGED_FILES" | grep -q ".codebase/DEPENDENCY_GRAPH.md"; then
60
+ if git diff package.json 2>/dev/null | grep -qE '^\+.*"(dependencies|devDependencies)"'; then
61
+ echo "⚠️ WARNING: You updated package.json dependencies but did not update DEPENDENCY_GRAPH.md!"
62
+ fi
63
+ fi
64
+ echo "✅ Documentation alignment check complete."
65
+ fi
66
+ else
67
+ echo "⚠️ Git repository not found. Skipping drift check."
68
+ fi
69
+
70
+ echo "4. Running Pre-emptive Prompt Sentinel check..."
71
+ if [ -f "$repo_root/scripts/prompt_sentinel.js" ] && [ -f "$repo_root/.codebase/CURRENT_STATE.md" ]; then
72
+ # Run prompt sentinel check on the state file as a pre-flight test
73
+ node "$repo_root/scripts/prompt_sentinel.js" --check "$repo_root/.codebase/CURRENT_STATE.md" --threshold 1500
74
+ fi
75
+
76
+
77
+
78
+ echo "====================================="
79
+ if [ $FAILURES -gt 0 ]; then
80
+ echo "❌ $FAILURES Validation Gate(s) failed."
81
+ exit 1
82
+ else
83
+ echo "✅ All Validation Gates passed! Output is ready for production."
84
+ exit 0
85
+ fi
package/scripts/verify.sh CHANGED
@@ -9,6 +9,7 @@ skill_names=(
9
9
  genesis-upgrade-design
10
10
  genesis-architecture
11
11
  genesis-planning
12
+ genesis-mvp-planning
12
13
  genesis-codebase-map
13
14
  genesis-design-spec
14
15
  genesis-api-contract
@@ -275,6 +276,10 @@ verify_one() {
275
276
  verify_skill_metadata "$skill_dir" "planning-skill"
276
277
  verify_skill_protocol "$skill_dir"
277
278
  ;;
279
+ genesis-mvp-planning)
280
+ verify_skill_metadata "$skill_dir" "genesis-mvp-planning"
281
+ verify_minimal_skill "$skill_dir"
282
+ ;;
278
283
  genesis-codebase-map)
279
284
  verify_skill_metadata "$skill_dir" "codebase-map-skill"
280
285
  verify_skill_protocol "$skill_dir"
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Unit Test for contract_integrity_gate.js
3
+ * Part of Genesis Codex Harness v0.1.8
4
+ */
5
+
6
+ const assert = require('assert');
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const { execSync } = require('child_process');
10
+
11
+ console.log('Running contract_integrity_gate.js unit tests...');
12
+
13
+ const TEST_CODE_PATH = path.resolve(__dirname, 'temp_dummy_code.js');
14
+ const TEST_CONTRACT_PATH = path.resolve(__dirname, 'temp_dummy_contract.json');
15
+
16
+ try {
17
+ // Setup dummy contract
18
+ const dummySchema = {
19
+ $schema: 'http://json-schema.org/draft-07/schema#',
20
+ title: 'Dummy Contract',
21
+ type: 'object',
22
+ properties: {
23
+ name: { type: 'string' },
24
+ score: { type: 'number' }
25
+ },
26
+ required: ['name', 'score']
27
+ };
28
+ fs.writeFileSync(TEST_CONTRACT_PATH, JSON.stringify(dummySchema, null, 2), 'utf8');
29
+
30
+ // Test case 1: Happy path (clean code matching schema keys)
31
+ console.log(' 1. Testing matching code content...');
32
+ const cleanCode = `
33
+ const user = {
34
+ name: 'Alice',
35
+ score: 95
36
+ };
37
+ `;
38
+ fs.writeFileSync(TEST_CODE_PATH, cleanCode, 'utf8');
39
+
40
+ const stdoutHappy = execSync(`node scripts/contract_integrity_gate.js --code "${TEST_CODE_PATH}" --contract "${TEST_CONTRACT_PATH}"`, { encoding: 'utf8' });
41
+ assert.ok(stdoutHappy.includes('INTEGRITY SUCCESS'), 'Must report integrity success when keys match.');
42
+ console.log(' ✓ Test case 1 passed: Matching keys pass gate successfully.');
43
+
44
+ // Test case 2: Failure path (missing a key in the code)
45
+ console.log(' 2. Testing missing key code content...');
46
+ const brokenCode = `
47
+ const user = {
48
+ name: 'Bob'
49
+ // score is missing!
50
+ };
51
+ `;
52
+ fs.writeFileSync(TEST_CODE_PATH, brokenCode, 'utf8');
53
+
54
+ try {
55
+ execSync(`node scripts/contract_integrity_gate.js --code "${TEST_CODE_PATH}" --contract "${TEST_CONTRACT_PATH}" 2>&1`, { encoding: 'utf8' });
56
+ assert.fail('Should throw an error and return exit code 1 for missing fields.');
57
+ } catch (err) {
58
+ const errorOutput = err.stdout || err.message;
59
+ assert.ok(errorOutput.includes('INTEGRITY FAILURE'), 'Must report integrity failure.');
60
+ assert.ok(errorOutput.includes('Missing property: "score"'), 'Must report exact missing property name.');
61
+ console.log(' ✓ Test case 2 passed: Missing key correctly blocks the gate.');
62
+ }
63
+
64
+ } finally {
65
+ if (fs.existsSync(TEST_CODE_PATH)) {
66
+ fs.unlinkSync(TEST_CODE_PATH);
67
+ }
68
+ if (fs.existsSync(TEST_CONTRACT_PATH)) {
69
+ fs.unlinkSync(TEST_CONTRACT_PATH);
70
+ }
71
+ }
72
+
73
+ console.log('All contract_integrity_gate.js tests passed! ✓\n');
74
+ process.exit(0);
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Unit Test for healing_telemetry.js
3
+ * Part of Genesis Codex Harness v0.1.8
4
+ */
5
+
6
+ const assert = require('assert');
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const { execSync } = require('child_process');
10
+
11
+ console.log('Running healing_telemetry.js unit tests...');
12
+
13
+ const TEST_LESSONS_PATH = path.resolve(__dirname, '../../.codebase/failures/lessons_learned.md');
14
+
15
+ // Backup existing if any
16
+ let originalLessons = null;
17
+ if (fs.existsSync(TEST_LESSONS_PATH)) {
18
+ originalLessons = fs.readFileSync(TEST_LESSONS_PATH, 'utf8');
19
+ } else {
20
+ // Ensure directory exists
21
+ fs.mkdirSync(path.dirname(TEST_LESSONS_PATH), { recursive: true });
22
+ }
23
+
24
+ try {
25
+ // Clean start
26
+ if (fs.existsSync(TEST_LESSONS_PATH)) {
27
+ fs.unlinkSync(TEST_LESSONS_PATH);
28
+ }
29
+
30
+ // Test case 1: Record a successful self-healing fix signature
31
+ console.log(' 1. Testing record signature...');
32
+ execSync('node scripts/healing_telemetry.js --record --error "SyntaxError: Unexpected token" --file "src/routes.js" --fix "Add missing closing brace to route handler"', { encoding: 'utf8' });
33
+
34
+ assert.ok(fs.existsSync(TEST_LESSONS_PATH), 'Lessons database file must be created.');
35
+ const dbContent = fs.readFileSync(TEST_LESSONS_PATH, 'utf8');
36
+ assert.ok(dbContent.includes('SyntaxError: Unexpected token'), 'Must contain matching error signature.');
37
+ assert.ok(dbContent.includes('Add missing closing brace'), 'Must contain matching fix payload.');
38
+ console.log(' ✓ Test case 1 passed: Lessons correctly recorded in markdown database.');
39
+
40
+ // Test case 2: Recall / retrieve matching fix signature
41
+ console.log(' 2. Testing recall search query matching...');
42
+ const stdoutRecall = execSync('node scripts/healing_telemetry.js --recall --error "SyntaxError: Unexpected token at src/routes.js:25"', { encoding: 'utf8' });
43
+
44
+ assert.ok(stdoutRecall.includes('RECALL MATCH FOUND'), 'Must report matching signature is found.');
45
+ assert.ok(stdoutRecall.includes('SUGGESTED_FIX_START: Add missing closing brace to route handler'), 'Must output matching corrective snippet.');
46
+ console.log(' ✓ Test case 2 passed: Match recall and fix parsing is 100% correct.');
47
+
48
+ } finally {
49
+ // Cleanup test structures
50
+ if (originalLessons !== null) {
51
+ fs.writeFileSync(TEST_LESSONS_PATH, originalLessons, 'utf8');
52
+ } else if (fs.existsSync(TEST_LESSONS_PATH)) {
53
+ fs.unlinkSync(TEST_LESSONS_PATH);
54
+ }
55
+ }
56
+
57
+ console.log('All healing_telemetry.js tests passed! ✓\n');
58
+ process.exit(0);
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Unit Test for prompt_sentinel.js
3
+ * Part of Genesis Codex Harness v0.1.7
4
+ */
5
+
6
+ const assert = require('assert');
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const { execSync } = require('child_process');
10
+
11
+ console.log('Running prompt_sentinel.js unit tests...');
12
+
13
+ const TEST_FILE_PATH = path.resolve(__dirname, 'prompt_sentinel_bloated_temp.log');
14
+
15
+ try {
16
+ // Test case 1: In bounds threshold
17
+ console.log(' 1. Testing in-bounds file check...');
18
+ fs.writeFileSync(TEST_FILE_PATH, 'Short log lines for in-bounds testing.\n'.repeat(10), 'utf8');
19
+
20
+ const stdoutSafe = execSync(`node scripts/prompt_sentinel.js --check "${TEST_FILE_PATH}" --threshold 100`, { encoding: 'utf8' });
21
+ assert.ok(stdoutSafe.includes('Token payload is within safe boundaries'), 'Must report safe bounds.');
22
+
23
+ const lineCountSafe = fs.readFileSync(TEST_FILE_PATH, 'utf8').trim().split('\n').length;
24
+ assert.strictEqual(lineCountSafe, 10, 'File must not be truncated when in bounds.');
25
+ console.log(' ✓ Test case 1 passed: Safe boundaries are respected without changes.');
26
+
27
+ // Test case 2: Out of bounds threshold (triggers truncation)
28
+ console.log(' 2. Testing out-of-bounds file check and truncation...');
29
+ fs.writeFileSync(TEST_FILE_PATH, 'Redundant bloated log data line entry.\n'.repeat(1200), 'utf8');
30
+
31
+ // Run with threshold of 100 tokens (will exceed, trigger truncation)
32
+ const stdoutExcessive = execSync(`node scripts/prompt_sentinel.js --check "${TEST_FILE_PATH}" --threshold 100 2>&1`, { encoding: 'utf8' });
33
+ assert.ok(stdoutExcessive.includes('exceeds the safety threshold'), 'Must log threshold exceeded warning.');
34
+ assert.ok(stdoutExcessive.includes('truncated successfully'), 'Must log truncation success message.');
35
+
36
+ const truncatedContent = fs.readFileSync(TEST_FILE_PATH, 'utf8');
37
+ const truncatedLines = truncatedContent.split('\n');
38
+ assert.ok(truncatedLines.length <= 1005, 'File must be truncated to standard boundaries (approx. 1000 lines).');
39
+ assert.ok(truncatedContent.includes('PROMPT SENTINEL AUTO-TRUNCATION'), 'Must contain sentinel truncation statement.');
40
+
41
+ console.log(' ✓ Test case 2 passed: Out-of-bounds trigger successfully auto-truncates data.');
42
+
43
+ } finally {
44
+ if (fs.existsSync(TEST_FILE_PATH)) {
45
+ fs.unlinkSync(TEST_FILE_PATH);
46
+ }
47
+ }
48
+
49
+ console.log('All prompt_sentinel.js tests passed! ✓\n');
50
+ process.exit(0);
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Unit Test for spec_visual_sync.js
3
+ * Part of Genesis Codex Harness v0.1.7
4
+ */
5
+
6
+ const assert = require('assert');
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const { execSync } = require('child_process');
10
+
11
+ console.log('Running spec_visual_sync.js unit tests...');
12
+
13
+ const TEST_PLANNING_DIR = path.resolve(__dirname, '../../.planning/diagrams');
14
+ const TEST_ERD_PATH = path.join(TEST_PLANNING_DIR, 'database-erd.mmd');
15
+ const TEST_CONTRACTS_DIR = path.resolve(__dirname, '../../contracts/api/testentity');
16
+ const TEST_CONTRACT_PATH = path.join(TEST_CONTRACTS_DIR, 'response.json');
17
+
18
+ // Backup existing if any
19
+ let originalErd = null;
20
+ if (fs.existsSync(TEST_ERD_PATH)) {
21
+ originalErd = fs.readFileSync(TEST_ERD_PATH, 'utf8');
22
+ }
23
+
24
+ // Ensure clean directories
25
+ fs.mkdirSync(TEST_PLANNING_DIR, { recursive: true });
26
+ fs.mkdirSync(TEST_CONTRACTS_DIR, { recursive: true });
27
+
28
+ try {
29
+ // Test case 1: Parse ERD to Contract JSON
30
+ const dummyErd = `erDiagram
31
+ TESTENTITY {
32
+ string name
33
+ int id
34
+ bool active
35
+ }
36
+ `;
37
+ fs.writeFileSync(TEST_ERD_PATH, dummyErd, 'utf8');
38
+
39
+ console.log(' 1. Running spec_visual_sync.js --from-erd...');
40
+ execSync('node scripts/spec_visual_sync.js --from-erd');
41
+
42
+ assert.ok(fs.existsSync(TEST_CONTRACT_PATH), 'Contract file response.json must be created.');
43
+ const contract = JSON.parse(fs.readFileSync(TEST_CONTRACT_PATH, 'utf8'));
44
+
45
+ assert.strictEqual(contract.title, 'Testentity Contract');
46
+ assert.strictEqual(contract.properties.name.type, 'string');
47
+ assert.strictEqual(contract.properties.id.type, 'number');
48
+ assert.strictEqual(contract.properties.active.type, 'boolean');
49
+ console.log(' ✓ Test case 1 passed: ERD to Contract parsing is 100% correct.');
50
+
51
+ // Test case 2: Generate ERD from Contract
52
+ console.log(' 2. Running spec_visual_sync.js --to-erd...');
53
+ execSync('node scripts/spec_visual_sync.js --to-erd');
54
+
55
+ const compiledErd = fs.readFileSync(TEST_ERD_PATH, 'utf8');
56
+ assert.ok(compiledErd.includes('TESTENTITY'), 'Erd must contain entity TESTENTITY.');
57
+ assert.ok(compiledErd.includes('int id'), 'Erd must contain attribute int id.');
58
+ assert.ok(compiledErd.includes('bool active'), 'Erd must contain attribute bool active.');
59
+ console.log(' ✓ Test case 2 passed: Contract to ERD generation is 100% correct.');
60
+
61
+ } finally {
62
+ // Cleanup test structures
63
+ if (fs.existsSync(TEST_CONTRACT_PATH)) {
64
+ fs.unlinkSync(TEST_CONTRACT_PATH);
65
+ }
66
+ if (fs.existsSync(TEST_CONTRACTS_DIR)) {
67
+ fs.rmdirSync(TEST_CONTRACTS_DIR);
68
+ }
69
+ if (originalErd !== null) {
70
+ fs.writeFileSync(TEST_ERD_PATH, originalErd, 'utf8');
71
+ } else if (fs.existsSync(TEST_ERD_PATH)) {
72
+ fs.unlinkSync(TEST_ERD_PATH);
73
+ }
74
+ }
75
+
76
+ console.log('All spec_visual_sync.js tests passed! ✓\n');
77
+ process.exit(0);
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Unit Test for test_generator.js
3
+ * Part of Genesis Codex Harness v0.1.7
4
+ */
5
+
6
+ const assert = require('assert');
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const { execSync } = require('child_process');
10
+
11
+ console.log('Running test_generator.js unit tests...');
12
+
13
+ const TEST_CONTRACT_DIR = path.resolve(__dirname, '../../contracts/api/testendpoint');
14
+ const TEST_RESPONSE_PATH = path.join(TEST_CONTRACT_DIR, 'response.json');
15
+ const EXPECTED_TEST_PATH = path.resolve(__dirname, '../../tests/integration/testendpoint.test.js');
16
+
17
+ // Ensure clean directories
18
+ fs.mkdirSync(TEST_CONTRACT_DIR, { recursive: true });
19
+
20
+ try {
21
+ // Setup mock contract
22
+ const mockSchema = {
23
+ $schema: 'http://json-schema.org/draft-07/schema#',
24
+ title: 'Test Endpoint response schema',
25
+ type: 'object',
26
+ properties: {
27
+ name: { type: 'string' },
28
+ score: { type: 'number' }
29
+ },
30
+ required: ['name']
31
+ };
32
+
33
+ fs.writeFileSync(TEST_RESPONSE_PATH, JSON.stringify(mockSchema, null, 2), 'utf8');
34
+
35
+ console.log(' 1. Running test_generator.js testendpoint...');
36
+ execSync('node scripts/test_generator.js testendpoint');
37
+
38
+ assert.ok(fs.existsSync(EXPECTED_TEST_PATH), 'Integration test file must be generated.');
39
+
40
+ const generatedCode = fs.readFileSync(EXPECTED_TEST_PATH, 'utf8');
41
+ assert.ok(generatedCode.includes('TDD Contract Compliance Test Suite'), 'Test suite must contain header statement.');
42
+ assert.ok(generatedCode.includes("data.name, 'string'"), 'Test code must assert property name is string.');
43
+ assert.ok(generatedCode.includes("data.score, 'number'"), 'Test code must assert property score is number.');
44
+ assert.ok(generatedCode.includes('["name"]'), 'Test code must assert required fields list matches contract.');
45
+
46
+ console.log(' ✓ Test case passed: Integration test template compilation is 100% correct.');
47
+
48
+ } finally {
49
+ // Cleanup
50
+ if (fs.existsSync(TEST_RESPONSE_PATH)) {
51
+ fs.unlinkSync(TEST_RESPONSE_PATH);
52
+ }
53
+ if (fs.existsSync(TEST_CONTRACT_DIR)) {
54
+ fs.rmdirSync(TEST_CONTRACT_DIR);
55
+ }
56
+ if (fs.existsSync(EXPECTED_TEST_PATH)) {
57
+ fs.unlinkSync(EXPECTED_TEST_PATH);
58
+ }
59
+ }
60
+
61
+ console.log('All test_generator.js tests passed! ✓\n');
62
+ process.exit(0);