@@ -177,15 +177,24 @@ describe("qqbot media path resolution honors OPENCLAW_HOME (#83562)", () => {
|
177 | 177 | return dir; |
178 | 178 | } |
179 | 179 | |
| 180 | +function isPathInsideOrEqual(candidate: string, parent: string): boolean { |
| 181 | +const relative = path.relative(parent, candidate); |
| 182 | +return ( |
| 183 | +relative === "" || |
| 184 | +(!!relative && !relative.startsWith("..") && !path.isAbsolute(relative)) |
| 185 | +); |
| 186 | +} |
| 187 | + |
180 | 188 | it("accepts files under $OPENCLAW_HOME/.openclaw/media/qqbot when OPENCLAW_HOME differs from HOME", () => { |
181 | 189 | const fakeOpenclawHome = makeFakeOpenclawHome(); |
182 | | -// Sanity: the fake OPENCLAW_HOME must not be a subpath of the real OS home, |
183 | | -// otherwise the test would pass for the wrong reason on hosts where |
184 | | -// `os.tmpdir()` happens to live under `$HOME`. |
185 | | -expect(fakeOpenclawHome.startsWith(realOsHome)).toBe(false); |
186 | 190 | vi.stubEnv("OPENCLAW_HOME", fakeOpenclawHome); |
187 | 191 | |
188 | 192 | const mediaFile = path.join(fakeOpenclawHome, ".openclaw", "media", "qqbot", "repro.png"); |
| 193 | +// Sanity: the fixture must not be accepted by the previous HOME media root. |
| 194 | +// On Windows, `os.tmpdir()` commonly lives under the user profile, so a raw |
| 195 | +// HOME-prefix assertion would make this test fail for the wrong reason. |
| 196 | +const oldHomeMediaRoot = path.join(realOsHome, ".openclaw", "media", "qqbot"); |
| 197 | +expect(isPathInsideOrEqual(mediaFile, oldHomeMediaRoot)).toBe(false); |
189 | 198 | fs.mkdirSync(path.dirname(mediaFile), { recursive: true }); |
190 | 199 | fs.writeFileSync(mediaFile, "image", "utf8"); |
191 | 200 | |
|