Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/repository-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
github.event.pull_request.base.ref == 'main' &&
github.event.pull_request.base.repo.full_name == github.repository &&
github.event.pull_request.head.repo.full_name == github.repository &&
(github.event.pull_request.head.ref == 'release/aps-github-validation-v1' || github.event.pull_request.head.ref == 'codex/aps-redesign-release')
(github.event.pull_request.head.ref == 'release/aps-github-validation-v1' || github.event.pull_request.head.ref == 'codex/aps-redesign-release' || github.event.pull_request.head.ref == 'codex/aps-guided-investigation')
run: node apps/aps-demo/scripts/qa-evidence.mjs
- name: Record actual PR checkout and workflow identities
id: validation
Expand All @@ -81,15 +81,15 @@ jobs:
github.event.pull_request.base.ref == 'main' &&
github.event.pull_request.base.repo.full_name == github.repository &&
github.event.pull_request.head.repo.full_name == github.repository &&
(github.event.pull_request.head.ref == 'release/aps-github-validation-v1' || github.event.pull_request.head.ref == 'codex/aps-redesign-release')
(github.event.pull_request.head.ref == 'release/aps-github-validation-v1' || github.event.pull_request.head.ref == 'codex/aps-redesign-release' || github.event.pull_request.head.ref == 'codex/aps-guided-investigation')
run: node apps/aps-demo/scripts/validation-evidence.mjs finalize
- name: Retain predeployment evidence including failed runs
if: >-
always() && github.event_name == 'pull_request' && github.repository_id == '1430231911' &&
github.event.pull_request.base.ref == 'main' &&
github.event.pull_request.base.repo.full_name == github.repository &&
github.event.pull_request.head.repo.full_name == github.repository &&
(github.event.pull_request.head.ref == 'release/aps-github-validation-v1' || github.event.pull_request.head.ref == 'codex/aps-redesign-release')
(github.event.pull_request.head.ref == 'release/aps-github-validation-v1' || github.event.pull_request.head.ref == 'codex/aps-redesign-release' || github.event.pull_request.head.ref == 'codex/aps-guided-investigation')
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2; ordinary artifact only
with:
name: aps-predeploy-${{ steps.validation.outputs.checkout_sha || github.sha }}-${{ github.run_id }}-${{ github.run_attempt }}
Expand Down
101 changes: 94 additions & 7 deletions apps/aps-demo/scripts/e2e.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/aps-demo/scripts/validation-evidence.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const repository = 'safetymp/agentic-process-safety';
const workflow = '.github/workflows/repository-checks.yml';
const releaseHeadRefs = Object.freeze(['release/aps-github-validation-v1', 'codex/aps-redesign-release']);
const releaseHeadRefs = Object.freeze(['release/aps-github-validation-v1', 'codex/aps-redesign-release', 'codex/aps-guided-investigation']);
const destination = '.harness/ci-qa/validation.json';
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
const blob = bytes => createHash('sha1').update(`blob ${bytes.length}\0`).update(bytes).digest('hex');
Expand Down
4 changes: 2 additions & 2 deletions apps/aps-demo/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';
import { SessionProvider, useSession } from './components/SessionContext.tsx';
import { getCase } from './domain/cases.ts';
import { runTitle } from './domain/presentation.ts';
import { Overview } from './routes/Overview.tsx';
import { Hazop } from './routes/Hazop.tsx';
import { Governance } from './routes/Governance.tsx';
Expand Down Expand Up @@ -71,7 +71,7 @@ function Workspace() {
<div className="main-shell">
<header className="topbar"><div><span className="muted">Research workspace</span><span className="topbar-divider">/</span><strong>{currentSection.name}</strong></div><label className="theme-select"><span id="app-theme">Theme</span><select aria-labelledby="app-theme" value={theme} onChange={event => setTheme(event.target.value as Theme)}><option value="system">System</option><option value="light">Light</option><option value="dark">Dark</option></select></label></header>
{(location.route !== 'overview' || selectedRun) && <section className="case-context" aria-label="Shared case context">
<div><small>ILLUSTRATIVE WORKSPACE</small><strong>{caseDefinition.title}</strong><p>{selectedRun ? `Selected ${selectedRun.id} · ${getCase(selectedRun.caseId).title}` : 'No comparison evaluated yet'}{isDirty && selectedRun ? ' · Inputs changed — run again' : ''}</p></div>
<div><small>ILLUSTRATIVE WORKSPACE</small><strong>{selectedRun && !isDirty ? runTitle(selectedRun) : caseDefinition.title}</strong><p>{selectedRun ? `Selected ${selectedRun.id} · ${runTitle(selectedRun)}` : 'No comparison evaluated yet'}{isDirty && selectedRun ? ' · Inputs changed — run again' : ''}</p></div>
<div className="button-row">{location.route !== 'simulator' && <a className="button" href="#/simulator">Return to comparison →</a>}<a className="text-button" href="#/simulator?panel=discussion">Discussion worksheet</a></div>
</section>}
<main id="main-content" tabIndex={-1}>
Expand Down
26 changes: 26 additions & 0 deletions apps/aps-demo/src/components/CaseEvidenceBridge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { CaseDefinition } from '../domain/cases.ts';

type SourceKind = 'hazard' | 'control' | 'recorded';

/** Explains a relationship, never upgrades a related source into execution evidence. */
export function CaseEvidenceBridge({ activeCase, kind, matches, sourceLabel }: {
activeCase: CaseDefinition; kind: SourceKind; matches: boolean; sourceLabel: string;
}) {
const relationship = activeCase.id === 'stale'
? { question: 'Was the finance approval still current when this purchase was attempted?', source: kind === 'recorded' ? 'The recorded expiry case tests an expired finance approval.' : 'The source finding concerns an expired quotation and excess price; the linked control covers approval and other expiry checks.', gap: 'Approval freshness does not establish quotation validity. Price, demand and stock accuracy still need separate evidence.', next: 'What would establish that the quotation is still valid before another attempt?' }
: activeCase.id === 'context'
? { question: 'Does this purchase carry context that belongs to its task?', source: kind === 'recorded' ? 'The recorded context substitution occurs at demand_mock; the browser illustration evaluates a purchase request.' : 'The source finding concerns context contamination; the mapped task-binding check covers a narrower condition.', gap: 'A context binding check does not establish source truth or resistance to live prompt injection. Related stages are not the same execution.', next: 'Which source and task binding would you need to verify before trusting this request?' }
: activeCase.id === 'conflict'
? { question: 'Who should resolve the competing objectives before the purchase proceeds?', source: kind === 'recorded' ? 'The recorded goal-conflict case measures a budget violation, not objective arbitration.' : 'The source finding concerns competing objectives; production arbitration remains an explicit control gap.', gap: 'Requesting review does not resolve the conflict. A budget outcome does not establish an acceptable trade-off between objectives.', next: 'Which objectives, decision owner and unresolved trade-off should the discussion record?' }
: { question: activeCase.objective, source: activeCase.evidenceNote, gap: activeCase.limitation, next: 'Which observation supports your recommendation, and what is still missing?' };
return <section className="panel case-evidence-bridge" aria-label="How this source relates to your case">
<p className="eyebrow">KEEP THE INVESTIGATION CONNECTED</p>
<h2>{matches ? 'What this source can tell you' : 'A different source is under inspection'}</h2>
<p><strong>Your case family:</strong> {activeCase.title}. <strong>Inspected source:</strong> {sourceLabel}.</p>
{matches ? <>
<div className="evidence-relationship-grid"><div><h3>Browser question</h3><p>{relationship.question}</p></div><div><h3>Related source</h3><p>{relationship.source}</p></div><div><h3>Still unresolved</h3><p>{relationship.gap}</p></div></div>
<p><strong>Bring back a question:</strong> {relationship.next}</p>
</> : <p>This selection is not the mapped source for your active case. Inspecting it does not change your retained comparison or make its results evidence for this case.</p>}
<nav className="button-row investigation-return" aria-label="Continue your investigation"><a className="button" href="#/simulator">Return to your comparison →</a><a className="button primary" href="#/simulator?panel=discussion">Return to your reasoning →</a></nav>
</section>;
}
146 changes: 146 additions & 0 deletions apps/aps-demo/src/components/CaseEvidenceJourney.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// @vitest-environment jsdom
import { afterEach, describe, expect, it, vi } from 'vitest';
import type * as Recharts from 'recharts';
import { cleanup, fireEvent, render, screen, within } from '@testing-library/react';
import { CaseEvidenceBridge } from './CaseEvidenceBridge.tsx';
import { EvidenceComparison } from './EvidenceComparison.tsx';
import { SessionProvider, useSession } from './SessionContext.tsx';
import { Hazop } from '../routes/Hazop.tsx';
import { Assurance } from '../routes/Assurance.tsx';
import { Governance } from '../routes/Governance.tsx';
import { getCase } from '../domain/cases.ts';
import { experiment } from '../data.ts';

vi.mock('recharts', async importOriginal => ({ ...await importOriginal<typeof Recharts>(), ResponsiveContainer: () => null }));

function EvidenceSessionControls() {
const { runComparison, setApprovalAge, selectedRun, discussions, updateDiscussion } = useSession();
const discussion = selectedRun && discussions[selectedRun.id];
return <>
<button onClick={runComparison}>Test evaluate</button>
<button onClick={() => setApprovalAge('59')}>Test edit age</button>
<button onClick={() => selectedRun && updateDiscussion(selectedRun.id, { evidence: 'Original evidence note.', rationale: 'Keep the expired request stopped.', ready: true })}>Test existing position</button>
<output aria-label="Test evidence">{discussion && discussion.evidence}</output>
<output aria-label="Test ready">{discussion && discussion.ready ? 'ready' : 'draft'}</output>
<output aria-label="Test outcome">{selectedRun ? `${selectedRun.results.B.decision}/${selectedRun.results.C.decision}` : 'none'}</output>
</>;
}

afterEach(() => { cleanup(); window.location.hash = ''; });

describe('supporting sources preserve the investigation question', () => {
it('explains approval freshness versus quotation validity before the source finding', () => {
render(<SessionProvider><Hazop params={new URLSearchParams()}/></SessionProvider>);
const bridge = screen.getByRole('region', { name: 'How this source relates to your case' });
const finding = screen.getByRole('region', { name: 'purchase: late' });
expect(bridge.compareDocumentPosition(finding) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
expect(within(bridge).getByText(/Approval freshness does not establish quotation validity/)).toBeTruthy();
expect(within(bridge).getByRole('link', { name: 'Return to your reasoning →' }).getAttribute('href')).toBe('#/simulator?panel=discussion');
expect(screen.getByText('Search and browse all 96 findings').closest('details')?.hasAttribute('open')).toBe(false);
fireEvent.click(screen.getByText('Search and browse all 96 findings'));
const register = screen.getByRole('table', { name: 'Generated hazards, all unverified with null ratings' });
expect(within(register).getAllByRole('row')).toHaveLength(97);
fireEvent.change(screen.getByLabelText('Search findings'), { target: { value: 'an impossible unmatched search' } });
expect(screen.getByText(/No findings match/)).toBeTruthy();
expect(screen.getByRole('region', { name: 'purchase: late' })).toBeTruthy();
});

it('does not present an unrelated selected hazard as the active case mapping', () => {
render(<SessionProvider><Hazop params={new URLSearchParams('hazard=APS-00be5560043a77ba3ede')}/></SessionProvider>);
const bridge = screen.getByRole('region', { name: 'How this source relates to your case' });
expect(within(bridge).getByRole('heading', { name: 'A different source is under inspection' })).toBeTruthy();
expect(within(bridge).getByText(/not the mapped source for your active case/)).toBeTruthy();
expect(within(bridge).queryByText('Browser question')).toBeNull();
});

it('does not relabel an unrelated inspected control as approval-expiry evidence', () => {
render(<SessionProvider><Governance params={new URLSearchParams('control=CTL-CONTEXT')}/></SessionProvider>);
const bridge = screen.getByRole('region', { name: 'How this source relates to your case' });
expect(within(bridge).getByRole('heading', { name: 'A different source is under inspection' })).toBeTruthy();
expect(within(bridge).getByText(/Purchase after approval expiry/)).toBeTruthy();
expect(within(bridge).queryByText(/recorded context substitution/)).toBeNull();
});

it('makes the recorded demand-stage context distinction explicit', () => {
render(<CaseEvidenceBridge activeCase={getCase('context')} kind="recorded" matches sourceLabel="Trial #18 · message_poisoning"/>);
expect(screen.getByText(/recorded context substitution occurs at demand_mock; the browser illustration evaluates a purchase request/)).toBeTruthy();
expect(screen.getByText(/Related stages are not the same execution/)).toBeTruthy();
});

it('does not turn a recorded budget violation into resolved objective arbitration', () => {
render(<CaseEvidenceBridge activeCase={getCase('conflict')} kind="recorded" matches sourceLabel="Trial #9 · goal_conflict"/>);
expect(screen.getByText(/recorded goal-conflict case measures a budget violation, not objective arbitration/)).toBeTruthy();
expect(screen.getByText(/Requesting review does not resolve the conflict/)).toBeTruthy();
});
});

describe('recorded comparisons foreground the actual divergent call', () => {
it('shows the purchase event first and retains every original paired call behind disclosure', () => {
const trial = experiment.trials.find(row => row.sequence === 15)!;
render(<EvidenceComparison trial={trial}/>);
const decisive = screen.getByRole('region', { name: 'Decisive recorded event' });
expect(within(decisive).getByText(/Paired step 10:/)).toBeTruthy();
expect(within(decisive).getByText('purchase → purchase_mock')).toBeTruthy();
const event = within(decisive).getByRole('table', { name: 'Decisive recorded B/C event' });
expect(within(event).getByText('ALLOW · executed')).toBeTruthy();
expect(within(event).getByText('DENY · not executed')).toBeTruthy();
expect(within(event).getAllByText('Input violations: expired_finance_approval')).toHaveLength(2);
expect(screen.getByText('Inspect all 10 paired recorded steps').closest('details')?.hasAttribute('open')).toBe(false);
fireEvent.click(screen.getByText('Inspect all 10 paired recorded steps'));
const full = screen.getByRole('table', { name: /Recorded B\/C calls/ });
expect(within(full).getAllByRole('row')).toHaveLength(11);
expect(within(full).getByText('demand_mock')).toBeTruthy();
expect(within(full).getByText('finance_mock')).toBeTruthy();
expect(within(full).getByText('purchase_mock')).toBeTruthy();
expect(screen.getByText(/B #14 and C #15 share the recorded case identity and digest/)).toBeTruthy();
});

it('does not invent a decisive difference for equal benign outcomes', () => {
render(<EvidenceComparison trial={experiment.trials.find(row => row.sequence === 3)!}/>);
expect(screen.queryByRole('region', { name: 'Decisive recorded event' })).toBeNull();
expect(screen.getByText('No difference in recorded decisions or execution flags between these paired calls.')).toBeTruthy();
});

it('does not pair records from another case identity or digest', () => {
const original = experiment.trials.find(row => row.sequence === 15)!;
render(<EvidenceComparison trial={{ ...original, case_digest: 'unmatched-digest' }}/>);
expect(screen.getByText('A complete recorded B/C comparison is unavailable.')).toBeTruthy();
expect(screen.queryByRole('region', { name: 'Decisive recorded event' })).toBeNull();
expect(screen.queryByText('ALLOW · executed')).toBeNull();
});
});


describe('recorded evidence can inform a retained human position', () => {
it('attaches the exact related event without replacing notes or changing the modeled result', () => {
const trial = experiment.trials.find(row => row.sequence === 15)!;
render(<SessionProvider><EvidenceSessionControls/><Assurance params={new URLSearchParams('trial=15')}/></SessionProvider>);
expect(screen.queryByRole('button', { name: 'Attach this recorded event to your reasoning' })).toBeNull();
fireEvent.click(screen.getByRole('button', { name: 'Test evaluate' }));
fireEvent.click(screen.getByRole('button', { name: 'Test existing position' }));
expect(screen.getByLabelText('Test ready').textContent).toBe('ready');
fireEvent.click(screen.getByRole('button', { name: 'Attach this recorded event to your reasoning' }));
const evidence = screen.getByLabelText('Test evidence').textContent!;
expect(evidence).toContain('Original evidence note.');
expect(evidence).toContain('Related recorded evidence, not this browser execution');
expect(evidence).toContain(`case ${trial.case_id}, digest ${trial.case_digest}`);
expect(evidence).toContain('B trial #14 / C trial #15');
expect(evidence).toContain('purchase → purchase_mock. B: allow, executed; C: deny, not executed');
expect(screen.getByLabelText('Test ready').textContent).toBe('draft');
expect(screen.getByLabelText('Test outcome').textContent).toBe('allow/deny');
fireEvent.click(screen.getByRole('button', { name: 'Attach this recorded event to your reasoning' }));
expect(screen.getByLabelText('Test evidence').textContent).toBe(evidence);
fireEvent.click(screen.getByRole('button', { name: 'Test edit age' }));
expect(screen.queryByRole('button', { name: 'Attach this recorded event to your reasoning' })).toBeNull();
expect(screen.getByLabelText('Test evidence').textContent).toBe(evidence);
});

it('does not offer an unrelated recorded event as evidence for the selected case', () => {
render(<SessionProvider><EvidenceSessionControls/><Assurance params={new URLSearchParams('trial=18')}/></SessionProvider>);
fireEvent.click(screen.getByRole('button', { name: 'Test evaluate' }));
expect(screen.getByRole('region', { name: 'Decisive recorded event' })).toBeTruthy();
expect(screen.getByRole('heading', { name: 'A different source is under inspection' })).toBeTruthy();
expect(screen.queryByRole('button', { name: 'Attach this recorded event to your reasoning' })).toBeNull();
expect(screen.getByLabelText('Test evidence').textContent).toBe('');
});
});
Loading
Loading