Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
branches: ["master", "codex/**"]


permissions: read-all
Expand Down Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
`
Expand Down
35 changes: 33 additions & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -22,6 +22,7 @@ import (
"strings"
"testing"

"github.com/1set/starlet"
"github.com/gin-gonic/gin"
"go.starlark.net/starlark"
)
Expand Down Expand Up @@ -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) {
Expand Down
Loading