fix: address CodeRabbit PR review feedback

- Use Object.hasOwn() instead of `in` for log level validation
- Normalize relativePath in shouldIgnore() for Windows compatibility
- Reject zero/negative/decimal values in embedding config (Number() instead of parseInt())
- Update aggregate test count to 765
- Harden code-graph test assertion with explicit toBeDefined()
This commit is contained in:
Giancarlo Erra
2026-04-12 21:31:45 +01:00
parent bb5e6c3e19
commit 00f7be169c
5 changed files with 14 additions and 15 deletions
+1 -1
View File
@@ -515,7 +515,7 @@ Uses depth-first search (DFS) with a recursion stack to find cycles in the direc
## Testing
SocratiCode uses **vitest** as its test framework with **634 tests** across three layers.
SocratiCode uses **vitest** as its test framework with **765 tests** across three layers.
### Running Tests
+7 -8
View File
@@ -129,13 +129,12 @@ export function loadEmbeddingConfig(): EmbeddingConfig {
// ── Model & dimensions (provider-specific defaults) ─────────────────
const embeddingModel = process.env.EMBEDDING_MODEL || providerDefaults.model;
const rawDimensions = parseInt(
process.env.EMBEDDING_DIMENSIONS || String(providerDefaults.dimensions),
10,
const rawDimensions = Number(
process.env.EMBEDDING_DIMENSIONS || providerDefaults.dimensions,
);
if (Number.isNaN(rawDimensions)) {
if (!Number.isInteger(rawDimensions) || rawDimensions <= 0) {
throw new Error(
`Invalid EMBEDDING_DIMENSIONS: "${process.env.EMBEDDING_DIMENSIONS}". Must be a number.`,
`Invalid EMBEDDING_DIMENSIONS: "${process.env.EMBEDDING_DIMENSIONS}". Must be a positive integer.`,
);
}
const embeddingDimensions = rawDimensions;
@@ -150,10 +149,10 @@ export function loadEmbeddingConfig(): EmbeddingConfig {
embeddingDimensions,
embeddingContextLength: contextLengthEnv
? (() => {
const parsed = parseInt(contextLengthEnv, 10);
if (Number.isNaN(parsed)) {
const parsed = Number(contextLengthEnv);
if (!Number.isInteger(parsed) || parsed <= 0) {
throw new Error(
`Invalid EMBEDDING_CONTEXT_LENGTH: "${contextLengthEnv}". Must be a number.`,
`Invalid EMBEDDING_CONTEXT_LENGTH: "${contextLengthEnv}". Must be a positive integer.`,
);
}
return parsed;
+2 -1
View File
@@ -158,5 +158,6 @@ function findNestedGitignores(rootPath: string, currentPath: string, ig: Ignore)
* Check if a relative path should be ignored.
*/
export function shouldIgnore(ig: Ignore, relativePath: string): boolean {
return ig.ignores(relativePath);
const normalized = relativePath.split(path.sep).join("/");
return ig.ignores(normalized);
}
+1 -1
View File
@@ -26,7 +26,7 @@ const LOG_LEVELS: Record<LogLevel, number> = {
};
const envLevel = process.env.SOCRATICODE_LOG_LEVEL?.toLowerCase();
const currentLevel: LogLevel = envLevel && envLevel in LOG_LEVELS
const currentLevel: LogLevel = envLevel && Object.hasOwn(LOG_LEVELS, envLevel)
? (envLevel as LogLevel)
: "info";
const logFilePath: string | undefined = process.env.SOCRATICODE_LOG_FILE || undefined;
+3 -4
View File
@@ -110,10 +110,9 @@ describe("code-graph service", () => {
const helpersNode = graph.nodes.find((n) =>
n.relativePath.includes("helpers.ts"),
);
if (helpersNode) {
// If the graph correctly resolves imports, helpers should have dependents
expect(helpersNode.dependents.length).toBeGreaterThan(0);
}
expect(helpersNode).toBeDefined();
// If the graph correctly resolves imports, helpers should have dependents
expect(helpersNode?.dependents.length).toBeGreaterThan(0);
});
it("includes Python files in the graph", async () => {