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.
78 lines
5.2 KiB
JavaScript
78 lines
5.2 KiB
JavaScript
import {test,expect} from 'bun:test';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import {_internal as I} from '../index.mjs';
|
|
|
|
// Where Kimi's Work sign-in is looked for on each system, the way Kimi
|
|
// 3.2.21's main process finds daimon-share: <userData>/daimon-storage.json's
|
|
// shareDir, else <userData>/daimon-share (#425).
|
|
const files=m=>file=>{if(!(file in m))throw Object.assign(Error('ENOENT'),{code:'ENOENT'});return m[file];};
|
|
|
|
test('each system\'s default, with no pointer',()=>{
|
|
const none=files({});
|
|
expect(I.desktopFile({platform:'win32',home:'C:\\Users\\u',appdata:'C:\\Users\\u\\AppData\\Roaming',read:none}))
|
|
.toBe('C:\\Users\\u\\AppData\\Roaming\\kimi-desktop\\daimon-share\\daimon\\config.json');
|
|
expect(I.desktopFile({platform:'win32',home:'C:\\Users\\u',appdata:'',read:none}))
|
|
.toBe('C:\\Users\\u\\AppData\\Roaming\\kimi-desktop\\daimon-share\\daimon\\config.json');
|
|
expect(I.desktopFile({platform:'darwin',home:'/Users/u',read:none}))
|
|
.toBe('/Users/u/Library/Application Support/kimi-desktop/daimon-share/daimon/config.json');
|
|
expect(I.desktopFile({platform:'linux',home:'/home/u',read:none}))
|
|
.toBe('/home/u/.config/kimi-desktop/daimon-share/daimon/config.json');
|
|
});
|
|
|
|
test('Windows: Kimi installed on another drive keeps daimon-share where its pointer says',()=>{
|
|
// What Kimi 3.2.21 writes for a new user who installed it on D:.
|
|
const read=files({'C:\\Users\\u\\AppData\\Roaming\\kimi-desktop\\daimon-storage.json':
|
|
'\uFEFF'+JSON.stringify({version:1,shareDir:'D:\\KimiData\\daimon-share'})});
|
|
expect(I.desktopFile({platform:'win32',home:'C:\\Users\\u',appdata:'C:\\Users\\u\\AppData\\Roaming',read}))
|
|
.toBe('D:\\KimiData\\daimon-share\\daimon\\config.json');
|
|
});
|
|
|
|
test('macOS and Linux: storage the user moved is followed too',()=>{
|
|
const mac=files({'/Users/u/Library/Application Support/kimi-desktop/daimon-storage.json':JSON.stringify({version:1,shareDir:'/Volumes/X/KimiData/daimon-share'})});
|
|
expect(I.desktopFile({platform:'darwin',home:'/Users/u',read:mac})).toBe('/Volumes/X/KimiData/daimon-share/daimon/config.json');
|
|
const linux=files({'/home/u/.config/kimi-desktop/daimon-storage.json':JSON.stringify({version:1,shareDir:'/data/kimi/daimon-share/'})});
|
|
expect(I.desktopFile({platform:'linux',home:'/home/u',read:linux})).toBe('/data/kimi/daimon-share/daimon/config.json');
|
|
});
|
|
|
|
test('a pointer Kimi would not take leaves the default, as in Kimi',()=>{
|
|
const ptr='C:\\Users\\u\\AppData\\Roaming\\kimi-desktop\\daimon-storage.json',def='C:\\Users\\u\\AppData\\Roaming\\kimi-desktop\\daimon-share\\daimon\\config.json';
|
|
for(const body of ['not json','null','[]','{}',JSON.stringify({shareDir:''}),JSON.stringify({shareDir:' '}),
|
|
JSON.stringify({shareDir:'KimiData\\daimon-share'}),JSON.stringify({shareDir:42})])
|
|
expect(I.desktopFile({platform:'win32',home:'C:\\Users\\u',appdata:'C:\\Users\\u\\AppData\\Roaming',read:files({[ptr]:body})})).toBe(def);
|
|
});
|
|
|
|
test('the real reader follows a pointer on disk and reads the sign-in there',()=>{
|
|
const home=fs.mkdtempSync(path.join(os.tmpdir(),'kimi-work-ptr-'));
|
|
try{
|
|
const platform=process.platform==='win32'?'win32':process.platform==='darwin'?'darwin':'linux';
|
|
const data=I.userDataDir({home,platform,appdata:path.join(home,'AppData','Roaming')});
|
|
const share=path.join(home,'KimiData','daimon-share');
|
|
fs.mkdirSync(path.join(share,'daimon'),{recursive:true});fs.mkdirSync(data,{recursive:true});
|
|
fs.writeFileSync(path.join(share,'daimon','config.json'),JSON.stringify({credentials:{kimiCode:{apiKey:'synthetic-work',baseUrl:I.BASE},kimiWeb:{accessToken:'synthetic-web',userId:'fixture-user'}}}));
|
|
const opts={home,platform,appdata:path.join(home,'AppData','Roaming')};
|
|
// No pointer: the default folder, which has no sign-in.
|
|
expect(()=>I.readDesktop(I.desktopFile(opts))).toThrow();
|
|
fs.writeFileSync(path.join(data,'daimon-storage.json'),JSON.stringify({version:1,shareDir:share}));
|
|
expect(I.desktopFile(opts)).toBe(path.join(share,'daimon','config.json'));
|
|
expect(I.readDesktop(I.desktopFile(opts)).workToken).toBe('synthetic-work');
|
|
}finally{fs.rmSync(home,{recursive:true,force:true});}
|
|
});
|
|
|
|
test('a failed sign-in says which file it looked for, and a failed Work check is not called a missing sign-in',async()=>{
|
|
const missing=I.createPlugin({readSession:()=>I.readDesktop('/nowhere/kimi-desktop/daimon-share/daimon/config.json')});
|
|
const a=await (await missing.auth.methods[0].authorize()).callback();
|
|
expect(a.type).toBe('failed');
|
|
expect(a.error).toContain('/nowhere/kimi-desktop/daimon-share/daimon/config.json');
|
|
const session={uid:'u',workToken:'synthetic-work-token',webToken:'w'};
|
|
const down=I.createPlugin({readSession:()=>session,fetchImpl:async()=>{throw Object.assign(TypeError('fetch failed'),{cause:{code:'ECONNRESET'}});}});
|
|
const b=await (await down.auth.methods[0].authorize()).callback();
|
|
expect(b.type).toBe('failed');
|
|
expect(b.error).toContain('ECONNRESET');
|
|
expect(b.error).not.toContain('没有可用');
|
|
expect(b.error).not.toContain(session.workToken);
|
|
const gone=I.createPlugin({readSession:()=>session,fetchImpl:async()=>new Response('{}',{status:401})});
|
|
expect((await (await gone.auth.methods[0].authorize()).callback()).error).toContain('过期');
|
|
});
|