fix: persist role field in metadata, isolate role test from name fallback

Bugbot caught two real issues:
- writeMetadata() and readMetadata() never serialized the role field,
  so role=orchestrator was silently dropped on disk
- The role-based test used "app-orchestrator" as session name, so the
  name fallback caught it — role check was never actually exercised

Fix: add role to metadata read/write, rename test session to "app-99"
so only the role metadata path can protect it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Prateek 2026-02-27 08:40:07 +05:30
parent 6195441d9f
commit 38cabe170b
2 changed files with 6 additions and 3 deletions

View File

@ -759,8 +759,9 @@ describe("cleanup", () => {
}),
};
// Session with role=orchestrator but a non-standard name
writeMetadata(sessionsDir, "app-orchestrator", {
// Session with role=orchestrator but a name that does NOT end in "-orchestrator"
// so only the role metadata check can protect it (not the name fallback)
writeMetadata(sessionsDir, "app-99", {
worktree: "/tmp",
branch: "main",
status: "working",
@ -773,7 +774,7 @@ describe("cleanup", () => {
const result = await sm.cleanup();
expect(result.killed).toHaveLength(0);
expect(result.skipped).toContain("app-orchestrator");
expect(result.skipped).toContain("app-99");
});
it("skips orchestrator sessions by name fallback (no role metadata)", async () => {

View File

@ -99,6 +99,7 @@ export function readMetadata(dataDir: string, sessionId: SessionId): SessionMeta
project: raw["project"],
createdAt: raw["createdAt"],
runtimeHandle: raw["runtimeHandle"],
role: raw["role"],
dashboardPort: raw["dashboardPort"] ? Number(raw["dashboardPort"]) : undefined,
terminalWsPort: raw["terminalWsPort"] ? Number(raw["terminalWsPort"]) : undefined,
directTerminalWsPort: raw["directTerminalWsPort"] ? Number(raw["directTerminalWsPort"]) : undefined,
@ -141,6 +142,7 @@ export function writeMetadata(
if (metadata.project) data["project"] = metadata.project;
if (metadata.createdAt) data["createdAt"] = metadata.createdAt;
if (metadata.runtimeHandle) data["runtimeHandle"] = metadata.runtimeHandle;
if (metadata.role) data["role"] = metadata.role;
if (metadata.dashboardPort !== undefined)
data["dashboardPort"] = String(metadata.dashboardPort);
if (metadata.terminalWsPort !== undefined)