Skip to content

test(language/lint): add unit tests for lint-utils helpers - #86

Open
BichengWang wants to merge 2 commits into
salesforce:mainfrom
BichengWang:test-lint-utils-helpers
Open

BichengWang wants to merge 2 commits into
salesforce:mainfrom
BichengWang:test-lint-utils-helpers

Conversation

@BichengWang

@BichengWang BichengWang commented Oct 3, 2026 •

Copy link
Copy Markdown

What

Adds unit tests for the shared helpers in packages/language/src/lint/lint-utils.ts: levenshtein, findSuggestion, formatSuggestionHint, lintDiagnostic, extractVariableRef, extractOutputRef, and resolveColinearAction. 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. findSuggestion picks 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. lintDiagnostic builds the diagnostics for most lint passes in language, agentscript and agentforce. extractOutputRef, extractVariableRef and resolveColinearAction back the agentscript dialect's action-io, action-type-check and reasoning-actions passes. Most of them are also exported from @agentscript/language/lint.

Several edge cases were only covered indirectly, or not at all, for example:

  • a suggestion exactly at the 40% SUGGESTION_THRESHOLD is offered, one just over it is not
  • the distance is divided by the longer of the two names
  • matching is case-insensitive, but an exact match suggests nothing
  • lintDiagnostic omits data when a caller forwards { suggestion: undefined } (as expression-validation does)

How

New test file at packages/language/src/lint/lint-utils.test.ts using vitest, with one describe block per helper. These are pure functions, so the tests call them directly instead of going through LintEngine, like expression-type.test.ts does. Expression inputs are built from MemberExpression / AtIdentifier, and CST metadata is attached the same way json-path-validation.test.ts does it.

To check that the tests catch real regressions, I applied 32 single-line mutations to lint-utils.ts one at a time. They included changing each edit cost, changing the threshold value or its > comparison, dropping either toLowerCase() call, removing the namespace checks, and always or never emitting data / tags / cst. Every mutation fails at least one test.

Test Plan

pnpm --filter @agentscript/language test lint-utils

Result:

✓ src/lint/lint-utils.test.ts (29 tests)
Test Files  1 passed (1)
     Tests  29 passed (29)
  • Existing tests pass: pnpm --filter @agentscript/language test (30 files, 336 tests)
  • New/updated tests cover the change — N/A (this PR is the tests)
  • Linting and type checks pass: npx eslint --config eslint.config.js packages/language/src/lint/lint-utils.test.ts, pnpm --filter @agentscript/language typecheck and pnpm format:check all exit 0

Checklist

  • My code follows the project's coding style
  • I have reviewed my own diff
  • I have added/updated documentation as needed
  • This change does not introduce new warnings

@salesforce-cla

salesforce-cla Bot commented Oct 3, 2026

Copy link
Copy Markdown

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant