From da76ee8e5ffada19da016503179309e9ec68c28f Mon Sep 17 00:00:00 2001 From: John Yeo Date: Thu, 6 Nov 2025 18:25:57 +0000 Subject: [PATCH] fix: tracking negative values --- opencode.json | 4 - scripts/testGroups/g1.sh | 10 +- scripts/testScripts/runTests.ts | 5 + server/shell/g1.sh | 27 --- .../track/eventUtils/EventBatchingManager.ts | 2 +- .../track/eventUtils/runInsertEventBatch.ts | 2 - .../track/redisTrackUtils/batchDeduction.lua | 14 +- temp_svg_analysis.svg | 208 ------------------ 8 files changed, 18 insertions(+), 254 deletions(-) delete mode 100644 opencode.json delete mode 100755 server/shell/g1.sh delete mode 100644 temp_svg_analysis.svg diff --git a/opencode.json b/opencode.json deleted file mode 100644 index 86ba625de..000000000 --- a/opencode.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "https://opencode.ai/config.json", - "instructions": ["CLAUDE.md"] -} diff --git a/scripts/testGroups/g1.sh b/scripts/testGroups/g1.sh index 683aca7ba..73f3b7e34 100755 --- a/scripts/testGroups/g1.sh +++ b/scripts/testGroups/g1.sh @@ -16,11 +16,11 @@ fi # Adjust --max to control concurrency (default: 6) BUN_PARALLEL_COMPACT \ 'server/tests/balances/track/basic' \ - 'server/tests/balances/track/concurrency' \ - 'server/tests/balances/track/credit-systems' \ - 'server/tests/balances/track/legacy' \ - 'server/tests/balances/check/basic' \ - 'server/tests/balances/check/credit-systems' \ + # 'server/tests/balances/track/concurrency' \ + # 'server/tests/balances/track/credit-systems' \ + # 'server/tests/balances/track/legacy' \ + # 'server/tests/balances/check/basic' \ + # 'server/tests/balances/check/credit-systems' \ # 'server/tests/attach/basic' \ # 'server/tests/attach/upgrade' \ # 'server/tests/attach/downgrade' \ diff --git a/scripts/testScripts/runTests.ts b/scripts/testScripts/runTests.ts index e85a1771a..2fbd88712 100755 --- a/scripts/testScripts/runTests.ts +++ b/scripts/testScripts/runTests.ts @@ -2,10 +2,14 @@ import { spawn } from "bun"; import chalk from "chalk"; +import dotenv from "dotenv"; import { readdir } from "fs/promises"; import pLimit from "p-limit"; import { basename, resolve } from "path"; +// Load environment variables from server/.env +dotenv.config({ path: resolve(process.cwd(), "server", ".env") }); + interface TestResult { file: string; status: "pending" | "running" | "passed" | "failed"; @@ -342,6 +346,7 @@ class TestRunner { const proc = spawn(["bun", "test", "--timeout", "0", file], { stdout: "pipe", stderr: "pipe", + env: { ...process.env }, }); let output = ""; diff --git a/server/shell/g1.sh b/server/shell/g1.sh deleted file mode 100755 index 43b4fd4bd..000000000 --- a/server/shell/g1.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# Test Group 1: Upgrade & Downgrade Tests -# Description: Tests for product upgrades and downgrades - -# Source shared configuration -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "$SCRIPT_DIR/config.sh" - -# Setup if requested -if [[ "$1" == *"setup"* ]]; then - echo "Running test setup..." - $BUN_SETUP -fi - -# Run tests using TypeScript runner with compact mode -# Adjust --max to control concurrency (default: 6) -$BUN_PARALLEL_COMPACT \ - 'tests/check/basic' \ - 'tests/balances/track' \ - 'tests/attach/basic' \ - 'tests/attach/upgrade' \ - 'tests/attach/downgrade' \ - 'tests/attach/free' \ - 'tests/attach/addOn' \ - 'tests/attach/entities' \ - 'tests/attach/checkout' \ No newline at end of file diff --git a/server/src/internal/balances/track/eventUtils/EventBatchingManager.ts b/server/src/internal/balances/track/eventUtils/EventBatchingManager.ts index 8a0bbbd32..b70ffc79f 100644 --- a/server/src/internal/balances/track/eventUtils/EventBatchingManager.ts +++ b/server/src/internal/balances/track/eventUtils/EventBatchingManager.ts @@ -6,7 +6,7 @@ class BatchingManager { private events: Map = new Map(); private timer: NodeJS.Timeout | null = null; private readonly batchWindow = 100; // 100ms batching window - private readonly maxBatchSize = 5000; // Max events per batch (PostgreSQL has ~65k param limit, ~11 fields per event = ~5.9k max) + private readonly maxBatchSize = 1000; // Max events per batch (PostgreSQL has ~65k param limit, ~11 fields per event = ~5.9k max) /** * Add an event to the batch diff --git a/server/src/internal/balances/track/eventUtils/runInsertEventBatch.ts b/server/src/internal/balances/track/eventUtils/runInsertEventBatch.ts index 4029d209c..dc2362086 100644 --- a/server/src/internal/balances/track/eventUtils/runInsertEventBatch.ts +++ b/server/src/internal/balances/track/eventUtils/runInsertEventBatch.ts @@ -33,8 +33,6 @@ export const runInsertEventBatch = async ({ } }); - console.log("Event Inserts", eventInserts); - // Batch insert events directly - no DB lookups needed try { await db.insert(events).values(eventInserts as any); diff --git a/server/src/internal/balances/track/redisTrackUtils/batchDeduction.lua b/server/src/internal/balances/track/redisTrackUtils/batchDeduction.lua index 2f9468613..ba75ad753 100644 --- a/server/src/internal/balances/track/redisTrackUtils/batchDeduction.lua +++ b/server/src/internal/balances/track/redisTrackUtils/batchDeduction.lua @@ -398,7 +398,7 @@ local function deductFromCusFeature(cusFeature, amount) end -- Step 2: Deduct remaining from main balance - if remaining > 0 then + if remaining ~= 0 then local mainResult = deductFromMainBalance(cusFeature, remaining) remaining = mainResult.remaining @@ -454,7 +454,7 @@ local function deductFromFeatureWithEntities(customerFeature, entityFeaturesMap, -- Step 2: Deduct from entity main balance if entityFeatures then local entityFeature = entityFeatures[customerFeature.id] - if entityFeature and remaining > 0 then + if entityFeature and remaining ~= 0 then local entityMainResult = deductFromMainBalance(entityFeature, remaining) remaining = entityMainResult.remaining for _, delta in ipairs(entityMainResult.deltas) do @@ -482,7 +482,7 @@ local function deductFromFeatureWithEntities(customerFeature, entityFeaturesMap, end -- Step 4: Deduct from customer main balance - if remaining > 0 then + if remaining ~= 0 then local customerMainResult = deductFromMainBalance(customerFeature, remaining) remaining = customerMainResult.remaining for _, delta in ipairs(customerMainResult.deltas) do @@ -506,7 +506,7 @@ local function deductFromFeatureWithEntities(customerFeature, entityFeaturesMap, end -- Step 2: Deduct from customer main balance - if remaining > 0 then + if remaining ~= 0 then local customerMainResult = deductFromMainBalance(customerFeature, remaining) remaining = customerMainResult.remaining for _, delta in ipairs(customerMainResult.deltas) do @@ -545,7 +545,7 @@ local function deductFromFeatureWithEntities(customerFeature, entityFeaturesMap, end -- Step 4: Deduct from all entity main balances (sorted for consistency) - if remaining > 0 then + if remaining ~= 0 then local sortedEntityIds = {} for entityId in pairs(entityFeaturesMap) do table.insert(sortedEntityIds, entityId) @@ -555,7 +555,7 @@ local function deductFromFeatureWithEntities(customerFeature, entityFeaturesMap, for _, entityId in ipairs(sortedEntityIds) do local entityFeatures = entityFeaturesMap[entityId] local entityFeature = entityFeatures[customerFeature.id] - if entityFeature and remaining > 0 then + if entityFeature and remaining ~= 0 then local entityMainResult = deductFromMainBalance(entityFeature, remaining) remaining = entityMainResult.remaining for _, delta in ipairs(entityMainResult.deltas) do @@ -709,7 +709,7 @@ local function processRequest(request, loadedCusFeatures, entityFeatureStates) for _, entId in ipairs(sortedEntityIds) do local entityFeatures = entityFeatureStates[entId] local entityFeature = entityFeatures[featureId] - if entityFeature and remainingAmount > 0 then + if entityFeature and remainingAmount ~= 0 then if not entityFeature.unlimited then local result = deductFromCusFeature(entityFeature, remainingAmount) diff --git a/temp_svg_analysis.svg b/temp_svg_analysis.svg deleted file mode 100644 index 306a19148..000000000 --- a/temp_svg_analysis.svg +++ /dev/null @@ -1,208 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file