chore: add community files, CI workflows, and host test tooling

Add the repository-facing scaffolding:

- Community/legal: README.md, LICENSE (GPL-3.0-or-later), NOTICE,
  CONTRIBUTING.md, SECURITY.md, CODE_OF_CONDUCT.md, .gitleaks.toml
- CI: .github/ workflows (ci.yml aggregate gate, nightly.yml, codeql.yml),
  issue/PR templates, dependabot config (pinned Actions per README)
- Host tooling: tools/frame_tools (ruff/pyright/pytest gates, partition,
  evidence-schema, doc-links, SBOM checks), tests/, pyproject.toml, uv.lock
- poc/ host side: poc/host contract-test suite (ASan/TSan-capable),
  poc/README.md, poc/poc-a.code-workspace

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <[email protected]>
This commit is contained in:
2026-08-31 08:00:51 +08:00
co-authored by Sisyphus
parent dbb7c13729
commit a6d6168fd5
40 changed files with 3792 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
#include <stddef.h>
#include "frame_poc/frame_abi.h"
_Static_assert(sizeof(frame_abi_header_t) == 16, "ABI header size changed");
_Static_assert(offsetof(frame_abi_header_t, struct_size) == 0, "ABI header prefix changed");
_Static_assert(sizeof(plugin_instance_handle_t) == sizeof(uint64_t), "handle width changed");
_Static_assert(FRAME_ERR_RATE_LIMITED == -29, "error value changed");
int main(void) {
const frame_abi_header_t abi = {
.struct_size = sizeof(frame_abi_header_t),
.abi_major = FRAME_ABI_MAJOR,
.abi_minor = FRAME_ABI_MINOR,
.feature_bits = 0,
};
return frame_abi_supports(&abi, FRAME_ABI_MAJOR, FRAME_ABI_MINOR, sizeof(frame_abi_header_t), 0)
? 0
: 1;
}
+74
View File
@@ -0,0 +1,74 @@
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <gtest/gtest.h>
#include "frame_poc/frame_abi.h"
namespace {
constexpr uint64_t kRequiredFeature = UINT64_C(1) << 12;
struct extended_service {
frame_abi_header_t abi;
void (*operation)(void);
};
static_assert(__cplusplus >= 202302L);
static_assert(std::is_standard_layout_v<frame_abi_header_t>);
static_assert(std::is_standard_layout_v<frame_post_operation_t>);
static_assert(std::is_standard_layout_v<frame_completion_operation_t>);
static_assert(offsetof(frame_abi_header_t, struct_size) == 0);
static_assert(offsetof(extended_service, abi) == 0);
static_assert(sizeof(plugin_instance_handle_t) == sizeof(uint64_t));
TEST(FrameAbi, AcceptsCompatibleExtension) {
const extended_service service{
.abi =
{
.struct_size = sizeof(extended_service),
.abi_major = FRAME_ABI_MAJOR,
.abi_minor = FRAME_ABI_MINOR + 1,
.feature_bits = kRequiredFeature,
},
.operation = nullptr,
};
EXPECT_TRUE(frame_abi_supports(&service.abi, FRAME_ABI_MAJOR, FRAME_ABI_MINOR,
sizeof(extended_service), kRequiredFeature));
}
TEST(FrameAbi, RejectsIncompatibleOffer) {
const extended_service service{
.abi =
{
.struct_size = sizeof(extended_service),
.abi_major = FRAME_ABI_MAJOR,
.abi_minor = FRAME_ABI_MINOR + 1,
.feature_bits = kRequiredFeature,
},
.operation = nullptr,
};
EXPECT_FALSE(frame_abi_supports(nullptr, FRAME_ABI_MAJOR, FRAME_ABI_MINOR,
sizeof(frame_abi_header_t), 0));
EXPECT_FALSE(frame_abi_supports(&service.abi, FRAME_ABI_MAJOR + 1, FRAME_ABI_MINOR,
sizeof(frame_abi_header_t), 0));
EXPECT_FALSE(frame_abi_supports(&service.abi, FRAME_ABI_MAJOR, FRAME_ABI_MINOR + 2,
sizeof(frame_abi_header_t), 0));
EXPECT_FALSE(frame_abi_supports(&service.abi, FRAME_ABI_MAJOR, FRAME_ABI_MINOR,
sizeof(extended_service) + 1, 0));
EXPECT_FALSE(frame_abi_supports(&service.abi, FRAME_ABI_MAJOR, FRAME_ABI_MINOR,
sizeof(frame_abi_header_t), kRequiredFeature << 1));
}
TEST(FrameAbi, PinsStableErrorValues) {
EXPECT_EQ(FRAME_OK, 0);
EXPECT_EQ(FRAME_ERR_INVALID_PTR, -1);
EXPECT_EQ(FRAME_ERR_INVALID_ARGUMENT, -28);
EXPECT_EQ(FRAME_ERR_RATE_LIMITED, -29);
EXPECT_EQ(FRAME_ERR_TARGET_MISMATCH, -35);
}
} // namespace
+41
View File
@@ -0,0 +1,41 @@
#include <cstddef>
#include <cstdint>
#include "frame_poc/frame_abi.h"
#include "frame_poc/frame_handle.hh"
#include "frame_poc/lifecycle_state.hh"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, std::size_t size) {
if (size < 4) {
return 0;
}
const auto state = static_cast<frame::poc::plugin_state>(data[0] % 10U);
const auto event = static_cast<frame::poc::lifecycle_event>(data[1] % 11U);
const auto result = frame::poc::transition(state, event);
if (result.error != FRAME_OK && result.next != state) {
__builtin_trap();
}
const frame_abi_header_t abi{
.struct_size = static_cast<uint32_t>(data[2]) * 8U,
.abi_major = data[0],
.abi_minor = data[1],
.feature_bits = static_cast<uint64_t>(data[3]),
};
(void)frame_abi_supports(&abi, FRAME_ABI_MAJOR, FRAME_ABI_MINOR, sizeof(frame_abi_header_t),
data[3] & UINT8_C(0x0F));
frame::poc::handle_table<uint32_t, 2> table;
const frame::poc::handle_owner owner{
.instance = static_cast<uint64_t>(data[0]) + 1U,
.generation = static_cast<uint64_t>(data[1]) + 1U,
};
uint64_t handle = 0;
if (table.acquire(owner, frame::poc::handle_type::buffer, data[2], &handle) == FRAME_OK) {
uint32_t* value = nullptr;
(void)table.get(handle, owner, frame::poc::handle_type::buffer, &value);
(void)table.release(handle, owner, frame::poc::handle_type::buffer);
}
return 0;
}
+70
View File
@@ -0,0 +1,70 @@
#include <cstdint>
#include <gtest/gtest.h>
#include "frame_poc/frame_handle.hh"
using frame::poc::handle_owner;
using frame::poc::handle_table;
using frame::poc::handle_type;
TEST(FrameHandle, EnforcesCapacityOwnershipGenerationAndType) {
handle_table<uint32_t, 1> table;
const handle_owner first_owner{.instance = 7, .generation = 11};
const handle_owner next_generation{.instance = 7, .generation = 12};
uint64_t first_handle = 0;
ASSERT_EQ(table.acquire(first_owner, handle_type::timer, 41, &first_handle), FRAME_OK);
EXPECT_NE(first_handle, 0U);
uint32_t* value = nullptr;
ASSERT_EQ(table.get(first_handle, first_owner, handle_type::timer, &value), FRAME_OK);
ASSERT_NE(value, nullptr);
EXPECT_EQ(*value, 41U);
EXPECT_EQ(table.get(first_handle, next_generation, handle_type::timer, &value),
FRAME_ERR_INVALID_PTR);
EXPECT_EQ(table.get(first_handle, first_owner, handle_type::buffer, &value),
FRAME_ERR_INVALID_PTR);
uint64_t overflow_handle = 0;
EXPECT_EQ(table.acquire(first_owner, handle_type::buffer, 99, &overflow_handle),
FRAME_ERR_CAPACITY);
EXPECT_EQ(table.release(first_handle, next_generation, handle_type::timer),
FRAME_ERR_INVALID_PTR);
EXPECT_EQ(table.release(first_handle, first_owner, handle_type::timer), FRAME_OK);
EXPECT_EQ(table.release(first_handle, first_owner, handle_type::timer), FRAME_ERR_INVALID_PTR);
}
TEST(FrameHandle, ReuseInvalidatesStaleHandle) {
handle_table<uint32_t, 1> table;
const handle_owner first_owner{.instance = 7, .generation = 11};
const handle_owner next_owner{.instance = 7, .generation = UINT64_C(1) << 40};
uint64_t first_handle = 0;
uint64_t replacement_handle = 0;
ASSERT_EQ(table.acquire(first_owner, handle_type::timer, 41, &first_handle), FRAME_OK);
ASSERT_EQ(table.release(first_handle, first_owner, handle_type::timer), FRAME_OK);
ASSERT_EQ(table.acquire(next_owner, handle_type::timer, 42, &replacement_handle), FRAME_OK);
EXPECT_NE(replacement_handle, first_handle);
uint32_t* value = nullptr;
EXPECT_EQ(table.get(first_handle, first_owner, handle_type::timer, &value),
FRAME_ERR_INVALID_PTR);
ASSERT_EQ(table.get(replacement_handle, next_owner, handle_type::timer, &value), FRAME_OK);
ASSERT_NE(value, nullptr);
EXPECT_EQ(*value, 42U);
}
TEST(FrameHandle, RejectsInvalidArguments) {
handle_table<uint32_t, 1> table;
const handle_owner valid{.instance = 1, .generation = 1};
uint64_t handle = 0;
EXPECT_EQ(table.acquire(valid, handle_type::timer, 1, nullptr), FRAME_ERR_INVALID_ARGUMENT);
EXPECT_EQ(table.acquire({.instance = 0, .generation = 1}, handle_type::timer, 1, &handle),
FRAME_ERR_INVALID_ARGUMENT);
EXPECT_EQ(table.acquire({.instance = 1, .generation = 0}, handle_type::timer, 1, &handle),
FRAME_ERR_INVALID_ARGUMENT);
ASSERT_EQ(table.acquire(valid, handle_type::timer, 1, &handle), FRAME_OK);
EXPECT_EQ(table.get(handle, valid, handle_type::timer, nullptr), FRAME_ERR_INVALID_PTR);
}
+103
View File
@@ -0,0 +1,103 @@
#include <array>
#include <gtest/gtest.h>
#include "frame_poc/lifecycle_state.hh"
using frame::poc::lifecycle_event;
using frame::poc::plugin_state;
using frame::poc::transition;
namespace {
struct step {
lifecycle_event event;
plugin_state expected;
};
template <std::size_t Size>
void expect_path(plugin_state initial, const std::array<step, Size>& steps) {
plugin_state current = initial;
for (const step& item : steps) {
const auto result = transition(current, item.event);
ASSERT_EQ(result.error, FRAME_OK);
ASSERT_EQ(result.next, item.expected);
current = result.next;
}
}
TEST(LifecycleState, FollowsColdStartAndUnload) {
constexpr std::array cold_start{
step{lifecycle_event::begin_load, plugin_state::loading},
step{lifecycle_event::prepare_succeeded, plugin_state::prepared},
step{lifecycle_event::activation_committed, plugin_state::active},
step{lifecycle_event::begin_quiesce, plugin_state::quiescing},
step{lifecycle_event::quiesce_succeeded, plugin_state::unloading},
step{lifecycle_event::unload_succeeded, plugin_state::unloaded},
};
expect_path(plugin_state::staged, cold_start);
}
TEST(LifecycleState, SupportsPauseResumeAndCommittedUpdate) {
constexpr std::array aborted{
step{lifecycle_event::begin_pause, plugin_state::pausing},
step{lifecycle_event::pause_succeeded, plugin_state::paused},
step{lifecycle_event::resume_succeeded, plugin_state::active},
};
expect_path(plugin_state::active, aborted);
constexpr std::array committed{
step{lifecycle_event::begin_pause, plugin_state::pausing},
step{lifecycle_event::pause_succeeded, plugin_state::paused},
step{lifecycle_event::begin_quiesce, plugin_state::quiescing},
step{lifecycle_event::quiesce_succeeded, plugin_state::unloading},
step{lifecycle_event::unload_succeeded, plugin_state::unloaded},
};
expect_path(plugin_state::active, committed);
}
TEST(LifecycleState, RejectsEveryUnspecifiedTransition) {
constexpr std::array states{
plugin_state::staged, plugin_state::loading,
plugin_state::prepared, plugin_state::active,
plugin_state::pausing, plugin_state::paused,
plugin_state::quiescing, plugin_state::unloading,
plugin_state::unloaded, plugin_state::failed_restart_required,
};
constexpr std::array events{
lifecycle_event::begin_load,
lifecycle_event::prepare_succeeded,
lifecycle_event::activation_committed,
lifecycle_event::begin_pause,
lifecycle_event::pause_succeeded,
lifecycle_event::resume_succeeded,
lifecycle_event::begin_quiesce,
lifecycle_event::quiesce_succeeded,
lifecycle_event::unload_succeeded,
lifecycle_event::discard_candidate,
lifecycle_event::fail_restart_required,
};
for (const plugin_state state : states) {
for (const lifecycle_event event : events) {
const auto result = transition(state, event);
if (result.error != FRAME_OK) {
EXPECT_EQ(result.error, FRAME_ERR_INVALID_ARGUMENT);
EXPECT_EQ(result.next, state);
}
}
}
}
TEST(LifecycleState, RestartRequiredIsTerminal) {
const auto restart = transition(plugin_state::pausing, lifecycle_event::fail_restart_required);
ASSERT_EQ(restart.error, FRAME_OK);
ASSERT_EQ(restart.next, plugin_state::failed_restart_required);
const auto terminal =
transition(plugin_state::failed_restart_required, lifecycle_event::begin_quiesce);
EXPECT_EQ(terminal.error, FRAME_ERR_INVALID_ARGUMENT);
EXPECT_EQ(terminal.next, plugin_state::failed_restart_required);
}
} // namespace