Skip to content

Commit

Permalink
Merge branch 'master' into CDX-1595
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprudhomme authored Oct 11, 2024
2 parents c46c05f + 497ede3 commit db287b1
Show file tree
Hide file tree
Showing 36 changed files with 343 additions and 124 deletions.
5 changes: 4 additions & 1 deletion .github/actions/playwright-atomic/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
shardTotal:
description: 'The total number of shards'
required: true
testsToRun:
description: 'The tests to run'
required: true
uploadArtifacts:
description: 'Whether to upload artifacts'
required: false
Expand All @@ -19,7 +22,7 @@ runs:
working-directory: packages/atomic
shell: bash
- name: Run Playwright tests
run: npx playwright test --shard=${{ inputs.shardIndex }}/${{ inputs.shardTotal }}
run: npx playwright test ${{ inputs.testsToRun }} --shard=${{ inputs.shardIndex }}/${{ inputs.shardTotal }}
working-directory: packages/atomic
shell: bash
- uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4
Expand Down
63 changes: 34 additions & 29 deletions .github/workflows/prbot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,41 +78,45 @@ jobs:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: ./.github/actions/setup
- uses: ./.github/actions/e2e-atomic-csp
prepare-playwright-atomic:
name: 'Determine Playwright E2E tests to run'
if: ${{ always() && github.event_name == 'pull_request'}}
runs-on: ubuntu-latest
env:
maximumShards: 24
outputs:
testsToRun: ${{ steps.determine-tests.outputs.testsToRun }}
shardIndex: ${{ steps.set-matrix.outputs.shardIndex }}
shardTotal: ${{ steps.set-matrix.outputs.shardTotal }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
fetch-depth: 0
- uses: ./.github/actions/setup
- run: npm run build
- name: Identify E2E Test Files to run
id: determine-tests
run: node ./scripts/ci/find-tests.mjs testsToRun
env:
projectRoot: ${{ github.workspace }}
shell: bash
- name: Determine Shard Values
id: set-matrix
run: node ./scripts/ci/determine-shard.mjs shardIndex shardTotal
env:
testsToRun: ${{ steps.determine-tests.outputs.testsToRun }}
maximumShards: ${{ env.maximumShards }}
shell: bash
playwright-atomic:
name: 'Run Playwright tests for Atomic'
needs: build
needs: prepare-playwright-atomic
if: ${{ always() }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shardIndex:
[
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
]
shardTotal: [24]
shardIndex: ${{fromJson(needs.prepare-playwright-atomic.outputs.shardIndex || '[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]')}}
shardTotal: ${{fromJson(needs.prepare-playwright-atomic.outputs.shardTotal || '[24]')}}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: ./.github/actions/setup
Expand All @@ -121,6 +125,7 @@ jobs:
with:
shardIndex: ${{ matrix.shardIndex }}
shardTotal: ${{ matrix.shardTotal }}
testsToRun: ${{ needs.prepare-playwright-atomic.outputs.testsToRun }}
merge-playwright-reports:
name: 'Merge Playwright reports'
environment: PR Artifacts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export class AtomicRecsList implements InitializableComponent<RecsBindings> {
}

private get recommendationListStateWithAugment() {
// TODO: some changes
return {
...this.recommendationListState,
firstRequestExecuted:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
buildQueryTrigger,
QueryTriggerState,
} from '@coveo/headless';
import {Component, h, Prop, State} from '@stencil/core';
import {Component, h, Prop, State, Watch} from '@stencil/core';
import {
BindStateToController,
InitializableComponent,
Expand Down Expand Up @@ -68,6 +68,11 @@ export class AtomicDidYouMean implements InitializableComponent {
@Prop({reflect: true})
public queryCorrectionMode: 'legacy' | 'next' = 'next';

@Watch('queryCorrectionMode')
public updateQueryCorrectionMode() {
this.didYouMean.updateQueryCorrectionMode(this.queryCorrectionMode);
}

public initialize() {
this.didYouMean = buildDidYouMean(this.bindings.engine, {
options: {
Expand Down
4 changes: 0 additions & 4 deletions packages/headless/src/api/platform-service-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ export interface ClientIDParam {
clientId?: string;
}

export interface VisitorIDParam {
visitorId?: string;
}

export interface FoldingParam {
filterField?: string;
parentField?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {BaseParam, VisitorIDParam} from '../../../platform-service-params.js';
import {BaseParam} from '../../../platform-service-params.js';
import {AuthenticationParam} from '../../search-api-params.js';
import {SearchRequest} from '../../search/search-request.js';

Expand All @@ -16,7 +16,6 @@ export interface FacetSearchRequestOptions {
export interface BaseFacetSearchRequest
extends FacetSearchRequestOptions,
BaseParam,
VisitorIDParam,
AuthenticationParam {
field: string;
searchContext?: SearchRequest;
Expand Down
3 changes: 0 additions & 3 deletions packages/headless/src/api/search/html/html-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export const buildContentURL = (req: HtmlRequest, path: string) => {
if (req.requestedOutputSize !== undefined) {
url.addParam('requestedOutputSize', `${req.requestedOutputSize}`);
}
if (req.visitorId !== undefined) {
url.addParam('visitorId', `${req.visitorId}`);
}
return url.href;
};

Expand Down
5 changes: 2 additions & 3 deletions packages/headless/src/api/search/html/html-request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {BaseParam, VisitorIDParam} from '../../platform-service-params.js';
import {BaseParam} from '../../platform-service-params.js';
import {AuthenticationParam} from '../search-api-params.js';

export interface HtmlRequestOptions {
Expand All @@ -8,8 +8,7 @@ export interface HtmlRequestOptions {

export type HtmlRequest = BaseParam &
HtmlRequestOptions &
AuthenticationParam &
VisitorIDParam & {
AuthenticationParam & {
enableNavigation: boolean;
requestedOutputSize: number;
q: string;
Expand Down
2 changes: 0 additions & 2 deletions packages/headless/src/api/search/plan/plan-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
BaseParam,
ContextParam,
LocaleParam,
VisitorIDParam,
} from '../../platform-service-params.js';
import {
AnalyticsParam,
Expand All @@ -20,6 +19,5 @@ export type PlanRequest = BaseParam &
PipelineParam &
LocaleParam &
TimezoneParam &
VisitorIDParam &
AnalyticsParam &
AuthenticationParam;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
BaseParam,
ContextParam,
LocaleParam,
VisitorIDParam,
} from '../../platform-service-params.js';
import {
ActionsHistoryParam,
Expand All @@ -24,7 +23,6 @@ export type QuerySuggestRequest = BaseParam &
LocaleParam &
TimezoneParam &
ActionsHistoryParam &
VisitorIDParam &
AuthenticationParam &
AnalyticsParam & {
count: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
DictionaryFieldContextParam,
LocaleParam,
NumberOfResultsParam,
VisitorIDParam,
} from '../../platform-service-params.js';
import {
ActionsHistoryParam,
Expand Down Expand Up @@ -35,7 +34,6 @@ export type RecommendationRequest = BaseParam &
ReferrerParam &
LocaleParam &
TimezoneParam &
VisitorIDParam &
AnalyticsParam &
AuthenticationParam &
NumberOfResultsParam;
6 changes: 0 additions & 6 deletions packages/headless/src/api/search/search-api-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ describe('search api client', () => {
fieldsToInclude: state.fields.fieldsToInclude,
pipeline: state.pipeline,
searchHub: state.searchHub,
visitorId: expect.any(String),
},
preprocessRequest: NoopPreprocessRequest,
requestMetadata: {method: 'search'},
Expand Down Expand Up @@ -346,7 +345,6 @@ describe('search api client', () => {
searchHub: state.searchHub,
timezone: state.configuration.search.timezone,
locale: state.configuration.search.locale,
visitorId: expect.any(String),
},
preprocessRequest: NoopPreprocessRequest,
requestMetadata: {method: 'plan'},
Expand Down Expand Up @@ -416,7 +414,6 @@ describe('search api client', () => {
timezone: state.configuration.search.timezone,
locale: state.configuration.search.locale,
actionsHistory: expect.any(Array),
visitorId: expect.any(String),
},
preprocessRequest: NoopPreprocessRequest,
requestMetadata: {method: 'querySuggest'},
Expand Down Expand Up @@ -570,7 +567,6 @@ describe('search api client', () => {
ignoreValues: [],
searchContext: {
...searchRequest,
visitorId: expect.any(String),
analytics: {
...searchRequest.analytics,
clientId: expect.any(String),
Expand Down Expand Up @@ -622,7 +618,6 @@ it calls PlatformClient.call with the category facet search params`, async () =>
ignorePaths: [],
searchContext: {
...searchRequest,
visitorId: expect.any(String),
analytics: {
...searchRequest.analytics,
clientId: expect.any(String),
Expand Down Expand Up @@ -685,7 +680,6 @@ it calls PlatformClient.call with the category facet search params`, async () =>
actionsHistory: expect.any(Array),
tab: originLevel2,
referrer: originLevel3,
visitorId: expect.any(String),
numberOfResults: recommendationState.pagination.numberOfResults,
},
preprocessRequest: NoopPreprocessRequest,
Expand Down
2 changes: 0 additions & 2 deletions packages/headless/src/api/search/search/search-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
FoldingParam,
LocaleParam,
NumberOfResultsParam,
VisitorIDParam,
} from '../../platform-service-params.js';
import {
ActionsHistoryParam,
Expand Down Expand Up @@ -54,7 +53,6 @@ export type SearchRequest = BaseParam &
PipelineParam &
SearchHubParam &
FacetOptionsParam &
VisitorIDParam &
DebugParam &
LocaleParam &
FoldingParam &
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
ContextParam,
LocaleParam,
VisitorIDParam,
} from '../../../platform-service-params.js';
import {ContextParam, LocaleParam} from '../../../platform-service-params.js';
import {
ActionsHistoryParam,
AnalyticsParam,
Expand All @@ -18,7 +14,6 @@ export type InsightQuerySuggestRequest = InsightParam &
LocaleParam &
TimezoneParam &
ActionsHistoryParam &
VisitorIDParam &
AuthenticationParam &
AnalyticsParam & {
count: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ describe('did you mean', () => {
expect(applyDidYouMeanCorrection).toHaveBeenCalledWith('bar');
});

it('should allow to update the query correction mode', () => {
const initialState = createMockState();
initialState.didYouMean.queryCorrectionMode = 'legacy';
initDidYouMean({}, initialState);
dym.updateQueryCorrectionMode('next');

expect(engine.dispatch).toHaveBeenCalledWith(setCorrectionMode('next'));
});

it('should dispatch disableAutomaticQueryCorrection at initialization when specified', () => {
initDidYouMean({options: {automaticallyCorrectQuery: false}});
expect(disableAutomaticQueryCorrection).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export interface DidYouMeanProps {
options?: DidYouMeanOptions;
}

type QueryCorrectionMode = 'legacy' | 'next';

export interface DidYouMeanOptions {
/**
* Whether to automatically apply corrections for queries that would otherwise return no results.
Expand All @@ -46,14 +48,25 @@ export interface DidYouMeanOptions {
*
* Default value is `next`.
*/
queryCorrectionMode?: 'legacy' | 'next';
queryCorrectionMode?: QueryCorrectionMode;
}
export interface DidYouMean extends Controller {
/**
* Apply query correction using the query correction, if any, currently present in the state.
*/
applyCorrection(): void;

/**
* Update which query correction system to use
*
* `legacy`: Query correction is powered by the legacy index system. This system relies on an algorithm using solely the index content to compute the suggested terms.
* `next`: Query correction is powered by a machine learning system, requiring a valid query suggestion model configured in your Coveo environment to function properly. This system relies on machine learning algorithms to compute the suggested terms.
*
* @param queryCorrectionMode - the query correction mode to use
*
*/
updateQueryCorrectionMode(queryCorrectionMode: QueryCorrectionMode): void;

/**
* The state of the `DidYouMean` controller.
*/
Expand Down Expand Up @@ -138,6 +151,9 @@ export function buildCoreDidYouMean(
applyDidYouMeanCorrection(this.state.queryCorrection.correctedQuery)
);
},
updateQueryCorrectionMode(queryCorrectionMode: QueryCorrectionMode) {
dispatch(setCorrectionMode(queryCorrectionMode));
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ describe('#buildCategoryFacetSearchRequest', () => {

expect((await buildParams()).searchContext).toEqual({
...request,
visitorId: expect.any(String),
analytics: {
...request.analytics,
clientId: expect.any(String),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ describe('#buildSpecificFacetSearchRequest', () => {

expect((await buildParams()).searchContext).toEqual({
...request,
visitorId: expect.any(String),
analytics: {
...request.analytics,
clientId: expect.any(String),
Expand Down
Loading

0 comments on commit db287b1

Please sign in to comment.