test(language/lint): add unit tests for lint-utils helpers - #86
Open
BichengWang wants to merge 2 commits into
Open
BichengWang wants to merge 2 commits into
BichengWang wants to merge 2 commits into
Conversation
|
Thanks for the contribution! Before we can merge this, we need @BichengWang to sign the Salesforce Inc. Contributor License Agreement. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds unit tests for the shared helpers in
packages/language/src/lint/lint-utils.ts:levenshtein,findSuggestion,formatSuggestionHint,lintDiagnostic,extractVariableRef,extractOutputRef, andresolveColinearAction. The file had no direct unit tests (the helpers were only exercised indirectly through the lint and dialect test suites); this adds 29.Why
These helpers sit underneath a lot of other code.
findSuggestionpicks the candidate for "Did you mean ...?" messages in the dialect parser, the typed-map parser and many lint passes, and for the LSP "Change to '...'" quick fix.lintDiagnosticbuilds the diagnostics for most lint passes inlanguage,agentscriptandagentforce.extractOutputRef,extractVariableRefandresolveColinearActionback the agentscript dialect'saction-io,action-type-checkandreasoning-actionspasses. Most of them are also exported from@agentscript/language/lint.Several edge cases were only covered indirectly, or not at all, for example:
SUGGESTION_THRESHOLDis offered, one just over it is notlintDiagnosticomitsdatawhen a caller forwards{ suggestion: undefined }(asexpression-validationdoes)How
New test file at
packages/language/src/lint/lint-utils.test.tsusing vitest, with onedescribeblock per helper. These are pure functions, so the tests call them directly instead of going throughLintEngine, likeexpression-type.test.tsdoes. Expression inputs are built fromMemberExpression/AtIdentifier, and CST metadata is attached the same wayjson-path-validation.test.tsdoes it.To check that the tests catch real regressions, I applied 32 single-line mutations to
lint-utils.tsone at a time. They included changing each edit cost, changing the threshold value or its>comparison, dropping eithertoLowerCase()call, removing the namespace checks, and always or never emittingdata/tags/cst. Every mutation fails at least one test.Test Plan
Result:
pnpm --filter @agentscript/language test(30 files, 336 tests)npx eslint --config eslint.config.js packages/language/src/lint/lint-utils.test.ts,pnpm --filter @agentscript/language typecheckandpnpm format:checkall exit 0Checklist