Skip to content

Don't rewrite a search prefix when attempting a suggestion #3343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,49 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Build test image
id: docker-build-test
id: docker-build-playwright
uses: docker/build-push-action@v6
with:
target: server
target: playwright
push: false
load: true
- name: Run Perl tests
- name: Start playwright server
id: start-container
run: >
docker run -d -i -p 8000:80
${{ steps.docker-build-test.outputs.imageid }}
CONTAINER_ID=$(docker run -d -i -p 8000:80
-v $(pwd):/app
${{ steps.docker-build-playwright.outputs.imageid }})
&& echo "container_id=$CONTAINER_ID" >> $GITHUB_OUTPUT
|| (echo "Failed to start container" && exit 1)
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Install Playwright Browsers
run: ./bin/install-playwright
- name: Install Codecovbash
uses: perl-actions/install-with-cpm@v1
with:
install: |
Devel::Cover
Devel::Cover::Report::Codecovbash
sudo: true
- name: Check docker status
id: playwright-tests
run: |
npx playwright test || {
echo "Playwright tests failed"
docker logs ${{ steps.start-container.outputs.container_id }}
exit 1
}
- name: Run Playwright tests
run: npx playwright test
- name: Generate Codecov report
run: cover -report codecovbash
- uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
file: ./cover_db/codecov.json
token: ${{ secrets.CODECOV_TOKEN }}
test:
runs-on: ubuntu-24.04
name: Dockerless
Expand Down
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,18 @@ CMD [ "prove", "-l", "-r", "-j", "2", "t" ]
FROM server AS production

USER metacpan

################### Playwright Server
FROM server AS playwright
USER root

RUN echo "Starting Playwright stage setup"
RUN --mount=type=cache,target=/root/.perl-cpm,sharing=private \
<<EOT
cpm install --show-build-log-on-failure Devel::Cover \
EOT

ENV HARNESS_ACTIVE=1
ENV PERL5OPT='-MDevel::Cover=+ignore,^local/|^templates/|^t/|yaml$'

USER metacpan
50 changes: 46 additions & 4 deletions e2e/home.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
import { test, expect } from '@playwright/test';
import { test, expect } from "@playwright/test";

test('home page', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveTitle(/Search the CPAN - metacpan.org/, { timeout: 10 });
test("home page", async ({ page }) => {
await page.goto("/");
await expect(page).toHaveTitle(/Search the CPAN - metacpan.org/, {
timeout: 10,
});
});

test("suggest is correct", async ({ page }) => {
await page.goto("/");
const searchInput = page.getByPlaceholder("Search the CPAN");
await expect(searchInput).toBeVisible();
searchInput.fill("HTML:Restrict");
await searchInput.press("Enter");

await expect(page.getByRole('alert')).toContainText('Did you mean: HTML::Restrict');
});

test("suggest accounts for prefix and makes suggestion", async ({ page }) => {
await page.goto("/");
const searchInput = page.getByPlaceholder("Search the CPAN");
await expect(searchInput).toBeVisible();
searchInput.fill("distribution:HTML:Restrict");
await searchInput.press("Enter");

await expect(page.getByRole('alert')).toContainText('Did you mean: distribution:HTML::Restrict');
});

test("suggest accounts for prefix but cannot make suggestion", async ({ page }) => {
await page.goto("/");
const searchInput = page.getByPlaceholder("Search the CPAN");
await expect(searchInput).toBeVisible();
searchInput.fill("distribution:HTMLRestrict");
await searchInput.press("Enter");

await expect(page.getByRole('alert')).toBeHidden();
});

test("suggest ignores misspelled prefix and makes suggestion", async ({ page }) => {
await page.goto("/");
const searchInput = page.getByPlaceholder("Search the CPAN");
await expect(searchInput).toBeVisible();
searchInput.fill("disstribution:HTML:Restrict");
await searchInput.press("Enter");

await expect(page.getByRole('alert')).toContainText('Did you mean: disstribution::HTML::Restrict');
});
8 changes: 6 additions & 2 deletions lib/MetaCPAN/Web/Controller/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@

if ( !$results->{total} && !$authors->{total} ) {
my $suggest = $query;
my $prefix = q{};
if ( $suggest =~ s{^(author|distribution|module|version):}{} ) {
$prefix = $1 . ':';

Check warning on line 89 in lib/MetaCPAN/Web/Controller/Search.pm

View check run for this annotation

Codecov / codecov/patch

lib/MetaCPAN/Web/Controller/Search.pm#L89

Added line #L89 was not covered by tests
}
$suggest =~ s/\s*:+\s*/::/g;
if ( $suggest ne $query ) {
if ( $prefix . $suggest ne $query ) {
$c->stash( {
suggest => $suggest,
suggest => $prefix . $suggest,
} );
}
$c->stash( {
Expand Down
2 changes: 1 addition & 1 deletion root/home.tx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<img src="/static/images/metacpan-logo.svg" alt="MetaCPAN" />
</div>
<h4>A search engine for <a href="https://www.cpan.org">CPAN</a></h4>
<form action="/search" class="search-form form-horizontal">
<form action="/search" class="search-form form-horizontal" role="search">
<input type="hidden" name="size" id="metacpan_search-size" value="20">
<div class="form-group">
<div class="search-group">
Expand Down
4 changes: 2 additions & 2 deletions root/no_result.tx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<div class="no-results">
<h3 class="search-results-header">No search results for [% $search_query %]</h3>
%% if $suggest {
<div class="alert alert-danger">
Did you mean :
<div class="alert alert-danger" role="alert">
Did you mean:
<a href="/search?q=[% $suggest | uri %]">[% $suggest %]</a>
</div>
%% }
Expand Down
Loading