halkyon/packages/halkyon_app/test/assistant/model/assistant_amount_test.dart
Tizian 「ティツィアーン」 36899cdc3b
feat(app,learn,todo): the assistants in Settings and on the operator's screen
ADR 0021, step 2's app half. halkyon_app asks the module's assistant
endpoints (ServerpodAssistantGateway, ServerpodAssistantOperatorGateway)
and a person's own provider directly (halkyon_llm), behind
AssistantRepository: an AssistantChoice is a GrantedAssistant, asked
through the instance, which counts it, or a PersonalAssistant with the
person's own key, which the instance never sees. assistant_messages.dart
turns a conversation into the endpoint's models and back.

AssistantsCard, for an app's settings: what is granted and left of its
limits, agreed to once on a sheet saying what goes where, the person's
use by UTC month, the instance's privacy page, and their own assistants
where the operator allows own keys (kept ones stay listed, unasked,
where it doesn't). AssistantGrantsCard on InstanceOperatorScreen: grants
by handle with their limits in the pricing's unit, changed and taken
back after asking, everyone's use by month; a found account's menu
grants too. Nothing shows where nothing is offered or can be read.
package:halkyon_app/assistant_models.dart holds the models in pure Dart.

Learn keeps own assistants in the person's settings (ownAssistants,
schema 12, SettingsOwnAssistants); SettingsRepository.update refuses
(OwnAssistantRefused) to write a key where the settings would not be
sealed (SettingsGateway.seals). Learn depends on halkyon_llm directly.
Todo wires the gateways; a member offers no assistant. No feature asks
an assistant yet (step 3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-26 07:17:07 +01:00

64 lines
2 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_app/halkyon_app.dart';
// A limit as the operator types it into the grant's sheet (Halkyon Learn's
// ADR 0021, D38): money in millionths, tokens whole.
void main() {
const money = AssistantLimitUnit.money;
const tokens = AssistantLimitUnit.tokens;
test('reads money as millionths, with a point or a comma', () {
expect(limitFromText('5', money), 5000000);
expect(limitFromText('2.50', money), 2500000);
expect(limitFromText('2,5', money), 2500000);
expect(limitFromText('0.000001', money), 1);
expect(limitFromText(' 1 000.25 ', money), 1000250000);
});
test('reads tokens whole, grouped by thousands or not', () {
expect(limitFromText('1000000', tokens), 1000000);
expect(limitFromText('1,000,000', tokens), 1000000);
expect(limitFromText('1.000.000', tokens), 1000000);
expect(limitFromText('1_000_000', tokens), 1000000);
expect(limitFromText('250', tokens), 250);
});
test('reads nothing typed as no limit', () {
expect(limitFromText('', money), isNull);
expect(limitFromText(' ', tokens), isNull);
});
test("refuses what isn't an amount", () {
for (final (text, unit) in [
('-1', money),
('1.5.0', money),
('0.0000001', money),
('five', money),
('1e6', money),
('1234567890123', money),
('1.5', tokens),
('1,00', tokens),
('1,000.000', tokens),
('-5', tokens),
('1234567890123', tokens),
]) {
expect(
() => limitFromText(text, unit),
throwsFormatException,
reason: '$text in ${unit.name}',
);
}
});
test('writes a limit as it is read back', () {
expect(limitText(null, money), '');
expect(limitText(5000000, money), '5');
expect(limitText(2500000, money), '2.5');
expect(limitText(1, money), '0.000001');
expect(limitText(1000000, tokens), '1000000');
for (final micros in [0, 1, 990000, 12345678]) {
expect(limitFromText(limitText(micros, money), money), micros);
}
});
}