Repository navigation
fix: align collection name validation with zvec (allow hyphens) - #12
webdevsamran wants to merge 5 commits into
Conversation
Signed-off-by: webdevsamran <samranwebdev2000@gmail.com>
Signed-off-by: webdevsamran <samranwebdev2000@gmail.com>
a938dc8 to
9137732
Compare
feihongxu0824
left a comment
There was a problem hiding this comment.
This fixes the immediate mismatch, but it still copies Zvec's collection-name regex into Studio, which preserves the duplication that caused #9. Could we make Zvec/SDK the source of truth for engine-level name validation, pass the name through, and translate SDK validation failures into a stable Studio API error?
The remaining recent / open restrictions are caused by route layout rather than collection-domain rules: static endpoints such as /collections/recent and /collections/open share the /collections/{name} namespace. Those operations should move out of the resource-name namespace—for example, POST /collections:open and GET /workspace/recent-collections—after which _RESERVED_COLLECTION_NAMES can be removed. Existing routes can remain temporarily as deprecated aliases if compatibility is required.
| import './CreateCollectionDialog.css'; | ||
|
|
||
| const COLLECTION_NAME_RE = /^[A-Za-z][A-Za-z0-9_]{2,63}$/; | ||
| const COLLECTION_NAME_RE = /^[A-Za-z0-9_-]{3,64}$/; |
There was a problem hiding this comment.
Please avoid duplicating the engine regex in the frontend. Otherwise Studio can again block names accepted by a future Zvec version. The UI can check that the name is present and surface the normalized backend validation error; if exact client-side constraints are required, they should come from a shared or generated contract.
| await userEvent.type(screen.getByTestId('zv-create-path'), '/tmp/foo'); | ||
| await userEvent.click(screen.getByTestId('zv-create-submit')); | ||
|
|
||
| expect(screen.queryByText(/Name must match/)).not.toBeInTheDocument(); |
There was a problem hiding this comment.
This only asserts that an error is not currently visible. Please wait for and assert the POST request, including body.schema.name, so the test proves that the hyphenated name was actually accepted and submitted.
…lean frontend regex - Remove duplicated collection name regex from CreateCollectionDialog and let backend/SDK serve as single source of truth for name format validation. - Surface backend INVALID_SCHEMA/VALIDATION_ERROR directly to field error state and toast notification. - Update CreateCollectionDialog.test.tsx to assert POST schema payload with body.schema.name and verify backend error presentation. - Update CollectionSchema to enforce non-empty names and REST route path reservations while delegating format validation to Zvec SDK. Signed-off-by: Samran Asif <samranwebdev2000@gmail.com>
|
Hi @feihongxu0824 👋 Thanks for the review and architectural guidance! Addressed in commit \2407f60:
|
feihongxu0824
left a comment
There was a problem hiding this comment.
Thanks—the validation ownership changes look good. The route coupling remains because recent and open are still reserved. Please create and link a follow-up issue or PR for the route migration so this architectural part is not lost.
One compatibility detail: GET /collections/recent cannot remain as a deprecated alias while also allowing a collection named recent, because the HTTP method and path are identical. Supporting both requires either a clean route break, API versioning, or moving item access to a different namespace. A clean target would be POST /collections:open, POST /collections:import, and GET /workspace/recent-collections, after which the reserved-name guards can be removed.
| err.error.code === 'VALIDATION_ERROR' || | ||
| err.error.code === 'INVALID_SCHEMA' | ||
| ) { | ||
| setErrors((prev) => ({ |
There was a problem hiding this comment.
INVALID_SCHEMA is not necessarily a collection-name error; it is also used for unrelated failures such as a missing parent directory, invalid fields, vectors, or index configuration. Mapping every INVALID_SCHEMA / VALIDATION_ERROR to errors.name can therefore display an unrelated error under the Name field. Please keep generic schema errors at the form/toast level, and only set errors.name when the backend returns an explicit field location such as schema.name.
… field location Signed-off-by: Samran Asif <samranwebdev2000@gmail.com>
|
Thank you @feihongxu0824! I have opened follow-up issue #13 to track the route decoupling and removal of reserved collection names: #13 |
|
CI is currently failing consistently across all backend matrices on the same test: This appears to be an outdated assertion after moving engine-level collection-name validation from Pydantic to Zvec/SDK. The request now reaches the SDK and is normalized as assert resp.status_code == 400
assert resp.json()["code"] == "INVALID_SCHEMA"Frontend Node 20/22 and E2E are green; the backend failures all point to this same expectation mismatch. |
…NVALID_SCHEMA Signed-off-by: Samran Asif <samranwebdev2000@gmail.com>
|
Hi @feihongxu0824 👋 Thanks for catching that! Updated the expectation in |
Fixes #9
Aligns Studio collection name validation with the underlying zvec engine to accept hyphens and numbers at the start of names.
Changes
_COLLECTION_NAME_REinapps/backend/zvec_studio/schemas/collection.pyfrom^[A-Za-z][A-Za-z0-9_]{2,63}$to^[A-Za-z0-9_-]{3,64}$, including collection creation and snapshot import rename validation.COLLECTION_NAME_REinapps/frontend/src/pages/collections/CreateCollectionDialog.tsxto/^[A-Za-z0-9_-]{3,64}$/.en.jsonandzh.json.apps/backend/tests/unit/test_collections_schemas.pyto verify valid hyphenated names (e.g.,pr-new-collection,-start,end-,a-b) and documentation indocs/backend.md.