fix(frontend): restore full admin gates and preserve analytics protocol
This commit is contained in:
1 parent
448c250944
commit
1bb6274b35
6 files changed
+37
-8
No files matched your search
@@ -32,7 +32,7 @@ export default function OrchestrationCommandCenter() {
|
||||
const [attempted,setAttempted]=useState(false); const [busy,setBusy]=useState(false); const [commandError,setCommandError]=useState('');
|
||||
const [success,setSuccess]=useState('');
|
||||
const [blocked,setBlocked]=useState(false);
|
||||
const [now,setNow]=useState(Date.now());
|
||||
const [now,setNow]=useState(()=>Date.now());
|
||||
useEffect(()=>{const timer=setInterval(()=>setNow(Date.now()),1000);return ()=>clearInterval(timer)},[]);
|
||||
const [kill,setKill]=useState<KillLevel>('FREEZE_NEW_WORK');
|
||||
const [session,setSession]=useState(''); const [message,setMessage]=useState('');
|
||||
|
||||
@@ -14,6 +14,11 @@ it('does not restore stale detail after authoritative refresh while detail reque
|
||||
it('keeps payload immutable when navigating after an ambiguous network failure',async()=>{
|
||||
vi.resetAllMocks();const t={id:'t',key:'t',title:'Task identity',department:'DEV',state:'GATE1_PENDING',version:2,operationMode:'PREPARE',budgetLimitCents:0,availableActions:[{id:'g1',label:'Approve safe work',gate:1,decision:'APPROVED'}]};
|
||||
vi.mocked(api.get).mockImplementation(async url=>({data:url.endsWith('/overview')?{items:[],measuredAt:'2026-10-23',capabilities:{mutations:true}}:url.endsWith('/tasks')?[t]:t}));vi.mocked(api.post).mockRejectedValue(new Error('network'));
|
||||
render(<OrchestrationCommandCenter/>);fireEvent.click(await screen.findByRole('button',{name:'Task identity'}));fireEvent.click(await screen.findByRole('button',{name:'تأیید در Gate1'}));const d=within(screen.getByRole('dialog'));fireEvent.change(d.getByLabelText('زمان انقضا'),{target:{value:'2099-01-01T12:00'}});fireEvent.change(d.getByLabelText('دلیل'),{target:{value:'Reviewed'}});fireEvent.click(d.getByLabelText('محدوده و اتصال تغییرناپذیر را بررسی کردم'));fireEvent.click(d.getByRole('button',{name:'تأیید فرمان'}));await d.findByRole('alert');
|
||||
render(<OrchestrationCommandCenter/>);fireEvent.click(await screen.findByRole('button',{name:'Task identity'}));fireEvent.click(await screen.findByRole('button',{name:'تأیید در Gate1'}));const d=within(screen.getByRole('dialog'));expect(d.queryByLabelText('زمان انقضا')).not.toBeInTheDocument();expect(d.getByLabelText('زمان اجرای برنامهریزیشده')).toHaveValue('');fireEvent.change(d.getByLabelText('دلیل'),{target:{value:'Reviewed'}});fireEvent.click(d.getByLabelText('محدوده و اتصال تغییرناپذیر را بررسی کردم'));fireEvent.click(d.getByRole('button',{name:'تأیید فرمان'}));await d.findByRole('alert');
|
||||
const sentPayload=structuredClone(vi.mocked(api.post).mock.calls[0][1]);
|
||||
expect(sentPayload).toMatchObject({expectedVersion:2,decision:'APPROVED',notes:'Reviewed'});
|
||||
expect(sentPayload).not.toHaveProperty('expiresAt');expect(sentPayload).not.toHaveProperty('notBefore');
|
||||
fireEvent.click(screen.getByRole('button',{name:'وظیفهها و تأییدها'}));expect(d.getByLabelText('دلیل')).toHaveValue('Reviewed');expect(d.getByLabelText('محدوده و اتصال تغییرناپذیر را بررسی کردم')).toBeChecked();
|
||||
expect(vi.mocked(api.post).mock.calls[0][1]).toEqual(sentPayload);
|
||||
expect(d.getByLabelText('دلیل')).toBeDisabled();expect(d.getByLabelText('زمان اجرای برنامهریزیشده')).toBeDisabled();
|
||||
});
|
||||
@@ -27,7 +27,7 @@ it('rejects Gate2 evidence from failed runs',async()=>{
|
||||
await expect(orchestration.command({...task,availableActions:[g2],runs:[{id:'r',status:'FAILED',commitSha:'abc',environment:'stage',artifacts:[{id:'a',sha256:'a'.repeat(64)}]}]},g2,{idempotencyKey:'key',expiresAt:'2099-01-01T00:00:00Z',runId:'r',artifactHash:'a'.repeat(64)})).rejects.toThrow(/Gate2.*غیرفعال/);
|
||||
expect(api.post).not.toHaveBeenCalled();
|
||||
});
|
||||
async function dialog(){render(<OrchestrationCommandCenter/>);fireEvent.click(await screen.findByRole('button',{name:'Safe proposal'}));fireEvent.click(await screen.findByRole('button',{name:'تأیید در Gate1'}));const d=within(screen.getByRole('dialog'));fireEvent.change(d.getByLabelText('زمان انقضا'),{target:{value:'2099-01-01T12:00'}});fireEvent.change(d.getByLabelText('دلیل'),{target:{value:'Reviewed bounds'}});fireEvent.click(d.getByLabelText('محدوده و اتصال تغییرناپذیر را بررسی کردم'));return d;}
|
||||
async function dialog(){render(<OrchestrationCommandCenter/>);fireEvent.click(await screen.findByRole('button',{name:'Safe proposal'}));fireEvent.click(await screen.findByRole('button',{name:'تأیید در Gate1'}));const d=within(screen.getByRole('dialog'));expect(d.queryByLabelText('زمان انقضا')).not.toBeInTheDocument();expect(d.getByLabelText('زمان اجرای برنامهریزیشده')).toHaveValue('');fireEvent.change(d.getByLabelText('دلیل'),{target:{value:'Reviewed bounds'}});fireEvent.click(d.getByLabelText('محدوده و اتصال تغییرناپذیر را بررسی کردم'));return d;}
|
||||
it('locks stale 409 command until authoritative refresh instead of retrying stale payload',async()=>{
|
||||
vi.mocked(api.post).mockRejectedValue({response:{status:409,data:{message:'Version conflict'}}});
|
||||
const d=await dialog();fireEvent.click(d.getByRole('button',{name:'تأیید فرمان'}));
|
||||
@@ -41,7 +41,9 @@ it('does not expose authorized task mutations when capabilities are unavailable'
|
||||
render(<OrchestrationCommandCenter/>);fireEvent.click(await screen.findByRole('button',{name:'Safe proposal'}));await screen.findByRole('region',{name:'جزئیات وظیفه'});
|
||||
expect(screen.getByRole('button',{name:'تأیید در Gate1'})).toBeDisabled();
|
||||
});
|
||||
it('prevents confirming an already expired approval',async()=>{
|
||||
const d=await dialog();fireEvent.change(d.getByLabelText('زمان انقضا'),{target:{value:'2020-01-01T12:00'}});
|
||||
it('prevents confirming a scheduled start in the past without sending a command',async()=>{
|
||||
const d=await dialog();fireEvent.change(d.getByLabelText('زمان اجرای برنامهریزیشده'),{target:{value:'2020-01-01T12:00'}});
|
||||
expect(d.getByRole('button',{name:'تأیید فرمان'})).toBeDisabled();
|
||||
fireEvent.click(d.getByRole('button',{name:'تأیید فرمان'}));
|
||||
expect(api.post).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -1 +1,13 @@
|
||||
import '@testing-library/jest-dom/vitest';
|
||||
|
||||
// Vitest preserves Node 26's host storage globals when populating jsdom.
|
||||
// Bind the actual jsdom Storage objects, not the unavailable host storage.
|
||||
const browserWindow = (globalThis as typeof globalThis & {
|
||||
jsdom: { window: Window };
|
||||
}).jsdom.window;
|
||||
for (const name of ['localStorage', 'sessionStorage'] as const) {
|
||||
Object.defineProperty(globalThis, name, {
|
||||
configurable: true,
|
||||
value: browserWindow[name],
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { expect, it } from 'vitest';
|
||||
|
||||
it('uses browser storage for persistent auth instead of Node host storage', () => {
|
||||
expect(localStorage).toBe(window.localStorage);
|
||||
expect(localStorage).toBeInstanceOf(window.Storage);
|
||||
expect(sessionStorage).toBeInstanceOf(window.Storage);
|
||||
localStorage.setItem('storage-probe', 'browser');
|
||||
expect(localStorage.getItem('storage-probe')).toBe('browser');
|
||||
localStorage.removeItem('storage-probe');
|
||||
});
|
||||
@@ -79,9 +79,9 @@ export default function AnalyticsDeferred({ gtmId, gaId, clarityId }: AnalyticsD
|
||||
if (gaId) {
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(..._args: any[]) {
|
||||
// Note: Google's gtag.js specifically expects the native `arguments` object.
|
||||
// Pushing an ES6 Array causes gtag.js to silently ignore tracking commands.
|
||||
window.dataLayer?.push(arguments);
|
||||
// gtag.js consumes the native Arguments object, not an ES6 rest array.
|
||||
// valueOf returns that same object without converting the vendor payload.
|
||||
window.dataLayer?.push(arguments.valueOf());
|
||||
}
|
||||
window.gtag = gtag;
|
||||
gtag('js', new Date());
|
||||
|
||||
Reference in new issue
Block a user