Skip to content

Commit e3d9da4

Browse files
committed
fix(daemon): doctor names same-device sessions by address; green the fallow gate
- sessionChecks enumerated same-device sessions by SessionState.name: the printed close --session default was the exact unreachable recovery this PR removes elsewhere, the name-based dedupe hid two cwd-scoped default sessions from each other, and the evidence sessionStateDir pointed at <state>/sessions/default, which never exists. Candidates now come from listRefs() and report addresses. - findByDevice joins values/delete in .fallowrc.json usedClassMembers (same resolution false positive on this class; the call site is session-open-execution.ts). - the scoped-paths test narrows its response once instead of nine optional-chaining hops, which tripped the CRAP gate.
1 parent c81bf0b commit e3d9da4

4 files changed

Lines changed: 58 additions & 16 deletions

File tree

‎.fallowrc.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
]
193193
}
194194
],
195-
"usedClassMembers": ["name", "listActiveLeases", "delete", "values", "elapsedMs", "isExpired"],
195+
"usedClassMembers": ["name", "listActiveLeases", "delete", "values", "elapsedMs", "isExpired", "findByDevice"],
196196
"rules": {
197197
"unused-types": "error",
198198
"duplicate-exports": "off"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { expect, test } from 'vitest';
2+
import { makeSessionStore } from '../../../__tests__/test-utils/store-factory.ts';
3+
import { makeIosSession } from '../../../__tests__/test-utils/session-factories.ts';
4+
import { sessionChecks } from '../session-doctor-options.ts';
5+
6+
// The doctor's recovery command must carry each session's ADDRESS — the string `close --session`
7+
// accepts — and dedupe by address: two cwd-scoped implicit sessions both carry the public name
8+
// `default`, so a name compare hid them from each other and the printed
9+
// `close --session default` addressed neither (#2031/#1394).
10+
test('the same-device warning names the other session by its address, not its name', () => {
11+
const store = makeSessionStore();
12+
const here = 'cwd:aaaaaaaaaaaaaaaa:default';
13+
const other = 'cwd:bbbbbbbbbbbbbbbb:default';
14+
store.set(here, makeIosSession('default'));
15+
store.set(other, makeIosSession('default'));
16+
17+
const [check] = sessionChecks(store, here, store.get(here));
18+
19+
expect(check?.status).toBe('warn');
20+
expect(check?.summary).toContain(other);
21+
expect(check?.command).toContain(`--session ${other}`);
22+
expect(check?.command).not.toContain('--session default');
23+
expect(check?.evidence).toMatchObject({ session: here, sameDeviceSessions: [other] });
24+
});
25+
26+
test('a session alone on its device passes with its own address in evidence', () => {
27+
const store = makeSessionStore();
28+
const here = 'cwd:aaaaaaaaaaaaaaaa:default';
29+
store.set(here, makeIosSession('default'));
30+
31+
const [check] = sessionChecks(store, here, store.get(here));
32+
33+
expect(check?.status).toBe('pass');
34+
expect(check?.command).toBeUndefined();
35+
expect(check?.evidence).toMatchObject({ session: here });
36+
});

‎src/daemon/handlers/__tests__/session-inventory-scoped-paths.test.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,17 @@ test('session list resolves a cwd-scoped session directory from its store key',
4343
const response = await runSessionList();
4444

4545
expect(response?.ok).toBe(true);
46-
const sessions = (response?.ok ? response.data?.sessions : undefined) as
47-
| { name: string; sessionStateDir: string; runnerLogPath: string }[]
48-
| undefined;
49-
const session = sessions?.[0];
50-
expect(session).toBeDefined();
46+
if (!response?.ok) return;
47+
const sessions = response.data?.sessions as {
48+
name: string;
49+
sessionStateDir: string;
50+
runnerLogPath: string;
51+
}[];
52+
expect(sessions).toHaveLength(1);
53+
const session = sessions[0]!;
5154
// The public name stays what the caller typed …
52-
expect(session?.name).toBe('default');
55+
expect(session.name).toBe('default');
5356
// … while the reported paths point at the directory that actually holds the session.
54-
expect(path.basename(session?.sessionStateDir ?? '')).toBe('cwd_8bea844ab16aa9b3_default');
55-
expect(session?.runnerLogPath.startsWith(`${session?.sessionStateDir}${path.sep}`)).toBe(true);
57+
expect(path.basename(session.sessionStateDir)).toBe('cwd_8bea844ab16aa9b3_default');
58+
expect(session.runnerLogPath.startsWith(`${session.sessionStateDir}${path.sep}`)).toBe(true);
5659
});

‎src/daemon/handlers/session-doctor-options.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,19 @@ export function sessionChecks(
8787
session: SessionState | undefined,
8888
options: { remote?: boolean } = {},
8989
): DoctorCheck[] {
90+
// Candidates report their ADDRESS — the string `close --session` actually accepts — and the
91+
// current session is excluded by address too: two cwd-scoped sessions share the name
92+
// `default`, so a name compare would hide them from each other (#2031/#1394).
9093
const sameDeviceSessions = session
9194
? sessionStore
92-
.toArray()
95+
.listRefs()
9396
.filter(
9497
(candidate) =>
95-
candidate.name !== session.name &&
96-
candidate.device.platform === session.device.platform &&
97-
candidate.device.id === session.device.id,
98+
candidate.address !== sessionName &&
99+
candidate.session.device.platform === session.device.platform &&
100+
candidate.session.device.id === session.device.id,
98101
)
99-
.map((candidate) => candidate.name)
102+
.map((candidate) => candidate.address)
100103
: [];
101104

102105
if (!session) {
@@ -129,9 +132,9 @@ export function sessionChecks(
129132
? `agent-device close --session ${sameDeviceSessions[0]} --platform ${publicPlatformString(session.device)}`
130133
: undefined,
131134
evidence: {
132-
session: session.name,
135+
session: sessionName,
133136
sameDeviceSessions,
134-
sessionStateDir: sessionStore.resolveSessionDir(session.name),
137+
sessionStateDir: sessionStore.resolveSessionDir(sessionName),
135138
},
136139
},
137140
];

0 commit comments

Comments
 (0)