- the project picker has an "Add project" action: a folder browser starts at the server user's home, navigates (typed path, up, new folder) and adds the chosen folder through POST /api/openchamber/directory; the new project becomes the draft's target at once - refreshProjects merges settings-only projects (newest added first), so a project added before its first session still appears in the picker; the first session moves it into /api/project as usual - usageReading no longer hides the composer's context ring when the session's model has left the server catalog: a 200K window is assumed, the percentage is prefixed with "~", and the usage sheet says the window is estimated. A failed model fetch at connect is retried when a chat opens, so a normal session shows the real percentage - tests: the add-project browser flow, settings-only projects, and the estimated/known context readings
107 lines
3.1 KiB
Dart
107 lines
3.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:openchamber/api/models.dart';
|
|
import 'package:openchamber/state.dart';
|
|
|
|
void main() {
|
|
group('context reading', () {
|
|
late AppState app;
|
|
late ChatState chat;
|
|
|
|
setUp(() {
|
|
app = AppState();
|
|
chat = ChatState(app, Session(id: 'ses_a', title: '会话'));
|
|
});
|
|
|
|
tearDown(() {
|
|
chat.dispose();
|
|
app.dispose();
|
|
});
|
|
|
|
Message assistant() => Message(
|
|
id: 'a1',
|
|
type: 'assistant',
|
|
model: ModelRef('getdeepin/deepseek-flash', 'axonhub'),
|
|
tokens: TokenUsage(input: 33800, output: 810, cacheRead: 1792),
|
|
);
|
|
|
|
test('a known model reports its limit and no estimate', () {
|
|
app.modelLimits = {
|
|
'axonhub/getdeepin/deepseek-flash': (1000000, 100000),
|
|
};
|
|
chat.msgs = [assistant()];
|
|
|
|
final reading = chat.usageReading();
|
|
expect(reading.$1, 36402);
|
|
expect(reading.$2, 1000000);
|
|
expect(reading.$5, isTrue);
|
|
expect(reading.$6, isFalse);
|
|
});
|
|
|
|
test('an unknown model keeps the ring and marks the window estimated', () {
|
|
app.modelLimits = {};
|
|
chat.msgs = [assistant()];
|
|
|
|
final reading = chat.usageReading();
|
|
expect(reading.$5, isTrue);
|
|
expect(reading.$6, isTrue);
|
|
expect(reading.$2, ChatState.estimatedContextWindow);
|
|
expect(reading.$4, greaterThan(0));
|
|
});
|
|
|
|
test('no assistant tokens means no ring', () {
|
|
chat.msgs = [Message(id: 'u1', type: 'user')];
|
|
expect(chat.usageReading().$5, isFalse);
|
|
});
|
|
});
|
|
|
|
// The app can be in the background while a turn starts or ends; the events
|
|
// that said so never arrive, so the chat's running flag has to be taken
|
|
// from the server again when the app comes back.
|
|
group('reconciling a turn on return', () {
|
|
late AppState app;
|
|
late ChatState chat;
|
|
|
|
setUp(() {
|
|
app = AppState();
|
|
chat = ChatState(app, Session(id: 'ses_a', title: '会话'));
|
|
});
|
|
|
|
tearDown(() {
|
|
chat.dispose();
|
|
app.dispose();
|
|
});
|
|
|
|
test('the server saying idle ends a turn that was left running', () {
|
|
chat.running = true;
|
|
chat.reconcileRunning({'ses_other'}, known: true);
|
|
expect(chat.running, isFalse);
|
|
});
|
|
|
|
test('the server saying running keeps the strip, even without events', () {
|
|
chat.running = false;
|
|
chat.reconcileRunning({'ses_a'}, known: true);
|
|
expect(chat.running, isTrue);
|
|
});
|
|
|
|
test('the server not answering falls back on the transcript tail', () {
|
|
chat.running = false;
|
|
chat.msgs = [
|
|
Message(id: 'u1', type: 'user'),
|
|
Message(id: 'a1', type: 'assistant', completed: 100),
|
|
Message(id: 'u2', type: 'user'),
|
|
Message(id: 'a2', type: 'assistant'),
|
|
];
|
|
chat.reconcileRunning(const {}, known: false);
|
|
expect(chat.running, isTrue);
|
|
|
|
chat.running = true;
|
|
chat.msgs = [
|
|
Message(id: 'u1', type: 'user'),
|
|
Message(id: 'a1', type: 'assistant', completed: 100),
|
|
];
|
|
chat.reconcileRunning(const {}, known: false);
|
|
expect(chat.running, isFalse);
|
|
});
|
|
});
|
|
}
|