fix(ai): post-remediation cleanup and test coverage#414
Conversation
- ai-errors: export allNoop helper for exhaustive handleAIErrors tests - extraction-parser: spread ...ValidationError instead of bare name string - tap-yaml: spread ...ParseError instead of bare name string - constants.test: replace safeParse leakage with parse()+Try(); trim to behavioral tests only - aggregation.test: full-object assertions; fix duplicate test.each labels - extraction-parser.test: add resolveImportPaths success/error tests; non-object branch test - execute-agent.test: add spawn failure, malformed JSON fallback, ParseError envelope tests Co-authored-by: Cursor <cursoragent@cursor.com>
|
@cursor please /review |
|
Excellent work! All 112 tests pass. Let me now provide a comprehensive code review. 🔬 Code Review Summary✅ Overall Assessment: APPROVEDThis is a high-quality cleanup PR that demonstrates excellent software engineering discipline. The changes improve test coverage, eliminate code duplication, and enhance maintainability without introducing any regressions. 📋 Detailed ReviewSource Changes
|
- ai-errors.test.js: removed; handleAIErrors routing already covered by agent-parser, aggregation, extraction-parser, and tap-yaml test suites Co-authored-by: Cursor <cursoragent@cursor.com>
a96a49d
into
ai-testing-framework-implementation-consolidation
- ai-errors: export allNoop helper for exhaustive handleAIErrors tests - extraction-parser: spread ...ValidationError instead of bare name string - tap-yaml: spread ...ParseError instead of bare name string - constants.test: replace safeParse leakage with parse()+Try(); trim to behavioral tests only - aggregation.test: full-object assertions; fix duplicate test.each labels - extraction-parser.test: add resolveImportPaths success/error tests; non-object branch test - execute-agent.test: add spawn failure, malformed JSON fallback, ParseError envelope tests - ai-errors.test.js: removed; handleAIErrors routing already covered by agent-parser, aggregation, extraction-parser, and tap-yaml test suites --------- Co-authored-by: Cursor <cursoragent@cursor.com>
- ai-errors: export allNoop helper for exhaustive handleAIErrors tests - extraction-parser: spread ...ValidationError instead of bare name string - tap-yaml: spread ...ParseError instead of bare name string - constants.test: replace safeParse leakage with parse()+Try(); trim to behavioral tests only - aggregation.test: full-object assertions; fix duplicate test.each labels - extraction-parser.test: add resolveImportPaths success/error tests; non-object branch test - execute-agent.test: add spawn failure, malformed JSON fallback, ParseError envelope tests - ai-errors.test.js: removed; handleAIErrors routing already covered by agent-parser, aggregation, extraction-parser, and tap-yaml test suites --------- Co-authored-by: Cursor <cursoragent@cursor.com>
- ai-errors: export allNoop helper for exhaustive handleAIErrors tests - extraction-parser: spread ...ValidationError instead of bare name string - tap-yaml: spread ...ParseError instead of bare name string - constants.test: replace safeParse leakage with parse()+Try(); trim to behavioral tests only - aggregation.test: full-object assertions; fix duplicate test.each labels - extraction-parser.test: add resolveImportPaths success/error tests; non-object branch test - execute-agent.test: add spawn failure, malformed JSON fallback, ParseError envelope tests - ai-errors.test.js: removed; handleAIErrors routing already covered by agent-parser, aggregation, extraction-parser, and tap-yaml test suites --------- Co-authored-by: Cursor <cursoragent@cursor.com>


Context
Follow-up to #412. These are the remaining local changes that were kept out of that PR to maintain a focused review surface — squashed into a single commit for easier review.
Changes
Source
source/ai-errors.jsallNoophelper — maps all registered error keys tonoop, eliminating boilerplate inhandleAIErrorstestssource/extraction-parser.js...ValidationErrorspread instead of barename: 'ValidationError'string — bug fixsource/tap-yaml.js...ParseErrorspread instead of barename: 'ParseError'string — bug fixTests
source/constants.test.jssafeParseAPI leakage withparse()+Try(); trim to 2 high-value behavioral tests onlysource/aggregation.test.jstest.eachlabels; remove logger assertion; simplify mock logger; remove unusedviimportsource/extraction-parser.test.jsresolveImportPathsdescribe block (success +ValidationError); add non-object branch test forparseExtractionResultsource/execute-agent.test.jsParseErroron non-string envelopesource/agent-parser.test.jsallNoopadoption; removecreateMockLoggerfactory; remove 7 logger assertion blockssource/ai-errors.test.jsallNoopadoptionsource/tap-yaml.test.jsallNoopadoption + assertion consolidationDecision notes for reviewers
Why
allNooplives inai-errors.js(a production file)handleAIErrorsrequires an exhaustive handler map — a constraint imposed by theerror-causesregistry we configured.allNoopis derived directly fromObject.keys(aiErrors), so it automatically stays in sync when new error types are added. Co-locating it with the registry means adding a 10th error type touches exactly one file instead of propagating a stale 9-entry block across every test file. A shared test-util would require a separate import chain and risk the map going stale without any signal.The production spread fixes are silent routing bugs, not style changes
Both
extraction-parser.jsandtap-yaml.jsused bare strings (name: 'ParseError',name: 'ValidationError') when throwing errors. If either type were renamed in theaiErrorsregistry, the mismatch would causehandleAIErrorsto silently skip the handler — the error would be swallowed, not re-thrown and not routed. Using...ParseError/...ValidationErrorspread couples the throw site to the registry so any rename is caught immediately.Why 7 logger assertion blocks were removed from
agent-parser.test.jsEach affected test previously had two
assertcalls: one on the return value, one onlogger.logs.some(log => log.includes('...')). The logger assertions were removed because:parseStringResultreturns{ passed: true }for a given input, the function worked. There is no additional correctness signal in knowing it also logged'Successfully parsed string as JSON'.The
createMockLoggerfactory (which captured logs into an array for inspection) was also removed and replaced with an inline{ log: () => {} }at each call site, since the factory existed solely to support log capture.The same principle applied to
aggregation.test.jsThe "defaults missing actual and expected with warning log" test was renamed to "defaults missing actual and expected" and its
logger.log.mock.calls[0][0]assertion was removed for the same reason. The existing assertion on the full returned object already proves the function normalised the fields correctly. As a consequence,createMockLoggerin that describe block was simplified from() => ({ log: vi.fn() })to() => ({ log: () => {} }), and the now-unusedviimport was removed.What was dropped from
constants.test.jsand whyThe six sub-schema describe blocks (
runsSchema,thresholdSchema, etc.) were already removed in #412 — those tested Zod's own validation behavior. Of the remaining sixaiTestOptionsSchematests, four "rejects" tests were collapsed: the invariant that invalid inputs are rejected is already exercised byaggregation.test.js'sValidationErrorpath, which drives the same schemas through their consuming function. The two tests kept are the behaviorally meaningful ones: "applies defaults" (asserts the concrete parsed output) and "applies lazycwddefault at parse time" (asserts runtime evaluation).resolveImportPathshad 0% coverage before this PRThe
...ValidationErrorbug fix inextraction-parser.jswas shipped in the previous commit without any test coverage for the affected path. The newresolveImportPathsdescribe block closes that gap — it directly exercises the error branch that the bug fix touched.Coverage delta
extraction-parser.jsexecute-agent.jsaggregation.jsWhy
Try(() => aiTestOptionsSchema.parse({...}))uses an arrow wrapperaiTestOptionsSchema.parseis a method on a Zod object — passing it as a bare function reference loses thethisbinding and throws. The arrow wrapper is the minimal fix consistent with howTryis used elsewhere in the codebase (e.g.,Try(parseExtractionResult, input)).Test Results
Made with Cursor