fix(v0.1): recover session PVC when prior create left session without storage

之前的失败用例会让 session 留在 storageKind=none 状态但 pvcName 缺失,
现在 POST /api/v1/sessions 在 storageKind=none || !storagePvcName 时
重新调 createSessionPvc 补建,action=session-storage-recovered。

selftest 覆盖:显式 reset storageKind=none 后第二次 POST 走 recovery。
This commit is contained in:
Codex
2026-06-03 19:59:49 +08:00
parent da797c907c
commit 4793ca154a
2 changed files with 13 additions and 2 deletions
+9 -2
View File
@@ -79,8 +79,15 @@ const selfTest: SelfTestCase = async () => {
const create = await client.post("/api/v1/sessions", { sessionId: "sess_rest_create_001", tenantId: "hwlab", projectId: "pikasTech/HWLAB", backendProfile: "codex" }) as { action: string; pvc: { pvcName: string; pvcPhase: string } };
assert.equal(create.action, "session-created");
assert.ok(create.pvc.pvcName.startsWith("agentrun-v01-session-"));
const existing = await client.post("/api/v1/sessions", { sessionId: "sess_rest_create_001", tenantId: "hwlab", projectId: "pikasTech/HWLAB", backendProfile: "codex" }) as { action: string };
assert.equal(existing.action, "session-exists");
const existing = await client.post("/api/v1/sessions", { sessionId: "sess_rest_create_001", tenantId: "hwlab", projectId: "pikasTech/HWLAB", backendProfile: "codex" }) as { action: string };
assert.equal(existing.action, "session-exists");
const recovered = await client.post("/api/v1/sessions", { sessionId: "sess_rest_create_002", tenantId: "hwlab", projectId: "pikasTech/HWLAB", backendProfile: "codex" }) as { action: string };
assert.equal(recovered.action, "session-created");
const recoveredFromNone = await client.post("/api/v1/sessions", { sessionId: "sess_rest_create_003", tenantId: "hwlab", projectId: "pikasTech/HWLAB", backendProfile: "codex" }) as { action: string };
assert.equal(recoveredFromNone.action, "session-created");
await restStore.refreshSessionStorage({ sessionId: "sess_rest_create_003", storageKind: "none", codexRolloutSubdir: "sessions" });
const recoveredAgain = await client.post("/api/v1/sessions", { sessionId: "sess_rest_create_003", tenantId: "hwlab", projectId: "pikasTech/HWLAB", backendProfile: "codex" }) as { action: string };
assert.equal(recoveredAgain.action, "session-storage-recovered");
} finally {
if (server.server.listening) await new Promise<void>((resolve) => server.server.close(() => resolve()));
}