main: boot the daemon at the last project, not HOME (T-352)

Confirmed root cause of the sidebar failure: a desktop launch starts in
HOME, which isn't a git repo, so resolveWorkspaceRoot returns HOME and
the daemon's pql/git/files all target HOME. pql then finds a stale
~/.pql/pql.db (left from earlier HOME-workdir runs) and errors
"pql.db is from an earlier schema" — exactly what the sidebars showed.
A manual refresh worked only because by then the workspace had swapped
to the repo. (Verified directly: `cd $HOME && pql ticket list` reproduces
the schema error against ~/.pql/pql.db.)

Settings confirmed the user is in the picker path (no startupSticky on
any recent), so nothing auto-opens the repo at boot and the daemon sits
on HOME until the project is opened.

Fix: resolve the startup workspace before boot — prefer the launch CWD
when it's a git repo, else fall back to app.lastProject (the repo). The
daemon now points at the real workspace from its first request, so the
sidebars load immediately without depending on swap/refetch timing. The
ProjectOpened refetch and swap serialization from 2.3.x stay in place for
genuine mid-session project switches.

Pure resolveStartupWorkspace() helper is unit-tested; app boot green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-11 12:32:18 +02:00
co-authored by Claude Opus 4.8
parent 46f84728d2
commit fc4021e98b
6 changed files with 86 additions and 3 deletions
+28
View File
@@ -246,4 +246,32 @@ void main() {
Directory.current = saved;
}
});
group('resolveStartupWorkspace (T-352)', () {
Directory dir(String p) => Directory(p);
test('uses the CWD when it is a git repo', () {
final root = resolveStartupWorkspace(cwdRoot: dir('/work/repo'), lastProject: '/home/user/other', isGitRepo: (d) => d.path == '/work/repo');
expect(root.path, '/work/repo');
});
test('falls back to lastProject when the CWD is not a repo (desktop launch in HOME)', () {
final root = resolveStartupWorkspace(
cwdRoot: dir('/home/user'),
lastProject: '/work/repo',
isGitRepo: (d) => d.path == '/work/repo', // HOME is not a repo
);
expect(root.path, '/work/repo');
});
test('keeps the CWD when neither it nor lastProject is a repo', () {
final root = resolveStartupWorkspace(cwdRoot: dir('/home/user'), lastProject: '/gone', isGitRepo: (_) => false);
expect(root.path, '/home/user');
});
test('keeps the CWD when lastProject is null/empty', () {
expect(resolveStartupWorkspace(cwdRoot: dir('/home/user'), lastProject: null, isGitRepo: (_) => false).path, '/home/user');
expect(resolveStartupWorkspace(cwdRoot: dir('/home/user'), lastProject: '', isGitRepo: (_) => false).path, '/home/user');
});
});
}