From 5dde677d01261f0c9e29350fed8db136d928fc75 Mon Sep 17 00:00:00 2001 From: Rory& Date: Tue, 20 Jan 2026 03:00:40 +0100 Subject: [PATCH] Fix NixOS tests, allow building via tsgo --- .gitignore | 3 ++- assets/openapi.json | Bin 894545 -> 896365 bytes default.nix | 2 +- flake.lock | Bin 1497 -> 1497 bytes nix/modules/default/default.nix | 1 + nix/tests/test-bundle-starts.nix | 36 ++++++++++++++++++++++++++++++- nix/trimNodeModules.sh | 15 +++++++------ package-lock.json | Bin 387152 -> 392540 bytes package.json | 3 +++ src/apply-migrations.ts | 4 +++- 10 files changed, 54 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index ea06d8997..47d221c8d 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,5 @@ schemas_nested/ schemas_final/ temp/ -!/extra/admin-api/Utilities/Spacebar.AdminApi.TestClient/wwwroot/lib/bootstrap/dist/ \ No newline at end of file +!/extra/admin-api/Utilities/Spacebar.AdminApi.TestClient/wwwroot/lib/bootstrap/dist/ +*.qcow2 \ No newline at end of file diff --git a/assets/openapi.json b/assets/openapi.json index efd3a4cdcf492459c6e357885f95e80891081ab4..fbadb7ab93814afa52226dce14c65a90eb605e70 100644 GIT binary patch delta 215 zcmcb3#_a7avxXMN7N!>F7M2#)7Pc1lEgZqqr(c-E@nrggMI5}_`=)cKaD(~VfqYL0 z6C}kwoplK_|Mb;cIE1DfbaJek-Y}0tb$ahs4!!LS>p2v-;AXIHzr2%!2ceO5yUF7M2#)7Pc1lEgZqqr+?_+(3{@>gM)Rte-8)icE=eU>fGpp zVM{pd(FLcoEMXRyes&v&&~$@Nj#bkIdO1|4uiMU{zdhh0hZWQG2U_fI+vPuSOk>)< zV;ct-E5gj}tM_p5AQ`uP!3ho(Wd7PK90ExE<;xy$AaS?%zu}O9@V5iq%?oC#wO6ok S0x=g5a|1EY_6io>uPXr44`9Lo diff --git a/default.nix b/default.nix index 7763d61c7..8f4280d80 100644 --- a/default.nix +++ b/default.nix @@ -41,7 +41,7 @@ pkgs.buildNpmPackage { npmDeps = pkgs.importNpmLock { npmRoot = filteredSrc; }; npmConfigHook = pkgs.importNpmLock.npmConfigHook; - npmBuildScript = "build:src"; + npmBuildScript = "build:src:tsgo"; makeCacheWritable = true; nativeBuildInputs = with pkgs; [ (pkgs.python3.withPackages (ps: with ps; [ setuptools ])) diff --git a/flake.lock b/flake.lock index 1805babff0a79df9347aededb17419fdddfa0e63..5a9df81916aac076318161015efa8571da64d934 100644 GIT binary patch delta 120 zcmcb~eUp2GCKJ1bshNqTf#t*rvfAFMIXU{l1zwS1*&gA(WqBEeURC-QE`@>VMoDG? z>7^B6;r^wGDM=pA$&=@^h)wQeGS)~nNlHvLOiD2{NVZHiHBT~1PBS$$w=^|QOfokx YFf&NBFtSKZHA|a(fKhof5A#_j03q@vx&QzG delta 120 zcmcb~eUp2GCKJ24g{6^+q4~rKvf3#b8D)WyX6A`W`A*puNe23*1`$qXW#t|z=}AHU zQ6a`@UXEFnei^3W<&)>Lh)wQeGS)CQu{2LiG)=ZNF*Q%LOtG*?F*i(0v@}jMNwhFF Yv#>BUOG`>kO-h`6fKhof5A#_j0N>Ch6#xJL diff --git a/nix/modules/default/default.nix b/nix/modules/default/default.nix index e3a65fb7f..d39919c32 100644 --- a/nix/modules/default/default.nix +++ b/nix/modules/default/default.nix @@ -235,6 +235,7 @@ in serviceConfig = { ExecStart = "${cfg.package}/bin/apply-migrations"; Type = "oneshot"; + RemainAfterExit = true; }; }; diff --git a/nix/tests/test-bundle-starts.nix b/nix/tests/test-bundle-starts.nix index 421517bcb..daebe5a1a 100644 --- a/nix/tests/test-bundle-starts.nix +++ b/nix/tests/test-bundle-starts.nix @@ -24,16 +24,50 @@ in cdnEndpoint = sb.mkEndpoint "cdn.sb.localhost" 3003 false; nginx.enable = true; serverName = "sb.localhost"; + extraEnvironment = { + DATABASE = "postgres://postgres:postgres@127.0.0.1/spacebar"; + LOG_REQUESTS = "-"; # Log all requests + LOG_VALIDATION_ERRORS = true; + }; }; in lib.trace ("Testing with config: " + builtins.toJSON cfg) cfg; services.nginx.enable = true; + services.postgresql = { + enable = true; + initdbArgs = [ + "--encoding=UTF8" + "--locale=C.UTF-8" + "--data-checksums" + "--allow-group-access" + ]; + enableTCPIP = true; + authentication = pkgs.lib.mkOverride 10 '' + # TYPE, DATABASE, USER, ADDRESS, METHOD + local all all trust + host all all 127.0.0.1/32 trust + host all all ::1/128 trust + host all all 0.0.0.0/0 md5 + ''; + initialScript = pkgs.writeText "backend-initScript" '' + CREATE ROLE spacebar WITH LOGIN PASSWORD 'spacebar' CREATEDB; + CREATE DATABASE spacebar; + GRANT ALL PRIVILEGES ON DATABASE spacebar TO spacebar; + ''; + }; }; testScript = '' + machine.wait_for_unit("spacebar-apply-migrations") machine.wait_for_unit("spacebar-api") machine.wait_for_unit("spacebar-cdn") machine.wait_for_unit("spacebar-gateway") - # machine.succeed("curl -f http://api.sb.localhost/.well-known/spacebar/client") + # Wait for unit doesn't mean the service is actually ready to accept connections + machine.wait_for_open_port(80) + machine.wait_for_open_port(3001) + machine.wait_for_open_port(3002) + machine.wait_for_open_port(3003) + # If well known works, its probably fine(tm)? + machine.succeed("curl -f http://api.sb.localhost/.well-known/spacebar/client") ''; } diff --git a/nix/trimNodeModules.sh b/nix/trimNodeModules.sh index debb27386..db057b117 100755 --- a/nix/trimNodeModules.sh +++ b/nix/trimNodeModules.sh @@ -1,5 +1,9 @@ # shellcheck shell=bash +# We don't care about CLI scripts: +for f in ./node_modules/.bin/*; do + rm -f "$(realpath $f)" $f +done # sources echo "Removing source files..." find ./node_modules -name '*.ts' -type f -delete @@ -30,17 +34,15 @@ find ./node_modules -name '*.ar-file-list' -type f -delete find ./node_modules -name '*.stamp' -type f -delete find ./node_modules -name '*musl.node' -type f -delete rm -rf ./node_modules/typescript +rm -rf ./node_modules/@typescript/native-preview rm -rf ./node_modules/ts-node rm -rf ./node_modules/node-gyp +rm -rf ./node_modules/node-gyp-build-optional-packages rm -rf ./node_modules/discord-protos/{discord_protos,scripts} -# We don't care about CLI scripts: -for f in ./node_modules/.bin/*; do - rm -vf "$(realpath $f)" $f -done # rm -rf ./node_modules/typescript-json-schema rm -rf ./node_modules/node-gyp -find ./node_modules -name '@types' -type d -exec rm -rfv {} + +find ./node_modules -name '@types' -type d -exec rm -rf {} + echo "Removing random common files..." find ./node_modules -name 'test' -type d -exec rm -rf {} + @@ -117,4 +119,5 @@ if false; then fi echo "Removing empty directories..." -find node_modules -maxdepth 1 -type d -empty -delete \ No newline at end of file +find node_modules -maxdepth 1 -type d -empty -delete +echo "Trimming complete." \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 4bc76d8b6728ed317ee477f5fa1a5dcd48487bcd..ae5e58252f04349d12b19d403e37e8994f09bb94 100644 GIT binary patch delta 2417 zcmbW1&2QUu7{|4=nb6AE0j2_niMHZpRIT4)J055vc4|AZofpS>>tR|_CypK4aU45# za{}$K1Go8L7!qR|L*fR9X%Ygd2no1MDt9>S58wbtqzckitx6K7h{I2^{P_7j&*%Am z{p{~A|N7VRSAQ;rh4Znc*8#KPsKeHVWw(ZE%Uiwn+UgB_6Wjzh*En(yP#ntEkb;B>;F1#1+Eym*T z#J9l4#EXsT@+;phte2%Wo{;2hC9CtIkOQkkrN$+-9gykS#JWd|Mgr_hyaQ)jtXi;2 zG%9W70E;bXdOMMkAunCZ)>y(qfimRLC1ij~CAbi#K3upQ?7#DFxc5=~)k_1VcQ}Ej zY68yqIRsW0SMJ<@F0d}Hh1SK`1!%HYxnX;%xzVrqR zRnzqki=I&uj7hQW6pp1Pm)6pn<4pdi66QxcERVubpXHa&l>eD_0$ldKm!jxT$sd7SFNTfZ1!AE?HZtSYq zfFyQR&q{+b3?j||gwnVxnG%)aWwlx}!Vk#Ui^2ZquY~XaaBeNQ`Q!CF_p#vjyUE$q z*FSk{9yJ?5Jsxl*^EehotPcA=WjFa+xxZb8@A&8<91EXS&@{*IxvC>F9elm6OFag~AX(+NL@n=SI=Qwq zDx^74DB-m{NPyK|%W4isv=#L4Od9$K_wvm4gU=qU%!7{5cc!C{kmnfM@CF*Q-7j;R zibOl?m>QMe#NR8tD-XSKd9)+?+a5_NbtiOBU5-)lE_ zeE^1;9n7_nCSZz57xLsSn6P83x~MZj`!7= U^!5`tHa-jEv-tQ49KZGGA8?~49RL6T delta 45 ycmccfOZ>tG@eQB2r#tX7aW}j0w7c*yZg=5fx}es6)13*3nSq#P`%QP&=B)syrxF1G diff --git a/package.json b/package.json index d2fee2947..9f71997d6 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,8 @@ "start:gateway": "node --enable-source-maps dist/gateway/start.js", "build": "npm run build:src && npm run generate:schema && npm run generate:openapi", "build:src": "tsc -b -v", + "build:tsgo": "npm run build:src:tsgo && npm run generate:schema && npm run generate:openapi", + "build:src:tsgo": "rm -rf dist/* && tsgo -b -v && mv -v dist/src/* dist/ && rm -rfv dist/src", "watch": "tsc -w -b .", "test": "node scripts/test.js", "lint": "eslint .", @@ -62,6 +64,7 @@ "@types/ws": "^8.18.1", "@typescript-eslint/eslint-plugin": "^8.51.0", "@typescript-eslint/parser": "^8.51.0", + "@typescript/native-preview": "^7.0.0-dev.20260119.1", "eslint": "^9.39.2", "globals": "^16.5.0", "husky": "^9.1.7", diff --git a/src/apply-migrations.ts b/src/apply-migrations.ts index 5c8060240..94f86320e 100644 --- a/src/apply-migrations.ts +++ b/src/apply-migrations.ts @@ -11,5 +11,7 @@ process.env.DB_LOGGING = "true"; import { closeDatabase, initDatabase } from "@spacebar/util"; initDatabase().then(() => { - closeDatabase().then((r) => {}); + closeDatabase().then((r) => { + console.log("Successfully applied migrations!"); + }); });