Files
yetone a9779ef864 kimi-work 0.1.12, kimi-desktop 0.1.4: Kimi's sign-in is read where daimon-storage.json points (#425)
Kimi 3.2.21 on Windows, installed on another drive than %APPDATA%'s,
keeps daimon-share at <install drive>\KimiData\daimon-share and writes
%APPDATA%\kimi-desktop\daimon-storage.json ({"version":1,"shareDir":...})
to point there. It writes the same pointer on any system when the user
moves its storage. Both packages read only
%APPDATA%\kimi-desktop\daimon-share, so the sign-in was "not found".

Read from Kimi's own code: Kimi-Setup-3.2.21.exe's app.asar,
out/main/index.js (string table decoded): the shareDir getter is
readPointer(userData) ?? join(userData, "daimon-share"); the pointer
reader takes an absolute shareDir and otherwise the default; the
"install-drive seed" writes the pointer on win32 when installRoot's drive
differs from userData's; driveDataDirName is "KimiData".

Both packages now follow the pointer the same way (unreadable, non-JSON
or non-absolute -> default, as Kimi does). kimi-work's sign-in failure
names the file it looked for, and a failed Work check (network, HTTP)
no longer says no sign-in was found.

Run at this tree (base fc2866f):
- Windows 11 box: installed Kimi 3.2.21 silently to D:\Kimi425, launched
  it once (no sign-in): it wrote daimon-storage.json with shareDir
  D:\KimiData\daimon-share and no daimon-share under %APPDATA%. Under
  bun 1.4.2 there the new desktopFile() is
  D:\KimiData\daimon-share\daimon\config.json; 0.1.11's path does not
  exist. Kimi uninstalled and its folders removed afterwards.
- New tests force win32, darwin and linux paths (tests/desktop-path.test.mjs,
  kimi-desktop/kimi-dir.test.mjs). Broken by hand (pointer ignored):
  3 of 6 kimi-work tests red.
- TMPDIR/HOME sandbox `bun test`: 2791 pass, 3 skip, 0 fail;
  `bun scripts/check.mjs`: ok.

Not tried: a signed-in Kimi on the other drive (no credentials were
entered), so a real Work request from D:\KimiData is untested. The
kimi-desktop adapter reads the folder once when it starts; storage moved
while it runs is seen on the next start.
2026-10-27 15:14:11 +08:00

27 lines
2.0 KiB
JavaScript

import { test, expect } from 'bun:test';
import { defaultKimiDirectory } from './adapter.mjs';
// Kimi's daimon folder on each system, as Kimi 3.2.21 finds it
// (magpie-community/plugins#425).
const files = m => file => { if (!(file in m)) throw Object.assign(Error('ENOENT'), { code: 'ENOENT' }); return m[file]; };
const win = { platform: 'win32', appdata: 'C:\\Users\\u\\AppData\\Roaming' };
test('each system\'s default with no pointer', () => {
expect(defaultKimiDirectory('C:\\Users\\u', { ...win, read: files({}) })).toBe('C:\\Users\\u\\AppData\\Roaming\\kimi-desktop\\daimon-share\\daimon');
expect(defaultKimiDirectory('/Users/u', { platform: 'darwin', read: files({}) })).toBe('/Users/u/Library/Application Support/kimi-desktop/daimon-share/daimon');
expect(defaultKimiDirectory('/home/u', { platform: 'linux', read: files({}) })).toBe('/home/u/.config/kimi-desktop/daimon-share/daimon');
});
test('the shareDir daimon-storage.json names, as Kimi on another Windows drive writes it', () => {
const read = files({ 'C:\\Users\\u\\AppData\\Roaming\\kimi-desktop\\daimon-storage.json': JSON.stringify({ version: 1, shareDir: 'D:\\KimiData\\daimon-share' }) });
expect(defaultKimiDirectory('C:\\Users\\u', { ...win, read })).toBe('D:\\KimiData\\daimon-share\\daimon');
const mac = files({ '/Users/u/Library/Application Support/kimi-desktop/daimon-storage.json': JSON.stringify({ version: 1, shareDir: '/Volumes/X/daimon-share' }) });
expect(defaultKimiDirectory('/Users/u', { platform: 'darwin', read: mac })).toBe('/Volumes/X/daimon-share/daimon');
});
test('a pointer Kimi would not take leaves the default', () => {
for (const body of ['nope', '{}', JSON.stringify({ shareDir: 'relative\\x' }), JSON.stringify({ shareDir: 1 })])
expect(defaultKimiDirectory('C:\\Users\\u', { ...win, read: files({ 'C:\\Users\\u\\AppData\\Roaming\\kimi-desktop\\daimon-storage.json': body }) }))
.toBe('C:\\Users\\u\\AppData\\Roaming\\kimi-desktop\\daimon-share\\daimon');
});