329: MSSQL: index.ts wiring (load env, refuse on invalid limits, pool, shutdown) #353
No reviewers
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills!353
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/issue-329/mssql-index-ts-wiring-load-env-refuse-on-invalid-l"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
329: MSSQL: index.ts wiring (load env, refuse on invalid limits, pool, shutdown)
Implements 329.
Generated in 1m 28s.
Review findings
Review Findings — 329
Summary
I fixed the High finding, all three Medium findings and the two Low findings that touched code or tests.
node --test extensions/mssql/index.test.tspasses all 14 tests. The repo has no build or lint script, so those gates did not run. I did not run the fullnpm testsuite.One finding remains: the root
README.mdstill has nomssqlentry. I left it for a follow-up documentation issue. I did document the env precedence inextensions/mssql/README.md.Critical
High
errorlistener is attached to the pool afterconnect().mssql.ConnectionPoolis an EventEmitter. A later connection drop or idle-connection error emitted with no listener becomes an uncaught exception and can crash the host pi process. Suggested fix: addManagedPool.on?("error", ...)(or extend the interface withon) and attach a handler right aftercreatePoolthat logs a generic message without credentials. Add a test that emittingerrordoes not throw.Medium
session_shutdownhandler awaitspool.close()without a try/catch. A rejected close during shutdown surfaces as an unhandled error. Suggested fix: useawait pool.close().catch(() => undefined), as the connect-failure path already does. Add a test wherecloserejects.audit.logsits inside the sametryas the permission check. If the audit write throws, the catch prints "could not verify that this login is read-only", which is misleading because the check actually succeeded. The failure is also silently lost. Suggested fix: wrap only thecheckWriteAccesscall in the try/catch and keep audit failures separate, sincecreateAuditLoggeralready reports write failures to stderr.{ ...loadEnvFile(), ...pickStrings(process.env) }merges the two sources by exact key.findEnvValueis case-insensitive and returns the first match. Keys that differ only in case (for example.envmssql_urlagainst processMSSQL_URL) therefore resolve to the.envvalue, not the process value. The intended precedence is unclear, and the mongodb extension and README say.envonly. Suggested fix: decide on one precedence. Either drop the process-env source, or normalise keys to upper case before merging so process env wins deterministically. Document the choice inextensions/mssql/README.md, and add a test for the precedence.Low
createAuditLogger()is called separately inwarnOnWriteAccess(line 31) and again at theregisterMssqlToolscall (line 68) whendeps.auditis absent. Suggested fix: resolveconst audit = deps.audit ?? createAuditLogger()once inloadMssqlExtensionand pass it to both.load_permissionCheckThrows_stillRegistersToolsonly asserts that the password is not leaked. It does not assert that the "could not verify" warning is printed. Suggested fix: addassert.ok(output.includes("could not verify")).mssqlentry. Suggested fix: addmssqldocumentation, either in this change or in a follow-up documentation issue.