fix(sawala): resolve Kontena schemas by slug in entry create/update/delete - #101
Merged
Merged
Conversation
…elete `sawala kontena entry create|update|delete <schemaSlug>` failed with `NOT_FOUND (…/schemas/<slug>)` for every schema, as did the matching create/update/delete entry MCP tools. Each verb first looks the schema up to decide whether to write to the `single` or the `collection` content route. That lookup resolves ULIDs only, while the content route it feeds resolves the schema by *slug* — so the identifier that makes the write succeed is exactly the one that makes the lookup 404, and no value satisfies both. `fetchSchemaType` now falls back to listing the project's schemas and matching by slug, mirroring `schema get`. The list rows already carry `type`, so the fallback costs one request rather than two. The three MCP tools share a new `resolveSchemaType` helper instead of repeating the pre-flight three times. A genuinely missing schema now reports `Schema 'x' not found. Available slugs: …` rather than a bare NOT_FOUND. Also syncs package-lock.json, whose workspace versions had drifted from the package.json versions (@sawala/cli recorded as 0.9.0 vs 0.14.1). Tests: three CLI cases and two MCP cases covering the fallback, the single-vs-collection routing through it, and the not-found message. All five fail before this change and pass after. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
sawala kontena entry create|update|delete <schemaSlug>failed withNOT_FOUND (…/schemas/<slug>)for every schema — the commands were unusable. Thesawala_kontena_{create,update,delete}_entryMCP tools failed identically.Each verb looks the schema up first, to decide whether to write to the
singleor thecollectioncontent route:eq(schemas.slug, schemaSlug))So the identifier that makes the write succeed is exactly the one that 404s on the lookup, and there is no value that satisfies both. A ULID passes the pre-flight and fails the write; a slug fails the pre-flight.
Found while seeding content for the sawala.cloud marketing blog, where every
entry createfailed against a freshly created schema.The fix
fetchSchemaTypenow falls back to listing the project's schemas and matching by slug on a 404 — the same fallbacksawala kontena schema getalready had. The list rows already carrytype, so this costs one extra request, not two.The three MCP entry tools had three copies of the same pre-flight; they now share one
resolveSchemaTypehelper (packages/sawala-mcp/src/lib/kontena-schema.ts), so the bug can't come back in only two of them.A genuinely absent schema now reports
Schema 'x' not found. Available slugs: posts, pages.instead of a bareNOT_FOUND.Note on the existing tests
The pre-existing tests stubbed schema-get as succeeding on a slug path, which encoded the very assumption that was wrong — which is how this shipped. The new cases stub the 404 the real server returns.
Verification
npm run typecheck && npm run test && npm run check:skills— clean; 545 tests pass.Also included
package-lock.jsonworkspace versions had drifted from thepackage.jsonversions (@sawala/clirecorded as 0.9.0 vs the actual 0.14.1). Anynpm installcorrects this; it is unrelated to the fix but was picked up in the same install.Changeset: patch bump for
@sawala/cliand@sawala/mcp.🤖 Generated with Claude Code