spmallette commented on code in PR #3238:
URL: https://github.com/apache/tinkerpop/pull/3238#discussion_r2437232092


##########
gremlin-mcp/src/main/javascript/tests/config.test.ts:
##########
@@ -0,0 +1,280 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+/**
+ * Tests for Effect-based configuration management and validation.
+ */
+
+import { Effect } from 'effect';
+import { GREMLIN_VERSION } from '../src/constants';
+import { AppConfig, type AppConfigType } from '../src/config';
+
+describe('Effect-based Configuration Management', () => {
+  const originalEnv = process.env;
+
+  beforeEach(() => {
+    // Reset environment variables
+    process.env = { ...originalEnv };
+  });
+
+  afterEach(() => {
+    // Restore original environment
+    process.env = originalEnv;
+  });
+
+  describe('AppConfig Effect', () => {
+    it('should validate a complete configuration', async () => {
+      process.env.GREMLIN_ENDPOINT = 'localhost:8182/g';
+      process.env.GREMLIN_USE_SSL = 'false';
+      process.env.GREMLIN_USERNAME = 'testuser';
+      process.env.GREMLIN_PASSWORD = 'testpass';
+      process.env.LOG_LEVEL = 'info';
+      process.env.GREMLIN_IDLE_TIMEOUT = '300';
+      process.env.GREMLIN_ENUM_DISCOVERY_ENABLED = 'true';
+      process.env.GREMLIN_ENUM_CARDINALITY_THRESHOLD = '10';
+      process.env.GREMLIN_ENUM_PROPERTY_DENYLIST = 'id,pk,name';
+      process.env.GREMLIN_SCHEMA_INCLUDE_SAMPLE_VALUES = 'false';
+      process.env.GREMLIN_SCHEMA_MAX_ENUM_VALUES = '10';
+      process.env.GREMLIN_SCHEMA_INCLUDE_COUNTS = 'true';
+
+      const result = await Effect.runPromise(AppConfig);
+
+      expect(result).toMatchObject({
+        gremlin: {
+          host: 'localhost',
+          port: 8182,
+          traversalSource: 'g',
+          useSSL: false,
+          idleTimeout: 300,
+        },
+        schema: {
+          enumDiscoveryEnabled: true,
+          enumCardinalityThreshold: 10,
+          enumPropertyDenyList: ['id', 'pk', 'name'],
+          includeSampleValues: false,
+          maxEnumValues: 10,
+          includeCounts: true,
+        },
+        logging: {
+          level: 'info',
+        },
+        server: {
+          name: 'gremlin-mcp',
+          version: GREMLIN_VERSION,
+        },
+      });
+      expect(result.gremlin.username).toBeDefined();
+      expect(result.gremlin.password).toBeDefined();
+    });
+
+    it('should handle minimal configuration with defaults', async () => {
+      process.env.GREMLIN_ENDPOINT = 'localhost:8182';
+
+      const result = await Effect.runPromise(AppConfig);
+
+      expect(result).toMatchObject({
+        gremlin: {
+          host: 'localhost',
+          port: 8182,
+          traversalSource: 'g',
+          useSSL: false,
+          idleTimeout: 300,
+        },
+        schema: {
+          enumDiscoveryEnabled: true,
+          enumCardinalityThreshold: 10,
+          includeSampleValues: false,
+          maxEnumValues: 10,
+          includeCounts: true,
+        },
+        logging: {
+          level: 'info',
+        },
+      });
+    });
+
+    it('should fail when required GREMLIN_ENDPOINT is missing', async () => {
+      delete process.env.GREMLIN_ENDPOINT;
+
+      await expect(Effect.runPromise(AppConfig)).rejects.toThrow();
+    });
+
+    it('should parse boolean values correctly', async () => {
+      process.env.GREMLIN_ENDPOINT = 'localhost:8182';
+      process.env.GREMLIN_USE_SSL = 'true';
+      process.env.GREMLIN_ENUM_DISCOVERY_ENABLED = 'true';
+      process.env.GREMLIN_SCHEMA_INCLUDE_SAMPLE_VALUES = 'true';
+      process.env.GREMLIN_SCHEMA_INCLUDE_COUNTS = 'false';
+
+      const result = await Effect.runPromise(AppConfig);
+
+      expect(result.gremlin.useSSL).toBe(true);
+      expect(result.schema.enumDiscoveryEnabled).toBe(true);
+      expect(result.schema.includeSampleValues).toBe(true);
+      expect(result.schema.includeCounts).toBe(false);
+    });
+
+    it('should parse endpoint with traversal source', async () => {
+      process.env.GREMLIN_ENDPOINT = 'localhost:8182/custom';
+
+      const result = await Effect.runPromise(AppConfig);
+
+      expect(result.gremlin.host).toBe('localhost');
+      expect(result.gremlin.port).toBe(8182);
+      expect(result.gremlin.traversalSource).toBe('custom');
+    });
+
+    it('should parse comma-separated denylist', async () => {
+      process.env.GREMLIN_ENDPOINT = 'localhost:8182';
+      process.env.GREMLIN_ENUM_PROPERTY_DENYLIST = 'id, pk, name, description';
+
+      const result = await Effect.runPromise(AppConfig);
+
+      expect(result.schema.enumPropertyDenyList).toEqual(['id', 'pk', 'name', 
'description']);
+    });
+
+    it('should validate log level enum', async () => {
+      process.env.GREMLIN_ENDPOINT = 'localhost:8182';
+      process.env.LOG_LEVEL = 'debug';
+
+      const result = await Effect.runPromise(AppConfig);
+
+      expect(result.logging.level).toBe('debug');

Review Comment:
   https://issues.apache.org/jira/browse/TINKERPOP-3206



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to