Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f2e6a517eb |
@@ -0,0 +1,44 @@
|
||||
# Preserve interview answer drafts through same-job refresh
|
||||
|
||||
18 November 2026. Branch `codex/interview-answer-refresh`, based on validated parent-lifetime checkpoint `336bc09987e5f3eb7b21c3a312284d9e45b3b9fc`. This resolves the ordinary-refresh draft-loss limitation recorded in that checkpoint, without changing job ownership, latest-read sequencing, APIs, locale catalogue or persistence contracts.
|
||||
|
||||
## Root cause and bounded change
|
||||
|
||||
`PrepRow` explicitly treats the answer as a local draft until saved, but `Shell` unmounted all children whenever its parent started a board GET. A sibling mark-ready, add, delete or explicit answer save therefore removed unrelated answer drafts. Failed refreshes also hid the loaded board with no GET retry. Separately, the row's shared write helper cleared its own draft after a readiness-only PATCH even though no answer was saved.
|
||||
|
||||
The shared local Shell now accepts an opt-in `keepContentOnLoading` flag. Only interview prep enables it, and only when its current job-keyed workspace has a successfully loaded board. That same condition retains content on a refresh error; read errors expose the existing GET-only retry. Initial loading/failed initial reads still have no editable board/default rows. Follow-up and AI Shell callers retain their existing defaults. Explicit answer saves clear that row's draft after successful persistence; readiness-only writes retain it.
|
||||
|
||||
Fresh successful GETs remain authoritative for row presence and server content. Surviving stable row IDs retain local drafts; rows absent from the refreshed board unmount normally. Explicit discard reveals the newest server answer. Changing job still unmounts all old private content/drafts via the existing keyed workspace. No global store, stale-content cache, string addition, implicit save or write retry was added.
|
||||
|
||||
## Test-first evidence
|
||||
|
||||
New deferred-promise tests initially failed on unchanged parent source: EN/NB sibling ready/add/delete/save refreshes, EN/NB refresh-error/retry preservation, and same-row readiness-only draft preservation. Delete fixtures were corrected to await modal exit; both corrected delete cases were then rerun against original `336bc099` production bytes and failed specifically because the editor disappeared during the board GET. Fixed production bytes were restored before final verification. Overlapping reruns are not added to test totals.
|
||||
|
||||
The final suite adds **13 cases**: eight sibling-action cases across EN/NB; two refresh-error/GET-retry cases; one readiness-only case; two job-change/failed-initial-read privacy controls. The inherited latest-read test now expects a previously loaded same-job board to remain mounted during refresh, while retaining its progress indicator. Initial/cross-job loading assertions remain unchanged. Native receipt: [jest-results.json](jest-results.json).
|
||||
|
||||
## Verification
|
||||
|
||||
From `job-tracker-ui`:
|
||||
|
||||
```powershell
|
||||
rtk proxy node node_modules/jest/bin/jest.js --runInBand --runTestsByPath src/interview-prep.test.tsx --cacheDirectory='../.test-cache' --json --outputFile='../docs/validation/interview-answer-refresh/jest-results.json'
|
||||
rtk proxy node node_modules/typescript/bin/tsc --noEmit --incremental false
|
||||
rtk proxy node node_modules/eslint/bin/eslint.js src/components/InterviewPrep.tsx src/interview-prep.test.tsx --max-warnings=0
|
||||
```
|
||||
|
||||
- Focused jsdom: **76/76 passed**, zero failed/skipped, no snapshots or React warnings; runner duration 28.558 seconds. This is 63 inherited plus 13 new cases, not a cumulative total of repeated runs.
|
||||
- Full UI TypeScript: passed, exit 0.
|
||||
- Scoped ESLint: passed, exit 0, zero warnings.
|
||||
- `rtk git diff --check`: passed.
|
||||
- Graph-first query used the existing parent worktree graph before source inspection. Its local graph artifacts were copied into this new worktree solely as an update seed. `rtk proxy graphify update .` ran AST-only here after source edits, with no API/model calls or shared graph mutation. Optional PDF/SQL extraction dependencies were absent; graph results provide structural orientation only. Generated graph and Jest cache remain local untracked artifacts.
|
||||
|
||||
Existing dependencies were accessed through the approved read-only junction to `next-security-patch/job-tracker-ui/node_modules`; no install, application build, browser or server ran.
|
||||
|
||||
Validated working-file SHA-256:
|
||||
|
||||
| File | SHA-256 |
|
||||
| --- | --- |
|
||||
| `job-tracker-ui/src/components/InterviewPrep.tsx` | `088cd555085bdecede0d61aa5b822505126ce5c66272f57030a532df50ff11cb` |
|
||||
| `job-tracker-ui/src/interview-prep.test.tsx` | `f02cfda979b20a76972765d96e47538b3574507a5b442c209086e663ce2e22bd` |
|
||||
|
||||
Browser/native/device, broader repository suites, hosted CI, backend/database, live AI/provider and production checks were not run. Root owns source-bound browser qualification, publication/integration and central tracking. Pending explicit writes still complete against their original job; this patch neither cancels nor redirects them. A deleted or recategorised row can legitimately unmount on authoritative refresh; preserving arbitrary removed content is outside this change.
|
||||
File diff suppressed because one or more lines are too long
@@ -25,7 +25,7 @@ import ViewStateNotice from "./ViewStateNotice";
|
||||
// become prep items after an explicit accept action.
|
||||
// docs/architecture/overview.md.
|
||||
|
||||
function Shell({ title, subtitle, loading, error, children, onRetry, keepContentOnError = false }: {
|
||||
function Shell({ title, subtitle, loading, error, children, onRetry, keepContentOnError = false, keepContentOnLoading = false }: {
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
loading: boolean;
|
||||
@@ -33,11 +33,12 @@ function Shell({ title, subtitle, loading, error, children, onRetry, keepContent
|
||||
children: React.ReactNode;
|
||||
onRetry?: () => void | Promise<void>;
|
||||
keepContentOnError?: boolean;
|
||||
keepContentOnLoading?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<PageSection surface title={title} description={subtitle} level="h3">
|
||||
<ViewStateNotice title={title} loading={loading} error={error ? { kind: "error", message: error, retryable: Boolean(onRetry) } : null} onRetry={onRetry} compact />
|
||||
{!loading && (!error || keepContentOnError) && children}
|
||||
{(!loading || keepContentOnLoading) && (!error || keepContentOnError) && children}
|
||||
</PageSection>
|
||||
);
|
||||
}
|
||||
@@ -118,7 +119,9 @@ function InterviewPrepWorkspace({ jobId }: { jobId: number }) {
|
||||
subtitle={t("interviewPrepSubtitle")}
|
||||
loading={loading}
|
||||
error={error ? getApiErrorMessage(error.cause, t(error.fallback)) : null}
|
||||
keepContentOnError={error?.fallback === "interviewPrepAnswerSaveFailed" || error?.fallback === "interviewPrepUpdateFailed"}
|
||||
onRetry={error?.fallback === "interviewPrepLoadFailed" ? load : undefined}
|
||||
keepContentOnLoading={board !== null}
|
||||
keepContentOnError={board !== null}
|
||||
>
|
||||
<Stack spacing={2}>
|
||||
{board && !board.isInterviewStage && (
|
||||
@@ -355,11 +358,11 @@ function PrepRow({ jobId, item, busy, onChanged, onError }: {
|
||||
const content = draft ?? item.content ?? "";
|
||||
const dirty = draft !== null && draft !== (item.content ?? "");
|
||||
|
||||
const run = async (fn: () => Promise<unknown>) => {
|
||||
const run = async (fn: () => Promise<unknown>, savesAnswer = false) => {
|
||||
setSaving(true);
|
||||
try {
|
||||
await fn();
|
||||
setDraft(null);
|
||||
if (savesAnswer) setDraft(null);
|
||||
onChanged();
|
||||
} catch (err) {
|
||||
onError({ cause: err, fallback: "interviewPrepAnswerSaveFailed" });
|
||||
@@ -404,7 +407,7 @@ function PrepRow({ jobId, item, busy, onChanged, onError }: {
|
||||
size="small"
|
||||
variant="contained"
|
||||
disabled={saving}
|
||||
onClick={() => run(() => interviewPrepApi.update(jobId, item.id, { content }))}
|
||||
onClick={() => run(() => interviewPrepApi.update(jobId, item.id, { content }), true)}
|
||||
>
|
||||
{t("interviewPrepSaveAnswer")}
|
||||
</Button>
|
||||
|
||||
@@ -70,6 +70,103 @@ function deferredRead() {
|
||||
return { promise, resolve, reject };
|
||||
}
|
||||
|
||||
test.each((['en', 'nb'] as const).flatMap(language => (['ready', 'add', 'delete', 'save'] as const).map(operation => [language, operation] as const)))('same-application %s %s refresh keeps a sibling answer mounted until explicit discard', async (language, operation) => {
|
||||
localStorage.setItem('uiLanguage', language);
|
||||
const copy = translations[language];
|
||||
mockedApi.get.mockReset(); routeGet();
|
||||
const read = mockedApi.get.getMockImplementation()!;
|
||||
const refresh = deferredRead(); let reads = 0;
|
||||
mockedApi.get.mockImplementation((url: string) => url.endsWith('/interview-prep') && ++reads > 1 ? refresh.promise : read(url));
|
||||
mockedApi.patch.mockReset().mockResolvedValue({ data: board.groups[0].items[0] } as any);
|
||||
mockedApi.post.mockReset().mockResolvedValue({ data: board.groups[0].items[0] } as any);
|
||||
mockedApi.delete.mockReset().mockResolvedValue({ data: null } as any);
|
||||
render(<ApplicationInterviewPrep jobId={7} />);
|
||||
const name = copy.interviewPrepAnswerFor.replace('{title}', 'Tell me about a conflict');
|
||||
const answer = await screen.findByRole('textbox', { name });
|
||||
fireEvent.change(answer, { target: { value: 'My unsaved sibling answer Øresund' } });
|
||||
if (operation === 'ready') fireEvent.click(screen.getByRole('checkbox', { name: copy.interviewPrepReadyLabel.replace('{title}', 'Funding history') }));
|
||||
if (operation === 'add') {
|
||||
fireEvent.change(screen.getByLabelText(copy.interviewPrepAddLabel), { target: { value: 'New prep item' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: copy.interviewPrepAdd }));
|
||||
}
|
||||
if (operation === 'delete') {
|
||||
fireEvent.click(screen.getByRole('button', { name: copy.interviewPrepDeleteLabel.replace('{title}', 'Funding history') }));
|
||||
fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: copy.interviewPrepDelete }));
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
||||
}
|
||||
if (operation === 'save') {
|
||||
fireEvent.change(screen.getByRole('textbox', { name: copy.interviewPrepAnswerFor.replace('{title}', 'Funding history') }), { target: { value: 'Saved first answer' } });
|
||||
fireEvent.click(screen.getAllByRole('button', { name: copy.interviewPrepSaveAnswer })[0]);
|
||||
}
|
||||
await waitFor(() => expect(reads).toBe(2));
|
||||
expect(screen.getByRole('textbox', { name })).toBe(answer);
|
||||
expect(answer).toHaveValue('My unsaved sibling answer Øresund');
|
||||
const updatedGroup = { ...board.groups[1], items: [{ ...board.groups[1].items[0], content: 'Current server answer' }] };
|
||||
const updated = { ...board, groups: operation === 'delete' ? [updatedGroup] : [board.groups[0], updatedGroup] };
|
||||
await act(async () => refresh.resolve({ data: updated }));
|
||||
expect(screen.getByRole('textbox', { name })).toBe(answer);
|
||||
expect(answer).toHaveValue('My unsaved sibling answer Øresund');
|
||||
expect(mockedApi.patch).not.toHaveBeenCalledWith('/jobapplications/7/interview-prep/2', expect.anything());
|
||||
fireEvent.click(screen.getByRole('button', { name: copy.interviewPrepDiscard }));
|
||||
expect(answer).toHaveValue('Current server answer');
|
||||
});
|
||||
|
||||
test.each(['en', 'nb'] as const)('same-application %s refresh failure and GET-only retry preserve an unsaved answer', async language => {
|
||||
localStorage.setItem('uiLanguage', language);
|
||||
const copy = translations[language];
|
||||
mockedApi.get.mockReset(); routeGet();
|
||||
const read = mockedApi.get.getMockImplementation()!;
|
||||
let reads = 0;
|
||||
mockedApi.get.mockImplementation((url: string) => url.endsWith('/interview-prep') && ++reads === 2 ? Promise.reject(new Error('Refresh failed')) : read(url));
|
||||
mockedApi.patch.mockReset().mockResolvedValue({ data: board.groups[0].items[0] } as any);
|
||||
render(<ApplicationInterviewPrep jobId={7} />);
|
||||
const name = copy.interviewPrepAnswerFor.replace('{title}', 'Tell me about a conflict');
|
||||
const answer = await screen.findByRole('textbox', { name });
|
||||
fireEvent.change(answer, { target: { value: 'Keep across failed refresh' } });
|
||||
fireEvent.click(screen.getByRole('checkbox', { name: copy.interviewPrepReadyLabel.replace('{title}', 'Funding history') }));
|
||||
expect(await screen.findByText(copy.interviewPrepLoadFailed)).toBeVisible();
|
||||
expect(screen.getByRole('textbox', { name })).toBe(answer);
|
||||
expect(answer).toHaveValue('Keep across failed refresh');
|
||||
fireEvent.click(screen.getByRole('button', { name: copy.retry }));
|
||||
await waitFor(() => expect(screen.queryByText(copy.interviewPrepLoadFailed)).not.toBeInTheDocument());
|
||||
expect(reads).toBe(3); expect(mockedApi.patch).toHaveBeenCalledTimes(1);
|
||||
expect(screen.getByRole('textbox', { name })).toBe(answer);
|
||||
expect(answer).toHaveValue('Keep across failed refresh');
|
||||
});
|
||||
|
||||
test('marking readiness preserves that row answer draft because the write contains no answer', async () => {
|
||||
mockedApi.get.mockReset(); routeGet();
|
||||
mockedApi.patch.mockReset().mockResolvedValue({ data: board.groups[1].items[0] } as any);
|
||||
render(<ApplicationInterviewPrep jobId={7} />);
|
||||
const name = translations.en.interviewPrepAnswerFor.replace('{title}', 'Tell me about a conflict');
|
||||
fireEvent.change(await screen.findByRole('textbox', { name }), { target: { value: 'Not saved by readiness' } });
|
||||
fireEvent.click(screen.getByRole('checkbox', { name: 'Ready: Tell me about a conflict' }));
|
||||
await waitFor(() => expect(mockedApi.get.mock.calls.filter(([url]) => String(url).endsWith('/interview-prep'))).toHaveLength(2));
|
||||
expect(screen.getByRole('textbox', { name })).toHaveValue('Not saved by readiness');
|
||||
expect(mockedApi.patch.mock.calls).toEqual([['/jobapplications/7/interview-prep/2', { isPrepared: true }]]);
|
||||
});
|
||||
|
||||
test.each(['en', 'nb'] as const)('changing job clears %s answer drafts and a failed initial read offers only a GET retry', async language => {
|
||||
localStorage.setItem('uiLanguage', language);
|
||||
const copy = translations[language];
|
||||
mockedApi.get.mockReset(); routeGet();
|
||||
const read = mockedApi.get.getMockImplementation()!;
|
||||
const current = deferredRead(); let currentReads = 0;
|
||||
mockedApi.get.mockImplementation((url: string) => url === '/jobapplications/8/interview-prep' && ++currentReads === 1 ? current.promise : read(url));
|
||||
const name = copy.interviewPrepAnswerFor.replace('{title}', 'Tell me about a conflict');
|
||||
const view = render(<ApplicationInterviewPrep jobId={7} />);
|
||||
fireEvent.change(await screen.findByRole('textbox', { name }), { target: { value: 'Private application seven answer' } });
|
||||
await act(async () => view.rerender(<I18nProvider><ConfirmProvider><ApplicationInterviewPrep jobId={8} /></ConfirmProvider></I18nProvider>));
|
||||
expect(screen.queryByRole('textbox', { name })).not.toBeInTheDocument();
|
||||
await act(async () => current.reject(new Error('New application initial read failed')));
|
||||
expect(screen.getByText(copy.interviewPrepLoadFailed)).toBeVisible();
|
||||
expect(screen.queryByLabelText(copy.interviewPrepAddLabel)).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: copy.retry }));
|
||||
expect(await screen.findByRole('textbox', { name })).toHaveValue('');
|
||||
expect(currentReads).toBe(2);
|
||||
expect(mockedApi.patch).not.toHaveBeenCalled(); expect(mockedApi.post).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test.each(['success', 'failure', 'pending-newer'] as const)('a newer preparation refresh wins against an older %s completion', async completion => {
|
||||
mockedApi.get.mockReset(); routeGet();
|
||||
const read = mockedApi.get.getMockImplementation()!;
|
||||
@@ -88,7 +185,7 @@ test.each(['success', 'failure', 'pending-newer'] as const)('a newer preparation
|
||||
await act(async () => older.resolve({ data: board }));
|
||||
const region = within(screen.getByRole('region', { name: translations.en.interviewPrepTitle }));
|
||||
expect(region.getByRole('progressbar', { name: translations.en.loading })).toBeVisible();
|
||||
expect(region.queryByLabelText(translations.en.interviewPrepAddLabel)).not.toBeInTheDocument();
|
||||
expect(region.getByLabelText(translations.en.interviewPrepAddLabel)).toBeVisible();
|
||||
}
|
||||
const currentBoard = { ...board, groups: [{ ...board.groups[0], items: [{ ...board.groups[0].items[0], title: 'Newest board' }] }] };
|
||||
await act(async () => newer.resolve({ data: currentBoard }));
|
||||
|
||||
Reference in New Issue
Block a user