Skip to content

Commit 52be89e

Browse files
committed
modified: .gitignore
new file: api/schemas/main_test.go modified: internal/agent/main_test.go modified: internal/analysis/active/taint/taint_shim.js modified: internal/analysis/active/taint/taint_shim.test.js modified: internal/analysis/active/timeslip/main_test.go modified: internal/browser/stealth/evasions.js modified: internal/browser/stealth/evasions.test.js modified: internal/browser/stealth/js_test.go modified: internal/config/config.go modified: internal/jsoncompare/main_test.go modified: internal/knowledgegraph/postgres_kg.go modified: internal/observability/logger_test.go new file: internal/observability/main_test.go new file: internal/reporting/main_test.go modified: internal/reporting/reporter.go modified: internal/reporting/reporter_test.go modified: internal/reporting/sarif_reporter.go modified: internal/reporting/sarif_reporter_test.go modified: package-lock.json
1 parent 26d3cef commit 52be89e

19 files changed

Lines changed: 3033 additions & 979 deletions

File tree

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ logs/
2222
# Local configuration overrides and environment files
2323
# It's good practice to commit config.yaml as a template,
2424
# but ignore local versions with secrets.
25+
config.yaml
2526
*.local.yaml
2627
.credentials.json
2728
.env
2829
.env.*
29-
config.yaml
3030
# Corrected path based on project structure
3131
internal/browser/testing/
3232
test_imports.go
@@ -59,6 +59,5 @@ Thumbs.db
5959
*.tar.gz
6060
*.rar
6161
.envrc
62-
scalpel
6362
node_modules/
6463
config.yaml

api/schemas/main_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
// File: api/schemas/main_test.go
3+
package schemas_test
4+
5+
import (
6+
"os"
7+
"testing"
8+
9+
"github.com/xkilldash9x/scalpel-cli/internal/config"
10+
"github.com/xkilldash9x/scalpel-cli/internal/observability"
11+
"go.uber.org/zap/zapcore"
12+
)
13+
14+
// TestMain serves as the entry point for all tests in the schemas package.
15+
// It instantiates the global dependency-injected logger before running tests.
16+
func TestMain(m *testing.M) {
17+
// 1. Load default configuration.
18+
appConfig := config.NewDefaultConfig()
19+
logConfig := appConfig.Logger()
20+
21+
// 2. Override settings for the test environment.
22+
logConfig.Level = "debug"
23+
logConfig.ServiceName = "test-suite"
24+
logConfig.Format = "console"
25+
26+
// 3. Initialize the global logger.
27+
observability.Initialize(logConfig, zapcore.Lock(os.Stdout))
28+
29+
// 4. Run the tests.
30+
exitCode := m.Run()
31+
32+
// 5. Teardown and Sync.
33+
observability.Sync()
34+
35+
// Explicitly reset the global state to be clean.
36+
observability.ResetForTest()
37+
38+
// 6. Exit with the result code.
39+
os.Exit(exitCode)
40+
}

internal/agent/main_test.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
1-
package agent
1+
2+
// File: internal/agent/main_test.go
3+
package agent_test
24

35
import (
46
"os"
57
"testing"
68

79
"github.com/xkilldash9x/scalpel-cli/internal/config"
810
"github.com/xkilldash9x/scalpel-cli/internal/observability"
11+
"go.uber.org/zap/zapcore"
912
)
1013

11-
// TestMain is executed before any tests in this package.
14+
// TestMain serves as the entry point for all tests in the agent package.
15+
// It instantiates the global dependency-injected logger before running tests.
1216
func TestMain(m *testing.M) {
13-
// Initialize a simple logger for testing purposes to avoid spamming the console.
14-
// This prevents the "Global logger requested before initialization" warning.
15-
cfg := config.NewDefaultConfig().Logger()
16-
cfg.Level = "fatal" // Silence all logs except fatal during tests
17-
observability.InitializeLogger(cfg)
17+
// 1. Load default configuration.
18+
appConfig := config.NewDefaultConfig()
19+
logConfig := appConfig.Logger()
20+
21+
// 2. Override settings for the test environment.
22+
logConfig.Level = "debug"
23+
logConfig.ServiceName = "test-suite"
24+
logConfig.Format = "console"
25+
26+
// 3. Initialize the global logger.
27+
observability.Initialize(logConfig, zapcore.Lock(os.Stdout))
28+
29+
// 4. Run the tests.
30+
exitCode := m.Run()
31+
32+
// 5. Teardown and Sync.
33+
observability.Sync()
1834

19-
// After running all tests, ensure logs are flushed.
20-
defer observability.Sync()
35+
// Explicitly reset the global state to be clean.
36+
observability.ResetForTest()
2137

22-
os.Exit(m.Run())
38+
// 6. Exit with the result code.
39+
os.Exit(exitCode)
2340
}

0 commit comments

Comments
 (0)