Skip to content
Merged
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
5 changes: 3 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@
"@nestjs/platform-express": "^10.0.0",
"@nestjs/typeorm": "^10.0.2",
"@types/bcrypt": "^5.0.2",
"axios": "^1.7.7",
"@types/fs-extra": "^11.0.4",
"@types/normalize-path": "^3.0.2",
"@types/toposort": "^2.0.7",
"axios": "^1.7.7",
"bcrypt": "^5.1.1",
"class-validator": "^0.14.1",
"fs-extra": "^11.2.0",
"graphql": "^16.9.0",
"lodash": "^4.17.21",
"graphql-subscriptions": "^2.0.0",
"graphql-ws": "^5.16.0",
"lodash": "^4.17.21",
"markdown-to-txt": "^2.0.1",
"normalize-path": "^3.0.0",
"reflect-metadata": "^0.2.2",
Expand Down
4 changes: 2 additions & 2 deletions backend/src/config/config-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export class ConfigLoader {

private loadConfig() {
const file = fs.readFileSync(this.configPath, 'utf-8');

this.chatsConfig = JSON.parse(file);
console.log('Raw file content:', this.chatsConfig);
}

get<T>(path: string) {
if (!path) {
return this.chatsConfig as unknown as T;
}
}
return _.get(this.chatsConfig, path) as T;
}
Comment on lines 30 to 35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Type safety concerns confirmed in config handling

The implementation shows several type-safety issues:

  • Raw JSON parsing without type validation
  • Basic existence check only in validateConfig
  • Unsafe type assertions in the get<T> method
  • No runtime type checking for the requested path's value type

Consider:

  • Using zod or similar for runtime type validation
  • Adding proper type guards before type assertions
  • Implementing stronger validation in validateConfig
  • Adding type checking for the path's return value before casting to T
🔗 Analysis chain

Verify type safety in the generic get method

The type casting using unknown could potentially bypass TypeScript's type checking. Consider adding runtime type validation or using a more type-safe approach.

Consider using a type-safe configuration library like zod or implementing runtime type checks. Here's a script to check for similar patterns in the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potentially unsafe type assertions
ast-grep --pattern 'as unknown as $_'

Length of output: 39


Script:

#!/bin/bash
# Let's try a different approach to find type assertions and the usage context
# First, let's see the full implementation of the config-loader
rg -A 10 "class.*Config" backend/src/config/config-loader.ts

# Then, let's look for any type assertions in the file
rg "as \w+" backend/src/config/config-loader.ts

# Also check how this config is used across the codebase
rg "get<\w+>" 

Length of output: 781


Script:

#!/bin/bash
# Let's examine how the config is actually used and validated
rg -B 2 -A 5 "ChatConfig\[\]" backend/src/config/config-loader.ts

# Check the ChatConfig type definition
fd -e ts -e d.ts ChatConfig --exec cat {}

# Look for any validation logic
rg -B 2 -A 5 "loadConfig|validateConfig" backend/src/config/config-loader.ts

Length of output: 791


Expand Down
2 changes: 1 addition & 1 deletion backend/src/model/__tests__/loadAllChatsModels.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('loadAllChatsModels with real model loading', () => {
{
model: 'Felladrin/onnx-flan-alpaca-base',
task: 'text2text-generation',
}
},
];
const configPath = getConfigPath('config');
fs.writeFileSync(configPath, JSON.stringify(testConfig, null, 2), 'utf8');
Expand Down
Loading
Loading