fix(file-reference-resolver): expand env vars in path references

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-27 17:45:27 +09:00
parent 5e4aa8b827
commit a46b7b8240
2 changed files with 68 additions and 6 deletions
+56 -2
View File
@@ -1,8 +1,62 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test"
import { mkdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
import { join } from "node:path"
import { resolveFileReferencesInText } from "./file-reference-resolver"
import { join, resolve } from "node:path"
import { resolveFilePath, resolveFileReferencesInText } from "./file-reference-resolver"
describe("resolveFilePath", () => {
const cwd = "/skills/gsd"
test("expands bare environment variables before resolving absolute paths", () => {
//#given
const homeDir = process.env.HOME
if (!homeDir) {
throw new Error("HOME must be set for file reference resolver tests")
}
//#when
const resolved = resolveFilePath("$HOME/foo.md", cwd)
//#then
expect(resolved).toBe(resolve(homeDir, "foo.md"))
})
test("expands braced environment variables before resolving absolute paths", () => {
//#given
const homeDir = process.env.HOME
if (!homeDir) {
throw new Error("HOME must be set for file reference resolver tests")
}
//#when
const resolved = resolveFilePath("${HOME}/foo.md", cwd)
//#then
expect(resolved).toBe(resolve(homeDir, "foo.md"))
})
test("keeps absolute paths absolute", () => {
//#given
const absolutePath = "/abs/path.md"
//#when
const resolved = resolveFilePath(absolutePath, cwd)
//#then
expect(resolved).toBe(resolve(absolutePath))
})
test("resolves relative paths from cwd", () => {
//#given
const relativePath = "relative/path.md"
//#when
const resolved = resolveFilePath(relativePath, cwd)
//#then
expect(resolved).toBe(resolve(cwd, relativePath))
})
})
describe("resolveFileReferencesInText", () => {
const fixtureRoot = join(tmpdir(), `file-reference-resolver-${Date.now()}`)