OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-cogserver commits / 1e3b8d8

Start repairs on broken unit test.
Once again, Claude sneaked some fast ones past me while I was not paying attention. Lesson: it is very eager to write unit tests that pass, rather than unit tests that actually find bugs. It will make sneaky changes and not follow given instructions, just so it can arrive at a unit test that passes. Core issue: it cannot tell apart unit test failures due to bed unit test design, from malfunctions in the core system. Thus, it twiddles the unit tests until they accept whatever the core system does. Intersting problem. This is very human "we've always don it this way." "Don't rock the boat." "The nail that sticks out gets pounded back in." Except now Claude has taken this very conservative bent, because it cannot tell apart how things are, from how things should be. Huh.
1e3b8d89d3330f6bf747b556ed0357dc4129b99b
by Linas Vepstas <linasvepstas@gmail.com> · 2025-12-14T06:51:31.000Z

Changed files (1) +55 -10

tests/scm/cog-server-test.scm +55 -10
……@@ -6,18 +6,13 @@
66(use-modules (opencog))
77(use-modules (opencog test-runner))
88(use-modules (opencog cogserver))
9(use-modules (ice-9 rdelim))
910
1011(opencog-test-runner)
1112(define tname "cog-server-test")
1213(test-begin tname)
1314
14(test-assert "CogServerNode-type-exists"
15 (defined? 'CogServerNode))
16
17(test-assert "CogServerNode-create"
18 (let ((csn (CogServerNode "test-server")))
19 (cog-atom? csn)))
20
15;; -------------------------------------------------------
2116;; Helper function to test if a port can be connected to
2217(define (can-connect-to-port? port)
2318 (catch #t
……@@ -29,7 +24,56 @@
2924 (lambda (key . args)
3025 #f)))
3126
32;; Helper to start a cogserver with given name and ports
27;; Helper to send data and receive response from a port
28(define (send-recv port data)
29 (let ((sock (socket AF_INET SOCK_STREAM 0)))
30 (connect sock AF_INET INADDR_LOOPBACK port)
31 (display data sock)
32 (force-output sock)
33 (let loop ((result ""))
34 (let ((line (read-line sock)))
35 (if (eof-object? line)
36 (begin (close-port sock) result)
37 (loop (string-append result line "\n")))))))
38
39;; -------------------------------------------------------
40;; ===== Test the exported start-cogserver and stop-cogserver functions =====
41(define exported-telnet 17401)
42(define exported-web 18481)
43
44(define exported-csn (start-cogserver #:port exported-telnet #:web exported-web #:mcp 0))
45
46(test-assert "start-cogserver"
47 (cog-atom? exported-csn))
48
49;; Test telnet port: send "help" and expect at least 250 bytes
50(test-assert "telnet-help"
51 (let ((response (send-recv exported-telnet "help\n.\n")))
52 (>= (string-length response) 250)))
53
54;; Test telnet port: send scheme expression and verify result
55(test-assert "telnet-scheme-eval"
56 (let ((response (send-recv exported-telnet "scm\n(+ 2 2)\n.\n")))
57 (string-contains response "4")))
58
59;; Test web port: send HTTP GET and expect 200 OK with at least 500 bytes
60(test-assert "web-stats"
61 (let ((response (send-recv exported-web "GET /stats HTTP/1.1\r\nHost: localhost\r\n\r\n")))
62 (and (string-contains response "200 OK")
63 (>= (string-length response) 500))))
64
65;; Stop the cogserver
66(stop-cogserver)
67
68;; Verify ports are closed after stop
69(test-assert "telnet-closed-after-stop"
70 (not (can-connect-to-port? exported-telnet)))
71
72(test-assert "web-closed-after-stop"
73 (not (can-connect-to-port? exported-web)))
74
75;; -------------------------------------------------------
76;; Custom helper to start a cogserver with given name and ports
3377(define (start-named-cogserver name telnet-port web-port)
3478 (define csn (CogServerNode name))
3579 (cog-set-value! csn (Predicate "*-telnet-port-*") (FloatValue telnet-port))
……@@ -42,7 +86,7 @@
4286(define (stop-named-cogserver csn)
4387 (cog-set-value! csn (Predicate "*-stop-*") (VoidValue)))
4488
45;; ===== Test 1: Single cogserver =====
89;; ===== Single cogserver =====
4690(define single-telnet-port 17101)
4791(define single-web-port 18181)
4892(define single-csn #f)
……@@ -69,7 +113,7 @@
69113(test-assert "single-web-closed"
70114 (not (can-connect-to-port? single-web-port)))
71115
72;; ===== Test 2: Three cogservers simultaneously =====
116;; ===== Three cogservers simultaneously =====
73117(define s1-telnet 17201) (define s1-web 18281)
74118(define s2-telnet 17202) (define s2-web 18282)
75119(define s3-telnet 17203) (define s3-web 18283)
……@@ -138,6 +182,7 @@
138182(test-assert "three-C-web-closed"
139183 (not (can-connect-to-port? s3-web)))
140184
185;; -------------------------------------------------------
141186(test-end tname)
142187
143188(opencog-test-end)