diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c6d4c02..a42fa3c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: push: branches: ["master"] pull_request: - branches: ["master"] + branches: ["master", "codex/**"] permissions: read-all @@ -38,7 +38,7 @@ jobs: # Star* module's pipeline. Pinned to a commit SHA for supply-chain safety; # bump the pin when meta's workflow changes (Dependabot github-actions can # automate this). - uses: 1set/meta/.github/workflows/go-ci.yml@23f088bcd6dce16c93e0056d7b70b4f4434208e8 + uses: 1set/meta/.github/workflows/go-ci.yml@6b334e6a2762acaeefcea9fc7d3e86964e9246be with: go-floor: "1.25" doc-coverage: true diff --git a/example_test.go b/example_test.go index fe385fa..1ad670f 100644 --- a/example_test.go +++ b/example_test.go @@ -46,16 +46,9 @@ def main(): # Register routes srv.get("/", home) srv.get("/api/info", api_info) - + + # This example configures routes without binding a shared test port. print("Server created successfully") - - # Start server - srv.start() - - # TODO: make something calling via http package to verify the response - - # Stop server - srv.stop() main() ` diff --git a/server_test.go b/server_test.go index e2e1691..e3a40d8 100644 --- a/server_test.go +++ b/server_test.go @@ -8,7 +8,7 @@ package web // - Start() bind errors: a failed listen must surface, not be swallowed // - create_server argument validation: port range / invalid port / header override // - server builtin arg validation: route / error_handler / use_for / group errors -// - lifecycle errors: stop()/double-start guards +// - lifecycle: script start()/stop() on an OS-assigned port; error guards // - wrapHandler + applyResponse: request->handler->response bridge via httptest // - file responses: complete entrypoint contract and fixed host root @@ -22,6 +22,7 @@ import ( "strings" "testing" + "github.com/1set/starlet" "github.com/gin-gonic/gin" "go.starlark.net/starlark" ) @@ -371,7 +372,37 @@ func TestServerGroupBuiltin(t *testing.T) { } } -// --- lifecycle errors -------------------------------------------------------- +// --- lifecycle --------------------------------------------------------------- + +// Exercise the real script-facing lifecycle on an OS-assigned loopback port. +// The configuration example stays free of fixed-port side effects, and this +// test retains successful wrapper coverage even across concurrent test runs. +func TestServerScriptLifecycle(t *testing.T) { + srv := newServer(NewModule(), "127.0.0.1", 0) + defer func() { + if srv.IsRunning() { + if err := srv.Stop(); err != nil { + t.Errorf("cleanup Stop(): %v", err) + } + } + }() + machine := starlet.NewWithGlobals(starlet.StringAnyMap{"server": NewServerWrapper(srv)}) + _, err := machine.RunScript([]byte(` +def check(): + if server.is_running(): + fail("server unexpectedly running before start") + server.start() + if not server.is_running(): + fail("server not running after start") + server.stop() + if server.is_running(): + fail("server still running after stop") +check() +`), nil) + if err != nil { + t.Fatal(err) + } +} func TestServerLifecycleGuards(t *testing.T) { t.Run("stop_when_not_running_errors", func(t *testing.T) {