issue-143: Implement index.ts async factory + lifecycle with tests #160
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!160
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/issue-143/implement-index-ts-async-factory-lifecycle-with-te"
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?
143: Implement index.ts async factory + lifecycle with tests
Implements 143.
Generated in 10m 23s.
Review findings
Now I have a full picture. Let me apply the fixes. First, the test file — extract a
withCapturedLoghelper and use it across the factory tests, plus assert the URI in thecreateClientseam:Now the documentation reconciliation for the Medium finding — DESIGN.md (Module layout + Connection Lifecycle) and the plan's 6.1 item:Let me verify the edits and check the package scripts:Now run the gates — mongodb tests and type check in parallel:Mongodb tests pass (93/93) andtsc --noEmitis clean. Now the root gate:All gates green. Let me review the final diff of my remediation changes:All three findings are resolved and all gates are green (bun test93 pass,bunx tsc --noEmitclean, rootnpm test58 pass).Review Findings — 143
Summary
Stage 1 implements the MongoDB extension async factory + lifecycle (Phase 4.1 of the plan) and adds four tests covering unconfigured-silent behavior, tool registration/execution via
registerMongoTools, and lazy-client +session_shutdowncleanup. All gates ran and passed:bun test(mongodb, 93 pass),bunx tsc --noEmit(clean), rootnpm test(58 pass); no lint gate exists in the repo. No critical or high findings — the remaining items are a design-consistency gap and two minor test-quality nits. All three findings were remediated in this pass: thecreateClienttest seam is now documented in DESIGN.md (Module layout + Connection Lifecycle) with the plan's Phase 6.1 reconciliation item ticked, the lazy-client test asserts the resolved URI is passed to the seam, and the duplicatedconsole.logcapture/restore scaffolding is extracted into a sharedwithCapturedLoghelper used across all factory tests. No findings remain.Critical
High
Medium
MongoExtensionOptions/createClienthook is production API surface that exists solely for tests (its own JSDoc at index.ts:17 points at the test-onlysrc/tools/testClient.ts), and it diverges from the documented "mirrors postgres" factory shape (export default async function (pi)with no options param) in DESIGN.md's Architecture/Connection Lifecycle and the plan's Phase 4.1. It is backward-compatible at runtime, but the seam should be reconciled or narrowed. Suggested fix: document the optionalcreateClienttest seam in DESIGN.md's Module layout / Connection Lifecycle (and tick the Phase 6.1 reconciliation item), or keep the interface unexported so production API surface stays parallel to postgres.Low
extensions/mongodb/index.test.ts:278 —
createClient: () => injectedignores the resolved URI, so the test would still pass if the factory stopped passing the URI (or passed a wrong one). Suggested fix: assert the argument inside the injected factory, e.g.createClient: (uri) => { expect(uri).toBe("mongodb://localhost:27017/mydb"); return injected; }.extensions/mongodb/index.test.ts:153,177 — The
console.logcapture/restore scaffolding is now duplicated across three tests in the file (the two new "logs nothing" tests plus the existing configured test). Suggested fix: extract a small local helper (e.g.withCapturedLog(fn)returninglogged) and use it in all three to reduce repetition.