Skip to content

Ensure every test case create and update path, including PUT and CSV - #37609

Merged
TeddyCr merged 3 commits into
open-metadata:mainfrom
TeddyCr:taskr/ensure-every-test-case-create-update-0182
Nov 16, 2026
Merged

TeddyCr merged 3 commits into
open-metadata:mainfrom
TeddyCr:taskr/ensure-every-test-case-create-update-0182

Conversation

@TeddyCr

@TeddyCr TeddyCr commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

PUT and CSV import now determine whether each test case is new or existing and pass the matching flag through preparation. CSV dry runs apply the same checks and report the same created or updated result as real imports, without creating test suites; the #35629 workaround was removed. Review the preparation and CSV import paths in TestCaseRepository first; 11 targeted integration tests pass.

Implementer's note: PUT-create and CSV import now run TestCaseRepository.prepare as creates or updates, CSV dry runs match real imports and create no suite, the #35629 workaround is removed, and the 11 targeted ITs pass (5 of them were confirmed failing on the original code).

Plan

  1. TestCaseResource.java createOrUpdate (~L951-965, createOrUpdateRequests ~L972-978): after the existing repository.setFullyQualifiedName(test), compute boolean exists = repository.findByNameOrNull(test.getFullyQualifiedName(), Include.ALL) != null once. Pass exists to the auth-request builder (change createOrUpdateRequests to take the flag so the lookup is not repeated) and call repository.prepareInternal(test, exists) instead of prepareInternal(test, true). Keep each method ≤15 lines.
  2. TestCaseRepository.java prepare (L875-914): split into Table validateForWrite(TestCase test, boolean update), which holds every check up to and including the if (!update) TestCaseDefinitionConformance.validate(...) block, and a suite step. The suite step becomes if (test.getTestSuite() == null) test.setTestSuite(getOrCreateTestSuite(test, table));, so a suite the caller already resolved (CSV row or bundle) is kept. Suite creation stays after all validation, as today.
  3. TestCaseRepository.java: add a package-private checkForImport(TestCase test, boolean isUpdate) for the CSV dry run. It runs the same checks prepareInternal runs for a test case (tags, extension, certification on create) and then validateForWrite, but never the suite step, so a dry run creates no basic suite. Verify the visibility of validateTags, validateExtension and prepareCertification in EntityRepository; widen them to package-private only if needed, and confirm prepareCertification does no writes.
  4. TestCaseRepository.java TestCaseCsv.createEntity (L2530-2665):
    a. Keep the manual FQN computation (L2600-2606). Compute boolean isUpdate = repository.findByNameOrNull(testCaseFqn, Include.ALL) != null once and reuse it in the authorizeRowForAny lambda (L2610-2614) instead of repeating the lookup.
    b. Delete the repository.getOrCreateTestSuite(testCase) branch (L2625-2629). A row with no testSuite column leaves the suite unset for prepare.
    c. Before the dry-run/real branch, run repository.checkForImport(testCase, isUpdate) in dry run and repository.prepareInternal(testCase, isUpdate) in the real run (the real run must call it before createOrUpdateForImport). Keep the id/updatedAt/updatedBy defaults (L2631-2641) but drop the stale comment that says prepare is not called.
    d. Record importedTestSuiteIds from testCase.getTestSuite() after prepare, in one place for both suite sources. Previously the ids were recorded from the getOrCreateTestSuite result, which is no longer available.
    e. Dry-run success status (L2658): isUpdate ? ENTITY_UPDATED : ENTITY_CREATED, matching the real run's CREATED→ENTITY_CREATED and OK→ENTITY_UPDATED. Today a dry run always reports ENTITY_CREATED, so the two runs disagree on updated rows.
    f. Remove the dry-run prepareInternal(testCase, true) (L2657), which is the Fixes 35274: Check test parameters against their definitions and fix open-window and boolean-set runs #35629 workaround.
  5. TestCaseRepository.java: grep for the "new-row conformance check" the card mentions. None exists

Verification

status: green (every planned check passed or was already seen green) · 4 checks: 4 passed
- [pass] mvn -B -q install -pl openmetadata-service -DskipTests -nsu
- [pass] mvn -B spotless:check -pl openmetadata-service,openmetadata-integration-tests
- [pass] mvn -B test -pl openmetadata-service -Dtest=TestCaseDefinitionConformanceTest -Dsurefire.failIfNoSpecifiedTests=false
- [pass] mvn -B verify -pl openmetadata-integration-tests -Dit.test='TestCaseResourceIT#put_create*+put_updateAfter*+csvImport_*+post_testWithUnofferedOptionValue_4xx+post_testOnUnsupportedColumnType_4xx+post_rejectedForConformance_leavesNoTestSuite' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

Review (sonnet): approve

  • [low] openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java: importedTestSuiteIds is now filled only in the real-run branch. The row-suite branch used to fill it in dry runs too, and the entry now comes after prepareInternal rather than before.
  • [low] openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java: id, updatedAt and updatedBy are now set after prepareInternal, and not at all in the dry-run path that calls checkForImport.
  • [low] openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/TestCaseResourceIT.java: csvImport_newRowMissingRequiredParameter_failsRealAndDryRun passes null as the failure reason, so any failure of that row satisfies it.

Files

...e-checked-against-their-definition-at-create.md |  17 +-
 .../openmetadata/it/tests/TestCaseResourceIT.java  | 225 +++++++++++++++++++++
 .../service/jdbi3/EntityRepository.java            |  14 +-
 .../service/jdbi3/TestCaseRepository.java          |  84 ++++----
 .../resources/dqtests/TestCaseResource.java        |  18 +-
 5 files changed, 295 insertions(+), 63 deletions(-)

Closes #35667

Opened by taskr run 0182.


Summary by Gitar

  • Entity link patch:
    • Reassigns the table's basic test suite when entityLink changes, via a shouldCompare override in TestCaseRepository
    • Switches the test-suite relationship from HAS to CONTAINS in entitySpecificUpdate
  • CSV import validation:
    • Rejects rows whose testSuite is not the target table's basic test suite, in both dry and real runs

This will update automatically on new commits.

taskr run 0182.
PUT-create and CSV import now run `TestCaseRepository.prepare` as creates or updates, CSV dry runs match real imports and create no suite, the open-metadata#35629 workaround is removed, and the 11 targeted ITs pass (5 of them were confirmed failing on the original code).
@TeddyCr
TeddyCr marked this pull request as ready for review November 11, 2026 20:28
@TeddyCr
TeddyCr requested a review from a team as a code owner November 11, 2026 20:28
@TeddyCr
TeddyCr requested review from harshach and a balanced review from Copilot November 11, 2026 20:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

taskr run 0183.
Test cases now resolve suites from `entityLink` on PATCH while CSV imports preserve their row-supplied suite.
@TeddyCr

TeddyCr commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

taskr run 0183: Test cases now resolve suites from entityLink on PATCH while CSV imports preserve their row-supplied suite.

Verification: green, mvn -q -pl openmetadata-service spotless:check pass, mvn -q -pl openmetadata-service -DskipTests install -nsu pass, mvn -pl openmetadata-service -Dtest=TestCaseRepositoryTest -Dsurefire.failIfNoSp pass, mvn -pl openmetadata-integration-tests verify -Dit.test='TestCaseResourceIT#patc pass

Review (terra): fix, 1 finding(s)

Copilot AI balanced review requested due to automatic review settings November 11, 2026 23:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 12, 2026 00:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@gitar-bot

gitar-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk 2 closed / 2 findings

Changing test-suite relationship persistence and entity-link reassignment could detach test cases from suites or leave their memberships inconsistent.

Adds PUT-create and CSV import paths that determine whether each test case is new or existing and run TestCaseRepository.prepare accordingly, with CSV dry runs matching real-run results. One open finding needs attention before merge: the CSV testSuite column is now limited to the target table's basic suite, which changes the existing import contract for logical suites and is not recorded in the linked decision record. Resolved this session: PATCH no longer resets testSuite in prepare().

✅ 2 closed
✅ Bug: prepare() no longer resets testSuite on PATCH, so stale/arbitrary suites persist

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java:875-883
prepare() used to overwrite testSuite with the linked table's basic suite every time. It now skips that step whenever testSuite is non-null. On PATCH, the entity passed to prepareInternal(updated, true) is loaded with PATCH_FIELDS, which include testSuite, so the field is always set and the guard never resolves it again. This causes two problems. First, a PATCH that moves entityLink to another table keeps the old table's basic suite, and the test case stays attached to the wrong table's suite. Second, a JSON patch that sets /testSuite to any suite now passes through, and TestUpdater.entitySpecificUpdate writes it as a relationship. Before this change prepare threw that value away. The only callers that need to keep a pre-set suite are the CSV row and the bundle path. Have them say so explicitly, for example with a flag or a separate method, and keep resolving the suite from entityLink on every other path.

Closed: Quality: CSV testSuite column now limited to table's basic suite; no record

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java:2646-2652 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java:2790-2800 📄 openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/TestCaseResourceIT.java:1390-1404 📄 docs/decisions/2026-10-12-test-cases-are-checked-against-their-definition-at-create.md:4-6
Before this PR, a CSV row's testSuite column could name any suite the caller could access, including a logical one. The importer stored that suite as the row's testSuite. The new validateRowTestSuite (TestCaseRepository.java:2790-2800) fails any row whose suite is not the basic suite of the row's own table, with the message "must be the basic test suite", in both dry runs and real runs. The csvImport_rejectsLogicalSuite and csvImport_rejectsBasicSuiteForAnotherTable tests pin this behavior. That changes the CSV import contract. Existing CSVs and clients that put a logical suite in that column will now fail, and the column becomes a consistency check, not a way to choose a suite. The rule also goes against the PR description's constraint that "A test suite already resolved by the CSV row or bundle is kept, not replaced". No record states the new rule: 2026-10-12-test-cases-are-checked-against-their-definition-at-create.md only covers definition conformance and dry-run suite creation. Record the rule, for example as a v4 revision of that ADR or a new record: "A CSV row's testSuite column, when set, must name the basic test suite of the row's target table; any other suite fails the row, and logical-suite membership comes only from the import bundle." Add the two new ITs as guards.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@TeddyCr TeddyCr changed the title Ensure every test case create and update path, including PUT and CSV i Ensure every test case create and update path, including PUT and CSV Nov 12, 2026
@TeddyCr
TeddyCr merged commit e2f39f9 into open-metadata:main Nov 16, 2026
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test case PUT-create and CSV import skip TestCaseRepository.prepare's create-time checks

3 participants