fix(admin): reconcile bounded PREPARE backend contracts

This commit is contained in:
devops committed 2026-10-23 13:04:06 +00:00
1 parent 56b6696ca3
commit f29ba4ab8b
7 files changed
+127 -31

No files matched your search

@@ -2,23 +2,24 @@ import {render,screen,fireEvent,within,waitFor} from '@testing-library/react';
import {beforeEach,it,expect,vi} from 'vitest';
import api from '../services/api';
import {orchestration} from '../services/orchestration';
import type {CreateTaskInput} from '../services/orchestration';
import OrchestrationCommandCenter from './OrchestrationCommandCenter';
vi.mock('../services/api',()=>({default:{get:vi.fn(),post:vi.fn(),put:vi.fn()}}));
const action={id:'g1',label:'Review Gate1',gate:1 as const,decision:'APPROVED' as const};
const task={id:'t',key:'t',title:'Safe proposal',department:'DEV',state:'GATE1_PENDING',version:2,operationMode:'PREPARE',budgetLimitCents:0,availableActions:[action],runs:[]};
beforeEach(()=>{vi.resetAllMocks();vi.mocked(api.get).mockImplementation(async url=>({data:url.endsWith('/overview')?{items:[],measuredAt:'2026-10-23T00:00:00Z',capabilities:{mutations:true,chat:false,runtime:false}}:url.endsWith('/tasks')?[task]:task}));});
it('refuses Production creation even when called outside form',async()=>{
await expect(orchestration.create({key:'x',title:'x',department:'DEV',operationMode:'MUTATE_PRODUCTION',budgetLimitCents:0,metadata:{scope:'x',acceptanceCriteria:['x']}})).rejects.toThrow(/Production/);
await expect(orchestration.create({key:'x',title:'x',department:'DEV',operationMode:'MUTATE_PRODUCTION',budgetLimitCents:0,metadata:{commitSha:'a'.repeat(40)}} as unknown as CreateTaskInput)).rejects.toThrow(/PREPARE|advertised/);
expect(api.post).not.toHaveBeenCalled();
});
it('rejects ambiguous advertised action rather than selecting a mutation path',async()=>{
const ambiguous={...action,toState:'READY'};
await expect(orchestration.command({...task,availableActions:[ambiguous]},ambiguous,{idempotencyKey:'key',expiresAt:'2099-01-01T00:00:00Z'})).rejects.toThrow(/Unsupported/);
await expect(orchestration.command({...task,availableActions:[ambiguous]},ambiguous,{idempotencyKey:'key',expiresAt:'2099-01-01T00:00:00Z'})).rejects.toThrow(/advertised/);
expect(api.post).not.toHaveBeenCalled();
});
it('blocks release transitions even when advertised by server',async()=>{
const release={id:'release',label:'Release',toState:'RELEASING'};
await expect(orchestration.command({...task,availableActions:[release]},release,{idempotencyKey:'key'})).rejects.toThrow(/Production/);
await expect(orchestration.command({...task,availableActions:[release]},release,{idempotencyKey:'key'})).rejects.toThrow(/PREPARE|advertised/);
expect(api.put).not.toHaveBeenCalled();
});
it('rejects Gate2 evidence from failed runs',async()=>{