Harden integration read-only boundaries and admin contracts
This commit is contained in:
1 parent
ac065fa911
commit
841eab0556
21 files changed
+179
-687
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import toast from "react-hot-toast";
|
||||
import api from "../services/api";
|
||||
import ApprovalsPage from "./ApprovalsPage";
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import React, { useState, useEffect, useMemo } from 'react';
|
||||
import { useState, useEffect, useMemo } from 'react';
|
||||
import {
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
Play,
|
||||
AlertTriangle,
|
||||
RefreshCw,
|
||||
DollarSign,
|
||||
ShoppingCart,
|
||||
@@ -14,10 +13,8 @@ import {
|
||||
MessageSquare,
|
||||
FileText,
|
||||
Search,
|
||||
ArrowUpDown,
|
||||
ArrowUpRight,
|
||||
Briefcase,
|
||||
Filter,
|
||||
CheckCheck,
|
||||
Building2,
|
||||
TrendingUp,
|
||||
@@ -31,12 +28,10 @@ import {
|
||||
ShieldCheck,
|
||||
Stethoscope,
|
||||
Cpu,
|
||||
Headphones,
|
||||
MessageCircle,
|
||||
BarChart3,
|
||||
AlertCircle,
|
||||
Info,
|
||||
Tag,
|
||||
Layers,
|
||||
Clock
|
||||
} from 'lucide-react';
|
||||
@@ -114,8 +109,6 @@ function StructuredPayloadViewer({ payload }: { payload: any }) {
|
||||
// 6. Detect Competitor Intelligence / Benchmark Pattern
|
||||
const hasCompetitorBenchmark = ('key_findings' in payload || 'scraped_sources' in payload);
|
||||
|
||||
// 7. Detect B2B Clinical Targets Pattern
|
||||
const hasB2BTargets = ('top_tier_targets' in payload || 'target_clinics_identified' in payload);
|
||||
|
||||
return (
|
||||
<div className="space-y-3 font-vazir">
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import {
|
||||
History,
|
||||
Search,
|
||||
Filter,
|
||||
RefreshCw,
|
||||
Clock,
|
||||
User,
|
||||
Database,
|
||||
ArrowRight,
|
||||
Shield,
|
||||
Layers,
|
||||
ChevronDown,
|
||||
Calendar,
|
||||
AlertCircle,
|
||||
Eye,
|
||||
CheckCircle2
|
||||
} from 'lucide-react';
|
||||
import api from '../services/api';
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
Building2,
|
||||
CheckCircle2,
|
||||
Clock,
|
||||
AlertTriangle,
|
||||
ArrowUpRight,
|
||||
RefreshCw,
|
||||
ShieldCheck,
|
||||
@@ -13,7 +10,6 @@ import {
|
||||
Search,
|
||||
Headphones,
|
||||
Cpu,
|
||||
Layers,
|
||||
Terminal,
|
||||
Activity,
|
||||
XCircle,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Activity, DollarSign, ShoppingCart, Users, ShieldAlert, ArrowLeft, History, Briefcase, Clock, Database } from "lucide-react";
|
||||
import { Activity, DollarSign, ShoppingCart, Users, ShieldAlert, ArrowLeft, History, Briefcase, Database } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { CartesianGrid, Cell, Line, LineChart, Pie, PieChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect, useMemo } from 'react';
|
||||
import { useState, useEffect, useMemo } from 'react';
|
||||
import {
|
||||
Building2,
|
||||
Briefcase,
|
||||
|
||||
@@ -15,6 +15,12 @@ describe('measured monitoring',()=>{
|
||||
expect(screen.queryByText('Production')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText(/۱۴ روز/)).not.toBeInTheDocument();
|
||||
});
|
||||
it.each([0,125])('accepts the real flat SMS success response with credit %s',async credit=>{
|
||||
vi.mocked(api.get).mockResolvedValue({data:{success:true,credit,message:'اعتبار پیامک'}});
|
||||
render(<MonitoringPage/>);
|
||||
expect(await screen.findByText(credit.toLocaleString('fa-IR')+' پیامک')).toBeInTheDocument();
|
||||
expect(screen.queryByText(/Invalid measurement response/)).not.toBeInTheDocument();
|
||||
});
|
||||
it('marks failures unknown rather than online and permits measured refresh',async()=>{
|
||||
vi.mocked(api.get).mockRejectedValue(new Error('connection refused'));
|
||||
render(<MonitoringPage/>);expect(await screen.findAllByText(/connection refused/)).toHaveLength(3);
|
||||
|
||||
@@ -10,7 +10,7 @@ export default function MonitoringPage() {
|
||||
const refresh=useCallback(async()=>{
|
||||
if(inFlight.current)return;inFlight.current=true;setLoading(true);
|
||||
const results=await Promise.all(endpoints.map(async url=>{
|
||||
try {const {data:raw}=await api.get(url);const data=raw?.success===true?raw.data:raw;
|
||||
try {const {data:raw}=await api.get(url);const data=raw?.success===true&&Object.hasOwn(raw,'data')?raw.data:raw;
|
||||
if(!data||typeof data!=='object'||raw?.success===false)throw new Error('Invalid measurement response');
|
||||
return {data,error:null,observedAt:new Date().toISOString()};
|
||||
}catch(e){return {data:null,error:e instanceof Error?e.message:'Request failed',observedAt:new Date().toISOString()}}
|
||||
|
||||
@@ -20,6 +20,14 @@ describe('command center', () => {
|
||||
fireEvent.click(screen.getByRole('button',{name:'Agents & departments'}));
|
||||
expect(await screen.findByRole('alert')).toHaveTextContent('Unavailable');
|
||||
});
|
||||
it('labels deliberately omitted scope metadata unavailable, not immutable scope',async()=>{
|
||||
const {metadata:_metadata,...safeTask}=task;
|
||||
vi.mocked(api.get).mockImplementation(async url=>({data:url.endsWith('/tasks')?[safeTask]:safeTask}));
|
||||
render(<OrchestrationCommandCenter/>);
|
||||
fireEvent.click(await screen.findByRole('button',{name:'Bounded SEO audit'}));
|
||||
expect(await screen.findByText('Scope / acceptance criteria unavailable — omitted by the safe backend projection.')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Immutable scope / acceptance criteria')).not.toBeInTheDocument();
|
||||
});
|
||||
it('requires explicit confirmation and expiry; retains idempotency across failed retry', async () => {
|
||||
vi.mocked(api.post).mockRejectedValue(new Error('network failure'));
|
||||
render(<OrchestrationCommandCenter />);
|
||||
|
||||
@@ -59,7 +59,7 @@ export default function OrchestrationCommandCenter() {
|
||||
{!loading&&!error&&!tasks.length&&<p>No tasks returned by backend.</p>}
|
||||
<div className="overflow-x-auto"><table className="w-full text-sm"><thead><tr>{['Task','Department','State','Mode','Budget cap (cents)','Version'].map(h=><th key={h} className="text-start p-2">{h}</th>)}</tr></thead><tbody>{filtered.map(t=><tr key={t.id} className="border-t"><td className="p-2"><button className="text-purple-700 underline" onClick={()=>void select(t)}>{t.title}</button></td><td>{t.department}</td><td>{t.state}</td><td>{t.operationMode}</td><td>{t.budgetLimitCents??'Unknown'}</td><td>{t.version}</td></tr>)}</tbody></table></div>
|
||||
</section>}
|
||||
{selected&&<section aria-label="Task detail" className="bg-white border rounded-2xl p-5 space-y-4"><h2 className="font-bold">{selected.title} · v{selected.version}</h2><h3>Immutable scope / acceptance criteria</h3><Json value={{operationMode:selected.operationMode,budgetLimitCents:selected.budgetLimitCents,metadata:selected.metadata}}/>
|
||||
{selected&&<section aria-label="Task detail" className="bg-white border rounded-2xl p-5 space-y-4"><h2 className="font-bold">{selected.title} · v{selected.version}</h2>{selected.metadata?<h3>Backend-reported scope / acceptance criteria</h3>:<p>Scope / acceptance criteria unavailable — omitted by the safe backend projection.</p>}<Json value={{operationMode:selected.operationMode,budgetLimitCents:selected.budgetLimitCents,metadata:selected.metadata}}/>
|
||||
<h3>Server-authorized actions</h3>{!selected.availableActions.length&&<p>No actions advertised. Read-only; the browser does not infer transitions.</p>}<div className="flex flex-wrap gap-2">{selected.availableActions.map(a=><Button key={a.id} disabled={!!a.disabledReason} title={a.disabledReason} onClick={()=>open(selected,a)}>{a.label}</Button>)}</div>
|
||||
<h3>Immutable approval decisions</h3><Json value={selected.decisions??[]}/>
|
||||
<h3>Runs & registered artifacts</h3>{!selected.runs?.length&&<p>No registered runs.</p>}{selected.runs?.map(r=><article key={r.id} className="border rounded-xl p-3 space-y-2"><h4>{r.id} · {r.status}</h4><p>Commit: {r.commitSha} · Environment: {r.environment}</p>{r.artifacts.map(a=><Json key={a.id} value={a}/>)}</article>)}
|
||||
|
||||
@@ -37,6 +37,7 @@ export interface OrderItem {
|
||||
priceValue?: number;
|
||||
quantity?: number;
|
||||
product?: {
|
||||
requiresRx?: boolean;
|
||||
id?: string;
|
||||
nameFa?: string;
|
||||
name?: string;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { MemoryRouter } from "react-router-dom";
|
||||
import { beforeEach, expect, it, vi } from "vitest";
|
||||
import api from "../services/api";
|
||||
import SymptomsPage from "./SymptomsPage";
|
||||
vi.mock("../services/api", () => ({default: {get: vi.fn(), delete: vi.fn()}}));
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
vi.mocked(api.get).mockResolvedValue({data: {data: [{id:"symptom-1", name:"Anemia", slug:"anemia"}], meta:{lastPage:1}}});
|
||||
vi.mocked(api.delete).mockResolvedValue({data:{}});
|
||||
});
|
||||
it("shows deletion consequences and cancels without deleting, then confirms the selected symptom", async () => {
|
||||
render(<MemoryRouter><SymptomsPage/></MemoryRouter>);
|
||||
await screen.findByText("Anemia");
|
||||
fireEvent.click(screen.getByTitle("حذف"));
|
||||
expect(screen.getByText(/با حذف این علامت، ارتباط آن/)).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button",{name:"لغو"}));
|
||||
expect(screen.queryByText(/با حذف این علامت، ارتباط آن/)).not.toBeInTheDocument();
|
||||
expect(api.delete).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByTitle("حذف"));
|
||||
fireEvent.click(screen.getByRole("button",{name:"تایید"}));
|
||||
await waitFor(() => expect(api.delete).toHaveBeenCalledWith("/admin/symptoms/symptom-1"));
|
||||
await waitFor(() => expect(screen.queryByText(/با حذف این علامت، ارتباط آن/)).not.toBeInTheDocument());
|
||||
});
|
||||
@@ -22,7 +22,7 @@ export interface Symptom {
|
||||
}
|
||||
|
||||
export default function SymptomsPage() {
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const [searchParams] = useSearchParams();
|
||||
const [symptoms, setSymptoms] = useState<Symptom[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [search, setSearch] = useState(() => searchParams.get('search') || '');
|
||||
@@ -311,10 +311,10 @@ export default function SymptomsPage() {
|
||||
{/* Delete Confirmation */}
|
||||
<ConfirmModal
|
||||
isOpen={!!deleteTargetId}
|
||||
onClose={() => setDeleteTargetId(null)}
|
||||
onCancel={() => setDeleteTargetId(null)}
|
||||
onConfirm={handleDelete}
|
||||
title="حذف علامت بالینی"
|
||||
description="با حذف این علامت، ارتباط آن از تمام محصولات کاتالوگ نیز به طور خودکار حذف خواهد شد. آیا مطمئن هستید؟"
|
||||
message="با حذف این علامت، ارتباط آن از تمام محصولات کاتالوگ نیز به طور خودکار حذف خواهد شد. آیا مطمئن هستید؟"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import {
|
||||
Search,
|
||||
RefreshCw,
|
||||
@@ -7,10 +7,6 @@ import {
|
||||
ChevronDown,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
Play,
|
||||
CheckCircle,
|
||||
Clock,
|
||||
Filter
|
||||
} from 'lucide-react';
|
||||
import api from '../services/api';
|
||||
import toast from 'react-hot-toast';
|
||||
|
||||
Reference in new issue
Block a user