diff --git a/docs/validation/interview-answer-refresh/README.md b/docs/validation/interview-answer-refresh/README.md new file mode 100644 index 00000000..977ca6a1 --- /dev/null +++ b/docs/validation/interview-answer-refresh/README.md @@ -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. diff --git a/docs/validation/interview-answer-refresh/jest-results.json b/docs/validation/interview-answer-refresh/jest-results.json new file mode 100644 index 00000000..f9f5e32b --- /dev/null +++ b/docs/validation/interview-answer-refresh/jest-results.json @@ -0,0 +1 @@ +{"numFailedTestSuites":0,"numFailedTests":0,"numPassedTestSuites":1,"numPassedTests":76,"numPendingTestSuites":0,"numPendingTests":0,"numRuntimeErrorTestSuites":0,"numTodoTests":0,"numTotalTestSuites":1,"numTotalTests":76,"openHandles":[],"snapshot":{"added":0,"didUpdate":false,"failure":false,"filesAdded":0,"filesRemoved":0,"filesRemovedList":[],"filesUnmatched":0,"filesUpdated":0,"matched":0,"total":0,"unchecked":0,"uncheckedKeysByFile":[],"unmatched":0,"updated":0},"startTime":1794959434697,"success":true,"testResults":[{"assertionResults":[{"ancestorTitles":[],"duration":619,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"same-application en ready refresh keeps a sibling answer mounted until explicit discard","invocations":1,"location":null,"numPassingAsserts":7,"retryReasons":[],"startAt":1794959438229,"status":"passed","title":"same-application en ready refresh keeps a sibling answer mounted until explicit discard"},{"ancestorTitles":[],"duration":665,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"same-application en add refresh keeps a sibling answer mounted until explicit discard","invocations":1,"location":null,"numPassingAsserts":7,"retryReasons":[],"startAt":1794959438849,"status":"passed","title":"same-application en add refresh keeps a sibling answer mounted until explicit discard"},{"ancestorTitles":[],"duration":645,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"same-application en delete refresh keeps a sibling answer mounted until explicit discard","invocations":1,"location":null,"numPassingAsserts":8,"retryReasons":[],"startAt":1794959439514,"status":"passed","title":"same-application en delete refresh keeps a sibling answer mounted until explicit discard"},{"ancestorTitles":[],"duration":479,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"same-application en save refresh keeps a sibling answer mounted until explicit discard","invocations":1,"location":null,"numPassingAsserts":7,"retryReasons":[],"startAt":1794959440160,"status":"passed","title":"same-application en save refresh keeps a sibling answer mounted until explicit discard"},{"ancestorTitles":[],"duration":371,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"same-application nb ready refresh keeps a sibling answer mounted until explicit discard","invocations":1,"location":null,"numPassingAsserts":7,"retryReasons":[],"startAt":1794959440639,"status":"passed","title":"same-application nb ready refresh keeps a sibling answer mounted until explicit discard"},{"ancestorTitles":[],"duration":609,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"same-application nb add refresh keeps a sibling answer mounted until explicit discard","invocations":1,"location":null,"numPassingAsserts":7,"retryReasons":[],"startAt":1794959441010,"status":"passed","title":"same-application nb add refresh keeps a sibling answer mounted until explicit discard"},{"ancestorTitles":[],"duration":561,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"same-application nb delete refresh keeps a sibling answer mounted until explicit discard","invocations":1,"location":null,"numPassingAsserts":8,"retryReasons":[],"startAt":1794959441619,"status":"passed","title":"same-application nb delete refresh keeps a sibling answer mounted until explicit discard"},{"ancestorTitles":[],"duration":414,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"same-application nb save refresh keeps a sibling answer mounted until explicit discard","invocations":1,"location":null,"numPassingAsserts":7,"retryReasons":[],"startAt":1794959442180,"status":"passed","title":"same-application nb save refresh keeps a sibling answer mounted until explicit discard"},{"ancestorTitles":[],"duration":385,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"same-application en refresh failure and GET-only retry preserve an unsaved answer","invocations":1,"location":null,"numPassingAsserts":8,"retryReasons":[],"startAt":1794959442594,"status":"passed","title":"same-application en refresh failure and GET-only retry preserve an unsaved answer"},{"ancestorTitles":[],"duration":432,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"same-application nb refresh failure and GET-only retry preserve an unsaved answer","invocations":1,"location":null,"numPassingAsserts":8,"retryReasons":[],"startAt":1794959442979,"status":"passed","title":"same-application nb refresh failure and GET-only retry preserve an unsaved answer"},{"ancestorTitles":[],"duration":241,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"marking readiness preserves that row answer draft because the write contains no answer","invocations":1,"location":null,"numPassingAsserts":3,"retryReasons":[],"startAt":1794959443411,"status":"passed","title":"marking readiness preserves that row answer draft because the write contains no answer"},{"ancestorTitles":[],"duration":451,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"changing job clears en answer drafts and a failed initial read offers only a GET retry","invocations":1,"location":null,"numPassingAsserts":7,"retryReasons":[],"startAt":1794959443652,"status":"passed","title":"changing job clears en answer drafts and a failed initial read offers only a GET retry"},{"ancestorTitles":[],"duration":385,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"changing job clears nb answer drafts and a failed initial read offers only a GET retry","invocations":1,"location":null,"numPassingAsserts":7,"retryReasons":[],"startAt":1794959444103,"status":"passed","title":"changing job clears nb answer drafts and a failed initial read offers only a GET retry"},{"ancestorTitles":[],"duration":373,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"a newer preparation refresh wins against an older success completion","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794959444488,"status":"passed","title":"a newer preparation refresh wins against an older success completion"},{"ancestorTitles":[],"duration":368,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"a newer preparation refresh wins against an older failure completion","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794959444861,"status":"passed","title":"a newer preparation refresh wins against an older failure completion"},{"ancestorTitles":[],"duration":320,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"a newer preparation refresh wins against an older pending-newer completion","invocations":1,"location":null,"numPassingAsserts":7,"retryReasons":[],"startAt":1794959445229,"status":"passed","title":"a newer preparation refresh wins against an older pending-newer completion"},{"ancestorTitles":[],"duration":474,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late prep write keeps its original target and cannot clear a new application draft","invocations":1,"location":null,"numPassingAsserts":4,"retryReasons":[],"startAt":1794959445549,"status":"passed","title":"late prep write keeps its original target and cannot clear a new application draft"},{"ancestorTitles":[],"duration":101,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late follow-up write keeps its original target and cannot clear a new application draft","invocations":1,"location":null,"numPassingAsserts":4,"retryReasons":[],"startAt":1794959446023,"status":"passed","title":"late follow-up write keeps its original target and cannot clear a new application draft"},{"ancestorTitles":[],"duration":159,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late prep read cannot replace the current application or its draft","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794959446124,"status":"passed","title":"late prep read cannot replace the current application or its draft"},{"ancestorTitles":[],"duration":28,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late follow-up read cannot replace the current application or its draft","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794959446283,"status":"passed","title":"late follow-up read cannot replace the current application or its draft"},{"ancestorTitles":[],"duration":144,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late prep read failure cannot hide the current draft","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794959446311,"status":"passed","title":"late prep read failure cannot hide the current draft"},{"ancestorTitles":[],"duration":48,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late follow-up read failure cannot hide the current draft","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794959446455,"status":"passed","title":"late follow-up read failure cannot hide the current draft"},{"ancestorTitles":[],"duration":230,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late prep finally cannot dismiss the current application loading state","invocations":1,"location":null,"numPassingAsserts":3,"retryReasons":[],"startAt":1794959446503,"status":"passed","title":"late prep finally cannot dismiss the current application loading state"},{"ancestorTitles":[],"duration":61,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late follow-up finally cannot dismiss the current application loading state","invocations":1,"location":null,"numPassingAsserts":3,"retryReasons":[],"startAt":1794959446733,"status":"passed","title":"late follow-up finally cannot dismiss the current application loading state"},{"ancestorTitles":[],"duration":525,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"changing application resets parent drafts and a failed follow-up read retains a GET-only retry","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794959446794,"status":"passed","title":"changing application resets parent drafts and a failed follow-up read retains a GET-only retry"},{"ancestorTitles":[],"duration":1310,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"pending preparation deletion follows en without a preparation reload or answer loss","invocations":1,"location":null,"numPassingAsserts":11,"retryReasons":[],"startAt":1794959447319,"status":"passed","title":"pending preparation deletion follows en without a preparation reload or answer loss"},{"ancestorTitles":[],"duration":1382,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"pending preparation deletion follows nb without a preparation reload or answer loss","invocations":1,"location":null,"numPassingAsserts":11,"retryReasons":[],"startAt":1794959448629,"status":"passed","title":"pending preparation deletion follows nb without a preparation reload or answer loss"},{"ancestorTitles":[],"duration":379,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"visible preparation read error follows en without another preparation request","invocations":1,"location":null,"numPassingAsserts":6,"retryReasons":[],"startAt":1794959450011,"status":"passed","title":"visible preparation read error follows en without another preparation request"},{"ancestorTitles":[],"duration":586,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"visible preparation read error follows nb without another preparation request","invocations":1,"location":null,"numPassingAsserts":6,"retryReasons":[],"startAt":1794959450391,"status":"passed","title":"visible preparation read error follows nb without another preparation request"},{"ancestorTitles":[],"duration":1091,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"visible preparation mutation error follows en without clearing the failure through a reload","invocations":1,"location":null,"numPassingAsserts":6,"retryReasons":[],"startAt":1794959450978,"status":"passed","title":"visible preparation mutation error follows en without clearing the failure through a reload"},{"ancestorTitles":[],"duration":921,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"visible preparation mutation error follows nb without clearing the failure through a reload","invocations":1,"location":null,"numPassingAsserts":6,"retryReasons":[],"startAt":1794959452069,"status":"passed","title":"visible preparation mutation error follows nb without clearing the failure through a reload"},{"ancestorTitles":["en unknown interview categories"],"duration":192,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"en unknown interview categories preserves constructor as a category label","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794959452991,"status":"passed","title":"preserves constructor as a category label"},{"ancestorTitles":["en unknown interview categories"],"duration":211,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"en unknown interview categories preserves toString as a category label","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794959453183,"status":"passed","title":"preserves toString as a category label"},{"ancestorTitles":["en unknown interview categories"],"duration":198,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"en unknown interview categories preserves __proto__ as a category label","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794959453395,"status":"passed","title":"preserves __proto__ as a category label"},{"ancestorTitles":["nb unknown interview categories"],"duration":279,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"nb unknown interview categories preserves constructor as a category label","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794959453593,"status":"passed","title":"preserves constructor as a category label"},{"ancestorTitles":["nb unknown interview categories"],"duration":206,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"nb unknown interview categories preserves toString as a category label","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794959453872,"status":"passed","title":"preserves toString as a category label"},{"ancestorTitles":["nb unknown interview categories"],"duration":238,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"nb unknown interview categories preserves __proto__ as a category label","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794959454079,"status":"passed","title":"preserves __proto__ as a category label"},{"ancestorTitles":[],"duration":637,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"answer save failure follows en / pending and retains the draft for explicit retry","invocations":1,"location":null,"numPassingAsserts":9,"retryReasons":[],"startAt":1794959454317,"status":"passed","title":"answer save failure follows en / pending and retains the draft for explicit retry"},{"ancestorTitles":[],"duration":700,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"answer save failure follows en / visible and retains the draft for explicit retry","invocations":1,"location":null,"numPassingAsserts":10,"retryReasons":[],"startAt":1794959454954,"status":"passed","title":"answer save failure follows en / visible and retains the draft for explicit retry"},{"ancestorTitles":[],"duration":607,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"answer save failure follows nb / pending and retains the draft for explicit retry","invocations":1,"location":null,"numPassingAsserts":9,"retryReasons":[],"startAt":1794959455654,"status":"passed","title":"answer save failure follows nb / pending and retains the draft for explicit retry"},{"ancestorTitles":[],"duration":578,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"answer save failure follows nb / visible and retains the draft for explicit retry","invocations":1,"location":null,"numPassingAsserts":10,"retryReasons":[],"startAt":1794959456261,"status":"passed","title":"answer save failure follows nb / visible and retains the draft for explicit retry"},{"ancestorTitles":[],"duration":186,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"localizes interview categories while preserving user-authored preparation","invocations":1,"location":null,"numPassingAsserts":3,"retryReasons":[],"startAt":1794959456839,"status":"passed","title":"localizes interview categories while preserving user-authored preparation"},{"ancestorTitles":[],"duration":130,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"prep renders grouped items with progress and marks AI-sourced ones","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794959457025,"status":"passed","title":"prep renders grouped items with progress and marks AI-sourced ones"},{"ancestorTitles":[],"duration":212,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"delete tooltip describes its wrapper while the disabled button keeps its item name","invocations":1,"location":null,"numPassingAsserts":4,"retryReasons":[],"startAt":1794959457156,"status":"passed","title":"delete tooltip describes its wrapper while the disabled button keeps its item name"},{"ancestorTitles":[],"duration":631,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"failed manual preparation add retains en question and answers for explicit retry","invocations":1,"location":null,"numPassingAsserts":12,"retryReasons":[],"startAt":1794959457368,"status":"passed","title":"failed manual preparation add retains en question and answers for explicit retry"},{"ancestorTitles":[],"duration":624,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"failed manual preparation add retains nb question and answers for explicit retry","invocations":1,"location":null,"numPassingAsserts":12,"retryReasons":[],"startAt":1794959457999,"status":"passed","title":"failed manual preparation add retains nb question and answers for explicit retry"},{"ancestorTitles":[],"duration":226,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"adding a prep item posts the chosen category and title","invocations":1,"location":null,"numPassingAsserts":1,"retryReasons":[],"startAt":1794959458624,"status":"passed","title":"adding a prep item posts the chosen category and title"},{"ancestorTitles":[],"duration":169,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"starts a structured interview debrief without inventing answers","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794959458850,"status":"passed","title":"starts a structured interview debrief without inventing answers"},{"ancestorTitles":[],"duration":153,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"marking an item ready patches it","invocations":1,"location":null,"numPassingAsserts":1,"retryReasons":[],"startAt":1794959459020,"status":"passed","title":"marking an item ready patches it"},{"ancestorTitles":[],"duration":170,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"an answer is only saved when the user asks","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794959459173,"status":"passed","title":"an answer is only saved when the user asks"},{"ancestorTitles":[],"duration":294,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"deleting a prep item calls delete","invocations":1,"location":null,"numPassingAsserts":1,"retryReasons":[],"startAt":1794959459343,"status":"passed","title":"deleting a prep item calls delete"},{"ancestorTitles":[],"duration":109,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"empty prep shows a useful empty state","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794959459637,"status":"passed","title":"empty prep shows a useful empty state"},{"ancestorTitles":[],"duration":309,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"AI preparation uses the linked CV and only saves after explicit acceptance","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794959459746,"status":"passed","title":"AI preparation uses the linked CV and only saves after explicit acceptance"},{"ancestorTitles":[],"duration":327,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late generation cannot offer another application the previous application suggestion","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794959460055,"status":"passed","title":"late generation cannot offer another application the previous application suggestion"},{"ancestorTitles":[],"duration":320,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"completed AI suggestion is scoped to its application instead of becoming a new application draft","invocations":1,"location":null,"numPassingAsserts":4,"retryReasons":[],"startAt":1794959460382,"status":"passed","title":"completed AI suggestion is scoped to its application instead of becoming a new application draft"},{"ancestorTitles":[],"duration":264,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late accepted suggestion does not reload the previous application board into the current application","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794959460702,"status":"passed","title":"late accepted suggestion does not reload the previous application board into the current application"},{"ancestorTitles":[],"duration":141,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"pending linked CV is loading, not an empty selection (en)","invocations":1,"location":null,"numPassingAsserts":6,"retryReasons":[],"startAt":1794959460966,"status":"passed","title":"pending linked CV is loading, not an empty selection (en)"},{"ancestorTitles":[],"duration":142,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"pending linked CV is loading, not an empty selection (nb)","invocations":1,"location":null,"numPassingAsserts":6,"retryReasons":[],"startAt":1794959461108,"status":"passed","title":"pending linked CV is loading, not an empty selection (nb)"},{"ancestorTitles":[],"duration":322,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"linked-CV failure has current-language GET-only retry and preserves instructions (en)","invocations":1,"location":null,"numPassingAsserts":11,"retryReasons":[],"startAt":1794959461250,"status":"passed","title":"linked-CV failure has current-language GET-only retry and preserves instructions (en)"},{"ancestorTitles":[],"duration":278,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"linked-CV failure has current-language GET-only retry and preserves instructions (nb)","invocations":1,"location":null,"numPassingAsserts":11,"retryReasons":[],"startAt":1794959461572,"status":"passed","title":"linked-CV failure has current-language GET-only retry and preserves instructions (nb)"},{"ancestorTitles":[],"duration":184,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"changing application hides the previous linked CV while the new read is pending (en)","invocations":1,"location":null,"numPassingAsserts":4,"retryReasons":[],"startAt":1794959461850,"status":"passed","title":"changing application hides the previous linked CV while the new read is pending (en)"},{"ancestorTitles":[],"duration":278,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"changing application hides the previous linked CV while the new read is pending (nb)","invocations":1,"location":null,"numPassingAsserts":4,"retryReasons":[],"startAt":1794959462034,"status":"passed","title":"changing application hides the previous linked CV while the new read is pending (nb)"},{"ancestorTitles":[],"duration":75,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"prep surfaces a load error","invocations":1,"location":null,"numPassingAsserts":1,"retryReasons":[],"startAt":1794959462312,"status":"passed","title":"prep surfaces a load error"},{"ancestorTitles":[],"duration":140,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"failed follow-up save retains editable en drafts and retries only the explicit write","invocations":1,"location":null,"numPassingAsserts":11,"retryReasons":[],"startAt":1794959462387,"status":"passed","title":"failed follow-up save retains editable en drafts and retries only the explicit write"},{"ancestorTitles":[],"duration":123,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"failed follow-up save retains editable nb drafts and retries only the explicit write","invocations":1,"location":null,"numPassingAsserts":11,"retryReasons":[],"startAt":1794959462527,"status":"passed","title":"failed follow-up save retains editable nb drafts and retries only the explicit write"},{"ancestorTitles":[],"duration":61,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"failed initial follow-up read offers en GET-only retry without editable defaults","invocations":1,"location":null,"numPassingAsserts":7,"retryReasons":[],"startAt":1794959462650,"status":"passed","title":"failed initial follow-up read offers en GET-only retry without editable defaults"},{"ancestorTitles":[],"duration":63,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"failed initial follow-up read offers nb GET-only retry without editable defaults","invocations":1,"location":null,"numPassingAsserts":7,"retryReasons":[],"startAt":1794959462711,"status":"passed","title":"failed initial follow-up read offers nb GET-only retry without editable defaults"},{"ancestorTitles":[],"duration":106,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"follow-up language switch from en preserves the unsaved date and next action without a read","invocations":1,"location":null,"numPassingAsserts":6,"retryReasons":[],"startAt":1794959462775,"status":"passed","title":"follow-up language switch from en preserves the unsaved date and next action without a read"},{"ancestorTitles":[],"duration":33,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"follow-up language switch from nb preserves the unsaved date and next action without a read","invocations":1,"location":null,"numPassingAsserts":6,"retryReasons":[],"startAt":1794959462881,"status":"passed","title":"follow-up language switch from nb preserves the unsaved date and next action without a read"},{"ancestorTitles":[],"duration":31,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"follow-up en read error stays current without another read","invocations":1,"location":null,"numPassingAsserts":4,"retryReasons":[],"startAt":1794959462914,"status":"passed","title":"follow-up en read error stays current without another read"},{"ancestorTitles":[],"duration":76,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"follow-up en save error stays current without another read","invocations":1,"location":null,"numPassingAsserts":4,"retryReasons":[],"startAt":1794959462945,"status":"passed","title":"follow-up en save error stays current without another read"},{"ancestorTitles":[],"duration":47,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"follow-up nb read error stays current without another read","invocations":1,"location":null,"numPassingAsserts":4,"retryReasons":[],"startAt":1794959463021,"status":"passed","title":"follow-up nb read error stays current without another read"},{"ancestorTitles":[],"duration":76,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"follow-up nb save error stays current without another read","invocations":1,"location":null,"numPassingAsserts":4,"retryReasons":[],"startAt":1794959463068,"status":"passed","title":"follow-up nb save error stays current without another read"},{"ancestorTitles":[],"duration":29,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"follow-up loads the existing date and open checklist tasks","invocations":1,"location":null,"numPassingAsserts":3,"retryReasons":[],"startAt":1794959463144,"status":"passed","title":"follow-up loads the existing date and open checklist tasks"},{"ancestorTitles":[],"duration":61,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"saving a follow-up sends the date and next action","invocations":1,"location":null,"numPassingAsserts":1,"retryReasons":[],"startAt":1794959463173,"status":"passed","title":"saving a follow-up sends the date and next action"},{"ancestorTitles":[],"duration":15,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"no follow-up shows an empty state","invocations":1,"location":null,"numPassingAsserts":1,"retryReasons":[],"startAt":1794959463234,"status":"passed","title":"no follow-up shows an empty state"}],"endTime":1794959463251,"message":"","name":"E:\\Storage\\Projects\\Active\\temp docs\\jobjakt-local-build\\interview-answer-refresh\\job-tracker-ui\\src\\interview-prep.test.tsx","startTime":1794959435736,"status":"passed","summary":""}],"wasInterrupted":false} diff --git a/job-tracker-ui/src/components/InterviewPrep.tsx b/job-tracker-ui/src/components/InterviewPrep.tsx index 36421c51..7e6b8a16 100644 --- a/job-tracker-ui/src/components/InterviewPrep.tsx +++ b/job-tracker-ui/src/components/InterviewPrep.tsx @@ -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; keepContentOnError?: boolean; + keepContentOnLoading?: boolean; }) { return ( - {!loading && (!error || keepContentOnError) && children} + {(!loading || keepContentOnLoading) && (!error || keepContentOnError) && children} ); } @@ -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} > {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) => { + const run = async (fn: () => Promise, 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")} diff --git a/job-tracker-ui/src/interview-prep.test.tsx b/job-tracker-ui/src/interview-prep.test.tsx index 43ac3c1e..c8bb057a 100644 --- a/job-tracker-ui/src/interview-prep.test.tsx +++ b/job-tracker-ui/src/interview-prep.test.tsx @@ -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(); + 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(); + 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(); + 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(); + fireEvent.change(await screen.findByRole('textbox', { name }), { target: { value: 'Private application seven answer' } }); + await act(async () => view.rerender()); + 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 }));