bulltrackers-module 1.0.750 → 1.0.751

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.
@@ -31,7 +31,10 @@ async function adminTestHandler(req, res) {
31
31
  limit = 10,
32
32
  force = true, // Default to force for testing
33
33
  useWorkerPool, // Override: true/false/undefined (use config)
34
- dryRun = false
34
+ dryRun = false,
35
+ // [NEW] Accept override parameters for infrastructure testing
36
+ outputTable, // e.g., "computation_results_test"
37
+ workerUrl // e.g., "https://...cloudfunctions.net/worker-test"
35
38
  } = req.body || {};
36
39
 
37
40
  console.log(`[AdminTest] Action: ${action}, Computation: ${computation}, Date: ${date}`);
@@ -93,38 +96,59 @@ async function adminTestHandler(req, res) {
93
96
  });
94
97
  }
95
98
 
96
- // Log worker pool override if specified
97
- if (useWorkerPool !== undefined) {
98
- console.log(`[AdminTest] Worker pool override: ${useWorkerPool ? 'ENABLED' : 'DISABLED'}`);
99
+ // Prepare Config Overrides
100
+ // We create this here so we can log what's happening
101
+ const baseConfig = system.config;
102
+ let customConfig = null;
103
+
104
+ // Check if we need to modify the configuration
105
+ if (outputTable || useWorkerPool !== undefined || workerUrl) {
106
+ customConfig = { ...baseConfig }; // Shallow copy
107
+
108
+ // 1. Override Output Table
109
+ if (outputTable) {
110
+ console.log(`[AdminTest] ⚠️ Redirecting output to: ${outputTable}`);
111
+ // Fix for TS Error: Ensure baseConfig.resultStore exists before spreading
112
+ const baseStore = baseConfig.resultStore;
113
+ if (!baseStore) {
114
+ throw new Error("System config is missing 'resultStore'");
115
+ }
116
+
117
+ customConfig.resultStore = {
118
+ ...baseStore,
119
+ table: outputTable
120
+ };
121
+ }
122
+
123
+ // 2. Override Worker Pool Settings
124
+ if (useWorkerPool !== undefined || workerUrl) {
125
+ const basePool = baseConfig.workerPool || {};
126
+ customConfig.workerPool = {
127
+ ...basePool,
128
+ // If useWorkerPool is explicitly provided, use it. Otherwise keep existing.
129
+ enabled: useWorkerPool !== undefined ? useWorkerPool : basePool.enabled,
130
+ // If workerUrl provided, override it.
131
+ workerUrl: workerUrl || basePool.workerUrl
132
+ };
133
+
134
+ // Log the override state
135
+ console.log(`[AdminTest] Worker Pool Override: Enabled=${customConfig.workerPool.enabled}, URL=${customConfig.workerPool.workerUrl || 'default'}`);
136
+ }
99
137
  }
100
138
 
101
139
  console.log(`[AdminTest] Running ${computation} for ${date}...`);
102
140
  console.log(`[AdminTest] Options: force=${force}, dryRun=${dryRun}, entityIds=${entityIds?.join(',') || 'all'}`);
103
141
 
104
- // Prepare run options
105
142
  const runOptions = {
106
143
  date,
107
144
  computation,
108
145
  entityIds: entityIds || null,
109
146
  dryRun,
110
147
  force,
111
- useWorkerPool
148
+ useWorkerPool,
149
+ config: customConfig // Inject the modified config
112
150
  };
113
151
 
114
- // [FIX] If forcing worker pool, inject config to enable it dynamically
115
- // This prevents Orchestrator from ignoring the request if default config has enabled: false
116
- if (useWorkerPool) {
117
- const baseConfig = system.config;
118
- runOptions.config = {
119
- ...baseConfig,
120
- workerPool: {
121
- ...(baseConfig.workerPool || {}),
122
- enabled: true
123
- }
124
- };
125
- console.log('[AdminTest] Injecting config to FORCE enable RemoteTaskRunner');
126
- }
127
-
128
152
  const result = await system.runComputation(runOptions);
129
153
 
130
154
  const duration = Date.now() - startTime;
@@ -169,27 +193,39 @@ async function adminTestHandler(req, res) {
169
193
 
170
194
  console.log(`[AdminTest] Running LIMITED test: ${sampleEntities.length} entities`);
171
195
 
196
+ // Prepare Config Overrides (Same logic as 'run')
197
+ const baseConfig = system.config;
198
+ let customConfig = null;
199
+
200
+ if (outputTable || useWorkerPool !== undefined || workerUrl) {
201
+ customConfig = { ...baseConfig };
202
+
203
+ if (outputTable) {
204
+ const baseStore = baseConfig.resultStore;
205
+ if (!baseStore) throw new Error("System config missing 'resultStore'");
206
+ customConfig.resultStore = { ...baseStore, table: outputTable };
207
+ }
208
+
209
+ if (useWorkerPool !== undefined || workerUrl) {
210
+ const basePool = baseConfig.workerPool || {};
211
+ customConfig.workerPool = {
212
+ ...basePool,
213
+ enabled: useWorkerPool !== undefined ? useWorkerPool : basePool.enabled,
214
+ workerUrl: workerUrl || basePool.workerUrl
215
+ };
216
+ }
217
+ }
218
+
172
219
  const runOptions = {
173
220
  date,
174
221
  computation,
175
222
  entityIds: sampleEntities,
176
223
  dryRun,
177
224
  force,
178
- useWorkerPool
225
+ useWorkerPool,
226
+ config: customConfig
179
227
  };
180
228
 
181
- // Apply the same fix for run_limited if needed
182
- if (useWorkerPool) {
183
- const baseConfig = system.config;
184
- runOptions.config = {
185
- ...baseConfig,
186
- workerPool: {
187
- ...(baseConfig.workerPool || {}),
188
- enabled: true
189
- }
190
- };
191
- }
192
-
193
229
  const result = await system.runComputation(runOptions);
194
230
 
195
231
  const duration = Date.now() - startTime;
@@ -0,0 +1,183 @@
1
+ #!/bin/bash
2
+
3
+ # ==============================================================================
4
+ # Admin Test Endpoint Interactive Tool
5
+ # Automates the admin.md testing procedures
6
+ # ==============================================================================
7
+
8
+ # Default Settings
9
+ REGION="europe-west1"
10
+ FUNCTION_NAME="compute-admin-test"
11
+ DEFAULT_DATE=$(date +%Y-%m-%d)
12
+
13
+ # Colors
14
+ GREEN='\033[0;32m'
15
+ BLUE='\033[0;34m'
16
+ YELLOW='\033[1;33m'
17
+ RED='\033[0;31m'
18
+ NC='\033[0m' # No Color
19
+
20
+ echo -e "${BLUE}=================================================${NC}"
21
+ echo -e "${BLUE} BullTrackers Admin Test Interactive Tool ${NC}"
22
+ echo -e "${BLUE}=================================================${NC}"
23
+
24
+ # ------------------------------------------------------------------------------
25
+ # 1. Setup & Auth
26
+ # ------------------------------------------------------------------------------
27
+ echo -e "\n${YELLOW}[Setup] Retrieving Function URL and Auth Token...${NC}"
28
+
29
+ # Get Function URL
30
+ FUNCTION_URL=$(gcloud functions describe $FUNCTION_NAME \
31
+ --region=$REGION \
32
+ --format="value(serviceConfig.uri)" 2>/dev/null)
33
+
34
+ if [ -z "$FUNCTION_URL" ]; then
35
+ echo -e "${RED}[Error] Could not retrieve Function URL for '$FUNCTION_NAME' in '$REGION'.${NC}"
36
+ echo "Please ensure you are authenticated (gcloud auth login) and the function is deployed."
37
+ exit 1
38
+ fi
39
+
40
+ # Get Identity Token
41
+ TOKEN=$(gcloud auth print-identity-token 2>/dev/null)
42
+
43
+ if [ -z "$TOKEN" ]; then
44
+ echo -e "${RED}[Error] Could not generate Identity Token.${NC}"
45
+ echo "Please run: gcloud auth login"
46
+ exit 1
47
+ fi
48
+
49
+ echo -e "${GREEN}[Success] Target: $FUNCTION_URL${NC}"
50
+
51
+ # ------------------------------------------------------------------------------
52
+ # 2. Helper Functions
53
+ # ------------------------------------------------------------------------------
54
+
55
+ # Function to prompt for variables with defaults
56
+ ask_var() {
57
+ local prompt="$1"
58
+ local default="$2"
59
+ local var_name="$3"
60
+
61
+ echo -ne "$prompt [${GREEN}$default${NC}]: "
62
+ read input
63
+ if [ -z "$input" ]; then
64
+ eval $var_name="$default"
65
+ else
66
+ eval $var_name="$input"
67
+ fi
68
+ }
69
+
70
+ # Function to execute the curl command
71
+ run_test() {
72
+ local json_payload="$1"
73
+
74
+ echo -e "\n${YELLOW}[Executing] Sending Request...${NC}"
75
+ echo -e "Payload: $json_payload"
76
+
77
+ curl -X POST "$FUNCTION_URL" \
78
+ -H "Authorization: Bearer $TOKEN" \
79
+ -H "Content-Type: application/json" \
80
+ -d "$json_payload"
81
+
82
+ echo -e "\n${BLUE}[Done]${NC}"
83
+ }
84
+
85
+ # ------------------------------------------------------------------------------
86
+ # 3. Interactive Menu
87
+ # ------------------------------------------------------------------------------
88
+
89
+ while true; do
90
+ echo -e "\n${BLUE}Select an Action:${NC}"
91
+ echo "1) System Status (status)"
92
+ echo "2) Analyze Schedule (analyze)"
93
+ echo "3) Run Full Computation (run)"
94
+ echo "4) Run Limited Test (run_limited - safer)"
95
+ echo "5) Test Specific Entities (run with entityIds)"
96
+ echo "6) Test Worker Logic Directly (test_worker)"
97
+ echo "7) Test Worker Pool Offloading (run with useWorkerPool)"
98
+ echo "q) Quit"
99
+
100
+ read -p "Enter choice: " choice
101
+
102
+ case $choice in
103
+ 1)
104
+ # Status
105
+ run_test '{"action": "status"}'
106
+ ;;
107
+
108
+ 2)
109
+ # Analyze
110
+ ask_var "Enter Date" "$DEFAULT_DATE" "TARGET_DATE"
111
+ run_test "{\"action\": \"analyze\", \"date\": \"$TARGET_DATE\"}"
112
+ ;;
113
+
114
+ 3)
115
+ # Run Full
116
+ ask_var "Enter Computation Name" "UserPortfolioSummary" "COMP_NAME"
117
+ ask_var "Enter Date" "$DEFAULT_DATE" "TARGET_DATE"
118
+
119
+ # Confirm dangerous action
120
+ echo -e "${RED}WARNING: This will run '$COMP_NAME' for ALL entities.${NC}"
121
+ read -p "Are you sure? (y/N): " confirm
122
+ if [[ $confirm == "y" || $confirm == "Y" ]]; then
123
+ run_test "{\"action\": \"run\", \"computation\": \"$COMP_NAME\", \"date\": \"$TARGET_DATE\", \"force\": true}"
124
+ else
125
+ echo "Cancelled."
126
+ fi
127
+ ;;
128
+
129
+ 4)
130
+ # Run Limited
131
+ ask_var "Enter Computation Name" "UserPortfolioSummary" "COMP_NAME"
132
+ ask_var "Enter Date" "$DEFAULT_DATE" "TARGET_DATE"
133
+ ask_var "Enter Limit (Num Entities)" "5" "LIMIT_NUM"
134
+
135
+ run_test "{\"action\": \"run_limited\", \"computation\": \"$COMP_NAME\", \"date\": \"$TARGET_DATE\", \"limit\": $LIMIT_NUM}"
136
+ ;;
137
+
138
+ 5)
139
+ # Test Entities
140
+ ask_var "Enter Computation Name" "UserPortfolioSummary" "COMP_NAME"
141
+ ask_var "Enter Date" "$DEFAULT_DATE" "TARGET_DATE"
142
+ ask_var "Enter Entity IDs (comma separated, no spaces)" "user-123,user-456" "RAW_IDS"
143
+
144
+ # Format IDs into JSON array
145
+ IFS=',' read -r -a id_array <<< "$RAW_IDS"
146
+ JSON_IDS=$(printf '"%s",' "${id_array[@]}")
147
+ JSON_IDS="[${JSON_IDS%,}]"
148
+
149
+ run_test "{\"action\": \"run\", \"computation\": \"$COMP_NAME\", \"date\": \"$TARGET_DATE\", \"entityIds\": $JSON_IDS, \"force\": true}"
150
+ ;;
151
+
152
+ 6)
153
+ # Test Worker Logic
154
+ ask_var "Enter Computation Name" "UserPortfolioSummary" "COMP_NAME"
155
+ ask_var "Enter Date" "$DEFAULT_DATE" "TARGET_DATE"
156
+ ask_var "Enter Single Entity ID" "user-123" "ENTITY_ID"
157
+
158
+ # Worker test expects array of entityIds
159
+ run_test "{\"action\": \"test_worker\", \"computation\": \"$COMP_NAME\", \"date\": \"$TARGET_DATE\", \"entityIds\": [\"$ENTITY_ID\"]}"
160
+ ;;
161
+
162
+ 7)
163
+ # Test Worker Pool
164
+ ask_var "Enter Computation Name" "UserPortfolioSummary" "COMP_NAME"
165
+ ask_var "Enter Date" "$DEFAULT_DATE" "TARGET_DATE"
166
+
167
+ echo -e "${YELLOW}Running with Worker Pool enabled...${NC}"
168
+ run_test "{\"action\": \"run\", \"computation\": \"$COMP_NAME\", \"date\": \"$TARGET_DATE\", \"useWorkerPool\": true, \"force\": true}"
169
+ ;;
170
+
171
+ q|Q)
172
+ echo "Exiting."
173
+ exit 0
174
+ ;;
175
+
176
+ *)
177
+ echo -e "${RED}Invalid option.${NC}"
178
+ ;;
179
+ esac
180
+
181
+ echo -e "\n-------------------------------------------------"
182
+ read -p "Press Enter to continue..."
183
+ done
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.750",
3
+ "version": "1.0.751",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [