core: clang-format pass against the landed root .clang-format

Pure formatting, no behaviour change. PKG landed .clang-format (Google
base, 4-space indent, 100 cols); this brings util/ and the test harness
into conformance so `clang-format --dry-run -Werror` is clean. Build and
all six test binaries unchanged and green.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HPPSGhiArbvQgwC2DNiURS
This commit is contained in:
2026-09-09 19:11:21 +04:00
co-authored by Claude Sonnet 5
parent ddf36e848a
commit a40585f419
10 changed files with 155 additions and 115 deletions
+11 -14
View File
@@ -49,12 +49,12 @@ enum class Error : std::uint16_t {
// --- local I/O --- // --- local I/O ---
disk_full = 500, disk_full = 500,
io_error, io_error,
path_rejected, // outside allowed roots or not writable path_rejected, // outside allowed roots or not writable
permission_denied, // EACCES on the destination permission_denied, // EACCES on the destination
// --- resume metadata --- // --- resume metadata ---
meta_corrupt = 600, // bad magic / failed CRC meta_corrupt = 600, // bad magic / failed CRC
meta_version_unsupported, // written by a newer engine meta_version_unsupported, // written by a newer engine
// --- probe --- // --- probe ---
probe_failed = 700, probe_failed = 700,
@@ -80,20 +80,17 @@ enum class Error : std::uint16_t {
// std::string here is fine. // std::string here is fine.
struct ErrorInfo { struct ErrorInfo {
Error code = Error::internal; Error code = Error::internal;
std::string context; // human-readable, for logs and event.notify bodies std::string context; // human-readable, for logs and event.notify bodies
int http_status = 0; // 0 when not HTTP-derived int http_status = 0; // 0 when not HTTP-derived
bool retryable = false; // snapshot of is_retryable(code) at construction, may be bool retryable = false; // snapshot of is_retryable(code) at construction, may be
// overridden by the caller (e.g. probe_failed) // overridden by the caller (e.g. probe_failed)
Error cause = Error::ok; // underlying error when `code` is a wrapper Error cause = Error::ok; // underlying error when `code` is a wrapper
// (max_retries_exhausted) // (max_retries_exhausted)
ErrorInfo() = default; ErrorInfo() = default;
explicit ErrorInfo(Error c, std::string ctx = {}, int status = 0) explicit ErrorInfo(Error c, std::string ctx = {}, int status = 0)
: code(c), : code(c), context(std::move(ctx)), http_status(status), retryable(is_retryable(c)) {}
context(std::move(ctx)),
http_status(status),
retryable(is_retryable(c)) {}
[[nodiscard]] std::string_view name() const noexcept { return error_name(code); } [[nodiscard]] std::string_view name() const noexcept { return error_name(code); }
+1 -3
View File
@@ -61,9 +61,7 @@ class EventBus {
auto &slot = channels_[std::type_index(typeid(E))]; auto &slot = channels_[std::type_index(typeid(E))];
slot.push_back(Entry{ slot.push_back(Entry{
tok, tok,
[h = std::move(handler)](const void *ev) { [h = std::move(handler)](const void *ev) { h(*static_cast<const E *>(ev)); },
h(*static_cast<const E *>(ev));
},
}); });
return tok; return tok;
} }
+7 -9
View File
@@ -45,8 +45,7 @@ class LogSink {
class CallbackSink final : public LogSink { class CallbackSink final : public LogSink {
public: public:
using Fn = std::function<void(const LogRecord &)>; using Fn = std::function<void(const LogRecord &)>;
explicit CallbackSink(Fn fn, LogLevel min = LogLevel::trace) explicit CallbackSink(Fn fn, LogLevel min = LogLevel::trace) : fn_(std::move(fn)), min_(min) {}
: fn_(std::move(fn)), min_(min) {}
void write(const LogRecord &r) override { fn_(r); } void write(const LogRecord &r) override { fn_(r); }
[[nodiscard]] bool enabled(LogLevel l) const override { return l >= min_; } [[nodiscard]] bool enabled(LogLevel l) const override { return l >= min_; }
@@ -64,21 +63,20 @@ void log_emit(LogLevel, std::string_view category, std::string message);
namespace detail { namespace detail {
[[nodiscard]] bool log_wants(LogLevel); // sink installed && sink.enabled(level) [[nodiscard]] bool log_wants(LogLevel); // sink installed && sink.enabled(level)
} } // namespace detail
} // namespace vdm } // namespace vdm
#define VDM_LOG(level, category, ...) \ #define VDM_LOG(level, category, ...) \
do { \ do { \
if (::vdm::detail::log_wants(level)) \ if (::vdm::detail::log_wants(level)) \
::vdm::log_emit((level), (category), \ ::vdm::log_emit((level), (category), std::format(__VA_ARGS__)); \
std::format(__VA_ARGS__)); \
} while (0) } while (0)
#define VDM_LOG_TRACE(cat, ...) VDM_LOG(::vdm::LogLevel::trace, cat, __VA_ARGS__) #define VDM_LOG_TRACE(cat, ...) VDM_LOG(::vdm::LogLevel::trace, cat, __VA_ARGS__)
#define VDM_LOG_DEBUG(cat, ...) VDM_LOG(::vdm::LogLevel::debug, cat, __VA_ARGS__) #define VDM_LOG_DEBUG(cat, ...) VDM_LOG(::vdm::LogLevel::debug, cat, __VA_ARGS__)
#define VDM_LOG_INFO(cat, ...) VDM_LOG(::vdm::LogLevel::info, cat, __VA_ARGS__) #define VDM_LOG_INFO(cat, ...) VDM_LOG(::vdm::LogLevel::info, cat, __VA_ARGS__)
#define VDM_LOG_WARN(cat, ...) VDM_LOG(::vdm::LogLevel::warn, cat, __VA_ARGS__) #define VDM_LOG_WARN(cat, ...) VDM_LOG(::vdm::LogLevel::warn, cat, __VA_ARGS__)
#define VDM_LOG_ERROR(cat, ...) VDM_LOG(::vdm::LogLevel::error, cat, __VA_ARGS__) #define VDM_LOG_ERROR(cat, ...) VDM_LOG(::vdm::LogLevel::error, cat, __VA_ARGS__)
#endif // VDM_UTIL_LOG_HPP #endif // VDM_UTIL_LOG_HPP
+28 -13
View File
@@ -37,7 +37,9 @@ class [[nodiscard]] Result {
!std::is_same_v<std::remove_cvref_t<U>, Result>>> !std::is_same_v<std::remove_cvref_t<U>, Result>>>
Result(U &&value) : exp_(std::in_place, std::forward<U>(value)) {} Result(U &&value) : exp_(std::in_place, std::forward<U>(value)) {}
Result() requires std::is_default_constructible_v<T> : exp_(std::in_place) {} Result()
requires std::is_default_constructible_v<T>
: exp_(std::in_place) {}
// Failure construction: implicit from an ErrorInfo/Err. // Failure construction: implicit from an ErrorInfo/Err.
Result(ErrorInfo error) : exp_(std::unexpected(std::move(error))) {} Result(ErrorInfo error) : exp_(std::unexpected(std::move(error))) {}
@@ -71,18 +73,30 @@ class [[nodiscard]] Result {
// Monadic forwarding — see std::expected. `and_then` chains Result-returning // Monadic forwarding — see std::expected. `and_then` chains Result-returning
// callables; `transform` maps the value; `transform_error` rewrites the failure. // callables; `transform` maps the value; `transform_error` rewrites the failure.
template <class F> template <class F>
auto and_then(F &&f) & { return exp_.and_then(std::forward<F>(f)); } auto and_then(F &&f) & {
return exp_.and_then(std::forward<F>(f));
}
template <class F> template <class F>
auto and_then(F &&f) const & { return exp_.and_then(std::forward<F>(f)); } auto and_then(F &&f) const & {
return exp_.and_then(std::forward<F>(f));
}
template <class F> template <class F>
auto and_then(F &&f) && { return std::move(exp_).and_then(std::forward<F>(f)); } auto and_then(F &&f) && {
return std::move(exp_).and_then(std::forward<F>(f));
}
template <class F> template <class F>
auto transform(F &&f) & { return exp_.transform(std::forward<F>(f)); } auto transform(F &&f) & {
return exp_.transform(std::forward<F>(f));
}
template <class F> template <class F>
auto transform(F &&f) const & { return exp_.transform(std::forward<F>(f)); } auto transform(F &&f) const & {
return exp_.transform(std::forward<F>(f));
}
template <class F> template <class F>
auto transform(F &&f) && { return std::move(exp_).transform(std::forward<F>(f)); } auto transform(F &&f) && {
return std::move(exp_).transform(std::forward<F>(f));
}
template <class F> template <class F>
auto transform_error(F &&f) const & { auto transform_error(F &&f) const & {
@@ -116,7 +130,9 @@ class [[nodiscard]] Result<void> {
}; };
// Explicit success sentinel for Result<void> returns that reads better than `return {}`. // Explicit success sentinel for Result<void> returns that reads better than `return {}`.
inline Result<void> ok() { return {}; } inline Result<void> ok() {
return {};
}
} // namespace vdm } // namespace vdm
@@ -135,11 +151,10 @@ inline Result<void> ok() { return {}; }
// VDM_TRY_ASSIGN(decl, expr): bind `decl` to the value of a successful Result, else // VDM_TRY_ASSIGN(decl, expr): bind `decl` to the value of a successful Result, else
// return its error. Usage: VDM_TRY_ASSIGN(auto n, read_some()); // return its error. Usage: VDM_TRY_ASSIGN(auto n, read_some());
#define VDM_TRY_ASSIGN(decl, expr) \ #define VDM_TRY_ASSIGN(decl, expr) \
auto VDM_DETAIL_CAT(_vdm_tmp_, __LINE__) = (expr); \ auto VDM_DETAIL_CAT(_vdm_tmp_, __LINE__) = (expr); \
if (!VDM_DETAIL_CAT(_vdm_tmp_, __LINE__).has_value()) \ if (!VDM_DETAIL_CAT(_vdm_tmp_, __LINE__).has_value()) \
return ::vdm::ErrorInfo( \ return ::vdm::ErrorInfo(std::move(VDM_DETAIL_CAT(_vdm_tmp_, __LINE__)).error()); \
std::move(VDM_DETAIL_CAT(_vdm_tmp_, __LINE__)).error()); \
decl = *std::move(VDM_DETAIL_CAT(_vdm_tmp_, __LINE__)) decl = *std::move(VDM_DETAIL_CAT(_vdm_tmp_, __LINE__))
#endif // VDM_UTIL_RESULT_HPP #endif // VDM_UTIL_RESULT_HPP
+2 -4
View File
@@ -46,13 +46,11 @@ class ThreadPool {
// Enqueue `fn(args...)`; returns a future for its result. Throws std::runtime_error // Enqueue `fn(args...)`; returns a future for its result. Throws std::runtime_error
// if the pool is already shutting down. // if the pool is already shutting down.
template <class F, class... Args> template <class F, class... Args>
auto submit(F &&fn, Args &&...args) auto submit(F &&fn, Args &&...args) -> std::future<std::invoke_result_t<F, Args...>> {
-> std::future<std::invoke_result_t<F, Args...>> {
using R = std::invoke_result_t<F, Args...>; using R = std::invoke_result_t<F, Args...>;
auto task = std::make_shared<std::packaged_task<R()>>( auto task = std::make_shared<std::packaged_task<R()>>(
[f = std::forward<F>(fn), [f = std::forward<F>(fn), ... a = std::forward<Args>(args)]() mutable -> R {
... a = std::forward<Args>(args)]() mutable -> R {
return std::invoke(std::move(f), std::move(a)...); return std::invoke(std::move(f), std::move(a)...);
}); });
std::future<R> fut = task->get_future(); std::future<R> fut = task->get_future();
+59 -31
View File
@@ -6,34 +6,62 @@ namespace vdm {
std::string_view error_name(Error e) noexcept { std::string_view error_name(Error e) noexcept {
switch (e) { switch (e) {
case Error::ok: return "ok"; case Error::ok:
case Error::canceled: return "canceled"; return "ok";
case Error::resolve_failed: return "resolve_failed"; case Error::canceled:
case Error::connect_failed: return "connect_failed"; return "canceled";
case Error::tls_failed: return "tls_failed"; case Error::resolve_failed:
case Error::connection_reset: return "connection_reset"; return "resolve_failed";
case Error::timeout: return "timeout"; case Error::connect_failed:
case Error::too_many_redirects: return "too_many_redirects"; return "connect_failed";
case Error::http_client_error: return "http_client_error"; case Error::tls_failed:
case Error::http_server_error: return "http_server_error"; return "tls_failed";
case Error::auth_required: return "auth_required"; case Error::connection_reset:
case Error::forbidden: return "forbidden"; return "connection_reset";
case Error::not_found: return "not_found"; case Error::timeout:
case Error::range_not_satisfiable: return "range_not_satisfiable"; return "timeout";
case Error::gone: return "gone"; case Error::too_many_redirects:
case Error::server_file_changed: return "server_file_changed"; return "too_many_redirects";
case Error::content_length_mismatch: return "content_length_mismatch"; case Error::http_client_error:
case Error::checksum_mismatch: return "checksum_mismatch"; return "http_client_error";
case Error::disk_full: return "disk_full"; case Error::http_server_error:
case Error::io_error: return "io_error"; return "http_server_error";
case Error::path_rejected: return "path_rejected"; case Error::auth_required:
case Error::permission_denied: return "permission_denied"; return "auth_required";
case Error::meta_corrupt: return "meta_corrupt"; case Error::forbidden:
case Error::meta_version_unsupported: return "meta_version_unsupported"; return "forbidden";
case Error::probe_failed: return "probe_failed"; case Error::not_found:
case Error::unsupported_url_scheme: return "unsupported_url_scheme"; return "not_found";
case Error::max_retries_exhausted: return "max_retries_exhausted"; case Error::range_not_satisfiable:
case Error::internal: return "internal"; return "range_not_satisfiable";
case Error::gone:
return "gone";
case Error::server_file_changed:
return "server_file_changed";
case Error::content_length_mismatch:
return "content_length_mismatch";
case Error::checksum_mismatch:
return "checksum_mismatch";
case Error::disk_full:
return "disk_full";
case Error::io_error:
return "io_error";
case Error::path_rejected:
return "path_rejected";
case Error::permission_denied:
return "permission_denied";
case Error::meta_corrupt:
return "meta_corrupt";
case Error::meta_version_unsupported:
return "meta_version_unsupported";
case Error::probe_failed:
return "probe_failed";
case Error::unsupported_url_scheme:
return "unsupported_url_scheme";
case Error::max_retries_exhausted:
return "max_retries_exhausted";
case Error::internal:
return "internal";
} }
return "unknown"; return "unknown";
} }
@@ -48,7 +76,7 @@ bool is_retryable(Error e) noexcept {
case Error::connection_reset: case Error::connection_reset:
case Error::timeout: case Error::timeout:
case Error::http_server_error: case Error::http_server_error:
case Error::range_not_satisfiable: // stale metadata → re-probe then retry case Error::range_not_satisfiable: // stale metadata → re-probe then retry
case Error::content_length_mismatch: case Error::content_length_mismatch:
return true; return true;
@@ -58,11 +86,11 @@ bool is_retryable(Error e) noexcept {
case Error::tls_failed: case Error::tls_failed:
case Error::too_many_redirects: case Error::too_many_redirects:
case Error::http_client_error: case Error::http_client_error:
case Error::auth_required: // resolved by credentials, not a retry case Error::auth_required: // resolved by credentials, not a retry
case Error::forbidden: case Error::forbidden:
case Error::not_found: case Error::not_found:
case Error::gone: case Error::gone:
case Error::server_file_changed: // needs a user decision case Error::server_file_changed: // needs a user decision
case Error::checksum_mismatch: case Error::checksum_mismatch:
case Error::disk_full: case Error::disk_full:
case Error::io_error: case Error::io_error:
+10 -5
View File
@@ -17,11 +17,16 @@ std::shared_ptr<LogSink> g_sink;
std::string_view log_level_name(LogLevel l) noexcept { std::string_view log_level_name(LogLevel l) noexcept {
switch (l) { switch (l) {
case LogLevel::trace: return "trace"; case LogLevel::trace:
case LogLevel::debug: return "debug"; return "trace";
case LogLevel::info: return "info"; case LogLevel::debug:
case LogLevel::warn: return "warn"; return "debug";
case LogLevel::error: return "error"; case LogLevel::info:
return "info";
case LogLevel::warn:
return "warn";
case LogLevel::error:
return "error";
} }
return "?"; return "?";
} }
+32 -33
View File
@@ -52,11 +52,11 @@ struct Registrar {
Registrar(const char *name, void (*fn)()) { registry().push_back({name, fn}); } Registrar(const char *name, void (*fn)()) { registry().push_back({name, fn}); }
}; };
inline void report(const char *file, int line, std::string_view expr, inline void report(const char *file, int line, std::string_view expr, std::string_view detail,
std::string_view detail, bool fatal) { bool fatal) {
stats().failures++; stats().failures++;
std::fprintf(stderr, " FAIL %s:%d %.*s", file, line, std::fprintf(stderr, " FAIL %s:%d %.*s", file, line, static_cast<int>(expr.size()),
static_cast<int>(expr.size()), expr.data()); expr.data());
if (!detail.empty()) if (!detail.empty())
std::fprintf(stderr, " [%.*s]", static_cast<int>(detail.size()), detail.data()); std::fprintf(stderr, " [%.*s]", static_cast<int>(detail.size()), detail.data());
std::fprintf(stderr, "\n"); std::fprintf(stderr, "\n");
@@ -110,46 +110,45 @@ inline int run_all() {
} // namespace vt } // namespace vt
#define VT_TEST(NAME) \ #define VT_TEST(NAME) \
static void NAME##_impl(); \ static void NAME##_impl(); \
static ::vt::Registrar NAME##_reg(#NAME, &NAME##_impl); \ static ::vt::Registrar NAME##_reg(#NAME, &NAME##_impl); \
static void NAME##_impl() static void NAME##_impl()
#define VT_CHECK(COND) \ #define VT_CHECK(COND) \
do { \ do { \
::vt::stats().checks++; \ ::vt::stats().checks++; \
if (!(COND)) \ if (!(COND)) \
::vt::report(__FILE__, __LINE__, #COND, {}, /*fatal=*/false); \ ::vt::report(__FILE__, __LINE__, #COND, {}, /*fatal=*/false); \
} while (0) } while (0)
#define VT_REQUIRE(COND) \ #define VT_REQUIRE(COND) \
do { \ do { \
::vt::stats().checks++; \ ::vt::stats().checks++; \
if (!(COND)) \ if (!(COND)) \
::vt::report(__FILE__, __LINE__, #COND, {}, /*fatal=*/true); \ ::vt::report(__FILE__, __LINE__, #COND, {}, /*fatal=*/true); \
} while (0) } while (0)
#define VT_CHECK_EQ(A, B) \ #define VT_CHECK_EQ(A, B) \
do { \ do { \
::vt::stats().checks++; \ ::vt::stats().checks++; \
auto &&_a = (A); \ auto &&_a = (A); \
auto &&_b = (B); \ auto &&_b = (B); \
if (!(_a == _b)) \ if (!(_a == _b)) \
::vt::report(__FILE__, __LINE__, #A " == " #B, \ ::vt::report(__FILE__, __LINE__, #A " == " #B, \
::vt::show(_a) + " vs " + ::vt::show(_b), false); \ ::vt::show(_a) + " vs " + ::vt::show(_b), false); \
} while (0) } while (0)
#define VT_CHECK_NE(A, B) \ #define VT_CHECK_NE(A, B) \
do { \ do { \
::vt::stats().checks++; \ ::vt::stats().checks++; \
auto &&_a = (A); \ auto &&_a = (A); \
auto &&_b = (B); \ auto &&_b = (B); \
if (!(_a != _b)) \ if (!(_a != _b)) \
::vt::report(__FILE__, __LINE__, #A " != " #B, \ ::vt::report(__FILE__, __LINE__, #A " != " #B, \
::vt::show(_a) + " vs " + ::vt::show(_b), false); \ ::vt::show(_a) + " vs " + ::vt::show(_b), false); \
} while (0) } while (0)
#define VT_FAIL(MSG) \ #define VT_FAIL(MSG) ::vt::report(__FILE__, __LINE__, "VT_FAIL", (MSG), /*fatal=*/false)
::vt::report(__FILE__, __LINE__, "VT_FAIL", (MSG), /*fatal=*/false)
#endif // VDM_TESTS_VTEST_HPP #endif // VDM_TESTS_VTEST_HPP
+3 -1
View File
@@ -1,4 +1,6 @@
// vtest_main.cpp — shared entry point for every CORE test binary. // vtest_main.cpp — shared entry point for every CORE test binary.
#include "vtest.hpp" #include "vtest.hpp"
int main() { return ::vt::run_all(); } int main() {
return ::vt::run_all();
}
+2 -2
View File
@@ -48,8 +48,8 @@ VT_TEST(log_forwards_to_sink_with_format) {
VT_TEST(log_level_filter_skips_below_min) { VT_TEST(log_level_filter_skips_below_min) {
SinkGuard g; SinkGuard g;
auto count = std::make_shared<int>(0); auto count = std::make_shared<int>(0);
vdm::set_log_sink(std::make_shared<CallbackSink>( vdm::set_log_sink(
[count](const LogRecord &) { ++*count; }, LogLevel::warn)); std::make_shared<CallbackSink>([count](const LogRecord &) { ++*count; }, LogLevel::warn));
VDM_LOG_DEBUG("x", "no"); VDM_LOG_DEBUG("x", "no");
VDM_LOG_INFO("x", "no"); VDM_LOG_INFO("x", "no");