mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 17:54:58 +00:00
fix(sandbox): restore SHA-1 in slugifySessionKey to preserve workspace dirs (#18503)
This commit is contained in:
committed by
Peter Steinberger
parent
d799a3994f
commit
f275611862
28
src/agents/sandbox/shared.test.ts
Normal file
28
src/agents/sandbox/shared.test.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { slugifySessionKey } from "./shared.js";
|
||||||
|
|
||||||
|
describe("slugifySessionKey", () => {
|
||||||
|
it("produces stable SHA-1 based slugs for existing workspace directories", () => {
|
||||||
|
// Hash stability is critical: changing the hash algorithm orphans existing
|
||||||
|
// sandbox workspace directories on upgrade (see #18503).
|
||||||
|
const slug = slugifySessionKey("agent:clawfront-dev:direct:23057054725");
|
||||||
|
expect(slug).toBe("agent-clawfront-dev-direct-23057-906dfaef");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses fallback for empty input", () => {
|
||||||
|
const slug = slugifySessionKey("");
|
||||||
|
expect(slug).toContain("session-");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses fallback for whitespace-only input", () => {
|
||||||
|
const slug = slugifySessionKey(" ");
|
||||||
|
expect(slug).toContain("session-");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("truncates base to 32 chars", () => {
|
||||||
|
const long = "a".repeat(100);
|
||||||
|
const slug = slugifySessionKey(long);
|
||||||
|
// 32 char base + "-" + 8 char hash = 41 chars
|
||||||
|
expect(slug.length).toBe(41);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
|
import crypto from "node:crypto";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { normalizeAgentId } from "../../routing/session-key.js";
|
import { normalizeAgentId } from "../../routing/session-key.js";
|
||||||
import { resolveUserPath } from "../../utils.js";
|
import { resolveUserPath } from "../../utils.js";
|
||||||
import { resolveAgentIdFromSessionKey } from "../agent-scope.js";
|
import { resolveAgentIdFromSessionKey } from "../agent-scope.js";
|
||||||
import { hashTextSha256 } from "./hash.js";
|
|
||||||
|
|
||||||
export function slugifySessionKey(value: string) {
|
export function slugifySessionKey(value: string) {
|
||||||
const trimmed = value.trim() || "session";
|
const trimmed = value.trim() || "session";
|
||||||
const hash = hashTextSha256(trimmed).slice(0, 8);
|
// SHA-1 is intentional: this is a non-security slug differentiator and changing
|
||||||
|
// the algorithm orphans existing workspace directories on upgrade (#18503).
|
||||||
|
const hash = crypto.createHash("sha1").update(trimmed).digest("hex").slice(0, 8);
|
||||||
const safe = trimmed
|
const safe = trimmed
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/[^a-z0-9._-]+/g, "-")
|
.replace(/[^a-z0-9._-]+/g, "-")
|
||||||
|
|||||||
Reference in New Issue
Block a user