()
| 138 | }, [open, step]); |
| 139 | |
| 140 | const poll = async (): Promise<void> => { |
| 141 | const tracked = jobRef.current; |
| 142 | if (!tracked || !Number.isInteger(tracked.slot) || tracked.slot < 0 || pollPending.current || tracked.status === 'done' || tracked.phase === 'failed') return; |
| 143 | clearTimeout(timer.current); |
| 144 | pollPending.current = true; setReadingStatus(true); |
| 145 | const current = () => alive.current && jobRef.current?.id === tracked.id; |
| 146 | try { |
| 147 | const jobs = await source.indexJobs(); |
| 148 | if (!current()) return; |
| 149 | const found = jobs.find(candidate => candidate.slot === tracked.slot); |
| 150 | if (!found || !samePath(found.path, tracked.path) || found.status === 'unknown') { |
| 151 | updateJob({ ...tracked, status: 'error', phase: 'lost', message: 'This job is no longer identifiable in the server status. Completion is unconfirmed.' }); |
| 152 | return; |
| 153 | } |
| 154 | if (found.status === 'error') { |
| 155 | updateJob({ ...tracked, status: 'error', phase: 'failed', message: found.error || 'The server reported an indexing failure.' }); |
| 156 | return; |
| 157 | } |
| 158 | if (found.status === 'indexing') { |
| 159 | updateJob({ ...tracked, status: 'indexing', phase: 'running', message: 'Indexing source and relationships…' }); |
| 160 | return; |
| 161 | } |
| 162 | updateJob({ ...tracked, status: 'indexing', phase: 'verifying', message: 'Indexing finished. Checking the project…' }); |
| 163 | const [projects, health] = await Promise.all([source.listProjects(), source.projectHealth(tracked.name)]); |
| 164 | if (!current()) return; |
| 165 | const project = projects.find(candidate => candidate.name === tracked.name); |
| 166 | setEntries(projects); setListStatus('ready'); |
| 167 | if (project && samePath(project.root_path, tracked.path) && health.status === 'healthy') { |
| 168 | updateJob({ ...tracked, status: 'done', phase: 'finished', message: 'The project index is ready to explore.' }); |
| 169 | } else if ((project?.root_path && !samePath(project.root_path, tracked.path)) || health.status === 'corrupt') { |
| 170 | updateJob({ ...tracked, status: 'error', phase: 'failed', message: health.status === 'corrupt' |
| 171 | ? 'The index could not be verified as healthy. Inspect its errors in System.' |
| 172 | : 'The returned project belongs to a different folder. This index was not verified.' }); |
| 173 | } else { |
| 174 | updateJob({ ...tracked, status: 'indexing', phase: 'unavailable', message: 'The job finished, but its project index could not be verified yet. Check again.' }); |
| 175 | } |
| 176 | } catch { |
| 177 | if (current()) updateJob({ ...tracked, phase: 'unavailable', message: 'Status is unavailable. The job may still be running; retry the status check.' }); |
| 178 | } finally { |
| 179 | pollPending.current = false; |
| 180 | if (alive.current) setReadingStatus(false); |
| 181 | const latest = jobRef.current; |
| 182 | if (alive.current && latest?.id === tracked.id && latest.status === 'indexing' && (latest.phase === 'running' || latest.phase === 'verifying')) { |
| 183 | timer.current = setTimeout(() => { void pollRef.current(); }, Math.max(1, pollMs)); |
| 184 | } |
| 185 | } |
| 186 | }; |
| 187 | pollRef.current = poll; |
| 188 | |
| 189 | const folderDuplicate = entries.find(entry => samePath(entry.root_path, selectedPath)); |
nothing calls this directly
no test coverage detected