Fix kill fixture origin and prove durable typing survives SIGKILL
4 files changed,
+68
−7
docs/testing/k3-evidence.md+13 −0internal/docs/native_kill_test.go+49 −4native/apple/Tests/DocsKitTests/OfflineKillTests.swift+3 −1native/scripts/test-offline-kill.py+3 −2
CI passed — run details
diff --git a/docs/testing/k3-evidence.md b/docs/testing/k3-evidence.md| index 7f99e8a..206f619 100644 |
| --- a/docs/testing/k3-evidence.md |
| +++ b/docs/testing/k3-evidence.md |
| @@ -110,3 +110,16 @@ native/crdt/target, native/host/target, native/build, and the generated |
| DocsCRDT.xcframework. The generated Xcode projects remain ignored. No other |
| session's outputs were removed. Cleanup briefly restored 1.7 GiB, then free |
| space continued falling; do not restart builds without sufficient headroom. |
| + |
| +## Resume: SIGKILL proof (2026-09-24) |
| + |
| +The fixture configured localhost:8080 while NativeHTTP used its random loopback |
| +origin. A native-style title POST failed 403 (`/tmp/k3-origin-red.log`). |
| +Configure the server's actual listener origin; do not bypass CSRF. The script |
| +now refuses a failed initial save or pre-kill typing assertion. |
| + |
| +With only lane replay omitted, offline reopen failed with empty text instead of |
| +all 12 edits; initial save and server convergence passed (one assertion failure, |
| +`/tmp/k3-kill-valid-red.log`). Restore replay: SIGKILL after 12 durable edits, |
| +exact offline recovery, real authenticated server convergence, no duplicate text |
| +all passed (`/tmp/k3-kill-valid-green.log`). |
diff --git a/internal/docs/native_kill_test.go b/internal/docs/native_kill_test.go| index 24bb3fc..37439fd 100644 |
| --- a/internal/docs/native_kill_test.go |
| +++ b/internal/docs/native_kill_test.go |
| @@ -2,9 +2,13 @@ package docs_test |
| import ( |
| "encoding/json" |
| + "github.com/carlosframework/docs/internal/docs" |
| + "net" |
| + "net/http" |
| "net/http/httptest" |
| "os" |
| "path/filepath" |
| + "strings" |
| "testing" |
| "time" |
| ) |
| @@ -16,11 +20,52 @@ func TestNativeKillServer(t *testing.T) { |
| if dir == "" { |
| t.Skip("Run native/scripts/test-offline-kill.py") |
| } |
| - app := members(t, "kill@example.com") |
| + listener, err := net.Listen("tcp", "127.0.0.1:0") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer listener.Close() |
| + app, err := docs.NewForTestWith(t, docs.Config{AllowedAddresses: "kill@example.com", Origin: "http://" + listener.Addr().String()}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| cookies := signInCookies(t, app, "kill@example.com") |
| - sqid := createDoc(t, app, cookies, "Kill recovery") |
| - server := httptest.NewServer(app.Handler()) |
| + create := httptest.NewRequest("POST", "/documents", strings.NewReader("title=Kill+recovery")) |
| + create.Header.Set("Origin", "http://"+listener.Addr().String()) |
| + create.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| + for _, cookie := range cookies { |
| + create.AddCookie(cookie) |
| + } |
| + created := httptest.NewRecorder() |
| + app.Handler().ServeHTTP(created, create) |
| + if created.Code != http.StatusSeeOther { |
| + t.Fatalf("create: status %d", created.Code) |
| + } |
| + sqid := strings.TrimPrefix(created.Header().Get("Location"), "/d/") |
| + server := httptest.NewUnstartedServer(app.Handler()) |
| + server.Listener.Close() |
| + server.Listener = listener |
| + server.Start() |
| defer server.Close() |
| + // Match NativeHTTP: Origin, without a browser's Sec-Fetch-Site shortcut. |
| + request, err := http.NewRequest("POST", server.URL+"/d/"+sqid+"/title", strings.NewReader("title=Kill+recovery")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + request.Header.Set("Origin", server.URL) |
| + request.Header.Set("Accept", "application/json") |
| + request.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| + for _, cookie := range cookies { |
| + request.AddCookie(cookie) |
| + } |
| + response, err := http.DefaultClient.Do(request) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + response.Body.Close() |
| + if response.StatusCode < 200 || response.StatusCode >= 300 { |
| + t.Fatalf("native-origin initial save: status %d, want 200", response.StatusCode) |
| + } |
| config := map[string]string{"origin": server.URL, "sqid": sqid, "name": cookies[0].Name, "value": cookies[0].Value} |
| data, err := json.Marshal(config) |
| if err != nil { |
| @@ -29,7 +74,7 @@ func TestNativeKillServer(t *testing.T) { |
| if err := os.WriteFile(filepath.Join(dir, "connection.json"), data, 0600); err != nil { |
| t.Fatal(err) |
| } |
| - deadline := time.Now().Add(3 * time.Minute) |
| + deadline := time.Now().Add(6 * time.Minute) |
| for time.Now().Before(deadline) { |
| if _, err := os.Stat(filepath.Join(dir, "done")); err == nil { |
| return |
diff --git a/native/apple/Tests/DocsKitTests/OfflineKillTests.swift b/native/apple/Tests/DocsKitTests/OfflineKillTests.swift| index 6fb096e..6fbc1d1 100644 |
| --- a/native/apple/Tests/DocsKitTests/OfflineKillTests.swift |
| +++ b/native/apple/Tests/DocsKitTests/OfflineKillTests.swift |
| @@ -23,7 +23,9 @@ final class OfflineKillTests: XCTestCase { |
| await model.open(config["sqid"]!) |
| XCTAssertNotNil(model.projection) |
| if mode == "write" { |
| - let saved = await model.saveAll(); XCTAssertTrue(saved) |
| + guard await model.saveAll() else { |
| + XCTFail("Initial save failed: \(model.syncStatus)"); return |
| + } |
| path.send(.unsatisfied) |
| while connectivity.isPathSatisfied { try await Task.sleep(for: .milliseconds(5)) } |
| try String(ProcessInfo.processInfo.processIdentifier).write(to: root.appendingPathComponent("pid"), atomically: true, encoding: .utf8) |
diff --git a/native/scripts/test-offline-kill.py b/native/scripts/test-offline-kill.py| index 645f66c..8857691 100755 |
| --- a/native/scripts/test-offline-kill.py |
| +++ b/native/scripts/test-offline-kill.py |
| @@ -12,7 +12,7 @@ import time |
| root = Path(__file__).resolve().parents[2] |
| -def wait_for(path, process, timeout=120): |
| +def wait_for(path, process, timeout=300): |
| deadline = time.monotonic() + timeout |
| while not path.exists(): |
| if process.poll() is not None: |
| @@ -25,7 +25,7 @@ with tempfile.TemporaryDirectory(prefix="docs-k3-kill-", dir="/tmp") as tmp: |
| scratch = Path(tmp) |
| env = dict(os.environ, DOCS_KILL_DIR=tmp, TMPDIR="/tmp") |
| server_log = (scratch / "server.log").open("w") |
| - server = subprocess.Popen(["go", "test", "./internal/docs", "-run", "^TestNativeKillServer$", "-count=1", "-timeout=4m"], cwd=root, env=env, stdout=server_log, stderr=subprocess.STDOUT, start_new_session=True) |
| + server = subprocess.Popen(["go", "test", "./internal/docs", "-run", "^TestNativeKillServer$", "-count=1", "-timeout=8m"], cwd=root, env=env, stdout=server_log, stderr=subprocess.STDOUT, start_new_session=True) |
| writer = None |
| try: |
| wait_for(scratch / "connection.json", server) |
| @@ -33,6 +33,7 @@ with tempfile.TemporaryDirectory(prefix="docs-k3-kill-", dir="/tmp") as tmp: |
| with (scratch / "writer.log").open("w") as log: |
| writer = subprocess.Popen(command, cwd=root, env=dict(env, DOCS_KILL_MODE="write"), stdout=log, stderr=subprocess.STDOUT, start_new_session=True) |
| wait_for(scratch / "kill-now", writer) |
| + assert ": error:" not in (scratch / "writer.log").read_text(), "typing assertions failed before kill" |
| pid = int((scratch / "pid").read_text()) |
| os.kill(pid, signal.SIGKILL) |
| result = writer.wait(timeout=20) |