This commit is contained in:
Your Name
2026-10-23 09:26:49 +08:00
parent 14abf67d0d
commit 3f15786491
34 changed files with 2866 additions and 225 deletions
@@ -111,5 +111,22 @@ namespace {
$short['case_text'] = str_repeat('a', 120000);
$copy = $short;
compactExpect($apply($short) && $short === $copy, 'exact threshold keeps the source untouched');
Cache::$items = [];
$compactionConfig['context_compaction_cache_ttl'] = 300;
DifyChatService::$calls = [];
$cancelledContext = $original;
$progress = [];
$cancelOptions = ['should_abort' => static fn (): bool => count(DifyChatService::$calls) >= 1,
'on_cancel_task' => static fn (string $taskId, callable $stop): array => ['accepted' => false, 'pending' => true],
'on_terminal' => static function (string $taskId, string $status): void {},
'on_progress' => static function (array $event) use (&$progress): void { $progress[] = $event; }];
compactExpect(!$fit->invokeArgs(null, [&$cancelledContext, 'qwen', new AssistantSseTiming(), $cancelOptions]), 'cancel during preprocessing terminates preparation');
compactExpect(count(DifyChatService::$calls) === 1 && Cache::$items === [] && $cancelledContext === $original, 'cancelled partial evidence never enters cache or final prompt');
compactExpect(DifyChatService::$calls[0]['options']['knowledge_mode'] === 'evidence'
&& is_callable(DifyChatService::$calls[0]['options']['should_abort'])
&& DifyChatService::$calls[0]['options']['on_cancel_task'] === $cancelOptions['on_cancel_task']
&& DifyChatService::$calls[0]['options']['on_terminal'] === $cancelOptions['on_terminal'],
'intermediate evidence request preserves abort, shared stop and terminal observers');
compactExpect(count($progress) === 1 && $progress[0]['completed'] === 0 && $progress[0]['total'] === 2, 'chunk progress counts only completed evidence results');
echo "AI context compaction latency and isolation: OK\n";
}