发布

  • [OPIK-6455] [BE] feat: add environment ownership to prompt versions (#6767)

    frostbyte_neo 发布于 2026-05-19 12:34:07 +00:00

    • Add environment to prompts

    • fix

    • fix(prompt-envs): require existing env on PATCH and address review nits

    Address PR #6767 review comments:

    • PATCH /versions/{id} now returns 404 when the environment does not exist
      in the workspace, instead of silently auto-creating (which could no-op at
      the workspace env cap and leave a version pointing at an unregistered
      env). Adds EnvironmentService.existsByName + DAO countByName.
    • getPromptById's environment query param now validates @Pattern + @Size,
      matching PromptVersionRetrieve / PromptVersion.
    • Migration 000072: add adjacent comment above CREATE UNIQUE INDEX and a
      trailing newline, per migrations.md.

    Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

    • test(prompt-envs): route new tests through PromptResourceClient

    Replace direct client.target(...) calls in the new PromptEnvironments
    nested block with PromptResourceClient helpers (matching the convention
    used elsewhere in PromptResourceTest):

    • callGetPrompt overload now accepts environment
    • callCreatePromptVersion / callGetPromptVersion / getPromptVersion
    • callSetPromptVersionEnvironment
    • callRestorePromptVersion

    Removed local getVersionById helper; postVersionRaw and
    patchVersionEnvironment now delegate to the client.

    Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

    • refactor(prompt-envs): address review nits on PATCH env endpoint
    • Rename PATCH /versions/{versionId} -> /versions/{versionId}/environments
      to scope the endpoint to environment ownership.
    • Move the mask+environment cross-field constraint to a class-level
      @AssertTrue on PromptVersion so it is enforced at request validation;
      remove the redundant service-side check on POST.
    • Drop LOWER() from EnvironmentDAO.countByName: the environments table
      uses utf8mb4 (case-insensitive default collation) and has a UNIQUE
      (workspace_id, name) index, so the LOWER() wrap was both unnecessary
      and index-defeating.
    • Extract withEnvironmentPromotionLock helper shared by
      createVersionWithEnvironment and setVersionEnvironment.
    • Update tests for the new path and the 422 status for the AssertTrue
      violation.

    Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

    • style: format PromptVersion @AssertTrue annotation
    下载附件