From ee5aaf4ca515b90c1c7504875614cc64d73377aa Mon Sep 17 00:00:00 2001 From: ALFRED-LUCIFER <95878204+ALFRED-LUCIFER@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:14:17 +0100 Subject: [PATCH 01/18] AIV-P2-006: submit the scorecard, apply the previewed change and log it submitScorecard completes the interview, keeps the draft (rebuilt on the questions the page shows) as the submitted scorecard with its recommendation, writes InterviewCompleted.v1, records each rated note as interview_note evidence ("Interviewer's scorecard") and applies the previewed ratings through the assessment's audited applyScoreChange, whose audit entries are the last statements, in one transaction. A competency not assessed in this round has no rating and stays a gap. A second submit or a double click is "Already submitted"; a failure rolls everything back and the saved draft stays. The scorecard page saves, then submits with the preview the person saw, says the outcome and links to the ranking; a rating needs a note. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- apps/backend/worker/src/main.ts | 5 +- .../[interviewId]/ScorecardClient.test.tsx | 111 ++++- .../[interviewId]/ScorecardClient.tsx | 13 +- .../scorecard/components/ScoreEffect.tsx | 1 - .../scorecard/components/Scorecard.tsx | 46 +- .../scorecard/domain/scorecard.test.ts | 4 +- .../features/scorecard/domain/scorecard.ts | 43 +- .../hooks/useScoreEffectController.ts | 8 +- .../scorecard/hooks/useScorecardController.ts | 29 +- .../scorecard/services/loadScorecard.ts | 2 + .../scorecard/services/previewEffect.test.ts | 3 +- .../scorecard/services/previewEffect.ts | 12 +- .../scorecard/services/submitScorecard.ts | 46 ++ apps/web/src/server/interviews.ts | 12 + modules/assessment/src/composition.ts | 1 - modules/assessment/src/domain/assess.ts | 2 +- modules/audit/README.md | 2 +- modules/evidence/src/application/evidence.ts | 13 +- modules/evidence/src/contracts/index.ts | 4 +- modules/interviews/README.md | 10 +- .../interviews/src/application/interviews.ts | 5 +- .../interviews/src/application/submit.test.ts | 233 +++++++++ modules/interviews/src/application/submit.ts | 131 ++++++ modules/interviews/src/composition.ts | 32 +- modules/interviews/src/contracts/index.ts | 19 + .../interviews/src/domain/interview.test.ts | 3 + modules/interviews/src/domain/interview.ts | 9 +- .../interviews/src/domain/scorecard.test.ts | 49 ++ modules/interviews/src/domain/scorecard.ts | 34 ++ packages/i18n/messages/en.json | 15 +- tests/e2e/src/scorecard.spec.ts | 19 +- tests/e2e/src/submit-scorecard.spec.ts | 205 ++++++++ .../integration/src/submit-scorecard.test.ts | 444 ++++++++++++++++++ 34 files changed, 1471 insertions(+), 96 deletions(-) create mode 100644 apps/web/src/features/scorecard/services/submitScorecard.ts create mode 100644 modules/interviews/src/application/submit.test.ts create mode 100644 modules/interviews/src/application/submit.ts create mode 100644 tests/e2e/src/submit-scorecard.spec.ts create mode 100644 tests/integration/src/submit-scorecard.test.ts diff --git a/README.md b/README.md index 2cb8b4fe..dd38033a 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Layout and rules: [ADR-002](docs/adr/ADR-002-repository-layout.md). **No empty s | `apps/web/src/features/members/` | Workspace members at `/app/settings/members` (admins): members and invitations with their jobs, invite form with the job picker, role, jobs and removal; the invitation link page at `/invite` | Built (AIV-P1-003) | | `apps/web/src/features/shell/` | Recruiter app shell: sidebar, top bar, synthetic data badge, theme cookie; `navigation.ts` maps every `/app` route | Built (AIV-P0-020) | | `apps/web/src/features/interviews/` | Interviews list at `/app/interviews`: ongoing and completed tabs, each interview's round, interviewer, time, status and competencies to investigate; the sidebar count of ongoing interviews | Built (AIV-P2-002) | -| `apps/web/src/features/scorecard/` | Interview scorecard at `/app/interviews/[interviewId]` (Interview artboard): each competency to investigate with its evidence and stored suggested questions, a rating and a note, "Not asked" and "Not answered" per question, a recommendation, and a draft that saves itself; submitting is AIV-P2-006 | Built (AIV-P2-004) | +| `apps/web/src/features/scorecard/` | Interview scorecard at `/app/interviews/[interviewId]` (Interview artboard): each competency to investigate with its evidence and stored suggested questions, a rating and a note, "Not asked" and "Not answered" per question, a recommendation, a self-saving draft, and the submit (AIV-P2-006) | Built (AIV-P2-004, AIV-P2-006) | | `apps/web/src/features/interview-summary/` | "Meeting summary" on the interview page: paste a summary, the worker proposes evidence changes, a preview-confirm card shows each change with its quoted excerpt and the backed score before and after, and only what a person confirms is applied, with their reason | Built (AIV-P1-115) | | `apps/web/src/features/marketing-home/` | Website at `/` (Landing artboard): header, hero with the animated evidence card, how it works, role families from the job-type catalogue, trust principles, pilot promise and footer (`motion`, off under reduced motion) | Built (AIV-P5-001 to 004) | | `apps/web/src/test/` | Unit-test fixtures shared by features: catalogue version 1, read from its committed snapshot | Built (AIV-P2-044) | diff --git a/apps/backend/worker/src/main.ts b/apps/backend/worker/src/main.ts index b6ddd5ad..a82ebfb9 100644 --- a/apps/backend/worker/src/main.ts +++ b/apps/backend/worker/src/main.ts @@ -149,8 +149,9 @@ const QUEUES: Record = { // 14-day TTL like PersonCreated.v1 above; that ticket's consumer replaces this note. [JobPublishedV1.type]: 'candidates', [JobUnpublishedV1.type]: 'candidates', - // shortcut: nothing consumes InterviewScheduled.v1 or InterviewCompleted.v1 (AIV-P2-001) yet, and seeded interviews write - // them, so they are parked the same way rather than retried for ever unmapped; the scorecard submit (AIV-P2-006) maps them. + // shortcut: nothing consumes InterviewScheduled.v1 or InterviewCompleted.v1 (AIV-P2-001; the scorecard submit writes + // the second, AIV-P2-006, which applies its change in its own transaction) yet, and seeded interviews write them, so + // they are parked the same way rather than retried for ever unmapped; their first consumer maps them. [InterviewScheduledV1.type]: 'candidates', [InterviewCompletedV1.type]: 'candidates', [EmailQueuedV1.type]: NOTIFICATIONS_QUEUE, diff --git a/apps/web/src/app/(recruiter)/app/interviews/[interviewId]/ScorecardClient.test.tsx b/apps/web/src/app/(recruiter)/app/interviews/[interviewId]/ScorecardClient.test.tsx index a12840e6..dbafbbba 100644 --- a/apps/web/src/app/(recruiter)/app/interviews/[interviewId]/ScorecardClient.test.tsx +++ b/apps/web/src/app/(recruiter)/app/interviews/[interviewId]/ScorecardClient.test.tsx @@ -9,10 +9,11 @@ import { ScorecardClient } from './ScorecardClient.tsx'; // AIV-P2-004: the scorecard form with its controller, the server action and the router faked. Daniel Novak's Round 1 // on Senior AI Engineer, as the Interview artboard draws it (synthetic cast, personas.md). -const fake = vi.hoisted(() => ({ save: vi.fn(), push: vi.fn(), preview: vi.fn() })); +const fake = vi.hoisted(() => ({ save: vi.fn(), push: vi.fn(), preview: vi.fn(), submit: vi.fn(), refresh: vi.fn() })); vi.mock('@/features/scorecard/services/saveDraft.ts', () => ({ saveScorecardDraft: fake.save })); +vi.mock('@/features/scorecard/services/submitScorecard.ts', () => ({ submitScorecard: fake.submit })); vi.mock('@/features/scorecard/services/previewEffect.ts', () => ({ previewScorecardRatings: fake.preview })); -vi.mock('next/navigation', () => ({ useRouter: () => ({ push: fake.push, refresh: vi.fn() }) })); +vi.mock('next/navigation', () => ({ useRouter: () => ({ push: fake.push, refresh: fake.refresh }) })); vi.mock('@/features/interview-summary/services/summaryActions.ts', () => ({})); vi.mock('next/link', () => ({ default: ({ href, children, ...rest }: { href: string; children: React.ReactNode }) => ( @@ -93,6 +94,8 @@ const data = (over: Partial = {}): ScorecardData => ({ today: true, interviewer: null, profileHref: '/app/candidates/p-daniel?job=j-ai', + rankingHref: '/app/jobs/j-ai/candidates', + submitted: false, assessed: { at: '2026-11-12T08:00:00.000Z', backedScore: 55 }, competencies, canEdit: true, @@ -285,27 +288,27 @@ describe('Scenario: Submit needs every competency rated or marked not tested', ( const user = userEvent.setup(); show(); await user.click(within(rating('Retrieval and evaluation')).getAllByRole('radio')[2] as HTMLElement); + // "Submit scorecard" waits for the preview of the ratings (AIV-P2-006). + await within(effectCard()).findByText(UNAVAILABLE); expect(screen.queryByText(BLOCKED)).toBeNull(); await user.click(screen.getByRole('button', { name: 'Submit scorecard' })); expect(within(card('Cost and reliability')).getByRole('alert').textContent).toBe(BLOCKED); - expect(within(card('Retrieval and evaluation')).queryByRole('alert')).toBeNull(); + // Rated, so not blocked; its missing note is said on the note (AIV-P2-006). + expect(within(card('Retrieval and evaluation')).queryByText(BLOCKED)).toBeNull(); expect(rating('Cost and reliability').getAttribute('aria-invalid')).toBe('true'); expect(screen.queryByText(/^Your scorecard is complete/)).toBeNull(); + expect(fake.submit).not.toHaveBeenCalled(); for (const button of within(card('Cost and reliability')).getAllByRole('button', { name: 'Not asked' })) await user.click(button); expect(screen.queryByText(BLOCKED)).toBeNull(); - await user.click(screen.getByRole('button', { name: 'Submit scorecard' })); - // It says plainly that nothing was submitted or changed (submitting is AIV-P2-006). - expect( - screen.getByText( - 'Your scorecard is complete and saved as a draft. It has not been submitted: the assessment, the stage and the ranking are unchanged.', - ), - ).toBeTruthy(); - expect(fake.push).not.toHaveBeenCalled(); }); }); +// AIV-P2-006: submitting, with the server action faked; the transaction itself is tests/integration. +const NO_NOTE = 'Write what you saw or heard before submitting: it is the reason logged with your rating'; +const UPDATED = "Scorecard submitted and logged. Daniel Novak's assessment has been updated."; + describe('Scenario: Recommendation is not a decision', () => { it('a recommendation is one field of the draft, beside the line that says who decides', async () => { const user = userEvent.setup(); @@ -373,6 +376,7 @@ const effectCard = () => const wait = (ms: number) => act(() => new Promise((resolve) => setTimeout(resolve, ms))); const state = (strength: string | null, provenLevel = 0) => ({ strength, provenLevel }); const answer = (from: ReturnType, to: ReturnType, score: [number, number]) => ({ + previewId: `p-${String(to.strength)}`, backedScore: { from: score[0], to: score[1] }, changes: from === to ? [] : [{ competencyId: RETRIEVAL, from, to }], }); @@ -505,3 +509,88 @@ describe('a member who may not change the scorecard (AIV-P2-005)', () => { expect(fake.preview).not.toHaveBeenCalled(); }); }); + +/** Retrieval rated Clearly shown (previewed), Cost and reliability not tested. */ +async function ready(user: ReturnType, note = NOTE) { + fake.preview.mockResolvedValue(RATED['Clearly shown']); + show(); + await user.click(within(rating('Retrieval and evaluation')).getByRole('radio', { name: 'Clearly shown' })); + if (note) await user.type(within(card('Retrieval and evaluation')).getByLabelText('What you saw or heard'), note); + for (const button of within(card('Cost and reliability')).getAllByRole('button', { name: 'Not asked' })) + await user.click(button); + await within(effectCard()).findByText('Backed score 55 to 67.'); +} + +describe('Scenario: Submitting applies the change', () => { + it('saves the draft, submits it with the preview shown, says so with "See the ranking", and re-reads the page', async () => { + fake.submit.mockResolvedValue('updated'); + const user = userEvent.setup(); + await ready(user); + await user.click(screen.getByRole('button', { name: 'Submit scorecard' })); + expect(await screen.findByText(UPDATED)).toBeTruthy(); + expect(fake.save).toHaveBeenCalled(); + // Only the interview and the preview the person saw: the ratings are the saved draft's, and no stage is sent. + expect(fake.submit).toHaveBeenCalledWith({ interviewId: data().interviewId, previewId: 'p-medium' }); + expect(screen.getByRole('link', { name: 'See the ranking' }).getAttribute('href')).toBe( + '/app/jobs/j-ai/candidates', + ); + expect(fake.refresh).toHaveBeenCalled(); + }); + + it('a rating with no note blocks the submit and says why, on that note', async () => { + const user = userEvent.setup(); + await ready(user, ''); + await user.click(screen.getByRole('button', { name: 'Submit scorecard' })); + const note = within(card('Retrieval and evaluation')).getByLabelText('What you saw or heard'); + expect(within(card('Retrieval and evaluation')).getByRole('alert').textContent).toBe(NO_NOTE); + expect(note.getAttribute('aria-invalid')).toBe('true'); + expect(fake.submit).not.toHaveBeenCalled(); + }); + + it('with every competency not tested there is no preview to send', async () => { + fake.submit.mockResolvedValue('unchanged'); + const user = userEvent.setup(); + show(); + for (const name of ['Retrieval and evaluation', 'Cost and reliability']) + for (const button of within(card(name)).getAllByRole('button', { name: 'Not asked' })) await user.click(button); + await user.click(screen.getByRole('button', { name: 'Submit scorecard' })); + expect( + await screen.findByText("Scorecard submitted and logged. Daniel Novak's assessment is unchanged."), + ).toBeTruthy(); + expect(fake.submit).toHaveBeenCalledWith({ interviewId: data().interviewId, previewId: null }); + }); +}); + +describe('Scenario: Double submit, and a submit that fails', () => { + it.each([ + ['already', 'Already submitted'], + ['failed', 'Not submitted. Your ratings are saved; try again.'], + ['changed', 'The assessment changed since this preview. Check the new preview, then submit again.'], + ] as const)('"%s" says "%s"', async (outcome, text) => { + fake.submit.mockResolvedValue(outcome); + const user = userEvent.setup(); + await ready(user); + await user.click(screen.getByRole('button', { name: 'Submit scorecard' })); + expect(await screen.findByText(text)).toBeTruthy(); + expect(screen.queryByRole('link', { name: 'See the ranking' })).toBeNull(); + }); + + it('a submit the network drops says "Not submitted" and keeps the form', async () => { + fake.submit.mockRejectedValue(new Error('offline')); + const user = userEvent.setup(); + await ready(user); + await user.click(screen.getByRole('button', { name: 'Submit scorecard' })); + expect(await screen.findByText('Not submitted. Your ratings are saved; try again.')).toBeTruthy(); + expect(fake.refresh).not.toHaveBeenCalled(); + expect(within(rating('Retrieval and evaluation')).getByRole('radio', { name: 'Clearly shown' })).toBeTruthy(); + }); +}); + +describe('a submitted scorecard', () => { + it('reads as submitted, with no way to change it and a way to the ranking', () => { + show({ canEdit: false, submitted: true }); + expect(screen.getByText('This scorecard is submitted and logged. It can no longer change.')).toBeTruthy(); + expect(screen.queryByRole('button', { name: 'Submit scorecard' })).toBeNull(); + expect(screen.getByRole('link', { name: 'See the ranking' })).toBeTruthy(); + }); +}); diff --git a/apps/web/src/app/(recruiter)/app/interviews/[interviewId]/ScorecardClient.tsx b/apps/web/src/app/(recruiter)/app/interviews/[interviewId]/ScorecardClient.tsx index b25b37a2..118a6b41 100644 --- a/apps/web/src/app/(recruiter)/app/interviews/[interviewId]/ScorecardClient.tsx +++ b/apps/web/src/app/(recruiter)/app/interviews/[interviewId]/ScorecardClient.tsx @@ -10,8 +10,8 @@ import { useScorecardController } from '@/features/scorecard/hooks/useScorecardC import { MeetingSummaryClient } from './MeetingSummaryClient.tsx'; /** - * The scorecard form with its draft (AIV-P2-004), the live preview of its ratings for whoever fills it in (AIV-P2-005) - * and, for the people who may act on it, the meeting-summary panel under the competencies (AIV-P1-115). While the + * The scorecard form with its draft (AIV-P2-004), the live preview of its ratings for whoever fills it in (AIV-P2-005), + * which "Submit scorecard" applies (AIV-P2-006), and, for the people who may act on it, the meeting-summary panel under the competencies (AIV-P1-115). While the * panel's preview card is open, its "Apply" is the view's one primary button. */ export function ScorecardClient({ data, summary = null }: { data: ScorecardData; summary?: SummaryPanel | null }) { @@ -21,7 +21,14 @@ export function ScorecardClient({ data, summary = null }: { data: ScorecardData; const [first] = data.competencies; return ( void scorecard.onSubmit(effect.status === 'ready' ? effect.previewId : null), + }} quietSubmit={proposalsOpen} effect={data.canEdit && first && } > diff --git a/apps/web/src/features/scorecard/components/ScoreEffect.tsx b/apps/web/src/features/scorecard/components/ScoreEffect.tsx index 3ffa58de..2d6ad54f 100644 --- a/apps/web/src/features/scorecard/components/ScoreEffect.tsx +++ b/apps/web/src/features/scorecard/components/ScoreEffect.tsx @@ -23,7 +23,6 @@ import type { EffectLine, EffectState } from '../domain/scorecard.ts'; // - the card is not a named region: the meeting summary's preview card has the same title, and two landmarks of one // name fail axe's landmark-unique rule; // - it shows only to someone who may fill in the scorecard; a read-only viewer submits nothing. -// shortcut: panel copy assumes submit applies (AIV-P2-006, #120); true once #120 merges. export function ScoreEffect({ state, first }: { state: EffectState; first: string }) { const t = useTranslations(); diff --git a/apps/web/src/features/scorecard/components/Scorecard.tsx b/apps/web/src/features/scorecard/components/Scorecard.tsx index b81bc517..3eba9afa 100644 --- a/apps/web/src/features/scorecard/components/Scorecard.tsx +++ b/apps/web/src/features/scorecard/components/Scorecard.tsx @@ -26,7 +26,7 @@ import { import type { Route } from 'next'; import Link from 'next/link'; import type { ReactNode } from 'react'; -import type { ScorecardCompetency, ScorecardData } from '../domain/scorecard.ts'; +import type { ScorecardCompetency, ScorecardData, SubmitOutcome } from '../domain/scorecard.ts'; // AIV-P2-004: the Interview artboard (docs/01-design/artboards/Interview.dc.html): breadcrumb, title, subtitle and "Save // and close"; the rounds; one card per competency to investigate with its evidence, questions, rating and note; and @@ -51,10 +51,12 @@ import type { ScorecardCompetency, ScorecardData } from '../domain/scorecard.ts' // its name (AGENTS.md 1.9); // - "Effect on the assessment" is a slot (`effect`) at the top of the right column: the live preview (AIV-P2-005) has // its own controller and component, `ScoreEffect`; -// - "Submit scorecard" checks that every competency is rated or marked as not tested, says which is not, and saves the -// draft. It applies nothing, and a line under it and its result say so: submitting, the score change, the -// `interview_note` evidence and "Scorecard submitted and logged" are AIV-P2-006 (#120); -// - no "Audit trail" card: a draft writes no audit entry; the trail comes with the submit (AIV-P2-006); +// - "Submit scorecard" (AIV-P2-006) first checks that every competency is rated or marked as not tested and that each +// rating has a note (the reason logged with it, and the words its evidence cites), saying which is not, and is +// disabled while the preview of the current ratings is on its way, so what is applied is what the person saw. Under +// "Scorecard submitted and logged" its name is the candidate's full name, not the first name; +// - no "Audit trail" card: the submit's entries are the audit log's (`score.changed`, one per rating), and reading them +// back onto this page and the evidence profile ("Interview history and score changes") is AIV-P1-046 (#110); // - the draft saves itself a moment after each change, with "Saving your draft…" and "Draft saved…" beside "Save and // close" (the ticket), which is a button that saves and then opens Interviews, not a plain link; // - a member who is not the interviewer or an admin, and anyone once the interview is completed or cancelled, reads the @@ -74,7 +76,10 @@ export type ScorecardHandlers = { draft: ScorecardDraft; saving: 'idle' | 'saving' | 'saved' | 'failed'; blocked: string[]; - complete: boolean; + noNote: string[]; + outcome: SubmitOutcome | 'submitting' | null; + /** The preview of the ratings now is on its way: submitting waits for it. */ + previewPending: boolean; onRate: (competencyId: string, rating: Rating) => void; onNote: (competencyId: string, note: string) => void; onMark: (competencyId: string, index: number, mark: Mark) => void; @@ -175,7 +180,11 @@ export function Scorecard({ )} - {!view.canEdit &&

{t('scorecard.readOnly')}

} + {!view.canEdit && ( +

+ {t(view.submitted ? 'scorecard.submittedReadOnly' : 'scorecard.readOnly')} +

+ )}
@@ -208,16 +217,27 @@ export function Scorecard({

{t('scorecard.submitHelp')}

- {view.complete ? t('scorecard.complete') : ''} )} + {/* Stays mounted, outside the editable state the submit ends, so its result is announced. */} + + {view.outcome && t(`scorecard.outcome.${view.outcome}`, { name })} + + {(view.submitted || view.outcome === 'updated' || view.outcome === 'unchanged') && ( +
+ {/* rankingHref builds the path from an opaque id, which typed routes cannot check. */} + + {t('scorecard.seeRanking')} + +
+ )}
@@ -279,6 +299,7 @@ function Competency({ competency, view }: { competency: ScorecardCompetency; vie if (!draft) return null; const untested = notAssessed(draft); const blocked = view.blocked.includes(id); + const noNote = view.noNote.includes(id); return (
@@ -459,6 +480,8 @@ function Competency({ competency, view }: { competency: ScorecardCompetency; vie