diff --git a/docs/validation/interview-parent-lifetime/README.md b/docs/validation/interview-parent-lifetime/README.md new file mode 100644 index 00000000..1d00b00c --- /dev/null +++ b/docs/validation/interview-parent-lifetime/README.md @@ -0,0 +1,45 @@ +# Interview parent state lifetime + +17 November 2026; final revalidation 18 November 2026. Development checkpoint based on A3 `eb253877`, branch `codex/interview-parent-lifetime`. Scope is the interview-preparation and follow-up parent components and their unit tests. No runtime locale expansion, model/service calls, schema changes, production work or approval changes. + +## Reproduced defects and fix + +On unchanged baseline, deferred reads for application 7 were completed after rendering application 8. Seven regression cases failed: previous prep content replaced the current board; previous follow-up data overwrote a current draft; stale errors appeared in either current surface; stale finalisers dismissed either current loading state; and parent drafts/data survived the application boundary, causing a failed new follow-up read to expose old editable data instead of a GET-only retry. + +A second pre-fix run added three cases: an older same-application refresh replaced a newer board, and a late prep addition cleared the new application's title draft and initiated a previous-application reload (both failed); a late follow-up write already retained its original API target (positive control passed). Thus nine expected failing regressions and one passing control were observed before editing production code; overlapping reruns are not additional unique tests. + +The exported prep/follow-up components now render a job-keyed private workspace, following the existing keyed interview-assistant ownership pattern. Changing job unmounts its board, drafts, error and busy state together. A per-workspace active flag and read sequence guard read success/error/finally, and prevent an unmounted workspace from starting a refresh after an existing write completes. Only the newest read can update a mounted owner. Explicit writes retain their original closure/API target; no write is cancelled, migrated to another application or retried automatically. Same-application language changes keep the same workspace and its drafts. + +Two additional same-application controls exercise stale errors and stale finalisers while a newer refresh remains pending. Existing rerender tests now await remount reads inside `act`, avoiding React test warnings caused by unawaited new parent workspaces. No test suppresses console output. + +## Verification + +Commands from `job-tracker-ui`: + +```powershell +rtk proxy node node_modules/jest/bin/jest.js --runInBand --runTestsByPath src/interview-prep.test.tsx --cacheDirectory='../.test-cache' +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 +``` + +- Final focused jsdom suite: **63/63 passed**, no snapshots, no React warnings. This includes 12 added cases and the existing 51; prior focused runs are not added to that total. +- Native runner receipt: [jest-results.json](jest-results.json), produced with `--json --outputFile='../docs/validation/interview-parent-lifetime/jest-results.json'` added to the command above. Final revalidation passed 63/63 with zero failed/pending tests and 23.206 seconds reported by the runner. This is a repeat of the same source-bound cases, not an additional 63 distinct tests. +- Full UI TypeScript check: passed, exit 0. +- Scoped lint: passed, exit 0, zero warnings. An earlier cleanup-ref lint warning was fixed by checking the active flag on completion instead of mutating the read ref during cleanup. +- `rtk git diff --check`: passed. +- Graph-first query used the existing isolated A3 research graph before source inspection. `rtk proxy graphify update .` performed AST-only extraction in this new worktree, without API/model calls or shared graph mutation. The initial refresh created 19,835 nodes and 48,044 edges; an incremental refresh followed the final source/test edits. Generated graph output is local untracked research material, not a new runtime dependency. Graph reported missing optional PDF/SQL extraction dependencies and unsupported/no-symbol files; this is structural orientation, not full runtime or document analysis. + +Existing dependencies were accessed read-only through a directory junction to `E:/Storage/Projects/Active/temp docs/jobjakt-local-build/next-security-patch/job-tracker-ui/node_modules`. No install/build/browser lane ran. + +Validated working-file SHA-256: + +| File | SHA-256 | +| --- | --- | +| `job-tracker-ui/src/components/InterviewPrep.tsx` | `57d208df5880d8b93c9a3acf13e7b11d2791f4a9d3fdf55da56debe68c3145ee` | +| `job-tracker-ui/src/interview-prep.test.tsx` | `82c36af6225d4fb00fb689bf7243ef2163b6abc237c91a7058f283c173d34471` | + +## Limits and integration + +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, integration/publication and central tracking. This checkpoint does not grant release or roadmap-stage approval. + +Adjacent existing behaviour remains: ordinary same-application board refresh hides/remounts row editors through `Shell`'s loading condition; preserving row-local unsaved answers during every ordinary refresh needs a separate behavioural decision and test package. This fix prevents superseded reads from replacing the newest board/draft state; it does not redesign refresh presentation or persistence. Pending writes may still finish on the original application after navigation, as explicitly initiated by the user. diff --git a/docs/validation/interview-parent-lifetime/jest-results.json b/docs/validation/interview-parent-lifetime/jest-results.json new file mode 100644 index 00000000..d3b3caae --- /dev/null +++ b/docs/validation/interview-parent-lifetime/jest-results.json @@ -0,0 +1 @@ +{"numFailedTestSuites":0,"numFailedTests":0,"numPassedTestSuites":1,"numPassedTests":63,"numPendingTestSuites":0,"numPendingTests":0,"numRuntimeErrorTestSuites":0,"numTodoTests":0,"numTotalTestSuites":1,"numTotalTests":63,"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":1794958920324,"success":true,"testResults":[{"assertionResults":[{"ancestorTitles":[],"duration":537,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"a newer preparation refresh wins against an older success completion","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794958930971,"status":"passed","title":"a newer preparation refresh wins against an older success completion"},{"ancestorTitles":[],"duration":318,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"a newer preparation refresh wins against an older failure completion","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794958931508,"status":"passed","title":"a newer preparation refresh wins against an older failure completion"},{"ancestorTitles":[],"duration":309,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"a newer preparation refresh wins against an older pending-newer completion","invocations":1,"location":null,"numPassingAsserts":7,"retryReasons":[],"startAt":1794958931826,"status":"passed","title":"a newer preparation refresh wins against an older pending-newer completion"},{"ancestorTitles":[],"duration":440,"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":1794958932135,"status":"passed","title":"late prep write keeps its original target and cannot clear a new application draft"},{"ancestorTitles":[],"duration":88,"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":1794958932575,"status":"passed","title":"late follow-up write keeps its original target and cannot clear a new application draft"},{"ancestorTitles":[],"duration":147,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late prep read cannot replace the current application or its draft","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794958932663,"status":"passed","title":"late prep read cannot replace the current application or its draft"},{"ancestorTitles":[],"duration":16,"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":1794958932810,"status":"passed","title":"late follow-up read cannot replace the current application or its draft"},{"ancestorTitles":[],"duration":121,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late prep read failure cannot hide the current draft","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794958932827,"status":"passed","title":"late prep read failure cannot hide the current draft"},{"ancestorTitles":[],"duration":19,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late follow-up read failure cannot hide the current draft","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794958932948,"status":"passed","title":"late follow-up read failure cannot hide the current draft"},{"ancestorTitles":[],"duration":141,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late prep finally cannot dismiss the current application loading state","invocations":1,"location":null,"numPassingAsserts":3,"retryReasons":[],"startAt":1794958932967,"status":"passed","title":"late prep finally cannot dismiss the current application loading state"},{"ancestorTitles":[],"duration":28,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late follow-up finally cannot dismiss the current application loading state","invocations":1,"location":null,"numPassingAsserts":3,"retryReasons":[],"startAt":1794958933108,"status":"passed","title":"late follow-up finally cannot dismiss the current application loading state"},{"ancestorTitles":[],"duration":354,"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":1794958933136,"status":"passed","title":"changing application resets parent drafts and a failed follow-up read retains a GET-only retry"},{"ancestorTitles":[],"duration":646,"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":1794958933490,"status":"passed","title":"pending preparation deletion follows en without a preparation reload or answer loss"},{"ancestorTitles":[],"duration":594,"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":1794958934136,"status":"passed","title":"pending preparation deletion follows nb without a preparation reload or answer loss"},{"ancestorTitles":[],"duration":94,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"visible preparation read error follows en without another preparation request","invocations":1,"location":null,"numPassingAsserts":6,"retryReasons":[],"startAt":1794958934731,"status":"passed","title":"visible preparation read error follows en without another preparation request"},{"ancestorTitles":[],"duration":125,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"visible preparation read error follows nb without another preparation request","invocations":1,"location":null,"numPassingAsserts":6,"retryReasons":[],"startAt":1794958934825,"status":"passed","title":"visible preparation read error follows nb without another preparation request"},{"ancestorTitles":[],"duration":372,"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":1794958934950,"status":"passed","title":"visible preparation mutation error follows en without clearing the failure through a reload"},{"ancestorTitles":[],"duration":387,"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":1794958935322,"status":"passed","title":"visible preparation mutation error follows nb without clearing the failure through a reload"},{"ancestorTitles":["en unknown interview categories"],"duration":75,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"en unknown interview categories preserves constructor as a category label","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794958935709,"status":"passed","title":"preserves constructor as a category label"},{"ancestorTitles":["en unknown interview categories"],"duration":60,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"en unknown interview categories preserves toString as a category label","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794958935784,"status":"passed","title":"preserves toString as a category label"},{"ancestorTitles":["en unknown interview categories"],"duration":62,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"en unknown interview categories preserves __proto__ as a category label","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794958935844,"status":"passed","title":"preserves __proto__ as a category label"},{"ancestorTitles":["nb unknown interview categories"],"duration":61,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"nb unknown interview categories preserves constructor as a category label","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794958935906,"status":"passed","title":"preserves constructor as a category label"},{"ancestorTitles":["nb unknown interview categories"],"duration":77,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"nb unknown interview categories preserves toString as a category label","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794958935967,"status":"passed","title":"preserves toString as a category label"},{"ancestorTitles":["nb unknown interview categories"],"duration":93,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"nb unknown interview categories preserves __proto__ as a category label","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794958936044,"status":"passed","title":"preserves __proto__ as a category label"},{"ancestorTitles":[],"duration":401,"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":1794958936137,"status":"passed","title":"answer save failure follows en / pending and retains the draft for explicit retry"},{"ancestorTitles":[],"duration":433,"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":1794958936538,"status":"passed","title":"answer save failure follows en / visible and retains the draft for explicit retry"},{"ancestorTitles":[],"duration":396,"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":1794958936972,"status":"passed","title":"answer save failure follows nb / pending and retains the draft for explicit retry"},{"ancestorTitles":[],"duration":450,"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":1794958937368,"status":"passed","title":"answer save failure follows nb / visible and retains the draft for explicit retry"},{"ancestorTitles":[],"duration":127,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"localizes interview categories while preserving user-authored preparation","invocations":1,"location":null,"numPassingAsserts":3,"retryReasons":[],"startAt":1794958937818,"status":"passed","title":"localizes interview categories while preserving user-authored preparation"},{"ancestorTitles":[],"duration":76,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"prep renders grouped items with progress and marks AI-sourced ones","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794958937945,"status":"passed","title":"prep renders grouped items with progress and marks AI-sourced ones"},{"ancestorTitles":[],"duration":155,"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":1794958938021,"status":"passed","title":"delete tooltip describes its wrapper while the disabled button keeps its item name"},{"ancestorTitles":[],"duration":572,"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":1794958938176,"status":"passed","title":"failed manual preparation add retains en question and answers for explicit retry"},{"ancestorTitles":[],"duration":521,"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":1794958938748,"status":"passed","title":"failed manual preparation add retains nb question and answers for explicit retry"},{"ancestorTitles":[],"duration":253,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"adding a prep item posts the chosen category and title","invocations":1,"location":null,"numPassingAsserts":1,"retryReasons":[],"startAt":1794958939269,"status":"passed","title":"adding a prep item posts the chosen category and title"},{"ancestorTitles":[],"duration":185,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"starts a structured interview debrief without inventing answers","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794958939522,"status":"passed","title":"starts a structured interview debrief without inventing answers"},{"ancestorTitles":[],"duration":139,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"marking an item ready patches it","invocations":1,"location":null,"numPassingAsserts":1,"retryReasons":[],"startAt":1794958939707,"status":"passed","title":"marking an item ready patches it"},{"ancestorTitles":[],"duration":108,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"an answer is only saved when the user asks","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794958939846,"status":"passed","title":"an answer is only saved when the user asks"},{"ancestorTitles":[],"duration":201,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"deleting a prep item calls delete","invocations":1,"location":null,"numPassingAsserts":1,"retryReasons":[],"startAt":1794958939954,"status":"passed","title":"deleting a prep item calls delete"},{"ancestorTitles":[],"duration":94,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"empty prep shows a useful empty state","invocations":1,"location":null,"numPassingAsserts":2,"retryReasons":[],"startAt":1794958940155,"status":"passed","title":"empty prep shows a useful empty state"},{"ancestorTitles":[],"duration":260,"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":1794958940249,"status":"passed","title":"AI preparation uses the linked CV and only saves after explicit acceptance"},{"ancestorTitles":[],"duration":289,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"late generation cannot offer another application the previous application suggestion","invocations":1,"location":null,"numPassingAsserts":5,"retryReasons":[],"startAt":1794958940509,"status":"passed","title":"late generation cannot offer another application the previous application suggestion"},{"ancestorTitles":[],"duration":243,"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":1794958940799,"status":"passed","title":"completed AI suggestion is scoped to its application instead of becoming a new application draft"},{"ancestorTitles":[],"duration":320,"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":1794958941043,"status":"passed","title":"late accepted suggestion does not reload the previous application board into the current application"},{"ancestorTitles":[],"duration":156,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"pending linked CV is loading, not an empty selection (en)","invocations":1,"location":null,"numPassingAsserts":6,"retryReasons":[],"startAt":1794958941363,"status":"passed","title":"pending linked CV is loading, not an empty selection (en)"},{"ancestorTitles":[],"duration":140,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"pending linked CV is loading, not an empty selection (nb)","invocations":1,"location":null,"numPassingAsserts":6,"retryReasons":[],"startAt":1794958941519,"status":"passed","title":"pending linked CV is loading, not an empty selection (nb)"},{"ancestorTitles":[],"duration":296,"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":1794958941659,"status":"passed","title":"linked-CV failure has current-language GET-only retry and preserves instructions (en)"},{"ancestorTitles":[],"duration":185,"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":1794958941955,"status":"passed","title":"linked-CV failure has current-language GET-only retry and preserves instructions (nb)"},{"ancestorTitles":[],"duration":200,"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":1794958942140,"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":1794958942340,"status":"passed","title":"changing application hides the previous linked CV while the new read is pending (nb)"},{"ancestorTitles":[],"duration":74,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"prep surfaces a load error","invocations":1,"location":null,"numPassingAsserts":1,"retryReasons":[],"startAt":1794958942618,"status":"passed","title":"prep surfaces a load error"},{"ancestorTitles":[],"duration":139,"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":1794958942693,"status":"passed","title":"failed follow-up save retains editable en drafts and retries only the explicit write"},{"ancestorTitles":[],"duration":139,"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":1794958942832,"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":1794958942971,"status":"passed","title":"failed initial follow-up read offers en GET-only retry without editable defaults"},{"ancestorTitles":[],"duration":62,"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":1794958943032,"status":"passed","title":"failed initial follow-up read offers nb GET-only retry without editable defaults"},{"ancestorTitles":[],"duration":46,"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":1794958943094,"status":"passed","title":"follow-up language switch from en preserves the unsaved date and next action without a read"},{"ancestorTitles":[],"duration":46,"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":1794958943140,"status":"passed","title":"follow-up language switch from nb preserves the unsaved date and next action without a read"},{"ancestorTitles":[],"duration":34,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"follow-up en read error stays current without another read","invocations":1,"location":null,"numPassingAsserts":4,"retryReasons":[],"startAt":1794958943186,"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":1794958943220,"status":"passed","title":"follow-up en save error stays current without another read"},{"ancestorTitles":[],"duration":46,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"follow-up nb read error stays current without another read","invocations":1,"location":null,"numPassingAsserts":4,"retryReasons":[],"startAt":1794958943296,"status":"passed","title":"follow-up nb read error stays current without another read"},{"ancestorTitles":[],"duration":77,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"follow-up nb save error stays current without another read","invocations":1,"location":null,"numPassingAsserts":4,"retryReasons":[],"startAt":1794958943342,"status":"passed","title":"follow-up nb save error stays current without another read"},{"ancestorTitles":[],"duration":28,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"follow-up loads the existing date and open checklist tasks","invocations":1,"location":null,"numPassingAsserts":3,"retryReasons":[],"startAt":1794958943419,"status":"passed","title":"follow-up loads the existing date and open checklist tasks"},{"ancestorTitles":[],"duration":50,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"saving a follow-up sends the date and next action","invocations":1,"location":null,"numPassingAsserts":1,"retryReasons":[],"startAt":1794958943447,"status":"passed","title":"saving a follow-up sends the date and next action"},{"ancestorTitles":[],"duration":26,"failing":false,"failureDetails":[],"failureMessages":[],"fullName":"no follow-up shows an empty state","invocations":1,"location":null,"numPassingAsserts":1,"retryReasons":[],"startAt":1794958943497,"status":"passed","title":"no follow-up shows an empty state"}],"endTime":1794958943525,"message":"","name":"E:\\Storage\\Projects\\Active\\temp docs\\jobjakt-local-build\\interview-parent-lifetime\\job-tracker-ui\\src\\interview-prep.test.tsx","startTime":1794958922484,"status":"passed","summary":""}],"wasInterrupted":false} diff --git a/job-tracker-ui/src/components/InterviewPrep.tsx b/job-tracker-ui/src/components/InterviewPrep.tsx index 1b279d6d..36421c51 100644 --- a/job-tracker-ui/src/components/InterviewPrep.tsx +++ b/job-tracker-ui/src/components/InterviewPrep.tsx @@ -43,6 +43,10 @@ function Shell({ title, subtitle, loading, error, children, onRetry, keepContent } export function ApplicationInterviewPrep({ jobId }: { jobId: number }) { + return ; +} + +function InterviewPrepWorkspace({ jobId }: { jobId: number }) { const { t } = useI18n(); const [board, setBoard] = useState(null); const [error, setError] = useState<{ cause: unknown; fallback: "interviewPrepLoadFailed" | "interviewPrepUpdateFailed" | "interviewPrepAnswerSaveFailed" } | null>(null); @@ -50,16 +54,26 @@ export function ApplicationInterviewPrep({ jobId }: { jobId: number }) { const [busy, setBusy] = useState(false); const [title, setTitle] = useState(""); const [category, setCategory] = useState(INTERVIEW_PREP_CATEGORIES[0].key); + const active = useRef(true); + const readSequence = useRef(0); + useLayoutEffect(() => { + active.current = true; + return () => { active.current = false; }; + }, []); const load = useCallback(async () => { + if (!active.current) return; + const request = ++readSequence.current; setLoading(true); try { - setBoard(await interviewPrepApi.get(jobId)); + const result = await interviewPrepApi.get(jobId); + if (!active.current || request !== readSequence.current) return; + setBoard(result); setError(null); } catch (err) { - setError({ cause: err, fallback: "interviewPrepLoadFailed" }); + if (active.current && request === readSequence.current) setError({ cause: err, fallback: "interviewPrepLoadFailed" }); } finally { - setLoading(false); + if (active.current && request === readSequence.current) setLoading(false); } }, [jobId]); @@ -424,6 +438,10 @@ function PrepRow({ jobId, item, busy, onChanged, onError }: { } export function ApplicationFollowUp({ jobId }: { jobId: number }) { + return ; +} + +function FollowUpWorkspace({ jobId }: { jobId: number }) { const { t } = useI18n(); const [data, setData] = useState(null); const [error, setError] = useState<{ cause: unknown; fallback: "interviewFollowUpLoadFailed" | "interviewFollowUpSaveFailed" } | null>(null); @@ -431,19 +449,28 @@ export function ApplicationFollowUp({ jobId }: { jobId: number }) { const [busy, setBusy] = useState(false); const [date, setDate] = useState(""); const [action, setAction] = useState(""); + const active = useRef(true); + const readSequence = useRef(0); + useLayoutEffect(() => { + active.current = true; + return () => { active.current = false; }; + }, []); const load = useCallback(async () => { + if (!active.current) return; + const request = ++readSequence.current; setLoading(true); try { const result = await interviewPrepApi.followUp(jobId); + if (!active.current || request !== readSequence.current) return; setData(result); setDate(result.followUpAt ? result.followUpAt.slice(0, 10) : ""); setAction(result.nextAction ?? ""); setError(null); } catch (err) { - setError({ cause: err, fallback: "interviewFollowUpLoadFailed" }); + if (active.current && request === readSequence.current) setError({ cause: err, fallback: "interviewFollowUpLoadFailed" }); } finally { - setLoading(false); + if (active.current && request === readSequence.current) setLoading(false); } }, [jobId]); diff --git a/job-tracker-ui/src/interview-prep.test.tsx b/job-tracker-ui/src/interview-prep.test.tsx index 1ecefff3..43ac3c1e 100644 --- a/job-tracker-ui/src/interview-prep.test.tsx +++ b/job-tracker-ui/src/interview-prep.test.tsx @@ -63,6 +63,135 @@ beforeEach(() => { window.localStorage.setItem("uiLanguage", "en"); }); +function deferredRead() { + let resolve!: (value: any) => void; + let reject!: (reason: unknown) => void; + const promise = new Promise((yes, no) => { resolve = yes; reject = no; }); + return { promise, resolve, reject }; +} + +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()!; + const older = deferredRead(); const newer = deferredRead(); + let reads = 0; + mockedApi.get.mockImplementation((url: string) => url.endsWith('/interview-prep') && ++reads > 1 ? (reads === 2 ? older.promise : newer.promise) : read(url)); + const firstWrite = deferredRead(); const secondWrite = deferredRead(); + mockedApi.patch.mockReset().mockReturnValueOnce(firstWrite.promise).mockReturnValueOnce(secondWrite.promise); + render(); + fireEvent.click(await screen.findByRole('checkbox', { name: 'Ready: Funding history' })); + fireEvent.click(screen.getByRole('checkbox', { name: 'Ready: Tell me about a conflict' })); + await act(async () => firstWrite.resolve({ data: {} })); + await act(async () => secondWrite.resolve({ data: {} })); + expect(reads).toBe(3); + if (completion === 'pending-newer') { + 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(); + } + const currentBoard = { ...board, groups: [{ ...board.groups[0], items: [{ ...board.groups[0].items[0], title: 'Newest board' }] }] }; + await act(async () => newer.resolve({ data: currentBoard })); + expect(await screen.findByText('Newest board')).toBeVisible(); + fireEvent.change(screen.getByLabelText(translations.en.interviewPrepAddLabel), { target: { value: 'Current draft' } }); + if (completion === 'success') await act(async () => older.resolve({ data: board })); + if (completion === 'failure') await act(async () => older.reject(new Error('Older refresh failure'))); + expect(screen.getByText('Newest board')).toBeVisible(); + expect(screen.queryByText(translations.en.interviewPrepLoadFailed)).not.toBeInTheDocument(); + expect(screen.getByLabelText(translations.en.interviewPrepAddLabel)).toHaveValue('Current draft'); +}); + +test.each(['prep', 'follow-up'] as const)('late %s write keeps its original target and cannot clear a new application draft', async surface => { + mockedApi.get.mockReset(); routeGet(); + const write = deferredRead(); + mockedApi.post.mockReset().mockReturnValueOnce(write.promise); + mockedApi.put.mockReset().mockReturnValueOnce(write.promise); + const component = (id: number) => surface === 'prep' ? : ; + const label = surface === 'prep' ? translations.en.interviewPrepAddLabel : translations.en.workspaceNextAction; + const view = render(component(7)); + fireEvent.change(await screen.findByLabelText(label), { target: { value: 'Original application write' } }); + fireEvent.click(screen.getByRole('button', { name: translations.en[surface === 'prep' ? 'interviewPrepAdd' : 'save'] })); + await act(async () => view.rerender({component(8)})); + fireEvent.change(await screen.findByLabelText(label), { target: { value: 'New application draft' } }); + await act(async () => write.resolve({ data: surface === 'prep' ? board.groups[0].items[0] : followUp })); + expect(screen.getByLabelText(label)).toHaveValue('New application draft'); + expect(surface === 'prep' ? mockedApi.post : mockedApi.put).toHaveBeenCalledTimes(1); + expect((surface === 'prep' ? mockedApi.post : mockedApi.put).mock.calls[0][0]).toBe(`/jobapplications/7/${surface === 'prep' ? 'interview-prep' : 'follow-up'}`); + expect(mockedApi.get.mock.calls.filter(([url]) => url === '/jobapplications/7/interview-prep')).toHaveLength(surface === 'prep' ? 1 : 0); +}); + +test.each(['prep', 'follow-up'] as const)('late %s read cannot replace the current application or its draft', async surface => { + mockedApi.get.mockReset(); routeGet(); + const read = mockedApi.get.getMockImplementation()!; + const old = deferredRead(); + const suffix = surface === 'prep' ? 'interview-prep' : 'follow-up'; + mockedApi.get.mockImplementation((url: string) => url === `/jobapplications/7/${suffix}` ? old.promise : read(url)); + const component = (id: number) => surface === 'prep' ? : ; + const view = render(component(7)); + await act(async () => view.rerender({component(8)})); + const label = surface === 'prep' ? translations.en.interviewPrepAddLabel : translations.en.workspaceNextAction; + fireEvent.change(await screen.findByLabelText(label), { target: { value: 'Current application draft' } }); + const oldData = surface === 'prep' + ? { ...board, groups: [{ ...board.groups[0], items: [{ ...board.groups[0].items[0], title: 'Previous application only' }] }] } + : { ...followUp, nextAction: 'Previous application only' }; + await act(async () => old.resolve({ data: oldData })); + expect(screen.getByLabelText(label)).toHaveValue('Current application draft'); + expect(screen.queryByText('Previous application only')).not.toBeInTheDocument(); + expect(screen.queryByDisplayValue('Previous application only')).not.toBeInTheDocument(); + expect(mockedApi.post).not.toHaveBeenCalled(); expect(mockedApi.put).not.toHaveBeenCalled(); +}); + +test.each(['prep', 'follow-up'] as const)('late %s read failure cannot hide the current draft', async surface => { + mockedApi.get.mockReset(); routeGet(); + const read = mockedApi.get.getMockImplementation()!; + const old = deferredRead(); + const suffix = surface === 'prep' ? 'interview-prep' : 'follow-up'; + mockedApi.get.mockImplementation((url: string) => url === `/jobapplications/7/${suffix}` ? old.promise : read(url)); + const component = (id: number) => surface === 'prep' ? : ; + const view = render(component(7)); + await act(async () => view.rerender({component(8)})); + const label = surface === 'prep' ? translations.en.interviewPrepAddLabel : translations.en.workspaceNextAction; + fireEvent.change(await screen.findByLabelText(label), { target: { value: 'Current application draft' } }); + await act(async () => old.reject(new Error('Previous application failure'))); + expect(screen.queryByText(translations.en[surface === 'prep' ? 'interviewPrepLoadFailed' : 'interviewFollowUpLoadFailed'])).not.toBeInTheDocument(); + expect(screen.getByLabelText(label)).toHaveValue('Current application draft'); +}); + +test.each(['prep', 'follow-up'] as const)('late %s finally cannot dismiss the current application loading state', async surface => { + mockedApi.get.mockReset(); routeGet(); + const read = mockedApi.get.getMockImplementation()!; + const old = deferredRead(); const current = deferredRead(); + const suffix = surface === 'prep' ? 'interview-prep' : 'follow-up'; + mockedApi.get.mockImplementation((url: string) => url.endsWith(`/${suffix}`) ? (url.includes('/7/') ? old.promise : current.promise) : read(url)); + const component = (id: number) => surface === 'prep' ? : ; + const view = render(component(7)); + await act(async () => view.rerender({component(8)})); + await act(async () => old.resolve({ data: surface === 'prep' ? board : followUp })); + const region = within(screen.getByRole('region', { name: translations.en[surface === 'prep' ? 'interviewPrepTitle' : 'interviewFollowUpTitle'] })); + expect(region.getByRole('progressbar', { name: translations.en.loading })).toBeVisible(); + expect(region.queryByLabelText(translations.en[surface === 'prep' ? 'interviewPrepAddLabel' : 'workspaceNextAction'])).not.toBeInTheDocument(); + await act(async () => current.resolve({ data: surface === 'prep' ? board : followUp })); + expect(await region.findByLabelText(translations.en[surface === 'prep' ? 'interviewPrepAddLabel' : 'workspaceNextAction'])).toBeVisible(); +}); + +test('changing application resets parent drafts and a failed follow-up read retains a GET-only retry', async () => { + mockedApi.get.mockReset(); routeGet(); + const read = mockedApi.get.getMockImplementation()!; + mockedApi.get.mockImplementation((url: string) => url === '/jobapplications/8/follow-up' ? Promise.reject(new Error('Current read failure')) : read(url)); + const view = render(); + fireEvent.change(await screen.findByLabelText(translations.en.interviewPrepAddLabel), { target: { value: 'Application seven draft' } }); + await screen.findByDisplayValue(followUp.nextAction); + await act(async () => view.rerender()); + expect(await screen.findByLabelText(translations.en.interviewPrepAddLabel)).toHaveValue(''); + expect(await screen.findByText(translations.en.interviewFollowUpLoadFailed)).toBeVisible(); + const region = within(screen.getByRole('region', { name: translations.en.interviewFollowUpTitle })); + expect(region.queryByLabelText(translations.en.workspaceNextAction)).not.toBeInTheDocument(); + mockedApi.get.mockImplementation(read); + fireEvent.click(region.getByRole('button', { name: translations.en.retry })); + expect(await region.findByLabelText(translations.en.workspaceNextAction)).toHaveValue(followUp.nextAction); + expect(mockedApi.put).not.toHaveBeenCalled(); +}); + test.each(['en', 'nb'] as const)('pending preparation deletion follows %s without a preparation reload or answer loss', async from => { localStorage.setItem('uiLanguage', from); const to = from === 'en' ? 'nb' : 'en'; @@ -352,7 +481,7 @@ test('late generation cannot offer another application the previous application fireEvent.change(screen.getByLabelText(translations.en.coverAiAdditionalInstructions), { target: { value: 'Private instructions for application seven' } }); fireEvent.click(screen.getByRole('button', { name: translations.en.interviewAiGenerate })); await waitFor(() => expect(mockedApi.post).toHaveBeenCalledTimes(1)); - view.rerender(); + await act(async () => view.rerender()); await act(async () => finish({ data: { result: { text: 'Only for application seven' } } })); const assistant = within(screen.getByRole('region', { name: translations.en.interviewAiTitle })); expect(assistant.queryByText('Only for application seven')).not.toBeInTheDocument(); @@ -368,7 +497,7 @@ test('completed AI suggestion is scoped to its application instead of becoming a await screen.findByText('Backend CV'); fireEvent.click(screen.getByRole('button', { name: translations.en.interviewAiGenerate })); expect(await screen.findByText('Prepared for application seven only')).toBeVisible(); - view.rerender(); + await act(async () => view.rerender()); const assistant = within(screen.getByRole('region', { name: translations.en.interviewAiTitle })); expect(assistant.queryByText('Prepared for application seven only')).not.toBeInTheDocument(); expect(assistant.queryByRole('button', { name: translations.en.interviewAiAddToPrep })).not.toBeInTheDocument(); @@ -385,7 +514,7 @@ test('late accepted suggestion does not reload the previous application board in await screen.findByText('Application seven suggestion'); fireEvent.click(screen.getByRole('button', { name: translations.en.interviewAiAddToPrep })); await waitFor(() => expect(mockedApi.post).toHaveBeenCalledTimes(2)); - view.rerender(); + await act(async () => view.rerender()); await waitFor(() => expect(mockedApi.get).toHaveBeenCalledWith('/jobapplications/8/interview-prep')); await act(async () => finish({ data: board.groups[0].items[0] })); expect(mockedApi.get.mock.calls.filter(([url]) => url === '/jobapplications/7/interview-prep')).toHaveLength(1); @@ -444,7 +573,7 @@ test.each(['en', 'nb'] as const)('changing application hides the previous linked mockedApi.get.mockImplementation((url: string) => url === '/jobapplications/8/cv' ? pending as any : read(url)); const view = render(); await screen.findByText('Backend CV'); - view.rerender(); + await act(async () => view.rerender()); const assistant = within(screen.getByRole('region', { name: translations[language].interviewAiTitle })); expect(assistant.queryByText('Backend CV')).not.toBeInTheDocument(); expect(assistant.getByRole('progressbar', { name: translations[language].loading })).toBeVisible();