diff options
| author | Adam Malczewski <[email protected]> | 2026-06-24 02:04:46 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-24 02:04:46 +0900 |
| commit | 41ca91a959ae245e76e50f1b55c8b21592bc6c50 (patch) | |
| tree | 289be7c0df654e75b6bc7552dd38bf0b9bda852d /packages/system-prompt/src/resolver.test.ts | |
| parent | 3a688edee373cbbc291a149e50e1d2802e2e29a4 (diff) | |
| download | dispatch-41ca91a959ae245e76e50f1b55c8b21592bc6c50.tar.gz dispatch-41ca91a959ae245e76e50f1b55c8b21592bc6c50.zip | |
feat(system-prompt): rich system:os with WSL detection + Linux distro
system:os now returns a descriptive string instead of the raw platform:
- Linux: reads /etc/os-release for distro name (PRETTY_NAME or NAME+VERSION_ID)
- WSL detection: checks /proc/sys/fs/binfmt_misc/WSLInterop or 'microsoft'
in /proc/version — appends (WSL) to the distro string
- Non-Linux: returns process.platform as-is (darwin, win32, etc.)
Examples: 'Ubuntu 22.04 LTS', 'Ubuntu 22.04 LTS (WSL)', 'Debian 12',
'Linux (WSL)', 'darwin'. All file reads use injected fs adapters (testable).
7 new resolver tests. 1403 vitest pass. FE CR-9.
Diffstat (limited to 'packages/system-prompt/src/resolver.test.ts')
| -rw-r--r-- | packages/system-prompt/src/resolver.test.ts | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/packages/system-prompt/src/resolver.test.ts b/packages/system-prompt/src/resolver.test.ts index 0585a33..474c79a 100644 --- a/packages/system-prompt/src/resolver.test.ts +++ b/packages/system-prompt/src/resolver.test.ts @@ -75,6 +75,86 @@ describe("resolver", () => { }); }); + describe("system:os rich resolution", () => { + it("returns distro from /etc/os-release PRETTY_NAME on Linux", async () => { + const files = new Map<string, string>([ + ["/etc/os-release", 'PRETTY_NAME="Ubuntu 22.04 LTS"\nNAME="Ubuntu"\n'], + ]); + const map = await resolveVariables("/proj", { + spawn: failSpawn(), + fs: fakeFs(files), + platform: () => "linux", + }); + expect(map.get("system:os")).toBe("Ubuntu 22.04 LTS"); + }); + + it("falls back to NAME + VERSION_ID when no PRETTY_NAME", async () => { + const files = new Map<string, string>([ + ["/etc/os-release", 'NAME="Debian"\nVERSION_ID="12"\n'], + ]); + const map = await resolveVariables("/proj", { + spawn: failSpawn(), + fs: fakeFs(files), + platform: () => "linux", + }); + expect(map.get("system:os")).toBe("Debian 12"); + }); + + it("appends (WSL) when WSLInterop exists", async () => { + const files = new Map<string, string>([ + ["/etc/os-release", 'PRETTY_NAME="Ubuntu 22.04 LTS"\n'], + ["/proc/sys/fs/binfmt_misc/WSLInterop", "enabled\n"], + ]); + const map = await resolveVariables("/proj", { + spawn: failSpawn(), + fs: fakeFs(files), + platform: () => "linux", + }); + expect(map.get("system:os")).toBe("Ubuntu 22.04 LTS (WSL)"); + }); + + it("detects WSL via 'microsoft' in /proc/version", async () => { + const files = new Map<string, string>([ + ["/etc/os-release", 'PRETTY_NAME="Ubuntu 22.04 LTS"\n'], + ["/proc/version", "Linux version 5.15.153.1-microsoft-standard-WSL2\n"], + ]); + const map = await resolveVariables("/proj", { + spawn: failSpawn(), + fs: fakeFs(files), + platform: () => "linux", + }); + expect(map.get("system:os")).toBe("Ubuntu 22.04 LTS (WSL)"); + }); + + it("returns 'Linux (WSL)' when WSL detected but no distro info", async () => { + const files = new Map<string, string>([["/proc/sys/fs/binfmt_misc/WSLInterop", "enabled\n"]]); + const map = await resolveVariables("/proj", { + spawn: failSpawn(), + fs: fakeFs(files), + platform: () => "linux", + }); + expect(map.get("system:os")).toBe("Linux (WSL)"); + }); + + it("returns plain 'linux' when no os-release and no WSL", async () => { + const map = await resolveVariables("/proj", { + spawn: failSpawn(), + fs: fakeFs(new Map()), + platform: () => "linux", + }); + expect(map.get("system:os")).toBe("linux"); + }); + + it("returns platform as-is for non-Linux (darwin)", async () => { + const map = await resolveVariables("/proj", { + spawn: failSpawn(), + fs: fakeFs(new Map()), + platform: () => "darwin", + }); + expect(map.get("system:os")).toBe("darwin"); + }); + }); + describe("file variables", () => { it("reads a file relative to cwd", async () => { // 12. file variable reads relative path; missing → null |
