mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-07 07:59:42 +02:00
fix(cases): tell an unreachable path from an absent one, scope the stall cap
The bounded path probe answered "absent" both when a path did not exist and
when it simply did not answer, so a stalled linked case 404'd and the Run
button scaffolded a stray local case over it, and two stalled paths anywhere
made every unrelated path read as absent (hooks skipped, statusLine
overridden, the clone warning lost).
- probePath()/probePathKind() are tri-state: present (or directory/file),
absent (ENOENT/ENOTDIR only) and unknown (timeout, other errors, refusal).
boundedPathExists() stays as the display-only boolean.
- A stalled path takes only its own mount out of probing (deepest mount
point from /proc/self/mounts, never /; just the path itself when there is
no mount table). Unrelated paths keep probing. The process-wide cap is a
backstop that answers unknown, and a single-path user request can probe
past it ({ pastCap: true }), still bounded and still recorded as stalled.
One console.warn when a path first stalls and one when the cap engages.
- GET /api/cases/:name keeps NOT_FOUND for definite absence only. An
unreachable linked case answers with its registered path and
unreachable: true; a local one answers OPERATION_FAILED. runClaude and
runShell create a case only on errorCode NOT_FOUND. The case list keeps an
unreachable linked case, marked unreachable, instead of dropping it, and
fix-plan reports an unreadable plan as an error, not "no plan".
- applyWorkspaceHooks and the statusLine helpers skip only a workspace that
is absent or on the stalled mount; a capacity refusal no longer stops
hooks being installed elsewhere, and an unreadable settings file never
lets the exporter override a user's own statusLine.
- The clone flow's repo-settings warning is back on its synchronous check,
and stripCaseEnvKeys uses pathExistsForWrite.
- POST /api/sessions (workingDir) and POST /api/quick-start (case folder)
probe with the bounded probe instead of statSync/existsSync. Missing and
non-directory keep INVALID_INPUT; unknown is OPERATION_FAILED, and
quick-start never scaffolds over a folder that did not answer.
- PATH_PROBE_TIMEOUT_MS and MAX_STALLED_PATH_PROBES move to
src/config/path-probe.ts, overridable via CODEMAN_PATH_PROBE_TIMEOUT_MS
(default 1500) and CODEMAN_PATH_PROBE_MAX_STALLED (default 3), and are
documented in the Settings Reference.
- The probe is exported from the utils barrel and imported from there.
This commit is contained in:
@@ -1227,4 +1227,66 @@ describe('Grok quick start', () => {
|
||||
expect(names).toEqual(['w1-grok-case', 'w2-grok-case', 'w3-grok-case']);
|
||||
expect(selected).toEqual(['sess-gk-0']);
|
||||
});
|
||||
|
||||
describe('case lookup before a local launch', () => {
|
||||
function loadLaunchHarness(caseAnswer: Record<string, unknown>) {
|
||||
const elements: Record<string, any> = {
|
||||
quickStartCase: { value: 'nas-case' },
|
||||
shellCount: { value: '1' },
|
||||
tabCount: { value: '1' },
|
||||
};
|
||||
const requests: Array<{ url: string; method?: string }> = [];
|
||||
const written: string[] = [];
|
||||
const CodemanApp = function CodemanApp(this: any) {};
|
||||
const context = vm.createContext({
|
||||
CodemanApp,
|
||||
localStorage: { getItem: () => null, setItem: () => {} },
|
||||
document: { getElementById: (id: string) => elements[id] ?? null },
|
||||
fetch: async (url: string, init?: { method?: string }) => {
|
||||
requests.push({ url, method: init?.method });
|
||||
if (url === '/api/cases/nas-case') return { json: async () => caseAnswer };
|
||||
if (url === '/api/cases' && init?.method === 'POST') {
|
||||
return {
|
||||
json: async () => ({
|
||||
success: true,
|
||||
data: { case: { name: 'nas-case', path: '/home/u/codeman-cases/nas-case' } },
|
||||
}),
|
||||
};
|
||||
}
|
||||
// Anything past the case lookup is out of scope here: stop the launch.
|
||||
throw new Error(`stop: ${url}`);
|
||||
},
|
||||
console,
|
||||
});
|
||||
const sessionUi = readFileSync(resolve(import.meta.dirname, '../src/web/public/session-ui.js'), 'utf8');
|
||||
vm.runInContext(sessionUi, context, { filename: 'session-ui.js' });
|
||||
const app = new (CodemanApp as any)();
|
||||
app.terminal = { clear: () => {}, writeln: (line: string) => written.push(line), focus: () => {} };
|
||||
app.sessions = new Map();
|
||||
app.cases = [];
|
||||
app.getTerminalDimensions = () => null;
|
||||
app._readTabCount = () => 1;
|
||||
app.loadAppSettingsFromStorage = () => ({});
|
||||
app.getCaseSettings = () => ({});
|
||||
return { app, requests, written };
|
||||
}
|
||||
|
||||
const unreachable = { success: false, error: 'Case folder is not responding', errorCode: 'OPERATION_FAILED' };
|
||||
const missing = { success: false, error: 'Case not found', errorCode: 'NOT_FOUND' };
|
||||
|
||||
for (const launcher of ['runClaude', 'runShell'] as const) {
|
||||
it(`${launcher} never creates a case when the lookup could not tell whether it exists`, async () => {
|
||||
const { app, requests, written } = loadLaunchHarness(unreachable);
|
||||
await app[launcher]();
|
||||
expect(requests.some((r) => r.url === '/api/cases' && r.method === 'POST')).toBe(false);
|
||||
expect(written.join('\n')).toContain('Case folder is not responding');
|
||||
});
|
||||
|
||||
it(`${launcher} creates the case when the lookup says it does not exist`, async () => {
|
||||
const { app, requests } = loadLaunchHarness(missing);
|
||||
await app[launcher]();
|
||||
expect(requests.some((r) => r.url === '/api/cases' && r.method === 'POST')).toBe(true);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user