-
[OPIK-4938] [BE] Extract project-scoped nested tests to top-level files with shared TestContainersSetup (#5806)
发布于
2026-03-24 17:18:33 +00:00 - [OPIK-4938] [BE] Add project_name support to dataset, experiment and optimization endpoints
- Add project_name field to DatasetItemBatch and propagate it through DatasetItemService to scope dataset items to a project
- Resolve project_name to project_id in DatasetService and ExperimentService when creating datasets/experiments
- Add project_id column to optimizations table via Liquibase migration (000073)
- Expose project_id (read-only) and project_name (write-only) on Optimization model
- Fix NullPointerException in OptimizationService when project_name is null by using AbstractMap.SimpleEntry instead of Map.entry
- Add integration tests for project-scoped dataset creation in DatasetsResourceTest, ExperimentsResourceTest, and OptimizationsResourceTest
-
Revision 2: Add ProjectOptimizationsResource for project-scoped optimization listing
-
Revision 3: Add project_id filter to OptimizationsResource and integration tests for ProjectOptimizationsResource
-
[OPIK-4938] [BE] Fix DatasetItemBatch project resolution and centralize test factory calls
Fix Reactor empty Mono bug in DatasetItemService.getDatasetId() where batches
without projectId/projectName caused the flatMap to never execute (data loss).
Added switchIfEmpty to handle the null-project case properly.Centralize factory.manufacturePojo(DatasetItemBatch.class) and
factory.manufacturePojo(DatasetItem.class) calls in DatasetResourceClient
to null out server-assigned fields (projectId, projectName, datasetId, etc.),
preventing PODAM-generated random UUIDs from causing 404 errors in tests.- Revision 2: Address PR review comments
- Rename migration 000073 → 000074 to avoid prefix conflict with main
- Add trailing blank line to migration file per guidelines
- Remove @RequiredPermissions(EXPERIMENT_VIEW) from ProjectOptimizationsResource.find()
to match unrestricted access pattern of the global endpoint - Add dataset_name query param to ProjectOptimizationsResource.find()
for parity with global /v1/private/optimizations endpoint - Fix @Schema description on DatasetItemBatch.projectId (was "dataset_name must be
provided", now "project_name must be provided") - Use DatasetItemBatch builder instead of positional constructor in
DatasetExportJobSubscriberResourceTest
- Revision 3: Fix insertInvalidDatasetItemWorkspace test failure
Use DatasetResourceClient helpers and null out datasetId to avoid PODAM
generating random UUIDs that cause 404s in DatasetItemService resolution.- Revision 4: Simplify resolveProjectId in OptimizationService
Inline context accesses inside fromCallable lambda, consistent with
DatasetItemService.resolveProjectId pattern.- Revision 5: Support projectId on Optimization write + validate on upsert
Remove READ_ONLY from Optimization.projectId so callers can pass it
directly. Add a resolveProjectId branch that validates the provided
projectId exists in the workspace before using it, mirroring the
DatasetItemBatch projectId/projectName duality.- Revision 6: Clarify projectName/projectId as optional in DatasetItemBatch schema
Both fields are optional (both null = no project scoping). Update @Schema
descriptions to remove misleading "must be provided" language and describe
precedence rules instead.- Revision 7: Extract resolveProjectIdOrCreate into ProjectService
Both OptimizationService and ExperimentService had identical inline logic
for resolving a project from (projectId, projectName): validate the id if
provided, getOrCreate from the name otherwise, return empty if neither.The shared helper lives in ProjectService.resolveProjectIdOrCreate and uses
deferContextual so callers no longer need to extract workspaceId/userName
themselves. ExperimentService's logic is also aligned to projectId-first
priority, consistent with OptimizationService and DatasetItemService.- Revision 8: Add OpenAPI schema descriptions for Optimization project_id/project_name
Matches the existing descriptions on Experiment, making the auto-create
and precedence semantics visible in the generated API docs.-
[OPIK-4938] [BE] Fix trailing blank line in migration 000074
-
[OPIK-4938] [BE] Minor test and code cleanup from PR review feedback
- Merge duplicate test pairs in DatasetsResourceTest: tests that checked
deprecated behavior and response headers now combined into single tests - Add callRetrievePromptVersion helper to PromptResourceClient and use it
in PromptResourceTest instead of raw HTTP calls - Fix StringUtils.isNotEmpty → isNotBlank in OptimizationDAO ClickHouse
row mapper for proper null/whitespace handling of project_id field
-
[OPIK-4938] [BE] Remove unused import and use factory directly in DatasetsResourceTest
-
[OPIK-4938] [BE] Use DatasetResourceClient factory methods instead of direct PODAM calls
-
[OPIK-4938] [BE] Restore separate deprecation header tests in DatasetsResourceTest
-
[OPIK-4938] [BE] Fix incorrect null assertion in twoSuiteExperiments test
computeRunSummaries populates summaries for any experiment that has
assertion results, regardless of group size. passThreshold defaults to 1
when no executionPolicy is set, so single-run experiments get independent
PASSED/FAILED summaries.-
Refactor project ID string check in OptimizationDAO
-
[OPIK-4938] [BE] Restore FindProjectDatasets tests accidentally deleted in refactoring
Restores 6 integration tests for GET /v1/private/projects/{projectId}/datasets
that were accidentally deleted in a prior sed-based refactoring commit.The tests cover: basic pagination, page size limiting, default sort by created
date, sorting by all valid fields (parameterized), filtering (parameterized),
and case-insensitive name search.Also promotes getDatasets__whenFetchingAllDatasets__thenReturnDatasetsSortedByByValidFields
and getValidFilters to static in FindDatasets so they can be shared as
external @MethodSource providers.- Revision 2: Extract project-scoped nested test classes to dedicated top-level files
Extract all project-scoped nested test classes from large test files into
standalone, focused test classes — one responsibility per file.New test files created (10 total):
- DatasetsResourceProjectScopedTest (6 tests)
- DatasetsResourceFindProjectDatasetsTest (24 tests)
- ExperimentsResourceProjectScopedDatasetCreationTest (1 test)
- ExperimentsResourceFindProjectExperimentsTest (35 tests)
- OptimizationsResourceProjectScopedDatasetCreationTest (1 test)
- OptimizationsResourceFindProjectOptimizationsTest (4 tests)
- PromptResourceProjectScopedPromptsTest (5 tests)
- PromptResourceFindProjectPromptsTest (8 tests)
- DashboardsResourceProjectScopedTest (5 tests)
- DashboardsResourceFindProjectDashboardsTest (16 tests)
Each file is self-contained with its own Testcontainers setup (MySQL,
ClickHouse, Redis, WireMock), following the pattern of
DatasetsResourceCreateFromTracesTest.java. Static @MethodSource factory
methods are defined locally to avoid USER constant cross-class mismatches.Removes ~3030 lines from DatasetsResourceTest, ExperimentsResourceTest,
OptimizationsResourceTest, PromptResourceTest, and DashboardsResourceTest.- [OPIK-4938] [BE] Extract project-scoped tests to top-level files using shared TestContainersSetup
Migrates the remaining project-scoped nested test classes from their
parent resource test files into dedicated top-level test classes, and
introduces TestContainersSetup / TestContainersSetupWithMinIO helper
classes to eliminate boilerplate container startup code.Affected test files:
- DatasetsResourceProjectScopedTest / DatasetsResourceFindProjectDatasetsTest
- ExperimentsResourceProjectScopedDatasetCreationTest / ExperimentsResourceFindProjectExperimentsTest
- OptimizationsResourceProjectScopedDatasetCreationTest / OptimizationsResourceFindProjectOptimizationsTest
- PromptResourceProjectScopedPromptsTest / PromptResourceFindProjectPromptsTest
- DashboardsResourceProjectScopedTest / DashboardsResourceFindProjectDashboardsTest
Co-authored-by: Andres Cruz andresc@comet.com
下载附件