Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/rank-eval-tests' in…
Browse files Browse the repository at this point in the history
…to rank-eval-tests
  • Loading branch information
Tokesh committed Dec 3, 2024
2 parents 68e42fa + 33c35c0 commit 4f8825b
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 21 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/test-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,22 @@ jobs:
with:
path: coverage

- name: Display Missing Test Paths
- name: Collect Test File Names
run: |
find tests/. -name "*.yaml" | xargs realpath | jq -Rn '{ files: [inputs | "\(.)"] }' > test-files.json
- name: Display Unused Test Files
run: |
jq -r -sc '
(map(.stories) | add | unique) as $stories |
(map(.files) | add | unique) as $all |
$all-$stories |
.[]
' $(find ./ -name "test-spec-coverage-*.json") test-files.json > ./coverage/files.txt
cat ./coverage/files.txt | sed -e 's/^/::error::/'
test ! -s ./coverage/files.txt || { echo "::error::Unused test files detected."; exit 1; }
- name: Collect and Display Missing Test Paths
run: |
jq -r -sc '
(map(.operations) | add | unique) as $all |
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added `s` to `/_ingest/processor/grok` ([#689](https://github.com/opensearch-project/opensearch-api-specification/pull/689))
- Added schema for security API error responses ([#646](https://github.com/opensearch-project/opensearch-api-specification/pull/646))
- Added `aggregations` to `/nodes/_usage/{metric}` requests and responses ([#615](https://github.com/opensearch-project/opensearch-api-specification/pull/615))
- Added missing `status` to `/_search/template` response ([#702](https://github.com/opensearch-project/opensearch-api-specification/pull/702))
- Added `_type` to `rank_eval` API specs ([#704](https://github.com/opensearch-project/opensearch-api-specification/pull/704))

### Removed
Expand Down Expand Up @@ -48,7 +49,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fixed response schema for `/_nodes/reload_secure_settings` and `/_nodes/{node_id}/reload_secure_settings` ([#694](https://github.com/opensearch-project/opensearch-api-specification/pull/694))
- Fixed `/_ingest/pipeline/{id}/_simulate` response `docs/_source` field schema ([#689](https://github.com/opensearch-project/opensearch-api-specification/pull/689))
- Fixed `/_scripts/painless/_execute` request and response schema ([#699](https://github.com/opensearch-project/opensearch-api-specification/pull/699))
- Fixed `fields` in `Hit` allowing primitive arrays ([#699](https://github.com/opensearch-project/opensearch-api-specification/pull/699))
- Fixed `fields` in `Hit` allowing primitive arrays ([#699](https://github.com/opensearch-project/opensearch-api-specification/pull/
- Added missing `repository` query parameter to `/_cat/snapshots` ([#700](https://github.com/opensearch-project/opensearch-api-specification/pull/700))
- Fixed `hits` in `rank_eval` allowing numbers ([#704](https://github.com/opensearch-project/opensearch-api-specification/pull/704))

### Changed
Expand Down
2 changes: 2 additions & 0 deletions spec/namespaces/_core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3266,6 +3266,8 @@ components:
$ref: '../schemas/_core.search.yaml#/components/schemas/Suggest'
terminated_early:
type: boolean
status:
type: number
required:
- _shards
- hits
Expand Down
13 changes: 13 additions & 0 deletions spec/namespaces/cat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ paths:
- $ref: '#/components/parameters/cat.snapshots::query.help'
- $ref: '#/components/parameters/cat.snapshots::query.ignore_unavailable'
- $ref: '#/components/parameters/cat.snapshots::query.master_timeout'
- $ref: '#/components/parameters/cat.snapshots::query.repository'
- $ref: '#/components/parameters/cat.snapshots::query.s'
- $ref: '#/components/parameters/cat.snapshots::query.time'
- $ref: '#/components/parameters/cat.snapshots::query.v'
Expand All @@ -658,6 +659,7 @@ paths:
- $ref: '#/components/parameters/cat.snapshots::query.help'
- $ref: '#/components/parameters/cat.snapshots::query.ignore_unavailable'
- $ref: '#/components/parameters/cat.snapshots::query.master_timeout'
- $ref: '#/components/parameters/cat.snapshots::query.repository'
- $ref: '#/components/parameters/cat.snapshots::query.s'
- $ref: '#/components/parameters/cat.snapshots::query.time'
- $ref: '#/components/parameters/cat.snapshots::query.v'
Expand Down Expand Up @@ -2544,6 +2546,17 @@ components:
type: boolean
default: false
description: Verbose mode. Display column headers.
cat.snapshots::query.repository:
in: query
name: repository
description: |-
A comma-separated list of snapshot repositories used to limit the request.
Accepts wildcard expressions.
`_all` returns all repositories.
If any repository fails during the request, OpenSearch returns an error.
required: true
schema:
$ref: '../schemas/_common.yaml#/components/schemas/Names'
cat.snapshots::path.repository:
in: path
name: repository
Expand Down
20 changes: 20 additions & 0 deletions tests/default/_core/upgrade.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$schema: ../../../json_schemas/test_story.schema.yaml

description: Test upgrading indices using both GET and POST methods.
chapters:
- synopsis: Trigger upgrade (POST).
path: /_upgrade
method: POST
request:
payload:
allow_no_indices: false
expand_wildcards: closed
ignore_unavailable: false
response:
status: 200

- synopsis: Check upgrade status (GET).
path: /_upgrade
method: GET
response:
status: 200
67 changes: 67 additions & 0 deletions tests/default/indices/search/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
$schema: ../../../../json_schemas/test_story.schema.yaml

description: Test search with templates using both index-specific and global endpoints via GET and POST methods.
epilogues:
- path: /movies
method: DELETE
status: [200, 404]
prologues:
- path: /_bulk
method: POST
parameters:
refresh: true
request:
content_type: application/x-ndjson
payload:
- {create: {_index: movies, _id: movie1}}
- {director: Quentin Tarantino, title: Pulp Fiction, year: 1994}
- {create: {_index: movies, _id: movie2}}
- {director: Christopher Nolan, title: Inception, year: 2010}
- path: /_scripts/movie_template
method: POST
request:
content_type: application/json
payload:
script:
lang: mustache
source: >
{
"query": {
"match": {
"{{field}}": "{{value}}"
}
}
}
chapters:
- synopsis: Perform a search using a template with GET (index-specific).
path: /{index}/_search/template
method: GET
parameters:
index: [movies]
request:
payload:
id: movie_template
params:
field:
value: director
value:
value: Quentin Tarantino
response:
status: 200

- synopsis: Perform a search using a template with POST (index-specific).
path: /{index}/_search/template
method: POST
parameters:
index: [movies]
request:
payload:
id: movie_template
params:
field:
value: title
value:
value: Inception
response:
status: 200
17 changes: 0 additions & 17 deletions tests/default/indices/upgrade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,5 @@ chapters:
method: GET
parameters:
index: [movies]
response:
status: 200

- synopsis: Trigger upgrade (POST).
path: /_upgrade
method: POST
request:
payload:
allow_no_indices: false
expand_wildcards: closed
ignore_unavailable: false
response:
status: 200

- synopsis: Check upgrade status (GET).
path: /_upgrade
method: GET
response:
status: 200
63 changes: 63 additions & 0 deletions tests/default/search/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
$schema: ../../../json_schemas/test_story.schema.yaml

description: Test search with templates using both index-specific and global endpoints via GET and POST methods.
epilogues:
- path: /movies
method: DELETE
status: [200, 404]
prologues:
- path: /_bulk
method: POST
parameters:
refresh: true
request:
content_type: application/x-ndjson
payload:
- {create: {_index: movies, _id: movie1}}
- {director: Quentin Tarantino, title: Pulp Fiction, year: 1994}
- {create: {_index: movies, _id: movie2}}
- {director: Christopher Nolan, title: Inception, year: 2010}
- path: /_scripts/movie_template
method: POST
request:
content_type: application/json
payload:
script:
lang: mustache
source: >
{
"query": {
"match": {
"{{field}}": "{{value}}"
}
}
}
chapters:
- synopsis: Perform a global search using a template with GET.
path: /_search/template
method: GET
request:
payload:
id: movie_template
params:
field:
value: year
value:
value: 1994
response:
status: 200

- synopsis: Perform a global search using a template with POST.
path: /_search/template
method: POST
request:
payload:
id: movie_template
params:
field:
value: year
value:
value: 2010
response:
status: 200
29 changes: 28 additions & 1 deletion tests/snapshot/cat/snapshots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ $schema: ../../../json_schemas/test_story.schema.yaml

description: Test cat/snapshots endpoints.
epilogues:
- path: /_snapshot/my-fs-repository/my-test-snapshot
method: DELETE
status: [200, 404]
- path: /_snapshot/my-fs-repository
method: DELETE
status: [200, 404]
Expand All @@ -13,12 +16,36 @@ prologues:
type: fs
settings:
location: /tmp/opensearch/repo
- path: /_snapshot/my-fs-repository/my-test-snapshot
method: PUT
parameters:
wait_for_completion: true
request:
payload:
indices: '*'
ignore_unavailable: true
include_global_state: false
partial: true
chapters:
- synopsis: List all snapshots for a repository.
- synopsis: List all snapshots for a repository (query).
path: /_cat/snapshots
method: GET
parameters:
format: json
repository: my-fs-repository
response:
status: 200
payload:
- id: my-test-snapshot
status: SUCCESS
- synopsis: List all snapshots for a repository (path).
path: /_cat/snapshots/{repository}
method: GET
parameters:
format: json
repository: my-fs-repository
response:
status: 200
payload:
- id: my-test-snapshot
status: SUCCESS
12 changes: 11 additions & 1 deletion tools/src/tester/TestResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class TestResults {
protected _evaluated_operations?: Operation[]
protected _unevaluated_operations?: Operation[]
protected _operations?: Operation[]
protected _stories?: string[]

constructor(spec: MergedOpenApiSpec, evaluations: StoryEvaluations) {
this._spec = spec
Expand Down Expand Up @@ -59,6 +60,14 @@ export default class TestResults {
return this._operations
}

stories(): string[] {
if (this._stories !== undefined) return this._stories
this._stories = _.uniqWith(_.compact(_.flatMap(this._evaluations.evaluations, (evaluation) =>
evaluation.full_path
)), isEqual)
return this._stories
}

test_coverage(): SpecTestCoverage {
return {
summary: {
Expand All @@ -69,7 +78,8 @@ export default class TestResults {
) / 100 : 0
},
operations: this.operations(),
evaluated_operations: this.evaluated_operations()
evaluated_operations: this.evaluated_operations(),
stories: this.stories()
}
}

Expand Down
1 change: 1 addition & 0 deletions tools/src/tester/types/test.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export interface SpecTestCoverage {
},
operations: Operation[]
evaluated_operations: Operation[]
stories: string[]
}
3 changes: 3 additions & 0 deletions tools/tests/tester/TestResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ describe('TestResults', () => {
{ method: 'POST', path: '/cluster_manager' },
{ method: 'GET', path: '/index' },
{ method: 'GET', path: '/nodes' }
],
stories: [
'full_path'
]
})
fs.unlinkSync(filename)
Expand Down

0 comments on commit 4f8825b

Please sign in to comment.