detz: M2 util+config

This commit is contained in:
2026-10-24 06:45:18 +02:00
parent ac4df725ef
commit d2244b00f0
14 changed files with 175 additions and 86 deletions
+37
View File
@@ -6,7 +6,12 @@
#include "../src/shell/livestream.h"
#include "../src/shell/lanes.h"
#include "../src/llm/llm.h"
#include "../src/util/ansi.h"
#include "../src/util/text.h"
#include "../src/config/config.h"
#include "../src/config/consts.h"
#include <cassert>
#include <filesystem>
#include <cstdio>
using detz::llm::ChatClient;
using detz::llm::ChatRequest;
@@ -64,6 +69,38 @@ int main() {
bool be = false;
try { detz::llm::Opencode no; no.complete("m", {}); } catch (const detz::llm::BackendError&) { be = true; }
assert(be);
// M2 util+config
assert(detz::Consts::kTotalStepCap == 500 && detz::Consts::kAuditMaxChars == 20000);
assert(std::string(detz::kDefaultModel) == "muse");
assert(!detz::ZenFreeModels().empty() && !detz::PollinationsModels().empty());
assert(detz::Paint("x", detz::Ansi::kRed).find("x") != std::string::npos);
assert(detz::Truncate("abc", 1500, 500) == "abc");
std::string big(3000, 'a');
assert(detz::Truncate(big, 100, 100).find("chars truncated") != std::string::npos);
assert(detz::TruncMarker(5).find("5") != std::string::npos);
assert(detz::CappedText("hi") == "hi");
assert(detz::ChunkLines("").empty());
assert(detz::ChunkLines("a\nb").size() == 1);
assert(detz::CollapseRepeatedLines("x\nx\nx").find("repeated 2") != std::string::npos);
assert(detz::CollapseRepeatedLines("a\nb").find("repeated") == std::string::npos);
{ auto [tags, rest] = detz::SplitLeadingTags("@a @b hello"); assert(tags.size() == 2 && rest == "hello"); }
{ auto [tags, rest] = detz::SplitLeadingTags("hi"); assert(tags.empty() && rest == "hi"); }
{ auto dir = std::filesystem::temp_directory_path().string();
std::string f = dir + "/detz_m2_test.txt"; FILE* fh = std::fopen(f.c_str(), "w"); std::fputs("x", fh); std::fclose(fh);
assert(detz::ExpandFileMentions("@detz_m2_test.txt", dir).find("detz_m2_test") != std::string::npos);
assert(detz::ExpandFileMentions("see @nope-missing-xyz", dir).find("@nope") != std::string::npos);
auto cf = detz::CompleteFiles("detz_m2_test", dir); assert(!cf.empty());
assert(detz::CompleteFiles("zzz-no-match-xyz", dir).empty());
std::filesystem::remove(f); }
{ detz::Config cfg = detz::Config::FromEnv(); assert(!cfg.model.empty());
assert(!detz::SettingsCatalog().empty());
assert(!detz::SplitModels("a, b;c").empty());
auto ids = detz::KnownModelIds(cfg); assert(!ids.empty());
auto rt = detz::ResolveTag("auto", {}, ids, "/tmp"); assert(rt.first == "auto");
auto ru = detz::ResolveTag("zzz-unknown-xyz", {}, ids, "/tmp"); assert(ru.first == "unknown");
std::map<std::string,std::string> bots = {{"bob", "BotBob"}};
auto rb = detz::ResolveTag("bob", bots, ids, "/tmp"); assert(rb.first == "bot"); }
std::puts("M2 OK");
std::puts("M4+M5 OK");
return 0;
}