mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-05 00:28:51 +01:00
Found by using the page. The Terminal was scoped to `loki` — the breadcrumb said `loki`, and the Profile/Chat/Control/Terminal strip linked to `/control?focus=loki` and `/loki?project=loki`. Two inches below, in the same render: "Open on Control" -> /control (scope dropped) "Ask Loki" -> /loki (scope dropped) the launch form -> "Bitbaum" (first project in the list) So the one obvious button on an empty terminal would have started Claude in the wrong repository, and nothing on screen said so. The cause is that this screen had its own idea of "the current project": the ATTACHED tab, which is null exactly here — nothing is running, that is why the empty state renders at all. Everything derived from it quietly lost the scope the page was still displaying. The page already had the right answer. `fleet-context` is the SSOT the tab strip reads, and TerminalSurface already WROTE to it (rememberFleetProject) without ever reading it back. So this is mostly deletion: the reader is extracted from FleetSurfaceGuide into useFleetProject() and used in both places, rather than copied into a second one. Two details worth keeping: - The launcher DERIVES its selection instead of seeding useState. The scope is null on the first render (it comes from a store the server cannot read) and real a tick later, so an initialiser would capture the null and go back to picking the first project — the bug, reintroduced by the fix. Same shape the agent select already used: the operator's own pick wins, and until they make one the scope answers. - A project in scope but not launchable is still not pre-selected. `launchable` is filtered to projects with a linked directory; offering one without would draw a button that fails every time. preferredLaunchProject is pure and exported so the rule is pinned without React — the defect is invisible to any test that renders nothing, and reads as a styling choice on screen. Proved by mutation: restoring the old rule fails 2 of the 5 cases with "expected loki, got Bitbaum". verify: format:check, tsc, lint (0 errors, 2 pre-existing warnings), check:design (10), check:desktop, test:home 140/140, and every check:*/gate member green. test:unit 200/202 — activity-time-zone-stable and telegram-allowlist fail with "probe failed:" and an empty reason; both need a live server and this diff touches neither them nor anything they import. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
71 lines
2.9 KiB
TypeScript
71 lines
2.9 KiB
TypeScript
/**
|
|
* Which project the Terminal's empty state offers to start an agent in.
|
|
*
|
|
* Found by using the page: the terminal was scoped to `loki` — the breadcrumb
|
|
* said so and the tab strip linked to `/control?focus=loki` — while the launch
|
|
* form two inches below offered "Bitbaum", the first project in the list.
|
|
* Clicking the one obvious button would have started Claude in the wrong
|
|
* repository, and nothing on screen said so.
|
|
*
|
|
* Run: npx tsx scripts/test/terminal-launch-project.ts
|
|
*/
|
|
import { preferredLaunchProject } from "@/components/terminal/TerminalLaunch";
|
|
|
|
let failures = 0;
|
|
function check(name: string, fn: () => void) {
|
|
try {
|
|
fn();
|
|
console.log(` ✓ ${name}`);
|
|
} catch (err) {
|
|
failures++;
|
|
console.log(` ✗ ${name}`);
|
|
console.log(` ${err instanceof Error ? err.message : String(err)}`);
|
|
}
|
|
}
|
|
function assert(cond: boolean, msg: string) {
|
|
if (!cond) throw new Error(msg);
|
|
}
|
|
|
|
const P = (name: string) => ({ name, dir: `/home/g/dev/${name}`, agentPref: null });
|
|
const PROJECTS = [P("Bitbaum"), P("loki"), P("orangecat")];
|
|
|
|
console.log("terminal-launch-project:");
|
|
|
|
check("the project in scope wins over the first in the list", () => {
|
|
assert(
|
|
preferredLaunchProject(PROJECTS, "loki") === "loki",
|
|
`expected loki, got ${preferredLaunchProject(PROJECTS, "loki")}`,
|
|
);
|
|
});
|
|
|
|
check("with no project in scope it falls back to the first", () => {
|
|
// Not a guess — with nothing in scope there is no better answer, and an
|
|
// empty select would disable the only button on the screen.
|
|
assert(preferredLaunchProject(PROJECTS, null) === "Bitbaum", "null should fall back");
|
|
assert(preferredLaunchProject(PROJECTS, undefined) === "Bitbaum", "undefined should fall back");
|
|
assert(preferredLaunchProject(PROJECTS, "") === "Bitbaum", "empty string should fall back");
|
|
});
|
|
|
|
check("a scoped project that cannot be launched does not get pre-selected", () => {
|
|
// `launchable` is already filtered to projects with a linked directory.
|
|
// Offering one that is not in it would draw a button that fails every time.
|
|
assert(preferredLaunchProject(PROJECTS, "solon") === "Bitbaum", "unlaunchable must not win");
|
|
});
|
|
|
|
check("no projects at all yields no selection rather than throwing", () => {
|
|
assert(preferredLaunchProject([], "loki") === "", "empty list");
|
|
});
|
|
|
|
check("the rule is stable across the render where scope arrives", () => {
|
|
// THE BUG, pinned. The scope is null on the first render (it comes from a
|
|
// store the server cannot read) and real a tick later. A value captured once
|
|
// at mount would stay "Bitbaum" forever; a derived one corrects itself.
|
|
const first = preferredLaunchProject(PROJECTS, null);
|
|
const afterHydration = preferredLaunchProject(PROJECTS, "loki");
|
|
assert(first === "Bitbaum", "pre-hydration falls back");
|
|
assert(afterHydration === "loki", "post-hydration follows the scope");
|
|
});
|
|
|
|
console.log(failures === 0 ? "\nall passed" : `\n${failures} failed`);
|
|
process.exit(failures === 0 ? 0 : 1);
|