tighten cross-target capability contracts

This commit is contained in:
Nanaloveyuki
2026-05-21 14:13:17 +08:00
parent 3e8d4c50a9
commit 3eee5893f5
5 changed files with 55 additions and 0 deletions
+8
View File
@@ -174,6 +174,14 @@ test "async runtime capability helpers stay consistent" {
)
}
test "async runtime mode and worker flag encode target contract" {
let mode_label = async_runtime_mode_label(async_runtime_mode())
let worker = async_runtime_supports_background_worker()
inspect(mode_label == "native_worker" || mode_label == "compatibility", content="true")
inspect((mode_label == "native_worker") == worker, content="true")
inspect((mode_label == "compatibility") == !worker, content="true")
}
test "async logger state snapshot reflects current counters and runtime" {
let logger = async_logger(
@bitlogger.callback_sink(fn(_) {
+3
View File
@@ -10,6 +10,9 @@ import {
options(
targets: {
"async_logger_shared.mbt": [ "native", "llvm", "js", "wasm", "wasm-gc" ],
"application_async_logger.mbt": [ "native", "llvm", "js", "wasm", "wasm-gc" ],
"library_async_logger.mbt": [ "native", "llvm", "js", "wasm", "wasm-gc" ],
"async_logger_native.mbt": [ "native", "llvm" ],
"async_logger_stub.mbt": [ "js", "wasm", "wasm-gc" ],
},
+17
View File
@@ -560,6 +560,23 @@ test "configured non-file logger has no file runtime state" {
inspect(logger.file_runtime_state() is None, content="true")
}
test "configured file logger mirrors backend file capability" {
let logger = build_logger(
LoggerConfig::new(
sink=SinkConfig::new(kind=SinkKind::File, path="config-capability.log"),
),
)
inspect(logger.file_available() == native_files_supported(), content="true")
if logger.file_available() {
inspect(logger.file_state().available, content="true")
ignore(logger.close())
} else {
inspect(logger.file_state().available, content="false")
inspect(logger.file_flush(), content="false")
inspect(logger.file_close(), content="false")
}
}
test "configured logger file setters update file sink policy state" {
let logger = build_logger(
LoggerConfig::new(
+25
View File
@@ -406,6 +406,31 @@ test "file sink availability reflects backend support" {
}
}
test "file sink unavailable backend keeps stable fallback state" {
let sink = file_sink("bitlogger-unavailable.log", rotation=Some(file_rotation(64, max_backups=2)))
if sink.is_available() {
inspect(sink.state().available, content="true")
ignore(sink.close())
} else {
let state = sink.state()
inspect(native_files_supported(), content="false")
inspect(state.available, content="false")
inspect(sink.flush(), content="false")
inspect(sink.close(), content="false")
inspect(sink.write_failures(), content="0")
sink.write(record(Level::Info, "dropped"))
inspect(sink.write_failures(), content="1")
inspect(sink.rotation_failures(), content="0")
match state.rotation {
Some(rotation) => {
inspect(rotation.max_bytes, content="64")
inspect(rotation.max_backups, content="2")
}
None => inspect(false, content="true")
}
}
}
test "file sink rotation config normalizes invalid inputs" {
let rotation = file_rotation(0, max_backups=0)
inspect(rotation.max_bytes, content="1")
+2
View File
@@ -12,6 +12,8 @@ import {
options(
targets: {
"sinks_file.mbt": [ "native", "llvm", "js", "wasm", "wasm-gc" ],
"runtime_file_controls.mbt": [ "native", "llvm", "js", "wasm", "wasm-gc" ],
"file_backend_native.mbt": [ "native", "llvm" ],
"file_backend_stub.mbt": [ "js", "wasm", "wasm-gc" ],
},