Windows: official port -- UCRT static build, UTF-8 throughout, Low IL sandbox, ncurses TUI, installer; v0.6.0
Build
* cross build switches to pkgsCross.ucrt64 (shell-win.nix); curl (Schannel),
winpthreads and ncurses 6.6 are linked statically, so the release is
cst-agent.exe + busybox.exe (busybox-w32 Unicode) with no extra DLLs
* windres embeds a manifest with activeCodePage=UTF-8 and a version resource
* ncurses 6.6 Windows console driver patches (mouse button state, A_DIM,
wide-char declarations): scripts/patches/
* scripts/bootstrap_msys2.sh builds the same release natively in MSYS2
UCRT64; PR #1's MINGW64 notes now point there
* vendor/tre-regex (musl's TRE) provides <regex.h> on MinGW
UTF-8
* paths cross the system call boundary as UTF-16 (*W APIs); console code
pages set to 65001 and restored on exit; files are read and written in
binary mode
* child output that is not valid UTF-8 is decoded from the console, OEM or
ANSI system code page
* read_file hides CR; edit_file, apply_patch and write_file keep CRLF line
endings and a UTF-8 BOM
OS layer and processes
* os_dir_* and cst_fnmatch replace the POSIX-only directory walks in
subagent, plugins, skills, undo and fs_tools; realpath / path_under and
symlink rejection work on Windows
* every child goes through CreateProcessW with its own environment block
inside a Job Object, so timeouts and Esc end the whole process tree
Sandbox (auto mode, "auto · lowil")
* run_shell runs with a restricted Low integrity token; the workspace gets
an inheritable Low label once, the sandbox TEMP is labeled Low, and the
credentials file gets a no-read-up label
* drive roots, the profile and system folders are never labeled
* network commands still ask, since Low IL does not block the network;
Access denied and MSYS2's 0xc0000142 offer a rerun outside the sandbox
* /sandbox lists labeled folders, /sandbox reset-labels restores them
TUI
* raster console fonts are switched to Consolas / NSimSun while running
* the home logo falls back to text when the console font lacks U+2580
* mouse drag copy goes to the Windows clipboard
Distribution
* scripts/install_windows.ps1 installs a Gitea release into
%LOCALAPPDATA%\Programs\cst-agent and adds it to the user PATH;
cst-agent-update.cmd reruns it; scripts/release_windows.sh uploads the
zip with the token taken from the environment
* scripts/run_windows.bat is gone; docs/README-windows.md is rewritten
Tests
* new test_lowil, test_win_utf8 and test_os_dir; tests made portable
(cst_test_util.h)
* scripts/win_test.sh and scripts/winvm/ run the suite on English and
Chinese Windows Server VMs as Administrator, a standard user and a
Chinese user name: 29/29 on all six
This commit is contained in:
+27
-32
@@ -15,19 +15,16 @@
|
||||
#include "cst_util.h"
|
||||
#include "os_compat.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#define CST_TEST_SOCKETS
|
||||
#include "cst_test_util.h"
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int nfail;
|
||||
|
||||
@@ -45,9 +42,9 @@ static atomic_int g_child_active, g_child_max, g_child_reqs;
|
||||
static atomic_int g_child_saw_task, g_child_saw_write, g_child_role_prompt;
|
||||
static atomic_int g_parent_saw_task;
|
||||
|
||||
static void send_all(int fd, const char *s, size_t n) {
|
||||
static void send_all(test_sock_t fd, const char *s, size_t n) {
|
||||
while (n > 0) {
|
||||
ssize_t w = send(fd, s, n, MSG_NOSIGNAL);
|
||||
long w = send(fd, s, (int)n, MSG_NOSIGNAL);
|
||||
if (w <= 0)
|
||||
return;
|
||||
s += w;
|
||||
@@ -55,7 +52,7 @@ static void send_all(int fd, const char *s, size_t n) {
|
||||
}
|
||||
}
|
||||
|
||||
static void sse(int fd, cJSON *delta, const char *finish) {
|
||||
static void sse(test_sock_t fd, cJSON *delta, const char *finish) {
|
||||
cJSON *o = cJSON_CreateObject();
|
||||
cJSON *ch = cJSON_AddArrayToObject(o, "choices");
|
||||
cJSON *c0 = cJSON_CreateObject();
|
||||
@@ -80,7 +77,7 @@ static void sse(int fd, cJSON *delta, const char *finish) {
|
||||
cJSON_Delete(o);
|
||||
}
|
||||
|
||||
static void reply_text(int fd, const char *text) {
|
||||
static void reply_text(test_sock_t fd, const char *text) {
|
||||
cJSON *d = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(d, "role", "assistant");
|
||||
cJSON_AddStringToObject(d, "content", text);
|
||||
@@ -90,7 +87,7 @@ static void reply_text(int fd, const char *text) {
|
||||
}
|
||||
|
||||
/* calls: {name, args_json} pairs */
|
||||
static void reply_calls(int fd, const char *const *calls, int n) {
|
||||
static void reply_calls(test_sock_t fd, const char *const *calls, int n) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
cJSON *d = cJSON_CreateObject();
|
||||
cJSON *tc = cJSON_AddArrayToObject(d, "tool_calls");
|
||||
@@ -121,7 +118,7 @@ static int has_tool(const cJSON *body, const char *name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void handle(int fd, const char *body_txt) {
|
||||
static void handle(test_sock_t fd, const char *body_txt) {
|
||||
cJSON *body = cJSON_Parse(body_txt);
|
||||
const cJSON *msgs = cJSON_GetObjectItemCaseSensitive(body, "messages");
|
||||
int nm = cJSON_GetArraySize(msgs);
|
||||
@@ -155,9 +152,9 @@ static void handle(int fd, const char *body_txt) {
|
||||
if (strstr(sys->valuestring, "Role instructions:\nYou only read."))
|
||||
atomic_store(&g_child_role_prompt, 1);
|
||||
if (strstr(user, "Slow")) {
|
||||
usleep(4000 * 1000); /* cancelled before this ends */
|
||||
test_sleep_ms(4000); /* cancelled before this ends */
|
||||
} else {
|
||||
usleep(300 * 1000);
|
||||
test_sleep_ms(300);
|
||||
}
|
||||
if (strcmp(last_role, "user") == 0) {
|
||||
const char *calls[] = {"read_file", "{\"path\":\"a.txt\"}"};
|
||||
@@ -206,13 +203,13 @@ static void handle(int fd, const char *body_txt) {
|
||||
}
|
||||
|
||||
static void *conn_main(void *p) {
|
||||
int fd = (int)(intptr_t)p;
|
||||
test_sock_t fd = (test_sock_t)(intptr_t)p;
|
||||
cst_buf_t req = {0};
|
||||
char tmp[8192];
|
||||
long need = -1;
|
||||
size_t hdr_end = 0;
|
||||
for (;;) {
|
||||
ssize_t n = recv(fd, tmp, sizeof(tmp), 0);
|
||||
long n = recv(fd, tmp, sizeof(tmp), 0);
|
||||
if (n <= 0)
|
||||
break;
|
||||
cst_buf_append(&req, tmp, (size_t)n);
|
||||
@@ -230,23 +227,23 @@ static void *conn_main(void *p) {
|
||||
if (hdr_end)
|
||||
handle(fd, req.buf + hdr_end);
|
||||
cst_buf_free(&req);
|
||||
close(fd);
|
||||
test_sock_close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int g_lfd;
|
||||
static test_sock_t g_lfd;
|
||||
|
||||
static void *server_main(void *p) {
|
||||
(void)p;
|
||||
for (;;) {
|
||||
int fd = accept(g_lfd, NULL, NULL);
|
||||
if (fd < 0)
|
||||
test_sock_t fd = accept(g_lfd, NULL, NULL);
|
||||
if (fd == TEST_BAD_SOCK)
|
||||
return NULL;
|
||||
pthread_t th;
|
||||
if (pthread_create(&th, NULL, conn_main, (void *)(intptr_t)fd) == 0)
|
||||
pthread_detach(th);
|
||||
else
|
||||
close(fd);
|
||||
test_sock_close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,10 +279,10 @@ static void put(const char *root, const char *rel, const char *text) {
|
||||
for (char *q = p + strlen(root) + 1; *q; q++)
|
||||
if (*q == '/') {
|
||||
*q = 0;
|
||||
mkdir(p, 0755);
|
||||
test_mkdir(p, 0755);
|
||||
*q = '/';
|
||||
}
|
||||
FILE *fp = fopen(p, "w");
|
||||
FILE *fp = fopen(p, "wb");
|
||||
if (fp) {
|
||||
fputs(text, fp);
|
||||
fclose(fp);
|
||||
@@ -293,13 +290,13 @@ static void put(const char *root, const char *rel, const char *text) {
|
||||
}
|
||||
|
||||
static void *cancel_later(void *p) {
|
||||
usleep(800 * 1000);
|
||||
test_sleep_ms(800);
|
||||
cst_agent_request_cancel(p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
test_sock_init();
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
g_lfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
struct sockaddr_in addr;
|
||||
@@ -316,10 +313,10 @@ int main(void) {
|
||||
pthread_t srv;
|
||||
pthread_create(&srv, NULL, server_main, NULL);
|
||||
|
||||
char root[256], ws[300];
|
||||
snprintf(root, sizeof(root), "/tmp/cst-sub-%d", (int)getpid());
|
||||
char root[600], ws[700];
|
||||
if (test_tmpdir(root, sizeof(root), "cst-sub") != 0)
|
||||
return 1;
|
||||
snprintf(ws, sizeof(ws), "%s/ws", root);
|
||||
mkdir(root, 0755);
|
||||
setenv("XDG_CONFIG_HOME", root, 1);
|
||||
put(root, "ws/a.txt", "alpha\n");
|
||||
put(root, "ws/.agent/agents/reviewer.md",
|
||||
@@ -470,11 +467,9 @@ int main(void) {
|
||||
CHECK(cst_subagent_list(ws, "parent1", recs, 8) == 0,
|
||||
"delete removes sub-agent transcripts");
|
||||
|
||||
char cmd[400];
|
||||
snprintf(cmd, sizeof(cmd), "rm -rf %s", root);
|
||||
if (system(cmd) != 0)
|
||||
if (test_rmrf(root) != 0)
|
||||
fprintf(stderr, "note: cleanup failed\n");
|
||||
close(g_lfd);
|
||||
test_sock_close(g_lfd);
|
||||
if (nfail) {
|
||||
fprintf(stderr, "test_subagent: %d failure(s)\n", nfail);
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user