I have not done more than read your post and noticed that you are having problems using an SWI-Prolog HTTP server to handle JSON. Instead of trying to find and fix your bug, I saw that Simple Prolog server with JavaScript clien is also using JSON and might be a better starting point for what you seek.
Also, again without running any code, in test_server.plt
noticed that
:- use_module(library(http/http_client)).
:- use_module(library(http/json)).
:- include(test_server).
is before
:- begin_tests(test_server).
When I see
:- begin_tests(test_server).
I think
module('test_server',[]).
In other words you are wanting the to use modules but you have asked for them outside of the test module.
I would try this:
:- begin_tests(test_server).
:- use_module(library(http/http_client)).
:- use_module(library(http/json)).
Not sure about what to do with
:- include(test_server).
but thinking the test_server
should be put into a module and then also added with use_module/1
HTH