Skip to content

Commit 482ff8a

Browse files
committed
fix(doctor): make session artifact findings advisory
1 parent c5fb3e6 commit 482ff8a

4 files changed

Lines changed: 44 additions & 17 deletions

File tree

src/commands/doctor-session-snapshots.test.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ async function writeSessionStore(
6969
await fs.writeFile(storePath, JSON.stringify(store, null, 2));
7070
}
7171

72+
function readMainSessionEntry(raw: string): SessionEntry {
73+
const parsed = JSON.parse(raw) as Record<string, SessionEntry>;
74+
const entry = parsed["agent:main"];
75+
if (!entry) {
76+
throw new Error("expected agent:main session entry");
77+
}
78+
return entry;
79+
}
80+
81+
function readMainSkillsSnapshot(raw: string): NonNullable<SessionEntry["skillsSnapshot"]> {
82+
const snapshot = readMainSessionEntry(raw).skillsSnapshot;
83+
if (!snapshot) {
84+
throw new Error("expected agent:main skills snapshot");
85+
}
86+
return snapshot;
87+
}
88+
7289
describe("doctor session snapshot stale runtime metadata", () => {
7390
let root = "";
7491
let bundledSkillsDir = "";
@@ -175,7 +192,7 @@ describe("doctor session snapshot stale runtime metadata", () => {
175192
});
176193
expect(sessionSnapshotIssueToHealthFinding(issue)).toMatchObject({
177194
checkId: "core/doctor/session-snapshots",
178-
severity: "warning",
195+
severity: "info",
179196
path: storePath,
180197
target: stalePath,
181198
requirement: expect.stringContaining(bundledSkillsDir),
@@ -510,8 +527,9 @@ describe("doctor session snapshot repair (shouldRepair)", () => {
510527
});
511528

512529
const raw = await fs.readFile(storePath, "utf-8");
513-
expect(raw).not.toContain(stalePath);
514-
expect(raw).toContain(path.join(bundledSkillsDir, "doctor", "SKILL.md"));
530+
const snapshot = readMainSkillsSnapshot(raw);
531+
expect(snapshot.prompt).not.toContain(stalePath);
532+
expect(snapshot.prompt).toContain(path.join(bundledSkillsDir, "doctor", "SKILL.md"));
515533
expect(note).toHaveBeenCalledTimes(1);
516534
const [message] = note.mock.calls[0] as [string, string];
517535
expect(message).toContain("Repaired");
@@ -589,9 +607,13 @@ describe("doctor session snapshot repair (shouldRepair)", () => {
589607

590608
const raw = await fs.readFile(storePath, "utf-8");
591609
const expectedBaseDir = path.dirname(path.join(bundledSkillsDir, "doctor", "SKILL.md"));
592-
expect(raw).toContain(path.join(bundledSkillsDir, "doctor", "SKILL.md"));
593-
expect(raw).toContain(expectedBaseDir);
594-
expect(raw).not.toContain(path.join(root, "old-runtime"));
610+
const expectedPath = path.join(bundledSkillsDir, "doctor", "SKILL.md");
611+
const snapshot = readMainSkillsSnapshot(raw);
612+
const skill = snapshot.resolvedSkills?.[0];
613+
expect(skill?.filePath).toBe(expectedPath);
614+
expect(skill?.baseDir).toBe(expectedBaseDir);
615+
expect(skill?.sourceInfo.path).toBe(expectedPath);
616+
expect(skill?.sourceInfo.baseDir).toBe(expectedBaseDir);
595617
expect(note).toHaveBeenCalledTimes(1);
596618
const [message] = note.mock.calls[0] as [string, string];
597619
expect(message).toContain("Repaired");
@@ -630,9 +652,12 @@ describe("doctor session snapshot repair (shouldRepair)", () => {
630652
});
631653

632654
const raw = await fs.readFile(storePath, "utf-8");
633-
expect(raw).toContain(currentPath);
634-
expect(raw).toContain(path.dirname(currentPath));
635-
expect(raw).not.toContain(path.join(root, "old-runtime"));
655+
const snapshot = readMainSkillsSnapshot(raw);
656+
const repairedSkill = snapshot.resolvedSkills?.[0];
657+
expect(repairedSkill?.filePath).toBe(currentPath);
658+
expect(repairedSkill?.baseDir).toBe(path.dirname(currentPath));
659+
expect(repairedSkill?.sourceInfo.path).toBe(currentPath);
660+
expect(repairedSkill?.sourceInfo.baseDir).toBe(path.dirname(currentPath));
636661
expect(note).toHaveBeenCalledTimes(1);
637662
const [message] = note.mock.calls[0] as [string, string];
638663
expect(message).toContain("Repaired");
@@ -797,7 +822,8 @@ describe("doctor session snapshot repair (shouldRepair)", () => {
797822
expect(backupFiles.length).toBe(1);
798823

799824
const backupContent = await fs.readFile(path.join(dir, backupFiles[0]), "utf-8");
800-
expect(backupContent).toContain(stalePath);
825+
const backupSnapshot = readMainSkillsSnapshot(backupContent);
826+
expect(backupSnapshot.prompt).toContain(stalePath);
801827
});
802828

803829
it("is idempotent — second repair finds nothing", async () => {

src/commands/doctor-session-snapshots.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,13 @@ export function sessionSnapshotIssueToHealthFinding(
338338
): HealthFinding {
339339
return {
340340
checkId: SESSION_SNAPSHOTS_CHECK_ID,
341-
severity: "warning",
342-
message: `${issue.sessionKey} cached session metadata references an inactive runtime root.`,
341+
severity: "info",
342+
message: `${issue.sessionKey} cached session metadata references an inactive runtime root that can be cleaned up.`,
343343
path: issue.storePath,
344344
target: issue.cachedPath,
345345
requirement: `Current bundled skill path: ${issue.expectedPath}`,
346346
fixHint:
347-
"Run `openclaw doctor --fix` to rewrite stale cached session metadata paths, or start a fresh session after confirming history can be retired.",
347+
"To clean up the advisory artifact, run `openclaw doctor --fix` to rewrite stale cached session metadata paths, or start a fresh session after confirming history can be retired.",
348348
};
349349
}
350350

src/commands/doctor-session-transcripts.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ describe("doctor session transcript repair", () => {
178178
expect(issue?.filePath).toBe(filePath);
179179
expect(sessionTranscriptIssueToHealthFinding(issue)).toMatchObject({
180180
checkId: "core/doctor/session-transcripts",
181-
severity: "warning",
181+
severity: "info",
182182
path: filePath,
183183
fixHint: expect.stringContaining("openclaw doctor --fix"),
184184
});

src/commands/doctor-session-transcripts.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,11 @@ export function sessionTranscriptIssueToHealthFinding(
411411
: "";
412412
return {
413413
checkId: SESSION_TRANSCRIPTS_CHECK_ID,
414-
severity: "warning",
415-
message: `Session transcript contains legacy branch or provider metadata state.${metadata}`,
414+
severity: "info",
415+
message: `Session transcript has legacy branch or provider metadata that can be cleaned up.${metadata}`,
416416
path: issue.filePath,
417-
fixHint: "Run `openclaw doctor --fix` to rewrite affected transcripts to their active branch.",
417+
fixHint:
418+
"To clean up the advisory artifact, run `openclaw doctor --fix` to rewrite affected transcripts to their active branch.",
418419
};
419420
}
420421

0 commit comments

Comments
 (0)