Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

test(fs): align cp overwrite integration expectation (#4809)

zgy2eb36eabbd6b
diff --git a/examples/openclaw-plugin/shared/recall-compress-core.mjs b/examples/openclaw-plugin/shared/recall-compress-core.mjs
index 6f8fe485b..1ced4cf4d 100644
--- a/examples/openclaw-plugin/shared/recall-compress-core.mjs
+++ b/examples/openclaw-plugin/shared/recall-compress-core.mjs
@@ -86,10 +86,16 @@ export function repairDigestUris(digest, validUris = []) {
lines.push(line);
continue;
}
+ let tokenized = line;
+ for (const uri of [...valid].sort((a, b) => b.length - a.length)) {
+ if (/\s/.test(uri)) tokenized = tokenized.split(uri).join(encodeURI(uri));
+ }
let dropped = false;
- const repaired = line.replace(/viking:\/\/[^\s<>"')\]]+/g, (uri) => {
- if (validSet.has(uri)) return uri;
- const nearest = nearestUri(uri, valid);
+ const repaired = tokenized.replace(/viking:\/\/[^\s<>"')\]]+/g, (uri) => {
+ let decoded = uri;
+ try { decoded = decodeURI(uri); } catch { /* keep the original candidate */ }
+ if (validSet.has(decoded)) return decoded;
+ const nearest = nearestUri(decoded, valid);
if (nearest) return nearest;
dropped = true;
return uri;
@@ -149,6 +155,7 @@ async function writeCache(path, value) {
export async function compressRecallContext({
query,
rendered,
+ shortContext = rendered,
entries = [],
cfg = {},
runCompressor,
@@ -158,7 +165,9 @@ export async function compressRecallContext({
const input = String(rendered || "").trim();
if (!input) return { status: COMPRESS_EMPTY, context: "" };
const minChars = Math.max(0, Number(cfg.recallCompressMinInputChars ?? 1500));
- if (input.length < minChars) return { status: COMPRESS_OK, context: input };
+ if (input.length < minChars) {
+ return { status: COMPRESS_OK, context: String(shortContext ?? input).trim() };
+ }
const maxInputChars = Math.max(1000, Number(cfg.recallCompressMaxInputChars || 18000));
const maxBullets = Math.max(1, Number(cfg.recallCompressMaxBullets || 6));
@@ -171,7 +180,8 @@ export async function compressRecallContext({
});
const cached = await readCache(cachePath);
if (cached?.key === key && typeof cached.digest === "string") {
- return { status: COMPRESS_OK, context: cached.digest };
+ const digest = normalizeCompressedContext(cached.digest, 4000, maxBullets);
+ if (digest) return { status: COMPRESS_OK, context: digest };
}
const prompt = buildRecallCompressionPrompt({
@@ -185,9 +195,10 @@ export async function compressRecallContext({
if (!normalized) return { status: COMPRESS_EMPTY, context: "" };
const validUris = entries.map((entry) => entry?.uri).filter(Boolean);
- const digest = repairDigestUris(normalized, validUris.length
+ const repaired = repairDigestUris(normalized, validUris.length
? validUris
: (input.match(/viking:\/\/[^\s<>"']+/g) || []));
+ const digest = normalizeCompressedContext(repaired, 4000, maxBullets);
if (!digest) return { status: COMPRESS_FAILED, context: "" };
await writeCache(cachePath, { key, digest, updatedAt: now || 0 });
diff --git a/tests/api_test/filesystem/test_fs_cp.py b/tests/api_test/filesystem/test_fs_cp.py
index 8c360da7c..c0ad58572 100644
--- a/tests/api_test/filesystem/test_fs_cp.py
+++ b/tests/api_test/filesystem/test_fs_cp.py
@@ -69,10 +69,10 @@ class TestFsCp:
api_client.fs_rm(source, recursive=True)
api_client.fs_rm(target, recursive=True)
- def test_cp_rejects_existing_target_without_changing_either_file(self, api_client):
+ def test_cp_overwrites_existing_target_and_preserves_source(self, api_client):
suffix = uuid.uuid4().hex[:8]
- source = f"viking://resources/cp-conflict-source-{suffix}.md"
- target = f"viking://resources/cp-conflict-target-{suffix}.md"
+ source = f"viking://resources/cp-overwrite-source-{suffix}.md"
+ target = f"viking://resources/cp-overwrite-target-{suffix}.md"
try:
assert (
api_client.fs_write(source, "source remains", mode="create", wait=True).status_code
@@ -84,9 +84,9 @@ class TestFsCp:
)
copied = api_client.fs_cp(source, target)
- assert copied.status_code == 409, copied.text
+ assert copied.status_code == 200, copied.text
assert "source remains" in api_client.fs_read(source).json().get("result", "")
- assert "target remains" in api_client.fs_read(target).json().get("result", "")
+ assert "source remains" in api_client.fs_read(target).json().get("result", "")
finally:
api_client.fs_rm(source)
api_client.fs_rm(target)