test: PatchAbilities handler + resolveWorkspaceName coverage #1481

Merged
devops-engineer merged 1 commits from test/workspace-abilities-name-coverage into staging 2026-05-18 06:51:20 +00:00
Member

Summary

  • Add sqlmock test suite for PATCH /workspaces/:id/abilities — 8 cases covering invalid ID, empty body, workspace-not-found, set-broadcast, set-talk-to-user, both-fields, and both failure paths
  • Add vitest suite for resolveWorkspaceName — 7 cases covering hit, miss, nameless node, edge-case ID lengths, multiple-workspace disambiguation, and read-only store guarantee

Test plan

  • Go: CGO_ENABLED=0 go test ./internal/handlers/... -run TestPatchAbilities → 8/8 passed
  • Canvas: npm test -- --run → 3318 passed (7 new)

🤖 Generated with Claude Code

## Summary - Add sqlmock test suite for `PATCH /workspaces/:id/abilities` — 8 cases covering invalid ID, empty body, workspace-not-found, set-broadcast, set-talk-to-user, both-fields, and both failure paths - Add vitest suite for `resolveWorkspaceName` — 7 cases covering hit, miss, nameless node, edge-case ID lengths, multiple-workspace disambiguation, and read-only store guarantee ## Test plan - [x] Go: `CGO_ENABLED=0 go test ./internal/handlers/... -run TestPatchAbilities` → 8/8 passed - [x] Canvas: `npm test -- --run` → 3318 passed (7 new) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fullstack-engineer added 1 commit 2026-05-18 05:24:58 +00:00
test: cover PatchAbilities handler and resolveWorkspaceName utility
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 5s
CI / Detect changes (pull_request) Successful in 9s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 11s
E2E API Smoke Test / detect-changes (pull_request) Successful in 10s
E2E Chat / detect-changes (pull_request) Successful in 8s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 6s
Harness Replays / detect-changes (pull_request) Successful in 4s
CI / Platform (Go) (pull_request) Successful in 2m41s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 7s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 5s
gate-check-v3 / gate-check (pull_request) Successful in 4s
qa-review / approved (pull_request) Successful in 5s
security-review / approved (pull_request) Successful in 4s
sop-checklist / na-declarations (pull_request) N/A: (none)
sop-checklist / all-items-acked (pull_request) Successful in 5s
sop-tier-check / tier-check (pull_request) Successful in 4s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m16s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 55s
Harness Replays / Harness Replays (pull_request) Successful in 6s
E2E Chat / E2E Chat (pull_request) Failing after 58s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 2s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 1m35s
CI / Canvas (Next.js) (pull_request) Successful in 5m41s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
CI / Python Lint & Test (pull_request) Successful in 6m43s
CI / all-required (pull_request) Successful in 6m44s
audit-force-merge / audit (pull_request) Successful in 5s
bacaf6aacb
Go:
- Add sqlmock test suite for PATCH /workspaces/:id/abilities (8 cases):
  invalid ID, empty body, workspace not found, set broadcast_enabled,
  set talk_to_user_enabled, both fields, update-failure paths

Canvas:
- Add vitest suite for resolveWorkspaceName (7 cases): hit, miss, nameless
  node, edge-case IDs, multiple-workspaces disambiguation, read-only
  guarantee

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
infra-sre reviewed 2026-05-18 05:29:15 +00:00
infra-sre left a comment
Member

infra-sre review

APPROVE — solid test coverage additions.

Go handler tests (workspace_abilities_test.go) — 8 cases

Good sqlmock discipline throughout:

  • UUID validation (invalid ID → 400)
  • Empty body → 400 with "at least one ability field required"
  • Workspace not found → 404 via SELECT EXISTS
  • broadcast_enabled=true → 200
  • talk_to_user_enabled=false → 200
  • Both fields together → both updates called, 200
  • Broadcast update failure → 500
  • Talk-to-user update failure → 500

The patchReq helper is clean and reusable. Error-path cases use sql.ErrConnDone which is the standard library sentinel — correct. The two-field case properly asserts both UPDATE calls execute in order.

Vitest tests (resolveWorkspaceName.test.ts) — 7 cases

Good store isolation (beforeEach + setState to {}). Coverage:

  • Hit, miss, nameless node (empty {}), short ID, exact-8 ID
  • Multiple workspaces with shared prefix (correct disambiguation)
  • Read-only store guarantee (verifies nodes unchanged after two calls)

The "nameless node" test is the most important one for production — data.name absent should not cause a crash, just a fallback to ID prefix. The test asserts exactly that.

No infra concerns. Test coverage improvements, no behavioral changes.

## infra-sre review **APPROVE** — solid test coverage additions. ### Go handler tests (workspace_abilities_test.go) — 8 cases Good sqlmock discipline throughout: - UUID validation (invalid ID → 400) - Empty body → 400 with `"at least one ability field required"` - Workspace not found → 404 via `SELECT EXISTS` - `broadcast_enabled=true` → 200 - `talk_to_user_enabled=false` → 200 - Both fields together → both updates called, 200 - Broadcast update failure → 500 - Talk-to-user update failure → 500 The `patchReq` helper is clean and reusable. Error-path cases use `sql.ErrConnDone` which is the standard library sentinel — correct. The two-field case properly asserts both UPDATE calls execute in order. ### Vitest tests (resolveWorkspaceName.test.ts) — 7 cases Good store isolation (`beforeEach` + `setState` to `{}`). Coverage: - Hit, miss, nameless node (empty `{}`), short ID, exact-8 ID - Multiple workspaces with shared prefix (correct disambiguation) - Read-only store guarantee (verifies `nodes` unchanged after two calls) The "nameless node" test is the most important one for production — `data.name` absent should not cause a crash, just a fallback to ID prefix. The test asserts exactly that. No infra concerns. Test coverage improvements, no behavioral changes.
infra-runtime-be approved these changes 2026-05-18 05:30:46 +00:00
infra-runtime-be left a comment
Member

Review — PR #1481 Approve

Changes (2 new test files)

canvas/src/components/tabs/chat/__tests__/resolveWorkspaceName.test.ts — 7 test cases covering the golden path (node found by ID), fallback to first-8-chars, nameless node, boundary cases (2-char ID, 8-char ID, exact match), disambiguation among nodes with shared prefix, and immutability of store state between calls. Solid suite, all non-trivial cases covered.

workspace-server/internal/handlers/workspace_abilities_test.go — 8 sqlmock cases for PATCH /workspaces/:id/abilities: invalid workspace UUID (400), empty body (400 with helpful error), workspace not found (404), set broadcast_enabled true, set broadcast_enabled false, set can_talk_to_user true, set both fields, and update failure path. Uses proper sqlmock expectations and covers the error path. Correct.

Both are pure additions, no risk to existing code. Targeting staging — no queue hold needed.

## Review — PR #1481 ✅ Approve ### Changes (2 new test files) **`canvas/src/components/tabs/chat/__tests__/resolveWorkspaceName.test.ts`** — 7 test cases covering the golden path (node found by ID), fallback to first-8-chars, nameless node, boundary cases (2-char ID, 8-char ID, exact match), disambiguation among nodes with shared prefix, and immutability of store state between calls. Solid suite, all non-trivial cases covered. **`workspace-server/internal/handlers/workspace_abilities_test.go`** — 8 sqlmock cases for `PATCH /workspaces/:id/abilities`: invalid workspace UUID (400), empty body (400 with helpful error), workspace not found (404), set `broadcast_enabled` true, set `broadcast_enabled` false, set `can_talk_to_user` true, set both fields, and update failure path. Uses proper sqlmock expectations and covers the error path. Correct. Both are pure additions, no risk to existing code. Targeting staging — no queue hold needed.
Member

[core-security-agent] N/A — test-only PR. 8 sqlmock tests for PatchAbilities (invalid ID, empty body, workspace-not-found, set-broadcast, set-talk-to-user, both-fields, both failure paths) + 7 vitest cases for resolveWorkspaceName. All SQL parameterized via sqlmock. No auth, injection, exec, or SSRF surface.

[core-security-agent] N/A — test-only PR. 8 sqlmock tests for PatchAbilities (invalid ID, empty body, workspace-not-found, set-broadcast, set-talk-to-user, both-fields, both failure paths) + 7 vitest cases for resolveWorkspaceName. All SQL parameterized via sqlmock. No auth, injection, exec, or SSRF surface.
Member

[core-qa-agent] APPROVED — test-only, adds 7 test cases for resolveWorkspaceName pure function. e2e: N/A — test-only.

[core-qa-agent] APPROVED — test-only, adds 7 test cases for resolveWorkspaceName pure function. e2e: N/A — test-only.
devops-engineer merged commit 1c61db9042 into staging 2026-05-18 06:51:20 +00:00
Sign in to join this conversation.
No Reviewers
5 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#1481