Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server utils config test #2486

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions packages/server/test/utils/config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const assert = require('assert')
const path = require('path')

// Mock dotenv to control the environment variables for testing
require('dotenv').config = ({ path, override }) => {

Check warning on line 5 in packages/server/test/utils/config.test.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

'path' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 5 in packages/server/test/utils/config.test.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

'override' is defined but never used. Allowed unused args must match /^_/u
process.env.LOG_PATH = '/custom/log/path'
process.env.LOG_LEVEL = 'debug'
}

// Mocked path join to control paths for testing
const originalPathJoin = path.join
path.join = (...args) => {
if (args.includes('logs')) {
return '/default/log/path'
}
return originalPathJoin(...args)
}

// Import the configuration module
const config = require('../../dist/utils/config').default

// Restore path.join after the test
path.join = originalPathJoin

// Test cases
function testLoggingConfig() {
const loggingConfig = config.logging

// Check if LOG_PATH environment variable is considered
assert.strictEqual(loggingConfig.dir, '/custom/log/path', 'Logging directory should match the LOG_PATH environment variable')

// Check if LOG_LEVEL environment variable is considered
assert.strictEqual(loggingConfig.server.level, 'debug', 'Server log level should match the LOG_LEVEL environment variable')
assert.strictEqual(loggingConfig.express.level, 'debug', 'Express log level should match the LOG_LEVEL environment variable')

// Check the default filenames
assert.strictEqual(loggingConfig.server.filename, 'server.log', 'Server log filename should be server.log')
assert.strictEqual(loggingConfig.server.errorFilename, 'server-error.log', 'Server error log filename should be server-error.log')
assert.strictEqual(
loggingConfig.express.filename,
'server-requests.log.jsonl',
'Express log filename should be server-requests.log.jsonl'
)

console.log('All config tests passed')

Check failure on line 45 in packages/server/test/utils/config.test.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Unexpected console statement
}

// Run the tests
testLoggingConfig()
140 changes: 140 additions & 0 deletions packages/server/test/utils/hub.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
const assert = require('assert')
const { parsePrompt } = require('../../dist/utils/hub')

// Test: Parse system message prompts correctly
const testSystemMessagePrompt = () => {
const prompt = JSON.stringify({
kwargs: {
messages: [
{
id: 'SystemMessagePromptTemplate1',
kwargs: {
prompt: {
kwargs: {
template: 'System message template'
}
}
}
}
]
}
})

const result = parsePrompt(prompt)
const expected = [
{
type: 'systemMessagePrompt',
typeDisplay: 'System Message',
template: 'System message template'
}
]
assert.deepStrictEqual(result, expected)
console.log('Test passed: System message prompt')

Check failure on line 32 in packages/server/test/utils/hub.test.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Unexpected console statement
}

// Test: Parse human message prompts correctly
const testHumanMessagePrompt = () => {
const prompt = JSON.stringify({
kwargs: {
messages: [
{
id: 'HumanMessagePromptTemplate1',
kwargs: {
prompt: {
kwargs: {
template: 'Human message template'
}
}
}
}
]
}
})

const result = parsePrompt(prompt)
const expected = [
{
type: 'humanMessagePrompt',
typeDisplay: 'Human Message',
template: 'Human message template'
}
]
assert.deepStrictEqual(result, expected)
console.log('Test passed: Human message prompt')

Check failure on line 63 in packages/server/test/utils/hub.test.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Unexpected console statement
}

// Test: Parse AI message prompts correctly
const testAIMessagePrompt = () => {
const prompt = JSON.stringify({
kwargs: {
messages: [
{
id: 'AIMessagePromptTemplate1',
kwargs: {
prompt: {
kwargs: {
template: 'AI message template'
}
}
}
}
]
}
})

const result = parsePrompt(prompt)
const expected = [
{
type: 'aiMessagePrompt',
typeDisplay: 'AI Message',
template: 'AI message template'
}
]
assert.deepStrictEqual(result, expected)
console.log('Test passed: AI message prompt')

Check failure on line 94 in packages/server/test/utils/hub.test.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Unexpected console statement
}

// Test: Parse template prompts correctly
const testTemplatePrompt = () => {
const prompt = JSON.stringify({
kwargs: {
template: 'General template'
}
})

const result = parsePrompt(prompt)
const expected = [
{
type: 'template',
typeDisplay: 'Prompt',
template: 'General template'
}
]
assert.deepStrictEqual(result, expected)
console.log('Test passed: Template prompt')

Check failure on line 114 in packages/server/test/utils/hub.test.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Unexpected console statement
}

// Test: Handle empty messages array
const testEmptyMessages = () => {
const prompt = JSON.stringify({
kwargs: {
messages: []
}
})

const result = parsePrompt(prompt)
const expected = []
assert.deepStrictEqual(result, expected)
console.log('Test passed: Empty messages array')

Check failure on line 128 in packages/server/test/utils/hub.test.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Unexpected console statement
}

// Run all tests
const runTests = () => {
testSystemMessagePrompt()
testHumanMessagePrompt()
testAIMessagePrompt()
testTemplatePrompt()
testEmptyMessages()
}

runTests()
8 changes: 7 additions & 1 deletion packages/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@
"strictPropertyInitialization": false,
"declaration": true
},
"include": ["src"]
"include": [

Check failure on line 17 in packages/server/tsconfig.json

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Replace `⏎········"src/**/*.ts"⏎····` with `"src/**/*.ts"`
"src/**/*.ts"
],
"exclude": [

Check failure on line 20 in packages/server/tsconfig.json

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Replace `⏎········"node_modules",⏎········"**/*.test.ts"⏎····` with `"node_modules",·"**/*.test.ts"`
"node_modules",
"**/*.test.ts"
]
}
Loading