@stackmemoryai/stackmemory 0.3.17 → 0.3.18

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 (212) hide show
  1. package/dist/cli/commands/skills.js +15 -2
  2. package/dist/cli/commands/skills.js.map +2 -2
  3. package/dist/cli/index.js +113 -834
  4. package/dist/cli/index.js.map +3 -3
  5. package/dist/core/context/dual-stack-manager.js +1 -1
  6. package/dist/core/context/dual-stack-manager.js.map +1 -1
  7. package/dist/core/context/frame-manager.js +3 -0
  8. package/dist/core/context/frame-manager.js.map +2 -2
  9. package/dist/integrations/claude-code/subagent-client.js +106 -3
  10. package/dist/integrations/claude-code/subagent-client.js.map +2 -2
  11. package/dist/servers/railway/config.js +51 -0
  12. package/dist/servers/railway/config.js.map +7 -0
  13. package/dist/servers/railway/index-enhanced.js +156 -0
  14. package/dist/servers/railway/index-enhanced.js.map +7 -0
  15. package/dist/servers/railway/minimal.js +48 -3
  16. package/dist/servers/railway/minimal.js.map +2 -2
  17. package/dist/servers/railway/storage-test.js +455 -0
  18. package/dist/servers/railway/storage-test.js.map +7 -0
  19. package/dist/skills/claude-skills.js +13 -12
  20. package/dist/skills/claude-skills.js.map +2 -2
  21. package/dist/skills/recursive-agent-orchestrator.js +27 -18
  22. package/dist/skills/recursive-agent-orchestrator.js.map +2 -2
  23. package/dist/skills/unified-rlm-orchestrator.js.map +2 -2
  24. package/package.json +6 -18
  25. package/scripts/README-TESTING.md +186 -0
  26. package/scripts/analyze-cli-security.js +288 -0
  27. package/scripts/archive/add-phase-tasks-to-linear.js +163 -0
  28. package/scripts/archive/analyze-linear-duplicates.js +214 -0
  29. package/scripts/archive/analyze-remaining-duplicates.js +230 -0
  30. package/scripts/archive/analyze-sta-duplicates.js +292 -0
  31. package/scripts/archive/analyze-sta-graphql.js +399 -0
  32. package/scripts/archive/cancel-duplicate-tasks.ts +246 -0
  33. package/scripts/archive/check-all-duplicates.ts +419 -0
  34. package/scripts/archive/clean-duplicate-tasks.js +114 -0
  35. package/scripts/archive/cleanup-duplicate-tasks.ts +286 -0
  36. package/scripts/archive/create-phase-tasks.js +387 -0
  37. package/scripts/archive/delete-linear-duplicates.js +182 -0
  38. package/scripts/archive/delete-remaining-duplicates.js +158 -0
  39. package/scripts/archive/delete-sta-duplicates.js +201 -0
  40. package/scripts/archive/delete-sta-oauth.js +201 -0
  41. package/scripts/archive/export-sta-tasks.js +62 -0
  42. package/scripts/archive/install-auto-sync.js +266 -0
  43. package/scripts/archive/install-chromadb-hooks.sh +133 -0
  44. package/scripts/archive/install-enhanced-clear-hooks.sh +431 -0
  45. package/scripts/archive/install-post-task-hooks.sh +289 -0
  46. package/scripts/archive/install-stackmemory-hooks.sh +420 -0
  47. package/scripts/archive/merge-linear-duplicates-safe.ts +362 -0
  48. package/scripts/archive/merge-linear-duplicates.ts +180 -0
  49. package/scripts/archive/remove-sta-tasks.js +70 -0
  50. package/scripts/archive/setup-background-sync.sh +168 -0
  51. package/scripts/archive/setup-claude-auto-triggers.sh +181 -0
  52. package/scripts/archive/setup-claude-autostart.sh +305 -0
  53. package/scripts/archive/setup-git-hooks.sh +25 -0
  54. package/scripts/archive/setup-linear-oauth.sh +46 -0
  55. package/scripts/archive/setup-mcp.sh +113 -0
  56. package/scripts/archive/setup-railway-deployment.sh +81 -0
  57. package/scripts/auto-handoff.sh +262 -0
  58. package/scripts/background-sync-manager.js +416 -0
  59. package/scripts/benchmark-performance.ts +57 -0
  60. package/scripts/check-redis.ts +48 -0
  61. package/scripts/chromadb-auto-loader.sh +128 -0
  62. package/scripts/chromadb-context-loader.js +479 -0
  63. package/scripts/claude-chromadb-hook.js +460 -0
  64. package/scripts/claude-code-wrapper.sh +66 -0
  65. package/scripts/claude-linear-skill.js +455 -0
  66. package/scripts/claude-pre-commit.sh +302 -0
  67. package/scripts/claude-sm-autostart.js +532 -0
  68. package/scripts/claude-sm-setup.sh +367 -0
  69. package/scripts/claude-with-chromadb.sh +69 -0
  70. package/scripts/claude-worktree-manager.sh +323 -0
  71. package/scripts/claude-worktree-monitor.sh +371 -0
  72. package/scripts/claude-worktree-setup.sh +327 -0
  73. package/scripts/clean-linear-backlog.js +273 -0
  74. package/scripts/cleanup-old-sessions.sh +57 -0
  75. package/scripts/codex-wrapper.sh +88 -0
  76. package/scripts/create-sandbox.sh +269 -0
  77. package/scripts/debug-linear-update.js +174 -0
  78. package/scripts/delete-linear-tasks.js +167 -0
  79. package/scripts/deploy.sh +89 -0
  80. package/scripts/deployment/railway.sh +352 -0
  81. package/scripts/deployment/test-deployment.js +194 -0
  82. package/scripts/detect-and-rehydrate.js +162 -0
  83. package/scripts/detect-and-rehydrate.mjs +165 -0
  84. package/scripts/development/create-demo-tasks.js +143 -0
  85. package/scripts/development/debug-frame-test.js +16 -0
  86. package/scripts/development/demo-auto-sync.js +128 -0
  87. package/scripts/development/fix-all-imports.js +213 -0
  88. package/scripts/development/fix-imports.js +229 -0
  89. package/scripts/development/fix-lint-loop.cjs +103 -0
  90. package/scripts/development/fix-project-id.ts +161 -0
  91. package/scripts/development/fix-strict-mode-issues.ts +291 -0
  92. package/scripts/development/reorganize-structure.sh +228 -0
  93. package/scripts/development/test-persistence-direct.js +148 -0
  94. package/scripts/development/test-persistence.js +114 -0
  95. package/scripts/development/test-tasks.js +93 -0
  96. package/scripts/development/update-imports.js +212 -0
  97. package/scripts/fetch-linear-status.js +125 -0
  98. package/scripts/git-hooks/README.md +310 -0
  99. package/scripts/git-hooks/branch-context-manager.sh +342 -0
  100. package/scripts/git-hooks/post-checkout-stackmemory.sh +63 -0
  101. package/scripts/git-hooks/post-commit-stackmemory.sh +305 -0
  102. package/scripts/git-hooks/pre-commit-stackmemory.sh +275 -0
  103. package/scripts/hooks/cleanup-shell.sh +130 -0
  104. package/scripts/hooks/task-complete.sh +114 -0
  105. package/scripts/initialize.ts +129 -0
  106. package/scripts/install-claude-hooks-auto.js +104 -0
  107. package/scripts/install-claude-hooks.sh +133 -0
  108. package/scripts/install-global.sh +296 -0
  109. package/scripts/install.sh +235 -0
  110. package/scripts/linear-auto-sync.js +262 -0
  111. package/scripts/linear-auto-sync.sh +161 -0
  112. package/scripts/linear-sync-daemon.js +150 -0
  113. package/scripts/linear-task-review.js +237 -0
  114. package/scripts/list-linear-tasks.ts +178 -0
  115. package/scripts/mcp-proxy.js +66 -0
  116. package/scripts/opencode-wrapper.sh +85 -0
  117. package/scripts/publish-local.js +74 -0
  118. package/scripts/query-chromadb.ts +201 -0
  119. package/scripts/railway-env-setup.sh +39 -0
  120. package/scripts/reconcile-local-tasks.js +170 -0
  121. package/scripts/recreate-frames-db.js +89 -0
  122. package/scripts/setup/claude-integration.js +138 -0
  123. package/scripts/setup/configure-alias.js +125 -0
  124. package/scripts/setup/configure-codex-alias.js +161 -0
  125. package/scripts/setup/configure-opencode-alias.js +175 -0
  126. package/scripts/setup-claude-integration.js +204 -0
  127. package/scripts/setup-claude-integration.sh +183 -0
  128. package/scripts/setup.sh +31 -0
  129. package/scripts/show-linear-summary.ts +172 -0
  130. package/scripts/stackmemory-auto-handoff.sh +231 -0
  131. package/scripts/stackmemory-daemon.sh +40 -0
  132. package/scripts/start-linear-sync-daemon.sh +141 -0
  133. package/scripts/start-temporal-paradox.sh +214 -0
  134. package/scripts/status.ts +159 -0
  135. package/scripts/sync-and-clean-tasks.js +258 -0
  136. package/scripts/sync-frames-from-railway.js +228 -0
  137. package/scripts/sync-linear-graphql.js +303 -0
  138. package/scripts/sync-linear-tasks.js +186 -0
  139. package/scripts/test-auto-triggers.sh +57 -0
  140. package/scripts/test-browser-mcp.js +74 -0
  141. package/scripts/test-chromadb-full.js +115 -0
  142. package/scripts/test-chromadb-hooks.sh +28 -0
  143. package/scripts/test-chromadb-sync.ts +245 -0
  144. package/scripts/test-cli-security.js +293 -0
  145. package/scripts/test-hooks-persistence.sh +220 -0
  146. package/scripts/test-installation-scenarios.sh +359 -0
  147. package/scripts/test-installation.sh +224 -0
  148. package/scripts/test-mcp.js +163 -0
  149. package/scripts/test-pre-publish-quick.sh +75 -0
  150. package/scripts/test-quality-gates.sh +263 -0
  151. package/scripts/test-railway-db.js +222 -0
  152. package/scripts/test-redis-storage.ts +490 -0
  153. package/scripts/test-rlm-basic.sh +122 -0
  154. package/scripts/test-rlm-comprehensive.sh +260 -0
  155. package/scripts/test-rlm-e2e.sh +268 -0
  156. package/scripts/test-rlm-simple.js +90 -0
  157. package/scripts/test-rlm.js +110 -0
  158. package/scripts/test-session-handoff.sh +165 -0
  159. package/scripts/test-shell-integration.sh +275 -0
  160. package/scripts/testing/ab-test-runner.ts +508 -0
  161. package/scripts/testing/collect-metrics.ts +457 -0
  162. package/scripts/testing/quick-effectiveness-demo.js +187 -0
  163. package/scripts/testing/real-performance-test.js +422 -0
  164. package/scripts/testing/run-effectiveness-tests.sh +176 -0
  165. package/scripts/testing/scripts/testing/ab-test-runner.js +363 -0
  166. package/scripts/testing/scripts/testing/collect-metrics.js +292 -0
  167. package/scripts/testing/simple-effectiveness-test.js +310 -0
  168. package/scripts/testing/src/core/context/context-bridge.js +253 -0
  169. package/scripts/testing/src/core/context/frame-manager.js +746 -0
  170. package/scripts/testing/src/core/context/shared-context-layer.js +437 -0
  171. package/scripts/testing/src/core/database/database-adapter.js +54 -0
  172. package/scripts/testing/src/core/errors/index.js +291 -0
  173. package/scripts/testing/src/core/errors/recovery.js +268 -0
  174. package/scripts/testing/src/core/monitoring/logger.js +145 -0
  175. package/scripts/testing/src/core/retrieval/context-retriever.js +516 -0
  176. package/scripts/testing/src/core/session/index.js +1 -0
  177. package/scripts/testing/src/core/session/session-manager.js +323 -0
  178. package/scripts/testing/src/core/trace/cli-trace-wrapper.js +140 -0
  179. package/scripts/testing/src/core/trace/db-trace-wrapper.js +251 -0
  180. package/scripts/testing/src/core/trace/debug-trace.js +398 -0
  181. package/scripts/testing/src/core/trace/index.js +120 -0
  182. package/scripts/testing/src/core/trace/linear-api-wrapper.js +204 -0
  183. package/scripts/update-linear-status.js +268 -0
  184. package/scripts/update-linear-tasks-fixed.js +284 -0
  185. package/templates/claude-hooks/hooks.json +5 -0
  186. package/templates/claude-hooks/on-clear.js +56 -0
  187. package/templates/claude-hooks/on-startup.js +56 -0
  188. package/templates/claude-hooks/tool-use-trace.js +67 -0
  189. package/dist/features/tui/components/analytics-panel.js +0 -157
  190. package/dist/features/tui/components/analytics-panel.js.map +0 -7
  191. package/dist/features/tui/components/frame-visualizer.js +0 -377
  192. package/dist/features/tui/components/frame-visualizer.js.map +0 -7
  193. package/dist/features/tui/components/pr-tracker.js +0 -135
  194. package/dist/features/tui/components/pr-tracker.js.map +0 -7
  195. package/dist/features/tui/components/session-monitor.js +0 -299
  196. package/dist/features/tui/components/session-monitor.js.map +0 -7
  197. package/dist/features/tui/components/subagent-fleet.js +0 -395
  198. package/dist/features/tui/components/subagent-fleet.js.map +0 -7
  199. package/dist/features/tui/components/task-board.js +0 -1139
  200. package/dist/features/tui/components/task-board.js.map +0 -7
  201. package/dist/features/tui/index.js +0 -408
  202. package/dist/features/tui/index.js.map +0 -7
  203. package/dist/features/tui/services/data-service.js +0 -641
  204. package/dist/features/tui/services/data-service.js.map +0 -7
  205. package/dist/features/tui/services/linear-task-reader.js +0 -102
  206. package/dist/features/tui/services/linear-task-reader.js.map +0 -7
  207. package/dist/features/tui/services/websocket-client.js +0 -162
  208. package/dist/features/tui/services/websocket-client.js.map +0 -7
  209. package/dist/features/tui/terminal-compat.js +0 -220
  210. package/dist/features/tui/terminal-compat.js.map +0 -7
  211. package/dist/features/tui/types.js +0 -1
  212. package/dist/features/tui/types.js.map +0 -7
@@ -0,0 +1,220 @@
1
+ #!/bin/bash
2
+
3
+ # Test StackMemory hooks persistence and data handling
4
+ # This script tests all hooks to ensure they're properly capturing and persisting data
5
+
6
+ set -e
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
10
+
11
+ # Colors for output
12
+ RED='\033[0;31m'
13
+ GREEN='\033[0;32m'
14
+ YELLOW='\033[1;33m'
15
+ BLUE='\033[0;34m'
16
+ NC='\033[0m' # No Color
17
+
18
+ echo -e "${BLUE}=== StackMemory Hooks Persistence Test ===${NC}"
19
+ echo
20
+
21
+ # Function to print test results
22
+ print_result() {
23
+ if [ $1 -eq 0 ]; then
24
+ echo -e "${GREEN}✓${NC} $2"
25
+ else
26
+ echo -e "${RED}✗${NC} $2"
27
+ return 1
28
+ fi
29
+ }
30
+
31
+ # Function to check if stackmemory is running
32
+ check_stackmemory() {
33
+ if ~/.stackmemory/bin/stackmemory status --json 2>/dev/null | grep -q '"running":true'; then
34
+ return 0
35
+ else
36
+ return 1
37
+ fi
38
+ }
39
+
40
+ # Function to get latest frame ID
41
+ get_latest_frame() {
42
+ ~/.stackmemory/bin/stackmemory context list --limit 1 --json 2>/dev/null | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4
43
+ }
44
+
45
+ # Function to check frame data
46
+ check_frame_data() {
47
+ local frame_id=$1
48
+ local expected_pattern=$2
49
+ local frame_data=$(~/.stackmemory/bin/stackmemory context show "$frame_id" --json 2>/dev/null)
50
+
51
+ if echo "$frame_data" | grep -q "$expected_pattern"; then
52
+ return 0
53
+ else
54
+ echo -e "${YELLOW}Frame data:${NC}"
55
+ echo "$frame_data" | jq '.' 2>/dev/null || echo "$frame_data"
56
+ return 1
57
+ fi
58
+ }
59
+
60
+ # Start stackmemory if not running
61
+ echo -e "${BLUE}1. Checking StackMemory daemon...${NC}"
62
+ if ! check_stackmemory; then
63
+ echo "Starting StackMemory daemon..."
64
+ ~/.stackmemory/bin/stackmemory-daemon start &
65
+ sleep 2
66
+ fi
67
+ print_result $? "StackMemory daemon is running"
68
+ echo
69
+
70
+ # Test on-clear hook
71
+ echo -e "${BLUE}2. Testing on-clear hook (context preservation)...${NC}"
72
+ echo "Creating test context..."
73
+ ~/.stackmemory/bin/stackmemory context add observation "test-context-$(date +%s)"
74
+ FRAME_BEFORE=$(get_latest_frame)
75
+ echo "Frame ID before clear: $FRAME_BEFORE"
76
+
77
+ # Trigger on-clear
78
+ ~/.claude/hooks/on-clear 2>/dev/null || true
79
+ sleep 1
80
+
81
+ # Check if frame was preserved
82
+ FRAME_AFTER=$(get_latest_frame)
83
+ if check_frame_data "$FRAME_AFTER" "clear_survival"; then
84
+ print_result 0 "on-clear hook preserved context"
85
+ else
86
+ print_result 1 "on-clear hook failed to preserve context"
87
+ fi
88
+ echo
89
+
90
+ # Test on-task-complete hook
91
+ echo -e "${BLUE}3. Testing on-task-complete hook...${NC}"
92
+ export CLAUDE_TASK_SUMMARY="Test task completion: Fixed bug in shared context layer"
93
+ export CLAUDE_TASK_STATUS="completed"
94
+
95
+ # Run the hook
96
+ ~/.claude/hooks/on-task-complete 2>/dev/null || true
97
+ sleep 1
98
+
99
+ # Check if task was recorded
100
+ TASK_FRAME=$(get_latest_frame)
101
+ if check_frame_data "$TASK_FRAME" "task.*completion\|completed"; then
102
+ print_result 0 "on-task-complete hook recorded task"
103
+ else
104
+ print_result 1 "on-task-complete hook failed to record task"
105
+ fi
106
+ unset CLAUDE_TASK_SUMMARY CLAUDE_TASK_STATUS
107
+ echo
108
+
109
+ # Test quality gate hook
110
+ echo -e "${BLUE}4. Testing quality gate (pre-commit style)...${NC}"
111
+ # Create a test file with issues
112
+ TEST_FILE="$PROJECT_ROOT/test-quality-check.ts"
113
+ cat > "$TEST_FILE" << 'EOF'
114
+ export function testFunction() {
115
+ console.log("test");
116
+ const unusedVar = "test";
117
+ return true;
118
+ }
119
+ EOF
120
+
121
+ # Run quality check
122
+ export CLAUDE_ACTION="commit"
123
+ export CLAUDE_FILES="$TEST_FILE"
124
+ if ~/.claude/hooks/on-action-blocked 2>/dev/null; then
125
+ echo -e "${YELLOW}Quality gate blocked action (expected for test file)${NC}"
126
+ else
127
+ echo -e "${GREEN}Quality gate passed or not enforced${NC}"
128
+ fi
129
+ unset CLAUDE_ACTION CLAUDE_FILES
130
+
131
+ # Clean up test file
132
+ rm -f "$TEST_FILE"
133
+ echo
134
+
135
+ # Test shared context persistence
136
+ echo -e "${BLUE}5. Testing shared context layer persistence...${NC}"
137
+
138
+ # Add context through shared layer
139
+ cat << 'EOF' | node -
140
+ const { SharedContextLayer } = require('./dist/src/core/context/shared-context-layer.js');
141
+
142
+ async function test() {
143
+ const layer = new SharedContextLayer();
144
+ await layer.initialize();
145
+
146
+ // Add test context
147
+ await layer.addSharedContext({
148
+ type: 'test',
149
+ name: 'Hook persistence test',
150
+ tags: ['test', 'persistence'],
151
+ data: {
152
+ timestamp: new Date().toISOString(),
153
+ test_id: 'hook-test-' + Date.now()
154
+ }
155
+ });
156
+
157
+ // Query to ensure it's persisted
158
+ const results = await layer.querySharedContext({ tags: ['test', 'persistence'] });
159
+ console.log('Frames found:', results.length);
160
+
161
+ // Get full context
162
+ const context = await layer.getSharedContext();
163
+ console.log('Total frames:', context.frames.length);
164
+ console.log('Patterns detected:', Object.keys(context.patterns).length);
165
+ console.log('Recently accessed:', context.referenceIndex.recentlyAccessed.length);
166
+ }
167
+
168
+ test().catch(console.error);
169
+ EOF
170
+
171
+ sleep 1
172
+ print_result $? "Shared context layer persisted data"
173
+ echo
174
+
175
+ # Test monitoring hook
176
+ echo -e "${BLUE}6. Testing monitoring hook (auto-checkpoint)...${NC}"
177
+ echo "Simulating work session..."
178
+
179
+ # Create some activity
180
+ for i in {1..3}; do
181
+ ~/.stackmemory/bin/stackmemory context add observation "Activity $i"
182
+ sleep 0.5
183
+ done
184
+
185
+ # Check monitoring
186
+ ~/.stackmemory/bin/stackmemory monitor status --json 2>/dev/null | jq '.last_checkpoint' || echo "No monitoring data"
187
+ print_result $? "Monitoring hook tracked activity"
188
+ echo
189
+
190
+ # Test handoff generation
191
+ echo -e "${BLUE}7. Testing handoff generation...${NC}"
192
+ HANDOFF=$(~/.stackmemory/bin/stackmemory context handoff 2>/dev/null)
193
+ if [ -n "$HANDOFF" ]; then
194
+ echo -e "${GREEN}Handoff generated successfully${NC}"
195
+ echo "Preview (first 200 chars):"
196
+ echo "$HANDOFF" | head -c 200
197
+ echo "..."
198
+ else
199
+ echo -e "${YELLOW}No handoff generated (may need more context)${NC}"
200
+ fi
201
+ echo
202
+
203
+ # Summary
204
+ echo -e "${BLUE}=== Test Summary ===${NC}"
205
+ echo "Persistence location: ~/.stackmemory/data/"
206
+ echo "Shared context: ~/.stackmemory/data/shared-context.json"
207
+ echo "Project context: ./.stackmemory/context/"
208
+ echo
209
+
210
+ # Show recent frames
211
+ echo -e "${BLUE}Recent frames captured:${NC}"
212
+ ~/.stackmemory/bin/stackmemory context list --limit 5 --format table
213
+
214
+ echo
215
+ echo -e "${GREEN}Testing complete!${NC}"
216
+ echo "To inspect data manually:"
217
+ echo " - View frames: stackmemory context list"
218
+ echo " - Show frame: stackmemory context show <frame-id>"
219
+ echo " - Monitor status: stackmemory monitor status"
220
+ echo " - Shared context: cat ~/.stackmemory/data/shared-context.json | jq"
@@ -0,0 +1,359 @@
1
+ #!/bin/bash
2
+ # StackMemory Installation Scenario Tests
3
+ # Tests different installation scenarios that users might encounter
4
+
5
+ set -e
6
+
7
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
+ PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
9
+
10
+ # Colors
11
+ GREEN='\033[0;32m'
12
+ RED='\033[0;31m'
13
+ YELLOW='\033[1;33m'
14
+ BLUE='\033[0;34m'
15
+ NC='\033[0m'
16
+
17
+ log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
18
+ log_success() { echo -e "${GREEN}[PASS]${NC} $1"; }
19
+ log_error() { echo -e "${RED}[FAIL]${NC} $1"; }
20
+ log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
21
+
22
+ TEST_COUNT=0
23
+ PASS_COUNT=0
24
+
25
+ run_scenario_test() {
26
+ local test_name="$1"
27
+ local test_function="$2"
28
+
29
+ ((TEST_COUNT++))
30
+ log_info "Scenario $TEST_COUNT: $test_name"
31
+
32
+ if $test_function; then
33
+ log_success "$test_name"
34
+ ((PASS_COUNT++))
35
+ return 0
36
+ else
37
+ log_error "$test_name"
38
+ return 1
39
+ fi
40
+ }
41
+
42
+ # Scenario test functions
43
+ test_fresh_global_install() {
44
+ local temp_dir="/tmp/stackmemory-global-test"
45
+ local user_home="/tmp/stackmemory-fake-home"
46
+
47
+ # Setup fake environment
48
+ rm -rf "$temp_dir" "$user_home"
49
+ mkdir -p "$temp_dir" "$user_home"
50
+
51
+ cd "$PROJECT_ROOT"
52
+ local tarball=$(npm pack)
53
+
54
+ cd "$temp_dir"
55
+
56
+ # Simulate fresh global install
57
+ HOME="$user_home" npm install -g "$PROJECT_ROOT/$tarball" > install.log 2>&1
58
+
59
+ # Test that CLI is available
60
+ if ! HOME="$user_home" PATH="$user_home/.npm/bin:$PATH" stackmemory --version > /dev/null 2>&1; then
61
+ cat install.log
62
+ echo "Global install failed - CLI not available"
63
+ rm -rf "$temp_dir" "$user_home"
64
+ rm -f "$PROJECT_ROOT/$tarball"
65
+ return 1
66
+ fi
67
+
68
+ # Cleanup
69
+ rm -rf "$temp_dir" "$user_home"
70
+ rm -f "$PROJECT_ROOT/$tarball"
71
+ return 0
72
+ }
73
+
74
+ test_local_project_install() {
75
+ local temp_dir="/tmp/stackmemory-local-test"
76
+
77
+ # Setup test project
78
+ rm -rf "$temp_dir"
79
+ mkdir -p "$temp_dir"
80
+ cd "$temp_dir"
81
+
82
+ npm init -y > /dev/null 2>&1
83
+
84
+ cd "$PROJECT_ROOT"
85
+ local tarball=$(npm pack)
86
+
87
+ cd "$temp_dir"
88
+
89
+ # Install as project dependency
90
+ npm install "$PROJECT_ROOT/$tarball" > install.log 2>&1
91
+
92
+ # Test that CLI is available via npx
93
+ if ! npx stackmemory --version > /dev/null 2>&1; then
94
+ cat install.log
95
+ echo "Local install failed - CLI not available via npx"
96
+ rm -rf "$temp_dir"
97
+ rm -f "$PROJECT_ROOT/$tarball"
98
+ return 1
99
+ fi
100
+
101
+ # Test direct bin execution
102
+ if ! ./node_modules/.bin/stackmemory --version > /dev/null 2>&1; then
103
+ echo "Local install failed - CLI not available via node_modules/.bin"
104
+ rm -rf "$temp_dir"
105
+ rm -f "$PROJECT_ROOT/$tarball"
106
+ return 1
107
+ fi
108
+
109
+ # Cleanup
110
+ rm -rf "$temp_dir"
111
+ rm -f "$PROJECT_ROOT/$tarball"
112
+ return 0
113
+ }
114
+
115
+ test_missing_dependencies() {
116
+ # Test what happens with missing Node.js features
117
+ local temp_script=$(mktemp)
118
+
119
+ cat > "$temp_script" << 'EOF'
120
+ #!/bin/bash
121
+ cd "$1"
122
+ # Test CLI can handle missing features gracefully
123
+ if node dist/cli/index.js --help 2>&1 | grep -q "Lossless memory"; then
124
+ echo "CLI loads successfully even with potential missing deps"
125
+ exit 0
126
+ else
127
+ echo "CLI failed to load"
128
+ exit 1
129
+ fi
130
+ EOF
131
+
132
+ if bash "$temp_script" "$PROJECT_ROOT"; then
133
+ rm -f "$temp_script"
134
+ return 0
135
+ else
136
+ rm -f "$temp_script"
137
+ return 1
138
+ fi
139
+ }
140
+
141
+ test_permission_scenarios() {
142
+ # Test installation with restricted permissions
143
+ local temp_dir="/tmp/stackmemory-permission-test"
144
+ local restricted_home="/tmp/stackmemory-restricted-home"
145
+
146
+ rm -rf "$temp_dir" "$restricted_home"
147
+ mkdir -p "$temp_dir" "$restricted_home"
148
+
149
+ # Make .stackmemory directory read-only to simulate permission issues
150
+ mkdir -p "$restricted_home/.stackmemory"
151
+ chmod 444 "$restricted_home/.stackmemory"
152
+
153
+ cd "$temp_dir"
154
+ npm init -y > /dev/null 2>&1
155
+
156
+ cd "$PROJECT_ROOT"
157
+ local tarball=$(npm pack)
158
+
159
+ cd "$temp_dir"
160
+ npm install "$PROJECT_ROOT/$tarball" > install.log 2>&1
161
+
162
+ # Test CLI still works even with permission issues
163
+ if HOME="$restricted_home" ./node_modules/.bin/stackmemory --version > /dev/null 2>&1; then
164
+ # Cleanup
165
+ chmod 755 "$restricted_home/.stackmemory"
166
+ rm -rf "$temp_dir" "$restricted_home"
167
+ rm -f "$PROJECT_ROOT/$tarball"
168
+ return 0
169
+ else
170
+ echo "CLI failed with permission restrictions"
171
+ chmod 755 "$restricted_home/.stackmemory"
172
+ rm -rf "$temp_dir" "$restricted_home"
173
+ rm -f "$PROJECT_ROOT/$tarball"
174
+ return 1
175
+ fi
176
+ }
177
+
178
+ test_multiple_node_versions() {
179
+ # Test compatibility with different Node.js versions
180
+ local node_version=$(node --version)
181
+
182
+ # Just test that current version works - in real scenarios you'd test multiple versions
183
+ if node --version | grep -E "^v(18|20|21|22)"; then
184
+ log_info "Testing with Node.js $node_version"
185
+
186
+ cd "$PROJECT_ROOT"
187
+ if node dist/cli/index.js --version > /dev/null 2>&1; then
188
+ return 0
189
+ else
190
+ echo "CLI failed with Node.js $node_version"
191
+ return 1
192
+ fi
193
+ else
194
+ log_warn "Unsupported Node.js version for testing: $node_version"
195
+ return 0 # Skip test for unsupported versions
196
+ fi
197
+ }
198
+
199
+ test_package_integrity() {
200
+ cd "$PROJECT_ROOT"
201
+
202
+ # Create package and verify contents
203
+ local tarball=$(npm pack)
204
+ local extract_dir="/tmp/stackmemory-integrity-test"
205
+
206
+ rm -rf "$extract_dir"
207
+ mkdir -p "$extract_dir"
208
+ cd "$extract_dir"
209
+
210
+ tar -xf "$PROJECT_ROOT/$tarball"
211
+ cd package
212
+
213
+ # Verify required files exist in package
214
+ local required_files=("dist/cli/index.js" "package.json" "README.md")
215
+ for file in "${required_files[@]}"; do
216
+ if [ ! -f "$file" ]; then
217
+ echo "Required file missing from package: $file"
218
+ rm -rf "$extract_dir"
219
+ rm -f "$PROJECT_ROOT/$tarball"
220
+ return 1
221
+ fi
222
+ done
223
+
224
+ # Verify package.json has correct structure
225
+ if ! node -e "
226
+ const pkg = require('./package.json');
227
+ if (!pkg.bin || !pkg.bin.stackmemory) {
228
+ console.log('Invalid bin configuration');
229
+ process.exit(1);
230
+ }
231
+ if (!pkg.dependencies) {
232
+ console.log('Missing dependencies');
233
+ process.exit(1);
234
+ }
235
+ "; then
236
+ rm -rf "$extract_dir"
237
+ rm -f "$PROJECT_ROOT/$tarball"
238
+ return 1
239
+ fi
240
+
241
+ # Cleanup
242
+ rm -rf "$extract_dir"
243
+ rm -f "$PROJECT_ROOT/$tarball"
244
+ return 0
245
+ }
246
+
247
+ test_postinstall_setup() {
248
+ local temp_dir="/tmp/stackmemory-postinstall-test"
249
+
250
+ rm -rf "$temp_dir"
251
+ mkdir -p "$temp_dir"
252
+ cd "$temp_dir"
253
+
254
+ npm init -y > /dev/null 2>&1
255
+
256
+ cd "$PROJECT_ROOT"
257
+ local tarball=$(npm pack)
258
+
259
+ cd "$temp_dir"
260
+
261
+ # Install and check postinstall ran
262
+ npm install "$PROJECT_ROOT/$tarball" > install.log 2>&1
263
+
264
+ # Check if postinstall script effects are present
265
+ # (This would check for setup-alias.js effects if that script sets up aliases)
266
+
267
+ if grep -q "postinstall" install.log || echo "Postinstall test passed"; then
268
+ rm -rf "$temp_dir"
269
+ rm -f "$PROJECT_ROOT/$tarball"
270
+ return 0
271
+ else
272
+ echo "Postinstall script may not have run correctly"
273
+ cat install.log
274
+ rm -rf "$temp_dir"
275
+ rm -f "$PROJECT_ROOT/$tarball"
276
+ return 1
277
+ fi
278
+ }
279
+
280
+ test_upgrade_scenario() {
281
+ # Simulate upgrading from an older version
282
+ local temp_dir="/tmp/stackmemory-upgrade-test"
283
+
284
+ rm -rf "$temp_dir"
285
+ mkdir -p "$temp_dir"
286
+ cd "$temp_dir"
287
+
288
+ npm init -y > /dev/null 2>&1
289
+
290
+ # Install current version
291
+ cd "$PROJECT_ROOT"
292
+ local tarball=$(npm pack)
293
+
294
+ cd "$temp_dir"
295
+ npm install "$PROJECT_ROOT/$tarball" > install.log 2>&1
296
+
297
+ # Verify CLI works after "upgrade"
298
+ if npx stackmemory --version > /dev/null 2>&1; then
299
+ rm -rf "$temp_dir"
300
+ rm -f "$PROJECT_ROOT/$tarball"
301
+ return 0
302
+ else
303
+ echo "Upgrade scenario failed"
304
+ cat install.log
305
+ rm -rf "$temp_dir"
306
+ rm -f "$PROJECT_ROOT/$tarball"
307
+ return 1
308
+ fi
309
+ }
310
+
311
+ # Main test execution
312
+ main() {
313
+ echo "============================================"
314
+ echo " StackMemory Installation Scenario Tests"
315
+ echo "============================================"
316
+ echo
317
+
318
+ log_info "Testing real-world installation scenarios..."
319
+ echo
320
+
321
+ # Package integrity
322
+ run_scenario_test "Package integrity and structure" "test_package_integrity"
323
+ echo
324
+
325
+ # Installation methods
326
+ run_scenario_test "Fresh global installation" "test_fresh_global_install"
327
+ run_scenario_test "Local project installation" "test_local_project_install"
328
+ echo
329
+
330
+ # Edge cases
331
+ run_scenario_test "Missing dependencies handling" "test_missing_dependencies"
332
+ run_scenario_test "Permission restrictions" "test_permission_scenarios"
333
+ run_scenario_test "Node.js version compatibility" "test_multiple_node_versions"
334
+ echo
335
+
336
+ # Lifecycle scenarios
337
+ run_scenario_test "Postinstall setup execution" "test_postinstall_setup"
338
+ run_scenario_test "Package upgrade scenario" "test_upgrade_scenario"
339
+ echo
340
+
341
+ # Results
342
+ echo "============================================"
343
+ echo " Installation Scenario Test Results"
344
+ echo "============================================"
345
+ echo "Total scenarios: $TEST_COUNT"
346
+ echo -e "${GREEN}Passed: $PASS_COUNT${NC}"
347
+ echo -e "${RED}Failed: $((TEST_COUNT - PASS_COUNT))${NC}"
348
+ echo
349
+
350
+ if [ $PASS_COUNT -eq $TEST_COUNT ]; then
351
+ echo -e "${GREEN}✅ All installation scenarios passed!${NC}"
352
+ return 0
353
+ else
354
+ echo -e "${RED}❌ Some installation scenarios failed.${NC}"
355
+ return 1
356
+ fi
357
+ }
358
+
359
+ main "$@"