mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-05 02:47:21 +01:00
fix(cat): correct create_task and create_organization handler column errors
create_task inserted invalid enum values that Postgres would reject: - status: 'pending' → current_status: 'idle' (correct column + valid value) - task_type: 'personal' → 'one_time' (valid: one_time|recurring_*|as_needed) - category: 'general' → 'other' (valid: cleaning|maintenance|admin|...|other) - priority: 'medium' → 'normal' (valid: low|normal|high|urgent) - removed due_date (not a column on the tasks table) create_organization had two fatal issues: - type (non-existent column) → label (valid: circle|family|dao|company|...) - missing slug (UNIQUE NOT NULL) — now generated from name + random suffix Also adds 4 regression tests covering both handlers. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
b7ac662db3
commit
a563de7967
2 files changed
+90
-7
No files matched your search
@@ -15,6 +15,7 @@
|
||||
|
||||
import { CatActionExecutor } from '@/services/cat/action-executor';
|
||||
import { ENTITY_REGISTRY } from '@/config/entity-registry';
|
||||
import { DATABASE_TABLES } from '@/config/database-tables';
|
||||
|
||||
// ── Mock CatPermissionService ─────────────────────────────────────────────────
|
||||
// Auto-allow every action: allowed=true, requiresConfirmation=false
|
||||
@@ -333,4 +334,73 @@ describe('Cat action-executor — correct DB column names', () => {
|
||||
expect(result.error).toMatch(/no valid fields/i);
|
||||
});
|
||||
});
|
||||
|
||||
// ── create_task ─────────────────────────────────────────────────────────────
|
||||
describe('create_task', () => {
|
||||
it('uses current_status (not status) with valid enum values', async () => {
|
||||
const supabase = buildMockSupabase();
|
||||
const result = await run(supabase, 'create_task', {
|
||||
title: 'Fix the sink',
|
||||
description: 'Leaking pipe under kitchen sink',
|
||||
});
|
||||
|
||||
expect(result.status).toBe('completed');
|
||||
const insert = getEntityInsert(supabase, DATABASE_TABLES.TASKS);
|
||||
expect(insert).toBeDefined();
|
||||
|
||||
// Correct column name
|
||||
expect(insert!.current_status).toBe('idle');
|
||||
// Wrong column name must NOT appear
|
||||
expect((insert as Record<string, unknown>).status).toBeUndefined();
|
||||
|
||||
// Valid enum values only
|
||||
expect(insert!.task_type).toBe('one_time'); // not 'personal'
|
||||
expect(insert!.category).toBe('other'); // not 'general'
|
||||
expect(insert!.priority).toBe('normal'); // not 'medium'
|
||||
expect(insert!.created_by).toBe(USER_ID);
|
||||
});
|
||||
});
|
||||
|
||||
// ── create_organization ─────────────────────────────────────────────────────
|
||||
describe('create_organization', () => {
|
||||
it('uses label (not type) and generates a slug', async () => {
|
||||
const supabase = buildMockSupabase();
|
||||
const result = await run(supabase, 'create_organization', {
|
||||
name: 'Bitcoin Builders',
|
||||
description: 'Building on Bitcoin',
|
||||
label: 'company',
|
||||
});
|
||||
|
||||
expect(result.status).toBe('completed');
|
||||
const insert = getEntityInsert(supabase, ENTITY_REGISTRY.group.tableName);
|
||||
expect(insert).toBeDefined();
|
||||
|
||||
// Correct column used
|
||||
expect(insert!.label).toBe('company');
|
||||
// Wrong column must NOT appear
|
||||
expect((insert as Record<string, unknown>).type).toBeUndefined();
|
||||
|
||||
// Slug must be generated (non-empty, derived from name)
|
||||
expect(typeof insert!.slug).toBe('string');
|
||||
expect((insert!.slug as string).length).toBeGreaterThan(0);
|
||||
expect((insert!.slug as string)).toMatch(/^bitcoin-builders-/);
|
||||
|
||||
expect(insert!.name).toBe('Bitcoin Builders');
|
||||
expect(insert!.created_by).toBe(USER_ID);
|
||||
});
|
||||
|
||||
it('defaults label to circle when not provided', async () => {
|
||||
const supabase = buildMockSupabase();
|
||||
await run(supabase, 'create_organization', { name: 'My Group' });
|
||||
const insert = getEntityInsert(supabase, ENTITY_REGISTRY.group.tableName);
|
||||
expect(insert!.label).toBe('circle');
|
||||
});
|
||||
|
||||
it('accepts legacy type param as fallback for label', async () => {
|
||||
const supabase = buildMockSupabase();
|
||||
await run(supabase, 'create_organization', { name: 'Coop', type: 'cooperative' });
|
||||
const insert = getEntityInsert(supabase, ENTITY_REGISTRY.group.tableName);
|
||||
expect(insert!.label).toBe('cooperative');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -372,17 +372,19 @@ const ACTION_HANDLERS: Partial<Record<string, ActionHandler>> = {
|
||||
// ---------- PRODUCTIVITY ACTIONS ----------
|
||||
|
||||
create_task: async (supabase, userId, _actorId, params) => {
|
||||
// DB columns: current_status (not status), task_type enum: one_time|recurring_scheduled|recurring_as_needed,
|
||||
// category enum: cleaning|maintenance|admin|inventory|it|kitchen|workshop|logistics|other,
|
||||
// priority enum: low|normal|high|urgent (not medium)
|
||||
const { data, error } = await supabase
|
||||
.from(DATABASE_TABLES.TASKS)
|
||||
.insert({
|
||||
created_by: userId,
|
||||
title: params.title,
|
||||
description: (params.description as string | null) || null,
|
||||
priority: (params.priority as string) || 'medium',
|
||||
due_date: (params.due_date as string | null) || null,
|
||||
status: 'pending',
|
||||
task_type: 'personal',
|
||||
category: 'general',
|
||||
priority: (params.priority as string) || 'normal',
|
||||
task_type: 'one_time',
|
||||
category: 'other',
|
||||
current_status: 'idle',
|
||||
})
|
||||
.select()
|
||||
.single();
|
||||
@@ -396,13 +398,24 @@ const ACTION_HANDLERS: Partial<Record<string, ActionHandler>> = {
|
||||
// ---------- ORGANIZATION ACTIONS ----------
|
||||
|
||||
create_organization: async (supabase, userId, _actorId, params) => {
|
||||
// groups table has: name, slug (UNIQUE NOT NULL), label (not type), created_by
|
||||
// label enum: circle|family|dao|company|nonprofit|cooperative|guild|network_state
|
||||
const name = params.name as string;
|
||||
const slug = name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-|-$/g, '')
|
||||
.slice(0, 60)
|
||||
+ '-' + Math.random().toString(36).slice(2, 7);
|
||||
|
||||
// Create the group (organization)
|
||||
const { data: group, error: groupError } = await supabase
|
||||
.from(ENTITY_REGISTRY.group.tableName)
|
||||
.insert({
|
||||
name: params.name,
|
||||
name,
|
||||
slug,
|
||||
description: params.description || null,
|
||||
type: params.type || 'organization',
|
||||
label: (params.label as string | null) ?? (params.type as string | null) ?? 'circle',
|
||||
created_by: userId,
|
||||
})
|
||||
.select()
|
||||
|
||||
Reference in new issue
Block a user