Re-vendor the canonical files from sneak/prompts at dd4027b (closes #112)
check / check (push) Waiting to run
check / check (push) Waiting to run
The shared files are fetched from sneak/prompts dd4027b, with this repository's own entries after the shared content in .gitignore, .editorconfig and .dockerignore. Lint and tests are Dockerfile phases (golangci-lint v2.14.0, Debian Go 1.24.13) that the build stage depends on, and the Makefile targets call the script/ entrypoints. make fmt also formats Markdown with prettier. Fixes for the new lint findings: the auth cookie is always Secure, an IRC connection's relay goroutine stops when the connection closes, and repeated strings are constants. neoirc-cli treats a plain-HTTP server on localhost or a loopback address as secure, so local use keeps its session. Whether the 60-second test cap covers building the test phase is open on sneak/prompts issue 113. Model: opus-5-5
This commit was merged in pull request #115.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"log/slog"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -71,7 +72,9 @@ func newTestEnv(t *testing.T) *testEnv {
|
||||
MOTD: "Welcome to test IRC",
|
||||
}
|
||||
|
||||
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
var listenConfig net.ListenConfig
|
||||
|
||||
listener, err := listenConfig.Listen(t.Context(), "tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("listen: %v", err)
|
||||
}
|
||||
@@ -116,10 +119,12 @@ func newTestEnv(t *testing.T) *testEnv {
|
||||
func (env *testEnv) dial(t *testing.T) *testClient {
|
||||
t.Helper()
|
||||
|
||||
conn, err := net.DialTimeout(
|
||||
dialer := net.Dialer{Timeout: testTimeout}
|
||||
|
||||
conn, err := dialer.DialContext(
|
||||
t.Context(),
|
||||
"tcp",
|
||||
env.srv.Listener().Addr().String(),
|
||||
testTimeout,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("dial: %v", err)
|
||||
@@ -323,6 +328,7 @@ func TestPrivmsgBetweenClients(t *testing.T) {
|
||||
bob.joinAndDrain("#chat")
|
||||
|
||||
alice.send("PRIVMSG #chat :hello bob!")
|
||||
|
||||
lines := bob.sendAndExpect("PING :sync", "hello bob!")
|
||||
assertContains(t, lines, "hello bob!", "channel PRIVMSG")
|
||||
}
|
||||
@@ -603,6 +609,56 @@ func TestNamesNonExistentChannel(t *testing.T) {
|
||||
)
|
||||
}
|
||||
|
||||
// TestRelayStopsWhenConnectionCloses checks that closing a
|
||||
// registered client's connection stops the goroutine that
|
||||
// relays its messages.
|
||||
//
|
||||
//nolint:paralleltest // counts every goroutine in the process
|
||||
func TestRelayStopsWhenConnectionCloses(t *testing.T) {
|
||||
env := newTestEnv(t)
|
||||
client := env.dial(t)
|
||||
|
||||
client.register("relaystop")
|
||||
waitForRelayGoroutines(t, 1)
|
||||
|
||||
err := client.conn.Close()
|
||||
if err != nil {
|
||||
t.Fatalf("close: %v", err)
|
||||
}
|
||||
|
||||
waitForRelayGoroutines(t, 0)
|
||||
}
|
||||
|
||||
const (
|
||||
stackDumpSize = 1 << 20
|
||||
relayCheckStep = 10 * time.Millisecond
|
||||
)
|
||||
|
||||
// waitForRelayGoroutines waits until exactly want goroutines
|
||||
// are running the relay loop, and fails the test if that does
|
||||
// not happen within testTimeout.
|
||||
func waitForRelayGoroutines(t *testing.T, want int) {
|
||||
t.Helper()
|
||||
|
||||
deadline := time.Now().Add(testTimeout)
|
||||
stacks := make([]byte, stackDumpSize)
|
||||
|
||||
for {
|
||||
n := runtime.Stack(stacks, true)
|
||||
got := strings.Count(string(stacks[:n]), "(*Conn).relayMessages(")
|
||||
|
||||
if got == want {
|
||||
return
|
||||
}
|
||||
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("relay goroutines: got %d, want %d", got, want)
|
||||
}
|
||||
|
||||
time.Sleep(relayCheckStep)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseMessage(b *testing.B) {
|
||||
line := ":nick!user@host PRIVMSG #channel :Hello, world!"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user