@build-astron-co/nimbus 0.4.2 → 0.4.3
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.
- package/dist/src/agent/compaction-agent.js +24 -12
- package/dist/src/agent/context-manager.js +2 -1
- package/dist/src/agent/expand-files.js +2 -1
- package/dist/src/agent/loop.js +71 -33
- package/dist/src/agent/permissions.js +4 -2
- package/dist/src/agent/system-prompt.js +34 -17
- package/dist/src/app.js +1 -1
- package/dist/src/auth/keychain.js +8 -4
- package/dist/src/auth/store.js +70 -107
- package/dist/src/cli/init.js +35 -19
- package/dist/src/cli/run.js +18 -10
- package/dist/src/cli/serve.js +4 -2
- package/dist/src/cli.js +52 -11
- package/dist/src/commands/alias.js +5 -3
- package/dist/src/commands/audit/index.js +2 -1
- package/dist/src/commands/aws-terraform.js +36 -18
- package/dist/src/commands/completions.js +1 -1
- package/dist/src/commands/config.js +3 -2
- package/dist/src/commands/connect-github.js +92 -0
- package/dist/src/commands/cost/index.js +3 -2
- package/dist/src/commands/deploy.js +15 -10
- package/dist/src/commands/doctor.js +6 -3
- package/dist/src/commands/drift/index.js +2 -1
- package/dist/src/commands/export.js +5 -3
- package/dist/src/commands/generate-terraform.js +110 -2
- package/dist/src/commands/import.js +3 -3
- package/dist/src/commands/incident.js +10 -5
- package/dist/src/commands/login.js +8 -93
- package/dist/src/commands/logs.js +16 -8
- package/dist/src/commands/onboarding.js +6 -4
- package/dist/src/commands/pipeline.js +6 -3
- package/dist/src/commands/plugin.js +3 -2
- package/dist/src/commands/profile.js +27 -14
- package/dist/src/commands/questionnaire.js +1 -1
- package/dist/src/commands/rollback.js +3 -2
- package/dist/src/commands/rollout.js +5 -3
- package/dist/src/commands/runbook.js +17 -10
- package/dist/src/commands/schedule.js +10 -5
- package/dist/src/commands/status.js +2 -1
- package/dist/src/commands/team-context.js +12 -7
- package/dist/src/commands/template.js +1 -1
- package/dist/src/commands/tf/index.js +6 -3
- package/dist/src/commands/version.js +6 -3
- package/dist/src/commands/watch.js +6 -3
- package/dist/src/compat/sqlite.js +5 -3
- package/dist/src/config/mode-store.js +2 -1
- package/dist/src/config/profiles.js +4 -2
- package/dist/src/config/types.js +2 -1
- package/dist/src/engine/executor.js +8 -4
- package/dist/src/engine/planner.js +9 -5
- package/dist/src/llm/providers/anthropic.js +6 -3
- package/dist/src/llm/providers/ollama.js +1 -1
- package/dist/src/llm/router.js +22 -7
- package/dist/src/sessions/manager.js +6 -3
- package/dist/src/sharing/viewer.js +2 -1
- package/dist/src/tools/file-ops.js +1 -2
- package/dist/src/tools/schemas/devops.js +197 -108
- package/dist/src/tools/schemas/standard.js +1 -1
- package/dist/src/ui/App.js +25 -13
- package/dist/src/ui/FileDiffModal.js +22 -11
- package/dist/src/ui/HelpModal.js +2 -1
- package/dist/src/ui/InputBox.js +6 -3
- package/dist/src/ui/MessageList.js +40 -20
- package/dist/src/ui/TerminalPane.js +2 -1
- package/dist/src/ui/ToolCallDisplay.js +12 -6
- package/dist/src/ui/TreePane.js +2 -1
- package/dist/src/ui/ink/index.js +37 -21
- package/dist/src/watcher/index.js +8 -4
- package/package.json +3 -5
- package/src/__tests__/alias.test.ts +0 -133
- package/src/__tests__/app.test.ts +0 -76
- package/src/__tests__/audit.test.ts +0 -877
- package/src/__tests__/circuit-breaker.test.ts +0 -116
- package/src/__tests__/cli-run.test.ts +0 -351
- package/src/__tests__/compat-sqlite.test.ts +0 -68
- package/src/__tests__/context-manager.test.ts +0 -632
- package/src/__tests__/context.test.ts +0 -242
- package/src/__tests__/devops-terminal-gaps.test.ts +0 -718
- package/src/__tests__/doctor.test.ts +0 -48
- package/src/__tests__/enterprise.test.ts +0 -401
- package/src/__tests__/export.test.ts +0 -236
- package/src/__tests__/gap-11-18-20.test.ts +0 -958
- package/src/__tests__/generator.test.ts +0 -433
- package/src/__tests__/helm-streaming.test.ts +0 -127
- package/src/__tests__/hooks.test.ts +0 -582
- package/src/__tests__/incident.test.ts +0 -179
- package/src/__tests__/init.test.ts +0 -487
- package/src/__tests__/intent-parser.test.ts +0 -229
- package/src/__tests__/llm-router.test.ts +0 -209
- package/src/__tests__/logs.test.ts +0 -107
- package/src/__tests__/loop-errors.test.ts +0 -244
- package/src/__tests__/lsp.test.ts +0 -293
- package/src/__tests__/modes.test.ts +0 -336
- package/src/__tests__/perf-optimizations.test.ts +0 -847
- package/src/__tests__/permissions.test.ts +0 -338
- package/src/__tests__/pipeline.test.ts +0 -50
- package/src/__tests__/polish-phase3.test.ts +0 -340
- package/src/__tests__/profile.test.ts +0 -237
- package/src/__tests__/rollback.test.ts +0 -83
- package/src/__tests__/runbook.test.ts +0 -219
- package/src/__tests__/schedule.test.ts +0 -206
- package/src/__tests__/serve.test.ts +0 -275
- package/src/__tests__/sessions.test.ts +0 -322
- package/src/__tests__/sharing.test.ts +0 -340
- package/src/__tests__/snapshots.test.ts +0 -581
- package/src/__tests__/standalone-migration.test.ts +0 -199
- package/src/__tests__/state-db.test.ts +0 -334
- package/src/__tests__/status.test.ts +0 -158
- package/src/__tests__/stream-with-tools.test.ts +0 -778
- package/src/__tests__/subagents.test.ts +0 -176
- package/src/__tests__/system-prompt.test.ts +0 -248
- package/src/__tests__/terminal-gap-v2.test.ts +0 -395
- package/src/__tests__/terminal-parity.test.ts +0 -393
- package/src/__tests__/tf-apply.test.ts +0 -187
- package/src/__tests__/tool-converter.test.ts +0 -256
- package/src/__tests__/tool-schemas.test.ts +0 -602
- package/src/__tests__/tools.test.ts +0 -144
- package/src/__tests__/version-json.test.ts +0 -184
- package/src/__tests__/version.test.ts +0 -49
- package/src/__tests__/watch.test.ts +0 -129
- package/src/agent/compaction-agent.ts +0 -266
- package/src/agent/context-manager.ts +0 -499
- package/src/agent/context.ts +0 -427
- package/src/agent/deploy-preview.ts +0 -487
- package/src/agent/expand-files.ts +0 -108
- package/src/agent/index.ts +0 -68
- package/src/agent/loop.ts +0 -1998
- package/src/agent/modes.ts +0 -429
- package/src/agent/permissions.ts +0 -513
- package/src/agent/subagents/base.ts +0 -116
- package/src/agent/subagents/cost.ts +0 -51
- package/src/agent/subagents/explore.ts +0 -42
- package/src/agent/subagents/general.ts +0 -54
- package/src/agent/subagents/index.ts +0 -102
- package/src/agent/subagents/infra.ts +0 -59
- package/src/agent/subagents/security.ts +0 -69
- package/src/agent/system-prompt.ts +0 -990
- package/src/app.ts +0 -180
- package/src/audit/activity-log.ts +0 -290
- package/src/audit/compliance-checker.ts +0 -540
- package/src/audit/cost-tracker.ts +0 -318
- package/src/audit/index.ts +0 -23
- package/src/audit/security-scanner.ts +0 -641
- package/src/auth/guard.ts +0 -75
- package/src/auth/index.ts +0 -56
- package/src/auth/keychain.ts +0 -82
- package/src/auth/oauth.ts +0 -465
- package/src/auth/providers.ts +0 -470
- package/src/auth/sso.ts +0 -113
- package/src/auth/store.ts +0 -505
- package/src/auth/types.ts +0 -187
- package/src/build.ts +0 -141
- package/src/cli/index.ts +0 -16
- package/src/cli/init.ts +0 -1227
- package/src/cli/openapi-spec.ts +0 -356
- package/src/cli/run.ts +0 -628
- package/src/cli/serve-auth.ts +0 -80
- package/src/cli/serve.ts +0 -539
- package/src/cli/web.ts +0 -71
- package/src/cli.ts +0 -1728
- package/src/clients/core-engine-client.ts +0 -227
- package/src/clients/enterprise-client.ts +0 -334
- package/src/clients/generator-client.ts +0 -351
- package/src/clients/git-client.ts +0 -627
- package/src/clients/github-client.ts +0 -410
- package/src/clients/helm-client.ts +0 -504
- package/src/clients/index.ts +0 -80
- package/src/clients/k8s-client.ts +0 -497
- package/src/clients/llm-client.ts +0 -161
- package/src/clients/rest-client.ts +0 -130
- package/src/clients/service-discovery.ts +0 -38
- package/src/clients/terraform-client.ts +0 -482
- package/src/clients/tools-client.ts +0 -1843
- package/src/clients/ws-client.ts +0 -115
- package/src/commands/alias.ts +0 -100
- package/src/commands/analyze/index.ts +0 -352
- package/src/commands/apply/helm.ts +0 -473
- package/src/commands/apply/index.ts +0 -213
- package/src/commands/apply/k8s.ts +0 -454
- package/src/commands/apply/terraform.ts +0 -582
- package/src/commands/ask.ts +0 -167
- package/src/commands/audit/index.ts +0 -357
- package/src/commands/auth-cloud.ts +0 -407
- package/src/commands/auth-list.ts +0 -134
- package/src/commands/auth-profile.ts +0 -121
- package/src/commands/auth-refresh.ts +0 -187
- package/src/commands/auth-status.ts +0 -141
- package/src/commands/aws/ec2.ts +0 -501
- package/src/commands/aws/iam.ts +0 -397
- package/src/commands/aws/index.ts +0 -133
- package/src/commands/aws/lambda.ts +0 -396
- package/src/commands/aws/rds.ts +0 -439
- package/src/commands/aws/s3.ts +0 -439
- package/src/commands/aws/vpc.ts +0 -393
- package/src/commands/aws-discover.ts +0 -542
- package/src/commands/aws-terraform.ts +0 -755
- package/src/commands/azure/aks.ts +0 -376
- package/src/commands/azure/functions.ts +0 -253
- package/src/commands/azure/index.ts +0 -116
- package/src/commands/azure/storage.ts +0 -478
- package/src/commands/azure/vm.ts +0 -355
- package/src/commands/billing/index.ts +0 -256
- package/src/commands/chat.ts +0 -320
- package/src/commands/completions.ts +0 -268
- package/src/commands/config.ts +0 -372
- package/src/commands/cost/cloud-cost-estimator.ts +0 -266
- package/src/commands/cost/estimator.ts +0 -79
- package/src/commands/cost/index.ts +0 -810
- package/src/commands/cost/parsers/terraform.ts +0 -273
- package/src/commands/cost/parsers/types.ts +0 -25
- package/src/commands/cost/pricing/aws.ts +0 -544
- package/src/commands/cost/pricing/azure.ts +0 -499
- package/src/commands/cost/pricing/gcp.ts +0 -396
- package/src/commands/cost/pricing/index.ts +0 -40
- package/src/commands/demo.ts +0 -250
- package/src/commands/deploy.ts +0 -260
- package/src/commands/doctor.ts +0 -1386
- package/src/commands/drift/index.ts +0 -787
- package/src/commands/explain.ts +0 -277
- package/src/commands/export.ts +0 -146
- package/src/commands/feedback.ts +0 -389
- package/src/commands/fix.ts +0 -324
- package/src/commands/fs/index.ts +0 -402
- package/src/commands/gcp/compute.ts +0 -325
- package/src/commands/gcp/functions.ts +0 -271
- package/src/commands/gcp/gke.ts +0 -438
- package/src/commands/gcp/iam.ts +0 -344
- package/src/commands/gcp/index.ts +0 -129
- package/src/commands/gcp/storage.ts +0 -284
- package/src/commands/generate-helm.ts +0 -1249
- package/src/commands/generate-k8s.ts +0 -1508
- package/src/commands/generate-terraform.ts +0 -1202
- package/src/commands/gh/index.ts +0 -863
- package/src/commands/git/index.ts +0 -1343
- package/src/commands/helm/index.ts +0 -1126
- package/src/commands/help.ts +0 -715
- package/src/commands/history.ts +0 -149
- package/src/commands/import.ts +0 -868
- package/src/commands/incident.ts +0 -166
- package/src/commands/index.ts +0 -367
- package/src/commands/init.ts +0 -1051
- package/src/commands/k8s/index.ts +0 -1137
- package/src/commands/login.ts +0 -716
- package/src/commands/logout.ts +0 -83
- package/src/commands/logs.ts +0 -167
- package/src/commands/onboarding.ts +0 -405
- package/src/commands/pipeline.ts +0 -186
- package/src/commands/plan/display.ts +0 -279
- package/src/commands/plan/index.ts +0 -599
- package/src/commands/plugin.ts +0 -398
- package/src/commands/preview.ts +0 -452
- package/src/commands/profile.ts +0 -342
- package/src/commands/questionnaire.ts +0 -1172
- package/src/commands/resume.ts +0 -47
- package/src/commands/rollback.ts +0 -315
- package/src/commands/rollout.ts +0 -88
- package/src/commands/runbook.ts +0 -346
- package/src/commands/schedule.ts +0 -236
- package/src/commands/status.ts +0 -252
- package/src/commands/team/index.ts +0 -346
- package/src/commands/team-context.ts +0 -220
- package/src/commands/template.ts +0 -233
- package/src/commands/tf/index.ts +0 -1093
- package/src/commands/upgrade.ts +0 -609
- package/src/commands/usage/index.ts +0 -134
- package/src/commands/version.ts +0 -174
- package/src/commands/watch.ts +0 -153
- package/src/compat/index.ts +0 -2
- package/src/compat/runtime.ts +0 -12
- package/src/compat/sqlite.ts +0 -177
- package/src/config/index.ts +0 -17
- package/src/config/manager.ts +0 -530
- package/src/config/mode-store.ts +0 -62
- package/src/config/profiles.ts +0 -84
- package/src/config/safety-policy.ts +0 -358
- package/src/config/schema.ts +0 -125
- package/src/config/types.ts +0 -609
- package/src/config/workspace-state.ts +0 -53
- package/src/context/context-db.ts +0 -199
- package/src/demo/index.ts +0 -349
- package/src/demo/scenarios/full-journey.ts +0 -229
- package/src/demo/scenarios/getting-started.ts +0 -127
- package/src/demo/scenarios/helm-release.ts +0 -341
- package/src/demo/scenarios/k8s-deployment.ts +0 -194
- package/src/demo/scenarios/terraform-vpc.ts +0 -170
- package/src/demo/types.ts +0 -92
- package/src/engine/cost-estimator.ts +0 -480
- package/src/engine/diagram-generator.ts +0 -256
- package/src/engine/drift-detector.ts +0 -902
- package/src/engine/executor.ts +0 -1066
- package/src/engine/index.ts +0 -76
- package/src/engine/orchestrator.ts +0 -636
- package/src/engine/planner.ts +0 -787
- package/src/engine/safety.ts +0 -743
- package/src/engine/verifier.ts +0 -770
- package/src/enterprise/audit.ts +0 -348
- package/src/enterprise/auth.ts +0 -270
- package/src/enterprise/billing.ts +0 -822
- package/src/enterprise/index.ts +0 -17
- package/src/enterprise/teams.ts +0 -443
- package/src/generator/best-practices.ts +0 -1608
- package/src/generator/helm.ts +0 -630
- package/src/generator/index.ts +0 -37
- package/src/generator/intent-parser.ts +0 -514
- package/src/generator/kubernetes.ts +0 -976
- package/src/generator/terraform.ts +0 -1875
- package/src/history/index.ts +0 -8
- package/src/history/manager.ts +0 -250
- package/src/history/types.ts +0 -34
- package/src/hooks/config.ts +0 -432
- package/src/hooks/engine.ts +0 -392
- package/src/hooks/index.ts +0 -4
- package/src/llm/auth-bridge.ts +0 -198
- package/src/llm/circuit-breaker.ts +0 -140
- package/src/llm/config-loader.ts +0 -201
- package/src/llm/cost-calculator.ts +0 -171
- package/src/llm/index.ts +0 -8
- package/src/llm/model-aliases.ts +0 -115
- package/src/llm/provider-registry.ts +0 -63
- package/src/llm/providers/anthropic.ts +0 -462
- package/src/llm/providers/bedrock.ts +0 -477
- package/src/llm/providers/google.ts +0 -405
- package/src/llm/providers/ollama.ts +0 -767
- package/src/llm/providers/openai-compatible.ts +0 -340
- package/src/llm/providers/openai.ts +0 -328
- package/src/llm/providers/openrouter.ts +0 -338
- package/src/llm/router.ts +0 -1104
- package/src/llm/types.ts +0 -232
- package/src/lsp/client.ts +0 -298
- package/src/lsp/languages.ts +0 -119
- package/src/lsp/manager.ts +0 -294
- package/src/mcp/client.ts +0 -402
- package/src/mcp/index.ts +0 -5
- package/src/mcp/manager.ts +0 -133
- package/src/nimbus.ts +0 -234
- package/src/plugins/index.ts +0 -27
- package/src/plugins/loader.ts +0 -334
- package/src/plugins/manager.ts +0 -376
- package/src/plugins/types.ts +0 -284
- package/src/scanners/cicd-scanner.ts +0 -258
- package/src/scanners/cloud-scanner.ts +0 -466
- package/src/scanners/framework-scanner.ts +0 -469
- package/src/scanners/iac-scanner.ts +0 -388
- package/src/scanners/index.ts +0 -539
- package/src/scanners/language-scanner.ts +0 -276
- package/src/scanners/package-manager-scanner.ts +0 -277
- package/src/scanners/types.ts +0 -172
- package/src/sessions/manager.ts +0 -472
- package/src/sessions/types.ts +0 -44
- package/src/sharing/sync.ts +0 -300
- package/src/sharing/viewer.ts +0 -163
- package/src/snapshots/index.ts +0 -2
- package/src/snapshots/manager.ts +0 -530
- package/src/state/artifacts.ts +0 -147
- package/src/state/audit.ts +0 -137
- package/src/state/billing.ts +0 -240
- package/src/state/checkpoints.ts +0 -117
- package/src/state/config.ts +0 -67
- package/src/state/conversations.ts +0 -14
- package/src/state/credentials.ts +0 -154
- package/src/state/db.ts +0 -58
- package/src/state/index.ts +0 -26
- package/src/state/messages.ts +0 -115
- package/src/state/projects.ts +0 -123
- package/src/state/schema.ts +0 -236
- package/src/state/sessions.ts +0 -147
- package/src/state/teams.ts +0 -200
- package/src/telemetry.ts +0 -108
- package/src/tools/aws-ops.ts +0 -952
- package/src/tools/azure-ops.ts +0 -579
- package/src/tools/file-ops.ts +0 -615
- package/src/tools/gcp-ops.ts +0 -625
- package/src/tools/git-ops.ts +0 -773
- package/src/tools/github-ops.ts +0 -799
- package/src/tools/helm-ops.ts +0 -943
- package/src/tools/index.ts +0 -17
- package/src/tools/k8s-ops.ts +0 -819
- package/src/tools/schemas/converter.ts +0 -184
- package/src/tools/schemas/devops.ts +0 -3502
- package/src/tools/schemas/index.ts +0 -73
- package/src/tools/schemas/standard.ts +0 -1148
- package/src/tools/schemas/types.ts +0 -735
- package/src/tools/spawn-exec.ts +0 -148
- package/src/tools/terraform-ops.ts +0 -862
- package/src/types/ambient.d.ts +0 -193
- package/src/types/config.ts +0 -83
- package/src/types/drift.ts +0 -116
- package/src/types/enterprise.ts +0 -335
- package/src/types/index.ts +0 -20
- package/src/types/plan.ts +0 -44
- package/src/types/request.ts +0 -65
- package/src/types/response.ts +0 -54
- package/src/types/service.ts +0 -51
- package/src/ui/App.tsx +0 -2114
- package/src/ui/DeployPreview.tsx +0 -174
- package/src/ui/FileDiffModal.tsx +0 -162
- package/src/ui/Header.tsx +0 -131
- package/src/ui/HelpModal.tsx +0 -57
- package/src/ui/InputBox.tsx +0 -503
- package/src/ui/MessageList.tsx +0 -1032
- package/src/ui/PermissionPrompt.tsx +0 -163
- package/src/ui/StatusBar.tsx +0 -277
- package/src/ui/TerminalPane.tsx +0 -84
- package/src/ui/ToolCallDisplay.tsx +0 -643
- package/src/ui/TreePane.tsx +0 -132
- package/src/ui/chat-ui.ts +0 -850
- package/src/ui/index.ts +0 -33
- package/src/ui/ink/index.ts +0 -1444
- package/src/ui/streaming.ts +0 -176
- package/src/ui/theme.ts +0 -104
- package/src/ui/types.ts +0 -75
- package/src/utils/analytics.ts +0 -72
- package/src/utils/cost-warning.ts +0 -27
- package/src/utils/env.ts +0 -46
- package/src/utils/errors.ts +0 -69
- package/src/utils/event-bus.ts +0 -38
- package/src/utils/index.ts +0 -24
- package/src/utils/logger.ts +0 -171
- package/src/utils/rate-limiter.ts +0 -121
- package/src/utils/service-auth.ts +0 -49
- package/src/utils/validation.ts +0 -53
- package/src/version.ts +0 -4
- package/src/watcher/index.ts +0 -214
- package/src/wizard/approval.ts +0 -383
- package/src/wizard/index.ts +0 -25
- package/src/wizard/prompts.ts +0 -338
- package/src/wizard/types.ts +0 -172
- package/src/wizard/ui.ts +0 -556
- package/src/wizard/wizard.ts +0 -304
- package/tsconfig.json +0 -24
|
@@ -1,877 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the Nimbus audit modules:
|
|
3
|
-
* - Security Scanner
|
|
4
|
-
* - Compliance Checker
|
|
5
|
-
* - Cost Tracker
|
|
6
|
-
* - Activity Log
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { describe, test, expect, beforeEach, afterEach } from 'vitest';
|
|
10
|
-
import * as fs from 'node:fs';
|
|
11
|
-
import * as path from 'node:path';
|
|
12
|
-
import * as os from 'node:os';
|
|
13
|
-
|
|
14
|
-
import { scanSecurity, formatFindings, type SecurityFinding } from '../audit/security-scanner';
|
|
15
|
-
import { checkCompliance, generateScorecard, type Framework } from '../audit/compliance-checker';
|
|
16
|
-
import { CostTracker } from '../audit/cost-tracker';
|
|
17
|
-
import { ActivityLog } from '../audit/activity-log';
|
|
18
|
-
|
|
19
|
-
// ---------------------------------------------------------------------------
|
|
20
|
-
// Shared helpers
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
|
|
23
|
-
function makeTmpDir(): string {
|
|
24
|
-
return fs.mkdtempSync(path.join(os.tmpdir(), 'nimbus-audit-test-'));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function removeTmpDir(dir: string): void {
|
|
28
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// ============================================================================
|
|
32
|
-
// Security Scanner
|
|
33
|
-
// ============================================================================
|
|
34
|
-
|
|
35
|
-
describe('Security Scanner', () => {
|
|
36
|
-
let tmpDir: string;
|
|
37
|
-
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
tmpDir = makeTmpDir();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
afterEach(() => {
|
|
43
|
-
removeTmpDir(tmpDir);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// ---- scanSecurity() ----
|
|
47
|
-
|
|
48
|
-
test('scanSecurity() finds hardcoded API keys', async () => {
|
|
49
|
-
fs.writeFileSync(path.join(tmpDir, 'config.ts'), 'const API_KEY = "sk-1234567890abcdef";\n');
|
|
50
|
-
|
|
51
|
-
const result = await scanSecurity({ dir: tmpDir });
|
|
52
|
-
|
|
53
|
-
expect(result.findings.length).toBeGreaterThanOrEqual(1);
|
|
54
|
-
const finding = result.findings.find(f => f.id.startsWith('SEC-001'));
|
|
55
|
-
expect(finding).toBeDefined();
|
|
56
|
-
expect(finding!.severity).toBe('CRITICAL');
|
|
57
|
-
expect(finding!.title).toContain('API key');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('scanSecurity() finds hardcoded passwords', async () => {
|
|
61
|
-
fs.writeFileSync(path.join(tmpDir, 'db.ts'), 'const password = "supersecret123";\n');
|
|
62
|
-
|
|
63
|
-
const result = await scanSecurity({ dir: tmpDir });
|
|
64
|
-
|
|
65
|
-
expect(result.findings.length).toBeGreaterThanOrEqual(1);
|
|
66
|
-
const finding = result.findings.find(f => f.id.startsWith('SEC-002'));
|
|
67
|
-
expect(finding).toBeDefined();
|
|
68
|
-
expect(finding!.severity).toBe('CRITICAL');
|
|
69
|
-
expect(finding!.title).toContain('password');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('scanSecurity() finds open security groups (0.0.0.0/0 in .tf files)', async () => {
|
|
73
|
-
fs.writeFileSync(path.join(tmpDir, 'main.tf'), 'cidr_blocks = ["0.0.0.0/0"]\n');
|
|
74
|
-
|
|
75
|
-
const result = await scanSecurity({ dir: tmpDir });
|
|
76
|
-
|
|
77
|
-
expect(result.findings.length).toBeGreaterThanOrEqual(1);
|
|
78
|
-
const finding = result.findings.find(f => f.id.startsWith('TF-001'));
|
|
79
|
-
expect(finding).toBeDefined();
|
|
80
|
-
expect(finding!.severity).toBe('HIGH');
|
|
81
|
-
expect(finding!.title).toContain('Open security group');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('scanSecurity() finds public S3 buckets', async () => {
|
|
85
|
-
fs.writeFileSync(path.join(tmpDir, 's3.tf'), 'acl = "public-read"\n');
|
|
86
|
-
|
|
87
|
-
const result = await scanSecurity({ dir: tmpDir });
|
|
88
|
-
|
|
89
|
-
expect(result.findings.length).toBeGreaterThanOrEqual(1);
|
|
90
|
-
const finding = result.findings.find(f => f.id.startsWith('TF-002'));
|
|
91
|
-
expect(finding).toBeDefined();
|
|
92
|
-
expect(finding!.severity).toBe('HIGH');
|
|
93
|
-
expect(finding!.title).toContain('Public S3 bucket');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('scanSecurity() returns no findings for clean code', async () => {
|
|
97
|
-
fs.writeFileSync(
|
|
98
|
-
path.join(tmpDir, 'clean.ts'),
|
|
99
|
-
[
|
|
100
|
-
'const apiKey = process.env.API_KEY;',
|
|
101
|
-
'const password = process.env.DB_PASSWORD;',
|
|
102
|
-
'export function greet(name: string): string {',
|
|
103
|
-
' return `Hello, ${name}`;',
|
|
104
|
-
'}',
|
|
105
|
-
].join('\n')
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const result = await scanSecurity({ dir: tmpDir });
|
|
109
|
-
|
|
110
|
-
expect(result.findings.length).toBe(0);
|
|
111
|
-
expect(result.scannedFiles).toBe(1);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('scanSecurity() skips node_modules', async () => {
|
|
115
|
-
const nodeModulesDir = path.join(tmpDir, 'node_modules', 'some-pkg');
|
|
116
|
-
fs.mkdirSync(nodeModulesDir, { recursive: true });
|
|
117
|
-
fs.writeFileSync(
|
|
118
|
-
path.join(nodeModulesDir, 'index.ts'),
|
|
119
|
-
'const API_KEY = "sk-should-be-ignored-abcde";\n'
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
// Also put a clean file in the root so scannedFiles > 0 in root but
|
|
123
|
-
// node_modules should be excluded entirely
|
|
124
|
-
fs.writeFileSync(path.join(tmpDir, 'index.ts'), 'export const x = 1;\n');
|
|
125
|
-
|
|
126
|
-
const result = await scanSecurity({ dir: tmpDir });
|
|
127
|
-
|
|
128
|
-
expect(result.scannedFiles).toBe(1); // only root index.ts
|
|
129
|
-
expect(result.findings.length).toBe(0);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// ---- formatFindings() ----
|
|
133
|
-
|
|
134
|
-
test('formatFindings() produces readable output', () => {
|
|
135
|
-
const findings: SecurityFinding[] = [
|
|
136
|
-
{
|
|
137
|
-
id: 'SEC-001-abcd1234',
|
|
138
|
-
severity: 'CRITICAL',
|
|
139
|
-
title: 'Hardcoded API key or secret',
|
|
140
|
-
description: 'A potential API key is hardcoded.',
|
|
141
|
-
file: 'config.ts',
|
|
142
|
-
line: 3,
|
|
143
|
-
recommendation: 'Move to environment variables.',
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
id: 'TF-001-efgh5678',
|
|
147
|
-
severity: 'HIGH',
|
|
148
|
-
title: 'Open security group (0.0.0.0/0)',
|
|
149
|
-
description: 'Security group allows traffic from any IP.',
|
|
150
|
-
file: 'main.tf',
|
|
151
|
-
line: 10,
|
|
152
|
-
recommendation: 'Restrict CIDR blocks.',
|
|
153
|
-
},
|
|
154
|
-
];
|
|
155
|
-
|
|
156
|
-
const output = formatFindings(findings);
|
|
157
|
-
|
|
158
|
-
expect(output).toContain('Security Scan Report');
|
|
159
|
-
expect(output).toContain('2 finding(s)');
|
|
160
|
-
expect(output).toContain('[CRITICAL]');
|
|
161
|
-
expect(output).toContain('[HIGH]');
|
|
162
|
-
expect(output).toContain('config.ts:3');
|
|
163
|
-
expect(output).toContain('main.tf:10');
|
|
164
|
-
expect(output).toContain('Recommendation:');
|
|
165
|
-
expect(output).toContain('1 critical');
|
|
166
|
-
expect(output).toContain('1 high');
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
test('formatFindings() returns clean message for empty findings', () => {
|
|
170
|
-
const output = formatFindings([]);
|
|
171
|
-
expect(output).toBe('No security issues found.');
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
// ============================================================================
|
|
176
|
-
// Compliance Checker
|
|
177
|
-
// ============================================================================
|
|
178
|
-
|
|
179
|
-
describe('Compliance Checker', () => {
|
|
180
|
-
let tmpDir: string;
|
|
181
|
-
|
|
182
|
-
beforeEach(() => {
|
|
183
|
-
tmpDir = makeTmpDir();
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
afterEach(() => {
|
|
187
|
-
removeTmpDir(tmpDir);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
test('checkCompliance() returns reports for all requested frameworks', async () => {
|
|
191
|
-
// Create a minimal .tf file so controls are evaluated (not skipped)
|
|
192
|
-
fs.writeFileSync(path.join(tmpDir, 'main.tf'), 'provider "aws" {\n region = "us-east-1"\n}\n');
|
|
193
|
-
|
|
194
|
-
const frameworks: Framework[] = ['SOC2', 'HIPAA', 'PCI'];
|
|
195
|
-
const reports = await checkCompliance({ dir: tmpDir, frameworks });
|
|
196
|
-
|
|
197
|
-
expect(reports.length).toBe(3);
|
|
198
|
-
expect(reports.map(r => r.framework)).toEqual(['SOC2', 'HIPAA', 'PCI']);
|
|
199
|
-
|
|
200
|
-
for (const report of reports) {
|
|
201
|
-
expect(report.controls.length).toBeGreaterThan(0);
|
|
202
|
-
expect(report.timestamp).toBeInstanceOf(Date);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test('checkCompliance() passes encryption check when encryption is configured', async () => {
|
|
207
|
-
fs.writeFileSync(
|
|
208
|
-
path.join(tmpDir, 'storage.tf'),
|
|
209
|
-
[
|
|
210
|
-
'resource "aws_s3_bucket" "data" {',
|
|
211
|
-
' bucket = "my-bucket"',
|
|
212
|
-
'',
|
|
213
|
-
' server_side_encryption_configuration {',
|
|
214
|
-
' rule {',
|
|
215
|
-
' apply_server_side_encryption_by_default {',
|
|
216
|
-
' sse_algorithm = "AES256"',
|
|
217
|
-
' }',
|
|
218
|
-
' }',
|
|
219
|
-
' }',
|
|
220
|
-
'}',
|
|
221
|
-
].join('\n')
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
const reports = await checkCompliance({
|
|
225
|
-
dir: tmpDir,
|
|
226
|
-
frameworks: ['SOC2'],
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
const soc2 = reports[0];
|
|
230
|
-
// SOC2-003 is the "Encryption at rest" control
|
|
231
|
-
const encryptionControl = soc2.controls.find(c => c.id === 'SOC2-003');
|
|
232
|
-
expect(encryptionControl).toBeDefined();
|
|
233
|
-
expect(encryptionControl!.status).toBe('pass');
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
test('checkCompliance() fails encryption check when missing', async () => {
|
|
237
|
-
fs.writeFileSync(
|
|
238
|
-
path.join(tmpDir, 'storage.tf'),
|
|
239
|
-
['resource "aws_s3_bucket" "data" {', ' bucket = "my-bucket"', '}'].join('\n')
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
const reports = await checkCompliance({
|
|
243
|
-
dir: tmpDir,
|
|
244
|
-
frameworks: ['SOC2'],
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
const soc2 = reports[0];
|
|
248
|
-
const encryptionControl = soc2.controls.find(c => c.id === 'SOC2-003');
|
|
249
|
-
expect(encryptionControl).toBeDefined();
|
|
250
|
-
expect(encryptionControl!.status).toBe('fail');
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
test('checkCompliance() returns correct score', async () => {
|
|
254
|
-
// Create .tf content that satisfies some SOC2 controls but not others.
|
|
255
|
-
// SOC2 has 5 controls. We provide content matching logging (SOC2-001)
|
|
256
|
-
// and access controls (SOC2-002) and network security groups (SOC2-005).
|
|
257
|
-
fs.writeFileSync(
|
|
258
|
-
path.join(tmpDir, 'infra.tf'),
|
|
259
|
-
[
|
|
260
|
-
'resource "aws_cloudtrail" "main" {}',
|
|
261
|
-
'resource "aws_iam_role" "admin" {}',
|
|
262
|
-
'resource "aws_security_group" "web" {}',
|
|
263
|
-
].join('\n')
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
const reports = await checkCompliance({
|
|
267
|
-
dir: tmpDir,
|
|
268
|
-
frameworks: ['SOC2'],
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
const soc2 = reports[0];
|
|
272
|
-
// 3 pass, 2 fail, 0 warn => score = round(3/5 * 100) = 60
|
|
273
|
-
expect(soc2.passCount).toBe(3);
|
|
274
|
-
expect(soc2.failCount).toBe(2);
|
|
275
|
-
expect(soc2.score).toBe(60);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
test('generateScorecard() produces formatted output', async () => {
|
|
279
|
-
fs.writeFileSync(path.join(tmpDir, 'main.tf'), 'resource "aws_cloudtrail" "main" {}\n');
|
|
280
|
-
|
|
281
|
-
const reports = await checkCompliance({
|
|
282
|
-
dir: tmpDir,
|
|
283
|
-
frameworks: ['SOC2'],
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
const scorecard = generateScorecard(reports);
|
|
287
|
-
|
|
288
|
-
expect(scorecard).toContain('Compliance Scorecard');
|
|
289
|
-
expect(scorecard).toContain('SOC2');
|
|
290
|
-
expect(scorecard).toContain('[PASS]');
|
|
291
|
-
expect(scorecard).toContain('[FAIL]');
|
|
292
|
-
expect(scorecard).toContain('Overall:');
|
|
293
|
-
expect(scorecard).toContain('compliant');
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
test('generateScorecard() handles empty reports', () => {
|
|
297
|
-
const scorecard = generateScorecard([]);
|
|
298
|
-
expect(scorecard).toBe('No compliance reports to display.');
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
// ============================================================================
|
|
303
|
-
// Cost Tracker
|
|
304
|
-
// ============================================================================
|
|
305
|
-
|
|
306
|
-
describe('Cost Tracker', () => {
|
|
307
|
-
let tracker: CostTracker;
|
|
308
|
-
|
|
309
|
-
beforeEach(() => {
|
|
310
|
-
tracker = new CostTracker();
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
test('recordLLMCost() adds an entry', () => {
|
|
314
|
-
const entry = tracker.recordLLMCost({
|
|
315
|
-
sessionId: 'session-1',
|
|
316
|
-
model: 'claude-sonnet-4-20250514',
|
|
317
|
-
inputTokens: 1000,
|
|
318
|
-
outputTokens: 500,
|
|
319
|
-
costUSD: 0.015,
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
expect(entry.id).toBeDefined();
|
|
323
|
-
expect(entry.category).toBe('llm');
|
|
324
|
-
expect(entry.amount).toBe(0.015);
|
|
325
|
-
expect(entry.model).toBe('claude-sonnet-4-20250514');
|
|
326
|
-
expect(entry.inputTokens).toBe(1000);
|
|
327
|
-
expect(entry.outputTokens).toBe(500);
|
|
328
|
-
expect(entry.sessionId).toBe('session-1');
|
|
329
|
-
expect(entry.timestamp).toBeInstanceOf(Date);
|
|
330
|
-
expect(entry.description).toContain('claude-sonnet-4-20250514');
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
test('recordInfraCost() adds an entry', () => {
|
|
334
|
-
const entry = tracker.recordInfraCost({
|
|
335
|
-
sessionId: 'session-2',
|
|
336
|
-
description: 'Added t3.medium EC2 instance',
|
|
337
|
-
monthlyCost: 30.37,
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
expect(entry.id).toBeDefined();
|
|
341
|
-
expect(entry.category).toBe('infra');
|
|
342
|
-
expect(entry.amount).toBe(30.37);
|
|
343
|
-
expect(entry.sessionId).toBe('session-2');
|
|
344
|
-
expect(entry.description).toBe('Added t3.medium EC2 instance');
|
|
345
|
-
expect(entry.inputTokens).toBeUndefined();
|
|
346
|
-
expect(entry.outputTokens).toBeUndefined();
|
|
347
|
-
expect(entry.model).toBeUndefined();
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
test('getSummary() calculates correct totals', () => {
|
|
351
|
-
tracker.recordLLMCost({
|
|
352
|
-
sessionId: 's1',
|
|
353
|
-
model: 'claude-sonnet-4-20250514',
|
|
354
|
-
inputTokens: 100,
|
|
355
|
-
outputTokens: 50,
|
|
356
|
-
costUSD: 0.01,
|
|
357
|
-
});
|
|
358
|
-
tracker.recordLLMCost({
|
|
359
|
-
sessionId: 's1',
|
|
360
|
-
model: 'claude-sonnet-4-20250514',
|
|
361
|
-
inputTokens: 200,
|
|
362
|
-
outputTokens: 100,
|
|
363
|
-
costUSD: 0.02,
|
|
364
|
-
});
|
|
365
|
-
tracker.recordInfraCost({
|
|
366
|
-
sessionId: 's1',
|
|
367
|
-
description: 'RDS',
|
|
368
|
-
monthlyCost: 50.0,
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
const summary = tracker.getSummary();
|
|
372
|
-
|
|
373
|
-
expect(summary.totalCost).toBeCloseTo(50.03, 6);
|
|
374
|
-
expect(summary.llmCost).toBeCloseTo(0.03, 6);
|
|
375
|
-
expect(summary.infraCost).toBeCloseTo(50.0, 6);
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
test('getSummary() groups by session', () => {
|
|
379
|
-
tracker.recordLLMCost({
|
|
380
|
-
sessionId: 'session-a',
|
|
381
|
-
model: 'gpt-4',
|
|
382
|
-
inputTokens: 100,
|
|
383
|
-
outputTokens: 50,
|
|
384
|
-
costUSD: 0.01,
|
|
385
|
-
});
|
|
386
|
-
tracker.recordLLMCost({
|
|
387
|
-
sessionId: 'session-b',
|
|
388
|
-
model: 'gpt-4',
|
|
389
|
-
inputTokens: 200,
|
|
390
|
-
outputTokens: 100,
|
|
391
|
-
costUSD: 0.02,
|
|
392
|
-
});
|
|
393
|
-
tracker.recordInfraCost({
|
|
394
|
-
sessionId: 'session-a',
|
|
395
|
-
description: 'EC2',
|
|
396
|
-
monthlyCost: 10.0,
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
const summary = tracker.getSummary();
|
|
400
|
-
|
|
401
|
-
expect(summary.entriesBySession.size).toBe(2);
|
|
402
|
-
expect(summary.entriesBySession.get('session-a')!.length).toBe(2);
|
|
403
|
-
expect(summary.entriesBySession.get('session-b')!.length).toBe(1);
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
test('getSummary() calculates daily costs', () => {
|
|
407
|
-
// All entries created with new Date(), so they all belong to today
|
|
408
|
-
tracker.recordLLMCost({
|
|
409
|
-
sessionId: 's1',
|
|
410
|
-
model: 'claude',
|
|
411
|
-
inputTokens: 100,
|
|
412
|
-
outputTokens: 50,
|
|
413
|
-
costUSD: 0.01,
|
|
414
|
-
});
|
|
415
|
-
tracker.recordLLMCost({
|
|
416
|
-
sessionId: 's1',
|
|
417
|
-
model: 'claude',
|
|
418
|
-
inputTokens: 200,
|
|
419
|
-
outputTokens: 100,
|
|
420
|
-
costUSD: 0.02,
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
const summary = tracker.getSummary();
|
|
424
|
-
|
|
425
|
-
expect(summary.dailyCosts.length).toBe(1);
|
|
426
|
-
// Today's date in YYYY-MM-DD
|
|
427
|
-
const today = new Date();
|
|
428
|
-
const y = today.getFullYear();
|
|
429
|
-
const m = String(today.getMonth() + 1).padStart(2, '0');
|
|
430
|
-
const d = String(today.getDate()).padStart(2, '0');
|
|
431
|
-
expect(summary.dailyCosts[0].date).toBe(`${y}-${m}-${d}`);
|
|
432
|
-
expect(summary.dailyCosts[0].amount).toBeCloseTo(0.03, 6);
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
test('getSummary() calculates monthly projection', () => {
|
|
436
|
-
tracker.recordLLMCost({
|
|
437
|
-
sessionId: 's1',
|
|
438
|
-
model: 'claude',
|
|
439
|
-
inputTokens: 100,
|
|
440
|
-
outputTokens: 50,
|
|
441
|
-
costUSD: 1.0,
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
const summary = tracker.getSummary();
|
|
445
|
-
|
|
446
|
-
// Single day of data: daily average = 1.0, projection = 1.0 * 30 = 30.0
|
|
447
|
-
expect(summary.monthlyProjection).toBeCloseTo(30.0, 6);
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
test('getEntries() filters by session', () => {
|
|
451
|
-
tracker.recordLLMCost({
|
|
452
|
-
sessionId: 'alpha',
|
|
453
|
-
model: 'claude',
|
|
454
|
-
inputTokens: 100,
|
|
455
|
-
outputTokens: 50,
|
|
456
|
-
costUSD: 0.01,
|
|
457
|
-
});
|
|
458
|
-
tracker.recordInfraCost({
|
|
459
|
-
sessionId: 'beta',
|
|
460
|
-
description: 'Lambda',
|
|
461
|
-
monthlyCost: 5.0,
|
|
462
|
-
});
|
|
463
|
-
tracker.recordLLMCost({
|
|
464
|
-
sessionId: 'alpha',
|
|
465
|
-
model: 'claude',
|
|
466
|
-
inputTokens: 200,
|
|
467
|
-
outputTokens: 100,
|
|
468
|
-
costUSD: 0.02,
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
const alphaEntries = tracker.getEntries('alpha');
|
|
472
|
-
expect(alphaEntries.length).toBe(2);
|
|
473
|
-
expect(alphaEntries.every(e => e.sessionId === 'alpha')).toBe(true);
|
|
474
|
-
|
|
475
|
-
const betaEntries = tracker.getEntries('beta');
|
|
476
|
-
expect(betaEntries.length).toBe(1);
|
|
477
|
-
expect(betaEntries[0].category).toBe('infra');
|
|
478
|
-
|
|
479
|
-
// All entries when no filter
|
|
480
|
-
const allEntries = tracker.getEntries();
|
|
481
|
-
expect(allEntries.length).toBe(3);
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
test('formatSummary() produces readable output', () => {
|
|
485
|
-
tracker.recordLLMCost({
|
|
486
|
-
sessionId: 'demo',
|
|
487
|
-
model: 'claude-sonnet-4-20250514',
|
|
488
|
-
inputTokens: 1500,
|
|
489
|
-
outputTokens: 800,
|
|
490
|
-
costUSD: 0.0165,
|
|
491
|
-
});
|
|
492
|
-
tracker.recordInfraCost({
|
|
493
|
-
sessionId: 'demo',
|
|
494
|
-
description: 'RDS t3.micro',
|
|
495
|
-
monthlyCost: 15.33,
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
const summary = tracker.getSummary();
|
|
499
|
-
const output = tracker.formatSummary(summary);
|
|
500
|
-
|
|
501
|
-
expect(output).toContain('Cost Summary');
|
|
502
|
-
expect(output).toContain('Total Cost:');
|
|
503
|
-
expect(output).toContain('LLM Cost:');
|
|
504
|
-
expect(output).toContain('Infra Cost:');
|
|
505
|
-
expect(output).toContain('Monthly Estimate:');
|
|
506
|
-
expect(output).toContain('Per-Session Breakdown:');
|
|
507
|
-
expect(output).toContain('demo');
|
|
508
|
-
expect(output).toContain('Daily Costs:');
|
|
509
|
-
expect(output).toContain('Projected monthly cost:');
|
|
510
|
-
});
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
// ============================================================================
|
|
514
|
-
// Activity Log
|
|
515
|
-
// ============================================================================
|
|
516
|
-
|
|
517
|
-
describe('Activity Log', () => {
|
|
518
|
-
let log: ActivityLog;
|
|
519
|
-
|
|
520
|
-
beforeEach(() => {
|
|
521
|
-
log = new ActivityLog();
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
test('log() creates entry with auto-generated ID', () => {
|
|
525
|
-
const entry = log.log({
|
|
526
|
-
timestamp: new Date(),
|
|
527
|
-
sessionId: 'session-1',
|
|
528
|
-
toolName: 'terraform_plan',
|
|
529
|
-
toolInput: { dir: '/infra' },
|
|
530
|
-
result: { output: 'Plan: 3 to add', isError: false },
|
|
531
|
-
duration: 4200,
|
|
532
|
-
mode: 'plan',
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
expect(entry.id).toBeDefined();
|
|
536
|
-
expect(typeof entry.id).toBe('string');
|
|
537
|
-
expect(entry.id.length).toBeGreaterThan(0);
|
|
538
|
-
expect(entry.toolName).toBe('terraform_plan');
|
|
539
|
-
expect(entry.sessionId).toBe('session-1');
|
|
540
|
-
expect(entry.duration).toBe(4200);
|
|
541
|
-
expect(entry.mode).toBe('plan');
|
|
542
|
-
});
|
|
543
|
-
|
|
544
|
-
test('query() returns all entries with no filter', () => {
|
|
545
|
-
log.log({
|
|
546
|
-
timestamp: new Date(),
|
|
547
|
-
sessionId: 's1',
|
|
548
|
-
toolName: 'file_read',
|
|
549
|
-
toolInput: { path: '/a.ts' },
|
|
550
|
-
result: { output: 'ok', isError: false },
|
|
551
|
-
duration: 50,
|
|
552
|
-
mode: 'build',
|
|
553
|
-
});
|
|
554
|
-
log.log({
|
|
555
|
-
timestamp: new Date(),
|
|
556
|
-
sessionId: 's1',
|
|
557
|
-
toolName: 'git_commit',
|
|
558
|
-
toolInput: { message: 'fix' },
|
|
559
|
-
result: { output: 'committed', isError: false },
|
|
560
|
-
duration: 300,
|
|
561
|
-
mode: 'build',
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
const results = log.query();
|
|
565
|
-
|
|
566
|
-
expect(results.length).toBe(2);
|
|
567
|
-
});
|
|
568
|
-
|
|
569
|
-
test('query() filters by toolName', () => {
|
|
570
|
-
log.log({
|
|
571
|
-
timestamp: new Date(),
|
|
572
|
-
sessionId: 's1',
|
|
573
|
-
toolName: 'file_read',
|
|
574
|
-
toolInput: {},
|
|
575
|
-
result: { output: 'ok', isError: false },
|
|
576
|
-
duration: 10,
|
|
577
|
-
mode: 'build',
|
|
578
|
-
});
|
|
579
|
-
log.log({
|
|
580
|
-
timestamp: new Date(),
|
|
581
|
-
sessionId: 's1',
|
|
582
|
-
toolName: 'terraform_plan',
|
|
583
|
-
toolInput: {},
|
|
584
|
-
result: { output: 'ok', isError: false },
|
|
585
|
-
duration: 3000,
|
|
586
|
-
mode: 'plan',
|
|
587
|
-
});
|
|
588
|
-
log.log({
|
|
589
|
-
timestamp: new Date(),
|
|
590
|
-
sessionId: 's1',
|
|
591
|
-
toolName: 'file_read',
|
|
592
|
-
toolInput: {},
|
|
593
|
-
result: { output: 'ok', isError: false },
|
|
594
|
-
duration: 15,
|
|
595
|
-
mode: 'build',
|
|
596
|
-
});
|
|
597
|
-
|
|
598
|
-
const results = log.query({ toolName: 'file_read' });
|
|
599
|
-
|
|
600
|
-
expect(results.length).toBe(2);
|
|
601
|
-
expect(results.every(e => e.toolName === 'file_read')).toBe(true);
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
test('query() filters by date range', () => {
|
|
605
|
-
const jan1 = new Date('2025-01-01T00:00:00Z');
|
|
606
|
-
const feb1 = new Date('2025-02-01T00:00:00Z');
|
|
607
|
-
const mar1 = new Date('2025-03-01T00:00:00Z');
|
|
608
|
-
|
|
609
|
-
log.log({
|
|
610
|
-
timestamp: jan1,
|
|
611
|
-
sessionId: 's1',
|
|
612
|
-
toolName: 'tool_a',
|
|
613
|
-
toolInput: {},
|
|
614
|
-
result: { output: '', isError: false },
|
|
615
|
-
duration: 100,
|
|
616
|
-
mode: 'build',
|
|
617
|
-
});
|
|
618
|
-
log.log({
|
|
619
|
-
timestamp: feb1,
|
|
620
|
-
sessionId: 's1',
|
|
621
|
-
toolName: 'tool_b',
|
|
622
|
-
toolInput: {},
|
|
623
|
-
result: { output: '', isError: false },
|
|
624
|
-
duration: 100,
|
|
625
|
-
mode: 'build',
|
|
626
|
-
});
|
|
627
|
-
log.log({
|
|
628
|
-
timestamp: mar1,
|
|
629
|
-
sessionId: 's1',
|
|
630
|
-
toolName: 'tool_c',
|
|
631
|
-
toolInput: {},
|
|
632
|
-
result: { output: '', isError: false },
|
|
633
|
-
duration: 100,
|
|
634
|
-
mode: 'build',
|
|
635
|
-
});
|
|
636
|
-
|
|
637
|
-
const results = log.query({
|
|
638
|
-
since: new Date('2025-01-15T00:00:00Z'),
|
|
639
|
-
until: new Date('2025-02-15T00:00:00Z'),
|
|
640
|
-
});
|
|
641
|
-
|
|
642
|
-
expect(results.length).toBe(1);
|
|
643
|
-
expect(results[0].toolName).toBe('tool_b');
|
|
644
|
-
});
|
|
645
|
-
|
|
646
|
-
test('query() filters by sessionId', () => {
|
|
647
|
-
log.log({
|
|
648
|
-
timestamp: new Date(),
|
|
649
|
-
sessionId: 'alpha',
|
|
650
|
-
toolName: 'file_read',
|
|
651
|
-
toolInput: {},
|
|
652
|
-
result: { output: '', isError: false },
|
|
653
|
-
duration: 10,
|
|
654
|
-
mode: 'build',
|
|
655
|
-
});
|
|
656
|
-
log.log({
|
|
657
|
-
timestamp: new Date(),
|
|
658
|
-
sessionId: 'beta',
|
|
659
|
-
toolName: 'file_write',
|
|
660
|
-
toolInput: {},
|
|
661
|
-
result: { output: '', isError: false },
|
|
662
|
-
duration: 20,
|
|
663
|
-
mode: 'build',
|
|
664
|
-
});
|
|
665
|
-
log.log({
|
|
666
|
-
timestamp: new Date(),
|
|
667
|
-
sessionId: 'alpha',
|
|
668
|
-
toolName: 'git_status',
|
|
669
|
-
toolInput: {},
|
|
670
|
-
result: { output: '', isError: false },
|
|
671
|
-
duration: 30,
|
|
672
|
-
mode: 'build',
|
|
673
|
-
});
|
|
674
|
-
|
|
675
|
-
const results = log.query({ sessionId: 'alpha' });
|
|
676
|
-
|
|
677
|
-
expect(results.length).toBe(2);
|
|
678
|
-
expect(results.every(e => e.sessionId === 'alpha')).toBe(true);
|
|
679
|
-
});
|
|
680
|
-
|
|
681
|
-
test('query() filters by error status', () => {
|
|
682
|
-
log.log({
|
|
683
|
-
timestamp: new Date(),
|
|
684
|
-
sessionId: 's1',
|
|
685
|
-
toolName: 'terraform_apply',
|
|
686
|
-
toolInput: {},
|
|
687
|
-
result: { output: 'Error: access denied', isError: true },
|
|
688
|
-
duration: 5000,
|
|
689
|
-
mode: 'deploy',
|
|
690
|
-
});
|
|
691
|
-
log.log({
|
|
692
|
-
timestamp: new Date(),
|
|
693
|
-
sessionId: 's1',
|
|
694
|
-
toolName: 'file_read',
|
|
695
|
-
toolInput: {},
|
|
696
|
-
result: { output: 'ok', isError: false },
|
|
697
|
-
duration: 10,
|
|
698
|
-
mode: 'build',
|
|
699
|
-
});
|
|
700
|
-
|
|
701
|
-
const errors = log.query({ isError: true });
|
|
702
|
-
expect(errors.length).toBe(1);
|
|
703
|
-
expect(errors[0].toolName).toBe('terraform_apply');
|
|
704
|
-
|
|
705
|
-
const successes = log.query({ isError: false });
|
|
706
|
-
expect(successes.length).toBe(1);
|
|
707
|
-
expect(successes[0].toolName).toBe('file_read');
|
|
708
|
-
});
|
|
709
|
-
|
|
710
|
-
test('query() respects limit', () => {
|
|
711
|
-
for (let i = 0; i < 10; i++) {
|
|
712
|
-
log.log({
|
|
713
|
-
timestamp: new Date(Date.now() + i * 1000),
|
|
714
|
-
sessionId: 's1',
|
|
715
|
-
toolName: `tool_${i}`,
|
|
716
|
-
toolInput: {},
|
|
717
|
-
result: { output: '', isError: false },
|
|
718
|
-
duration: 100,
|
|
719
|
-
mode: 'build',
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
const results = log.query({ limit: 3 });
|
|
724
|
-
|
|
725
|
-
expect(results.length).toBe(3);
|
|
726
|
-
});
|
|
727
|
-
|
|
728
|
-
test('getStats() returns correct totals', () => {
|
|
729
|
-
log.log({
|
|
730
|
-
timestamp: new Date(),
|
|
731
|
-
sessionId: 's1',
|
|
732
|
-
toolName: 'file_read',
|
|
733
|
-
toolInput: {},
|
|
734
|
-
result: { output: '', isError: false },
|
|
735
|
-
duration: 100,
|
|
736
|
-
mode: 'build',
|
|
737
|
-
});
|
|
738
|
-
log.log({
|
|
739
|
-
timestamp: new Date(),
|
|
740
|
-
sessionId: 's1',
|
|
741
|
-
toolName: 'terraform_plan',
|
|
742
|
-
toolInput: {},
|
|
743
|
-
result: { output: 'Error', isError: true },
|
|
744
|
-
duration: 5000,
|
|
745
|
-
mode: 'plan',
|
|
746
|
-
});
|
|
747
|
-
log.log({
|
|
748
|
-
timestamp: new Date(),
|
|
749
|
-
sessionId: 's1',
|
|
750
|
-
toolName: 'file_read',
|
|
751
|
-
toolInput: {},
|
|
752
|
-
result: { output: '', isError: false },
|
|
753
|
-
duration: 200,
|
|
754
|
-
mode: 'build',
|
|
755
|
-
});
|
|
756
|
-
|
|
757
|
-
const stats = log.getStats();
|
|
758
|
-
|
|
759
|
-
expect(stats.totalCalls).toBe(3);
|
|
760
|
-
expect(stats.errorCount).toBe(1);
|
|
761
|
-
// avg = (100 + 5000 + 200) / 3 = 1766.666... => round = 1767
|
|
762
|
-
expect(stats.avgDuration).toBe(1767);
|
|
763
|
-
});
|
|
764
|
-
|
|
765
|
-
test('getStats() returns tool breakdown', () => {
|
|
766
|
-
log.log({
|
|
767
|
-
timestamp: new Date(),
|
|
768
|
-
sessionId: 's1',
|
|
769
|
-
toolName: 'file_read',
|
|
770
|
-
toolInput: {},
|
|
771
|
-
result: { output: '', isError: false },
|
|
772
|
-
duration: 10,
|
|
773
|
-
mode: 'build',
|
|
774
|
-
});
|
|
775
|
-
log.log({
|
|
776
|
-
timestamp: new Date(),
|
|
777
|
-
sessionId: 's1',
|
|
778
|
-
toolName: 'file_read',
|
|
779
|
-
toolInput: {},
|
|
780
|
-
result: { output: '', isError: false },
|
|
781
|
-
duration: 10,
|
|
782
|
-
mode: 'build',
|
|
783
|
-
});
|
|
784
|
-
log.log({
|
|
785
|
-
timestamp: new Date(),
|
|
786
|
-
sessionId: 's1',
|
|
787
|
-
toolName: 'terraform_plan',
|
|
788
|
-
toolInput: {},
|
|
789
|
-
result: { output: '', isError: false },
|
|
790
|
-
duration: 3000,
|
|
791
|
-
mode: 'plan',
|
|
792
|
-
});
|
|
793
|
-
log.log({
|
|
794
|
-
timestamp: new Date(),
|
|
795
|
-
sessionId: 's1',
|
|
796
|
-
toolName: 'git_commit',
|
|
797
|
-
toolInput: {},
|
|
798
|
-
result: { output: '', isError: false },
|
|
799
|
-
duration: 500,
|
|
800
|
-
mode: 'build',
|
|
801
|
-
});
|
|
802
|
-
|
|
803
|
-
const stats = log.getStats();
|
|
804
|
-
|
|
805
|
-
expect(stats.toolBreakdown['file_read']).toBe(2);
|
|
806
|
-
expect(stats.toolBreakdown['terraform_plan']).toBe(1);
|
|
807
|
-
expect(stats.toolBreakdown['git_commit']).toBe(1);
|
|
808
|
-
});
|
|
809
|
-
|
|
810
|
-
test('formatLog() produces readable output', () => {
|
|
811
|
-
const now = new Date('2025-06-15T10:30:00Z');
|
|
812
|
-
log.log({
|
|
813
|
-
timestamp: now,
|
|
814
|
-
sessionId: 's1',
|
|
815
|
-
toolName: 'terraform_plan',
|
|
816
|
-
toolInput: { dir: '/infra' },
|
|
817
|
-
result: { output: 'Plan: 3 to add', isError: false },
|
|
818
|
-
duration: 4200,
|
|
819
|
-
mode: 'plan',
|
|
820
|
-
});
|
|
821
|
-
log.log({
|
|
822
|
-
timestamp: new Date(now.getTime() + 60000),
|
|
823
|
-
sessionId: 's1',
|
|
824
|
-
toolName: 'terraform_apply',
|
|
825
|
-
toolInput: { dir: '/infra' },
|
|
826
|
-
result: { output: 'Error: access denied', isError: true },
|
|
827
|
-
duration: 1200,
|
|
828
|
-
mode: 'deploy',
|
|
829
|
-
});
|
|
830
|
-
|
|
831
|
-
const entries = log.query();
|
|
832
|
-
const output = log.formatLog(entries);
|
|
833
|
-
|
|
834
|
-
expect(output).toContain('Activity Log');
|
|
835
|
-
expect(output).toContain('2 entries');
|
|
836
|
-
expect(output).toContain('terraform_plan');
|
|
837
|
-
expect(output).toContain('terraform_apply');
|
|
838
|
-
expect(output).toContain('[OK]');
|
|
839
|
-
expect(output).toContain('[ERROR]');
|
|
840
|
-
expect(output).toContain('[plan]');
|
|
841
|
-
expect(output).toContain('[deploy]');
|
|
842
|
-
expect(output).toContain('1 errors');
|
|
843
|
-
});
|
|
844
|
-
|
|
845
|
-
test('formatLog() handles empty entries', () => {
|
|
846
|
-
const output = log.formatLog([]);
|
|
847
|
-
expect(output).toBe('No activity entries to display.');
|
|
848
|
-
});
|
|
849
|
-
|
|
850
|
-
test('clear() removes all entries', () => {
|
|
851
|
-
log.log({
|
|
852
|
-
timestamp: new Date(),
|
|
853
|
-
sessionId: 's1',
|
|
854
|
-
toolName: 'file_read',
|
|
855
|
-
toolInput: {},
|
|
856
|
-
result: { output: '', isError: false },
|
|
857
|
-
duration: 10,
|
|
858
|
-
mode: 'build',
|
|
859
|
-
});
|
|
860
|
-
log.log({
|
|
861
|
-
timestamp: new Date(),
|
|
862
|
-
sessionId: 's1',
|
|
863
|
-
toolName: 'git_status',
|
|
864
|
-
toolInput: {},
|
|
865
|
-
result: { output: '', isError: false },
|
|
866
|
-
duration: 50,
|
|
867
|
-
mode: 'build',
|
|
868
|
-
});
|
|
869
|
-
|
|
870
|
-
expect(log.query().length).toBe(2);
|
|
871
|
-
|
|
872
|
-
log.clear();
|
|
873
|
-
|
|
874
|
-
expect(log.query().length).toBe(0);
|
|
875
|
-
expect(log.getStats().totalCalls).toBe(0);
|
|
876
|
-
});
|
|
877
|
-
});
|