std/mock_platform
std/mock_platform
Section titled “std/mock_platform”std/mock_platform — test-ergonomics helpers for Tier-C Rec §11 (docs/PLATFORM-RESEARCH.md §6). Today’s Platform is a one-field placeholder. Once Phase 2 adds capability fields (log / fetch / kv / now), MockPlatform grows matching methods that intercept calls + return canned responses. Phase 1 (this PR) ships the call-recording infrastructure so tests can manually drive an effect log and inspect it. Intended use (Phase 1): var m: MockPlatform = mock_platform_new(); m = m.record(“fetch”, “GET /users/42”); m = m.record(“kv_set”, “user:42=Alice”); // Drive the handler manually: var req: HttpRequest = …; var resp: HttpResponse = handle(req, Platform { version: 1 }); // Inspect the recorded call log: assert_eq(m.call_count(), 2); assert_eq(m.calls[0].name, “fetch”); Intended use (Phase 2 — once Platform grows capability fields): var m: MockPlatform = mock_platform_new(); var plat: Platform = m.as_platform(); plat.kv_set(“user:42”, ”{ “name”: “Alice” }”); var resp: HttpResponse = handle(req, plat); assert_eq(m.calls[0].name, “kv_set”);
mock_platform_new
Section titled “mock_platform_new”pub function mock_platform_new(): MockPlatformmock_platform_new() — fresh MockPlatform with an empty
call log.
record
Section titled “record”pub function (m: MockPlatform) record(name: string, args: string): MockPlatform(m: MockPlatform).record(name, args): MockPlatform —
return a MockPlatform whose log has name/args appended.
args is a free-form string; tests typically stuff a
comma-separated argument summary or a JSON-shaped payload
representation in there for assertion. Functional update
(immutable data structures): rebind the result —
m = m.record(...).
call_count
Section titled “call_count”pub function (m: MockPlatform) call_count(): i32(m: MockPlatform).call_count() — number of calls
recorded so far. Convenience for the common
assert_eq(m.call_count(), N) shape.
pub function (m: MockPlatform) reset(): MockPlatform(m: MockPlatform).reset(): MockPlatform — return a
MockPlatform with an empty call log. Functional update
(immutable data structures): rebind the result —
m = m.reset().
has_call
Section titled “has_call”pub function (m: MockPlatform) has_call(name: string): boolean(m: MockPlatform).has_call(name) — true iff any
recorded call matches name. Less precise than
inspecting m.calls[N].name directly but handy when the
test cares “did this side effect happen at all?”
regardless of position.
find_call
Section titled “find_call”pub function (m: MockPlatform) find_call(name: string): Option[MockCall](m: MockPlatform).find_call(name): Option[MockCall] —
return the first call with the given name, or None.
Useful when the test wants to inspect the args of a
specific call without pinning its position in the log.