@@ -6,6 +6,7 @@ import { describe, expect, it } from "vitest";
66import type { OpenClawConfig } from "../config/config.js" ;
77import type { SessionEntry } from "../config/sessions.js" ;
88import { withEnv } from "../test-utils/env.js" ;
9+ import { findOverlappingWorkspaceAgentIds } from "./agent-delete-safety.js" ;
910import {
1011 clearAutoFallbackPrimaryProbeSelection ,
1112 hasLegacyAutoFallbackWithoutOrigin ,
@@ -1128,6 +1129,34 @@ describe("resolveAgentConfig", () => {
11281129} ) ;
11291130
11301131describe ( "resolveAgentIdByWorkspacePath" , ( ) => {
1132+ it . runIf ( process . platform === "linux" ) (
1133+ "keeps distinct Unicode workspace directories under their own agents" ,
1134+ ( ) => {
1135+ const root = fs . realpathSync ( fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "workspace-unicode-" ) ) ) ;
1136+ const composed = path . join ( root , "caf\u00e9" ) ;
1137+ const decomposed = path . join ( root , "cafe\u0301" ) ;
1138+ try {
1139+ fs . mkdirSync ( composed ) ;
1140+ fs . mkdirSync ( decomposed ) ;
1141+ const cfg : OpenClawConfig = {
1142+ agents : {
1143+ entries : {
1144+ composed : { workspace : composed } ,
1145+ decomposed : { workspace : decomposed } ,
1146+ } ,
1147+ } ,
1148+ } ;
1149+
1150+ expect ( fs . statSync ( composed ) . ino ) . not . toBe ( fs . statSync ( decomposed ) . ino ) ;
1151+ expect ( resolveAgentIdByWorkspacePath ( cfg , composed ) ) . toBe ( "composed" ) ;
1152+ expect ( resolveAgentIdByWorkspacePath ( cfg , decomposed ) ) . toBe ( "decomposed" ) ;
1153+ expect ( findOverlappingWorkspaceAgentIds ( cfg , "composed" , composed ) ) . toEqual ( [ ] ) ;
1154+ } finally {
1155+ fs . rmSync ( root , { recursive : true , force : true } ) ;
1156+ }
1157+ } ,
1158+ ) ;
1159+
11311160 it ( "returns the most specific workspace match for a directory" , ( ) => {
11321161 const workspaceRoot = `/tmp/openclaw-agent-scope-${ Date . now ( ) } -root` ;
11331162 const opsWorkspace = `${ workspaceRoot } /projects/ops` ;
@@ -1192,6 +1221,40 @@ describe("resolveAgentIdByWorkspacePath", () => {
11921221 fs . rmSync ( tempRoot , { recursive : true , force : true } ) ;
11931222 }
11941223 } ) ;
1224+
1225+ it ( "matches a dangling workspace symlink to its vanished target" , ( ) => {
1226+ const tempRoot = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-agent-scope-dangling-" ) ) ;
1227+ const workspaceDir = path . join ( tempRoot , "vanished-workspace" ) ;
1228+ const workspaceAliasDir = path . join ( tempRoot , "workspace-alias" ) ;
1229+ try {
1230+ fs . symlinkSync (
1231+ workspaceDir ,
1232+ workspaceAliasDir ,
1233+ process . platform === "win32" ? "junction" : "dir" ,
1234+ ) ;
1235+ const cfg : OpenClawConfig = {
1236+ agents : { list : [ { id : "ops" , workspace : workspaceAliasDir } ] } ,
1237+ } ;
1238+
1239+ expect ( resolveAgentIdByWorkspacePath ( cfg , workspaceDir ) ) . toBe ( "ops" ) ;
1240+ } finally {
1241+ fs . rmSync ( tempRoot , { recursive : true , force : true } ) ;
1242+ }
1243+ } ) ;
1244+
1245+ it ( "keeps a cyclic workspace alias bounded and separate from unrelated paths" , ( ) => {
1246+ const root = fs . realpathSync ( fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "workspace-cycle-" ) ) ) ;
1247+ const alias = path . join ( root , "alias" ) ;
1248+ try {
1249+ fs . symlinkSync ( alias , alias , process . platform === "win32" ? "junction" : "dir" ) ;
1250+ const cfg : OpenClawConfig = { agents : { entries : { ops : { workspace : alias } } } } ;
1251+
1252+ expect ( resolveAgentIdByWorkspacePath ( cfg , alias ) ) . toBe ( "ops" ) ;
1253+ expect ( resolveAgentIdByWorkspacePath ( cfg , path . join ( root , "other" ) ) ) . toBeUndefined ( ) ;
1254+ } finally {
1255+ fs . rmSync ( root , { recursive : true , force : true } ) ;
1256+ }
1257+ } ) ;
11951258} ) ;
11961259
11971260describe ( "resolveAgentSkillsFilter" , ( ) => {
0 commit comments