From f29ba4ab8bc5a059286fa486fe5f81d2a7f10a6e Mon Sep 17 00:00:00 2001 From: devops Date: Fri, 23 Oct 2026 13:03:23 +0000 Subject: [PATCH] fix(admin): reconcile bounded PREPARE backend contracts --- .../CreateOrchestrationTask.test.tsx | 8 ++- .../components/CreateOrchestrationTask.tsx | 15 ++--- .../pages/OrchestrationCommandCenter.test.tsx | 9 ++- .../src/pages/OrchestrationCommandCenter.tsx | 10 ++-- .../src/pages/workflowSafety.test.tsx | 7 ++- .../src/services/orchestration.test.ts | 54 +++++++++++++++++- .../admin-panel/src/services/orchestration.ts | 55 ++++++++++++++++--- 7 files changed, 127 insertions(+), 31 deletions(-) diff --git a/frontend/admin-panel/src/components/CreateOrchestrationTask.test.tsx b/frontend/admin-panel/src/components/CreateOrchestrationTask.test.tsx index 573578dc..88fc0e98 100644 --- a/frontend/admin-panel/src/components/CreateOrchestrationTask.test.tsx +++ b/frontend/admin-panel/src/components/CreateOrchestrationTask.test.tsx @@ -3,12 +3,14 @@ import {it,expect,vi} from 'vitest'; import api from '../services/api'; import CreateOrchestrationTask from './CreateOrchestrationTask'; vi.mock('../services/api',()=>({default:{post:vi.fn()}})); -it('submits explicit bounded scope and acceptance criteria, only after valid input',async()=>{ +it('submits exact bounded PREPARE contract only after valid commit and budget',async()=>{ vi.mocked(api.post).mockResolvedValue({data:{id:'new'}});const done=vi.fn();render(); expect(screen.getByRole('button',{name:'Create bounded task'})).toBeDisabled(); - for(const [label,value] of Object.entries({'Task key':'audit-1','Title':'Audit schema','Department':'SEO','Bounded scope':'Staging schema audit only','Acceptance criteria (one per line)':'Report all failures','Budget cap in cents':'500'}))fireEvent.change(screen.getByLabelText(label),{target:{value}}); + for(const [label,value] of Object.entries({'Task key':'audit-1','Title':'Audit schema','Department':'SEO','Commit SHA (40 lowercase hex)':'a'.repeat(40),'Budget cap in cents':'500'}))fireEvent.change(screen.getByLabelText(label),{target:{value}}); + for(const value of ['19','10001','20.5']){fireEvent.change(screen.getByLabelText('Budget cap in cents'),{target:{value}});expect(screen.getByRole('button',{name:'Create bounded task'})).toBeDisabled();} + fireEvent.change(screen.getByLabelText('Budget cap in cents'),{target:{value:'500'}}); fireEvent.click(screen.getByRole('button',{name:'Create bounded task'})); await screen.findByText('Task created by backend.'); - expect(api.post).toHaveBeenCalledWith('/admin/orchestration/tasks',expect.objectContaining({operationMode:'PREPARE',budgetLimitCents:500,metadata:{scope:'Staging schema audit only',acceptanceCriteria:['Report all failures']}})); + expect(api.post).toHaveBeenCalledWith('/admin/orchestration/tasks',expect.objectContaining({operationMode:'PREPARE',budgetLimitCents:500,metadata:{commitSha:'a'.repeat(40)}})); expect(done).toHaveBeenCalledOnce(); }); diff --git a/frontend/admin-panel/src/components/CreateOrchestrationTask.tsx b/frontend/admin-panel/src/components/CreateOrchestrationTask.tsx index 1931041a..a9645761 100644 --- a/frontend/admin-panel/src/components/CreateOrchestrationTask.tsx +++ b/frontend/admin-panel/src/components/CreateOrchestrationTask.tsx @@ -1,14 +1,15 @@ import {useState} from 'react'; import Button from './ui/Button'; -import {orchestration} from '../services/orchestration'; +import {orchestration,proposalError} from '../services/orchestration'; import type {CreateTaskInput} from '../services/orchestration'; export default function CreateOrchestrationTask({onCreated}:{onCreated:()=>void}){ - const [fields,setFields]=useState({key:'',title:'',department:'',scope:'',criteria:'',budget:''}); - const [mode,setMode]=useState('PREPARE');const [busy,setBusy]=useState(false);const [error,setError]=useState('');const [success,setSuccess]=useState(''); - const valid=Object.values(fields).every(value=>value.trim())&&Number.isSafeInteger(Number(fields.budget))&&Number(fields.budget)>=0; - return
Create bounded work
{e.preventDefault();if(!valid||busy||success)return;setBusy(true);setError('');setSuccess('');try{await orchestration.create({key:fields.key,title:fields.title,department:fields.department,operationMode:mode,budgetLimitCents:Number(fields.budget),metadata:{scope:fields.scope,acceptanceCriteria:fields.criteria.split('\n').map(s=>s.trim()).filter(Boolean)}});setSuccess('Task created by backend.');onCreated()}catch(error){setError(error instanceof Error?error.message+' — Refresh and reconcile the task key before resubmitting.':'Create failed; reconcile task key before retry')}finally{setBusy(false)}}}> - {([['key','Task key'],['title','Title'],['department','Department'],['scope','Bounded scope'],['criteria','Acceptance criteria (one per line)'],['budget','Budget cap in cents']] as const).map(([key,label])=>