Skip to content

Add a regression test for Query Tool autocomplete reuse when there is text after the cursor. #10819 - #10881

Merged
dpage merged 1 commit into
pgadmin-org:masterfrom
shuseng8:issue-10819-autocomplete-validfor
Nov 27, 2026
Merged

dpage merged 1 commit into
pgadmin-org:masterfrom
shuseng8:issue-10819-autocomplete-validfor

Conversation

@shuseng8

@shuseng8 shuseng8 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #10819

This is a test-only PR. After #10787 landed, I re-ran the validFor Jest cases from the earlier patch against current master. They all pass: validFor now compares against the completed word (word.text) rather than fullSql.slice(from), so a result is reused when there is text after the cursor, as Dave suggested in #10819 (comment).

The earlier production change (fullSql.slice(from, head)) is not included, to avoid conflicting with the #10787 rewrite.

This PR adds a direct validFor regression test for that case, including the issue's SELECT dem FROM demo_table; reproduction, plus the end-of-document and "typed text no longer extends the original word" checks. #10787 already has an editor-level test that reuses the response when text follows the cursor.

Testing

From web/:

  • yarn run eslint -c .eslintrc.js on QueryAutocomplete.spec.js: clean
  • yarn run jest regression/javascript/sqleditor/QueryAutocomplete.spec.js regression/javascript/sqleditor/QueryInsertSQLAtCursor.spec.js regression/javascript/components/CodeMirror: 4 suites, 102 tests passed
  • yarn run jest: 200 suites, 1388 tests passed

Not run: the Python tests or a manual check against a live server.

Summary by CodeRabbit

  • Tests
    • Expanded autocomplete regression coverage for cursor positions at the end of a document and before trailing text.
    • Added checks that autocomplete results are reused only when the typed text continues the original word.

… text after the cursor. pgadmin-org#10819

pgadmin-org#10787 now compares validFor against the completed word, which already
fixes the reuse failure when trailing SQL follows the cursor. Keep a
direct validFor regression test for that case, including the issue's
SELECT ... FROM demo_table reproduction.

Signed-off-by: Shubham <87247136+shuseng8@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change extends the autocomplete test helper with configurable document and cursor positions. New tests cover result reuse when typed text extends the matched word and invalidation when it does not.

Changes

Autocomplete reuse regression coverage

Layer / File(s) Summary
Test context and reuse coverage
web/regression/javascript/sqleditor/QueryAutocomplete.spec.js
The test helper accepts optional document and cursor values. New tests check reuse at the document end and before trailing text, and invalidation when typed text does not extend the matched word.

Estimated code review effort: 2 (Simple) | ~7 minutes

Change: Other

Possibly related PRs

  • pgadmin-org/pgadmin4#10787: This PR tests autocomplete result reuse behavior that #10787 changes in the production completion source.

Suggested reviewers: deba2k5, dpage

Merge Risk: Minimal · up to 54e0e

This change only adds regression tests for autocomplete reuse and does not alter production behavior. It carries no actionable merge risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change accurately: it adds a regression test for Query Tool autocomplete reuse when text follows the cursor. The raw summary and objectives confirm the PR is test-only, covering en…
Linked Issues check Passed [#10819] The requirement is that a running autocomplete result is reused while typed text still extends the original word, even when text follows the cursor. At the reviewed head, Query.jsx validFor i…
Out of Scope Changes check Passed The change summary reports edits only to web/regression/javascript/sqleditor/QueryAutocomplete.spec.js (+42/-3). The summary describes new validFor tests for reuse at document end, reuse with trailing…
Full details: Title check

Explanation

The title names the change accurately: it adds a regression test for Query Tool autocomplete reuse when text follows the cursor. The raw summary and objectives confirm the PR is test-only, covering end-of-document behavior and the case where typed text no longer extends the original word. The title is concise, specific, and references issue #10819, so a teammate scanning history can identify the primary change.

Full details: Linked Issues check

Explanation

[#10819] The requirement is that a running autocomplete result is reused while typed text still extends the original word, even when text follows the cursor. At the reviewed head, Query.jsx validFor is /^[\w$]*$/.test(text) &amp;&amp; text.startsWith(word.text). It no longer compares against fullSql.slice(from). The word.text value comes from context.matchBefore(/[\w$]*/), which ends at the cursor. Trailing document text therefore no longer blocks reuse, and the reuse condition matches the issue's expected behavior. This implementation already exists at head, so this PR does not need to add production code for it. The PR diff could not be read (changed blobs unavailable), so the added regression tests in QueryAutocomplete.spec.js were not inspected directly. The issue does not require tests as a separate coding deliverable, so this does not affect the verdict. The PR does not implement the issue's suggested fullSql.slice(from, head) change. The issue's requirement is met by the head behavior instead.

Full details: Out of Scope Changes check

Explanation

The change summary reports edits only to web/regression/javascript/sqleditor/QueryAutocomplete.spec.js (+42/-3). The summary describes new validFor tests for reuse at document end, reuse with trailing text, and non-reuse when typed text no longer extends the word. These tests cover the linked issue #10819 behavior. The PR states it contains no production change. The actual diff could not be read, so the exact test contents are based on the summary. Based on that evidence, no unrelated change is demonstrated.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 235eeb6 and 54e0e0b.

Files selected for processing: 1

  • web/regression/javascript/sqleditor/QueryAutocomplete.spec.js

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@dpage dpage left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, Shubham. It's a test-only change that pins down the #10819 behaviour now that #10787 has landed, and I'm happy with it.

I checked that the new tests actually guard the fix rather than only the fake context. With validFor switched back to comparing against fullSql.slice(word.from), the old behaviour, two of the new cases fail; with the current code all 18 tests in QueryAutocomplete.spec.js pass, and eslint is clean on the file.

Making matchBefore() in fakeContext return text is a welcome side effect too. Before this, word.text was undefined in these unit tests, so validFor was never really exercised at this level.

No changes needed.

  • Correctness
  • Security
  • Error handling
  • Tests
  • Documentation (not needed for a test-only change)

@dpage
dpage merged commit f540e4a into pgadmin-org:master Nov 27, 2026
21 of 22 checks passed
@shuseng8

Copy link
Copy Markdown
Contributor Author

Thanks dpage 🚀

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query Tool autocomplete never reuses a result when there is text after the cursor

2 participants