diff --git a/.github/workflows/test-spec.yml b/.github/workflows/test-spec.yml index afa2de821..1e6490c4c 100644 --- a/.github/workflows/test-spec.yml +++ b/.github/workflows/test-spec.yml @@ -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 | diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ae3f40a2..b0118c095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/spec/namespaces/_core.yaml b/spec/namespaces/_core.yaml index 8149f7cf4..6b032fc2f 100644 --- a/spec/namespaces/_core.yaml +++ b/spec/namespaces/_core.yaml @@ -3266,6 +3266,8 @@ components: $ref: '../schemas/_core.search.yaml#/components/schemas/Suggest' terminated_early: type: boolean + status: + type: number required: - _shards - hits diff --git a/spec/namespaces/cat.yaml b/spec/namespaces/cat.yaml index e9981e972..68fff5182 100644 --- a/spec/namespaces/cat.yaml +++ b/spec/namespaces/cat.yaml @@ -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' @@ -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' @@ -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 diff --git a/tests/default/_core/upgrade.yaml b/tests/default/_core/upgrade.yaml new file mode 100644 index 000000000..9075e1a6f --- /dev/null +++ b/tests/default/_core/upgrade.yaml @@ -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 \ No newline at end of file diff --git a/tests/default/indices/search/template.yaml b/tests/default/indices/search/template.yaml new file mode 100644 index 000000000..879b73386 --- /dev/null +++ b/tests/default/indices/search/template.yaml @@ -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 \ No newline at end of file diff --git a/tests/default/indices/upgrade.yaml b/tests/default/indices/upgrade.yaml index 281f94029..46d81bb06 100644 --- a/tests/default/indices/upgrade.yaml +++ b/tests/default/indices/upgrade.yaml @@ -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 \ No newline at end of file diff --git a/tests/default/search/template.yaml b/tests/default/search/template.yaml new file mode 100644 index 000000000..956f6fbd9 --- /dev/null +++ b/tests/default/search/template.yaml @@ -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 \ No newline at end of file diff --git a/tests/snapshot/cat/snapshots.yaml b/tests/snapshot/cat/snapshots.yaml index 81a51bfc2..3a0924980 100644 --- a/tests/snapshot/cat/snapshots.yaml +++ b/tests/snapshot/cat/snapshots.yaml @@ -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] @@ -13,8 +16,29 @@ 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: @@ -22,3 +46,6 @@ chapters: repository: my-fs-repository response: status: 200 + payload: + - id: my-test-snapshot + status: SUCCESS diff --git a/tools/src/tester/TestResults.ts b/tools/src/tester/TestResults.ts index 3b79d2ad2..03553941f 100644 --- a/tools/src/tester/TestResults.ts +++ b/tools/src/tester/TestResults.ts @@ -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 @@ -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: { @@ -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() } } diff --git a/tools/src/tester/types/test.types.ts b/tools/src/tester/types/test.types.ts index 15fc0cabb..45d89cb31 100644 --- a/tools/src/tester/types/test.types.ts +++ b/tools/src/tester/types/test.types.ts @@ -17,4 +17,5 @@ export interface SpecTestCoverage { }, operations: Operation[] evaluated_operations: Operation[] + stories: string[] } diff --git a/tools/tests/tester/TestResults.test.ts b/tools/tests/tester/TestResults.test.ts index 4ca6aac5d..f1c7816fe 100644 --- a/tools/tests/tester/TestResults.test.ts +++ b/tools/tests/tester/TestResults.test.ts @@ -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)