fix: resume sessions with missing workdir (#1517)

This commit is contained in:
Luyu Cheng 2026-07-09 16:46:57 +08:00 committed by GitHub
parent 9fb19154ac
commit 173bdfdab1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---
Fix resuming sessions whose original working directory no longer exists.

View file

@ -48,7 +48,7 @@ export class ConfigState {
});
if (changed.cwd) {
this._cwd = changed.cwd;
void this.agent.kaos.chdir(changed.cwd);
this.agent.setKaos(this.agent.kaos.withCwd(changed.cwd));
}
if (changed.modelAlias) {
this._modelAlias = changed.modelAlias;

View file

@ -4,8 +4,27 @@ import { emptyUsage } from '@moonshot-ai/kosong';
import { ProviderManager } from '../../src/session/provider-manager';
import type { KimiConfig } from '../../src/config';
import { testAgent } from './harness';
import { createFakeKaos } from '../tools/fixtures/fake-kaos';
describe('ConfigState model capabilities', () => {
it('updates the agent cwd without requiring the directory to exist', () => {
const chdir = vi.fn(async () => {
throw Object.assign(new Error('missing workspace'), { code: 'ENOENT' });
});
const ctx = testAgent({
kaos: createFakeKaos({
getcwd: () => '/workspace',
chdir,
}),
});
ctx.agent.config.update({ cwd: '/tmp/missing-workdir' });
expect(ctx.agent.config.cwd).toBe('/tmp/missing-workdir');
expect(ctx.agent.kaos.getcwd()).toBe('/tmp/missing-workdir');
expect(chdir).not.toHaveBeenCalled();
});
it('computes provider and model capabilities from ProviderManager metadata', () => {
const ctx = testAgent({
providerManager: new ProviderManager({

View file

@ -32,9 +32,9 @@ export function createFakeKaos(
overrides?: Partial<Kaos>,
envLayers: readonly Record<string, string>[] = [],
): Kaos {
// Hold cwd in a closure so `chdir` (which `config.update({cwd})` now
// routes through) can mutate it and later `getcwd()` calls see the
// update — mirroring real-kaos semantics without needing a backing fs.
// Hold cwd in a closure so tests that call `chdir` directly can mutate it
// and later `getcwd()` calls see the update — mirroring real-kaos semantics
// without needing a backing fs.
let cwd = overrides?.getcwd?.() ?? '/workspace';
const base: Kaos = {
name: 'fake',